Skip to content

Commit 37a3d44

Browse files
committed
MDEV-23809: Server crash in JOIN_CACHE::free ...: part #2
Part #2: make sure we allocate space for two JOIN_TABs that use temporary tables. The dbug_join_tab_array_size is still set to catch cases where we try to access more JOIN_TAB object than we thought we would have.
1 parent 2cd98c9 commit 37a3d44

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

sql/sql_select.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9780,6 +9780,23 @@ bool JOIN::get_best_combination()
97809780

97819781
if (aggr_tables > 2)
97829782
aggr_tables= 2;
9783+
9784+
#ifndef DBUG_OFF
9785+
dbug_join_tab_array_size= top_join_tab_count + aggr_tables;
9786+
#endif
9787+
/*
9788+
NOTE: The above computation of aggr_tables can produce wrong result because some
9789+
of the variables it uses may change their values after we leave this function.
9790+
Known examples:
9791+
- Dangerous: using_outer_summary_function=false at this point. Added
9792+
DBUG_ASSERT below to demonstrate. Can this cause us to allocate less
9793+
space than we would need?
9794+
- Not dangerous: select_distinct can be true here but be assigned false
9795+
afterwards.
9796+
*/
9797+
aggr_tables= 2;
9798+
DBUG_ASSERT(!tmp_table_param.using_outer_summary_function);
9799+
97839800
if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*
97849801
(top_join_tab_count + aggr_tables))))
97859802
DBUG_RETURN(TRUE);
@@ -9789,10 +9806,6 @@ bool JOIN::get_best_combination()
97899806

97909807
fix_semijoin_strategies_for_picked_join_order(this);
97919808

9792-
#ifndef DBUG_OFF
9793-
dbug_join_tab_array_size= top_join_tab_count + aggr_tables;
9794-
#endif
9795-
97969809
if (inject_splitting_cond_for_all_tables_with_split_opt())
97979810
DBUG_RETURN(TRUE);
97989811

0 commit comments

Comments
 (0)