8.2.2.5 Derived Condition Pushdown Optimization导出条件下推优化

MySQL 8.0.22 and later supports derived condition pushdown for eligible subqueries. MySQL 8.0.22及更高版本支持符合条件的子查询的派生条件下推。For a query such as SELECT * FROM (SELECT i, j FROM t1) AS dt WHERE i > constant, it is possible in many cases to push the the outer WHERE condition down to the derived table, in this case resulting in SELECT * FROM (SELECT i, j FROM t1 WHERE i > constant) AS dt. 对于像SELECT * FROM (SELECT i, j FROM t1) AS dt WHERE i > constant这样的查询,在很多情况下,可能把外部WHERE条件下推到派生表,在这种情况下,产生SELECT * FROM (SELECT i, j FROM t1 WHERE i > constant) AS dtWhen a derived table cannot be merged into the outer query (for example, if the derived table uses aggregation), pushing the outer WHERE condition down to the derived table should decrease the number of rows that need to be processed and thus speed up execution of the query.当无法将派生表合并到外部查询中时(例如,如果派生表使用聚合),将外部WHERE条件向下推到派生表应减少需要处理的行数,从而加快查询的执行。

Note注意

Prior to MySQL 8.0.22, if a derived table was materialized but not merged, MySQL materialized the entire table, then qualified all of the resulting rows with the WHERE condition. 在MySQL 8.0.22之前,如果派生表被物化但未合并,MySQL物化整个表,然后使用WHERE条件限定所有结果行。This is still the case if derived condition pushdown is not enabled, or cannot be employed for some other reason.如果派生条件下推未启用,或由于其他原因无法使用,则仍然是这种情况。

Outer WHERE conditions can be pushed down to derived materialized tables under the following circumstances:在以下情况下,可以将WHERE条件下推到派生物化表中:

To enable derived condition pushdown, the optimizer_switch system variable's derived_condition_pushdown flag (added in this release) must be set to on, which is the default setting. 要启用派生条件下推,必须将optimizer_switch系统变量的derived_condition_pushdown标志(在此版本中添加)设置为on,这是默认设置。If this optimization is disabled by optimizer_switch, you can enable it for a specific query using the DERIVED_CONDITION_PUSHDOWN optimizer hint. 如果optimizer_switch禁用此优化,则可以使用DERIVED_CONDITION_PUSHDOWN优化器提示为特定查询启用它。To disable the optimization for a given query, use the NO_DERIVED_CONDITION_PUSHDOWN optimizer hint.要禁用给定查询的优化,请使用NO_DERIVED_CONDITION_PUSHDOWN优化器提示。

The following restrictions and limitations apply to the derived table condition pushdown optimization:以下限制和限制适用于衍生表格条件下推优化: