Skip to content
Permalink
Browse files
MDEV-15204: lag/lead function order list mandatory
  • Loading branch information
zhzhzoo authored and cvicentiu committed Aug 25, 2018
1 parent c826b6b commit 2a361eb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
@@ -3219,8 +3219,8 @@ DROP TABLE fv_test, fv_result;
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0),(1),(2);
SELECT LEAD(a) OVER (PARTITION BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a) AS a_and_lead_part
SELECT LEAD(a) OVER (PARTITION BY a ORDER BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a ORDER BY a) AS a_and_lead_part
FROM t1;
lead a_and_lead_part
NULL 0
@@ -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
10 2 0 2 14
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;
@@ -2000,8 +2000,8 @@ DROP TABLE fv_test, fv_result;

CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0),(1),(2);
SELECT LEAD(a) OVER (PARTITION BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a) AS a_and_lead_part
SELECT LEAD(a) OVER (PARTITION BY a ORDER BY a) as lead,
a AND LEAD(a) OVER (PARTITION BY a ORDER BY a) AS a_and_lead_part
FROM t1;

SELECT a OR LEAD(a) OVER (ORDER BY a) AS a_or_lead_order
@@ -107,4 +107,17 @@ select pk, a, b, a+b,
from t1
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;
@@ -792,6 +792,8 @@ class Item_window_func : public Item_func_or_sum
case Item_sum::DENSE_RANK_FUNC:
case Item_sum::PERCENT_RANK_FUNC:
case Item_sum::CUME_DIST_FUNC:
case Item_sum::LAG_FUNC:
case Item_sum::LEAD_FUNC:
return true;
default:
return false;

0 comments on commit 2a361eb

Please sign in to comment.