-
Notifications
You must be signed in to change notification settings - Fork 330
/
MySQLParser.g4
5023 lines (4351 loc) · 140 KB
/
MySQLParser.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 MySQLParser;
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0,
* as published by the Free Software Foundation.
*
* This program is designed to work with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms, as
* designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an additional
* permission to link the program and your derivative works with the
* separately licensed software that they have either included with
* the program or referenced in the documentation.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Merged in all changes up to mysql-trunk git revision [6d4f66a] (16. January 2020).
*
* MySQL grammar for ANTLR 4.5+ with language features from MySQL 5.6.0 up to MySQL 8.0.
* The server version in the generated parser can be switched at runtime, making it so possible
* to switch the supported feature set dynamically.
*
* The coverage of the MySQL language should be 100%, but there might still be bugs or omissions.
*
* To use this grammar you will need a few support classes (which should be close to where you found this grammar).
* These classes implement the target specific action code, so we don't clutter the grammar with that
* and make it simpler to adjust it for other targets. See the demo/test project for further details.
*
* Written by Mike Lischke. Direct all bug reports, omissions etc. to [email protected].
*/
//----------------------------------------------------------------------------------------------------------------------
// $antlr-format alignTrailingComments on, columnLimit 130, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments off
// $antlr-format useTab off, allowShortRulesOnASingleLine off, allowShortBlocksOnASingleLine on, alignSemicolons ownLine
options {
superClass = MySQLBaseRecognizer;
tokenVocab = MySQLLexer;
exportMacro = PARSERS_PUBLIC_TYPE;
}
//----------------------------------------------------------------------------------------------------------------------
@header {/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0,
* as published by the Free Software Foundation.
*
* This program is designed to work with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms, as
* designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an additional
* permission to link the program and your derivative works with the
* separately licensed software that they have either included with
* the program or referenced in the documentation.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
}
@postinclude {
#include "MySQLBaseRecognizer.h"
}
//----------------------------------------------------------------------------------------------------------------------
query:
EOF
| (simpleStatement | beginWork) (SEMICOLON_SYMBOL EOF? | EOF)
;
simpleStatement:
// DDL
alterStatement
| createStatement
| dropStatement
| renameTableStatement
| truncateTableStatement
| {serverVersion >= 80000}? importStatement
// DML
| callStatement
| deleteStatement
| doStatement
| handlerStatement
| insertStatement
| loadStatement
| replaceStatement
| selectStatement
| updateStatement
| transactionOrLockingStatement
| replicationStatement
| preparedStatement
// Data Directory
| {serverVersion >= 80000}? cloneStatement
// Database administration
| accountManagementStatement
| tableAdministrationStatement
| installUninstallStatment
| setStatement // SET PASSWORD is handled in accountManagementStatement.
| showStatement
| {serverVersion >= 80000}? resourceGroupManagement
| otherAdministrativeStatement
// MySQL utilitity statements
| utilityStatement
| {serverVersion >= 50604}? getDiagnostics
| signalStatement
| resignalStatement
;
//----------------- DDL statements -------------------------------------------------------------------------------------
alterStatement:
ALTER_SYMBOL (
alterTable
| alterDatabase
| PROCEDURE_SYMBOL procedureRef routineAlterOptions?
| FUNCTION_SYMBOL functionRef routineAlterOptions?
| alterView
| alterEvent
| alterTablespace
| {serverVersion >= 80014}? alterUndoTablespace
| alterLogfileGroup
| alterServer
// ALTER USER is part of the user management rule.
| {serverVersion >= 50713}? INSTANCE_SYMBOL ROTATE_SYMBOL textOrIdentifier MASTER_SYMBOL KEY_SYMBOL
)
;
alterDatabase:
DATABASE_SYMBOL schemaRef (
createDatabaseOption+
| {serverVersion < 80000}? UPGRADE_SYMBOL DATA_SYMBOL DIRECTORY_SYMBOL NAME_SYMBOL
)
;
alterEvent:
definerClause? EVENT_SYMBOL eventRef (ON_SYMBOL SCHEDULE_SYMBOL schedule)? (
ON_SYMBOL COMPLETION_SYMBOL NOT_SYMBOL? PRESERVE_SYMBOL
)? (RENAME_SYMBOL TO_SYMBOL identifier)? (
ENABLE_SYMBOL
| DISABLE_SYMBOL (ON_SYMBOL SLAVE_SYMBOL)?
)? (COMMENT_SYMBOL textLiteral)? (DO_SYMBOL compoundStatement)?
;
alterLogfileGroup:
LOGFILE_SYMBOL GROUP_SYMBOL logfileGroupRef ADD_SYMBOL UNDOFILE_SYMBOL textLiteral alterLogfileGroupOptions?
;
alterLogfileGroupOptions:
alterLogfileGroupOption (COMMA_SYMBOL? alterLogfileGroupOption)*
;
alterLogfileGroupOption:
tsOptionInitialSize
| tsOptionEngine
| tsOptionWait
;
alterServer:
SERVER_SYMBOL serverRef serverOptions
;
alterTable:
onlineOption? ({serverVersion < 50700}? IGNORE_SYMBOL)? TABLE_SYMBOL tableRef alterTableActions?
;
alterTableActions:
alterCommandList (partitionClause | removePartitioning)?
| partitionClause
| removePartitioning
| (alterCommandsModifierList COMMA_SYMBOL)? standaloneAlterCommands
;
alterCommandList:
alterCommandsModifierList
| (alterCommandsModifierList COMMA_SYMBOL)? alterList
;
alterCommandsModifierList:
alterCommandsModifier (COMMA_SYMBOL alterCommandsModifier)*
;
standaloneAlterCommands:
DISCARD_SYMBOL TABLESPACE_SYMBOL
| IMPORT_SYMBOL TABLESPACE_SYMBOL
| alterPartition
| {serverVersion >= 80014}? (SECONDARY_LOAD_SYMBOL | SECONDARY_UNLOAD_SYMBOL)
;
alterPartition:
ADD_SYMBOL PARTITION_SYMBOL noWriteToBinLog? (
partitionDefinitions
| PARTITIONS_SYMBOL real_ulong_number
)
| DROP_SYMBOL PARTITION_SYMBOL identifierList
| REBUILD_SYMBOL PARTITION_SYMBOL noWriteToBinLog? allOrPartitionNameList
// yes, twice "no write to bin log".
| OPTIMIZE_SYMBOL PARTITION_SYMBOL noWriteToBinLog? allOrPartitionNameList noWriteToBinLog?
| ANALYZE_SYMBOL PARTITION_SYMBOL noWriteToBinLog? allOrPartitionNameList
| CHECK_SYMBOL PARTITION_SYMBOL allOrPartitionNameList checkOption*
| REPAIR_SYMBOL PARTITION_SYMBOL noWriteToBinLog? allOrPartitionNameList repairType*
| COALESCE_SYMBOL PARTITION_SYMBOL noWriteToBinLog? real_ulong_number
| TRUNCATE_SYMBOL PARTITION_SYMBOL allOrPartitionNameList
| REORGANIZE_SYMBOL PARTITION_SYMBOL noWriteToBinLog? (
identifierList INTO_SYMBOL partitionDefinitions
)?
| EXCHANGE_SYMBOL PARTITION_SYMBOL identifier WITH_SYMBOL TABLE_SYMBOL tableRef withValidation?
| {serverVersion >= 50704}? DISCARD_SYMBOL PARTITION_SYMBOL allOrPartitionNameList TABLESPACE_SYMBOL
| {serverVersion >= 50704}? IMPORT_SYMBOL PARTITION_SYMBOL allOrPartitionNameList TABLESPACE_SYMBOL
;
alterList:
(alterListItem | createTableOptionsSpaceSeparated) (
COMMA_SYMBOL (
alterListItem
| alterCommandsModifier
| createTableOptionsSpaceSeparated
)
)*
;
alterCommandsModifier:
alterAlgorithmOption
| alterLockOption
| withValidation
;
alterListItem:
ADD_SYMBOL COLUMN_SYMBOL? (
identifier fieldDefinition checkOrReferences? place?
| OPEN_PAR_SYMBOL tableElementList CLOSE_PAR_SYMBOL
)
| ADD_SYMBOL tableConstraintDef
| CHANGE_SYMBOL COLUMN_SYMBOL? columnInternalRef identifier fieldDefinition place?
| MODIFY_SYMBOL COLUMN_SYMBOL? columnInternalRef fieldDefinition place?
| DROP_SYMBOL (
COLUMN_SYMBOL? columnInternalRef restrict?
| FOREIGN_SYMBOL KEY_SYMBOL (
// This part is no longer optional starting with 5.7.
{serverVersion >= 50700}? columnInternalRef
| {serverVersion < 50700}? columnInternalRef?
)
| PRIMARY_SYMBOL KEY_SYMBOL
| keyOrIndex indexRef
| {serverVersion >= 80017}? CHECK_SYMBOL identifier
| {serverVersion >= 80019}? CONSTRAINT_SYMBOL identifier
)
| DISABLE_SYMBOL KEYS_SYMBOL
| ENABLE_SYMBOL KEYS_SYMBOL
| ALTER_SYMBOL COLUMN_SYMBOL? columnInternalRef (
SET_SYMBOL DEFAULT_SYMBOL (
{serverVersion >= 80014}? exprWithParentheses
| signedLiteral
)
| DROP_SYMBOL DEFAULT_SYMBOL
)
| {serverVersion >= 80000}? ALTER_SYMBOL INDEX_SYMBOL indexRef visibility
| {serverVersion >= 80017}? ALTER_SYMBOL CHECK_SYMBOL identifier constraintEnforcement
| {serverVersion >= 80019}? ALTER_SYMBOL CONSTRAINT_SYMBOL identifier constraintEnforcement
| {serverVersion >= 80000}? RENAME_SYMBOL COLUMN_SYMBOL columnInternalRef TO_SYMBOL identifier
| RENAME_SYMBOL (TO_SYMBOL | AS_SYMBOL)? tableName
| {serverVersion >= 50700}? RENAME_SYMBOL keyOrIndex indexRef TO_SYMBOL indexName
| CONVERT_SYMBOL TO_SYMBOL charset (
{serverVersion >= 80014}? DEFAULT_SYMBOL
| charsetName
) collate?
| FORCE_SYMBOL
| ORDER_SYMBOL BY_SYMBOL alterOrderList
| {serverVersion >= 50708 && serverVersion < 80000}? UPGRADE_SYMBOL PARTITIONING_SYMBOL
;
place:
AFTER_SYMBOL identifier
| FIRST_SYMBOL
;
restrict:
RESTRICT_SYMBOL
| CASCADE_SYMBOL
;
alterOrderList:
identifier direction? (COMMA_SYMBOL identifier direction?)*
;
alterAlgorithmOption:
ALGORITHM_SYMBOL EQUAL_OPERATOR? (DEFAULT_SYMBOL | identifier)
;
alterLockOption:
LOCK_SYMBOL EQUAL_OPERATOR? (DEFAULT_SYMBOL | identifier)
;
indexLockAndAlgorithm:
alterAlgorithmOption alterLockOption?
| alterLockOption alterAlgorithmOption?
;
withValidation:
{serverVersion >= 50706}? (WITH_SYMBOL | WITHOUT_SYMBOL) VALIDATION_SYMBOL
;
removePartitioning:
REMOVE_SYMBOL PARTITIONING_SYMBOL
;
allOrPartitionNameList:
ALL_SYMBOL
| identifierList
;
alterTablespace:
TABLESPACE_SYMBOL tablespaceRef (
(ADD_SYMBOL | DROP_SYMBOL) DATAFILE_SYMBOL textLiteral alterTablespaceOptions?
| {serverVersion < 80000}? (
| CHANGE_SYMBOL DATAFILE_SYMBOL textLiteral (
changeTablespaceOption (COMMA_SYMBOL? changeTablespaceOption)*
)?
| (READ_ONLY_SYMBOL | READ_WRITE_SYMBOL)
| NOT_SYMBOL ACCESSIBLE_SYMBOL
)
| RENAME_SYMBOL TO_SYMBOL identifier
| {serverVersion >= 80014}? alterTablespaceOptions
)
;
alterUndoTablespace:
UNDO_SYMBOL TABLESPACE_SYMBOL tablespaceRef SET_SYMBOL (
ACTIVE_SYMBOL
| INACTIVE_SYMBOL
) undoTableSpaceOptions?
;
undoTableSpaceOptions:
undoTableSpaceOption (COMMA_SYMBOL? undoTableSpaceOption)*
;
undoTableSpaceOption:
tsOptionEngine
;
alterTablespaceOptions:
alterTablespaceOption (COMMA_SYMBOL? alterTablespaceOption)*
;
alterTablespaceOption:
INITIAL_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
| tsOptionAutoextendSize
| tsOptionMaxSize
| tsOptionEngine
| tsOptionWait
| tsOptionEncryption
;
changeTablespaceOption:
INITIAL_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
| tsOptionAutoextendSize
| tsOptionMaxSize
;
alterView:
viewAlgorithm? definerClause? viewSuid? VIEW_SYMBOL viewRef viewTail
;
// 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
;
//----------------------------------------------------------------------------------------------------------------------
createStatement:
CREATE_SYMBOL (
createDatabase
| createTable
| createFunction
| createProcedure
| createUdf
| createLogfileGroup
| createView
| createTrigger
| createIndex
| createServer
| createTablespace
| createEvent
| {serverVersion >= 80000}? createRole
| {serverVersion >= 80011}? createSpatialReference
| {serverVersion >= 80014}? createUndoTablespace
)
;
createDatabase:
DATABASE_SYMBOL ifNotExists? schemaName createDatabaseOption*
;
createDatabaseOption:
defaultCharset
| defaultCollation
| {serverVersion >= 80016}? defaultEncryption
;
createTable:
TEMPORARY_SYMBOL? TABLE_SYMBOL ifNotExists? tableName (
(OPEN_PAR_SYMBOL tableElementList CLOSE_PAR_SYMBOL)? createTableOptions? partitionClause? duplicateAsQueryExpression?
| LIKE_SYMBOL tableRef
| OPEN_PAR_SYMBOL LIKE_SYMBOL tableRef CLOSE_PAR_SYMBOL
)
;
tableElementList:
tableElement (COMMA_SYMBOL tableElement)*
;
tableElement:
columnDefinition
| tableConstraintDef
;
duplicateAsQueryExpression: (REPLACE_SYMBOL | IGNORE_SYMBOL)? AS_SYMBOL? queryExpressionOrParens
;
queryExpressionOrParens:
queryExpression
| queryExpressionParens
;
createRoutine: // Rule for external use only.
CREATE_SYMBOL (createProcedure | createFunction | createUdf) SEMICOLON_SYMBOL? EOF
;
createProcedure:
definerClause? PROCEDURE_SYMBOL procedureName OPEN_PAR_SYMBOL (
procedureParameter (COMMA_SYMBOL procedureParameter)*
)? CLOSE_PAR_SYMBOL routineCreateOption* compoundStatement
;
createFunction:
definerClause? FUNCTION_SYMBOL functionName OPEN_PAR_SYMBOL (
functionParameter (COMMA_SYMBOL functionParameter)*
)? CLOSE_PAR_SYMBOL RETURNS_SYMBOL typeWithOptCollate routineCreateOption* compoundStatement
;
createUdf:
AGGREGATE_SYMBOL? FUNCTION_SYMBOL udfName RETURNS_SYMBOL type = (
STRING_SYMBOL
| INT_SYMBOL
| REAL_SYMBOL
| DECIMAL_SYMBOL
) SONAME_SYMBOL textLiteral
;
routineCreateOption:
routineOption
| NOT_SYMBOL? DETERMINISTIC_SYMBOL
;
routineAlterOptions:
routineCreateOption+
;
routineOption:
option = COMMENT_SYMBOL textLiteral
| option = LANGUAGE_SYMBOL SQL_SYMBOL
| option = NO_SYMBOL SQL_SYMBOL
| option = CONTAINS_SYMBOL SQL_SYMBOL
| option = READS_SYMBOL SQL_SYMBOL DATA_SYMBOL
| option = MODIFIES_SYMBOL SQL_SYMBOL DATA_SYMBOL
| option = SQL_SYMBOL SECURITY_SYMBOL security = (
DEFINER_SYMBOL
| INVOKER_SYMBOL
)
;
createIndex:
onlineOption? (
UNIQUE_SYMBOL? type = INDEX_SYMBOL (
{serverVersion >= 80014}? indexName indexTypeClause?
| indexNameAndType?
) createIndexTarget indexOption*
| type = FULLTEXT_SYMBOL INDEX_SYMBOL indexName createIndexTarget fulltextIndexOption*
| type = SPATIAL_SYMBOL INDEX_SYMBOL indexName createIndexTarget spatialIndexOption*
) indexLockAndAlgorithm?
;
/*
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
;
createIndexTarget:
ON_SYMBOL tableRef keyListVariants
;
createLogfileGroup:
LOGFILE_SYMBOL GROUP_SYMBOL logfileGroupName ADD_SYMBOL (
UNDOFILE_SYMBOL
| REDOFILE_SYMBOL // No longer used from 8.0 onwards. Taken out by lexer.
) textLiteral logfileGroupOptions?
;
logfileGroupOptions:
logfileGroupOption (COMMA_SYMBOL? logfileGroupOption)*
;
logfileGroupOption:
tsOptionInitialSize
| tsOptionUndoRedoBufferSize
| tsOptionNodegroup
| tsOptionEngine
| tsOptionWait
| tsOptionComment
;
createServer:
SERVER_SYMBOL serverName FOREIGN_SYMBOL DATA_SYMBOL WRAPPER_SYMBOL textOrIdentifier serverOptions
;
serverOptions:
OPTIONS_SYMBOL OPEN_PAR_SYMBOL serverOption (COMMA_SYMBOL serverOption)* CLOSE_PAR_SYMBOL
;
// Options for CREATE/ALTER SERVER, used for the federated storage engine.
serverOption:
option = HOST_SYMBOL textLiteral
| option = DATABASE_SYMBOL textLiteral
| option = USER_SYMBOL textLiteral
| option = PASSWORD_SYMBOL textLiteral
| option = SOCKET_SYMBOL textLiteral
| option = OWNER_SYMBOL textLiteral
| option = PORT_SYMBOL ulong_number
;
createTablespace:
TABLESPACE_SYMBOL tablespaceName tsDataFileName (
USE_SYMBOL LOGFILE_SYMBOL GROUP_SYMBOL logfileGroupRef
)? tablespaceOptions?
;
createUndoTablespace:
UNDO_SYMBOL TABLESPACE_SYMBOL tablespaceName ADD_SYMBOL tsDataFile undoTableSpaceOptions?
;
tsDataFileName:
{serverVersion >= 80014}? (ADD_SYMBOL tsDataFile)?
| ADD_SYMBOL tsDataFile
;
tsDataFile:
DATAFILE_SYMBOL textLiteral
;
tablespaceOptions:
tablespaceOption (COMMA_SYMBOL? tablespaceOption)*
;
tablespaceOption:
tsOptionInitialSize
| tsOptionAutoextendSize
| tsOptionMaxSize
| tsOptionExtentSize
| tsOptionNodegroup
| tsOptionEngine
| tsOptionWait
| tsOptionComment
| {serverVersion >= 50707}? tsOptionFileblockSize
| {serverVersion >= 80014}? tsOptionEncryption
;
tsOptionInitialSize:
INITIAL_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
;
tsOptionUndoRedoBufferSize:
(UNDO_BUFFER_SIZE_SYMBOL | REDO_BUFFER_SIZE_SYMBOL) EQUAL_OPERATOR? sizeNumber
;
tsOptionAutoextendSize:
AUTOEXTEND_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
;
tsOptionMaxSize:
MAX_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
;
tsOptionExtentSize:
EXTENT_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
;
tsOptionNodegroup:
NODEGROUP_SYMBOL EQUAL_OPERATOR? real_ulong_number
;
tsOptionEngine:
STORAGE_SYMBOL? ENGINE_SYMBOL EQUAL_OPERATOR? engineRef
;
tsOptionWait: (WAIT_SYMBOL | NO_WAIT_SYMBOL)
;
tsOptionComment:
COMMENT_SYMBOL EQUAL_OPERATOR? textLiteral
;
tsOptionFileblockSize:
FILE_BLOCK_SIZE_SYMBOL EQUAL_OPERATOR? sizeNumber
;
tsOptionEncryption:
ENCRYPTION_SYMBOL EQUAL_OPERATOR? textStringLiteral
;
createView:
viewReplaceOrAlgorithm? definerClause? viewSuid? VIEW_SYMBOL viewName viewTail
;
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)
;
createTrigger:
definerClause? TRIGGER_SYMBOL triggerName timing = (BEFORE_SYMBOL | AFTER_SYMBOL) event = (
INSERT_SYMBOL
| UPDATE_SYMBOL
| DELETE_SYMBOL
) ON_SYMBOL tableRef FOR_SYMBOL EACH_SYMBOL ROW_SYMBOL triggerFollowsPrecedesClause? compoundStatement
;
triggerFollowsPrecedesClause:
{serverVersion >= 50700}? ordering = (FOLLOWS_SYMBOL | PRECEDES_SYMBOL) textOrIdentifier // not a trigger reference!
;
createEvent:
definerClause? EVENT_SYMBOL ifNotExists? eventName ON_SYMBOL SCHEDULE_SYMBOL schedule (
ON_SYMBOL COMPLETION_SYMBOL NOT_SYMBOL? PRESERVE_SYMBOL
)? (ENABLE_SYMBOL | DISABLE_SYMBOL (ON_SYMBOL SLAVE_SYMBOL)?)? (
COMMENT_SYMBOL textLiteral
)? DO_SYMBOL compoundStatement
;
createRole:
// The server grammar has a clear_privileges rule here, which is only used to clear internal state.
ROLE_SYMBOL ifNotExists? roleList
;
createSpatialReference:
OR_SYMBOL REPLACE_SYMBOL SPATIAL_SYMBOL REFERENCE_SYMBOL SYSTEM_SYMBOL real_ulonglong_number srsAttribute*
| SPATIAL_SYMBOL REFERENCE_SYMBOL SYSTEM_SYMBOL ifNotExists? real_ulonglong_number srsAttribute*
;
srsAttribute:
NAME_SYMBOL TEXT_SYMBOL textStringNoLinebreak
| DEFINITION_SYMBOL TEXT_SYMBOL textStringNoLinebreak
| ORGANIZATION_SYMBOL textStringNoLinebreak IDENTIFIED_SYMBOL BY_SYMBOL real_ulonglong_number
| DESCRIPTION_SYMBOL TEXT_SYMBOL textStringNoLinebreak
;
//----------------------------------------------------------------------------------------------------------------------
dropStatement:
DROP_SYMBOL (
dropDatabase
| dropEvent
| dropFunction
| dropProcedure
| dropIndex
| dropLogfileGroup
| dropServer
| dropTable
| dropTableSpace
| dropTrigger
| dropView
| {serverVersion >= 80000}? dropRole
| {serverVersion >= 80011}? dropSpatialReference
| {serverVersion >= 80014}? dropUndoTablespace
)
;
dropDatabase:
DATABASE_SYMBOL ifExists? schemaRef
;
dropEvent:
EVENT_SYMBOL ifExists? eventRef
;
dropFunction:
FUNCTION_SYMBOL ifExists? functionRef // Including UDFs.
;
dropProcedure:
PROCEDURE_SYMBOL ifExists? procedureRef
;
dropIndex:
onlineOption? type = INDEX_SYMBOL indexRef ON_SYMBOL tableRef indexLockAndAlgorithm?
;
dropLogfileGroup:
LOGFILE_SYMBOL GROUP_SYMBOL logfileGroupRef (
dropLogfileGroupOption (COMMA_SYMBOL? dropLogfileGroupOption)*
)?
;
dropLogfileGroupOption:
tsOptionWait
| tsOptionEngine
;
dropServer:
SERVER_SYMBOL ifExists? serverRef
;
dropTable:
TEMPORARY_SYMBOL? type = (TABLE_SYMBOL | TABLES_SYMBOL) ifExists? tableRefList (
RESTRICT_SYMBOL
| CASCADE_SYMBOL
)?
;
dropTableSpace:
TABLESPACE_SYMBOL tablespaceRef (
dropLogfileGroupOption (COMMA_SYMBOL? dropLogfileGroupOption)*
)?
;
dropTrigger:
TRIGGER_SYMBOL ifExists? triggerRef
;
dropView:
VIEW_SYMBOL ifExists? viewRefList (RESTRICT_SYMBOL | CASCADE_SYMBOL)?
;
dropRole:
ROLE_SYMBOL ifExists? roleList
;
dropSpatialReference:
SPATIAL_SYMBOL REFERENCE_SYMBOL SYSTEM_SYMBOL ifExists? real_ulonglong_number
;
dropUndoTablespace:
UNDO_SYMBOL TABLESPACE_SYMBOL tablespaceRef undoTableSpaceOptions?
;
//----------------------------------------------------------------------------------------------------------------------
renameTableStatement:
RENAME_SYMBOL (TABLE_SYMBOL | TABLES_SYMBOL) renamePair (COMMA_SYMBOL renamePair)*
;
renamePair:
tableRef TO_SYMBOL tableName
;
//----------------------------------------------------------------------------------------------------------------------
truncateTableStatement:
TRUNCATE_SYMBOL TABLE_SYMBOL? tableRef
;
//----------------------------------------------------------------------------------------------------------------------
importStatement:
IMPORT_SYMBOL TABLE_SYMBOL FROM_SYMBOL textStringLiteralList
;
//--------------- DML statements ---------------------------------------------------------------------------------------
callStatement:
CALL_SYMBOL procedureRef (OPEN_PAR_SYMBOL exprList? CLOSE_PAR_SYMBOL)?
;
deleteStatement:
({serverVersion >= 80000}? withClause)? DELETE_SYMBOL deleteStatementOption* (
FROM_SYMBOL (
tableAliasRefList USING_SYMBOL tableReferenceList whereClause? // Multi table variant 1.
| tableRef ({serverVersion >= 80017}? tableAlias)? partitionDelete?
whereClause? orderClause? simpleLimitClause? // Single table delete.
)
| tableAliasRefList FROM_SYMBOL tableReferenceList whereClause? // Multi table variant 2.
)
;
partitionDelete:
{serverVersion >= 50602}? PARTITION_SYMBOL OPEN_PAR_SYMBOL identifierList CLOSE_PAR_SYMBOL
;
deleteStatementOption: // opt_delete_option in sql_yacc.yy, but the name collides with another rule (delete_options).
QUICK_SYMBOL
| LOW_PRIORITY_SYMBOL
| QUICK_SYMBOL
| IGNORE_SYMBOL
;
doStatement:
DO_SYMBOL (
{serverVersion < 50709}? exprList
| {serverVersion >= 50709}? selectItemList
)
;
handlerStatement:
HANDLER_SYMBOL (
tableRef OPEN_SYMBOL tableAlias?
| identifier (
CLOSE_SYMBOL
| READ_SYMBOL handlerReadOrScan whereClause? limitClause?
)
)
;
handlerReadOrScan:
(FIRST_SYMBOL | NEXT_SYMBOL) // Scan function.
| identifier (
// The rkey part.
(FIRST_SYMBOL | NEXT_SYMBOL | PREV_SYMBOL | LAST_SYMBOL)
| (
EQUAL_OPERATOR
| LESS_THAN_OPERATOR
| GREATER_THAN_OPERATOR
| LESS_OR_EQUAL_OPERATOR
| GREATER_OR_EQUAL_OPERATOR
) OPEN_PAR_SYMBOL values CLOSE_PAR_SYMBOL
)
;
//----------------------------------------------------------------------------------------------------------------------
insertStatement:
INSERT_SYMBOL insertLockOption? IGNORE_SYMBOL? INTO_SYMBOL? tableRef usePartition? (
insertFromConstructor ({ serverVersion >= 80018}? valuesReference)?
| SET_SYMBOL updateList ({ serverVersion >= 80018}? valuesReference)?
| insertQueryExpression
) insertUpdateList?
;
insertLockOption:
LOW_PRIORITY_SYMBOL
| DELAYED_SYMBOL // Only allowed if no select is used. Check in the semantic phase.
| HIGH_PRIORITY_SYMBOL
;
insertFromConstructor:
(OPEN_PAR_SYMBOL fields? CLOSE_PAR_SYMBOL)? insertValues
;
fields:
insertIdentifier (COMMA_SYMBOL insertIdentifier)*
;
insertValues:
(VALUES_SYMBOL | VALUE_SYMBOL) valueList
;
insertQueryExpression:
queryExpressionOrParens
| OPEN_PAR_SYMBOL fields? CLOSE_PAR_SYMBOL queryExpressionOrParens
;
valueList:
OPEN_PAR_SYMBOL values? CLOSE_PAR_SYMBOL (
COMMA_SYMBOL OPEN_PAR_SYMBOL values? CLOSE_PAR_SYMBOL
)*
;
values:
(expr | DEFAULT_SYMBOL) (COMMA_SYMBOL (expr | DEFAULT_SYMBOL))*
;
valuesReference:
AS_SYMBOL identifier columnInternalRefList?
;
insertUpdateList:
ON_SYMBOL DUPLICATE_SYMBOL KEY_SYMBOL UPDATE_SYMBOL updateList
;
//----------------------------------------------------------------------------------------------------------------------
loadStatement:
LOAD_SYMBOL dataOrXml (LOW_PRIORITY_SYMBOL | CONCURRENT_SYMBOL)? LOCAL_SYMBOL? INFILE_SYMBOL textLiteral (
REPLACE_SYMBOL
| IGNORE_SYMBOL
)? INTO_SYMBOL TABLE_SYMBOL tableRef usePartition? charsetClause? xmlRowsIdentifiedBy? fieldsClause? linesClause?
loadDataFileTail
;
dataOrXml:
DATA_SYMBOL
| XML_SYMBOL
;
xmlRowsIdentifiedBy:
ROWS_SYMBOL IDENTIFIED_SYMBOL BY_SYMBOL textString
;
loadDataFileTail:
(IGNORE_SYMBOL INT_NUMBER (LINES_SYMBOL | ROWS_SYMBOL))? loadDataFileTargetList? (
SET_SYMBOL updateList
)?
;
loadDataFileTargetList:
OPEN_PAR_SYMBOL fieldOrVariableList? CLOSE_PAR_SYMBOL
;
fieldOrVariableList:
(columnRef | userVariable) (COMMA_SYMBOL (columnRef | userVariable))*
;
//----------------------------------------------------------------------------------------------------------------------
replaceStatement:
REPLACE_SYMBOL (LOW_PRIORITY_SYMBOL | DELAYED_SYMBOL)? INTO_SYMBOL? tableRef usePartition? (
insertFromConstructor
| SET_SYMBOL updateList
| insertQueryExpression
)
;
//----------------------------------------------------------------------------------------------------------------------
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