Commit 9073f9fd authored by Igor Babaev's avatar Igor Babaev

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.
parent 81c1abe8
...@@ -2398,3 +2398,37 @@ SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 ); ...@@ -2398,3 +2398,37 @@ SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 );
i i
1 1
DROP TABLE t1, t2; 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;
...@@ -1442,3 +1442,24 @@ SELECT COUNT(*) OVER (PARTITION BY c) FROM t2; ...@@ -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 ); SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 );
DROP TABLE t1, 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;
...@@ -517,8 +517,8 @@ static SYMBOL symbols[] = { ...@@ -517,8 +517,8 @@ static SYMBOL symbols[] = {
{ "ROLLUP", SYM(ROLLUP_SYM)}, { "ROLLUP", SYM(ROLLUP_SYM)},
{ "ROUTINE", SYM(ROUTINE_SYM)}, { "ROUTINE", SYM(ROUTINE_SYM)},
{ "ROW", SYM(ROW_SYM)}, { "ROW", SYM(ROW_SYM)},
{ "ROW_COUNT", SYM(ROW_COUNT_SYM)},
{ "ROWS", SYM(ROWS_SYM)}, { "ROWS", SYM(ROWS_SYM)},
{ "ROW_COUNT", SYM(ROW_COUNT_SYM)},
{ "ROW_FORMAT", SYM(ROW_FORMAT_SYM)}, { "ROW_FORMAT", SYM(ROW_FORMAT_SYM)},
{ "RTREE", SYM(RTREE_SYM)}, { "RTREE", SYM(RTREE_SYM)},
{ "SAVEPOINT", SYM(SAVEPOINT_SYM)}, { "SAVEPOINT", SYM(SAVEPOINT_SYM)},
......
...@@ -1021,10 +1021,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); ...@@ -1021,10 +1021,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%parse-param { THD *thd } %parse-param { THD *thd }
%lex-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. We should not introduce new conflicts any more.
*/ */
%expect 103 %expect 102
/* /*
Comments for TOKENS. Comments for TOKENS.
...@@ -1535,10 +1535,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); ...@@ -1535,10 +1535,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token ROLLBACK_SYM /* SQL-2003-R */ %token ROLLBACK_SYM /* SQL-2003-R */
%token ROLLUP_SYM /* SQL-2003-R */ %token ROLLUP_SYM /* SQL-2003-R */
%token ROUTINE_SYM /* SQL-2003-N */ %token ROUTINE_SYM /* SQL-2003-N */
%token ROWS_SYM /* SQL-2003-R */
%token ROW_FORMAT_SYM
%token ROW_SYM /* SQL-2003-R */ %token ROW_SYM /* SQL-2003-R */
%token ROWS_SYM /* SQL-2003-R */
%token ROW_COUNT_SYM /* SQL-2003-N */ %token ROW_COUNT_SYM /* SQL-2003-N */
%token ROW_FORMAT_SYM
%token ROW_NUMBER_SYM %token ROW_NUMBER_SYM
%token RTREE_SYM %token RTREE_SYM
%token SAVEPOINT_SYM /* SQL-2003-R */ %token SAVEPOINT_SYM /* SQL-2003-R */
...@@ -14835,7 +14835,6 @@ keyword_sp: ...@@ -14835,7 +14835,6 @@ keyword_sp:
| ROLE_SYM {} | ROLE_SYM {}
| ROLLUP_SYM {} | ROLLUP_SYM {}
| ROUTINE_SYM {} | ROUTINE_SYM {}
| ROWS_SYM {}
| ROW_COUNT_SYM {} | ROW_COUNT_SYM {}
| ROW_FORMAT_SYM {} | ROW_FORMAT_SYM {}
| ROW_SYM {} | ROW_SYM {}
......
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