【发布时间】:2019-03-07 19:20:32
【问题描述】:
我有一个包含大量记录的表:
date instrument price
2019.03.07 X 1.1
2019.03.07 X 1.0
2019.03.07 X 1.2
...
当我查询当日开盘价时,我使用:
1 sublist select from prices where date = 2019.03.07, instrument = `X
执行需要很长时间,因为它选择了当天的所有价格并获得第一个。
我也试过了:
select from prices where date = 2019.03.07, instrument = `X, i = 0 //It does not return any record (why?)
select from prices where date = 2019.03.07, instrument = `X, i = first i //Seem to work. Does it?
在 Oracle 中,等价物是:
select * from prices where date = to_date(...) and instrument = "X" and rownum = 1
Oracle 将在找到第一条记录时立即停止。
如何在 KDB 中执行此操作(例如,在找到第一条记录后立即停止)?
【问题讨论】:
-
使用
i=0仅当您要查找的仪器是表中的第一项时才有效。使用i=first i时,查询将使用过滤选择中的第一个索引。 -
您是否已向仪器列添加(或考虑添加)属性?例如,如果您要应用 `p# 属性,它应该使您的 select 语句 (instrument=X) 中的第二个子句明显更快。
标签: kdb