diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-08-06 17:50:20 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-08-06 18:01:00 +0530 |
commit | caa474f8e3139b1d8d00be7bedf337af7fd304a3 (patch) | |
tree | ba34a9f8dfcdd7becb4b073a64797a96d6c61c64 | |
parent | 1e31d74833d56609f8711022394c1eb2eb25a19a (diff) | |
download | mariadb-git-caa474f8e3139b1d8d00be7bedf337af7fd304a3.tar.gz |
MDEV-15180: server crashed with NTH_VALUE()
fix_fields for the arguments of the NTH_VALUE function was updating the same reference,
so for the second argument (or after the first argument) the items were not resolved
to their corresponding field from the view as they were updating the reference to the
first argument.
-rw-r--r-- | mysql-test/r/win.result | 16 | ||||
-rw-r--r-- | mysql-test/t/win.test | 16 | ||||
-rw-r--r-- | sql/item_windowfunc.cc | 2 |
3 files changed, 33 insertions, 1 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 081aaedd323..3023a86eaad 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3850,5 +3850,21 @@ ERROR 42000: Too big scale 56 specified for 'rank() over w1'. Maximum is 38 SELECT cast((rank() over w1) as decimal (53,30)); ERROR HY000: Window specification with name 'w1' is not defined # +# MDEV-15180: server crashed with NTH_VALUE() +# +CREATE TABLE t1 (i1 int, a int); +INSERT INTO t1 VALUES (1, 1), (2, 2),(3, 3); +CREATE TABLE t2 (i2 int); +INSERT INTO t2 VALUES (1),(2),(5),(1),(7),(4),(3); +CREATE VIEW v1 AS (SELECT * FROM t1,t2 WHERE t1.i1=t2.i2) ; +SELECT NTH_VALUE(i1, i1) OVER (PARTITION BY i1) FROM v1; +NTH_VALUE(i1, i1) OVER (PARTITION BY i1) +1 +1 +NULL +NULL +DROP VIEW v1; +DROP TABLE t1,t2; +# # End of 10.2 tests # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index b749b235082..c7e3dac598b 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2507,5 +2507,21 @@ SELECT cast((rank() over w1) as decimal (53,56)); SELECT cast((rank() over w1) as decimal (53,30)); --echo # +--echo # MDEV-15180: server crashed with NTH_VALUE() +--echo # + +CREATE TABLE t1 (i1 int, a int); +INSERT INTO t1 VALUES (1, 1), (2, 2),(3, 3); + +CREATE TABLE t2 (i2 int); +INSERT INTO t2 VALUES (1),(2),(5),(1),(7),(4),(3); + +CREATE VIEW v1 AS (SELECT * FROM t1,t2 WHERE t1.i1=t2.i2) ; +SELECT NTH_VALUE(i1, i1) OVER (PARTITION BY i1) FROM v1; + +DROP VIEW v1; +DROP TABLE t1,t2; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 87dddbfb439..bb4a8a9f3af 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -234,7 +234,7 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) { Item *item= args[i]; // 'item' can be changed during fix_fields - if ((!item->fixed && item->fix_fields(thd, args)) || + if ((!item->fixed && item->fix_fields(thd, args + i)) || (item= args[i])->check_cols(1)) return TRUE; with_window_func|= item->with_window_func; |