From 875bd20a7327b7fd03d1b020e25054755e42d5ad Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Jul 2010 13:52:02 +0300 Subject: MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation 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. --- sql/sql_class.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c85ea76c70d..8fd73fec960 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3052,6 +3052,7 @@ void TMP_TABLE_PARAM::init() table_charset= 0; precomputed_group_by= 0; bit_fields_as_long= 0; + materialized_subquery= 0; skip_create_table= 0; DBUG_VOID_RETURN; } -- cgit v1.2.1 From 18ad3bdc2fa3bbe1bfd7e433adb0bc6b3dbce8c8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 5 Sep 2010 18:43:47 +0300 Subject: MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation Fixes for multiple problems/bugs/test failures that resulted from moving subquery optimization from the execution phase to the optimization phase. --- sql/sql_class.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a4e8c84401b..930cf2393f7 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2630,6 +2630,7 @@ void Query_arena::free_items() for (; free_list; free_list= next) { next= free_list->next; + DBUG_ASSERT(free_list != next); free_list->delete_self(); } /* Postcondition: free_list is 0 */ -- cgit v1.2.1