10.2.2.5 Derived Condition Pushdown Optimization (original) (raw)

10.2.2.5 Derived Condition Pushdown Optimization

MySQL supports derived condition pushdown for eligible subqueries. 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 outer WHERE condition down to the derived table, in this case resulting inSELECT * FROM (SELECT i, j FROM t1 WHERE i >_`constant`_) AS dt. When 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.

Outer WHERE conditions can be pushed down to derived materialized tables under the following circumstances:

SELECT * FROM (  
    SELECT i, j, SUM(k) AS sum FROM t1  
        WHERE i > 10  
        GROUP BY i, j  
        HAVING sum > 100  
    ) AS dt;  

To enable derived condition pushdown, theoptimizer_switch system variable'sderived_condition_pushdown flag (added in this release) must be set toon, which is the default setting. If this optimization is disabled byoptimizer_switch, you can enable it for a specific query using theDERIVED_CONDITION_PUSHDOWN optimizer hint. To disable the optimization for a given query, use theNO_DERIVED_CONDITION_PUSHDOWN optimizer hint.

The following restrictions and limitations apply to the derived table condition pushdown optimization: