我的表包含与对象相关的值的历史记录,如下所示:
create table History (
object_id bigint NOT NULL,
value int NOT NULL,
date bigint NOT NULL
);
如何对其进行索引以优化以下查询:
select * from History
where object_id = ? and date < ?
order by date desc
limit ?
答案 0 :(得分:3)
创建复合索引object_id + date
CREATE INDEX object_id_date ON History(object_id, `date`);