forked from square/mysql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.y.rb
1384 lines (1192 loc) · 48 KB
/
mysql.y.rb
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
class MySQLParser
options no_result_var
rule
root : S r_commands {
call(:root, nil, val)
}
r_commands :
r_ALTER_TABLE { call(:r_commands, :ALTER_TABLE, val) }
| r_CREATE_TABLE { call(:r_commands, :CREATE_TABLE, val) }
| r_DROP_TABLE { call(:r_commands, :DROP_TABLE, val) }
| r_DROP_VIEW { call(:r_commands, :DROP_VIEW, val) }
| r_CREATE_VIEW { call(:r_commands, :CREATE_VIEW, val) }
| r_TRUNCATE_TABLE { call(:r_commands, :TRUNCATE_TABLE, val) }
| r_CREATE_INDEX { call(:r_commands, :CREATE_INDEX, val) }
| r_DROP_INDEX { call(:r_commands, :DROP_INDEX, val) }
# ===========================
# ======= CREATE VIEW =======
# ===========================
r_CREATE_VIEW :
CREATE S r_opt_OR_REPLACE r_opt_ALGORITHM_with_val r_opt_DEFINER_with_val
r_opt_SQL_SECURITY VIEW S r_view_name r_opt_COLUMN_list AS S star
{ call(:r_CREATE_VIEW, nil, val) } # incomplete grammar
r_opt_COLUMN_list :
{ call(:r_opt_COLUMN_list, :empty, val) }
| left_paren r_comma_separated_col_name right_paren
{ call(:r_opt_COLUMN_list, :body, val) }
r_opt_OR_REPLACE :
{ call(:r_opt_OR_REPLACE, :empty, val) }
| OR S REPLACE S
{ call(:r_opt_OR_REPLACE, :body, val) }
r_opt_ALGORITHM_with_val :
{ call(:r_opt_ALGORITHM_with_val, :empty, val) }
| ALGORITHM S equal UNDEFINED S
{ call(:r_opt_ALGORITHM_with_val, :UNDEFINED, val) }
| ALGORITHM S equal MERGE S
{ call(:r_opt_ALGORITHM_with_val, :MERGE, val) }
| ALGORITHM S equal TEMPTABLE S
{ call(:r_opt_ALGORITHM_with_val, :TEMPTABLE, val) }
r_opt_DEFINER_with_val :
{ call(:r_opt_DEFINER_with_val, :empty, val) }
| DEFINER S equal r_user_name
{ call(:r_opt_DEFINER_with_val, :user_name, val) }
| DEFINER S equal CURRENT_USER S
{ call(:r_opt_DEFINER_with_val, :CURRENT_USER, val) }
r_opt_SQL_SECURITY :
{ call(:r_opt_SQL_SECURITY, :empty, val) }
| SQL S SECURITY S DEFINER S
{ call(:r_opt_SQL_SECURITY, :DEFINER, val) }
| SQL S SECURITY S INVOKER S
{ call(:r_opt_SQL_SECURITY, :INVOKER, val) }
# =========================
# ======= DROP VIEW =======
# =========================
r_DROP_VIEW :
DROP S VIEW S r_opt_IF_EXISTS r_comma_separated_view_name
r_opt_RESTRICT_or_CASCADE
{ call(:r_DROP_VIEW, nil, val) }
r_opt_IF_EXISTS :
{ call(:r_opt_IF_EXISTS, :empty, val) }
| IF S EXISTS S
{ call(:r_opt_IF_EXISTS, :body, val) }
r_opt_RESTRICT_or_CASCADE :
{ call(:r_opt_RESTRICT_or_CASCADE, :empty, val) }
| r_RESTRICT_or_CASCADE
{ call(:r_opt_RESTRICT_or_CASCADE, :body, val) }
# ============================
# ======= DROP TABLE =======
# ============================
r_DROP_TABLE :
DROP S r_opt_TEMPORARY TABLE S r_opt_IF_EXISTS r_comma_separated_tbl_name
r_opt_RESTRICT_or_CASCADE
{ call(:r_DROP_TABLE, nil, val) }
# ========================
# ======= TRUNCATE =======
# ========================
r_TRUNCATE_TABLE :
TRUNCATE S r_opt_TABLE r_tbl_name
{ call(:r_TRUNCATE_TABLE, nil, val) }
# ============================
# ======= CREATE TABLE =======
# ============================
r_CREATE_TABLE :
CREATE S r_opt_TEMPORARY TABLE S r_opt_IF_NOT_EXISTS
r_tbl_name r_create_variation
{ call(:r_CREATE_TABLE, nil, val) }
r_create_variation :
r_create_definition_list r_opt_CREATE_TABLE_options r_opt_PARTITION_options
{ call(:r_create_variation, :with_list_without_select, val) }
| r_create_definition_list r_opt_CREATE_TABLE_options r_opt_PARTITION_options
r_select_statement
{ call(:r_create_variation, :with_list_with_select, val) }
| r_opt_CREATE_TABLE_options r_opt_PARTITION_options r_select_statement
{ call(:r_create_variation, :without_list_with_select, val) }
| left_paren LIKE S r_tbl_name right_paren
{ call(:r_create_variation, :LIKE_with_paren, val) }
| LIKE S r_tbl_name
{ call(:r_create_variation, :LIKE_without_paren, val) }
r_create_definition_list :
left_paren r_comma_separated_create_definition right_paren
{ call(:r_create_definition_list, nil, val) }
r_opt_TEMPORARY :
{ call(:r_opt_TEMPORARY, :empty, val) }
| TEMPORARY S
{ call(:r_opt_TEMPORARY, :body, val) }
r_opt_TABLE :
{ call(:r_opt_TABLE, :empty, val) }
| TABLE S
{ call(:r_opt_TABLE, :body, val) }
r_opt_IF_NOT_EXISTS :
{ call(:r_opt_IF_NOT_EXISTS, :empty, val) }
| IF S NOT S EXISTS S
{ call(:r_opt_IF_NOT_EXISTS, :body, val) }
r_create_definition :
r_col_name_with_definition
{ call(:r_create_definition, :col, val) }
| r_shared_create_alter
{ call(:r_create_definition, :shared_create_alter, val) }
| CHECK S {
raise 'check not supported' # incomplete grammar
}
r_col_name_with_definition :
r_col_name r_column_definition
{ call(:r_col_name_with_definition, nil, val) }
# =====================
# ======= ALTER =======
# =====================
r_ALTER_TABLE :
ALTER S r_opt_ONLINE_OFFLINE r_opt_IGNORE TABLE S r_tbl_name
r_opt_alter_commands r_opt_after_alter r_opt_PARTITION_options
{ call(:r_ALTER_TABLE, nil, val) }
r_opt_ONLINE_OFFLINE :
{ call(:r_opt_ONLINE_OFFLINE, :empty, val) }
| ONLINE S
{ call(:r_opt_ONLINE_OFFLINE, :ONLINE, val) }
| OFFLINE S
{ call(:r_opt_ONLINE_OFFLINE, :OFFLINE, val) }
r_opt_IGNORE :
{ call(:r_opt_IGNORE, :empty, val) }
| IGNORE S
{ call(:r_opt_IGNORE, :body, val) }
r_opt_alter_commands :
{ call(:r_opt_alter_commands, :empty, val) }
| r_comma_separated_alter_specification
{ call(:r_opt_alter_commands, :list, val) }
| r_single_alter_specification
{ call(:r_opt_alter_commands, :single, val) }
r_ROW_FORMAT_option :
DEFAULT S { call(:r_ROW_FORMAT_option, :DEFAULT, val) }
| DYNAMIC S { call(:r_ROW_FORMAT_option, :DYNAMIC, val) }
| COMPRESSED S { call(:r_ROW_FORMAT_option, :COMPRESSED, val) }
| FIXED S { call(:r_ROW_FORMAT_option, :FIXED, val) }
| REDUNDANT S { call(:r_ROW_FORMAT_option, :REDUNDANT, val) }
| COMPACT S { call(:r_ROW_FORMAT_option, :COMPACT, val) }
r_opt_CREATE_TABLE_options :
{ call(:r_opt_CREATE_TABLE_options, :empty, val) }
| r_space_or_comma_separated_table_option
{ call(:r_opt_CREATE_TABLE_options, :body, val) }
r_opt_PARTITION_options :
{ call(:r_opt_PARTITION_options, :empty, val) }
| REMOVE S PARTITIONING S
{ call(:r_opt_PARTITION_options, :REMOVE, val) }
# not on the list, but it fits
| PARTITION S BY S # incomplete grammar
{ call(:r_opt_PARTITION_options, :PARTITION, val) }
r_select_statement : # incomplete grammar
r_opt_IGNORE_or_REPLACE r_opt_AS SELECT S star
{ call(:r_select_statement, nil, val) }
r_shared_create_alter :
r_opt_CONSTRAINT_with_val PRIMARY S KEY S r_alter_index_opt
{ call(:r_shared_create_alter, :PRIMARY, val) }
| r_INDEX_or_KEY r_opt_index_name r_alter_index_opt
{ call(:r_shared_create_alter, :alter_index, val) }
| r_opt_CONSTRAINT_with_val UNIQUE S r_opt_INDEX_or_KEY r_opt_index_name
r_alter_index_opt
{ call(:r_shared_create_alter, :UNIQUE, val) }
| FULLTEXT S r_opt_INDEX_or_KEY r_opt_index_name r_alter_index_opt
{ call(:r_shared_create_alter, :FULLTEXT, val) }
| SPATIAL S r_opt_INDEX_or_KEY r_opt_index_name r_alter_index_opt
{ call(:r_shared_create_alter, :SPATIAL, val) }
| r_opt_CONSTRAINT_with_val FOREIGN S KEY S r_opt_index_name r_alter_index_opt r_REFERENCES_definition
{ call(:r_shared_create_alter, :FOREIGN_KEY, val) }
r_alter_specification :
r_space_separated_alter_table_option
{ call(:r_alter_specification, :table_options, val) }
| ADD S r_opt_COLUMN r_col_name r_column_definition r_opt_pos_column
{ call(:r_alter_specification, :ADD_col, val) }
| ADD S r_opt_COLUMN left_paren r_comma_separated_add_col right_paren
{ call(:r_alter_specification, :ADD_cols, val) }
| ADD S r_shared_create_alter
{ call(:r_alter_specification, :ADD_shared, val) }
| ALTER S r_opt_COLUMN r_col_name r_SET_or_DROP_DEFAULT
{ call(:r_alter_specification, :ALTER_col_SET_or_DROP_DEFAULT, val) }
| CHANGE S r_opt_COLUMN r_col_name r_col_name r_column_definition
r_opt_pos_column
{ call(:r_alter_specification, :CHANGE_col, val) }
| DROP S r_opt_COLUMN r_col_name
{ call(:r_alter_specification, :DROP_col, val) }
| DROP S FOREIGN S KEY S r_fk_symbol
{ call(:r_alter_specification, :DROP_FOREIGN_KEY, val) }
| DISABLE S KEYS S
{ call(:r_alter_specification, :DISABLE_KEYS, val) }
| ENABLE S KEYS S
{ call(:r_alter_specification, :ENABLE_KEYS, val) }
| RENAME S r_opt_TO_or_AS r_tbl_name
{ call(:r_alter_specification, :RENAME, val) }
| CONVERT S TO S L_CHARACTER_SET S r_charset_name opt_COLLATE_with_val
{ call(:r_alter_specification, :CONVERT, val) }
| r_CHARACTER_SET_equal_with_val COLLATE S opt_equal r_collation_name
{ call(:r_alter_specification, :CHARACTER_SET_COLLATE, val) }
# enforce to have collate -- the opt case is handle by table_option
| DROP S r_INDEX_or_KEY r_index_name
{ call(:r_alter_specification, :DROP_index, val) }
| MODIFY S r_opt_COLUMN r_col_name r_column_definition r_opt_pos_column
{ call(:r_alter_specification, :MODIFY_col, val) }
| DROP S PRIMARY S KEY S
{ call(:r_alter_specification, :DROP_PRIMARY_KEY, val) }
r_opt_after_alter :
{ call(:r_opt_after_alter, :empty, val) }
| ORDER S BY S r_comma_separated_col_name
{ call(:r_opt_after_alter, :ORDER_BY, val) }
r_DATA_DIRECTORY_equal_with_val :
DATA S DIRECTORY S opt_equal string
{ call(:r_DATA_DIRECTORY_equal_with_val, nil, val) }
r_INDEX_DIRECTORY_equal_with_val :
INDEX S DIRECTORY S opt_equal string
{ call(:r_INDEX_DIRECTORY_equal_with_val, nil, val) }
# ref: https://dev.mysql.com/doc/refman/5.1/en/create-table.html
r_shared_table_option :
AUTO_INCREMENT S opt_equal nat
{ call(:r_shared_table_option, :AUTO_INCREMENT, val) }
| AVG_ROW_LENGTH S opt_equal nat
{ call(:r_shared_table_option, :AVG_ROW_LENGTH, val) }
| r_CHARACTER_SET_equal_with_val
{ call(:r_shared_table_option, :CHARACTER_SET, val) }
| CHECKSUM S opt_equal binary
{ call(:r_shared_table_option, :CHECKSUM, val) }
| CONNECTION S opt_equal string
{ call(:r_shared_table_option, :CONNECTION, val) }
| DELAY_KEY_WRITE S opt_equal binary
{ call(:r_shared_table_option, :DELAY_KEY_WRITE, val) }
| INSERT_METHOD S opt_equal r_NO_or_FIRST_or_LAST
{ call(:r_shared_table_option, :INSERT_METHOD, val) }
| PACK_KEYS S opt_equal r_binary_or_DEFAULT
{ call(:r_shared_table_option, :PACK_KEYS, val) }
| PASSWORD S opt_equal string
{ call(:r_shared_table_option, :PASSWORD, val) }
| ROW_FORMAT S opt_equal r_ROW_FORMAT_option
{ call(:r_shared_table_option, :ROW_FORMAT, val) }
| TABLESPACE S r_tablespace_name r_opt_STORAGE_option
{ call(:r_shared_table_option, :TABLESPACE, val) }
| UNION S opt_equal left_paren opt_equal
r_comma_separated_tbl_name right_paren
{ call(:r_shared_table_option, :UNION, val) }
| KEY_BLOCK_SIZE S opt_equal nat
{ call(:r_shared_table_option, :KEY_BLOCK_SIZE, val) }
| r_COMMENT_equal_with_val
{ call(:r_shared_table_option, :COMMENT, val) }
| r_DATA_DIRECTORY_equal_with_val
{ call(:r_shared_table_option, :DATA_DIRECTORY, val) }
| r_INDEX_DIRECTORY_equal_with_val
{ call(:r_shared_table_option, :INDEX_DIRECTORY, val) }
| r_MAX_ROWS_equal_with_val
{ call(:r_shared_table_option, :MAX_ROWS, val) }
| r_MIN_ROWS_equal_with_val
{ call(:r_shared_table_option, :MIN_ROWS, val) }
| r_ENGINE_equal_with_val
{ call(:r_shared_table_option, :ENGINE, val) }
r_CREATE_TABLE_option :
r_shared_table_option
{ call(:r_CREATE_TABLE_option, :shared, val) }
| r_opt_DEFAULT COLLATE S opt_equal r_collation_name
{ call(:r_CREATE_TABLE_option, :COLLATE, val) }
# include COLLATE command specifically because alter's COLLATE and
# create's COLLATE are different.
r_alter_table_option :
r_shared_table_option
{ call(:r_alter_table_option, nil, val) }
# exclude COLLATE command specifically. It is in r_alter_specification already
r_opt_NODEGROUP_equal_with_val :
{ call(:r_opt_NODEGROUP_equal_with_val, :empty, val) }
| NODEGROUP S
{ call(:r_opt_NODEGROUP_equal_with_val, :body, val) }
r_single_alter_specification :
DISCARD S TABLESPACE S
{ call(:r_single_alter_specification, :DISCARD_TABLESPACE, val) }
| IMPORT S TABLESPACE S
{ call(:r_single_alter_specification, :IMPORT_TABLESPACE, val) }
| ADD S PARTITION S left_paren r_partition_definition right_paren
{ call(:r_single_alter_specification, :ADD_PARTITION, val) }
| DROP S PARTITION S r_comma_separated_partition_name
{ call(:r_single_alter_specification, :DROP_PARTITION, val) }
| REBUILD S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :REBUILD_PARTITION, val) }
| OPTIMIZE S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :OPTIMIZE_PARTITION, val) }
| ANALYZE S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :ANALYZE_PARTITION, val) }
| CHECK S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :CHECK_PARTITION, val) }
| REPAIR S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :REPAIR_PARTITION, val) }
| COALESCE S PARTITION S nat
{ call(:r_single_alter_specification, :COALESCE_PARTITION, val) }
| TRUNCATE S PARTITION S r_partition_name_list_or_ALL
{ call(:r_single_alter_specification, :TRUNCATE_PARTITION, val) }
| REORGANIZE S PARTITION S r_opt_partition_names_INTO_definitions
{ call(:r_single_alter_specification, :REORGANIZE_PARTITION, val) }
r_opt_CONSTRAINT_with_val :
{ call(:r_opt_CONSTRAINT_with_val, :empty, val) }
| CONSTRAINT S
{ call(:r_opt_CONSTRAINT_with_val, :CONTRAINT_without_symbol, val) }
| CONSTRAINT S symbol
{ call(:r_opt_CONSTRAINT_with_val, :CONTRAINT_with_symbol, val) }
r_CHARACTER_SET_equal_with_val :
r_opt_DEFAULT L_CHARACTER_SET S opt_equal r_charset_name
{ call(:r_CHARACTER_SET_equal_with_val, nil, val) }
r_alter_index_opt :
r_opt_index_type left_paren r_comma_separated_index_col_name right_paren
r_opt_space_separated_index_option
{ call(:r_alter_index_opt, nil, val) }
r_opt_INDEX_or_KEY :
{ call(:r_opt_INDEX_or_KEY, :empty, val) }
| r_INDEX_or_KEY
{ call(:r_opt_INDEX_or_KEY, :body, val) }
r_INDEX_or_KEY :
INDEX S
{ call(:r_INDEX_or_KEY, :INDEX, val) }
| KEY S
{ call(:r_INDEX_or_KEY, :KEY, val) }
r_opt_index_name :
{ call(:r_opt_index_name, :empty, val) }
| r_index_name
{ call(:r_opt_index_name, :body, val) }
r_opt_index_type :
{ call(:r_opt_index_type, :empty, val) }
| r_index_type
{ call(:r_opt_index_type, :body, val) }
r_index_type :
USING S BTREE S
{ call(:r_index_type, :BTREE, val) }
| USING S HASH S
{ call(:r_index_type, :HASH, val) }
r_index_option :
r_index_type
{ call(:r_index_option, :index_type, val) }
| KEY_BLOCK_SIZE S opt_equal nat
{ call(:r_index_option, :KEY_BLOCK_SIZE, val) }
| WITH S PARSER S r_parser_name
{ call(:r_index_option, :WITH_PARSER, val) }
r_SET_or_DROP_DEFAULT :
SET S DEFAULT S literal
{ call(:r_SET_or_DROP_DEFAULT, :SET, val) }
| DROP S DEFAULT S
{ call(:r_SET_or_DROP_DEFAULT, :DROP, val) }
r_opt_COLUMN :
{ call(:r_opt_COLUMN, :empty, val) }
| COLUMN S
{ call(:r_opt_COLUMN, :body, val) }
r_column_definition :
r_datatype r_opt_column_attribute
{ call(:r_column_definition, nil, val) }
r_opt_column_attribute :
{ call(:r_opt_column_attribute, :empty, val) }
| r_space_separated_column_attribute { call(:r_opt_column_attribute, :column_attributes, val) }
r_column_attribute :
r_NULL_status { call(:r_column_attribute, :NULL_status, val) }
| r_DEFAULT_with_val { call(:r_column_attribute, :DEFAULT, val) }
| r_DEFAULT_with_expr { call(:r_column_attribute, :DEFAULT, val) }
| r_AUTO_INCREMENT { call(:r_column_attribute, :AUTO_INCREMENT, val) }
| r_UNIQUE_or_PRIMARY { call(:r_column_attribute, :UNIQUE_or_PRIMARY, val) }
| r_COMMENT_with_val { call(:r_column_attribute, :COMMENT, val) }
| r_COLUMN_FORMAT { call(:r_column_attribute, :COLUMN_FORMAT, val) }
| r_STORAGE { call(:r_column_attribute, :STORAGE, val) }
| r_COLUMN_ON_UPDATE { call(:r_column_attribute, :COLUMN_ON_UPDATE, val) }
| r_COLUMN_GENERATED_ALWAYS { call(:r_column_attribute, :COLUMN_GENERATED_ALWAYS, val) }
# ============================
# ======= CREATE INDEX =======
# ============================
r_CREATE_INDEX :
CREATE S r_opt_ONLINE_OFFLINE r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL
INDEX S r_index_name r_opt_index_type ON S r_tbl_name
left_paren r_comma_separated_index_col_name right_paren
r_opt_index_option
{ call(:r_CREATE_INDEX, nil, val) }
r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL :
{ call(:r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL, :empty, val) }
| UNIQUE S
{ call(:r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL, :UNIQUE, val) }
| FULLTEXT S
{ call(:r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL, :FULLTEXT, val) }
| SPATIAL S
{ call(:r_opt_UNIQUE_or_FULLTEXT_or_SPATIAL, :SPATIAL, val) }
r_opt_index_option :
{ call(:r_opt_index_option, :empty, val) }
| r_index_option
{ call(:r_opt_index_option, :index_option, val) }
# ==========================
# ======= DROP INDEX =======
# ==========================
r_DROP_INDEX :
DROP S INDEX S r_opt_ONLINE_OFFLINE r_index_name ON S r_tbl_name
{ call(:r_DROP_INDEX, nil, val) }
# ========================
# ======= DATATYPE =======
# ========================
r_opt_datatype_number :
{ call(:r_opt_datatype_number, :empty, val) }
| r_length_int
{ call(:r_opt_datatype_number, :int, val) }
| r_length_real
{ call(:r_opt_datatype_number, :real, val) }
r_opt_datatype_int :
r_opt_length_int r_opt_UNSIGNED r_opt_ZEROFILL
{ call(:r_opt_datatype_int, nil, val) }
r_opt_datatype_real :
r_opt_length_real r_opt_UNSIGNED r_opt_ZEROFILL
{ call(:r_opt_datatype_real, nil, val) }
r_opt_datatype_char :
r_opt_BINARY r_opt_CHARACTER_SET_with_val opt_COLLATE_with_val
{ call(:r_opt_datatype_char, nil, val) }
r_opt_datatype_linestring :
r_opt_SRID_with_val
{ call(:r_opt_datatype_linestring, nil, val) }
r_opt_length_int :
{ call(:r_opt_length_int, :empty, val) }
| r_length_int
{ call(:r_opt_length_int, :body, val) }
r_opt_length_real :
{ call(:r_opt_length_real, :empty, val) }
| r_length_real
{ call(:r_opt_length_real, :body, val) }
r_length_int :
left_paren nat right_paren
{ call(:r_length_int, nil, val) }
r_length_real :
left_paren nat comma nat right_paren
{ call(:r_length_real, nil, val) }
r_opt_UNSIGNED :
{ call(:r_opt_UNSIGNED, :empty, val) }
| UNSIGNED S
{ call(:r_opt_UNSIGNED, :body, val) }
r_opt_ZEROFILL :
{ call(:r_opt_ZEROFILL, :empty, val) }
| ZEROFILL S
{ call(:r_opt_ZEROFILL, :body, val) }
r_opt_BINARY :
{ call(:r_opt_BINARY, :empty, val) }
| BINARY S
{ call(:r_opt_BINARY, :body, val) }
r_NULL_status :
NOT S null
{ call(:r_NULL_status, :NOT_NULL, val) }
| null
{ call(:r_NULL_status, :NULL, val) }
r_DEFAULT_with_val :
DEFAULT S value
{ call(:r_DEFAULT_with_val, :body, val) }
r_DEFAULT_with_expr :
DEFAULT S left_paren r_func_call_empty right_paren
{ call(:r_DEFAULT_with_expr, :body, val) }
| DEFAULT S left_paren string right_paren
{ call(:r_DEFAULT_with_expr, :body, val) }
r_AUTO_INCREMENT :
AUTO_INCREMENT S
{ call(:r_AUTO_INCREMENT, :body, val) }
r_UNIQUE_or_PRIMARY :
UNIQUE S
{ call(:r_UNIQUE_or_PRIMARY, :UNIQUE, val) }
| UNIQUE S KEY S
{ call(:r_UNIQUE_or_PRIMARY, :UNIQUE_KEY, val) }
| PRIMARY S
{ call(:r_UNIQUE_or_PRIMARY, :PRIMARY, val) }
| PRIMARY S KEY S
{ call(:r_UNIQUE_or_PRIMARY, :PRIMARY_KEY, val) }
r_COMMENT_with_val :
COMMENT S string
{ call(:r_COMMENT_with_val, :body, val) }
r_COLUMN_FORMAT :
COLUMN_FORMAT S FIXED S
{ call(:r_COLUMN_FORMAT, :FIXED, val) }
| COLUMN_FORMAT S DYNAMIC S
{ call(:r_COLUMN_FORMAT, :DYNAMIC, val) }
| COLUMN_FORMAT S DEFAULT S
{ call(:r_COLUMN_FORMAT, :DEFAULT, val) }
r_STORAGE :
STORAGE S DISK S
{ call(:r_STORAGE, :DISK, val) }
| STORAGE S MEMORY S
{ call(:r_STORAGE, :MEMORY, val) }
| STORAGE S DEFAULT S
{ call(:r_STORAGE, :DEFAULT, val) }
r_REFERENCES_definition :
REFERENCES S r_tbl_name left_paren r_comma_separated_index_col_name
right_paren r_opt_MATCH r_opt_ON_DELETE_and_UPDATE
{ call(:r_REFERENCES_definition, :body, val) }
r_opt_MATCH :
{ call(:r_opt_MATCH, :empty, val) }
| MATCH S FULL S
{ call(:r_opt_MATCH, :FULL, val) }
| MATCH S PARTIAL S
{ call(:r_opt_MATCH, :PARTIAL, val) }
| MATCH S SIMPLE S
{ call(:r_opt_MATCH, :SIMPLE, val) }
r_opt_ASC_or_DESC :
{ call(:r_opt_ASC_or_DESC, :empty, val) }
| ASC S
{ call(:r_opt_ASC_or_DESC, :ASC, val) }
| DESC S
{ call(:r_opt_ASC_or_DESC, :DESC, val) }
r_opt_ON_DELETE_and_UPDATE :
{ call(:r_opt_ON_DELETE_and_UPDATE, :empty, val) }
| ON S DELETE S r_reference_option
{ call(:r_opt_ON_DELETE_and_UPDATE, :DELETE, val) }
| ON S DELETE S r_reference_option
ON S UPDATE S r_reference_option
{ call(:r_opt_ON_DELETE_and_UPDATE, :DELETE_UPDATE, val) }
| ON S UPDATE S r_reference_option
{ call(:r_opt_ON_DELETE_and_UPDATE, :UPDATE, val) }
r_COLUMN_ON_UPDATE :
ON S UPDATE S literal
{ call(:r_COLUMN_ON_UPDATE, :UPDATE, val) }
r_COLUMN_GENERATED_ALWAYS :
GENERATED S ALWAYS S AS star
{ call(:r_COLUMN_GENERATED_ALWAYS, :GENERATED_ALWAYS, val) }
r_RESTRICT_or_CASCADE :
RESTRICT S
{ call(:r_RESTRICT_or_CASCADE, :RESTRICT, val) }
| CASCADE S
{ call(:r_RESTRICT_or_CASCADE, :CASCADE, val) }
r_reference_option :
r_RESTRICT_or_CASCADE
{ call(:r_reference_option, :RESTRICT_or_CASCADE, val) }
| SET S null
{ call(:r_reference_option, :SET, val) }
| NO S ACTION S
{ call(:r_reference_option, :NO_ACTION, val) }
r_opt_TO_or_AS :
{ call(:r_opt_TO_or_AS, :empty, val) }
| AS S
{ call(:r_opt_TO_or_AS, :AS, val) }
| TO S
{ call(:r_opt_TO_or_AS, :TO, val) }
r_opt_AS :
{ call(:r_opt_AS, :empty, val) }
| AS S
{ call(:r_opt_AS, :AS, val) }
r_opt_CHARACTER_SET_with_val :
{ call(:r_opt_CHARACTER_SET_with_val, :empty, val) }
| L_CHARACTER_SET S r_charset_name
{ call(:r_opt_CHARACTER_SET_with_val, :body, val) }
opt_COLLATE_with_val :
{ call(:opt_COLLATE_with_val, :empty, val) }
| COLLATE S r_collation_name
{ call(:opt_COLLATE_with_val, :body, val) }
r_opt_SRID_with_val :
{ call(:r_opt_SRID_with_val, :empty, val) }
| SRID S integer
{ call(:r_opt_SRID_with_val, :body, val) }
r_opt_pos_column :
{ call(:r_opt_pos_column, :empty, val) }
| FIRST S
{ call(:r_opt_pos_column, :FIRST, val) }
| AFTER S r_col_name
{ call(:r_opt_pos_column, :AFTER, val) }
r_binary_or_DEFAULT :
DEFAULT S
{ call(:r_binary_or_DEFAULT, :DEFAULT, val) }
| binary
{ call(:r_binary_or_DEFAULT, :binary, val) }
r_NO_or_FIRST_or_LAST :
NO S
{ call(:r_NO_or_FIRST_or_LAST, :NO, val) }
| FIRST S
{ call(:r_NO_or_FIRST_or_LAST, :FIRST, val) }
| LAST S
{ call(:r_NO_or_FIRST_or_LAST, :LAST, val) }
r_opt_STORAGE_option :
{ call(:r_opt_STORAGE_option, :empty, val) }
| STORAGE S DISK S
{ call(:r_opt_STORAGE_option, :DISK, val) }
| STORAGE S MEMORY S
{ call(:r_opt_STORAGE_option, :MEMORY, val) }
| STORAGE S DEFAULT S
{ call(:r_opt_STORAGE_option, :DEFAULT, val) }
r_opt_DEFAULT :
{ call(:r_opt_DEFAULT, :empty, val) }
| DEFAULT S
{ call(:r_opt_DEFAULT, :body, val) }
r_opt_COMMENT_equal_with_val :
{ call(:r_opt_COMMENT_equal_with_val, :empty, val) }
| r_COMMENT_equal_with_val
{ call(:r_opt_COMMENT_equal_with_val, :body, val) }
r_COMMENT_equal_with_val :
COMMENT S opt_equal string
{ call(:r_COMMENT_equal_with_val, nil, val) }
r_MAX_ROWS_equal_with_val :
MAX_ROWS S opt_equal nat
{ call(:r_MAX_ROWS_equal_with_val, nil, val) }
r_MIN_ROWS_equal_with_val :
MIN_ROWS S opt_equal nat
{ call(:r_MIN_ROWS_equal_with_val, nil, val) }
r_partition_definition :
PARTITION S r_partition_name r_opt_partition_values
r_partition_subpartition_share r_opt_subpartition_definition_list
{ call(:r_partition_definition, nil, val) }
r_opt_partition_values :
{ call(:r_opt_partition_values, :empty, val) }
| VALUES S LESS S THAN S MAXVALUE S
{ call(:r_opt_partition_values, :LESS_THAN_MAXVALUE, val) }
| VALUES S LESS S THAN S left_paren expr right_paren
{ call(:r_opt_partition_values, :LESS_THAN_values, val) }
| VALUES S IN S left_paren r_comma_separated_integer right_paren
{ call(:r_opt_partition_values, :IN_values, val) }
r_ENGINE_equal_with_val :
ENGINE S opt_equal r_ENGINE_name
{ call(:r_ENGINE_equal_with_val, nil, val) }
r_opt_STORAGE_ENGINE_equal_with_val :
{ call(:r_opt_STORAGE_ENGINE_equal_with_val, :empty, val) }
| STORAGE S ENGINE S opt_equal r_ENGINE_name
{ call(:r_opt_STORAGE_ENGINE_equal_with_val, :STORAGE_ENGINE, val) }
| r_ENGINE_equal_with_val
{ call(:r_opt_STORAGE_ENGINE_equal_with_val, :ENGINE, val) }
r_opt_DATA_DIRECTORY_equal_with_val :
{ call(:r_opt_DATA_DIRECTORY_equal_with_val, :empty, val) }
| r_DATA_DIRECTORY_equal_with_val
{ call(:r_opt_DATA_DIRECTORY_equal_with_val, :body, val) }
r_opt_INDEX_DIRECTORY_equal_with_val :
{ call(:r_opt_INDEX_DIRECTORY_equal_with_val, :empty, val) }
| r_INDEX_DIRECTORY_equal_with_val
{ call(:r_opt_INDEX_DIRECTORY_equal_with_val, :body, val) }
r_opt_MAX_ROWS_equal_with_val :
{ call(:r_opt_MAX_ROWS_equal_with_val, :empty, val) }
| r_MAX_ROWS_equal_with_val
{ call(:r_opt_MAX_ROWS_equal_with_val, :body, val) }
r_opt_MIN_ROWS_equal_with_val :
{ call(:r_opt_MIN_ROWS_equal_with_val, :empty, val) }
| r_MIN_ROWS_equal_with_val
{ call(:r_opt_MIN_ROWS_equal_with_val, :body, val) }
r_opt_TABLESPACE_equal_with_val :
{ call(:r_opt_TABLESPACE_equal_with_val, :empty, val) }
| TABLESPACE S opt_equal r_tablespace_name
{ call(:r_opt_TABLESPACE_equal_with_val, :body, val) }
r_subpartition_definition :
SUBPARTITION S r_logical_name r_partition_subpartition_share
{ call(:r_subpartition_definition, nil, val) }
r_partition_subpartition_share :
r_opt_STORAGE_ENGINE_equal_with_val r_opt_COMMENT_equal_with_val
r_opt_DATA_DIRECTORY_equal_with_val r_opt_INDEX_DIRECTORY_equal_with_val
r_opt_MAX_ROWS_equal_with_val r_opt_MIN_ROWS_equal_with_val
r_opt_TABLESPACE_equal_with_val r_opt_NODEGROUP_equal_with_val
{ call(:r_partition_subpartition_share, nil, val) }
r_opt_subpartition_definition_list :
{ call(:r_opt_subpartition_definition_list, :empty, val) }
| left_paren r_comma_separated_subpartition_definition right_paren
{ call(:r_opt_subpartition_definition_list, :body, val) }
r_opt_partition_names_INTO_definitions :
{ call(:r_opt_partition_names_INTO_definitions, :empty, val) }
| r_comma_separated_partition_name INTO S left_paren
r_comma_separated_partition_definition right_paren
{ call(:r_opt_partition_names_INTO_definitions, :body, val) }
r_partition_name_list_or_ALL :
ALL S
{ call(:r_partition_name_list_or_ALL, :ALL, val) }
| r_comma_separated_partition_name
{ call(:r_partition_name_list_or_ALL, :list, val) }
r_opt_IGNORE_or_REPLACE :
{ call(:r_opt_IGNORE_or_REPLACE, :empty, val) }
| IGNORE
{ call(:r_opt_IGNORE_or_REPLACE, :IGNORE, val) }
| REPLACE S
{ call(:r_opt_IGNORE_or_REPLACE, :REPLACE, val) }
# ============================================
# ======= COMMA/SPACE-SEPARATED-THINGS =======
# ============================================
r_comma_separated_col_name :
r_col_name
{ call(:r_comma_separated_col_name, :base, val) }
| r_comma_separated_col_name comma r_col_name
{ call(:r_comma_separated_col_name, :inc, val) }
r_comma_separated_tbl_name :
r_tbl_name
{ call(:r_comma_separated_tbl_name, :base, val) }
| r_comma_separated_tbl_name comma r_tbl_name
{ call(:r_comma_separated_tbl_name, :inc, val) }
r_comma_separated_index_col_name :
r_index_col_name
{ call(:r_comma_separated_index_col_name, :base, val) }
| r_comma_separated_index_col_name comma r_index_col_name
{ call(:r_comma_separated_index_col_name, :inc, val) }
r_comma_separated_add_col :
r_col_name_with_definition
{ call(:r_comma_separated_add_col, :base, val) }
| r_comma_separated_add_col comma r_col_name_with_definition
{ call(:r_comma_separated_add_col, :inc, val) }
r_comma_separated_alter_specification :
r_alter_specification
{ call(:r_comma_separated_alter_specification, :base, val) }
| r_comma_separated_alter_specification comma r_alter_specification
{ call(:r_comma_separated_alter_specification, :inc, val) }
r_comma_separated_partition_name :
r_partition_name
{ call(:r_comma_separated_partition_name, :base, val) }
| r_comma_separated_partition_name comma r_partition_name
{ call(:r_comma_separated_partition_name, :inc, val) }
r_comma_separated_subpartition_definition :
r_subpartition_definition
{ call(:r_comma_separated_subpartition_definition, :base, val) }
| r_comma_separated_subpartition_definition comma r_subpartition_definition
{ call(:r_comma_separated_subpartition_definition, :inc, val) }
r_comma_separated_partition_definition :
r_partition_definition
{ call(:r_comma_separated_partition_definition, :base, val) }
| r_comma_separated_partition_definition comma r_partition_definition
{ call(:r_comma_separated_partition_definition, :inc, val) }
r_space_separated_alter_table_option :
r_alter_table_option
{ call(:r_space_separated_alter_table_option, :base, val) }
| r_space_separated_alter_table_option r_alter_table_option
{ call(:r_space_separated_alter_table_option, :inc, val) }
# not comma separated, the comma separated one is done by the top level
r_comma_separated_view_name :
r_view_name
{ call(:r_comma_separated_view_name, :base, val) }
| r_comma_separated_view_name comma r_view_name
{ call(:r_comma_separated_view_name, :inc, val) }
r_opt_space_separated_index_option :
{ call(:r_opt_space_separated_index_option, :base, val) }
| r_opt_space_separated_index_option r_index_option
{ call(:r_opt_space_separated_index_option, :inc, val) }
r_comma_separated_integer :
integer
{ call(:r_comma_separated_integer, :base, val) }
| r_comma_separated_integer comma integer
{ call(:r_comma_separated_integer, :inc, val) }
r_comma_separated_create_definition :
r_create_definition
{ call(:r_comma_separated_create_definition, :base, val) }
| r_comma_separated_create_definition comma r_create_definition
{ call(:r_comma_separated_create_definition, :inc, val) }
r_space_or_comma_separated_table_option :
r_CREATE_TABLE_option
{ call(:r_space_or_comma_separated_table_option, :base, val) }
| r_space_or_comma_separated_table_option
opt_comma r_CREATE_TABLE_option
{ call(:r_space_or_comma_separated_table_option, :inc, val) }
r_comma_separated_string :
string
{ call(:r_comma_separated_string, :base, val) }
| r_comma_separated_string comma string
{ call(:r_comma_separated_string, :inc, val) }
r_space_separated_column_attribute :
r_column_attribute
{ call(:r_space_separated_column_attribute, :base, val) }
| r_space_separated_column_attribute r_column_attribute
{ call(:r_space_separated_column_attribute, :inc, val) }
# ==================================
# ======= ALL THE NAME THING =======
# ==================================
r_index_col_name :
r_col_name r_opt_length_int r_opt_ASC_or_DESC
{ call(:r_index_col_name, nil, val) }
r_view_name : r_tbl_name_int { call(:r_view_name, nil, val) }
r_partition_name : ident { call(:r_partition_name, nil, val) }
r_logical_name : ident { call(:r_logical_name, nil, val) }
r_parser_name : ident { call(:r_parser_name, nil, val) }
r_index_name : ident { call(:r_index_name, nil, val) }
r_tablespace_name : ident { call(:r_tablespace_name, nil, val) }
r_collation_name : raw_ident { call(:r_collation_name, nil, val) }
r_col_name : ident { call(:r_col_name, nil, val) }
r_tbl_name : r_tbl_name_int { call(:r_tbl_name, nil, val) }
r_func_call_empty :
ident left_paren right_paren
{ call(:r_func_call_empty, :empty_func_call, val) }
r_tbl_name_int :
ident
{ call(:r_tbl_name_int, :without_dot, val) }
| S_IDENT_NORMAL S_DOT ident
{ call(:r_tbl_name_int, :with_database, val) }
| S_DOT ident
{ call(:r_tbl_name_int, :with_dot, val) }
r_user_name :
r_user_name_part
{ call(:r_user_name, :without_at, val) }
| r_user_name_part S_AT r_user_name_part # no S after S_AT
{ call(:r_user_name, :with_at, val) }
r_user_name_part :
string { call(:r_user_name_part, :string, val) }
| ident { call(:r_user_name_part, :ident, val) } # could have backtick
r_fk_symbol : ident { call(:r_fk_symbol, nil, val) }
r_ENGINE_name :
INNODB S { call(:r_ENGINE_name, :INNODB, val) }
| raw_ident { call(:r_ENGINE_name, :other, val) } # TODO
r_charset_name :
LATIN1 S { call(:r_charset_name, :LATIN1, val) }
| UTF8 S { call(:r_charset_name, :UTF8, val) }
| UTF8MB4 S { call(:r_charset_name, :UTF8MB4, val) }
| UTF8MB3 S { call(:r_charset_name, :UTF8MB3, val) }
| raw_ident { call(:r_charset_name, :other, val) }
# ref: https://dev.mysql.com/doc/refman/5.1/en/create-table.html
r_datatype :
BIT S r_opt_length_int
{ call(:r_datatype, :BIT, val) }
| TINYINT S r_opt_datatype_int
{ call(:r_datatype, :TINYINT, val) }
| SMALLINT S r_opt_datatype_int
{ call(:r_datatype, :SMALLINT, val) }
| MEDIUMINT S r_opt_datatype_int
{ call(:r_datatype, :MEDIUMINT, val) }
| INT S r_opt_datatype_int
{ call(:r_datatype, :INT, val) }
| INTEGER S r_opt_datatype_int
{ call(:r_datatype, :INTEGER, val) }
| BIGINT S r_opt_datatype_int
{ call(:r_datatype, :BIGINT, val) }
| REAL S r_opt_datatype_real
{ call(:r_datatype, :REAL, val) }
| DOUBLE S r_opt_datatype_real
{ call(:r_datatype, :DOUBLE, val) }
| FLOAT S r_opt_datatype_number
{ call(:r_datatype, :FLOAT, val) }
| DECIMAL S r_opt_datatype_number
{ call(:r_datatype, :DECIMAL, val) }
| NUMERIC S r_opt_datatype_number
{ call(:r_datatype, :NUMERIC, val) }
| DATE S r_opt_datatype_int
{ call(:r_datatype, :DATE, val) }
| TIME S r_opt_datatype_int
{ call(:r_datatype, :TIME, val) }
| TIMESTAMP S r_opt_datatype_int
{ call(:r_datatype, :TIMESTAMP, val) }
| DATETIME S r_opt_datatype_int
{ call(:r_datatype, :DATETIME, val) }
| YEAR S
{ call(:r_datatype, :YEAR, val) }
| CHAR S r_opt_length_int r_opt_datatype_char
{ call(:r_datatype, :CHAR, val) }
| VARCHAR S r_opt_length_int r_opt_datatype_char
{ call(:r_datatype, :VARCHAR, val) }
| BINARY S r_opt_length_int
{ call(:r_datatype, :BINARY, val) }
| VARBINARY S r_length_int
{ call(:r_datatype, :VARBINARY, val) }
| TINYBLOB S
{ call(:r_datatype, :TINYBLOB, val) }
| BLOB S
{ call(:r_datatype, :BLOB, val) }