【问题标题】:What is the meaning of `s attribute on a table?表上的`s属性是什么意思?
【发布时间】:2020-10-14 11:13:34
【问题描述】:

Q 语言简略手册中 Arthur mentioned

`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。而且搜索时间也是一样的。并且两个表 with 属性的大小是相同的 - 我使用 AquaQ blogpost 中描述的 objsize 函数来确保。

那么's#tabletable 在第一列上具有'#p 属性的q 的3.6+ 版本有什么区别吗?

【问题讨论】:

  • “两个表的大小与属性相同”不太确定您引用的是哪个属性,但 `s# 没有开销,因为没有额外的结构来维护排序列表。

标签: kdb k


【解决方案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

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

【讨论】:

  • 知道了 - 表的一个实体是字典列表,因此将属性应用于列表可以加快搜索速度(二分搜索)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-16
  • 2019-09-13
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 2019-08-24
  • 2015-10-08
相关资源
最近更新 更多