mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-14791: Crash with order by expression containing window functions
The issue here is that for a window function in the ORDER BY clause, we were not creating an extra field in the temporary table for the window function (which is contained in an expression). So a call to split_sum_func is added to handle this case Also we need to update all items that contain a window function in the temp table during window function computation as filesort would need these values to be updated to calculate the ORDER BY clause of the select.
This commit is contained in:
@ -933,8 +933,9 @@ JOIN::prepare(TABLE_LIST *tables_init,
|
||||
item->max_length)))
|
||||
real_order= TRUE;
|
||||
|
||||
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
|
||||
item->split_sum_func(thd, ref_ptrs, all_fields, 0);
|
||||
if ((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
item->with_window_func)
|
||||
item->split_sum_func(thd, ref_ptrs, all_fields, SPLIT_SUM_SELECT);
|
||||
}
|
||||
if (!real_order)
|
||||
order= NULL;
|
||||
@ -26714,27 +26715,6 @@ AGGR_OP::end_send()
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
In case we have window functions present, an extra step is required
|
||||
to compute all the fields from the temporary table.
|
||||
In case we have a compound expression such as: expr + expr,
|
||||
where one of the terms has a window function inside it, only
|
||||
after computing window function values we actually know the true
|
||||
final result of the compounded expression.
|
||||
|
||||
Go through all the func items and save their values once again in the
|
||||
corresponding temp table fields. Do this for each row in the table.
|
||||
*/
|
||||
if (join_tab->window_funcs_step)
|
||||
{
|
||||
Item **func_ptr= join_tab->tmp_table_param->items_to_copy;
|
||||
Item *func;
|
||||
for (; (func = *func_ptr) ; func_ptr++)
|
||||
{
|
||||
if (func->with_window_func)
|
||||
func->save_in_result_field(true);
|
||||
}
|
||||
}
|
||||
rc= evaluate_join_record(join, join_tab, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user