diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2011-09-20 20:40:07 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2011-09-20 20:40:07 +0400 |
commit | f0323a40d8cbc5228015c1565a4800fd05fd61a8 (patch) | |
tree | cefb6b9ba9567df1f2b6a56dd9a26206469d887f /sql/sql_lex.cc | |
parent | 27cd8d7b70cc22693b9dab35ac2d1e720b8fc7a7 (diff) | |
download | mariadb-git-f0323a40d8cbc5228015c1565a4800fd05fd61a8.tar.gz |
BUG#849763: Wrong result with second execution of prepared statement with semijoin + view
- The problem was that Item_direct_view_ref and its embedded Item_field were getting incorrect
value of item->used_tables() after fix_fields() in the second and subsequent EXECUTE.
- Made relevant fixes in Item_field::fix_fields() and find_field_in_tables(), so that the
Item_field gets the correct attributes.
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r-- | sql/sql_lex.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 23662339cff..72cf0179449 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3622,6 +3622,47 @@ bool st_select_lex::save_prep_leaf_tables(THD *thd) } +/* + Return true if this select_lex has been converted into a semi-join nest + within 'ancestor'. + + We need a loop to check this because there could be several nested + subselects, like + + SELECT ... FROM grand_parent + WHERE expr1 IN (SELECT ... FROM parent + WHERE expr2 IN ( SELECT ... FROM child) + + which were converted into: + + SELECT ... + FROM grand_parent SEMI_JOIN (parent JOIN child) + WHERE + expr1 AND expr2 + + In this case, both parent and child selects were merged into the parent. +*/ + +bool st_select_lex::is_merged_child_of(st_select_lex *ancestor) +{ + bool all_merged= TRUE; + for (SELECT_LEX *sl= this; sl && sl!=ancestor; + sl=sl->outer_select()) + { + Item *subs= sl->master_unit()->item; + if (subs && subs->type() == Item::SUBSELECT_ITEM && + ((Item_subselect*)subs)->substype() == Item_subselect::IN_SUBS && + ((Item_in_subselect*)subs)->in_strategy & SUBS_SEMI_JOIN) + { + continue; + } + all_merged= FALSE; + break; + } + return all_merged; +} + + /** A routine used by the parser to decide whether we are specifying a full partitioning or if only partitions to add or to split. |