1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-10815: Window Function Expressions Wrong Results

Fix window function expressions such as win_func() <operator> expr.
The problem was found in 2 places.
First, when we have complex expressions containing window functions, we
can only compute their final value _after_ we have computed the window
function's values. These values must be stored within the temporary
table that we are using, before sending them off.
This is done by performing an extra copy_funcs call before the final
end_send() call.

Second, such expressions need to have their inner arguments,
changed such that the references within those arguments point to fields within
the temporary table.
Ex: sum(t.a) over (order by t.b) + sum(t.a) over (order by t.b)
Before this fix, t.a pointed to the original table's a field. In order
to compute the sum function's value correctly, it needs to point to the
copy of this field inside the temp table.
This is done by calling split_sum_func for each argument in the
expression in turn.

The win.test results have also been updated as they contained wrong
values for such a use case.
This commit is contained in:
Vicențiu Ciorbaru
2016-09-16 20:38:22 +02:00
parent 1c72441364
commit 2857ff3c98
5 changed files with 78 additions and 12 deletions

View File

@ -26228,7 +26228,22 @@ AGGR_OP::end_send()
rc= NESTED_LOOP_KILLED;
}
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)
copy_funcs(join_tab->tmp_table_param->items_to_copy, join->thd);
rc= evaluate_join_record(join, join_tab, 0);
}
}
// Finish rnd scn after sending records