我有这个表:
CREATE TABLE `fund_historical_serie` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`date` date DEFAULT NULL,
`patrimony` decimal(14,5) NOT NULL,
`quota` decimal(14,5) NOT NULL,
`fund_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKchhpobehjf7ebat11b4clv7yx` (`fund_id`),
CONSTRAINT `FKchhpobehjf7ebat11b4clv7yx` FOREIGN KEY (`fund_id`) REFERENCES `fund` (`id`)
)
有大约 8 密耳的记录。
执行此查询大约需要 6 秒:
select * from fund_historical_serie where fund_id IN (17957,308331) and `date` >= '2017-02-28' and `date` <= '2017-08-30';
我正在日期列上创建一个索引,但它并没有改善查询时间:
Alter table fund_historical_serie add index date_idx (`date`);
查询仍需要 6 秒。
当我运行索引查询时,它显示 0 行和 0 条记录受到影响,索引不应该影响表上的当前记录吗? 还是我必须重新插入?
我还能做些什么来缩短查询时间?
谢谢。
> Fund_ID和日期的综合指数将提高性能。