diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2013-09-12 13:54:46 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2013-09-12 13:54:46 +0400 |
commit | 33f807fd91826013499c996f9515838cf2c6d0c5 (patch) | |
tree | 50a6bd91fc3772d6f7e505fa9e7adcaca456c26b /sql | |
parent | adf637dff6484e602567a5294a43cb4b3aea606f (diff) | |
parent | 7e4845beea1a86dc53dc67908a2779ea2f0190a2 (diff) | |
download | mariadb-git-33f807fd91826013499c996f9515838cf2c6d0c5.tar.gz |
Merge 5.3 -> 5.5
Diffstat (limited to 'sql')
-rw-r--r-- | sql/opt_subselect.cc | 42 | ||||
-rw-r--r-- | sql/opt_subselect.h | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 6 |
3 files changed, 49 insertions, 0 deletions
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 85df9a47152..c9bc0289ba9 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -5231,6 +5231,12 @@ bool setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list, DBUG_RETURN(1); table->table= dummy_table; table->table->pos_in_table_list= table; + /* + Note: the table created above may be freed by: + 1. JOIN_TAB::cleanup(), when the parent join is a regular join. + 2. cleanup_empty_jtbm_semi_joins(), when the parent join is a + degenerate join (e.g. one with "Impossible where"). + */ setup_table_map(table->table, table, table->jtbm_table_no); } else @@ -5263,6 +5269,42 @@ bool setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list, } +/* + Cleanup non-merged semi-joins (JBMs) that have empty. + + This function is to cleanups for a special case: + Consider a query like + + select * from t1 where 1=2 AND t1.col IN (select max(..) ... having 1=2) + + For this query, optimization of subquery will short-circuit, and + setup_jtbm_semi_joins() will call create_dummy_tmp_table() so that we have + empty, constant temp.table to stand in as materialized temp. table. + + Now, suppose that the upper join is also found to be degenerate. In that + case, no JOIN_TAB array will be produced, and hence, JOIN::cleanup() will + have a problem with cleaning up empty JTBMs (non-empty ones are cleaned up + through Item::cleanup() calls). +*/ + +void cleanup_empty_jtbm_semi_joins(JOIN *join) +{ + List_iterator<TABLE_LIST> li(*join->join_list); + TABLE_LIST *table; + while ((table= li++)) + { + if ((table->jtbm_subselect && table->jtbm_subselect->is_jtbm_const_tab)) + { + if (table->table) + { + free_tmp_table(join->thd, table->table); + table->table= NULL; + } + } + } +} + + /** Choose an optimal strategy to execute an IN/ALL/ANY subquery predicate based on cost. diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h index 7b8f3142851..1e8b4cc50a1 100644 --- a/sql/opt_subselect.h +++ b/sql/opt_subselect.h @@ -28,6 +28,7 @@ int pull_out_semijoin_tables(JOIN *join); bool optimize_semijoin_nests(JOIN *join, table_map all_table_map); bool setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list, Item **join_where); +void cleanup_empty_jtbm_semi_joins(JOIN *join); // used by Loose_scan_opt ulonglong get_bound_sj_equalities(TABLE_LIST *sj_nest, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b7ba2fb7b58..b5ecaecda89 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10314,6 +10314,11 @@ void JOIN_TAB::cleanup() { if (table->pos_in_table_list->jtbm_subselect->is_jtbm_const_tab) { + /* + Set this to NULL so that cleanup_empty_jtbm_semi_joins() doesn't + attempt to make another free_tmp_table call. + */ + table->pos_in_table_list->table= NULL; free_tmp_table(join->thd, table); table= NULL; } @@ -10727,6 +10732,7 @@ void JOIN::cleanup(bool full) } if (full) { + cleanup_empty_jtbm_semi_joins(this); /* Ensure that the following delete_elements() would not be called twice for the same list. |