Skip to content

Commit 023c789

Browse files
committed
MDEV-15818 Fix shift-reduce conflicts in the new 10.3 syntax
Fixing shift/reduce conflicts introduced by the new system versioning syntax. Additionally, fixing old shift/reduce conflicts: In PREVIOUS/NEXT being identifiers or sequence operations: SELECT PREVIOUS FROM t1; SELECT PREVIOUS VALUE FOR t1; In TIME/DATE/TIMESTAMP being literals, functions or identifiers: SELECT TIMESTAMP'2001-01-01 10:20:30' FROM t1; SELECT TIMESTAMP('2001-01-01 10:20:30') FROM t1; SELECT TIMESTAMP FROM t1;
1 parent f38d8c1 commit 023c789

File tree

2 files changed

+129
-17
lines changed

2 files changed

+129
-17
lines changed

sql/sql_yacc.yy

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
892892
%parse-param { THD *thd }
893893
%lex-param { THD *thd }
894894
/*
895-
Currently there are 122 shift/reduce conflicts.
895+
Currently there are 99 shift/reduce conflicts.
896896
We should not introduce new conflicts any more.
897897
*/
898-
%expect 122
898+
%expect 99
899899

900900
/*
901901
Comments for TOKENS.
@@ -1671,6 +1671,93 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
16711671
%left NEG '~' NOT2_SYM BINARY
16721672
%left COLLATE_SYM
16731673

1674+
/*
1675+
Tokens that can change their meaning from identifier to something else
1676+
in certain context.
1677+
1678+
- TRANSACTION: identifier, history unit:
1679+
SELECT transaction FROM t1;
1680+
SELECT * FROM t1 FOR SYSTEM_TIME AS OF TRANSACTION @var;
1681+
1682+
- TIMESTAMP: identifier, literal, history unit:
1683+
SELECT timestamp FROM t1;
1684+
SELECT TIMESTAMP '2001-01-01 10:20:30';
1685+
SELECT * FROM t1 FOR SYSTEM_TIME AS OF TIMESTAMP CONCAT(@date,' ',@time);
1686+
1687+
- PERIOD: identifier, period for sytem time:
1688+
SELECT period FROM t1;
1689+
ALTER TABLE DROP PERIOD FOR SYSTEM TIME;
1690+
1691+
- SYSTEM: identifier, system versioning:
1692+
SELECT system FROM t1;
1693+
ALTER TABLE DROP SYSTEM VERSIONIONG;
1694+
1695+
Note, we need here only tokens that cause shirt/reduce conflicts
1696+
with keyword identifiers. For example:
1697+
opt_clause1: %empty | KEYWORD ... ;
1698+
clause2: opt_clause1 ident;
1699+
KEYWORD can appear both in opt_clause1 and in "ident" through the "keyword"
1700+
rule. So the parser reports a conflict on how to interpret KEYWORD:
1701+
- as a start of non-empty branch in opt_clause1, or
1702+
- as an identifier which follows the empty branch in opt_clause1.
1703+
1704+
Example#1:
1705+
alter_list_item:
1706+
DROP opt_column opt_if_exists_table_element field_ident
1707+
| DROP SYSTEM VERSIONING_SYM
1708+
SYSTEM can be a keyword in field_ident, or can be a start of
1709+
SYSTEM VERSIONING.
1710+
1711+
Example#2:
1712+
system_time_expr: AS OF_SYM history_point
1713+
history_point: opt_history_unit bit_expr
1714+
opt_history_unit: | TRANSACTION_SYM
1715+
TRANSACTION can be a non-empty history unit, or can be an identifier
1716+
in bit_expr.
1717+
1718+
In the grammar below we use %prec to explicitely tell Bison to go
1719+
through the empty branch in the optional rule only when the lookahead
1720+
token does not belong to a small set of selected tokens.
1721+
1722+
Tokens NEXT_SYM and PREVIOUS_SYM also change their meaning from
1723+
identifiers to sequence operations when followed by VALUE_SYM:
1724+
SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1725+
but we don't need to list them here as they do not seem to cause
1726+
conflicts (according to bison -v), as both meanings
1727+
(as identifier, and as a sequence operation) are parts of the same target
1728+
column_default_non_parenthesized_expr, and there are no any optional
1729+
clauses between the start of column_default_non_parenthesized_expr
1730+
and until NEXT_SYM / PREVIOUS_SYM.
1731+
*/
1732+
%left PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
1733+
%left TRANSACTION_SYM TIMESTAMP PERIOD SYSTEM
1734+
1735+
1736+
/*
1737+
Tokens that can appear in a token contraction on the second place
1738+
and change the meaning of the previous token.
1739+
1740+
- TEXT_STRING: changes the meaning of TIMESTAMP/TIME/DATE
1741+
from identifier to literal:
1742+
SELECT timestamp FROM t1;
1743+
SELECT TIMESTAMP'2001-01-01 00:00:00' FROM t1;
1744+
1745+
- Parenthesis: changes the meaning of TIMESTAMP/TIME/DATE
1746+
from identifiers to CAST-alike functions:
1747+
SELECT timestamp FROM t1;
1748+
SELECT timestamp(1) FROM t1;
1749+
1750+
- VALUE: changes NEXT and PREVIOUS from identifier to sequence operation:
1751+
SELECT next, previous FROM t1;
1752+
SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1753+
1754+
- VERSIONING: changes SYSTEM from identifier to SYSTEM VERSIONING
1755+
SELECT system FROM t1;
1756+
ALTER TABLE t1 ADD SYSTEM VERSIONING;
1757+
*/
1758+
%left PREC_BELOW_CONTRACTION_TOKEN2
1759+
%left TEXT_STRING '(' VALUE_SYM VERSIONING_SYM
1760+
16741761
%type <lex_str>
16751762
DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
16761763
HEX_NUM HEX_STRING
@@ -8355,7 +8442,7 @@ alter_lock_option:
83558442
;
83568443

