在 MySql 中,有一个大表,与表a和 ahistorical_price
有 2 个n:1
关系:instrument
timestamp
price
CREATE TABLE `historical_price`
(
`price_nbr` int(11) NOT NULL AUTO_INCREMENT,
`insid` int(11) NOT NULL,
`curr_insid` int(11) NOT NULL,
`timestamp_` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`price` float DEFAULT NULL,
PRIMARY KEY (`price_nbr`),
KEY `insid` (`insid`),
KEY `curr_insid` (`curr_insid`),
KEY `timestamp_` (`timestamp_`),
CONSTRAINT ...
) ENGINE=InnoDB
我想运行很多这样的查询:
SELECT price
FROM historical_price
WHERE insid=566 AND curr_insid=2 AND timestamp_ > '2012-05-01'
LIMIT 0,1
获取与条件instrument
匹配的旧记录。timestamp
greater than
explain
输出是:
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
1 | SIMPLE | historical_price | ref | insid,curr_insid,timestamp_ | insid | 4 | const | 987190 | Using where
在添加新的多列索引或用于帮助 db 引擎的新列之前,我想询问您对哪个选项可以带来最佳结果的意见(如果有的话)。