From c917ba1d5108ab90f861d4cd099feb515e54844d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 9 Jun 2017 14:23:45 +0200 Subject: [PATCH] fix the comparison in st_select_lex::setup_ref_array() the array only needs to be reallocated if it's smaller than needed. Being larger is ok. also: remove a duplicated check (merge error) --- sql/item.cc | 3 +-- sql/item_subselect.cc | 5 ++--- sql/sql_lex.cc | 12 +----------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 30778132afc..df1f66fde28 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -494,8 +494,7 @@ Item::Item(THD *thd): { enum_parsing_place place= thd->lex->current_select->parsing_place; - if (place == SELECT_LIST || - place == IN_HAVING) + if (place == SELECT_LIST || place == IN_HAVING) thd->lex->current_select->select_n_having_items++; } } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 3c967b6f7e5..4713129c49e 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -116,9 +116,8 @@ void Item_subselect::init(st_select_lex *select_lex, do not take into account expression inside aggregate functions because they can access original table fields */ - parsing_place= (outer_select->in_sum_expr ? - NO_MATTER : - outer_select->parsing_place); + parsing_place= (outer_select->in_sum_expr ? NO_MATTER + : outer_select->parsing_place); if (unit->is_union()) engine= new subselect_union_engine(unit, result, this); else diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9584f2aba36..21d7637ec06 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2665,16 +2665,6 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) order_group_num) * 5; if (!ref_pointer_array.is_null()) { - /* - We need to take 'n_sum_items' into account when allocating the array, - and this may actually increase during the optimization phase due to - MIN/MAX rewrite in Item_in_subselect::single_value_transformer. - In the usual case we can reuse the array from the prepare phase. - If we need a bigger array, we must allocate a new one. - */ - if (ref_pointer_array.size() == n_elems) - return false; - /* We need to take 'n_sum_items' into account when allocating the array, and this may actually increase during the optimization phase due to @@ -2682,7 +2672,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) In the usual case we can reuse the array from the prepare phase. If we need a bigger array, we must allocate a new one. */ - if (ref_pointer_array.size() == n_elems) + if (ref_pointer_array.size() >= n_elems) return false; } Item **array= static_cast(arena->alloc(sizeof(Item*) * n_elems));