kdb q - 分区内的组 table
kdb q - group table within partition
从新分区开始 mydb
我将以下三个表 table1
、table2
、table3
保存在分区 2018.01.01
、[=18 中=]、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
组,稍后我将 select 添加到这些组中。
当我在按 acc
额外存储之前对表进行排序时,我得到了轻微的加速(253 对 391 毫秒)。所以如果我以后想查询
select from t where date=2018.01.01, acc=`C123
是在存储之前按 acc
排序吗?还是在存储分区时会为不同的 acc
组创建索引?
感谢您的帮助
我认为您应该使用 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
从新分区开始 mydb
我将以下三个表 table1
、table2
、table3
保存在分区 2018.01.01
、[=18 中=]、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
组,稍后我将 select 添加到这些组中。
当我在按 acc
额外存储之前对表进行排序时,我得到了轻微的加速(253 对 391 毫秒)。所以如果我以后想查询
select from t where date=2018.01.01, acc=`C123
是在存储之前按 acc
排序吗?还是在存储分区时会为不同的 acc
组创建索引?
感谢您的帮助
我认为您应该使用 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