按分区字段查,查询性能为什么差别这么大

我的建库建表代码如下:


dbDate = database("", VALUE, 2020.01.01..2030.12.31)
dbSymbol=database("", HASH, [SYMBOL, 10])
db = database("dfs://OptionTick", COMPO, [dbSymbol,dbDate])
colNames=`secu_code`market`trade_date`trade_time`preclose`open`high`low`close`totalposition`totalvolume`turnover`big_price1`big_price2`big_price3`big_price4`big_price5`big_volume1`big_volume2`big_volume3`big_volume4`big_volume5`ask_price1`ask_price2`ask_price3`ask_price4`ask_price5`ask_volume1`ask_volume2`ask_volume3`ask_volume4`ask_volume5`flag
colTypes=[SYMBOL,SYMBOL,DATE,SECOND,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,INT,INT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,INT,INT,INT,INT,STRING]
t=table(1:0,colNames,colTypes)
db.createPartitionedTable(t,`optiontick,`secu_code`trade_date)


在表中写入数据后,然后发现通过 secu_code 和  trade_date查询速度差好几倍。按照trade_date查询更快一点,而且trade_date的查询条数有500w条,按照 secu_code代码查询才50w条,为什么会按照时间查询快很多呢?

附:查询语句如下:


snap = loadTable(dbPath,"opt_index_tick")
opday = select * from tmporder where trade_date=2020.01.02
opt_tick =  select * from tmporder  where secu_code = "10002340"


请先 登录 后评论

1 个回答

wale

 select * from tmporder where trade_date=2020.01.02  这个查询涉及2020.01.02的10个分区;

select * from tmporder  where secu_code = "10002340" 这个查询涉及的分区数跟库中保存了多少天有关,它涉及的分区数为每天1个。若总数 超过了10天,就可能比第1个查询涉及的分区数要多,而且它每个分区有多个股票,还需要过滤,所以说按照时间查询的第一个查询会快很多。

请先 登录 后评论