表上的属性是什么意思

  • 本文关键字:是什么 属性 kdb k
  • 更新时间 :
  • 英文 :


Q语言手册摘要Arthur提到:

`s#table marks the table to use binary search and marks first column sorted

如果我们看看3.6版本:

N:1000000;
t1:t2:([]n:til N; m:N?`6);
t1:update `p#n from t1;
t2:`s#t2;
(meta t1)[`n]`a / `p
(meta t2)[`n]`a / `p
attr t1 / `
attr t2 / `s
ts:10000 select count i from t1 where n in 1000?N
/ ~7000
ts:10000 select count i from t2 where n in 1000?N
/ ~7000

我们发现是的,t2具有这个属性:s

但是由于某种原因,第一列上的属性不是s而是p。而且搜索时间也是一样的。具有属性的两个表的大小是相同的-我使用了AquaQ博客文章中描述的objsize函数来确保。

那么,在q的3.6+版本中,'s#table和第一列具有'#p属性的table之间有什么区别吗?

我认为,表上的s#能够改善搜索时间的唯一方法是使用?进行查找,如下所述:https://code.kx.com/q/ref/find/#searching-表格

q)ts:100000 t1?t1[0]
105 800
q)ts:100000 t2?t2[0]
86 800
q)
q)ts:100000 t1?t1[500000]
108 800
q)ts:100000 t2?t2[500000]
83 800
q)
q)ts:100000 t1?t1[999999]
107 800
q)ts:100000 t2?t2[999999]
83 800

对于键控表,它的行为有所不同(将其转换为阶跃函数(,但我认为这超出了您最初问题的范围。

最新更新