Commit 2a361ebe authored by zhzhzoo's avatar zhzhzoo Committed by Vicențiu Ciorbaru

MDEV-15204: lag/lead function order list mandatory

parent c826b6b8
...@@ -3219,8 +3219,8 @@ DROP TABLE fv_test, fv_result; ...@@ -3219,8 +3219,8 @@ DROP TABLE fv_test, fv_result;
# #
CREATE TABLE t1 (a int); CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0),(1),(2); INSERT INTO t1 VALUES (0),(1),(2);
SELECT LEAD(a) OVER (PARTITION BY a) as lead, SELECT LEAD(a) OVER (PARTITION BY a ORDER BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a) AS a_and_lead_part a AND LEAD(a) OVER (PARTITION BY a ORDER BY a) AS a_and_lead_part
FROM t1; FROM t1;
lead a_and_lead_part lead a_and_lead_part
NULL 0 NULL 0
......
...@@ -226,4 +226,15 @@ pk a b a+b lag(a + b) over (partition by a order by pk) + pk ...@@ -226,4 +226,15 @@ pk a b a+b lag(a + b) over (partition by a order by pk) + pk
9 2 2 4 12 9 2 2 4 12
10 2 0 2 14 10 2 0 2 14
11 2 10 12 13 11 2 10 12 13
#
# MDEV-15204 - LAG function doesn't require ORDER BY in OVER clause
#
select pk,
lag(pk, 1) over ()
from t1;
ERROR HY000: No order list in window specification for 'lag'
select pk,
lead(pk, 1) over ()
from t1;
ERROR HY000: No order list in window specification for 'lead'
drop table t1; drop table t1;
...@@ -2000,8 +2000,8 @@ DROP TABLE fv_test, fv_result; ...@@ -2000,8 +2000,8 @@ DROP TABLE fv_test, fv_result;
CREATE TABLE t1 (a int); CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0),(1),(2); INSERT INTO t1 VALUES (0),(1),(2);
SELECT LEAD(a) OVER (PARTITION BY a) as lead, SELECT LEAD(a) OVER (PARTITION BY a ORDER BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a) AS a_and_lead_part a AND LEAD(a) OVER (PARTITION BY a ORDER BY a) AS a_and_lead_part
FROM t1; FROM t1;
SELECT a OR LEAD(a) OVER (ORDER BY a) AS a_or_lead_order SELECT a OR LEAD(a) OVER (ORDER BY a) AS a_or_lead_order
......
...@@ -107,4 +107,17 @@ select pk, a, b, a+b, ...@@ -107,4 +107,17 @@ select pk, a, b, a+b,
from t1 from t1
order by pk asc; order by pk asc;
--echo #
--echo # MDEV-15204 - LAG function doesn't require ORDER BY in OVER clause
--echo #
--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC
select pk,
lag(pk, 1) over ()
from t1;
--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC
select pk,
lead(pk, 1) over ()
from t1;
drop table t1; drop table t1;
...@@ -792,6 +792,8 @@ class Item_window_func : public Item_func_or_sum ...@@ -792,6 +792,8 @@ class Item_window_func : public Item_func_or_sum
case Item_sum::DENSE_RANK_FUNC: case Item_sum::DENSE_RANK_FUNC:
case Item_sum::PERCENT_RANK_FUNC: case Item_sum::PERCENT_RANK_FUNC:
case Item_sum::CUME_DIST_FUNC: case Item_sum::CUME_DIST_FUNC:
case Item_sum::LAG_FUNC:
case Item_sum::LEAD_FUNC:
return true; return true;
default: default:
return false; return false;
......
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