diff options
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e21beace4f5..3b0061fcf8e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2023,6 +2023,9 @@ JOIN::optimize_inner() DEBUG_SYNC(thd, "before_join_optimize"); THD_STAGE_INFO(thd, stage_optimizing); +#ifndef DBUG_OFF + dbug_join_tab_array_size= 0; +#endif // rownum used somewhere in query, no limits and it is derived if (unlikely(thd->lex->with_rownum && @@ -3316,6 +3319,9 @@ setup_subq_exit: { if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) DBUG_RETURN(1); +#ifndef DBUG_OFF + dbug_join_tab_array_size= 1; +#endif need_tmp= 1; } if (make_aggr_tables_info()) @@ -3629,6 +3635,7 @@ bool JOIN::make_aggr_tables_info() { aggr_tables++; curr_tab= join_tab + exec_join_tab_cnt(); + DBUG_ASSERT(curr_tab - join_tab < dbug_join_tab_array_size); bzero((void*)curr_tab, sizeof(JOIN_TAB)); curr_tab->ref.key= -1; if (only_const_tables()) @@ -3757,6 +3764,7 @@ bool JOIN::make_aggr_tables_info() curr_tab++; aggr_tables++; + DBUG_ASSERT(curr_tab - join_tab < dbug_join_tab_array_size); bzero((void*)curr_tab, sizeof(JOIN_TAB)); curr_tab->ref.key= -1; @@ -10909,6 +10917,21 @@ bool JOIN::get_best_combination() fix_semijoin_strategies_for_picked_join_order(this); top_join_tab_count= get_number_of_tables_at_top_level(this); +#ifndef DBUG_OFF + dbug_join_tab_array_size= top_join_tab_count + aggr_tables; +#endif + /* + NOTE: The above computation of aggr_tables can produce wrong result because some + of the variables it uses may change their values after we leave this function. + Known examples: + - Dangerous: using_outer_summary_function=false at this point. Added + DBUG_ASSERT below to demonstrate. Can this cause us to allocate less + space than we would need? + - Not dangerous: select_distinct can be true here but be assigned false + afterwards. + */ + aggr_tables= 2; + DBUG_ASSERT(!tmp_table_param.using_outer_summary_function); if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)* (top_join_tab_count + aggr_tables)))) DBUG_RETURN(TRUE); |