diff options
| author | Sergei Petrunia <sergey@mariadb.com> | 2022-08-03 16:07:16 +0300 |
|---|---|---|
| committer | Sergei Petrunia <sergey@mariadb.com> | 2022-08-03 19:40:02 +0300 |
| commit | 2cd98c95dee7ae77e6280b4e047a2ebec00b5442 (patch) | |
| tree | 0506fbc5986f2d075e914673f5e23f7b87393901 /sql/sql_select.cc | |
| parent | f9ec9b6abbce8c88b0cfd1888135b9701415162a (diff) | |
| download | mariadb-git-2cd98c95dee7ae77e6280b4e047a2ebec00b5442.tar.gz | |
MDEV-23809: Server crash in JOIN_CACHE::free or ...
The problem was caused by use of COLLATION(AVG('x')). This is an
item whose value is a constant.
Name Resolution code called convert_const_to_int() which removed AVG('x').
However, the item representing COLLATION(...) still had with_sum_func=1.
This inconsistent state confused the code that handles grouping and
DISTINCT: JOIN::get_best_combination() decided to use one temporary
table and allocated one JOIN_TAB for it, but then
JOIN::make_aggr_tables_info() attempted to use two and made writes
beyond the end of the JOIN::join_tab array.
The fix:
- Do not replace constant expressions which contain aggregate functions.
- Add JOIN::dbug_join_tab_array_size to catch attempts to use more
JOIN_TAB objects than we've allocated.
Diffstat (limited to 'sql/sql_select.cc')
| -rw-r--r-- | sql/sql_select.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 33fb19966b2..a865c75184f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1596,6 +1596,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; @@ -2740,6 +2743,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()) @@ -3044,6 +3050,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()) @@ -3172,6 +3179,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; @@ -9781,6 +9789,10 @@ bool JOIN::get_best_combination() fix_semijoin_strategies_for_picked_join_order(this); +#ifndef DBUG_OFF + dbug_join_tab_array_size= top_join_tab_count + aggr_tables; +#endif + if (inject_splitting_cond_for_all_tables_with_split_opt()) DBUG_RETURN(TRUE); |
