diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2022-08-08 17:15:13 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2022-08-08 17:15:13 +0200 |
commit | 50b270525a5d2626c81425890e74d906f5515e89 (patch) | |
tree | 3500af31b2674edd9f9d621f8549b6911ab7cdec /sql/sql_select.cc | |
parent | 9cbf8ccf2990f9db8d9debee42bc9213cbb04457 (diff) | |
parent | 1d480419822b53c840de54542c1d1a0851dbe2c8 (diff) | |
download | mariadb-git-50b270525a5d2626c81425890e74d906f5515e89.tar.gz |
Merge branch '10.7' into 10.8
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 48f75f89dd1..9bd6aa4d5d3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1996,6 +1996,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 && @@ -3289,6 +3292,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()) @@ -3602,6 +3608,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()) @@ -3730,6 +3737,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; @@ -10882,6 +10890,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); |