从新分区mydb
开始,我在分区table1
,table2
中保存以下三个表table3
,2018.01.01
,2018.01.02
,2018.01.03
,分别为:
npertable:10000000;
table1:([]date:npertable?2018.01.01+til 25;acc:npertable?`C123`C132`C321`C121`C131;c:npertable?til 100);
table2:([]date:npertable?2018.02.01+til 25;acc:npertable?`C123`C132`C321`C121`C131;c:npertable?til 100);
table3:([]date:npertable?2018.03.01+til 25;acc:npertable?`C123`C132`C321`C121`C131;c:npertable?til 100);
table1:`date xasc table1;
table2:`date xasc table2;
table3:`date xasc table3;
`:mydb/2018.01.01/t/ set .Q.en[`:mydb;table1];
`:mydb/2018.01.02/t/ set .Q.en[`:mydb;table2];
`:mydb/2018.01.03/t/ set .Q.en[`:mydb;table3];
您可以看到我有不同的acc
组,我稍后会选择这些组。
当我在acc
另外存储之前对表进行排序时,我获得了一点点加速(253对391毫秒)。所以如果我以后想查询
select from t where date=2018.01.01, acc=`C123
在存储我能做的最好的事情之前,按acc
排序?或者存储分区的内容是否会为不同的acc
组创建索引?
感谢您的帮助
答案 0 :(得分:2)
我认为您应该使用parted属性来优化查询。 例如,您可以使用此位按acc进行排序并应用属性。
{@[`acc xasc .Q.par[`:mydb;x;`t];`acc;`p#]}'[2018.01.01 2018.01.02 2018.01.03]
有关parted属性及其效果的更多详细信息,您可以从KX阅读本白皮书 - > https://kx.com/media/2017/11/Columnar_database_and_query_optimization.pdf
另请注意,您可以使用月份分区来满足您的需求。
如果我正确理解了您的示例,那么您有year.day.month
,因此如果日期始终为year.month
,您可以将其减少到01
即没有使用
`:mydb/2018.01.01/t/ set .Q.en[`:mydb;table1];
你可以简单地使用
`:mydb/2018.01/t/ set .Q.en[`:mydb;table1];
您可以在此处找到有关实现此目标的更多详细信息 - > https://code.kx.com/wiki/JB:KdbplusForMortals/partitioned_tables#1.3.7.2_Monthly