diff options
author | unknown <timour@askmonty.org> | 2010-10-04 17:30:46 +0300 |
---|---|---|
committer | unknown <timour@askmonty.org> | 2010-10-04 17:30:46 +0300 |
commit | 77c03bcf45aef44971a454a1f1a622fc8779089f (patch) | |
tree | f7dac2cf79707f7536b4b42a0302c68b8e11c1b4 /sql/sql_lex.cc | |
parent | 8ec5e13f1f0d56afe42e5ded02baeab7a6a60261 (diff) | |
download | mariadb-git-77c03bcf45aef44971a454a1f1a622fc8779089f.tar.gz |
MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation
Improved handling of EXPLAIN statements for subqueries.
This patch specifically solves the problem when EXPLAIN reports:
"const row not found"
instead of
"no matching row in const table".
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r-- | sql/sql_lex.cc | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index bfd24a2491c..445fdf5a7fd 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3100,11 +3100,20 @@ bool st_select_lex::optimize_unflattened_subqueries() { JOIN *inner_join= sl->join; SELECT_LEX *save_select= un->thd->lex->current_select; + ulonglong save_options; int res; /* We need only 1 row to determine existence */ un->set_limit(un->global_parameters); un->thd->lex->current_select= sl; + save_options= inner_join->select_options; + if (un->outer_select()->options & SELECT_DESCRIBE) + { + /* Optimize the subquery in the context of EXPLAIN. */ + set_explain_type(); + inner_join->select_options= options; + } res= inner_join->optimize(); + inner_join->select_options= save_options; un->thd->lex->current_select= save_select; if (res) return TRUE; @@ -3112,7 +3121,35 @@ bool st_select_lex::optimize_unflattened_subqueries() } } return FALSE; -} +} + + +/** + Set the EXPLAIN type for this subquery. +*/ + +void st_select_lex::set_explain_type() +{ + SELECT_LEX *first= master_unit()->first_select(); + /* drop UNCACHEABLE_EXPLAIN, because it is for internal usage only */ + uint8 is_uncacheable= (uncacheable & ~UNCACHEABLE_EXPLAIN); + + type= ((&master_unit()->thd->lex->select_lex == this) ? + (first_inner_unit() || next_select() ? + "PRIMARY" : "SIMPLE") : + ((this == first) ? + ((linkage == DERIVED_TABLE_TYPE) ? + "DERIVED" : + ((is_uncacheable & UNCACHEABLE_DEPENDENT) ? + "DEPENDENT SUBQUERY" : + (is_uncacheable ? "UNCACHEABLE SUBQUERY" : + "SUBQUERY"))) : + ((is_uncacheable & UNCACHEABLE_DEPENDENT) ? + "DEPENDENT UNION": + is_uncacheable ? "UNCACHEABLE UNION": + "UNION"))); + options|= SELECT_DESCRIBE; +} /** |