diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 559e8747068c76f08c330cc29a5732ab9fba0aff..339b264141a19cca00bd1c32d5b8ce0d6f065a7c 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -371,12 +371,6 @@ class Item_in_subselect :public Item_exists_subselect See also THD::emb_on_expr_nest. */ TABLE_LIST *emb_on_expr_nest; - /* - Location of the subquery predicate. It is either - - pointer to join nest if the subquery predicate is in the ON expression - - (TABLE_LIST*)1 if the predicate is in the WHERE. - */ - //TABLE_LIST *expr_join_nest; /* Types of left_expr and subquery's select list allow to perform subquery materialization. Currently, we set this to FALSE when it as well could @@ -402,6 +396,18 @@ class Item_in_subselect :public Item_exists_subselect TRUE<=>this is a flattenable semi-join, false overwise. */ bool is_flattenable_semijoin; + + /* + Used to determine how this subselect item is represented in the item tree, + in case there is a need to locate it there and replace with something else. + Two options are possible: + 1. This item is there 'as-is'. + 1. This item is wrapped within Item_in_optimizer. + */ + Item *original_item() + { + return is_flattenable_semijoin ? (Item*)this : (Item*)optimizer; + } bool *get_cond_guard(int i) { diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 395e26caadc7303756b18f3eb267d41268995a09..820b15e8ea2f6fe1d2f5d580f70b5a8c96f7db4f 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -712,16 +712,7 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) { Item **tree= ((*in_subq)->emb_on_expr_nest == NO_JOIN_NEST)? &join->conds : &((*in_subq)->emb_on_expr_nest->on_expr); - Item *replace_me= *in_subq; - /* - JTBM: the subquery was already mapped with Item_in_optimizer, so we - should search for that, not for original Item_in_subselect. - TODO: what about delaying that rewrite until here? - */ - if (!(*in_subq)->is_flattenable_semijoin) - { - replace_me= (*in_subq)->optimizer; - } + Item *replace_me= (*in_subq)->original_item(); if (replace_where_subcondition(join, tree, replace_me, new Item_int(1), FALSE)) DBUG_RETURN(TRUE); /* purecov: inspected */ @@ -756,18 +747,7 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) bool do_fix_fields= !(*in_subq)->substitution->fixed; Item **tree= ((*in_subq)->emb_on_expr_nest == NO_JOIN_NEST)? &join->conds : &((*in_subq)->emb_on_expr_nest->on_expr); - - Item *replace_me= *in_subq; - /* - JTBM: the subquery was already mapped with Item_in_optimizer, so we - should search for that, not for original Item_in_subselect. - TODO: what about delaying that rewrite until here? - */ - if (!(*in_subq)->is_flattenable_semijoin) - { - replace_me= (*in_subq)->optimizer; - } - + Item *replace_me= (*in_subq)->original_item(); if (replace_where_subcondition(join, tree, replace_me, substitute, do_fix_fields)) DBUG_RETURN(TRUE);