1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

MDEV-10859: Wrong result of aggregate window function in query with HAVING and no ORDER BY

Window functions need to be computed after applying the HAVING clause.
An optimization that we have for regular, non-window function, cases is
to apply having only during sending of the rows to the client. This
allows rows that should be filtered from the temporary table used to
store aggregation results to be stored there.

This behaviour is undesireable for window functions, as we have to
compute window functions on the result-set after HAVING is applied.
Storing extra rows in the table leads to wrong values as the frame
bounds might capture those -to be filtered afterwards- rows.
This commit is contained in:
Vicențiu Ciorbaru
2017-02-14 14:02:29 +02:00
parent a90066b1c7
commit 9fe9fb68ac
4 changed files with 70 additions and 3 deletions

View File

@@ -2840,6 +2840,12 @@ bool Window_funcs_computation::setup(THD *thd,
order_window_funcs_by_window_specs(window_funcs);
SQL_SELECT *sel= NULL;
/*
If the tmp table is filtered during sorting
(ex: SELECT with HAVING && ORDER BY), we must make sure to keep the
filtering conditions when we perform sorting for window function
computation.
*/
if (tab->filesort && tab->filesort->select)
{
sel= tab->filesort->select;