-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTiDBParser.g4
3296 lines (2820 loc) · 90.6 KB
/
TiDBParser.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
parser grammar TiDBParser;
options {
tokenVocab = TiDBLexer;
exportMacro = PARSERS_PUBLIC_TYPE;
}
//-------------------------- TiDB grammar -------------------------------------------------------------------------
script: (query | SEMICOLON_SYMBOL)* EOF;
query: (simpleStatement | beginWork) SEMICOLON_SYMBOL;
simpleStatement:
// DDL
createStatement
| dropStatement;
createStatement: CREATE_SYMBOL ( createTable | createView);
dropStatement: DROP_SYMBOL ( dropView);
/* Don't support CREATE LIKE */
createTable:
temporaryOption? TABLE_SYMBOL ifNotExists? tableName (
(OPEN_PAR_SYMBOL tableElementList CLOSE_PAR_SYMBOL)? createTableOptions? partitionClause?
duplicateAsQueryExpression?
);
createView:
viewReplaceOrAlgorithm? definerClause? viewSuid? VIEW_SYMBOL viewName viewTail;
dropView:
VIEW_SYMBOL ifExists? viewRefList (
RESTRICT_SYMBOL
| CASCADE_SYMBOL
)?;
viewReplaceOrAlgorithm:
OR_SYMBOL REPLACE_SYMBOL viewAlgorithm?
| viewAlgorithm;
viewAlgorithm:
ALGORITHM_SYMBOL EQUAL_OPERATOR algorithm = (
UNDEFINED_SYMBOL
| MERGE_SYMBOL
| TEMPTABLE_SYMBOL
);
viewSuid:
SQL_SYMBOL SECURITY_SYMBOL (DEFINER_SYMBOL | INVOKER_SYMBOL);
// This is not the full view_tail from sql_yacc.yy as we have either a view name or a view
// reference, depending on whether we come from createView or alterView. Everything until this
// difference is duplicated in those rules.
viewTail: columnInternalRefList? AS_SYMBOL viewSelect;
viewSelect: queryExpressionOrParens viewCheckOption?;
viewCheckOption:
WITH_SYMBOL (CASCADED_SYMBOL | LOCAL_SYMBOL) CHECK_SYMBOL OPTION_SYMBOL;
duplicateAsQueryExpression:
(REPLACE_SYMBOL | IGNORE_SYMBOL)? AS_SYMBOL? queryExpressionOrParens;
queryExpressionOrParens:
queryExpression
| queryExpressionParens;
tableElementList: tableElement (COMMA_SYMBOL tableElement)*;
tableElement: columnDef | tableConstraintDef;
tableConstraintDef:
type = (KEY_SYMBOL | INDEX_SYMBOL) indexNameAndType? keyListVariants indexOption*
| type = FULLTEXT_SYMBOL keyOrIndex? indexName? keyListVariants fulltextIndexOption*
| type = SPATIAL_SYMBOL keyOrIndex? indexName? keyListVariants spatialIndexOption*
| constraintName? (
(
type = PRIMARY_SYMBOL KEY_SYMBOL
| type = UNIQUE_SYMBOL keyOrIndex?
) indexNameAndType? keyListVariants indexOption*
| type = FOREIGN_SYMBOL KEY_SYMBOL indexName? keyList references
| checkConstraint (constraintEnforcement)?
);
indexOption: commonIndexOption | indexTypeClause;
checkConstraint: CHECK_SYMBOL exprWithParentheses;
/*
The syntax for defining an index is:
... INDEX [index_name] [USING|TYPE] <index_type> ...
The problem is that whereas USING is a reserved word, TYPE is not. We can still handle it if an
index name is supplied, i.e.:
... INDEX type TYPE <index_type> ...
here the index's name is unmbiguously 'type', but for this:
... INDEX TYPE <index_type> ...
it's impossible to know what this actually mean - is 'type' the name or the type? For this reason
we accept the TYPE syntax only if a name is supplied.
*/
indexNameAndType:
indexName (USING_SYMBOL indexType)?
| indexName TYPE_SYMBOL indexType;
temporaryOption: GLOBAL_SYMBOL? TEMPORARY_SYMBOL;
columnDef: columnName dataType columnOptionList?;
columnOptionList: columnOption+;
columnOption:
NOT_SYMBOL? NULL_SYMBOL
| AUTO_INCREMENT_SYMBOL
| PRIMARY_SYMBOL? KEY_SYMBOL
| UNIQUE_SYMBOL KEY_SYMBOL?
| DEFAULT_SYMBOL (
signedLiteral
| NOW_SYMBOL timeFunctionParameters?
| exprWithParentheses
)
| SERIAL_SYMBOL DEFAULT_SYMBOL VALUE_SYMBOL
| ON_SYMBOL UPDATE_SYMBOL NOW_SYMBOL timeFunctionParameters?
| COMMENT_SYMBOL textLiteral
| constraintName? CHECK_SYMBOL OPEN_PAR_SYMBOL expr CLOSE_PAR_SYMBOL constraintEnforcement?
| (GENERATED_SYMBOL ALWAYS_SYMBOL)? AS_SYMBOL OPEN_PAR_SYMBOL expr CLOSE_PAR_SYMBOL (
VIRTUAL_SYMBOL
| STORED_SYMBOL
)?
| references
| COLLATE_SYMBOL collationName
| COLUMN_FORMAT_SYMBOL columnFormat
| STORAGE_SYMBOL storageMedia
| AUTO_RANDOM_SYMBOL autoRandomFieldLength?;
constraintName: CONSTRAINT_SYMBOL identifier?;
constraintEnforcement: NOT_SYMBOL? ENFORCED_SYMBOL;
//----------------------------------------------------------------------------------------------------------------------
selectStatement:
queryExpression lockingClauseList?
| queryExpressionParens
| selectStatementWithInto;
/*
From the server grammar:
MySQL has a syntax extension that allows into clauses in any one of two places. They may appear
either before the from clause or at the end. All in a top-level select statement. This extends the
standard syntax in two ways. First, we don't have the restriction that the result can contain only
one row: the into clause might be INTO OUTFILE/DUMPFILE in which case any number of rows is
allowed. Hence MySQL does not have any special case for the standard's <select statement: single
row>. Secondly, and this has more severe implications for the parser, it makes the grammar
ambiguous, because in a from-clause-less select statement with an into clause, it is not clear
whether the into clause is the leading or the trailing one.
While it's possible to write an unambiguous grammar, it would force us to duplicate the entire
<select statement> syntax all the way down to the <into clause>. So instead we solve it by writing
an ambiguous grammar and use precedence rules to sort out the shift/reduce conflict.
The problem is when the parser has seen SELECT <select list>, and sees an INTO token. It can now
either shift it or reduce what it has to a table-less query expression. If it shifts the token, it
will accept seeing a FROM token next and hence the INTO will be interpreted as the leading INTO. If
it reduces what it has seen to a table-less select, however, it will interpret INTO as the trailing
into. But what if the next token is FROM? Obviously, we want to always shift INTO. We do this by
two precedence declarations: We make the INTO token right-associative, and we give it higher
precedence than an empty from clause, using the artificial token EMPTY_FROM_CLAUSE.
The remaining problem is that now we allow the leading INTO anywhere, when it should be allowed on
the top level only. We solve this by manually throwing parse errors whenever we reduce a nested
query expression if it contains an into clause.
*/
selectStatementWithInto:
OPEN_PAR_SYMBOL selectStatementWithInto CLOSE_PAR_SYMBOL
| queryExpression intoClause lockingClauseList?
| lockingClauseList intoClause;
queryExpression:
(withClause)? (
queryExpressionBody orderClause? limitClause?
| queryExpressionParens orderClause? limitClause?
) (procedureAnalyseClause)?;
queryExpressionBody:
(
queryPrimary
| queryExpressionParens setOprSymbol setOprOption? (
queryPrimary
| queryExpressionParens
)
) (
setOprSymbol setOprOption? (
queryPrimary
| queryExpressionParens
)
)*;
queryExpressionParens:
OPEN_PAR_SYMBOL (
queryExpressionParens
| queryExpression lockingClauseList?
) CLOSE_PAR_SYMBOL;
queryPrimary:
querySpecification
| tableValueConstructor
| explicitTable;
querySpecification:
SELECT_SYMBOL selectOption* selectItemList intoClause? fromClause? whereClause? groupByClause?
havingClause? (windowClause)?;
subquery: queryExpressionParens;
querySpecOption:
ALL_SYMBOL
| DISTINCT_SYMBOL
| STRAIGHT_JOIN_SYMBOL
| HIGH_PRIORITY_SYMBOL
| SQL_SMALL_RESULT_SYMBOL
| SQL_BIG_RESULT_SYMBOL
| SQL_BUFFER_RESULT_SYMBOL
| SQL_CALC_FOUND_ROWS_SYMBOL;
limitClause: LIMIT_SYMBOL limitOptions;
simpleLimitClause: LIMIT_SYMBOL limitOption;
limitOptions:
limitOption ((COMMA_SYMBOL | OFFSET_SYMBOL) limitOption)?;
limitOption:
identifier
| (
PARAM_MARKER
| ULONGLONG_NUMBER
| LONG_NUMBER
| INT_NUMBER
);
intoClause:
INTO_SYMBOL (
OUTFILE_SYMBOL textStringLiteral charsetClause? fieldsClause? linesClause?
| DUMPFILE_SYMBOL textStringLiteral
| (textOrIdentifier | userVariable) (
COMMA_SYMBOL (textOrIdentifier | userVariable)
)*
);
procedureAnalyseClause:
PROCEDURE_SYMBOL ANALYSE_SYMBOL OPEN_PAR_SYMBOL (
INT_NUMBER (COMMA_SYMBOL INT_NUMBER)?
)? CLOSE_PAR_SYMBOL;
havingClause: HAVING_SYMBOL expr;
windowClause:
WINDOW_SYMBOL windowDefinition (
COMMA_SYMBOL windowDefinition
)*;
windowDefinition: windowName AS_SYMBOL windowSpec;
windowSpec: OPEN_PAR_SYMBOL windowSpecDetails CLOSE_PAR_SYMBOL;
windowSpecDetails:
windowName? (PARTITION_SYMBOL BY_SYMBOL orderList)? orderClause? windowFrameClause?;
windowFrameClause:
windowFrameUnits windowFrameExtent windowFrameExclusion?;
windowFrameUnits: ROWS_SYMBOL | RANGE_SYMBOL | GROUPS_SYMBOL;
windowFrameExtent: windowFrameStart | windowFrameBetween;
windowFrameStart:
UNBOUNDED_SYMBOL PRECEDING_SYMBOL
| ulonglong_number PRECEDING_SYMBOL
| PARAM_MARKER PRECEDING_SYMBOL
| INTERVAL_SYMBOL expr interval PRECEDING_SYMBOL
| CURRENT_SYMBOL ROW_SYMBOL;
windowFrameBetween:
BETWEEN_SYMBOL windowFrameBound AND_SYMBOL windowFrameBound;
windowFrameBound:
windowFrameStart
| UNBOUNDED_SYMBOL FOLLOWING_SYMBOL
| ulonglong_number FOLLOWING_SYMBOL
| PARAM_MARKER FOLLOWING_SYMBOL
| INTERVAL_SYMBOL expr interval FOLLOWING_SYMBOL;
windowFrameExclusion:
EXCLUDE_SYMBOL (
CURRENT_SYMBOL ROW_SYMBOL
| GROUP_SYMBOL
| TIES_SYMBOL
| NO_SYMBOL OTHERS_SYMBOL
);
withClause:
WITH_SYMBOL RECURSIVE_SYMBOL? commonTableExpression (
COMMA_SYMBOL commonTableExpression
)*;
commonTableExpression:
identifier columnInternalRefList? AS_SYMBOL subquery;
groupByClause: GROUP_SYMBOL BY_SYMBOL orderList olapOption?;
olapOption: WITH_SYMBOL ROLLUP_SYMBOL | WITH_SYMBOL CUBE_SYMBOL;
orderClause: ORDER_SYMBOL BY_SYMBOL orderList;
direction: ASC_SYMBOL | DESC_SYMBOL;
fromClause: FROM_SYMBOL (DUAL_SYMBOL | tableReferenceList);
tableReferenceList:
tableReference (COMMA_SYMBOL tableReference)*;
tableValueConstructor:
VALUES_SYMBOL rowValueExplicit (
COMMA_SYMBOL rowValueExplicit
)*;
explicitTable: TABLE_SYMBOL tableRef;
rowValueExplicit:
ROW_SYMBOL OPEN_PAR_SYMBOL values? CLOSE_PAR_SYMBOL;
values:
(expr | DEFAULT_SYMBOL) (
COMMA_SYMBOL (expr | DEFAULT_SYMBOL)
)*;
selectOption:
querySpecOption
| SQL_NO_CACHE_SYMBOL // Deprecated and ignored in 8.0.
| SQL_CACHE_SYMBOL
| MAX_STATEMENT_TIME_SYMBOL EQUAL_OPERATOR real_ulong_number;
lockingClauseList: lockingClause+;
lockingClause:
FOR_SYMBOL lockStrengh (OF_SYMBOL tableAliasRefList)? (
lockedRowAction
)?
| LOCK_SYMBOL IN_SYMBOL SHARE_SYMBOL MODE_SYMBOL;
lockStrengh: UPDATE_SYMBOL | SHARE_SYMBOL;
lockedRowAction: SKIP_SYMBOL LOCKED_SYMBOL | NOWAIT_SYMBOL;
selectItemList: (selectItem | MULT_OPERATOR) (
COMMA_SYMBOL selectItem
)*;
selectItem: tableWild | expr selectAlias?;
selectAlias: AS_SYMBOL? (identifier | textStringLiteral);
whereClause: WHERE_SYMBOL expr;
tableReference: (
// Note: we have also a tableRef rule for identifiers that reference a table anywhere.
tableFactor
| OPEN_CURLY_SYMBOL (identifier | OJ_SYMBOL) escapedTableReference CLOSE_CURLY_SYMBOL
// ODBC syntax
) joinedTable*;
escapedTableReference: tableFactor joinedTable*;
joinedTable: // Same as joined_table in sql_yacc.yy, but with removed left recursion.
innerJoinType tableReference (
ON_SYMBOL expr
| USING_SYMBOL identifierListWithParentheses
)?
| outerJoinType tableReference (
ON_SYMBOL expr
| USING_SYMBOL identifierListWithParentheses
)
| naturalJoinType tableFactor;
naturalJoinType:
NATURAL_SYMBOL INNER_SYMBOL? JOIN_SYMBOL
| NATURAL_SYMBOL (LEFT_SYMBOL | RIGHT_SYMBOL) OUTER_SYMBOL? JOIN_SYMBOL;
innerJoinType:
type = (INNER_SYMBOL | CROSS_SYMBOL)? JOIN_SYMBOL
| type = STRAIGHT_JOIN_SYMBOL;
outerJoinType:
type = (LEFT_SYMBOL | RIGHT_SYMBOL) OUTER_SYMBOL? JOIN_SYMBOL;
/**
MySQL has a syntax extension where a comma-separated list of table references is allowed as a table
reference in itself, for instance
SELECT * FROM (t1, t2) JOIN t3 ON 1
which is not allowed in standard SQL. The syntax is equivalent to
SELECT * FROM (t1 CROSS JOIN t2) JOIN t3 ON 1
We call this rule tableReferenceListParens.
*/
tableFactor:
singleTable
| singleTableParens
| derivedTable
| tableReferenceListParens
| tableFunction;
singleTable: tableRef usePartition? tableAlias? indexHintList?;
singleTableParens:
OPEN_PAR_SYMBOL (singleTable | singleTableParens) CLOSE_PAR_SYMBOL;
derivedTable:
subquery tableAlias? (columnInternalRefList)?
| LATERAL_SYMBOL subquery tableAlias? columnInternalRefList?;
// This rule covers both: joined_table_parens and table_reference_list_parens from sql_yacc.yy. We
// can simplify that because we have unrolled the indirect left recursion in joined_table <->
// table_reference.
tableReferenceListParens:
OPEN_PAR_SYMBOL (
tableReferenceList
| tableReferenceListParens
) CLOSE_PAR_SYMBOL;
tableFunction:
JSON_TABLE_SYMBOL OPEN_PAR_SYMBOL expr COMMA_SYMBOL textStringLiteral columnsClause
CLOSE_PAR_SYMBOL tableAlias?;
columnsClause:
COLUMNS_SYMBOL OPEN_PAR_SYMBOL jtColumn (
COMMA_SYMBOL jtColumn
)* CLOSE_PAR_SYMBOL;
jtColumn:
identifier FOR_SYMBOL ORDINALITY_SYMBOL
| identifier dataType (collate)? EXISTS_SYMBOL? PATH_SYMBOL textStringLiteral onEmptyOrError?
| NESTED_SYMBOL PATH_SYMBOL textStringLiteral columnsClause;
onEmptyOrError: onEmpty onError? | onError onEmpty?;
onEmpty: jtOnResponse ON_SYMBOL EMPTY_SYMBOL;
onError: jtOnResponse ON_SYMBOL ERROR_SYMBOL;
jtOnResponse:
ERROR_SYMBOL
| NULL_SYMBOL
| DEFAULT_SYMBOL textStringLiteral;
setOprSymbol: UNION_SYMBOL | INTERSECT_SYMBOL | EXCEPT_SYMBOL;
setOprOption: DISTINCT_SYMBOL | ALL_SYMBOL;
tableAlias: (AS_SYMBOL | EQUAL_OPERATOR)? identifier;
indexHintList: indexHint (COMMA_SYMBOL indexHint)*;
indexHint:
indexHintType keyOrIndex indexHintClause? OPEN_PAR_SYMBOL indexList CLOSE_PAR_SYMBOL
| USE_SYMBOL keyOrIndex indexHintClause? OPEN_PAR_SYMBOL indexList? CLOSE_PAR_SYMBOL;
indexHintType: FORCE_SYMBOL | IGNORE_SYMBOL;
keyOrIndex: KEY_SYMBOL | INDEX_SYMBOL;
constraintKeyType:
PRIMARY_SYMBOL KEY_SYMBOL
| UNIQUE_SYMBOL keyOrIndex?;
indexHintClause:
FOR_SYMBOL (
JOIN_SYMBOL
| ORDER_SYMBOL BY_SYMBOL
| GROUP_SYMBOL BY_SYMBOL
);
indexList: indexListElement (COMMA_SYMBOL indexListElement)*;
indexListElement: identifier | PRIMARY_SYMBOL;
//----------------------------------------------------------------------------------------------------------------------
updateStatement:
(withClause)? UPDATE_SYMBOL LOW_PRIORITY_SYMBOL? IGNORE_SYMBOL? tableReferenceList SET_SYMBOL
updateList whereClause? orderClause? simpleLimitClause?;
//----------------------------------------------------------------------------------------------------------------------
transactionOrLockingStatement:
transactionStatement
| savepointStatement
| lockStatement
| xaStatement;
transactionStatement:
START_SYMBOL TRANSACTION_SYMBOL transactionCharacteristic*
| COMMIT_SYMBOL WORK_SYMBOL? (
AND_SYMBOL NO_SYMBOL? CHAIN_SYMBOL
)? (NO_SYMBOL? RELEASE_SYMBOL)?; // SET TRANSACTION is part of setStatement.
// BEGIN WORK is separated from transactional statements as it must not appear as part of a stored program.
beginWork: BEGIN_SYMBOL WORK_SYMBOL?;
transactionCharacteristic:
WITH_SYMBOL CONSISTENT_SYMBOL SNAPSHOT_SYMBOL
| READ_SYMBOL (WRITE_SYMBOL | ONLY_SYMBOL);
savepointStatement:
SAVEPOINT_SYMBOL identifier
| ROLLBACK_SYMBOL WORK_SYMBOL? (
TO_SYMBOL SAVEPOINT_SYMBOL? identifier
| (AND_SYMBOL NO_SYMBOL? CHAIN_SYMBOL)? (
NO_SYMBOL? RELEASE_SYMBOL
)?
)
| RELEASE_SYMBOL SAVEPOINT_SYMBOL identifier;
lockStatement:
LOCK_SYMBOL (TABLES_SYMBOL | TABLE_SYMBOL) lockItem (
COMMA_SYMBOL lockItem
)*
| LOCK_SYMBOL INSTANCE_SYMBOL FOR_SYMBOL BACKUP_SYMBOL
| UNLOCK_SYMBOL (
TABLES_SYMBOL
| TABLE_SYMBOL
| INSTANCE_SYMBOL
);
lockItem: tableRef tableAlias? lockOption;
lockOption:
READ_SYMBOL LOCAL_SYMBOL?
| LOW_PRIORITY_SYMBOL? WRITE_SYMBOL; // low priority deprecated since 5.7
xaStatement:
XA_SYMBOL (
(START_SYMBOL | BEGIN_SYMBOL) xid (
JOIN_SYMBOL
| RESUME_SYMBOL
)?
| END_SYMBOL xid (
SUSPEND_SYMBOL (FOR_SYMBOL MIGRATE_SYMBOL)?
)?
| PREPARE_SYMBOL xid
| COMMIT_SYMBOL xid (ONE_SYMBOL PHASE_SYMBOL)?
| ROLLBACK_SYMBOL xid
| RECOVER_SYMBOL xaConvert
);
xaConvert: (CONVERT_SYMBOL XID_SYMBOL)? | /* empty */;
xid:
textString (
COMMA_SYMBOL textString (COMMA_SYMBOL ulong_number)?
)?;
//----------------------------------------------------------------------------------------------------------------------
replicationStatement:
PURGE_SYMBOL (BINARY_SYMBOL | MASTER_SYMBOL) LOGS_SYMBOL (
TO_SYMBOL textLiteral
| BEFORE_SYMBOL expr
)
| changeMaster
| RESET_SYMBOL resetOption (COMMA_SYMBOL resetOption)*
| RESET_SYMBOL PERSIST_SYMBOL (ifExists identifier)?
| slave
| changeReplication
| replicationLoad
| groupReplication;
resetOption:
option = MASTER_SYMBOL masterResetOptions?
| option = QUERY_SYMBOL CACHE_SYMBOL
| option = SLAVE_SYMBOL ALL_SYMBOL? channel?;
masterResetOptions:
TO_SYMBOL (real_ulong_number | real_ulonglong_number);
replicationLoad:
LOAD_SYMBOL (DATA_SYMBOL | TABLE_SYMBOL tableRef) FROM_SYMBOL MASTER_SYMBOL;
changeMaster:
CHANGE_SYMBOL MASTER_SYMBOL TO_SYMBOL changeMasterOptions channel?;
changeMasterOptions: masterOption (COMMA_SYMBOL masterOption)*;
masterOption:
MASTER_HOST_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| NETWORK_NAMESPACE_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_BIND_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_USER_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_PASSWORD_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_PORT_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_CONNECT_RETRY_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_RETRY_COUNT_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_DELAY_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_SSL_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_SSL_CA_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_SSL_CAPATH_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_TLS_VERSION_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_SSL_CERT_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_TLS_CIPHERSUITES_SYMBOL EQUAL_OPERATOR masterTlsCiphersuitesDef
| MASTER_SSL_CIPHER_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_SSL_KEY_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_SSL_VERIFY_SERVER_CERT_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_SSL_CRL_SYMBOL EQUAL_OPERATOR textLiteral
| MASTER_SSL_CRLPATH_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_PUBLIC_KEY_PATH_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
// Conditionally set in the lexer.
| GET_MASTER_PUBLIC_KEY_SYMBOL EQUAL_OPERATOR ulong_number // Conditionally set in the lexer.
| MASTER_HEARTBEAT_PERIOD_SYMBOL EQUAL_OPERATOR ulong_number
| IGNORE_SERVER_IDS_SYMBOL EQUAL_OPERATOR serverIdList
| MASTER_COMPRESSION_ALGORITHM_SYMBOL EQUAL_OPERATOR textStringLiteral
| MASTER_ZSTD_COMPRESSION_LEVEL_SYMBOL EQUAL_OPERATOR ulong_number
| MASTER_AUTO_POSITION_SYMBOL EQUAL_OPERATOR ulong_number
| PRIVILEGE_CHECKS_USER_SYMBOL EQUAL_OPERATOR privilegeCheckDef
| REQUIRE_ROW_FORMAT_SYMBOL EQUAL_OPERATOR ulong_number
| REQUIRE_TABLE_PRIMARY_KEY_CHECK_SYMBOL EQUAL_OPERATOR tablePrimaryKeyCheckDef
| masterFileDef;
privilegeCheckDef: userIdentifierOrText | NULL_SYMBOL;
tablePrimaryKeyCheckDef: STREAM_SYMBOL | ON_SYMBOL | OFF_SYMBOL;
masterTlsCiphersuitesDef: textStringNoLinebreak | NULL_SYMBOL;
masterFileDef:
MASTER_LOG_FILE_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| MASTER_LOG_POS_SYMBOL EQUAL_OPERATOR ulonglong_number
| RELAY_LOG_FILE_SYMBOL EQUAL_OPERATOR textStringNoLinebreak
| RELAY_LOG_POS_SYMBOL EQUAL_OPERATOR ulong_number;
serverIdList:
OPEN_PAR_SYMBOL (ulong_number (COMMA_SYMBOL ulong_number)*)? CLOSE_PAR_SYMBOL;
changeReplication:
CHANGE_SYMBOL REPLICATION_SYMBOL FILTER_SYMBOL filterDefinition (
COMMA_SYMBOL filterDefinition
)* (channel)?;
filterDefinition:
REPLICATE_DO_DB_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterDbList? CLOSE_PAR_SYMBOL
| REPLICATE_IGNORE_DB_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterDbList? CLOSE_PAR_SYMBOL
| REPLICATE_DO_TABLE_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterTableList? CLOSE_PAR_SYMBOL
| REPLICATE_IGNORE_TABLE_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterTableList? CLOSE_PAR_SYMBOL
| REPLICATE_WILD_DO_TABLE_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterStringList?
CLOSE_PAR_SYMBOL
| REPLICATE_WILD_IGNORE_TABLE_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterStringList?
CLOSE_PAR_SYMBOL
| REPLICATE_REWRITE_DB_SYMBOL EQUAL_OPERATOR OPEN_PAR_SYMBOL filterDbPairList? CLOSE_PAR_SYMBOL;
filterDbList: schemaRef (COMMA_SYMBOL schemaRef)*;
filterTableList: filterTableRef (COMMA_SYMBOL filterTableRef)*;
filterStringList:
filterWildDbTableString (
COMMA_SYMBOL filterWildDbTableString
)*;
filterWildDbTableString: textStringNoLinebreak;
// sql_yacc.yy checks for the existance of at least one dot char in the string.
filterDbPairList:
schemaIdentifierPair (COMMA_SYMBOL schemaIdentifierPair)*;
slave:
START_SYMBOL SLAVE_SYMBOL slaveThreadOptions? (
UNTIL_SYMBOL slaveUntilOptions
)? slaveConnectionOptions channel?
| STOP_SYMBOL SLAVE_SYMBOL slaveThreadOptions? channel?;
slaveUntilOptions:
(
masterFileDef
| (SQL_BEFORE_GTIDS_SYMBOL | SQL_AFTER_GTIDS_SYMBOL) EQUAL_OPERATOR textString
| SQL_AFTER_MTS_GAPS_SYMBOL
) (COMMA_SYMBOL masterFileDef)*;
slaveConnectionOptions:
(USER_SYMBOL EQUAL_OPERATOR textString)? (
PASSWORD_SYMBOL EQUAL_OPERATOR textString
)? (DEFAULT_AUTH_SYMBOL EQUAL_OPERATOR textString)? (
PLUGIN_DIR_SYMBOL EQUAL_OPERATOR textString
)?
| /* empty */;
slaveThreadOptions:
slaveThreadOption (COMMA_SYMBOL slaveThreadOption)*;
slaveThreadOption: RELAY_THREAD_SYMBOL | SQL_THREAD_SYMBOL;
groupReplication:
(START_SYMBOL | STOP_SYMBOL) GROUP_REPLICATION_SYMBOL;
//----------------------------------------------------------------------------------------------------------------------
preparedStatement:
type = PREPARE_SYMBOL identifier FROM_SYMBOL (
textLiteral
| userVariable
)
| executeStatement
| type = (DEALLOCATE_SYMBOL | DROP_SYMBOL) PREPARE_SYMBOL identifier;
executeStatement:
EXECUTE_SYMBOL identifier (USING_SYMBOL executeVarList)?;
executeVarList: userVariable (COMMA_SYMBOL userVariable)*;
//----------------------------------------------------------------------------------------------------------------------
cloneStatement:
CLONE_SYMBOL (
LOCAL_SYMBOL DATA_SYMBOL DIRECTORY_SYMBOL equal? textStringLiteral
// Clone remote has been removed in 8.0.14. This alt is taken out by the conditional REMOTE_SYMBOL.
| REMOTE_SYMBOL (FOR_SYMBOL REPLICATION_SYMBOL)?
| INSTANCE_SYMBOL FROM_SYMBOL user COLON_SYMBOL ulong_number IDENTIFIED_SYMBOL BY_SYMBOL
textStringLiteral dataDirSSL?
);
dataDirSSL:
ssl
| DATA_SYMBOL DIRECTORY_SYMBOL equal? textStringLiteral ssl?;
ssl: REQUIRE_SYMBOL NO_SYMBOL? SSL_SYMBOL;
//----------------------------------------------------------------------------------------------------------------------
// Note: SET PASSWORD is part of the SET statement.
accountManagementStatement:
alterUser
| createUser
| dropUser
| grant
| renameUser
| revoke
| setRole;
alterUser: ALTER_SYMBOL USER_SYMBOL (ifExists)? alterUserTail;
alterUserTail:
(createUserList | alterUserList) createUserTail
| user IDENTIFIED_SYMBOL BY_SYMBOL textString (
replacePassword
)? (retainCurrentPassword)?
| user discardOldPassword
| user DEFAULT_SYMBOL ROLE_SYMBOL (
ALL_SYMBOL
| NONE_SYMBOL
| roleList
)
| user IDENTIFIED_SYMBOL (WITH_SYMBOL textOrIdentifier)? BY_SYMBOL RANDOM_SYMBOL PASSWORD_SYMBOL
retainCurrentPassword?
| FAILED_LOGIN_ATTEMPTS_SYMBOL real_ulong_number
| PASSWORD_LOCK_TIME_SYMBOL (
real_ulong_number
| UNBOUNDED_SYMBOL
);
userFunction: USER_SYMBOL parentheses;
createUser:
CREATE_SYMBOL USER_SYMBOL (ifNotExists | /* empty */) createUserList defaultRoleClause
createUserTail;
createUserTail:
requireClause? connectOptions? accountLockPasswordExpireOptions* (
(COMMENT_SYMBOL textStringLiteral)
| (ATTRIBUTE_SYMBOL textStringLiteral)
)?
| /* empty */;
defaultRoleClause:
(DEFAULT_SYMBOL ROLE_SYMBOL roleList)?
| /* empty */;
requireClause:
REQUIRE_SYMBOL (
requireList
| option = (SSL_SYMBOL | X509_SYMBOL | NONE_SYMBOL)
);
connectOptions:
WITH_SYMBOL (
MAX_QUERIES_PER_HOUR_SYMBOL ulong_number
| MAX_UPDATES_PER_HOUR_SYMBOL ulong_number
| MAX_CONNECTIONS_PER_HOUR_SYMBOL ulong_number
| MAX_USER_CONNECTIONS_SYMBOL ulong_number
)+;
accountLockPasswordExpireOptions:
ACCOUNT_SYMBOL (LOCK_SYMBOL | UNLOCK_SYMBOL)
| PASSWORD_SYMBOL (
EXPIRE_SYMBOL (
INTERVAL_SYMBOL real_ulong_number DAY_SYMBOL
| NEVER_SYMBOL
| DEFAULT_SYMBOL
)?
| HISTORY_SYMBOL (real_ulong_number | DEFAULT_SYMBOL)
| REUSE_SYMBOL INTERVAL_SYMBOL (
real_ulong_number DAY_SYMBOL
| DEFAULT_SYMBOL
)
| REQUIRE_SYMBOL CURRENT_SYMBOL (
DEFAULT_SYMBOL
| OPTIONAL_SYMBOL
)?
);
dropUser: DROP_SYMBOL USER_SYMBOL (ifExists)? userList;
grant:
GRANT_SYMBOL (
roleOrPrivilegesList TO_SYMBOL userList (
WITH_SYMBOL ADMIN_SYMBOL OPTION_SYMBOL
)?
| (roleOrPrivilegesList | ALL_SYMBOL PRIVILEGES_SYMBOL?) ON_SYMBOL aclType? grantIdentifier
TO_SYMBOL grantTargetList versionedRequireClause? grantOptions? grantAs?
| PROXY_SYMBOL ON_SYMBOL user TO_SYMBOL grantTargetList (
WITH_SYMBOL GRANT_SYMBOL OPTION_SYMBOL
)?
);
grantTargetList: createUserList | userList;
grantOptions:
WITH_SYMBOL grantOption+
| WITH_SYMBOL GRANT_SYMBOL OPTION_SYMBOL;
exceptRoleList: EXCEPT_SYMBOL roleList;
withRoles:
WITH_SYMBOL ROLE_SYMBOL (
roleList
| ALL_SYMBOL exceptRoleList?
| NONE_SYMBOL
| DEFAULT_SYMBOL
);
grantAs: AS_SYMBOL user withRoles?;
versionedRequireClause: requireClause;
renameUser:
RENAME_SYMBOL USER_SYMBOL user TO_SYMBOL user (
COMMA_SYMBOL user TO_SYMBOL user
)*;
revoke:
REVOKE_SYMBOL (
roleOrPrivilegesList FROM_SYMBOL userList
| roleOrPrivilegesList onTypeTo FROM_SYMBOL userList
| ALL_SYMBOL PRIVILEGES_SYMBOL? (
ON_SYMBOL aclType? grantIdentifier
| COMMA_SYMBOL GRANT_SYMBOL OPTION_SYMBOL FROM_SYMBOL userList
)
| PROXY_SYMBOL ON_SYMBOL user FROM_SYMBOL userList
);
onTypeTo: // Optional, starting with 8.0.1.
ON_SYMBOL aclType? grantIdentifier
| (ON_SYMBOL aclType? grantIdentifier)?;
aclType: TABLE_SYMBOL | FUNCTION_SYMBOL | PROCEDURE_SYMBOL;
roleOrPrivilegesList:
roleOrPrivilege (COMMA_SYMBOL roleOrPrivilege)*;
roleOrPrivilege:
(
roleIdentifierOrText columnInternalRefList?
| roleIdentifierOrText (
AT_TEXT_SUFFIX
| AT_SIGN_SYMBOL textOrIdentifier
)
)
| (
SELECT_SYMBOL
| INSERT_SYMBOL
| UPDATE_SYMBOL
| REFERENCES_SYMBOL
) columnInternalRefList?
| (
DELETE_SYMBOL
| USAGE_SYMBOL
| INDEX_SYMBOL
| DROP_SYMBOL
| EXECUTE_SYMBOL
| RELOAD_SYMBOL
| SHUTDOWN_SYMBOL
| PROCESS_SYMBOL
| FILE_SYMBOL
| PROXY_SYMBOL
| SUPER_SYMBOL
| EVENT_SYMBOL
| TRIGGER_SYMBOL
)
| GRANT_SYMBOL OPTION_SYMBOL
| SHOW_SYMBOL DATABASES_SYMBOL
| CREATE_SYMBOL (
TEMPORARY_SYMBOL object = TABLES_SYMBOL
| object = (
ROUTINE_SYMBOL
| TABLESPACE_SYMBOL
| USER_SYMBOL
| VIEW_SYMBOL
)
)?
| LOCK_SYMBOL TABLES_SYMBOL
| REPLICATION_SYMBOL object = (CLIENT_SYMBOL | SLAVE_SYMBOL)
| SHOW_SYMBOL VIEW_SYMBOL
| ALTER_SYMBOL ROUTINE_SYMBOL?
| (CREATE_SYMBOL | DROP_SYMBOL) ROLE_SYMBOL
// The following are AWS RDS MySQL extensions.
| LOAD_SYMBOL FROM_SYMBOL S3_SYMBOL
| SELECT_SYMBOL INTO_SYMBOL S3_SYMBOL
| INVOKE_SYMBOL LAMBDA_SYMBOL;
grantIdentifier:
MULT_OPERATOR (DOT_SYMBOL MULT_OPERATOR)?
| schemaRef (DOT_SYMBOL MULT_OPERATOR)?
| tableRef
| schemaRef DOT_SYMBOL tableRef;
requireList:
requireListElement (AND_SYMBOL? requireListElement)*;
requireListElement:
element = CIPHER_SYMBOL textString
| element = ISSUER_SYMBOL textString
| element = SUBJECT_SYMBOL textString;
grantOption:
option = GRANT_SYMBOL OPTION_SYMBOL
| option = MAX_QUERIES_PER_HOUR_SYMBOL ulong_number
| option = MAX_UPDATES_PER_HOUR_SYMBOL ulong_number
| option = MAX_CONNECTIONS_PER_HOUR_SYMBOL ulong_number
| option = MAX_USER_CONNECTIONS_SYMBOL ulong_number;
setRole:
SET_SYMBOL ROLE_SYMBOL roleList
| SET_SYMBOL ROLE_SYMBOL (NONE_SYMBOL | DEFAULT_SYMBOL)
| SET_SYMBOL DEFAULT_SYMBOL ROLE_SYMBOL (
roleList
| NONE_SYMBOL
| ALL_SYMBOL
) TO_SYMBOL roleList
| SET_SYMBOL ROLE_SYMBOL ALL_SYMBOL (EXCEPT_SYMBOL roleList)?;
roleList: role (COMMA_SYMBOL role)*;
role:
roleIdentifierOrText (
AT_SIGN_SYMBOL textOrIdentifier
| AT_TEXT_SUFFIX
)?;
//----------------------------------------------------------------------------------------------------------------------
tableAdministrationStatement:
type = ANALYZE_SYMBOL noWriteToBinLog? TABLE_SYMBOL tableRefList (
histogram
)?
| type = CHECK_SYMBOL TABLE_SYMBOL tableRefList checkOption*
| type = CHECKSUM_SYMBOL TABLE_SYMBOL tableRefList (
QUICK_SYMBOL
| EXTENDED_SYMBOL
)?
| type = OPTIMIZE_SYMBOL noWriteToBinLog? TABLE_SYMBOL tableRefList
| type = REPAIR_SYMBOL noWriteToBinLog? TABLE_SYMBOL tableRefList repairType*;
histogram:
UPDATE_SYMBOL HISTOGRAM_SYMBOL ON_SYMBOL identifierList (
WITH_SYMBOL INT_NUMBER BUCKETS_SYMBOL
)?
| DROP_SYMBOL HISTOGRAM_SYMBOL ON_SYMBOL identifierList;
checkOption:
FOR_SYMBOL UPGRADE_SYMBOL
| (
QUICK_SYMBOL
| FAST_SYMBOL
| MEDIUM_SYMBOL