Commit 4a2e7b53 authored by Varun Gupta's avatar Varun Gupta

MDEV-22984: Throw an error when arguments to window functions are window functions

Window function is not allowed as arguments to window functions according to the standard.
parent 17109001
......@@ -3788,5 +3788,15 @@ row_number() OVER()
3
DROP TABLE t1;
#
# MDEV-22984: Throw an error when arguments to window functions are window functions
#
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
SELECT NTILE(MAX(a) OVER (PARTITION BY a)) OVER (PARTITION BY a ORDER BY b) FROM t1;
ERROR HY000: Window functions can not be used as arguments to group functions.
SELECT FIRST_VALUE(MAX(a) OVER (PARTITION BY a)) OVER (ORDER BY a) AS x FROM t1 GROUP BY a;
ERROR HY000: Window functions can not be used as arguments to group functions.
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -2459,6 +2459,19 @@ ANALYZE FORMAT=JSON SELECT row_number() OVER() FROM t1;
SELECT row_number() OVER() FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-22984: Throw an error when arguments to window functions are window functions
--echo #
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
--error ER_SUM_FUNC_WITH_WINDOW_FUNC_AS_ARG
SELECT NTILE(MAX(a) OVER (PARTITION BY a)) OVER (PARTITION BY a ORDER BY b) FROM t1;
--error ER_SUM_FUNC_WITH_WINDOW_FUNC_AS_ARG
SELECT FIRST_VALUE(MAX(a) OVER (PARTITION BY a)) OVER (ORDER BY a) AS x FROM t1 GROUP BY a;
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -237,6 +237,7 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref)
if ((!item->fixed && item->fix_fields(thd, args)) ||
(item= args[i])->check_cols(1))
return TRUE;
with_window_func|= item->with_window_func;
}
Type_std_attributes::set(args[0]);
for (uint i= 0; i < arg_count && !with_subselect; i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment