0

Abridged Q Language Manual 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

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

q那么 3.6+ 版本的between's#table和第一列的tablewith属性有什么区别吗?'#p

4

1 回答 1

1

我认为表本身上的 s# 可以改善搜索时间的唯一方法是,如果您?按照此处所述进行查找:https ://code.kx.com/q/ref/find/#searching-tables

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

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

于 2020-10-14T11:49:29.250 回答