diff options
author | unknown <timour@askmonty.org> | 2011-03-03 23:48:31 +0200 |
---|---|---|
committer | unknown <timour@askmonty.org> | 2011-03-03 23:48:31 +0200 |
commit | adce16f96f08dc66e493b11af209663c3f5b7c02 (patch) | |
tree | 3148bb3b497b865257e266a46585bd5ca9fb0cfb /sql/item_subselect.cc | |
parent | c6ba9598026b06f5d64e7508abb652ac22d50e48 (diff) | |
download | mariadb-git-adce16f96f08dc66e493b11af209663c3f5b7c02.tar.gz |
Fix LP BUG#718763
Analysis:
The reason for the crash was that the inner subquery was executed
via a scan on a final temporary table applied after all other
operations. This final operation is implemented by changing the
contents of the JOIN object of the subquery to represent a table
scan over the temp table. At the same time query optimization of
the outer subquery required evaluation of the inner subquery, which
happened before the actual EXPLAIN. The evaluation left the JOIN
object of the inner subquery in the changed state, where it represented
a table scan over a temp table, and EXPLAIN crashed because the temp
table is not associated with any table reference (TABLE_LIST object).
The reason the JOIN was not restored was because its saving/restoration
was controlled by the join->select_lex->uncacheable flag, which was
not set in the case of materialization.
Solution:
In the methods Item_in_subselect::[single | row]_value_transformer() set:
select_lex->uncacheable|= UNCACHEABLE_EXPLAIN;
In addition, for symmetry, change:
master_unit->uncacheable|= UNCACHEABLE_EXPLAIN;
instead of UNCACHEABLE_DEPENDENT because if a subquery was not
dependent initially, the changed methods do not change this
fact. The subquery may later become correlated if it is transformed
to an EXISTS query, but it may stay uncorrelated if executed via
materialization.
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r-- | sql/item_subselect.cc | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 0300bf8171c..e89f8032e4f 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1464,8 +1464,15 @@ Item_in_subselect::single_value_transformer(JOIN *join, (char *)"<no matter>", (char *)in_left_expr_name); - master_unit->uncacheable|= UNCACHEABLE_DEPENDENT; - //psergey: placed then removed: select_lex->uncacheable|= UNCACHEABLE_DEPENDENT; + /* + The uncacheable property controls a number of actions, e.g. whether to + save/restore (via init_save_join_tab/restore_tmp) the original JOIN for + plans with a temp table where the original JOIN was overriden by + make_simple_join. The UNCACHEABLE_EXPLAIN is ignored by EXPLAIN, thus + non-correlated subqueries will not appear as such to EXPLAIN. + */ + master_unit->uncacheable|= UNCACHEABLE_EXPLAIN; + select_lex->uncacheable|= UNCACHEABLE_EXPLAIN; } if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards) @@ -1529,6 +1536,9 @@ Item_in_subselect::single_value_in_to_exists_transformer(JOIN * join, Comp_creat SELECT_LEX *select_lex= join->select_lex; DBUG_ENTER("Item_in_subselect::single_value_in_to_exists_transformer"); + /* + The IN=>EXISTS transformation makes non-correlated subqueries correlated. + */ select_lex->uncacheable|= UNCACHEABLE_DEPENDENT; if (join->having || select_lex->with_sum_func || select_lex->group_list.elements) @@ -1742,7 +1752,15 @@ Item_in_subselect::row_value_transformer(JOIN *join) optimizer->keep_top_level_cache(); thd->lex->current_select= current; - master_unit->uncacheable|= UNCACHEABLE_DEPENDENT; + /* + The uncacheable property controls a number of actions, e.g. whether to + save/restore (via init_save_join_tab/restore_tmp) the original JOIN for + plans with a temp table where the original JOIN was overriden by + make_simple_join. The UNCACHEABLE_EXPLAIN is ignored by EXPLAIN, thus + non-correlated subqueries will not appear as such to EXPLAIN. + */ + master_unit->uncacheable|= UNCACHEABLE_EXPLAIN; + select_lex->uncacheable|= UNCACHEABLE_EXPLAIN; if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards) { @@ -1796,6 +1814,9 @@ Item_in_subselect::row_value_in_to_exists_transformer(JOIN * join) DBUG_ENTER("Item_in_subselect::row_value_in_to_exists_transformer"); + /* + The IN=>EXISTS transformation makes non-correlated subqueries correlated. + */ select_lex->uncacheable|= UNCACHEABLE_DEPENDENT; if (is_having_used) { |