gpt4 book ai didi

mysql - 按 SQL 查询排序

转载 作者:行者123 更新时间:2023-11-29 14:05:49 24 4
gpt4 key购买 nike

这是在线门户的产品表结构。
目前产品表有超过100万条记录。

enter image description here

我创建了状态和交付 ID 索引。
我在按 ORDER BY status DESC、delivery_id ASC 列出产品时遇到性能问题
完整查询:

SELECT product_name FROM product ORDER BY status DESC, delivery_id ASC LIMIT 10

如何改进此查询以加快执行速度?

最佳答案

ORDER BY Optimization 下所述:

In some cases, MySQL cannot use indexes to resolve the ORDER BY, although it still uses indexes to find the rows that match the WHERE clause. These cases include the following:

[ <em>deletia</em> ]

  • You mix ASC and DESC:

    SELECT * FROM t1 ORDER BY <strong><em>key_part1</em></strong> DESC, <strong><em>key_part2</em></strong> ASC;

关于mysql - 按 SQL 查询排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355471/

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