83578444
opt_column:
8358-
/* empty */ {}
8445+
/* empty */ {} %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
83598446
| COLUMN_SYM {}
83608447
;
83618448

@@ -9239,7 +9326,7 @@ select_options:
92399326
;
92409327

92419328
opt_history_unit:
9242-
/* empty*/
9329+
/* empty*/ %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
92439330
{
92449331
$$= VERS_UNDEFINED;
92459332
}
@@ -15440,7 +15527,7 @@ keyword_sp_data_type:
1544015527
| BOOLEAN_SYM
1544115528
| BOOL_SYM
1544215529
| CLOB
15443-
| DATE_SYM
15530+
| DATE_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1544415531
| DATETIME
1544515532
| ENUM
1544615533
| FIXED_SYM
@@ -15462,8 +15549,8 @@ keyword_sp_data_type:
1546215549
| ROW_SYM
1546315550
| SERIAL_SYM
1546415551
| TEXT_SYM
15465-
| TIMESTAMP
15466-
| TIME_SYM
15552+
| TIMESTAMP %prec PREC_BELOW_CONTRACTION_TOKEN2
15553+
| TIME_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1546715554
| VARCHAR2
1546815555
| YEAR_SYM
1546915556
;
@@ -15646,7 +15733,7 @@ keyword_sp_not_data_type:
1564615733
| MYSQL_ERRNO_SYM
1564715734
| NAME_SYM
1564815735
| NAMES_SYM
15649-
| NEXT_SYM
15736+
| NEXT_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1565015737
| NEXTVAL_SYM
1565115738
| NEW_SYM
1565215739
| NOCACHE_SYM
@@ -15677,7 +15764,7 @@ keyword_sp_not_data_type:
1567715764
| PLUGINS_SYM
1567815765
| PRESERVE_SYM
1567915766
| PREV_SYM
15680-
| PREVIOUS_SYM
15767+
| PREVIOUS_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1568115768
| PRIVILEGES
1568215769
| PROCESS
1568315770
| PROCESSLIST_SYM
@@ -15760,7 +15847,7 @@ keyword_sp_not_data_type:
1576015847
| TEMPORARY
1576115848
| TEMPTABLE_SYM
1576215849
| THAN_SYM
15763-
| TRANSACTION_SYM
15850+
| TRANSACTION_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1576415851
| TRANSACTIONAL_SYM
1576515852
| TRIGGERS_SYM
1576615853
| TRIM_ORACLE

