From d8574dbba3c5b414c496ab9588733d5104eddf1e Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Fri, 1 Sep 2023 19:26:24 +0700 Subject: [PATCH] MDEV-14959: Moved calculation the number of items reserved for exists to in transformation It is done now before call of select_lex->setup_ref_array() in order to avoid allocation of SP/PS's memory on its second invocation. --- sql/sql_select.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5955cbef8dd..805ba19f0bc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -727,8 +727,7 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array, ORDER *group, List &win_specs, List &win_funcs, - bool *hidden_group_fields, - uint *reserved) + bool *hidden_group_fields) { int res; enum_parsing_place save_place; @@ -743,13 +742,6 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array, thd->lex->allow_sum_func.clear_bit(select->nest_level); res= setup_conds(thd, tables, leaves, conds); - if (thd->lex->current_select->first_cond_optimization) - { - if (!res && *conds && ! thd->lex->current_select->merged_into) - (*reserved)= (*conds)->exists2in_reserved_items(); - else - (*reserved)= 0; - } /* it's not wrong to have non-aggregated columns in a WHERE */ select->set_non_agg_field_used(saved_non_agg_field_used); @@ -1318,6 +1310,15 @@ JOIN::prepare(TABLE_LIST *tables_init, if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num, &select_lex->hidden_bit_fields)) DBUG_RETURN(-1); + + if (thd->lex->current_select->first_cond_optimization) + { + if ( conds && ! thd->lex->current_select->merged_into) + select_lex->select_n_reserved= conds->exists2in_reserved_items(); + else + select_lex->select_n_reserved= 0; + } + if (select_lex->setup_ref_array(thd, real_og_num)) DBUG_RETURN(-1); @@ -1336,8 +1337,7 @@ JOIN::prepare(TABLE_LIST *tables_init, all_fields, &conds, order, group_list, select_lex->window_specs, select_lex->window_funcs, - &hidden_group_fields, - &select_lex->select_n_reserved)) + &hidden_group_fields)) DBUG_RETURN(-1); /*