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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
|
%{
#include <NdbApi.hpp>
#include <common/StmtArea.hpp>
#include <common/DataRow.hpp>
#include "CodeGen.hpp"
#include <FlexLexer.h>
#include "SimpleParser.hpp"
/* redefine globals after headers */
#define yyparse SimpleParser_yyparse
#if YYDEBUG
#define yydebug SimpleParser_yydebug
#endif
#define YYLEX_PARAM simpleParserPtr
#define YYPARSE_PARAM simpleParserPtr
#define simpleParser (*static_cast<SimpleParser*>(simpleParserPtr))
static int yylex(YYSTYPE* lvalp, void* simpleParserPtr);
#define yyerror(s) simpleParser.parseError(s)
#if YYDEBUG
// does not work in bison 1.75
#undef stderr
#define stderr 0
#define YYFPRINTF simpleParser.ctx().print
#endif
// scanner states
#define pushState(sc) simpleParser.pushState(sc)
#define popState() simpleParser.popState()
#define StateEval SimpleParser_stateEval
#define StateType SimpleParser_stateType
#define StatePhys SimpleParser_statePhys
extern int SimpleParser_stateEval;
extern int SimpleParser_stateType;
extern int SimpleParser_statePhys;
struct LimitPair { int off; int cnt; };
struct PhysAttr { int storage; int logging; };
%}
%defines
%pure-parser
%verbose
%union {
Plan_root* m_root;
Plan_stmt* m_stmt;
Plan_select* m_select;
Insert_op m_insert_op;
Plan_insert* m_insert;
Plan_update* m_update;
Plan_delete* m_delete;
Plan_create_table* m_create_table;
Plan_create_index* m_create_index;
NdbDictionary::Object::Type m_index_type;
Plan_create_row* m_create_row;
Plan_ddl_row* m_ddl_row;
Plan_ddl_column* m_ddl_column;
Plan_ddl_constr* m_ddl_constr;
Plan_idx_column* m_idx_column;
Plan_data_type* m_data_type;
Plan_drop_table* m_drop_table;
Plan_drop_index* m_drop_index;
Plan_set_row* m_set_row;
Plan_expr_row* m_expr_row;
bool m_asc_desc;
Plan_pred* m_pred;
Pred_op::Opcode m_pred_opcode;
Comp_op::Opcode m_comp_opcode;
Plan_expr* m_expr;
Expr_op::Opcode m_expr_opcode;
Plan_dml_row* m_dml_row;
Plan_dml_column* m_dml_column;
Plan_table* m_table;
Plan_table_list* m_table_list;
const char* m_string;
struct LimitPair* m_limit;
int m_signed_integer;
bool m_distinct;
struct PhysAttr* m_phys_attr;
NdbDictionary::Object::FragmentType m_storage_attr;
bool m_logging_attr;
}
/* keywords */
%token
T_AND
T_ASC
T_AUTO_INCREMENT
T_BIGINT
T_BINARY
T_BLOB
T_BY
T_CHAR
T_CONSTRAINT
T_CREATE
T_DATETIME
T_DEFAULT
T_DELETE
T_DESC
T_DISTINCT
T_DOUBLE
T_DROP
T_FLOAT
T_FOREIGN
T_FROM
T_GROUP
T_HASH
T_HAVING
T_IN
T_INDEX
T_INSERT
T_INT
T_INTEGER
T_INTO
T_IS
T_KEY
T_LARGE
T_LIKE
T_LIMIT
T_LOGGING
T_LONGBLOB
T_MEDIUM
T_NOLOGGING
T_NOT
T_NULL
T_OFFSET
T_ON
T_OR
T_ORDER
T_PRECISION
T_PRIMARY
T_REAL
T_REFERENCES
T_ROWNUM
T_SELECT
T_SET
T_SINGLE
T_SMALL
T_SMALLINT
T_STORAGE
T_SYSDATE
T_TABLE
T_UNIQUE
T_UNSIGNED
T_UPDATE
T_VALUES
T_VARBINARY
T_VARCHAR
T_WHERE
T_WRITE
/* identifiers and constants */
%token
<m_string> T_IDENTIFIER
<m_string> T_LINTEGER
<m_string> T_LDECIMAL
<m_string> T_LREAL
<m_string> T_STRING
/* expressions and predicates */
%token
T_PLUS
T_MINUS
T_TIMES
T_DIVIDE
T_EQ
T_NOTEQ
T_LT
T_LTEQ
T_GT
T_GTEQ
T_QUES
/* common special symbols */
%token
T_PERIOD
T_COMMA
T_PARENLEFT
T_PARENRIGHT
T_ASTERISK
T_ASSIGN
%type <m_root> root
%type <m_stmt> stmt
%type <m_select> stmt_select
%type <m_insert> stmt_insert
%type <m_insert_op> insert_op
%type <m_update> stmt_update
%type <m_delete> stmt_delete
%type <m_create_table> create_table
%type <m_create_index> create_index
%type <m_index_type> index_type
%type <m_create_row> create_row
%type <m_ddl_column> create_column
%type <m_ddl_constr> create_constr
%type <m_idx_column> idx_column
%type <m_data_type> data_type
%type <m_ddl_row> ddl_row
%type <m_ddl_column> ddl_column
%type <m_drop_table> drop_table
%type <m_drop_index> drop_index
%type <m_asc_desc> asc_desc
%type <m_set_row> set_row
%type <m_expr_row> expr_row
%type <m_expr_row> sort_row
%type <m_pred> where_clause
%type <m_expr_row> order_clause
%type <m_pred> pred
%type <m_pred> pred1
%type <m_pred_opcode> pred1_op
%type <m_pred> pred2
%type <m_pred_opcode> pred2_op
%type <m_pred> pred3
%type <m_pred_opcode> pred3_op
%type <m_pred> pred4
%type <m_comp_opcode> comp_op
%type <m_expr> expr
%type <m_expr> expr1
%type <m_expr_opcode> expr1_op
%type <m_expr> expr2
%type <m_expr_opcode> expr2_op
%type <m_expr> expr3
%type <m_expr_opcode> expr3_op
%type <m_expr> expr4
%type <m_expr> expr_column
%type <m_dml_row> dml_row
%type <m_dml_column> dml_column
%type <m_expr_row> value_row
%type <m_expr> value_expr
%type <m_table> table
%type <m_table_list> table_list
%type <m_string> dot_identifier
%type <m_limit> limit_clause
%type <m_signed_integer> signed_integer
%type <m_distinct> distinct_clause
%type <m_expr_row> group_clause
%type <m_pred> having_clause
%type <m_phys_attr> phys_attr
%type <m_phys_attr> phys_attr2
%type <m_storage_attr> storage_attr
%type <m_logging_attr> logging_attr
%%
root:
stmt
{
Plan_root* root = simpleParser.root();
root->setStmt($1);
}
;
stmt:
stmt_select
{
$$ = $1;
}
|
stmt_insert
{
$$ = $1;
}
|
stmt_update
{
$$ = $1;
}
|
stmt_delete
{
$$ = $1;
}
|
create_table
{
$$ = $1;
}
|
create_index
{
$$ = $1;
}
|
drop_table
{
$$ = $1;
}
|
drop_index
{
$$ = $1;
}
;
stmt_select:
T_SELECT distinct_clause expr_row T_FROM table_list where_clause group_clause having_clause order_clause limit_clause
{
Plan_root* root = simpleParser.root();
Plan_select* stmt = new Plan_select(root);
root->saveNode(stmt);
stmt->setDistinct($2);
stmt->setRow($3);
stmt->setList($5);
if ($6 != 0)
stmt->setPred($6);
if ($7 != 0)
stmt->setGroup($7);
if ($8 != 0)
stmt->setHaving($8);
if ($9 != 0)
stmt->setSort($9);
if ($10 != 0) {
stmt->setLimit($10->off, $10->cnt);
delete $10;
}
$$ = stmt;
}
;
stmt_insert:
insert_op T_INTO table T_VALUES T_PARENLEFT value_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_insert* stmt = new Plan_insert(root, $1);
root->saveNode(stmt);
stmt->setTable($3);
stmt->setExprRow($6);
$$ = stmt;
}
|
insert_op T_INTO table T_PARENLEFT dml_row T_PARENRIGHT T_VALUES T_PARENLEFT value_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_insert* stmt = new Plan_insert(root, $1);
root->saveNode(stmt);
stmt->setTable($3);
stmt->setDmlRow($5);
stmt->setExprRow($9);
$$ = stmt;
}
|
insert_op T_INTO table stmt_select
{
Plan_root* root = simpleParser.root();
Plan_insert* stmt = new Plan_insert(root, $1);
root->saveNode(stmt);
stmt->setTable($3);
stmt->setSelect($4);
$$ = stmt;
}
|
insert_op T_INTO table T_PARENLEFT dml_row T_PARENRIGHT stmt_select
{
Plan_root* root = simpleParser.root();
Plan_insert* stmt = new Plan_insert(root, $1);
root->saveNode(stmt);
stmt->setTable($3);
stmt->setDmlRow($5);
stmt->setSelect($7);
$$ = stmt;
}
|
insert_op T_INTO table T_SET set_row
{
Plan_root* root = simpleParser.root();
Plan_insert* stmt = new Plan_insert(root, $1);
root->saveNode(stmt);
stmt->setTable($3);
stmt->setMysqlRow($5);
$$ = stmt;
}
;
insert_op:
T_INSERT
{
$$ = Insert_op_insert;
}
|
T_WRITE
{
$$ = Insert_op_write;
}
;
stmt_update:
T_UPDATE table T_SET set_row where_clause
{
Plan_root* root = simpleParser.root();
Plan_update* stmt = new Plan_update(root);
root->saveNode(stmt);
stmt->setTable($2);
stmt->setRow($4);
if ($5 != 0)
stmt->setPred($5);
$$ = stmt;
}
;
stmt_delete:
T_DELETE T_FROM table where_clause
{
Plan_root* root = simpleParser.root();
Plan_delete* stmt = new Plan_delete(root);
root->saveNode(stmt);
stmt->setTable($3);
if ($4 != 0)
stmt->setPred($4);
$$ = stmt;
}
;
create_table:
T_CREATE T_TABLE dot_identifier T_PARENLEFT create_row T_PARENRIGHT phys_attr
{
Plan_root* root = simpleParser.root();
Plan_create_table* stmt = new Plan_create_table(root, $3);
root->saveNode(stmt);
delete[] $3;
stmt->setCreateRow($5);
if ($7->storage != -1)
stmt->setFragmentType((NdbDictionary::Object::FragmentType)$7->storage);
if ($7->logging != -1)
stmt->setLogging($7->logging);
delete $7;
$$ = stmt;
}
;
create_row:
create_column
{
Plan_root* root = simpleParser.root();
Plan_create_row* createRow = new Plan_create_row(root);
root->saveNode(createRow);
createRow->addColumn($1);
$$ = createRow;
}
|
create_constr
{
Plan_root* root = simpleParser.root();
Plan_create_row* createRow = new Plan_create_row(root);
root->saveNode(createRow);
createRow->addConstr($1);
$$ = createRow;
}
|
create_row T_COMMA create_column
{
Plan_create_row* createRow = $1;
createRow->addColumn($3);
$$ = createRow;
}
|
create_row T_COMMA create_constr
{
Plan_create_row* createRow = $1;
createRow->addConstr($3);
$$ = createRow;
}
|
create_row T_COMMA create_ignore
{
$$ = $1;
}
;
create_column:
T_IDENTIFIER { pushState(StateType); } data_type { popState(); }
{
Plan_root* root = simpleParser.root();
Plan_ddl_column* ddlColumn = new Plan_ddl_column(root, $1);
root->saveNode(ddlColumn);
delete[] $1;
ddlColumn->setType($3);
simpleParser.curr(ddlColumn);
}
create_column_rest
{
$$ = simpleParser.curr((Plan_ddl_column*)0);
}
;
data_type:
T_CHAR T_PARENLEFT T_LINTEGER T_PARENRIGHT dummy_binary
{
Plan_root* root = simpleParser.root();
SqlType sqlType(simpleParser.ctx(), SqlType::Char, atoi($3), true);
delete[] $3;
if (! simpleParser.ctx().ok()) {
YYABORT;
}
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_BINARY T_PARENLEFT T_LINTEGER T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(simpleParser.ctx(), SqlType::Binary, atoi($3), true);
delete[] $3;
if (! simpleParser.ctx().ok()) {
YYABORT;
}
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_VARCHAR T_PARENLEFT T_LINTEGER T_PARENRIGHT dummy_binary
{
Plan_root* root = simpleParser.root();
SqlType sqlType(simpleParser.ctx(), SqlType::Varchar, atoi($3), true);
delete[] $3;
if (! simpleParser.ctx().ok()) {
YYABORT;
}
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_VARBINARY T_PARENLEFT T_LINTEGER T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(simpleParser.ctx(), SqlType::Varbinary, atoi($3), true);
delete[] $3;
if (! simpleParser.ctx().ok()) {
YYABORT;
}
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_SMALLINT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Smallint, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_INTEGER
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Integer, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_INT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Integer, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_BIGINT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Bigint, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_REAL
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Real, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_FLOAT
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Double, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_DOUBLE T_PRECISION
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Double, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
T_DATETIME
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Datetime, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
|
blob_keyword
{
Plan_root* root = simpleParser.root();
SqlType sqlType(SqlType::Blob, true);
Plan_data_type* dataType = new Plan_data_type(root, sqlType);
root->saveNode(dataType);
$$ = dataType;
}
;
dummy_binary:
/* empty */
|
T_BINARY
;
blob_keyword:
T_BLOB
|
T_LONGBLOB
;
create_column_rest:
/* empty */
|
data_constr_list
;
data_constr_list:
data_constr
|
data_constr_list data_constr
;
data_constr:
T_NULL
|
T_NOT T_NULL
{
Plan_ddl_column* ddlColumn = simpleParser.curr((Plan_ddl_column*)0);
ddlColumn->setNotNull();
}
|
T_UNSIGNED
{
Plan_ddl_column* ddlColumn = simpleParser.curr((Plan_ddl_column*)0);
ddlColumn->setUnSigned();
}
|
T_PRIMARY T_KEY
{
Plan_ddl_column* ddlColumn = simpleParser.curr((Plan_ddl_column*)0);
ddlColumn->setPrimaryKey();
}
|
T_AUTO_INCREMENT
{
Plan_ddl_column* ddlColumn = simpleParser.curr((Plan_ddl_column*)0);
ddlColumn->setAutoIncrement();
}
|
T_DEFAULT expr
{
Plan_ddl_column* ddlColumn = simpleParser.curr((Plan_ddl_column*)0);
ddlColumn->setDefaultValue($2);
}
;
create_constr:
T_PRIMARY T_KEY T_PARENLEFT ddl_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_ddl_constr* ddlConstr = new Plan_ddl_constr(root);
root->saveNode(ddlConstr);
ddlConstr->setRow($4);
$$ = ddlConstr;
}
|
T_CONSTRAINT dot_identifier T_PRIMARY T_KEY T_PARENLEFT ddl_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_ddl_constr* ddlConstr = new Plan_ddl_constr(root);
root->saveNode(ddlConstr);
ddlConstr->setRow($6);
$$ = ddlConstr;
}
;
create_ignore:
T_INDEX dot_identifier T_PARENLEFT ddl_row T_PARENRIGHT
|
T_FOREIGN T_KEY T_PARENLEFT ddl_row T_PARENRIGHT T_REFERENCES dot_identifier T_PARENLEFT ddl_row T_PARENRIGHT
;
ddl_row:
ddl_column
{
Plan_root* root = simpleParser.root();
Plan_ddl_row* ddlRow = new Plan_ddl_row(root);
root->saveNode(ddlRow);
ddlRow->addColumn($1);
$$ = ddlRow;
}
|
ddl_row T_COMMA ddl_column
{
Plan_ddl_row* ddlRow = $1;
ddlRow->addColumn($3);
$$ = ddlRow;
}
;
ddl_column:
T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_ddl_column* column = new Plan_ddl_column(root, $1);
root->saveNode(column);
delete[] $1;
$$ = column;
}
;
create_index:
T_CREATE index_type T_INDEX dot_identifier T_ON table
{
Plan_root* root = simpleParser.root();
Plan_create_index* stmt = new Plan_create_index(root, $4);
root->saveNode(stmt);
delete[] $4;
stmt->setType($2);
stmt->setTable($6);
simpleParser.curr(stmt);
}
T_PARENLEFT idx_row T_PARENRIGHT phys_attr
{
$$ = simpleParser.curr((Plan_create_index*)0);
if ($11->storage != -1)
$$->setFragmentType((NdbDictionary::Object::FragmentType)$11->storage);
if ($11->logging != -1)
$$->setLogging($11->logging);
delete $11;
}
;
index_type:
T_HASH
{
$$ = NdbDictionary::Object::HashIndex;
}
|
T_UNIQUE T_HASH
{
$$ = NdbDictionary::Object::UniqueHashIndex;
}
|
/* empty */
{
$$ = NdbDictionary::Object::OrderedIndex;
}
|
T_UNIQUE
{
$$ = NdbDictionary::Object::UniqueOrderedIndex;
}
;
idx_row:
idx_column
{
}
|
idx_row T_COMMA idx_column
{
}
;
idx_column:
T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_idx_column* column = new Plan_idx_column(root, $1);
root->saveNode(column);
delete[] $1;
Plan_create_index* stmt = simpleParser.curr((Plan_create_index*)0);
stmt->addColumn(column);
}
;
phys_attr:
{ pushState(StatePhys); } phys_attr2 { popState(); }
{
$$ = $2;
}
;
phys_attr2:
/* empty */
{
$$ = new PhysAttr();
$$->storage = $$->logging = -1;
}
|
phys_attr2 storage_attr
{
if ($1->storage != -1 && $1->storage != $2) {
simpleParser.ctx().pushStatus(Sqlstate::_42000, Error::Gen, "conflicting STORAGE clauses");
YYABORT;
}
$$->storage = $2;
}
|
phys_attr2 logging_attr
{
if ($1->logging != -1 && $1->logging != $2) {
simpleParser.ctx().pushStatus(Sqlstate::_42000, Error::Gen, "conflicting LOGGING clauses");
YYABORT;
}
$$->logging = $2;
}
;
logging_attr:
T_LOGGING
{
$$ = true;
}
|
T_NOLOGGING
{
$$ = false;
}
;
storage_attr:
T_STORAGE T_PARENLEFT T_SINGLE T_PARENRIGHT
{
$$ = NdbDictionary::Object::FragSingle;
}
|
T_STORAGE T_PARENLEFT T_SMALL T_PARENRIGHT
{
$$ = NdbDictionary::Object::FragAllSmall;
}
|
T_STORAGE T_PARENLEFT T_MEDIUM T_PARENRIGHT
{
$$ = NdbDictionary::Object::FragAllMedium;
}
|
T_STORAGE T_PARENLEFT T_LARGE T_PARENRIGHT
{
$$ = NdbDictionary::Object::FragAllLarge;
}
;
drop_table:
T_DROP T_TABLE dot_identifier
{
Plan_root* root = simpleParser.root();
Plan_drop_table* stmt = new Plan_drop_table(root, $3);
root->saveNode(stmt);
delete[] $3;
$$ = stmt;
}
;
drop_index:
T_DROP T_INDEX dot_identifier
{
Plan_root* root = simpleParser.root();
Plan_drop_index* stmt = new Plan_drop_index(root, $3);
root->saveNode(stmt);
delete[] $3;
$$ = stmt;
}
|
T_DROP T_INDEX dot_identifier T_ON dot_identifier
{
Plan_root* root = simpleParser.root();
Plan_drop_index* stmt = new Plan_drop_index(root, $3, $5);
root->saveNode(stmt);
delete[] $3;
delete[] $5;
$$ = stmt;
}
;
distinct_clause:
/* empty */
{
$$ = false;
}
|
T_DISTINCT
{
$$ = true;
}
;
where_clause:
/* empty */
{
$$ = 0;
}
|
T_WHERE pred
{
$$ = $2;
}
;
group_clause:
/* empty */
{
$$ = 0;
}
|
T_GROUP T_BY value_row
{
$$ = $3;
}
;
having_clause:
/* empty */
{
$$ = 0;
}
|
T_HAVING pred
{
$$ = $2;
}
;
order_clause:
/* empty */
{
$$ = 0;
}
|
T_ORDER T_BY sort_row
{
$$ = $3;
}
;
limit_clause:
/* empty */
{
$$ = 0;
}
|
T_LIMIT signed_integer
{
LimitPair* p = new LimitPair;
p->off = 0;
p->cnt = $2;
$$ = p;
}
|
T_LIMIT signed_integer T_COMMA signed_integer
{
LimitPair* p = new LimitPair;
p->off = $2,
p->cnt = $4;
$$ = p;
}
|
T_LIMIT signed_integer T_OFFSET signed_integer
{
LimitPair* p = new LimitPair;
p->off = $4;
p->cnt = $2;
$$ = p;
}
;
signed_integer:
T_LINTEGER
{
$$ = atoi($1);
delete[] $1;
}
|
T_MINUS T_LINTEGER
{
$$ = (-1) * atoi($2);
delete[] $2;
}
;
set_row:
dml_column T_ASSIGN expr
{
Plan_root* root = simpleParser.root();
Plan_set_row* row = new Plan_set_row(root);
root->saveNode(row);
row->addColumn($1);
row->addExpr($3);
$$ = row;
}
|
set_row T_COMMA dml_column T_ASSIGN expr
{
Plan_set_row* row = $1;
row->addColumn($3);
row->addExpr($5);
$$ = row;
}
;
dml_row:
dml_column
{
Plan_root* root = simpleParser.root();
Plan_dml_row* row = new Plan_dml_row(root);
root->saveNode(row);
row->addColumn($1);
$$ = row;
}
|
dml_row T_COMMA dml_column
{
Plan_dml_row* row = $1;
row->addColumn($3);
$$ = row;
}
;
dml_column:
T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_dml_column* column = new Plan_dml_column(root, $1);
root->saveNode(column);
delete[] $1;
$$ = column;
}
;
value_row:
value_expr
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->addExpr($1);
$$ = row;
}
|
value_row T_COMMA value_expr
{
Plan_expr_row* row = $1;
row->addExpr($3);
$$ = row;
}
;
value_expr:
expr
{
$$ = $1;
}
;
sort_row:
expr asc_desc
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->addExpr($1, $2);
$$ = row;
}
|
sort_row T_COMMA expr asc_desc
{
Plan_expr_row* row = $1;
row->addExpr($3, $4);
$$ = row;
}
;
asc_desc:
/* empty */
{
$$ = true;
}
|
T_ASC
{
$$ = true;
}
|
T_DESC
{
$$ = false;
}
;
expr_row:
T_ASTERISK
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->setAsterisk();
$$ = row;
}
|
T_TIMES /* XXX fix scanner state */
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->setAsterisk();
$$ = row;
}
|
expr
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->addExpr($1);
$$ = row;
}
|
expr T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_expr_row* row = new Plan_expr_row(root);
root->saveNode(row);
row->addExpr($1, BaseString($2));
$$ = row;
}
|
expr_row T_COMMA expr
{
Plan_expr_row* row = $1;
row->addExpr($3);
$$ = row;
}
|
expr_row T_COMMA expr T_IDENTIFIER
{
Plan_expr_row* row = $1;
row->addExpr($3, BaseString($4));
$$ = row;
}
;
pred:
{ pushState(StateEval); } pred1 { popState(); }
{
$$ = $2;
}
;
pred1:
pred2
{
$$ = $1;
}
|
pred1 pred1_op pred2
{
Plan_root* root = simpleParser.root();
Pred_op op($2);
Plan_pred_op* pred = new Plan_pred_op(root, op);
root->saveNode(pred);
pred->setPred(1, $1);
pred->setPred(2, $3);
$$ = pred;
}
;
pred1_op:
T_OR
{
$$ = Pred_op::Or;
}
;
pred2:
pred3
{
$$ = $1;
}
|
pred2 pred2_op pred3
{
Plan_root* root = simpleParser.root();
Pred_op op($2);
Plan_pred_op* pred = new Plan_pred_op(root, op);
root->saveNode(pred);
pred->setPred(1, $1);
pred->setPred(2, $3);
$$ = pred;
}
;
pred2_op:
T_AND
{
$$ = Pred_op::And;
}
;
pred3:
pred4
{
$$ = $1;
}
|
pred3_op pred3
{
Plan_root* root = simpleParser.root();
Pred_op op($1);
Plan_pred_op* pred = new Plan_pred_op(root, op);
root->saveNode(pred);
pred->setPred(1, $2);
$$ = pred;
}
;
pred3_op:
T_NOT
{
$$ = Pred_op::Not;
}
;
pred4:
T_PARENLEFT pred1 T_PARENRIGHT
{
$$ = $2;
}
|
expr1 comp_op expr1
{
Plan_root* root = simpleParser.root();
Comp_op op($2);
Plan_comp_op* comp = new Plan_comp_op(root, op);
root->saveNode(comp);
comp->setExpr(1, $1);
comp->setExpr(2, $3);
$$ = comp;
}
|
expr1 T_IS T_NULL
{
Plan_root* root = simpleParser.root();
Comp_op op(Comp_op::Isnull);
Plan_comp_op* comp = new Plan_comp_op(root, op);
root->saveNode(comp);
comp->setExpr(1, $1);
$$ = comp;
}
|
expr1 T_IS T_NOT T_NULL
{
Plan_root* root = simpleParser.root();
Comp_op op(Comp_op::Isnotnull);
Plan_comp_op* comp = new Plan_comp_op(root, op);
root->saveNode(comp);
comp->setExpr(1, $1);
$$ = comp;
}
|
expr1 T_IN T_PARENLEFT value_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_pred* predOut = 0; // hack directly into Or of Eq
Plan_expr* exprLeft = $1;
Plan_expr_row* row = $4;
for (unsigned i = row->getSize(); i >= 1; i--) {
Plan_expr* exprRight = row->getExpr(i);
Plan_comp_op* comp = new Plan_comp_op(root, Comp_op::Eq);
root->saveNode(comp);
comp->setExpr(1, exprLeft);
comp->setExpr(2, exprRight);
if (predOut == 0) {
predOut = comp;
} else {
Plan_pred_op* pred = new Plan_pred_op(root, Pred_op::Or);
root->saveNode(pred);
pred->setPred(1, predOut);
pred->setPred(2, comp);
predOut = pred;
}
}
$$ = predOut;
}
|
expr1 T_NOT T_IN T_PARENLEFT value_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
Plan_pred* predOut = 0; // hack directly into And of Noteq
Plan_expr* exprLeft = $1;
Plan_expr_row* row = $5;
for (unsigned i = row->getSize(); i >= 1; i--) {
Plan_expr* exprRight = row->getExpr(i);
Plan_comp_op* comp = new Plan_comp_op(root, Comp_op::Noteq);
root->saveNode(comp);
comp->setExpr(1, exprLeft);
comp->setExpr(2, exprRight);
if (predOut == 0) {
predOut = comp;
} else {
Plan_pred_op* pred = new Plan_pred_op(root, Pred_op::And);
root->saveNode(pred);
pred->setPred(1, predOut);
pred->setPred(2, comp);
predOut = pred;
}
}
$$ = predOut;
}
;
comp_op:
T_EQ
{
$$ = Comp_op::Eq;
}
|
T_NOTEQ
{
$$ = Comp_op::Noteq;
}
|
T_LT
{
$$ = Comp_op::Lt;
}
|
T_LTEQ
{
$$ = Comp_op::Lteq;
}
|
T_GT
{
$$ = Comp_op::Gt;
}
|
T_GTEQ
{
$$ = Comp_op::Gteq;
}
|
T_LIKE
{
$$ = Comp_op::Like;
}
|
T_NOT T_LIKE
{
$$ = Comp_op::Notlike;
}
;
expr:
{ pushState(StateEval); } expr1 { popState(); }
{
$$ = $2;
}
;
expr1:
expr2
{
$$ = $1;
}
|
expr1 expr1_op expr2
{
Plan_root* root = simpleParser.root();
Expr_op op($2);
Plan_expr_op* expr = new Plan_expr_op(root, op);
root->saveNode(expr);
expr->setExpr(1, $1);
expr->setExpr(2, $3);
$$ = expr;
}
;
expr1_op:
T_PLUS
{
$$ = Expr_op::Add;
}
|
T_MINUS
{
$$ = Expr_op::Subtract;
}
;
expr2:
expr3
{
$$ = $1;
}
|
expr2 expr2_op expr3
{
Plan_root* root = simpleParser.root();
Expr_op op($2);
Plan_expr_op* expr = new Plan_expr_op(root, op);
root->saveNode(expr);
expr->setExpr(1, $1);
expr->setExpr(2, $3);
$$ = expr;
}
;
expr2_op:
T_TIMES
{
$$ = Expr_op::Multiply;
}
|
T_DIVIDE
{
$$ = Expr_op::Divide;
}
;
expr3:
expr4
{
$$ = $1;
}
|
expr3_op expr3
{
Plan_root* root = simpleParser.root();
Expr_op op($1);
Plan_expr_op* expr = new Plan_expr_op(root, op);
root->saveNode(expr);
expr->setExpr(1, $2);
$$ = expr;
}
;
expr3_op:
T_PLUS
{
$$ = Expr_op::Plus;
}
|
T_MINUS
{
$$ = Expr_op::Minus;
}
;
expr4:
T_PARENLEFT expr1 T_PARENRIGHT
{
$$ = $2;
}
|
T_IDENTIFIER T_PARENLEFT expr_row T_PARENRIGHT
{
Plan_root* root = simpleParser.root();
const Expr_func& spec = Expr_func::find($1);
if (spec.m_name == 0) {
simpleParser.ctx().pushStatus(Sqlstate::_42000, Error::Gen, "unknown function %s", $1);
delete[] $1;
YYABORT;
}
Plan_expr_func* func = new Plan_expr_func(root, spec);
root->saveNode(func);
delete[] $1;
func->setArgs($3);
$$ = func;
}
|
T_ROWNUM
{
Plan_root* root = simpleParser.root();
const Expr_func& spec = Expr_func::find("ROWNUM");
ctx_assert(spec.m_name != 0);
Plan_expr_func* func = new Plan_expr_func(root, spec);
root->saveNode(func);
func->setArgs(0);
$$ = func;
}
|
T_SYSDATE
{
Plan_root* root = simpleParser.root();
const Expr_func& spec = Expr_func::find("SYSDATE");
ctx_assert(spec.m_name != 0);
Plan_expr_func* func = new Plan_expr_func(root, spec);
root->saveNode(func);
func->setArgs(0);
$$ = func;
}
|
expr_column
{
$$ = $1;
}
|
T_STRING
{
Plan_root* root = simpleParser.root();
LexType lexType(LexType::Char);
Plan_expr_const* expr = new Plan_expr_const(root, lexType, $1);
root->saveNode(expr);
delete[] $1;
$$ = expr;
}
|
T_LINTEGER
{
Plan_root* root = simpleParser.root();
LexType lexType(LexType::Integer);
Plan_expr_const* expr = new Plan_expr_const(root, lexType, $1);
root->saveNode(expr);
delete[] $1;
$$ = expr;
}
|
T_LDECIMAL
{
Plan_root* root = simpleParser.root();
LexType lexType(LexType::Float);
Plan_expr_const* expr = new Plan_expr_const(root, lexType, $1);
root->saveNode(expr);
delete[] $1;
$$ = expr;
}
|
T_LREAL
{
Plan_root* root = simpleParser.root();
LexType lexType(LexType::Float);
Plan_expr_const* expr = new Plan_expr_const(root, lexType, $1);
root->saveNode(expr);
delete[] $1;
$$ = expr;
}
|
T_NULL
{
Plan_root* root = simpleParser.root();
LexType lexType(LexType::Null);
Plan_expr_const* expr = new Plan_expr_const(root, lexType, "");
root->saveNode(expr);
$$ = expr;
}
|
T_QUES
{
Plan_root* root = simpleParser.root();
unsigned paramNumber = simpleParser.paramNumber();
ctx_assert(paramNumber != 0);
Plan_expr_param* expr = new Plan_expr_param(root, paramNumber);
root->saveNode(expr);
$$ = expr;
}
;
expr_column:
T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_expr_column* column = new Plan_expr_column(root, $1);
root->saveNode(column);
delete[] $1;
$$ = column;
}
|
T_IDENTIFIER T_PERIOD T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_expr_column* column = new Plan_expr_column(root, $3);
root->saveNode(column);
delete[] $3;
column->setCname($1);
$$ = column;
}
|
T_IDENTIFIER T_PERIOD T_IDENTIFIER T_PERIOD T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
BaseString str;
str.append($1);
str.append(".");
str.append($3);
delete[] $1;
delete[] $3;
Plan_expr_column* column = new Plan_expr_column(root, $5);
root->saveNode(column);
delete[] $5;
column->setCname(str);
$$ = column;
}
;
table_list:
table
{
Plan_root* root = simpleParser.root();
Plan_table_list* tableList = new Plan_table_list(root);
root->saveNode(tableList);
tableList->addTable($1);
$$ = tableList;
}
|
table_list T_COMMA table
{
Plan_table_list* tableList = $1;
tableList->addTable($3);
$$ = tableList;
}
;
table:
dot_identifier
{
Plan_root* root = simpleParser.root();
Plan_table* table = new Plan_table(root, $1);
root->saveNode(table);
delete[] $1;
$$ = table;
}
|
dot_identifier T_IDENTIFIER
{
Plan_root* root = simpleParser.root();
Plan_table* table = new Plan_table(root, $1);
root->saveNode(table);
delete[] $1;
table->setCname($2);
delete[] $2;
$$ = table;
}
;
dot_identifier:
T_IDENTIFIER
{
$$ = $1;
}
|
T_IDENTIFIER T_PERIOD T_IDENTIFIER
{
char* s = new char[strlen($1) + 1 + strlen($3) + 1];
strcpy(s, $1);
strcat(s, ".");
strcat(s, $3);
delete[] $1;
delete[] $3;
$$ = s;
}
;
%%
static int
yylex(YYSTYPE* lvalp, void* simpleParserPtr)
{
int ret = simpleParser.yylex();
*lvalp = simpleParser.yylval();
return ret;
}
/* vim: set filetype=yacc: */
|