8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 10 优化 / 10.2 优化 SQL 语句 / 10.2.2 优化子查询、派生表、视图引用和公用表表达式
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.2.2 子查询、派生表、视图引用和公用表表达式优化10.2.2 Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions

MySQL 查询优化器有不同的策略可用于评估子查询:The MySQL query optimizer has different strategies available to evaluate subqueries:

  • 对于与 IN、= ANY 或 EXISTS 谓词一起使用的子查询,优化器有以下选择:For a subquery used with an IN, = ANY, or EXISTS predicate, the optimizer has these choices:

    • 半连接Semijoin

    • 物化Materialization

    • EXISTS 策略EXISTS strategy

  • 对于与 NOT IN、<> ALL 或 NOT EXISTS 谓词一起使用的子查询,优化器有以下选择:For a subquery used with a NOT IN, <> ALL or NOT EXISTS predicate, the optimizer has these choices:

    • 物化Materialization

    • EXISTS 策略EXISTS strategy

对于派生表,优化器有以下选择(这些选择也适用于视图引用和公用表表达式):For a derived table, the optimizer has these choices (which also apply to view references and common table expressions):

  • 将派生表合并到外部查询块中Merge the derived table into the outer query block

  • 将派生表物化为内部临时表Materialize the derived table to an internal temporary table

以下讨论提供了关于前述优化策略的更多信息。The following discussion provides more information about the preceding optimization strategies.

Note

使用子查询修改单个表的 UPDATE 和 DELETE 语句的一个限制是优化器不会使用半连接或物化子查询优化。作为解决方法,可以尝试将它们重写为使用连接而非子查询的多表 UPDATE 和 DELETE 语句。A limitation on UPDATE and DELETE statements that use a subquery to modify a single table is that the optimizer does not use semijoin or materialization subquery optimizations. As a workaround, try rewriting them as multiple-table UPDATE and DELETE statements that use a join rather than a subquery.