gpt4 book ai didi

MySQL:如何索引我的表以优化此查询?

转载 作者:行者123 更新时间:2023-11-29 02:03:07 25 4
gpt4 key购买 nike

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

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 ?

最佳答案

创建复合索引object_id + date

CREATE INDEX object_id_date ON History(object_id, `date`);

关于MySQL:如何索引我的表以优化此查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11443177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com