2

我的表包含与对象相关的值的历史记录,它看起来像:

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 ?
4

1 回答 1

3

创建复合索引object_id + date

CREATE INDEX object_id_date ON History(object_id, `date`);
于 2012-07-11T23:45:02.220 回答