summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2022-08-03 19:51:44 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2022-08-03 19:51:44 +0200
commite509065247b1a0cda0bc7863ac1d43d0fab9acc8 (patch)
tree0a89b1350bbf06177b63c92111e769a71a4b84c0 /sql/sql_select.cc
parent8fd8a81a9933e6a5b8afe2e7a2655652bd7c7190 (diff)
parent37a3d4467e3115f4d4dfcad0a6ee3c23e785f524 (diff)
downloadmariadb-git-e509065247b1a0cda0bc7863ac1d43d0fab9acc8.tar.gz
Merge branch '10.3' into 10.4
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 6509f25a41f..a91b4571b21 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1871,6 +1871,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
set_allowed_join_cache_types();
need_distinct= TRUE;
@@ -3104,6 +3107,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())
@@ -3416,6 +3422,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())
@@ -3544,6 +3551,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;
@@ -10426,6 +10434,23 @@ bool JOIN::get_best_combination()
if (aggr_tables > 2)
aggr_tables= 2;
+
+#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);