gpt4 book ai didi

mysql - 大表 (> 1M) 上 MySQL 查询的最佳键

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

我的查询执行时间过长(超过 300 秒)。可以通过索引或查询修改来优化吗?最好的 key 是什么?

SELECT
`streams_channel`.`id`,
`streams_channel`.`uid`,
`streams_channel`.`provider_id`
FROM
`streams_channel`
WHERE
`streams_channel`.`provider_id` = 1
AND
`streams_channel`.`followers` < 50
ORDER BY `streams_channel`.`id` ASC
LIMIT 15000 OFFSET 1440000;

最佳答案

此查询的最佳索引可能是streams_channel(provider_id, followers, id)。您还可以添加uid,以便索引覆盖查询(即,正在使用的所有列都在索引中)。

但是,该索引不会阻止 ORDER BY 的最终排序,这可能是性能问题。如果没有 LIMIT,查询会返回多少行?

streams_channel(provider_id, id, followers, uid) 上的索引可能会阻止排序。您需要测试您的数据。

关于mysql - 大表 (> 1M) 上 MySQL 查询的最佳键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720506/

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