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