summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-06-30 18:16:01 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-06-30 18:16:01 +0530
commit4a2e7b5368b2c78c5965b74727727053c67b406d (patch)
tree07819d050921640f8bec1d82f973f1ef3d9ac66c
parent17109001d6db712187ff2ccb43f6c18b01458318 (diff)
downloadmariadb-git-4a2e7b5368b2c78c5965b74727727053c67b406d.tar.gz
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.
-rw-r--r--mysql-test/r/win.result10
-rw-r--r--mysql-test/t/win.test13
-rw-r--r--sql/item_windowfunc.cc1
3 files changed, 24 insertions, 0 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index c73f9f8ce6b..9c85315b7c1 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -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
#
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index 37c107633d9..d19ff2c624d 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -2460,5 +2460,18 @@ 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 #
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index 7cb07af440b..a3edacd880e 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -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++)