• unknown's avatar
    Fix for bug lp:944706, task MDEV-193 · da521483
    unknown authored
    The patch enables back constant subquery execution during
    query optimization after it was disabled during the development
    of MWL#89 (cost-based choice of IN-TO-EXISTS vs MATERIALIZATION).
    
    The main idea is that constant subqueries are allowed to be executed
    during optimization if their execution is not expensive.
    
    The approach is as follows:
    - Constant subqueries are recursively optimized in the beginning of
      JOIN::optimize of the outer query. This is done by the new method
      JOIN::optimize_constant_subqueries(). This is done so that the cost
      of executing these queries can be estimated.
    - Optimization of the outer query proceeds normally. During this phase
      the optimizer may request execution of non-expensive constant subqueries.
      Each place where the optimizer may potentially execute an expensive
      expression is guarded with the predicate Item::is_expensive().
    - The implementation of Item_subselect::is_expensive has been extended
      to use the number of examined rows (estimated by the optimizer) as a
      way to determine whether the subquery is expensive or not.
    - The new system variable "expensive_subquery_limit" controls how many
      examined rows are considered to be not expensive. The default is 100.
    
    In addition, multiple changes were needed to make this solution work
    in the light of the changes made by MWL#89. These changes were needed
    to fix various crashes and wrong results, and legacy bugs discovered
    during development.
    da521483
subselect_no_semijoin.result 228 KB