gpt4 book ai didi

optimization - 优化MySQL查询: Is it always possible to optimize a query so that it doesn't use "ALL"

转载 作者:行者123 更新时间:2023-11-29 06:24:04 28 4
gpt4 key购买 nike

根据MySQL文档关于Optimizing Queries With Explain :

* ALL: A full table scan is done for each combination of rows from the previous tables. This is normally not good if the table is the first table not marked const, and usually very bad in all other cases. Normally, you can avoid ALL by adding indexes that allow row retrieval from the table based on constant values or column values from earlier tables.

这是否意味着任何使用 ALL 的查询都可以进行优化,使其不再进行全表扫描?

换句话来说,通过向表添加正确的索引,是否可以始终避免使用 ALL?或者是否存在某些情况,无论添加什么索引,ALL 都是不可避免的?

最佳答案

几乎(在某些情况下进行全面扫描实际上更便宜)总是可以优化一个查询,通过创建适当的索引来避免全面扫描。但是,如果您对同一个表运行多个查询,那么在某些情况下,其中一些查询最终会进行完整扫描,或者您最终会得到比表中的列更多的索引:-)

关于optimization - 优化MySQL查询: Is it always possible to optimize a query so that it doesn't use "ALL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1196362/

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