我有一张股票价格表。该模式是这样的:MySQL - 具有多个条件的缓慢查询(尽管建立索引)
在表“data_1d”有对ticker_id和时间戳唯一索引ticker_timestamp。还有一个关于timestamp_id的主要索引。
'data_1d'中有~630万行。
此查询需要4+秒:
select * from data_1d where timestamp_id=1387 and open_close>20
解释:
而且它是20-30秒,如果我搜索范围时间戳。
如果我只用一个标准,timestamp或open_close搜索,它需要0.1-0.6秒。
例如:
select * from data_1d where timestamp_id=1387
OR
select * from data_1d where and open_close>20
我能做些什么来改善这里的表现?
谢谢。
编辑:我没有使用语句来创建表,但他们应该可以从架构中理解。但这些都是在他们使用
行情 主键的键:ID
timestamps_1d 主键:ID 唯一索引:时间戳
data_1d ticker_id - 引用行情.id timestamp_id - 引用timestamps_1d.id 唯一索引(或2列,ticker_id和timestamp_id):tic ker_timestamps
请将你得到的查询计划添加到EXPLAIN –
以及对所有相关表格适当的CREATE TABLE语句 – Strawberry
以及你在不同情况下实际尝试的不同查询 – THN