sql/sql_yacc_ora.yy

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
278278
%parse-param { THD *thd }
279279
%lex-param { THD *thd }
280280
/*
281-
Currently there are 99 shift/reduce conflicts.
281+
Currently there are 94 shift/reduce conflicts.
282282
We should not introduce new conflicts any more.
283283
*/
284-
%expect 99
284+
%expect 94
285285

286286
/*
287287
Comments for TOKENS.
@@ -1057,6 +1057,31 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
10571057
%left NEG '~' NOT2_SYM BINARY
10581058
%left COLLATE_SYM
10591059

1060+
/*
1061+
Tokens that can appear in a token contraction on the second place
1062+
and change the meaning of the previous token.
1063+
1064+
- TEXT_STRING: changes the meaning of TIMESTAMP/TIME/DATE
1065+
from identifier to literal:
1066+
SELECT timestamp FROM t1;
1067+
SELECT TIMESTAMP'2001-01-01 00:00:00' FROM t1;
1068+
1069+
- Parenthesis: changes the meaning of TIMESTAMP/TIME/DATE
1070+
from identifier to CAST:
1071+
SELECT timestamp FROM t1;
1072+
SELECT timestamp(1) FROM t1;
1073+
1074+
- VALUE: changes NEXT and PREVIOUS from identifier to sequence operation:
1075+
SELECT next, previous FROM t1;
1076+
SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1077+
1078+
- VERSIONING: changes SYSTEM from identifier to SYSTEM VERSIONING
1079+
SELECT system FROM t1;
1080+
ALTER TABLE t1 ADD SYSTEM VERSIONING;
1081+
*/
1082+
%left PREC_BELOW_CONTRACTION_TOKEN2
1083+
%left TEXT_STRING '(' VALUE_SYM
1084+
10601085
%type <lex_str>
10611086
DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
10621087
HEX_NUM HEX_STRING
@@ -15253,7 +15278,7 @@ keyword_sp_data_type:
1525315278
| BOOLEAN_SYM
1525415279
| BOOL_SYM
1525515280
| CLOB
15256-
| DATE_SYM
15281+
| DATE_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1525715282
| DATETIME
1525815283
| ENUM
1525915284
| FIXED_SYM
@@ -15275,8 +15300,8 @@ keyword_sp_data_type:
1527515300
| ROW_SYM
1527615301
| SERIAL_SYM
1527715302
| TEXT_SYM
15278-
| TIMESTAMP
15279-
| TIME_SYM
15303+
| TIMESTAMP %prec PREC_BELOW_CONTRACTION_TOKEN2
15304+
| TIME_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1528015305
| VARCHAR2
1528115306
| YEAR_SYM
1528215307
;
@@ -15455,7 +15480,7 @@ keyword_sp_not_data_type:
1545515480
| MYSQL_ERRNO_SYM
1545615481
| NAME_SYM
1545715482
| NAMES_SYM
15458-
| NEXT_SYM
15483+
| NEXT_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1545915484
| NEXTVAL_SYM
1546015485
| NEW_SYM
1546115486
| NOCACHE_SYM
@@ -15486,7 +15511,7 @@ keyword_sp_not_data_type:
1548615511
| PLUGINS_SYM
1548715512
| PRESERVE_SYM
1548815513
| PREV_SYM
15489-
| PREVIOUS_SYM
15514+
| PREVIOUS_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1549015515
| PRIVILEGES
1549115516
| PROCESS
1549215517
| PROCESSLIST_SYM

0 commit comments

Comments
 (0)