diff options
author | Igor Babaev <igor@askmonty.org> | 2017-01-31 10:32:59 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2017-01-31 20:37:26 -0800 |
commit | 9073f9fd7da80752c4fcb7c6bed1d51b4853d3ce (patch) | |
tree | e25dc3164f756f3482e8b1f139c79eb6c1708706 | |
parent | 81c1abe8cf3dda1fe097256a06daab3041409e14 (diff) | |
download | mariadb-git-9073f9fd7da80752c4fcb7c6bed1d51b4853d3ce.tar.gz |
Fixed bug mdev-9976.
This bug happens due to a conflict in the construct window_spec.
(win_ref conflicts with the non-reserved key word ROWS).
The standard SQL-2003 says that ROWS is a reserved key word.
Made this key word reserved in our grammar and removed
the conflict.
-rw-r--r-- | mysql-test/r/win.result | 34 | ||||
-rw-r--r-- | mysql-test/t/win.test | 21 | ||||
-rw-r--r-- | sql/lex.h | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 9 |
4 files changed, 60 insertions, 6 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 1c46f43a22c..0a003b0fe28 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -2398,3 +2398,37 @@ SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 ); i 1 DROP TABLE t1, t2; +# +# MDEV-9976: window function without PARTITION BY and ORDER BY +# +CREATE TABLE t1 (id int, a int); +INSERT INTO t1 VALUES +(1,1000), (2,1100), (3,1800), (4,1500), (5,1700), (6,1200), +(7,2000), (8,2100), (9,1600); +SELECT id, sum(a) OVER (PARTITION BY id +ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +FROM t1; +id sum(a) OVER (PARTITION BY id +1 1000 +2 1100 +3 1800 +4 1500 +5 1700 +6 1200 +7 2000 +8 2100 +9 1600 +ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +SELECT id, sum(a) OVER (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +FROM t1; +id sum(a) OVER (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +1 14000 +2 13000 +3 5900 +4 10700 +5 7600 +6 11900 +7 4100 +8 2100 +9 9200 +DROP TABLE t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index b9490c82039..00fbec7d88d 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -1442,3 +1442,24 @@ SELECT COUNT(*) OVER (PARTITION BY c) FROM t2; SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 ); DROP TABLE t1, t2; + +--echo # +--echo # MDEV-9976: window function without PARTITION BY and ORDER BY +--echo # + +CREATE TABLE t1 (id int, a int); +INSERT INTO t1 VALUES + (1,1000), (2,1100), (3,1800), (4,1500), (5,1700), (6,1200), + (7,2000), (8,2100), (9,1600); + +--sorted_result +SELECT id, sum(a) OVER (PARTITION BY id + ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +FROM t1; + +--sorted_result +SELECT id, sum(a) OVER (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +FROM t1; + +DROP TABLE t1; + diff --git a/sql/lex.h b/sql/lex.h index c40aa8f546d..baeae088234 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -517,8 +517,8 @@ static SYMBOL symbols[] = { { "ROLLUP", SYM(ROLLUP_SYM)}, { "ROUTINE", SYM(ROUTINE_SYM)}, { "ROW", SYM(ROW_SYM)}, - { "ROW_COUNT", SYM(ROW_COUNT_SYM)}, { "ROWS", SYM(ROWS_SYM)}, + { "ROW_COUNT", SYM(ROW_COUNT_SYM)}, { "ROW_FORMAT", SYM(ROW_FORMAT_SYM)}, { "RTREE", SYM(RTREE_SYM)}, { "SAVEPOINT", SYM(SAVEPOINT_SYM)}, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 74a61425141..0cd2c563319 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1021,10 +1021,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 103 shift/reduce conflicts. + Currently there are 102 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 103 +%expect 102 /* Comments for TOKENS. @@ -1535,10 +1535,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token ROLLBACK_SYM /* SQL-2003-R */ %token ROLLUP_SYM /* SQL-2003-R */ %token ROUTINE_SYM /* SQL-2003-N */ -%token ROWS_SYM /* SQL-2003-R */ -%token ROW_FORMAT_SYM %token ROW_SYM /* SQL-2003-R */ +%token ROWS_SYM /* SQL-2003-R */ %token ROW_COUNT_SYM /* SQL-2003-N */ +%token ROW_FORMAT_SYM %token ROW_NUMBER_SYM %token RTREE_SYM %token SAVEPOINT_SYM /* SQL-2003-R */ @@ -14835,7 +14835,6 @@ keyword_sp: | ROLE_SYM {} | ROLLUP_SYM {} | ROUTINE_SYM {} - | ROWS_SYM {} | ROW_COUNT_SYM {} | ROW_FORMAT_SYM {} | ROW_SYM {} |