• Sergei Petrunia's avatar
    MDEV-23809: Server crash in JOIN_CACHE::free or ... · 2cd98c95
    Sergei Petrunia authored
    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.
    2cd98c95
func_group.test 52.1 KB