• unknown's avatar
    MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation · 875bd20a
    unknown authored
    1. Changed the lazy optimization for subqueries that can be
       materialized into bottom-up optimization during the optimization of
       the main query.
    
       The main change is implemented by the method
       Item_in_subselect::setup_engine.
      
       All other changes were required to correct problems resulting from
       changing the order of optimization. Most of these problems followed
       the same pattern - there are some shared structures between a
       subquery and its parent query. Depending on which one is optimized
       first (parent or child query), these shared strucutres may get
       different values, thus resulting in an inconsistent query plan.
    
    2. Changed the code-generation for subquery materialization to be
       performed in runtime memory for each (re)execution, instead of in
       statement memory (once per prepared statement).
       - Item_in_subselect::setup_engine() no longer creates materialization
         related objects in statement memory.
       - Merged subselect_hash_sj_engine::init_permanent and
         subselect_hash_sj_engine::init_runtime into
         subselect_hash_sj_engine::init, which is called for each
         (re)execution.
       - Fixed deletion of the temp table accordingly.
    
    
    mysql-test/r/subselect_mat.result:
      Adjusted changed EXPLAIN because of earlier optimization of subqueries.
    875bd20a
item_subselect.cc 147 KB