The MySQL query optimizer has different strategies available to evaluate subqueries:MySQL查询优化器有不同的策略可用于评估子查询:
For a subquery used with an 对于与IN
, = ANY
, or EXISTS
predicate, the optimizer has these choices:IN
、=ANY
或EXISTS
谓词一起使用的子查询,优化器有以下选择:
Semijoin半连接
Materialization物化
EXISTS
strategy策略
For a subquery used with a 对于与NOT IN
, <> ALL
or NOT EXISTS
predicate, the optimizer has these choices:NOT IN
、<> ALL
或NOT EXISTS
谓语一起使用的子查询,优化器有以下选择:
Materialization物化
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.下面的讨论提供了有关上述优化策略的更多信息。
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. UPDATE
和DELETE
语句的一个限制是优化器不使用半联接或物化子查询优化。As a workaround, try rewriting them as multiple-table 作为一种变通方法,请尝试将它们重写为使用联接而不是子查询的多表UPDATE
and DELETE
statements that use a join rather than a subquery.UPDATE
和DELETE
语句。