diff options
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r-- | sql/item_subselect.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 62df666b71f..8b0c6efc9ee 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1999,12 +1999,31 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN * join, during JOIN::optimize: this->tmp_having= this->having; this->having= 0; */ Item* join_having= join->having ? join->having : join->tmp_having; - DBUG_ENTER("Item_in_subselect::create_single_in_to_exists_cond"); *where_item= NULL; *having_item= NULL; + /* + For PS we have to do fix_fields(expr) here to ensure that it's + evaluated in the outer context. If not, then fix_having() will do + a fix_fields(expr) in the inner context and mark expr as + 'depended', which will cause update_ref_and_keys() to find wrong + keys. + When not running PS, fix_fields(expr) as already been done earlier and + the following test does nothing. + */ + if (expr && !expr->fixed) + { + SELECT_LEX *save_current_select= thd->lex->current_select; + thd->lex->current_select= thd->lex->current_select->outer_select(); + bool tmp; + tmp= expr->fix_fields(thd, 0); + thd->lex->current_select= save_current_select; + if (tmp) + DBUG_RETURN(true); + } + if (join_having || select_lex->with_sum_func || select_lex->group_list.elements) { |