github.com/team-ide/go-dialect@v1.9.20/vitess/sqlparser/sql.y (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 %{ 18 package sqlparser 19 20 func setParseTree(yylex yyLexer, stmt Statement) { 21 yylex.(*Tokenizer).ParseTree = stmt 22 } 23 24 func setAllowComments(yylex yyLexer, allow bool) { 25 yylex.(*Tokenizer).AllowComments = allow 26 } 27 28 func setDDL(yylex yyLexer, node Statement) { 29 yylex.(*Tokenizer).partialDDL = node 30 } 31 32 func incNesting(yylex yyLexer) bool { 33 yylex.(*Tokenizer).nesting++ 34 if yylex.(*Tokenizer).nesting == 200 { 35 return true 36 } 37 return false 38 } 39 40 func decNesting(yylex yyLexer) { 41 yylex.(*Tokenizer).nesting-- 42 } 43 44 // skipToEnd forces the lexer to end prematurely. Not all SQL statements 45 // are supported by the Parser, thus calling skipToEnd will make the lexer 46 // return EOF early. 47 func skipToEnd(yylex yyLexer) { 48 yylex.(*Tokenizer).SkipToEnd = true 49 } 50 51 func bindVariable(yylex yyLexer, bvar string) { 52 yylex.(*Tokenizer).BindVars[bvar] = struct{}{} 53 } 54 55 %} 56 57 %struct { 58 empty struct{} 59 LengthScaleOption LengthScaleOption 60 tableName TableName 61 tableIdent TableIdent 62 str string 63 strs []string 64 vindexParam VindexParam 65 colIdent ColIdent 66 joinCondition *JoinCondition 67 collateAndCharset CollateAndCharset 68 columnType ColumnType 69 } 70 71 %union { 72 statement Statement 73 selStmt SelectStatement 74 tableExpr TableExpr 75 expr Expr 76 colTuple ColTuple 77 optVal Expr 78 constraintInfo ConstraintInfo 79 alterOption AlterOption 80 characteristic Characteristic 81 82 ins *Insert 83 colName *ColName 84 indexHints *IndexHints 85 literal *Literal 86 subquery *Subquery 87 derivedTable *DerivedTable 88 when *When 89 with *With 90 cte *CommonTableExpr 91 ctes []*CommonTableExpr 92 order *Order 93 limit *Limit 94 95 updateExpr *UpdateExpr 96 setExpr *SetExpr 97 convertType *ConvertType 98 aliasedTableName *AliasedTableExpr 99 tableSpec *TableSpec 100 columnDefinition *ColumnDefinition 101 indexDefinition *IndexDefinition 102 indexInfo *IndexInfo 103 indexOption *IndexOption 104 indexColumn *IndexColumn 105 partDef *PartitionDefinition 106 partSpec *PartitionSpec 107 showFilter *ShowFilter 108 optLike *OptLike 109 selectInto *SelectInto 110 createDatabase *CreateDatabase 111 alterDatabase *AlterDatabase 112 createTable *CreateTable 113 tableAndLockType *TableAndLockType 114 alterTable *AlterTable 115 tableOption *TableOption 116 columnTypeOptions *ColumnTypeOptions 117 constraintDefinition *ConstraintDefinition 118 revertMigration *RevertMigration 119 alterMigration *AlterMigration 120 121 whens []*When 122 columnDefinitions []*ColumnDefinition 123 indexOptions []*IndexOption 124 indexColumns []*IndexColumn 125 collateAndCharsets []CollateAndCharset 126 tableAndLockTypes TableAndLockTypes 127 renameTablePairs []*RenameTablePair 128 alterOptions []AlterOption 129 vindexParams []VindexParam 130 partDefs []*PartitionDefinition 131 partSpecs []*PartitionSpec 132 characteristics []Characteristic 133 selectExpr SelectExpr 134 columns Columns 135 partitions Partitions 136 tableExprs TableExprs 137 tableNames TableNames 138 exprs Exprs 139 values Values 140 valTuple ValTuple 141 orderBy OrderBy 142 updateExprs UpdateExprs 143 setExprs SetExprs 144 selectExprs SelectExprs 145 tableOptions TableOptions 146 147 colKeyOpt ColumnKeyOption 148 ReferenceAction ReferenceAction 149 isolationLevel IsolationLevel 150 insertAction InsertAction 151 scope Scope 152 lock Lock 153 joinType JoinType 154 comparisonExprOperator ComparisonExprOperator 155 isExprOperator IsExprOperator 156 matchExprOption MatchExprOption 157 orderDirection OrderDirection 158 explainType ExplainType 159 intervalType IntervalTypes 160 lockType LockType 161 referenceDefinition *ReferenceDefinition 162 163 columnStorage ColumnStorage 164 165 boolean bool 166 boolVal BoolVal 167 ignore Ignore 168 partitionOption *PartitionOption 169 exprOrColumns *ExprOrColumns 170 subPartition *SubPartition 171 } 172 173 %token LEX_ERROR 174 %left <str> UNION 175 %token <str> SELECT STREAM VSTREAM INSERT UPDATE DELETE FROM WHERE GROUP HAVING ORDER BY LIMIT OFFSET FOR 176 %token <str> ALL DISTINCT AS EXISTS ASC DESC INTO DUPLICATE DEFAULT SET LOCK UNLOCK KEYS DO CALL 177 %token <str> DISTINCTROW PARSER GENERATED ALWAYS 178 %token <str> OUTFILE S3 DATA LOAD LINES TERMINATED ESCAPED ENCLOSED 179 %token <str> DUMPFILE CSV HEADER MANIFEST OVERWRITE STARTING OPTIONALLY 180 %token <str> VALUES LAST_INSERT_ID 181 %token <str> NEXT VALUE SHARE MODE 182 %token <str> SQL_NO_CACHE SQL_CACHE SQL_CALC_FOUND_ROWS 183 %left <str> JOIN STRAIGHT_JOIN LEFT RIGHT INNER OUTER CROSS NATURAL USE FORCE 184 %left <str> ON USING INPLACE COPY ALGORITHM NONE SHARED EXCLUSIVE 185 %left <str> SUBQUERY_AS_EXPR 186 %left <str> '(' ',' ')' 187 %token <str> ID AT_ID AT_AT_ID HEX STRING NCHAR_STRING INTEGRAL FLOAT DECIMAL HEXNUM VALUE_ARG LIST_ARG COMMENT COMMENT_KEYWORD BIT_LITERAL COMPRESSION 188 %token <str> EXTRACT 189 %token <str> NULL TRUE FALSE OFF 190 %token <str> DISCARD IMPORT ENABLE DISABLE TABLESPACE 191 %token <str> VIRTUAL STORED 192 193 %left EMPTY_FROM_CLAUSE 194 %right INTO 195 196 // Precedence dictated by mysql. But the vitess grammar is simplified. 197 // Some of these operators don't conflict in our situation. Nevertheless, 198 // it's better to have these listed in the correct order. Also, we don't 199 // support all operators yet. 200 // * NOTE: If you change anything here, update precedence.go as well * 201 %nonassoc <str> LOWER_THAN_CHARSET 202 %nonassoc <str> CHARSET 203 // Resolve column attribute ambiguity. 204 %right <str> UNIQUE KEY 205 %left <str> EXPRESSION_PREC_SETTER 206 %left <str> OR '|' 207 %left <str> XOR 208 %left <str> AND 209 %right <str> NOT '!' 210 %left <str> BETWEEN CASE WHEN THEN ELSE END 211 %left <str> '=' '<' '>' LE GE NE NULL_SAFE_EQUAL IS LIKE REGEXP IN 212 %left <str> '&' 213 %left <str> SHIFT_LEFT SHIFT_RIGHT 214 %left <str> '+' '-' 215 %left <str> '*' '/' DIV '%' MOD 216 %left <str> '^' 217 %right <str> '~' UNARY 218 %left <str> COLLATE 219 %right <str> BINARY UNDERSCORE_ARMSCII8 UNDERSCORE_ASCII UNDERSCORE_BIG5 UNDERSCORE_BINARY UNDERSCORE_CP1250 UNDERSCORE_CP1251 220 %right <str> UNDERSCORE_CP1256 UNDERSCORE_CP1257 UNDERSCORE_CP850 UNDERSCORE_CP852 UNDERSCORE_CP866 UNDERSCORE_CP932 221 %right <str> UNDERSCORE_DEC8 UNDERSCORE_EUCJPMS UNDERSCORE_EUCKR UNDERSCORE_GB18030 UNDERSCORE_GB2312 UNDERSCORE_GBK UNDERSCORE_GEOSTD8 222 %right <str> UNDERSCORE_GREEK UNDERSCORE_HEBREW UNDERSCORE_HP8 UNDERSCORE_KEYBCS2 UNDERSCORE_KOI8R UNDERSCORE_KOI8U UNDERSCORE_LATIN1 UNDERSCORE_LATIN2 UNDERSCORE_LATIN5 223 %right <str> UNDERSCORE_LATIN7 UNDERSCORE_MACCE UNDERSCORE_MACROMAN UNDERSCORE_SJIS UNDERSCORE_SWE7 UNDERSCORE_TIS620 UNDERSCORE_UCS2 UNDERSCORE_UJIS UNDERSCORE_UTF16 224 %right <str> UNDERSCORE_UTF16LE UNDERSCORE_UTF32 UNDERSCORE_UTF8 UNDERSCORE_UTF8MB4 225 %right <str> INTERVAL 226 %nonassoc <str> '.' 227 228 // There is no need to define precedence for the JSON 229 // operators because the syntax is restricted enough that 230 // they don't cause conflicts. 231 %token <empty> JSON_EXTRACT_OP JSON_UNQUOTE_EXTRACT_OP 232 233 // DDL Tokens 234 %token <str> CREATE ALTER DROP RENAME ANALYZE ADD FLUSH CHANGE MODIFY 235 %token <str> REVERT 236 %token <str> SCHEMA TABLE INDEX VIEW TO IGNORE IF PRIMARY COLUMN SPATIAL FULLTEXT KEY_BLOCK_SIZE CHECK INDEXES 237 %token <str> ACTION CASCADE CONSTRAINT FOREIGN NO REFERENCES RESTRICT 238 %token <str> SHOW DESCRIBE EXPLAIN DATE ESCAPE REPAIR OPTIMIZE TRUNCATE COALESCE EXCHANGE REBUILD PARTITIONING REMOVE 239 %token <str> MAXVALUE PARTITION REORGANIZE LESS THAN PROCEDURE TRIGGER 240 %token <str> VINDEX VINDEXES DIRECTORY NAME UPGRADE 241 %token <str> STATUS VARIABLES WARNINGS CASCADED DEFINER OPTION SQL UNDEFINED 242 %token <str> SEQUENCE MERGE TEMPORARY TEMPTABLE INVOKER SECURITY FIRST AFTER LAST 243 244 // Migration tokens 245 %token <str> VITESS_MIGRATION CANCEL RETRY COMPLETE CLEANUP 246 247 // Transaction Tokens 248 %token <str> BEGIN START TRANSACTION COMMIT ROLLBACK SAVEPOINT RELEASE WORK 249 250 // Type Tokens 251 %token <str> BIT TINYINT SMALLINT MEDIUMINT INT INTEGER BIGINT INTNUM 252 %token <str> REAL DOUBLE FLOAT_TYPE DECIMAL_TYPE NUMERIC 253 %token <str> TIME TIMESTAMP DATETIME YEAR 254 %token <str> CHAR VARCHAR BOOL CHARACTER VARBINARY NCHAR 255 %token <str> TEXT TINYTEXT MEDIUMTEXT LONGTEXT 256 %token <str> BLOB TINYBLOB MEDIUMBLOB LONGBLOB JSON ENUM 257 %token <str> GEOMETRY POINT LINESTRING POLYGON GEOMETRYCOLLECTION MULTIPOINT MULTILINESTRING MULTIPOLYGON 258 259 // Type Modifiers 260 %token <str> NULLX AUTO_INCREMENT APPROXNUM SIGNED UNSIGNED ZEROFILL 261 262 // SHOW tokens 263 %token <str> CODE COLLATION COLUMNS DATABASES ENGINES EVENT EXTENDED FIELDS FULL FUNCTION GTID_EXECUTED 264 %token <str> KEYSPACES OPEN PLUGINS PRIVILEGES PROCESSLIST SCHEMAS TABLES TRIGGERS USER 265 %token <str> VGTID_EXECUTED VITESS_KEYSPACES VITESS_METADATA VITESS_MIGRATIONS VITESS_REPLICATION_STATUS VITESS_SHARDS VITESS_TABLETS VSCHEMA 266 267 // SET tokens 268 %token <str> NAMES GLOBAL SESSION ISOLATION LEVEL READ WRITE ONLY REPEATABLE COMMITTED UNCOMMITTED SERIALIZABLE 269 270 // Functions 271 %token <str> CURRENT_TIMESTAMP DATABASE CURRENT_DATE NOW 272 %token <str> CURRENT_TIME LOCALTIME LOCALTIMESTAMP CURRENT_USER 273 %token <str> UTC_DATE UTC_TIME UTC_TIMESTAMP 274 %token <str> DAY DAY_HOUR DAY_MICROSECOND DAY_MINUTE DAY_SECOND HOUR HOUR_MICROSECOND HOUR_MINUTE HOUR_SECOND MICROSECOND MINUTE MINUTE_MICROSECOND MINUTE_SECOND MONTH QUARTER SECOND SECOND_MICROSECOND YEAR_MONTH WEEK 275 %token <str> REPLACE 276 %token <str> CONVERT CAST 277 %token <str> SUBSTR SUBSTRING 278 %token <str> GROUP_CONCAT SEPARATOR 279 %token <str> TIMESTAMPADD TIMESTAMPDIFF 280 281 // Match 282 %token <str> MATCH AGAINST BOOLEAN LANGUAGE WITH QUERY EXPANSION WITHOUT VALIDATION 283 284 // MySQL reserved words that are unused by this grammar will map to this token. 285 %token <str> UNUSED ARRAY CUME_DIST DESCRIPTION DENSE_RANK EMPTY EXCEPT FIRST_VALUE GROUPING GROUPS JSON_TABLE LAG LAST_VALUE LATERAL LEAD MEMBER 286 %token <str> NTH_VALUE NTILE OF OVER PERCENT_RANK RANK RECURSIVE ROW_NUMBER SYSTEM WINDOW 287 %token <str> ACTIVE ADMIN BUCKETS CLONE COMPONENT DEFINITION ENFORCED EXCLUDE FOLLOWING GEOMCOLLECTION GET_MASTER_PUBLIC_KEY HISTOGRAM HISTORY 288 %token <str> INACTIVE INVISIBLE LOCKED MASTER_COMPRESSION_ALGORITHMS MASTER_PUBLIC_KEY_PATH MASTER_TLS_CIPHERSUITES MASTER_ZSTD_COMPRESSION_LEVEL 289 %token <str> NESTED NETWORK_NAMESPACE NOWAIT NULLS OJ OLD OPTIONAL ORDINALITY ORGANIZATION OTHERS PATH PERSIST PERSIST_ONLY PRECEDING PRIVILEGE_CHECKS_USER PROCESS 290 %token <str> RANDOM REFERENCE REQUIRE_ROW_FORMAT RESOURCE RESPECT RESTART RETAIN REUSE ROLE SECONDARY SECONDARY_ENGINE SECONDARY_LOAD SECONDARY_UNLOAD SKIP SRID 291 %token <str> THREAD_PRIORITY TIES UNBOUNDED VCPU VISIBLE 292 293 // Explain tokens 294 %token <str> FORMAT TREE VITESS TRADITIONAL 295 296 // Lock type tokens 297 %token <str> LOCAL LOW_PRIORITY 298 299 // Flush tokens 300 %token <str> NO_WRITE_TO_BINLOG LOGS ERROR GENERAL HOSTS OPTIMIZER_COSTS USER_RESOURCES SLOW CHANNEL RELAY EXPORT 301 302 // TableOptions tokens 303 %token <str> AVG_ROW_LENGTH CONNECTION CHECKSUM DELAY_KEY_WRITE ENCRYPTION ENGINE INSERT_METHOD MAX_ROWS MIN_ROWS PACK_KEYS PASSWORD 304 %token <str> FIXED DYNAMIC COMPRESSED REDUNDANT COMPACT ROW_FORMAT STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES STORAGE MEMORY DISK 305 306 // Partitions tokens 307 %token <str> PARTITIONS LINEAR RANGE LIST SUBPARTITION SUBPARTITIONS HASH 308 309 %type <str> linear_opt range_or_list partitions_opt subpartitions_opt algorithm_opt 310 %type <statement> command 311 %type <selStmt> query_expression_parens query_expression query_expression_body select_statement query_primary select_stmt_with_into 312 %type <statement> explain_statement explainable_statement 313 %type <statement> stream_statement vstream_statement insert_statement update_statement delete_statement set_statement set_transaction_statement 314 %type <statement> create_statement alter_statement rename_statement drop_statement truncate_statement flush_statement do_statement 315 %type <with> with_clause_opt with_clause 316 %type <cte> common_table_expr 317 %type <ctes> with_list 318 %type <renameTablePairs> rename_list 319 %type <createTable> create_table_prefix 320 %type <alterTable> alter_table_prefix 321 %type <alterOption> alter_option alter_commands_modifier lock_index algorithm_index 322 %type <alterOptions> alter_options alter_commands_list alter_commands_modifier_list algorithm_lock_opt 323 %type <alterTable> create_index_prefix 324 %type <createDatabase> create_database_prefix 325 %type <alterDatabase> alter_database_prefix 326 %type <collateAndCharset> collate character_set 327 %type <collateAndCharsets> create_options create_options_opt 328 %type <boolean> default_optional first_opt 329 %type <statement> analyze_statement show_statement use_statement other_statement 330 %type <statement> begin_statement commit_statement rollback_statement savepoint_statement release_statement load_statement 331 %type <statement> lock_statement unlock_statement call_statement 332 %type <statement> revert_statement 333 %type <strs> comment_opt comment_list 334 %type <str> wild_opt check_option_opt cascade_or_local_opt restrict_or_cascade_opt 335 %type <explainType> explain_format_opt 336 %type <insertAction> insert_or_replace 337 %type <str> explain_synonyms 338 %type <partitionOption> partitions_options_opt 339 %type <exprOrColumns> expr_or_col 340 %type <subPartition> subpartition_opt 341 %type <intervalType> interval_time_stamp interval 342 %type <str> cache_opt separator_opt flush_option for_channel_opt 343 %type <matchExprOption> match_option 344 %type <boolean> distinct_opt union_op replace_opt local_opt 345 %type <selectExprs> select_expression_list select_expression_list_opt 346 %type <selectExpr> select_expression 347 %type <strs> select_options flush_option_list 348 %type <str> select_option algorithm_view security_view security_view_opt 349 %type <str> definer_opt user generated_always_opt 350 %type <expr> expression signed_literal signed_literal_or_null null_as_literal now_or_signed_literal signed_literal bit_expr simple_expr literal NUM_literal text_literal text_literal_or_arg bool_pri literal_or_null now predicate tuple_expression 351 %type <tableExprs> from_opt table_references from_clause 352 %type <tableExpr> table_reference table_factor join_table 353 %type <joinCondition> join_condition join_condition_opt on_expression_opt 354 %type <tableNames> table_name_list delete_table_list view_name_list 355 %type <joinType> inner_join outer_join straight_join natural_join 356 %type <tableName> table_name into_table_name delete_table_name 357 %type <aliasedTableName> aliased_table_name 358 %type <indexHints> index_hint_list 359 %type <expr> where_expression_opt 360 %type <boolVal> boolean_value 361 %type <comparisonExprOperator> compare 362 %type <ins> insert_data 363 %type <expr> num_val 364 %type <expr> function_call_keyword function_call_nonkeyword function_call_generic function_call_conflict 365 %type <isExprOperator> is_suffix 366 %type <colTuple> col_tuple 367 %type <exprs> expression_list expression_list_opt 368 %type <values> tuple_list 369 %type <valTuple> row_tuple tuple_or_empty 370 %type <subquery> subquery 371 %type <derivedTable> derived_table 372 %type <colName> column_name after_opt 373 %type <whens> when_expression_list 374 %type <when> when_expression 375 %type <expr> expression_opt else_expression_opt 376 %type <exprs> group_by_opt 377 %type <expr> having_opt 378 %type <orderBy> order_by_opt order_list order_by_clause 379 %type <order> order 380 %type <orderDirection> asc_desc_opt 381 %type <limit> limit_opt limit_clause 382 %type <selectInto> into_clause 383 %type <columnTypeOptions> column_attribute_list_opt generated_column_attribute_list_opt 384 %type <str> header_opt export_options manifest_opt overwrite_opt format_opt optionally_opt 385 %type <str> fields_opts fields_opt_list fields_opt lines_opts lines_opt lines_opt_list 386 %type <lock> locking_clause 387 %type <columns> ins_column_list column_list column_list_opt index_list 388 %type <partitions> opt_partition_clause partition_list 389 %type <updateExprs> on_dup_opt 390 %type <updateExprs> update_list 391 %type <setExprs> set_list 392 %type <str> charset_or_character_set charset_or_character_set_or_names 393 %type <updateExpr> update_expression 394 %type <setExpr> set_expression 395 %type <characteristic> transaction_char 396 %type <characteristics> transaction_chars 397 %type <isolationLevel> isolation_level 398 %type <str> for_from 399 %type <str> default_opt 400 %type <ignore> ignore_opt 401 %type <str> columns_or_fields extended_opt storage_opt 402 %type <showFilter> like_or_where_opt like_opt 403 %type <boolean> exists_opt not_exists_opt enforced_opt temp_opt full_opt 404 %type <empty> to_opt 405 %type <str> reserved_keyword non_reserved_keyword 406 %type <colIdent> sql_id reserved_sql_id col_alias as_ci_opt 407 %type <expr> charset_value 408 %type <tableIdent> table_id reserved_table_id table_alias as_opt_id table_id_opt from_database_opt 409 %type <empty> as_opt work_opt savepoint_opt 410 %type <empty> skip_to_end ddl_skip_to_end 411 %type <str> charset 412 %type <scope> set_session_or_global 413 %type <convertType> convert_type 414 %type <columnType> column_type 415 %type <columnType> int_type decimal_type numeric_type time_type char_type spatial_type 416 %type <literal> length_opt 417 %type <expr> func_datetime_precision 418 %type <str> charset_opt collate_opt 419 %type <LengthScaleOption> float_length_opt decimal_length_opt 420 %type <boolean> unsigned_opt zero_fill_opt without_valid_opt 421 %type <strs> enum_values 422 %type <columnDefinition> column_definition 423 %type <columnDefinitions> column_definition_list 424 %type <indexDefinition> index_definition 425 %type <constraintDefinition> constraint_definition check_constraint_definition 426 %type <str> index_or_key index_symbols from_or_in index_or_key_opt 427 %type <str> name_opt constraint_name_opt 428 %type <str> equal_opt 429 %type <tableSpec> table_spec table_column_list 430 %type <optLike> create_like 431 %type <str> table_opt_value 432 %type <tableOption> table_option 433 %type <tableOptions> table_option_list table_option_list_opt space_separated_table_option_list 434 %type <indexInfo> index_info 435 %type <indexColumn> index_column 436 %type <indexColumns> index_column_list 437 %type <indexOption> index_option using_index_type 438 %type <indexOptions> index_option_list index_option_list_opt using_opt 439 %type <constraintInfo> constraint_info check_constraint_info 440 %type <partDefs> partition_definitions partition_definition_opt 441 %type <partDef> partition_definition 442 %type <partSpec> partition_operation 443 %type <vindexParam> vindex_param 444 %type <vindexParams> vindex_param_list vindex_params_opt 445 %type <colIdent> id_or_var vindex_type vindex_type_opt id_or_var_opt 446 %type <str> database_or_schema column_opt insert_method_options row_format_options 447 %type <ReferenceAction> fk_reference_action fk_on_delete fk_on_update 448 %type <str> vitess_topo 449 %type <tableAndLockTypes> lock_table_list 450 %type <tableAndLockType> lock_table 451 %type <lockType> lock_type 452 %type <empty> session_or_local_opt 453 %type <columnStorage> column_storage 454 %type <colKeyOpt> keys 455 %type <referenceDefinition> reference_definition reference_definition_opt 456 %type <str> underscore_charsets 457 %start any_command 458 459 %% 460 461 any_command: 462 command semicolon_opt 463 { 464 setParseTree(yylex, $1) 465 } 466 467 semicolon_opt: 468 /*empty*/ {} 469 | ';' {} 470 471 command: 472 select_statement 473 { 474 $$ = $1 475 } 476 | stream_statement 477 | vstream_statement 478 | insert_statement 479 | update_statement 480 | delete_statement 481 | set_statement 482 | set_transaction_statement 483 | create_statement 484 | alter_statement 485 | rename_statement 486 | drop_statement 487 | truncate_statement 488 | analyze_statement 489 | show_statement 490 | use_statement 491 | begin_statement 492 | commit_statement 493 | rollback_statement 494 | savepoint_statement 495 | release_statement 496 | explain_statement 497 | other_statement 498 | flush_statement 499 | do_statement 500 | load_statement 501 | lock_statement 502 | unlock_statement 503 | call_statement 504 | revert_statement 505 | /*empty*/ 506 { 507 setParseTree(yylex, nil) 508 } 509 510 id_or_var: 511 ID 512 { 513 $$ = NewColIdentWithAt(string($1), NoAt) 514 } 515 | AT_ID 516 { 517 $$ = NewColIdentWithAt(string($1), SingleAt) 518 } 519 | AT_AT_ID 520 { 521 $$ = NewColIdentWithAt(string($1), DoubleAt) 522 } 523 524 id_or_var_opt: 525 { 526 $$ = NewColIdentWithAt("", NoAt) 527 } 528 | id_or_var 529 { 530 $$ = $1 531 } 532 533 do_statement: 534 DO expression_list 535 { 536 $$ = &OtherAdmin{} 537 } 538 539 load_statement: 540 LOAD DATA skip_to_end 541 { 542 $$ = &Load{} 543 } 544 545 with_clause: 546 WITH with_list 547 { 548 $$ = &With{ctes: $2, Recursive: false} 549 } 550 | WITH RECURSIVE with_list 551 { 552 $$ = &With{ctes: $3, Recursive: true} 553 } 554 555 with_clause_opt: 556 { 557 $$ = nil 558 } 559 | with_clause 560 { 561 $$ = $1 562 } 563 564 with_list: 565 with_list ',' common_table_expr 566 { 567 $$ = append($1, $3) 568 } 569 | common_table_expr 570 { 571 $$ = []*CommonTableExpr{$1} 572 } 573 574 common_table_expr: 575 table_id column_list_opt AS subquery 576 { 577 $$ = &CommonTableExpr{TableID: $1, Columns: $2, Subquery: $4} 578 } 579 580 query_expression_parens: 581 openb query_expression_parens closeb 582 { 583 $$ = $2 584 } 585 | openb query_expression closeb 586 { 587 $$ = $2 588 } 589 | openb query_expression locking_clause closeb 590 { 591 setLockInSelect($2, $3) 592 $$ = $2 593 } 594 595 // TODO; (Manan, Ritwiz) : Use this in create, insert statements 596 //query_expression_or_parens: 597 // query_expression 598 // { 599 // $$ = $1 600 // } 601 // | query_expression locking_clause 602 // { 603 // setLockInSelect($1, $2) 604 // $$ = $1 605 // } 606 // | query_expression_parens 607 // { 608 // $$ = $1 609 // } 610 611 query_expression: 612 query_expression_body order_by_opt limit_opt 613 { 614 $1.SetOrderBy($2) 615 $1.SetLimit($3) 616 $$ = $1 617 } 618 | query_expression_parens limit_clause 619 { 620 $1.SetLimit($2) 621 $$ = $1 622 } 623 | query_expression_parens order_by_clause limit_opt 624 { 625 $1.SetOrderBy($2) 626 $1.SetLimit($3) 627 $$ = $1 628 } 629 | with_clause query_expression_body order_by_opt limit_opt 630 { 631 $2.SetWith($1) 632 $2.SetOrderBy($3) 633 $2.SetLimit($4) 634 $$ = $2 635 } 636 | with_clause query_expression_parens limit_clause 637 { 638 $2.SetWith($1) 639 $2.SetLimit($3) 640 $$ = $2 641 } 642 | with_clause query_expression_parens order_by_clause limit_opt 643 { 644 $2.SetWith($1) 645 $2.SetOrderBy($3) 646 $2.SetLimit($4) 647 $$ = $2 648 } 649 | with_clause query_expression_parens 650 { 651 $2.SetWith($1) 652 } 653 | SELECT comment_opt cache_opt NEXT num_val for_from table_name 654 { 655 $$ = NewSelect(Comments($2), SelectExprs{&Nextval{Expr: $5}}, []string{$3}/*options*/, nil, TableExprs{&AliasedTableExpr{Expr: $7}}, nil/*where*/, nil/*groupBy*/, nil/*having*/) 656 } 657 658 query_expression_body: 659 query_primary 660 { 661 $$ = $1 662 } 663 | query_expression_body union_op query_primary 664 { 665 $$ = &Union{Left: $1, Distinct: $2, Right: $3} 666 } 667 | query_expression_parens union_op query_primary 668 { 669 $$ = &Union{Left: $1, Distinct: $2, Right: $3} 670 } 671 | query_expression_body union_op query_expression_parens 672 { 673 $$ = &Union{Left: $1, Distinct: $2, Right: $3} 674 } 675 | query_expression_parens union_op query_expression_parens 676 { 677 $$ = &Union{Left: $1, Distinct: $2, Right: $3} 678 } 679 680 select_statement: 681 query_expression 682 { 683 $$ = $1 684 } 685 | query_expression locking_clause 686 { 687 setLockInSelect($1, $2) 688 $$ = $1 689 } 690 | query_expression_parens 691 { 692 $$ = $1 693 } 694 | select_stmt_with_into 695 { 696 $$ = $1 697 } 698 699 select_stmt_with_into: 700 openb select_stmt_with_into closeb 701 { 702 $$ = $2; 703 } 704 | query_expression into_clause 705 { 706 $1.SetInto($2) 707 $$ = $1 708 } 709 | query_expression into_clause locking_clause 710 { 711 $1.SetInto($2) 712 $1.SetLock($3) 713 $$ = $1 714 } 715 | query_expression locking_clause into_clause 716 { 717 $1.SetInto($3) 718 $1.SetLock($2) 719 $$ = $1 720 } 721 | query_expression_parens into_clause 722 { 723 $1.SetInto($2) 724 $$ = $1 725 } 726 727 stream_statement: 728 STREAM comment_opt select_expression FROM table_name 729 { 730 $$ = &Stream{Comments: Comments($2), SelectExpr: $3, Table: $5} 731 } 732 733 vstream_statement: 734 VSTREAM comment_opt select_expression FROM table_name where_expression_opt limit_opt 735 { 736 $$ = &VStream{Comments: Comments($2), SelectExpr: $3, Table: $5, Where: NewWhere(WhereClause, $6), Limit: $7} 737 } 738 739 // query_primary is an unparenthesized SELECT with no order by clause or beyond. 740 query_primary: 741 // 1 2 3 4 5 6 7 8 742 SELECT comment_opt select_options select_expression_list into_clause from_opt where_expression_opt group_by_opt having_opt 743 { 744 $$ = NewSelect(Comments($2), $4/*SelectExprs*/, $3/*options*/, $5/*into*/, $6/*from*/, NewWhere(WhereClause, $7), GroupBy($8), NewWhere(HavingClause, $9)) 745 } 746 | SELECT comment_opt select_options select_expression_list from_opt where_expression_opt group_by_opt having_opt 747 { 748 $$ = NewSelect(Comments($2), $4/*SelectExprs*/, $3/*options*/, nil, $5/*from*/, NewWhere(WhereClause, $6), GroupBy($7), NewWhere(HavingClause, $8)) 749 } 750 751 752 753 insert_statement: 754 insert_or_replace comment_opt ignore_opt into_table_name opt_partition_clause insert_data on_dup_opt 755 { 756 // insert_data returns a *Insert pre-filled with Columns & Values 757 ins := $6 758 ins.Action = $1 759 ins.Comments = $2 760 ins.Ignore = $3 761 ins.Table = $4 762 ins.Partitions = $5 763 ins.OnDup = OnDup($7) 764 $$ = ins 765 } 766 | insert_or_replace comment_opt ignore_opt into_table_name opt_partition_clause SET update_list on_dup_opt 767 { 768 cols := make(Columns, 0, len($7)) 769 vals := make(ValTuple, 0, len($8)) 770 for _, updateList := range $7 { 771 cols = append(cols, updateList.Name.Name) 772 vals = append(vals, updateList.Expr) 773 } 774 $$ = &Insert{Action: $1, Comments: Comments($2), Ignore: $3, Table: $4, Partitions: $5, Columns: cols, Rows: Values{vals}, OnDup: OnDup($8)} 775 } 776 777 insert_or_replace: 778 INSERT 779 { 780 $$ = InsertAct 781 } 782 | REPLACE 783 { 784 $$ = ReplaceAct 785 } 786 787 update_statement: 788 with_clause_opt UPDATE comment_opt ignore_opt table_references SET update_list where_expression_opt order_by_opt limit_opt 789 { 790 $$ = &Update{With: $1, Comments: Comments($3), Ignore: $4, TableExprs: $5, Exprs: $7, Where: NewWhere(WhereClause, $8), OrderBy: $9, Limit: $10} 791 } 792 793 delete_statement: 794 with_clause_opt DELETE comment_opt ignore_opt FROM table_name as_opt_id opt_partition_clause where_expression_opt order_by_opt limit_opt 795 { 796 $$ = &Delete{With: $1, Comments: Comments($3), Ignore: $4, TableExprs: TableExprs{&AliasedTableExpr{Expr:$6, As: $7}}, Partitions: $8, Where: NewWhere(WhereClause, $9), OrderBy: $10, Limit: $11} 797 } 798 | with_clause_opt DELETE comment_opt ignore_opt FROM table_name_list USING table_references where_expression_opt 799 { 800 $$ = &Delete{With: $1, Comments: Comments($3), Ignore: $4, Targets: $6, TableExprs: $8, Where: NewWhere(WhereClause, $9)} 801 } 802 | with_clause_opt DELETE comment_opt ignore_opt table_name_list from_or_using table_references where_expression_opt 803 { 804 $$ = &Delete{With: $1, Comments: Comments($3), Ignore: $4, Targets: $5, TableExprs: $7, Where: NewWhere(WhereClause, $8)} 805 } 806 | with_clause_opt DELETE comment_opt ignore_opt delete_table_list from_or_using table_references where_expression_opt 807 { 808 $$ = &Delete{With: $1, Comments: Comments($3), Ignore: $4, Targets: $5, TableExprs: $7, Where: NewWhere(WhereClause, $8)} 809 } 810 811 from_or_using: 812 FROM {} 813 | USING {} 814 815 view_name_list: 816 table_name 817 { 818 $$ = TableNames{$1.ToViewName()} 819 } 820 | view_name_list ',' table_name 821 { 822 $$ = append($$, $3.ToViewName()) 823 } 824 825 table_name_list: 826 table_name 827 { 828 $$ = TableNames{$1} 829 } 830 | table_name_list ',' table_name 831 { 832 $$ = append($$, $3) 833 } 834 835 delete_table_list: 836 delete_table_name 837 { 838 $$ = TableNames{$1} 839 } 840 | delete_table_list ',' delete_table_name 841 { 842 $$ = append($$, $3) 843 } 844 845 opt_partition_clause: 846 { 847 $$ = nil 848 } 849 | PARTITION openb partition_list closeb 850 { 851 $$ = $3 852 } 853 854 set_statement: 855 SET comment_opt set_list 856 { 857 $$ = &Set{Comments: Comments($2), Exprs: $3} 858 } 859 860 set_transaction_statement: 861 SET comment_opt set_session_or_global TRANSACTION transaction_chars 862 { 863 $$ = &SetTransaction{Comments: Comments($2), Scope: $3, Characteristics: $5} 864 } 865 | SET comment_opt TRANSACTION transaction_chars 866 { 867 $$ = &SetTransaction{Comments: Comments($2), Characteristics: $4, Scope: ImplicitScope} 868 } 869 870 transaction_chars: 871 transaction_char 872 { 873 $$ = []Characteristic{$1} 874 } 875 | transaction_chars ',' transaction_char 876 { 877 $$ = append($$, $3) 878 } 879 880 transaction_char: 881 ISOLATION LEVEL isolation_level 882 { 883 $$ = $3 884 } 885 | READ WRITE 886 { 887 $$ = ReadWrite 888 } 889 | READ ONLY 890 { 891 $$ = ReadOnly 892 } 893 894 isolation_level: 895 REPEATABLE READ 896 { 897 $$ = RepeatableRead 898 } 899 | READ COMMITTED 900 { 901 $$ = ReadCommitted 902 } 903 | READ UNCOMMITTED 904 { 905 $$ = ReadUncommitted 906 } 907 | SERIALIZABLE 908 { 909 $$ = Serializable 910 } 911 912 set_session_or_global: 913 SESSION 914 { 915 $$ = SessionScope 916 } 917 | GLOBAL 918 { 919 $$ = GlobalScope 920 } 921 922 create_statement: 923 create_table_prefix table_spec 924 { 925 $1.TableSpec = $2 926 $1.FullyParsed = true 927 $$ = $1 928 } 929 | create_table_prefix create_like 930 { 931 // Create table [name] like [name] 932 $1.OptLike = $2 933 $1.FullyParsed = true 934 $$ = $1 935 } 936 | create_index_prefix '(' index_column_list ')' index_option_list_opt algorithm_lock_opt 937 { 938 indexDef := $1.AlterOptions[0].(*AddIndexDefinition).IndexDefinition 939 indexDef.Columns = $3 940 indexDef.Options = append(indexDef.Options,$5...) 941 $1.AlterOptions = append($1.AlterOptions,$6...) 942 $1.FullyParsed = true 943 $$ = $1 944 } 945 | CREATE comment_opt replace_opt algorithm_view definer_opt security_view_opt VIEW table_name column_list_opt AS select_statement check_option_opt 946 { 947 $$ = &CreateView{ViewName: $8.ToViewName(), IsReplace:$3, Algorithm:$4, Definer: $5 ,Security:$6, Columns:$9, Select: $11, CheckOption: $12 } 948 } 949 | create_database_prefix create_options_opt 950 { 951 $1.FullyParsed = true 952 $1.CreateOptions = $2 953 $$ = $1 954 } 955 956 replace_opt: 957 { 958 $$ = false 959 } 960 | OR REPLACE 961 { 962 $$ = true 963 } 964 965 vindex_type_opt: 966 { 967 $$ = NewColIdent("") 968 } 969 | USING vindex_type 970 { 971 $$ = $2 972 } 973 974 vindex_type: 975 sql_id 976 { 977 $$ = $1 978 } 979 980 vindex_params_opt: 981 { 982 var v []VindexParam 983 $$ = v 984 } 985 | WITH vindex_param_list 986 { 987 $$ = $2 988 } 989 990 vindex_param_list: 991 vindex_param 992 { 993 $$ = make([]VindexParam, 0, 4) 994 $$ = append($$, $1) 995 } 996 | vindex_param_list ',' vindex_param 997 { 998 $$ = append($$, $3) 999 } 1000 1001 vindex_param: 1002 reserved_sql_id '=' table_opt_value 1003 { 1004 $$ = VindexParam{Key: $1, Val: $3} 1005 } 1006 1007 create_table_prefix: 1008 CREATE comment_opt temp_opt TABLE not_exists_opt table_name 1009 { 1010 $$ = &CreateTable{Comments: Comments($2), Table: $6, IfNotExists: $5, Temp: $3} 1011 setDDL(yylex, $$) 1012 } 1013 1014 alter_table_prefix: 1015 ALTER comment_opt TABLE table_name 1016 { 1017 $$ = &AlterTable{Comments: Comments($2), Table: $4} 1018 setDDL(yylex, $$) 1019 } 1020 1021 create_index_prefix: 1022 CREATE comment_opt INDEX id_or_var using_opt ON table_name 1023 { 1024 $$ = &AlterTable{Table: $7, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$4, Type:string($3)}, Options:$5}}}} 1025 setDDL(yylex, $$) 1026 } 1027 | CREATE comment_opt FULLTEXT INDEX id_or_var using_opt ON table_name 1028 { 1029 $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Fulltext:true}, Options:$6}}}} 1030 setDDL(yylex, $$) 1031 } 1032 | CREATE comment_opt SPATIAL INDEX id_or_var using_opt ON table_name 1033 { 1034 $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Spatial:true}, Options:$6}}}} 1035 setDDL(yylex, $$) 1036 } 1037 | CREATE comment_opt UNIQUE INDEX id_or_var using_opt ON table_name 1038 { 1039 $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Unique:true}, Options:$6}}}} 1040 setDDL(yylex, $$) 1041 } 1042 1043 create_database_prefix: 1044 CREATE comment_opt database_or_schema comment_opt not_exists_opt table_id 1045 { 1046 $$ = &CreateDatabase{Comments: Comments($4), DBName: $6, IfNotExists: $5} 1047 setDDL(yylex,$$) 1048 } 1049 1050 alter_database_prefix: 1051 ALTER comment_opt database_or_schema 1052 { 1053 $$ = &AlterDatabase{} 1054 setDDL(yylex,$$) 1055 } 1056 1057 database_or_schema: 1058 DATABASE 1059 | SCHEMA 1060 1061 table_spec: 1062 '(' table_column_list ')' table_option_list_opt partitions_options_opt 1063 { 1064 $$ = $2 1065 $$.Options = $4 1066 $$.PartitionOption = $5 1067 } 1068 1069 create_options_opt: 1070 { 1071 $$ = nil 1072 } 1073 | create_options 1074 { 1075 $$ = $1 1076 } 1077 1078 create_options: 1079 character_set 1080 { 1081 $$ = []CollateAndCharset{$1} 1082 } 1083 | collate 1084 { 1085 $$ = []CollateAndCharset{$1} 1086 } 1087 | create_options collate 1088 { 1089 $$ = append($1,$2) 1090 } 1091 | create_options character_set 1092 { 1093 $$ = append($1,$2) 1094 } 1095 1096 default_optional: 1097 /* empty */ %prec LOWER_THAN_CHARSET 1098 { 1099 $$ = false 1100 } 1101 | DEFAULT 1102 { 1103 $$ = true 1104 } 1105 1106 character_set: 1107 default_optional charset_or_character_set equal_opt id_or_var 1108 { 1109 $$ = CollateAndCharset{Type:CharacterSetType, Value:($4.String()), IsDefault:$1} 1110 } 1111 | default_optional charset_or_character_set equal_opt STRING 1112 { 1113 $$ = CollateAndCharset{Type:CharacterSetType, Value:(encodeSQLString($4)), IsDefault:$1} 1114 } 1115 1116 collate: 1117 default_optional COLLATE equal_opt id_or_var 1118 { 1119 $$ = CollateAndCharset{Type:CollateType, Value:($4.String()), IsDefault:$1} 1120 } 1121 | default_optional COLLATE equal_opt STRING 1122 { 1123 $$ = CollateAndCharset{Type:CollateType, Value:(encodeSQLString($4)), IsDefault:$1} 1124 } 1125 1126 1127 create_like: 1128 LIKE table_name 1129 { 1130 $$ = &OptLike{LikeTable: $2} 1131 } 1132 | '(' LIKE table_name ')' 1133 { 1134 $$ = &OptLike{LikeTable: $3} 1135 } 1136 1137 column_definition_list: 1138 column_definition 1139 { 1140 $$ = []*ColumnDefinition{$1} 1141 } 1142 | column_definition_list ',' column_definition 1143 { 1144 $$ = append($1,$3) 1145 } 1146 1147 table_column_list: 1148 column_definition 1149 { 1150 $$ = &TableSpec{} 1151 $$.AddColumn($1) 1152 } 1153 | check_constraint_definition 1154 { 1155 $$ = &TableSpec{} 1156 $$.AddConstraint($1) 1157 } 1158 | table_column_list ',' column_definition 1159 { 1160 $$.AddColumn($3) 1161 } 1162 | table_column_list ',' column_definition check_constraint_definition 1163 { 1164 $$.AddColumn($3) 1165 $$.AddConstraint($4) 1166 } 1167 | table_column_list ',' index_definition 1168 { 1169 $$.AddIndex($3) 1170 } 1171 | table_column_list ',' constraint_definition 1172 { 1173 $$.AddConstraint($3) 1174 } 1175 | table_column_list ',' check_constraint_definition 1176 { 1177 $$.AddConstraint($3) 1178 } 1179 1180 column_definition: 1181 sql_id column_type column_attribute_list_opt reference_definition_opt 1182 { 1183 $2.Options = $3 1184 $2.Options.Reference = $4 1185 $$ = &ColumnDefinition{Name: $1, Type: $2} 1186 } 1187 | sql_id column_type generated_always_opt AS '(' expression ')' generated_column_attribute_list_opt reference_definition_opt 1188 { 1189 $2.Options = $8 1190 $2.Options.As = $6 1191 $2.Options.Reference = $9 1192 $$ = &ColumnDefinition{Name: $1, Type: $2} 1193 } 1194 1195 generated_always_opt: 1196 { 1197 $$ = "" 1198 } 1199 | GENERATED ALWAYS 1200 { 1201 $$ = "" 1202 } 1203 1204 // There is a shift reduce conflict that arises here because UNIQUE and KEY are column_type_option and so is UNIQUE KEY. 1205 // So in the state "column_type_options UNIQUE. KEY" there is a shift-reduce conflict(resovled by "%rigth <str> UNIQUE KEY"). 1206 // This has been added to emulate what MySQL does. The previous architecture was such that the order of the column options 1207 // was specific (as stated in the MySQL guide) and did not accept arbitrary order options. For example NOT NULL DEFAULT 1 and not DEFAULT 1 NOT NULL 1208 column_attribute_list_opt: 1209 { 1210 $$ = &ColumnTypeOptions{Null: nil, Default: nil, OnUpdate: nil, Autoincrement: false, KeyOpt: colKeyNone, Comment: nil, As: nil} 1211 } 1212 | column_attribute_list_opt NULL 1213 { 1214 val := true 1215 $1.Null = &val 1216 $$ = $1 1217 } 1218 | column_attribute_list_opt NOT NULL 1219 { 1220 val := false 1221 $1.Null = &val 1222 $$ = $1 1223 } 1224 | column_attribute_list_opt DEFAULT openb expression closeb 1225 { 1226 $1.Default = $4 1227 $$ = $1 1228 } 1229 | column_attribute_list_opt DEFAULT now_or_signed_literal 1230 { 1231 $1.Default = $3 1232 $$ = $1 1233 } 1234 | column_attribute_list_opt ON UPDATE function_call_nonkeyword 1235 { 1236 $1.OnUpdate = $4 1237 $$ = $1 1238 } 1239 | column_attribute_list_opt AUTO_INCREMENT 1240 { 1241 $1.Autoincrement = true 1242 $$ = $1 1243 } 1244 | column_attribute_list_opt COMMENT_KEYWORD STRING 1245 { 1246 $1.Comment = NewStrLiteral($3) 1247 $$ = $1 1248 } 1249 | column_attribute_list_opt keys 1250 { 1251 $1.KeyOpt = $2 1252 $$ = $1 1253 } 1254 | column_attribute_list_opt COLLATE STRING 1255 { 1256 $1.Collate = encodeSQLString($3) 1257 } 1258 | column_attribute_list_opt COLLATE id_or_var 1259 { 1260 $1.Collate = string($3.String()) 1261 $$ = $1 1262 } 1263 1264 column_storage: 1265 VIRTUAL 1266 { 1267 $$ = VirtualStorage 1268 } 1269 | STORED 1270 { 1271 $$ = StoredStorage 1272 } 1273 1274 generated_column_attribute_list_opt: 1275 { 1276 $$ = &ColumnTypeOptions{} 1277 } 1278 | generated_column_attribute_list_opt column_storage 1279 { 1280 $1.Storage = $2 1281 $$ = $1 1282 } 1283 | generated_column_attribute_list_opt NULL 1284 { 1285 val := true 1286 $1.Null = &val 1287 $$ = $1 1288 } 1289 | generated_column_attribute_list_opt NOT NULL 1290 { 1291 val := false 1292 $1.Null = &val 1293 $$ = $1 1294 } 1295 | generated_column_attribute_list_opt COMMENT_KEYWORD STRING 1296 { 1297 $1.Comment = NewStrLiteral($3) 1298 $$ = $1 1299 } 1300 | generated_column_attribute_list_opt keys 1301 { 1302 $1.KeyOpt = $2 1303 $$ = $1 1304 } 1305 1306 now_or_signed_literal: 1307 now 1308 { 1309 $$ = $1 1310 } 1311 | signed_literal_or_null 1312 1313 now: 1314 CURRENT_TIMESTAMP func_datetime_precision 1315 { 1316 $$ = &CurTimeFuncExpr{Name:NewColIdent("current_timestamp"), Fsp: $2} 1317 } 1318 | LOCALTIME func_datetime_precision 1319 { 1320 $$ = &CurTimeFuncExpr{Name:NewColIdent("localtime"), Fsp: $2} 1321 } 1322 | LOCALTIMESTAMP func_datetime_precision 1323 { 1324 $$ = &CurTimeFuncExpr{Name:NewColIdent("localtimestamp"), Fsp: $2} 1325 } 1326 | UTC_TIMESTAMP func_datetime_precision 1327 { 1328 $$ = &CurTimeFuncExpr{Name:NewColIdent("utc_timestamp"), Fsp:$2} 1329 } 1330 | NOW func_datetime_precision 1331 { 1332 $$ = &CurTimeFuncExpr{Name:NewColIdent("now"), Fsp: $2} 1333 } 1334 1335 1336 signed_literal_or_null: 1337 signed_literal 1338 | null_as_literal 1339 1340 null_as_literal: 1341 NULL 1342 { 1343 $$ = &NullVal{} 1344 } 1345 1346 signed_literal: 1347 literal 1348 | '+' NUM_literal 1349 { 1350 $$= $2 1351 } 1352 | '-' NUM_literal 1353 { 1354 $$ = &UnaryExpr{Operator: UMinusOp, Expr: $2} 1355 } 1356 1357 literal: 1358 text_literal 1359 { 1360 $$= $1 1361 } 1362 | NUM_literal 1363 { 1364 $$= $1 1365 } 1366 | boolean_value 1367 { 1368 $$ = $1 1369 } 1370 | HEX 1371 { 1372 $$ = NewHexLiteral($1) 1373 } 1374 | HEXNUM 1375 { 1376 $$ = NewHexNumLiteral($1) 1377 } 1378 | BIT_LITERAL 1379 { 1380 $$ = NewBitLiteral($1) 1381 } 1382 | VALUE_ARG 1383 { 1384 $$ = NewArgument($1[1:]) 1385 bindVariable(yylex, $1[1:]) 1386 } 1387 | underscore_charsets BIT_LITERAL %prec UNARY 1388 { 1389 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewBitLiteral($2)} 1390 } 1391 | underscore_charsets HEXNUM %prec UNARY 1392 { 1393 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewHexNumLiteral($2)} 1394 } 1395 | underscore_charsets HEX %prec UNARY 1396 { 1397 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewHexLiteral($2)} 1398 } 1399 | underscore_charsets column_name %prec UNARY 1400 { 1401 $$ = &IntroducerExpr{CharacterSet: $1, Expr: $2} 1402 } 1403 | underscore_charsets VALUE_ARG %prec UNARY 1404 { 1405 bindVariable(yylex, $2[1:]) 1406 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewArgument($2[1:])} 1407 } 1408 1409 underscore_charsets: 1410 UNDERSCORE_ARMSCII8 1411 { 1412 $$ = Armscii8Str 1413 } 1414 | UNDERSCORE_ASCII 1415 { 1416 $$ = ASCIIStr 1417 } 1418 | UNDERSCORE_BIG5 1419 { 1420 $$ = Big5Str 1421 } 1422 | UNDERSCORE_BINARY 1423 { 1424 $$ = UBinaryStr 1425 } 1426 | UNDERSCORE_CP1250 1427 { 1428 $$ = Cp1250Str 1429 } 1430 | UNDERSCORE_CP1251 1431 { 1432 $$ = Cp1251Str 1433 } 1434 | UNDERSCORE_CP1256 1435 { 1436 $$ = Cp1256Str 1437 } 1438 | UNDERSCORE_CP1257 1439 { 1440 $$ = Cp1257Str 1441 } 1442 | UNDERSCORE_CP850 1443 { 1444 $$ = Cp850Str 1445 } 1446 | UNDERSCORE_CP852 1447 { 1448 $$ = Cp852Str 1449 } 1450 | UNDERSCORE_CP866 1451 { 1452 $$ = Cp866Str 1453 } 1454 | UNDERSCORE_CP932 1455 { 1456 $$ = Cp932Str 1457 } 1458 | UNDERSCORE_DEC8 1459 { 1460 $$ = Dec8Str 1461 } 1462 | UNDERSCORE_EUCJPMS 1463 { 1464 $$ = EucjpmsStr 1465 } 1466 | UNDERSCORE_EUCKR 1467 { 1468 $$ = EuckrStr 1469 } 1470 | UNDERSCORE_GB18030 1471 { 1472 $$ = Gb18030Str 1473 } 1474 | UNDERSCORE_GB2312 1475 { 1476 $$ = Gb2312Str 1477 } 1478 | UNDERSCORE_GBK 1479 { 1480 $$ = GbkStr 1481 } 1482 | UNDERSCORE_GEOSTD8 1483 { 1484 $$ = Geostd8Str 1485 } 1486 | UNDERSCORE_GREEK 1487 { 1488 $$ = GreekStr 1489 } 1490 | UNDERSCORE_HEBREW 1491 { 1492 $$ = HebrewStr 1493 } 1494 | UNDERSCORE_HP8 1495 { 1496 $$ = Hp8Str 1497 } 1498 | UNDERSCORE_KEYBCS2 1499 { 1500 $$ = Keybcs2Str 1501 } 1502 | UNDERSCORE_KOI8R 1503 { 1504 $$ = Koi8rStr 1505 } 1506 | UNDERSCORE_KOI8U 1507 { 1508 $$ = Koi8uStr 1509 } 1510 | UNDERSCORE_LATIN1 1511 { 1512 $$ = Latin1Str 1513 } 1514 | UNDERSCORE_LATIN2 1515 { 1516 $$ = Latin2Str 1517 } 1518 | UNDERSCORE_LATIN5 1519 { 1520 $$ = Latin5Str 1521 } 1522 | UNDERSCORE_LATIN7 1523 { 1524 $$ = Latin7Str 1525 } 1526 | UNDERSCORE_MACCE 1527 { 1528 $$ = MacceStr 1529 } 1530 | UNDERSCORE_MACROMAN 1531 { 1532 $$ = MacromanStr 1533 } 1534 | UNDERSCORE_SJIS 1535 { 1536 $$ = SjisStr 1537 } 1538 | UNDERSCORE_SWE7 1539 { 1540 $$ = Swe7Str 1541 } 1542 | UNDERSCORE_TIS620 1543 { 1544 $$ = Tis620Str 1545 } 1546 | UNDERSCORE_UCS2 1547 { 1548 $$ = Ucs2Str 1549 } 1550 | UNDERSCORE_UJIS 1551 { 1552 $$ = UjisStr 1553 } 1554 | UNDERSCORE_UTF16 1555 { 1556 $$ = Utf16Str 1557 } 1558 | UNDERSCORE_UTF16LE 1559 { 1560 $$ = Utf16leStr 1561 } 1562 | UNDERSCORE_UTF32 1563 { 1564 $$ = Utf32Str 1565 } 1566 | UNDERSCORE_UTF8 1567 { 1568 $$ = Utf8Str 1569 } 1570 | UNDERSCORE_UTF8MB4 1571 { 1572 $$ = Utf8mb4Str 1573 } 1574 1575 literal_or_null: 1576 literal 1577 | null_as_literal 1578 1579 NUM_literal: 1580 INTEGRAL 1581 { 1582 $$ = NewIntLiteral($1) 1583 } 1584 | FLOAT 1585 { 1586 $$ = NewFloatLiteral($1) 1587 } 1588 | DECIMAL 1589 { 1590 $$ = NewDecimalLiteral($1) 1591 } 1592 1593 1594 text_literal: 1595 STRING 1596 { 1597 $$ = NewStrLiteral($1) 1598 } 1599 | NCHAR_STRING 1600 { 1601 $$ = &UnaryExpr{Operator: NStringOp, Expr: NewStrLiteral($1)} 1602 } 1603 | underscore_charsets STRING %prec UNARY 1604 { 1605 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewStrLiteral($2)} 1606 } 1607 1608 text_literal_or_arg: 1609 STRING 1610 { 1611 $$ = NewStrLiteral($1) 1612 } 1613 | NCHAR_STRING 1614 { 1615 $$ = &UnaryExpr{Operator: NStringOp, Expr: NewStrLiteral($1)} 1616 } 1617 | underscore_charsets STRING %prec UNARY 1618 { 1619 $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewStrLiteral($2)} 1620 } 1621 | VALUE_ARG 1622 { 1623 $$ = NewArgument($1[1:]) 1624 bindVariable(yylex, $1[1:]) 1625 } 1626 1627 keys: 1628 PRIMARY KEY 1629 { 1630 $$ = colKeyPrimary 1631 } 1632 | UNIQUE 1633 { 1634 $$ = colKeyUnique 1635 } 1636 | UNIQUE KEY 1637 { 1638 $$ = colKeyUniqueKey 1639 } 1640 | KEY 1641 { 1642 $$ = colKey 1643 } 1644 1645 column_type: 1646 numeric_type unsigned_opt zero_fill_opt 1647 { 1648 $$ = $1 1649 $$.Unsigned = $2 1650 $$.Zerofill = $3 1651 } 1652 | char_type 1653 | time_type 1654 | spatial_type 1655 1656 numeric_type: 1657 int_type length_opt 1658 { 1659 $$ = $1 1660 $$.Length = $2 1661 } 1662 | decimal_type 1663 { 1664 $$ = $1 1665 } 1666 1667 int_type: 1668 BIT 1669 { 1670 $$ = ColumnType{Type: string($1)} 1671 } 1672 | BOOL 1673 { 1674 $$ = ColumnType{Type: string($1)} 1675 } 1676 | BOOLEAN 1677 { 1678 $$ = ColumnType{Type: string($1)} 1679 } 1680 | TINYINT 1681 { 1682 $$ = ColumnType{Type: string($1)} 1683 } 1684 | SMALLINT 1685 { 1686 $$ = ColumnType{Type: string($1)} 1687 } 1688 | MEDIUMINT 1689 { 1690 $$ = ColumnType{Type: string($1)} 1691 } 1692 | INT 1693 { 1694 $$ = ColumnType{Type: string($1)} 1695 } 1696 | INTEGER 1697 { 1698 $$ = ColumnType{Type: string($1)} 1699 } 1700 | BIGINT 1701 { 1702 $$ = ColumnType{Type: string($1)} 1703 } 1704 1705 decimal_type: 1706 REAL float_length_opt 1707 { 1708 $$ = ColumnType{Type: string($1)} 1709 $$.Length = $2.Length 1710 $$.Scale = $2.Scale 1711 } 1712 | DOUBLE float_length_opt 1713 { 1714 $$ = ColumnType{Type: string($1)} 1715 $$.Length = $2.Length 1716 $$.Scale = $2.Scale 1717 } 1718 | FLOAT_TYPE float_length_opt 1719 { 1720 $$ = ColumnType{Type: string($1)} 1721 $$.Length = $2.Length 1722 $$.Scale = $2.Scale 1723 } 1724 | DECIMAL_TYPE decimal_length_opt 1725 { 1726 $$ = ColumnType{Type: string($1)} 1727 $$.Length = $2.Length 1728 $$.Scale = $2.Scale 1729 } 1730 | NUMERIC decimal_length_opt 1731 { 1732 $$ = ColumnType{Type: string($1)} 1733 $$.Length = $2.Length 1734 $$.Scale = $2.Scale 1735 } 1736 1737 time_type: 1738 DATE 1739 { 1740 $$ = ColumnType{Type: string($1)} 1741 } 1742 | TIME length_opt 1743 { 1744 $$ = ColumnType{Type: string($1), Length: $2} 1745 } 1746 | TIMESTAMP length_opt 1747 { 1748 $$ = ColumnType{Type: string($1), Length: $2} 1749 } 1750 | DATETIME length_opt 1751 { 1752 $$ = ColumnType{Type: string($1), Length: $2} 1753 } 1754 | YEAR length_opt 1755 { 1756 $$ = ColumnType{Type: string($1), Length: $2} 1757 } 1758 1759 char_type: 1760 CHAR length_opt charset_opt 1761 { 1762 $$ = ColumnType{Type: string($1), Length: $2, Charset: $3} 1763 } 1764 | VARCHAR length_opt charset_opt 1765 { 1766 $$ = ColumnType{Type: string($1), Length: $2, Charset: $3} 1767 } 1768 | BINARY length_opt 1769 { 1770 $$ = ColumnType{Type: string($1), Length: $2} 1771 } 1772 | VARBINARY length_opt 1773 { 1774 $$ = ColumnType{Type: string($1), Length: $2} 1775 } 1776 | TEXT charset_opt 1777 { 1778 $$ = ColumnType{Type: string($1), Charset: $2} 1779 } 1780 | TINYTEXT charset_opt 1781 { 1782 $$ = ColumnType{Type: string($1), Charset: $2} 1783 } 1784 | MEDIUMTEXT charset_opt 1785 { 1786 $$ = ColumnType{Type: string($1), Charset: $2} 1787 } 1788 | LONGTEXT charset_opt 1789 { 1790 $$ = ColumnType{Type: string($1), Charset: $2} 1791 } 1792 | BLOB 1793 { 1794 $$ = ColumnType{Type: string($1)} 1795 } 1796 | TINYBLOB 1797 { 1798 $$ = ColumnType{Type: string($1)} 1799 } 1800 | MEDIUMBLOB 1801 { 1802 $$ = ColumnType{Type: string($1)} 1803 } 1804 | LONGBLOB 1805 { 1806 $$ = ColumnType{Type: string($1)} 1807 } 1808 | JSON 1809 { 1810 $$ = ColumnType{Type: string($1)} 1811 } 1812 | ENUM '(' enum_values ')' charset_opt 1813 { 1814 $$ = ColumnType{Type: string($1), EnumValues: $3, Charset: $5} 1815 } 1816 // need set_values / SetValues ? 1817 | SET '(' enum_values ')' charset_opt 1818 { 1819 $$ = ColumnType{Type: string($1), EnumValues: $3, Charset: $5} 1820 } 1821 1822 spatial_type: 1823 GEOMETRY 1824 { 1825 $$ = ColumnType{Type: string($1)} 1826 } 1827 | POINT 1828 { 1829 $$ = ColumnType{Type: string($1)} 1830 } 1831 | LINESTRING 1832 { 1833 $$ = ColumnType{Type: string($1)} 1834 } 1835 | POLYGON 1836 { 1837 $$ = ColumnType{Type: string($1)} 1838 } 1839 | GEOMETRYCOLLECTION 1840 { 1841 $$ = ColumnType{Type: string($1)} 1842 } 1843 | MULTIPOINT 1844 { 1845 $$ = ColumnType{Type: string($1)} 1846 } 1847 | MULTILINESTRING 1848 { 1849 $$ = ColumnType{Type: string($1)} 1850 } 1851 | MULTIPOLYGON 1852 { 1853 $$ = ColumnType{Type: string($1)} 1854 } 1855 1856 enum_values: 1857 STRING 1858 { 1859 $$ = make([]string, 0, 4) 1860 $$ = append($$, encodeSQLString($1)) 1861 } 1862 | enum_values ',' STRING 1863 { 1864 $$ = append($1, encodeSQLString($3)) 1865 } 1866 1867 length_opt: 1868 { 1869 $$ = nil 1870 } 1871 | '(' INTEGRAL ')' 1872 { 1873 $$ = NewIntLiteral($2) 1874 } 1875 1876 float_length_opt: 1877 { 1878 $$ = LengthScaleOption{} 1879 } 1880 | '(' INTEGRAL ',' INTEGRAL ')' 1881 { 1882 $$ = LengthScaleOption{ 1883 Length: NewIntLiteral($2), 1884 Scale: NewIntLiteral($4), 1885 } 1886 } 1887 1888 decimal_length_opt: 1889 { 1890 $$ = LengthScaleOption{} 1891 } 1892 | '(' INTEGRAL ')' 1893 { 1894 $$ = LengthScaleOption{ 1895 Length: NewIntLiteral($2), 1896 } 1897 } 1898 | '(' INTEGRAL ',' INTEGRAL ')' 1899 { 1900 $$ = LengthScaleOption{ 1901 Length: NewIntLiteral($2), 1902 Scale: NewIntLiteral($4), 1903 } 1904 } 1905 1906 unsigned_opt: 1907 { 1908 $$ = false 1909 } 1910 | UNSIGNED 1911 { 1912 $$ = true 1913 } 1914 | SIGNED 1915 { 1916 $$ = false 1917 } 1918 1919 zero_fill_opt: 1920 { 1921 $$ = false 1922 } 1923 | ZEROFILL 1924 { 1925 $$ = true 1926 } 1927 1928 charset_opt: 1929 { 1930 $$ = "" 1931 } 1932 | charset_or_character_set id_or_var 1933 { 1934 $$ = string($2.String()) 1935 } 1936 | charset_or_character_set STRING 1937 { 1938 $$ = encodeSQLString($2) 1939 } 1940 | charset_or_character_set BINARY 1941 { 1942 $$ = string($2) 1943 } 1944 1945 collate_opt: 1946 { 1947 $$ = "" 1948 } 1949 | COLLATE id_or_var 1950 { 1951 $$ = string($2.String()) 1952 } 1953 | COLLATE STRING 1954 { 1955 $$ = encodeSQLString($2) 1956 } 1957 1958 1959 index_definition: 1960 index_info '(' index_column_list ')' index_option_list_opt 1961 { 1962 $$ = &IndexDefinition{Info: $1, Columns: $3, Options: $5} 1963 } 1964 1965 index_option_list_opt: 1966 { 1967 $$ = nil 1968 } 1969 | index_option_list 1970 { 1971 $$ = $1 1972 } 1973 1974 index_option_list: 1975 index_option 1976 { 1977 $$ = []*IndexOption{$1} 1978 } 1979 | index_option_list index_option 1980 { 1981 $$ = append($$, $2) 1982 } 1983 1984 index_option: 1985 using_index_type 1986 { 1987 $$ = $1 1988 } 1989 | KEY_BLOCK_SIZE equal_opt INTEGRAL 1990 { 1991 // should not be string 1992 $$ = &IndexOption{Name: string($1), Value: NewIntLiteral($3)} 1993 } 1994 | COMMENT_KEYWORD STRING 1995 { 1996 $$ = &IndexOption{Name: string($1), Value: NewStrLiteral($2)} 1997 } 1998 | WITH PARSER id_or_var 1999 { 2000 $$ = &IndexOption{Name: string($1) + " " + string($2), String: $3.String()} 2001 } 2002 2003 equal_opt: 2004 /* empty */ 2005 { 2006 $$ = "" 2007 } 2008 | '=' 2009 { 2010 $$ = string($1) 2011 } 2012 2013 index_info: 2014 constraint_name_opt PRIMARY KEY name_opt 2015 { 2016 $$ = &IndexInfo{Type: string($2) + " " + string($3), ConstraintName: NewColIdent($1), Name: NewColIdent("PRIMARY"), Primary: true, Unique: true} 2017 } 2018 | SPATIAL index_or_key_opt name_opt 2019 { 2020 $$ = &IndexInfo{Type: string($1) + " " + string($2), Name: NewColIdent($3), Spatial: true, Unique: false} 2021 } 2022 | FULLTEXT index_or_key_opt name_opt 2023 { 2024 $$ = &IndexInfo{Type: string($1) + " " + string($2), Name: NewColIdent($3), Fulltext: true, Unique: false} 2025 } 2026 | constraint_name_opt UNIQUE index_or_key_opt name_opt 2027 { 2028 $$ = &IndexInfo{Type: string($2) + " " + string($3), ConstraintName: NewColIdent($1), Name: NewColIdent($4), Unique: true} 2029 } 2030 | index_or_key name_opt 2031 { 2032 $$ = &IndexInfo{Type: string($1), Name: NewColIdent($2), Unique: false} 2033 } 2034 2035 constraint_name_opt: 2036 { 2037 $$ = "" 2038 } 2039 | CONSTRAINT name_opt 2040 { 2041 $$ = $2 2042 } 2043 2044 index_symbols: 2045 INDEX 2046 { 2047 $$ = string($1) 2048 } 2049 | KEYS 2050 { 2051 $$ = string($1) 2052 } 2053 | INDEXES 2054 { 2055 $$ = string($1) 2056 } 2057 2058 2059 from_or_in: 2060 FROM 2061 { 2062 $$ = string($1) 2063 } 2064 | IN 2065 { 2066 $$ = string($1) 2067 } 2068 2069 index_or_key_opt: 2070 { 2071 $$ = "key" 2072 } 2073 | index_or_key 2074 { 2075 $$ = $1 2076 } 2077 2078 index_or_key: 2079 INDEX 2080 { 2081 $$ = string($1) 2082 } 2083 | KEY 2084 { 2085 $$ = string($1) 2086 } 2087 2088 name_opt: 2089 { 2090 $$ = "" 2091 } 2092 | id_or_var 2093 { 2094 $$ = string($1.String()) 2095 } 2096 2097 index_column_list: 2098 index_column 2099 { 2100 $$ = []*IndexColumn{$1} 2101 } 2102 | index_column_list ',' index_column 2103 { 2104 $$ = append($$, $3) 2105 } 2106 2107 index_column: 2108 sql_id length_opt asc_desc_opt 2109 { 2110 $$ = &IndexColumn{Column: $1, Length: $2, Direction: $3} 2111 } 2112 2113 constraint_definition: 2114 CONSTRAINT id_or_var_opt constraint_info 2115 { 2116 $$ = &ConstraintDefinition{Name: $2, Details: $3} 2117 } 2118 | constraint_info 2119 { 2120 $$ = &ConstraintDefinition{Details: $1} 2121 } 2122 2123 check_constraint_definition: 2124 CONSTRAINT id_or_var_opt check_constraint_info 2125 { 2126 $$ = &ConstraintDefinition{Name: $2, Details: $3} 2127 } 2128 | check_constraint_info 2129 { 2130 $$ = &ConstraintDefinition{Details: $1} 2131 } 2132 2133 constraint_info: 2134 FOREIGN KEY name_opt '(' column_list ')' reference_definition 2135 { 2136 $$ = &ForeignKeyDefinition{IndexName: NewColIdent($3), Source: $5, ReferenceDefinition: $7} 2137 } 2138 2139 reference_definition: 2140 REFERENCES table_name '(' column_list ')' 2141 { 2142 $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4} 2143 } 2144 | REFERENCES table_name '(' column_list ')' fk_on_delete 2145 { 2146 $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, OnDelete: $6} 2147 } 2148 | REFERENCES table_name '(' column_list ')' fk_on_update 2149 { 2150 $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, OnUpdate: $6} 2151 } 2152 | REFERENCES table_name '(' column_list ')' fk_on_delete fk_on_update 2153 { 2154 $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, OnDelete: $6, OnUpdate: $7} 2155 } 2156 2157 reference_definition_opt: 2158 { 2159 $$ = nil 2160 } 2161 | reference_definition 2162 { 2163 $$ = $1 2164 } 2165 2166 check_constraint_info: 2167 CHECK '(' expression ')' enforced_opt 2168 { 2169 $$ = &CheckConstraintDefinition{Expr: $3, Enforced: $5} 2170 } 2171 2172 fk_on_delete: 2173 ON DELETE fk_reference_action 2174 { 2175 $$ = $3 2176 } 2177 2178 fk_on_update: 2179 ON UPDATE fk_reference_action 2180 { 2181 $$ = $3 2182 } 2183 2184 fk_reference_action: 2185 RESTRICT 2186 { 2187 $$ = Restrict 2188 } 2189 | CASCADE 2190 { 2191 $$ = Cascade 2192 } 2193 | NO ACTION 2194 { 2195 $$ = NoAction 2196 } 2197 | SET DEFAULT 2198 { 2199 $$ = SetDefault 2200 } 2201 | SET NULL 2202 { 2203 $$ = SetNull 2204 } 2205 2206 restrict_or_cascade_opt: 2207 { 2208 $$ = "" 2209 } 2210 | RESTRICT 2211 { 2212 $$ = string($1) 2213 } 2214 | CASCADE 2215 { 2216 $$ = string($1) 2217 } 2218 2219 enforced_opt: 2220 { 2221 $$ = true 2222 } 2223 | ENFORCED 2224 { 2225 $$ = true 2226 } 2227 | NOT ENFORCED 2228 { 2229 $$ = false 2230 } 2231 2232 table_option_list_opt: 2233 { 2234 $$ = nil 2235 } 2236 | table_option_list 2237 { 2238 $$ = $1 2239 } 2240 2241 table_option_list: 2242 table_option 2243 { 2244 $$ = TableOptions{$1} 2245 } 2246 | table_option_list ',' table_option 2247 { 2248 $$ = append($1,$3) 2249 } 2250 | table_option_list table_option 2251 { 2252 $$ = append($1,$2) 2253 } 2254 2255 space_separated_table_option_list: 2256 table_option 2257 { 2258 $$ = TableOptions{$1} 2259 } 2260 | space_separated_table_option_list table_option 2261 { 2262 $$ = append($1,$2) 2263 } 2264 2265 table_option: 2266 AUTO_INCREMENT equal_opt INTEGRAL 2267 { 2268 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2269 } 2270 | AVG_ROW_LENGTH equal_opt INTEGRAL 2271 { 2272 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2273 } 2274 | default_optional charset_or_character_set equal_opt charset 2275 { 2276 $$ = &TableOption{Name:(string($2)), String:$4} 2277 } 2278 | default_optional COLLATE equal_opt charset 2279 { 2280 $$ = &TableOption{Name:string($2), String:$4} 2281 } 2282 | CHECKSUM equal_opt INTEGRAL 2283 { 2284 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2285 } 2286 | COMMENT_KEYWORD equal_opt STRING 2287 { 2288 $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)} 2289 } 2290 | COMPRESSION equal_opt STRING 2291 { 2292 $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)} 2293 } 2294 | CONNECTION equal_opt STRING 2295 { 2296 $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)} 2297 } 2298 | DATA DIRECTORY equal_opt STRING 2299 { 2300 $$ = &TableOption{Name:(string($1)+" "+string($2)), Value:NewStrLiteral($4)} 2301 } 2302 | INDEX DIRECTORY equal_opt STRING 2303 { 2304 $$ = &TableOption{Name:(string($1)+" "+string($2)), Value:NewStrLiteral($4)} 2305 } 2306 | DELAY_KEY_WRITE equal_opt INTEGRAL 2307 { 2308 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2309 } 2310 | ENCRYPTION equal_opt STRING 2311 { 2312 $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)} 2313 } 2314 | ENGINE equal_opt table_alias 2315 { 2316 $$ = &TableOption{Name:string($1), String:$3.String()} 2317 } 2318 | INSERT_METHOD equal_opt insert_method_options 2319 { 2320 $$ = &TableOption{Name:string($1), String:string($3)} 2321 } 2322 | KEY_BLOCK_SIZE equal_opt INTEGRAL 2323 { 2324 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2325 } 2326 | MAX_ROWS equal_opt INTEGRAL 2327 { 2328 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2329 } 2330 | MIN_ROWS equal_opt INTEGRAL 2331 { 2332 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2333 } 2334 | PACK_KEYS equal_opt INTEGRAL 2335 { 2336 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2337 } 2338 | PACK_KEYS equal_opt DEFAULT 2339 { 2340 $$ = &TableOption{Name:string($1), String:string($3)} 2341 } 2342 | PASSWORD equal_opt STRING 2343 { 2344 $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)} 2345 } 2346 | ROW_FORMAT equal_opt row_format_options 2347 { 2348 $$ = &TableOption{Name:string($1), String:string($3)} 2349 } 2350 | STATS_AUTO_RECALC equal_opt INTEGRAL 2351 { 2352 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2353 } 2354 | STATS_AUTO_RECALC equal_opt DEFAULT 2355 { 2356 $$ = &TableOption{Name:string($1), String:string($3)} 2357 } 2358 | STATS_PERSISTENT equal_opt INTEGRAL 2359 { 2360 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2361 } 2362 | STATS_PERSISTENT equal_opt DEFAULT 2363 { 2364 $$ = &TableOption{Name:string($1), String:string($3)} 2365 } 2366 | STATS_SAMPLE_PAGES equal_opt INTEGRAL 2367 { 2368 $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)} 2369 } 2370 | TABLESPACE equal_opt sql_id storage_opt 2371 { 2372 $$ = &TableOption{Name:string($1), String: ($3.String() + $4)} 2373 } 2374 | UNION equal_opt '(' table_name_list ')' 2375 { 2376 $$ = &TableOption{Name:string($1), Tables: $4} 2377 } 2378 2379 storage_opt: 2380 { 2381 $$ = "" 2382 } 2383 | STORAGE DISK 2384 { 2385 $$ = " " + string($1) + " " + string($2) 2386 } 2387 | STORAGE MEMORY 2388 { 2389 $$ = " " + string($1) + " " + string($2) 2390 } 2391 2392 row_format_options: 2393 DEFAULT 2394 | DYNAMIC 2395 | FIXED 2396 | COMPRESSED 2397 | REDUNDANT 2398 | COMPACT 2399 2400 insert_method_options: 2401 NO 2402 | FIRST 2403 | LAST 2404 2405 table_opt_value: 2406 reserved_sql_id 2407 { 2408 $$ = $1.String() 2409 } 2410 | STRING 2411 { 2412 $$ = encodeSQLString($1) 2413 } 2414 | INTEGRAL 2415 { 2416 $$ = string($1) 2417 } 2418 2419 column_opt: 2420 { 2421 $$ = "" 2422 } 2423 | COLUMN 2424 2425 first_opt: 2426 { 2427 $$ = false 2428 } 2429 | FIRST 2430 { 2431 $$ = true 2432 } 2433 2434 after_opt: 2435 { 2436 $$ = nil 2437 } 2438 | AFTER column_name 2439 { 2440 $$ = $2 2441 } 2442 2443 alter_commands_list: 2444 { 2445 $$ = nil 2446 } 2447 | alter_options 2448 { 2449 $$ = $1 2450 } 2451 | alter_options ',' ORDER BY column_list 2452 { 2453 $$ = append($1,&OrderByOption{Cols:$5}) 2454 } 2455 | alter_commands_modifier_list 2456 { 2457 $$ = $1 2458 } 2459 | alter_commands_modifier_list ',' alter_options 2460 { 2461 $$ = append($1,$3...) 2462 } 2463 | alter_commands_modifier_list ',' alter_options ',' ORDER BY column_list 2464 { 2465 $$ = append(append($1,$3...),&OrderByOption{Cols:$7}) 2466 } 2467 2468 alter_options: 2469 alter_option 2470 { 2471 $$ = []AlterOption{$1} 2472 } 2473 | alter_options ',' alter_option 2474 { 2475 $$ = append($1,$3) 2476 } 2477 | alter_options ',' alter_commands_modifier 2478 { 2479 $$ = append($1,$3) 2480 } 2481 2482 alter_option: 2483 space_separated_table_option_list 2484 { 2485 $$ = $1 2486 } 2487 | ADD check_constraint_definition 2488 { 2489 $$ = &AddConstraintDefinition{ConstraintDefinition: $2} 2490 } 2491 | ADD constraint_definition 2492 { 2493 $$ = &AddConstraintDefinition{ConstraintDefinition: $2} 2494 } 2495 | ADD index_definition 2496 { 2497 $$ = &AddIndexDefinition{IndexDefinition: $2} 2498 } 2499 | ADD column_opt '(' column_definition_list ')' 2500 { 2501 $$ = &AddColumns{Columns: $4} 2502 } 2503 | ADD column_opt column_definition first_opt after_opt 2504 { 2505 $$ = &AddColumns{Columns: []*ColumnDefinition{$3}, First:$4, After:$5} 2506 } 2507 | ALTER column_opt column_name DROP DEFAULT 2508 { 2509 $$ = &AlterColumn{Column: $3, DropDefault:true} 2510 } 2511 | ALTER column_opt column_name SET DEFAULT signed_literal_or_null 2512 { 2513 $$ = &AlterColumn{Column: $3, DropDefault:false, DefaultVal:$6} 2514 } 2515 | ALTER column_opt column_name SET DEFAULT openb expression closeb 2516 { 2517 $$ = &AlterColumn{Column: $3, DropDefault:false, DefaultVal:$7} 2518 } 2519 | CHANGE column_opt column_name column_definition first_opt after_opt 2520 { 2521 $$ = &ChangeColumn{OldColumn:$3, NewColDefinition:$4, First:$5, After:$6} 2522 } 2523 | MODIFY column_opt column_definition first_opt after_opt 2524 { 2525 $$ = &ModifyColumn{NewColDefinition:$3, First:$4, After:$5} 2526 } 2527 | CONVERT TO charset_or_character_set charset collate_opt 2528 { 2529 $$ = &AlterCharset{CharacterSet:$4, Collate:$5} 2530 } 2531 | DISABLE KEYS 2532 { 2533 $$ = &KeyState{Enable:false} 2534 } 2535 | ENABLE KEYS 2536 { 2537 $$ = &KeyState{Enable:true} 2538 } 2539 | DISCARD TABLESPACE 2540 { 2541 $$ = &TablespaceOperation{Import:false} 2542 } 2543 | IMPORT TABLESPACE 2544 { 2545 $$ = &TablespaceOperation{Import:true} 2546 } 2547 | DROP column_opt column_name 2548 { 2549 $$ = &DropColumn{Name:$3} 2550 } 2551 | DROP index_or_key id_or_var 2552 { 2553 $$ = &DropKey{Type:NormalKeyType, Name:$3} 2554 } 2555 | DROP PRIMARY KEY 2556 { 2557 $$ = &DropKey{Type:PrimaryKeyType} 2558 } 2559 | DROP FOREIGN KEY id_or_var 2560 { 2561 $$ = &DropKey{Type:ForeignKeyType, Name:$4} 2562 } 2563 | FORCE 2564 { 2565 $$ = &Force{} 2566 } 2567 | RENAME to_opt table_name 2568 { 2569 $$ = &RenameTableName{Table:$3} 2570 } 2571 | RENAME index_or_key id_or_var TO id_or_var 2572 { 2573 $$ = &RenameIndex{OldName:$3, NewName:$5} 2574 } 2575 2576 alter_commands_modifier_list: 2577 alter_commands_modifier 2578 { 2579 $$ = []AlterOption{$1} 2580 } 2581 | alter_commands_modifier_list ',' alter_commands_modifier 2582 { 2583 $$ = append($1,$3) 2584 } 2585 2586 alter_commands_modifier: 2587 ALGORITHM equal_opt DEFAULT 2588 { 2589 $$ = AlgorithmValue(string($3)) 2590 } 2591 | ALGORITHM equal_opt INPLACE 2592 { 2593 $$ = AlgorithmValue(string($3)) 2594 } 2595 | ALGORITHM equal_opt COPY 2596 { 2597 $$ = AlgorithmValue(string($3)) 2598 } 2599 | LOCK equal_opt DEFAULT 2600 { 2601 $$ = &LockOption{Type:DefaultType} 2602 } 2603 | LOCK equal_opt NONE 2604 { 2605 $$ = &LockOption{Type:NoneType} 2606 } 2607 | LOCK equal_opt SHARED 2608 { 2609 $$ = &LockOption{Type:SharedType} 2610 } 2611 | LOCK equal_opt EXCLUSIVE 2612 { 2613 $$ = &LockOption{Type:ExclusiveType} 2614 } 2615 | WITH VALIDATION 2616 { 2617 $$ = &Validation{With:true} 2618 } 2619 | WITHOUT VALIDATION 2620 { 2621 $$ = &Validation{With:false} 2622 } 2623 2624 alter_statement: 2625 alter_table_prefix alter_commands_list 2626 { 2627 $1.FullyParsed = true 2628 $1.AlterOptions = $2 2629 $$ = $1 2630 } 2631 | alter_table_prefix alter_commands_list REMOVE PARTITIONING 2632 { 2633 $1.FullyParsed = true 2634 $1.AlterOptions = $2 2635 $1.PartitionSpec = &PartitionSpec{Action:RemoveAction} 2636 $$ = $1 2637 } 2638 | alter_table_prefix alter_commands_modifier_list ',' partition_operation 2639 { 2640 $1.FullyParsed = true 2641 $1.AlterOptions = $2 2642 $1.PartitionSpec = $4 2643 $$ = $1 2644 } 2645 | alter_table_prefix partition_operation 2646 { 2647 $1.FullyParsed = true 2648 $1.PartitionSpec = $2 2649 $$ = $1 2650 } 2651 | ALTER comment_opt algorithm_view definer_opt security_view_opt VIEW table_name column_list_opt AS select_statement check_option_opt 2652 { 2653 $$ = &AlterView{ViewName: $7.ToViewName(), Algorithm:$3, Definer: $4 ,Security:$5, Columns:$8, Select: $10, CheckOption: $11 } 2654 } 2655 | alter_database_prefix table_id_opt create_options 2656 { 2657 $1.FullyParsed = true 2658 $1.DBName = $2 2659 $1.AlterOptions = $3 2660 $$ = $1 2661 } 2662 | alter_database_prefix table_id UPGRADE DATA DIRECTORY NAME 2663 { 2664 $1.FullyParsed = true 2665 $1.DBName = $2 2666 $1.UpdateDataDirectory = true 2667 $$ = $1 2668 } 2669 | ALTER comment_opt VSCHEMA CREATE VINDEX table_name vindex_type_opt vindex_params_opt 2670 { 2671 $$ = &AlterVschema{ 2672 Action: CreateVindexDDLAction, 2673 Table: $6, 2674 VindexSpec: &VindexSpec{ 2675 Name: NewColIdent($6.Name.String()), 2676 Type: $7, 2677 Params: $8, 2678 }, 2679 } 2680 } 2681 | ALTER comment_opt VSCHEMA DROP VINDEX table_name 2682 { 2683 $$ = &AlterVschema{ 2684 Action: DropVindexDDLAction, 2685 Table: $6, 2686 VindexSpec: &VindexSpec{ 2687 Name: NewColIdent($6.Name.String()), 2688 }, 2689 } 2690 } 2691 | ALTER comment_opt VSCHEMA ADD TABLE table_name 2692 { 2693 $$ = &AlterVschema{Action: AddVschemaTableDDLAction, Table: $6} 2694 } 2695 | ALTER comment_opt VSCHEMA DROP TABLE table_name 2696 { 2697 $$ = &AlterVschema{Action: DropVschemaTableDDLAction, Table: $6} 2698 } 2699 | ALTER comment_opt VSCHEMA ON table_name ADD VINDEX sql_id '(' column_list ')' vindex_type_opt vindex_params_opt 2700 { 2701 $$ = &AlterVschema{ 2702 Action: AddColVindexDDLAction, 2703 Table: $5, 2704 VindexSpec: &VindexSpec{ 2705 Name: $8, 2706 Type: $12, 2707 Params: $13, 2708 }, 2709 VindexCols: $10, 2710 } 2711 } 2712 | ALTER comment_opt VSCHEMA ON table_name DROP VINDEX sql_id 2713 { 2714 $$ = &AlterVschema{ 2715 Action: DropColVindexDDLAction, 2716 Table: $5, 2717 VindexSpec: &VindexSpec{ 2718 Name: $8, 2719 }, 2720 } 2721 } 2722 | ALTER comment_opt VSCHEMA ADD SEQUENCE table_name 2723 { 2724 $$ = &AlterVschema{Action: AddSequenceDDLAction, Table: $6} 2725 } 2726 | ALTER comment_opt VSCHEMA ON table_name ADD AUTO_INCREMENT sql_id USING table_name 2727 { 2728 $$ = &AlterVschema{ 2729 Action: AddAutoIncDDLAction, 2730 Table: $5, 2731 AutoIncSpec: &AutoIncSpec{ 2732 Column: $8, 2733 Sequence: $10, 2734 }, 2735 } 2736 } 2737 | ALTER comment_opt VITESS_MIGRATION STRING RETRY 2738 { 2739 $$ = &AlterMigration{ 2740 Type: RetryMigrationType, 2741 UUID: string($4), 2742 } 2743 } 2744 | ALTER comment_opt VITESS_MIGRATION STRING CLEANUP 2745 { 2746 $$ = &AlterMigration{ 2747 Type: CleanupMigrationType, 2748 UUID: string($4), 2749 } 2750 } 2751 | ALTER comment_opt VITESS_MIGRATION STRING COMPLETE 2752 { 2753 $$ = &AlterMigration{ 2754 Type: CompleteMigrationType, 2755 UUID: string($4), 2756 } 2757 } 2758 | ALTER comment_opt VITESS_MIGRATION STRING CANCEL 2759 { 2760 $$ = &AlterMigration{ 2761 Type: CancelMigrationType, 2762 UUID: string($4), 2763 } 2764 } 2765 | ALTER comment_opt VITESS_MIGRATION CANCEL ALL 2766 { 2767 $$ = &AlterMigration{ 2768 Type: CancelAllMigrationType, 2769 } 2770 } 2771 2772 partitions_options_opt: 2773 { 2774 $$ = nil 2775 } 2776 | PARTITION BY linear_opt HASH '(' expression ')' partitions_opt 2777 subpartition_opt partition_definition_opt 2778 { 2779 $$ = &PartitionOption { 2780 Linear: $3, 2781 isHASH: true, 2782 Expr: $6, 2783 Partitions: $8, 2784 SubPartition: $9, 2785 Definitions: $10, 2786 } 2787 } 2788 | PARTITION BY linear_opt KEY algorithm_opt '(' column_list ')' 2789 partitions_opt subpartition_opt partition_definition_opt 2790 { 2791 $$ = &PartitionOption { 2792 Linear: $3, 2793 isKEY: true, 2794 KeyAlgorithm: $5, 2795 KeyColList: $7, 2796 Partitions: $9, 2797 SubPartition: $10, 2798 Definitions: $11, 2799 } 2800 } 2801 | PARTITION BY range_or_list expr_or_col partitions_opt subpartition_opt 2802 partition_definition_opt 2803 { 2804 $$ = &PartitionOption { 2805 RangeOrList: $3, 2806 ExprOrCol: $4, 2807 Partitions: $5, 2808 SubPartition: $6, 2809 Definitions: $7, 2810 } 2811 } 2812 2813 subpartition_opt: 2814 { 2815 $$ = nil 2816 } 2817 | SUBPARTITION BY linear_opt HASH '(' expression ')' subpartitions_opt 2818 { 2819 $$ = &SubPartition { 2820 Linear: $3, 2821 isHASH: true, 2822 Expr: $6, 2823 SubPartitions: $8, 2824 } 2825 } 2826 | SUBPARTITION BY linear_opt KEY algorithm_opt '(' column_list ')' subpartitions_opt 2827 { 2828 $$ = &SubPartition { 2829 Linear: $3, 2830 isKEY: true, 2831 KeyAlgorithm: $5, 2832 KeyColList: $7, 2833 SubPartitions: $9, 2834 } 2835 } 2836 2837 partition_definition_opt: 2838 { 2839 $$ = nil 2840 } 2841 | '(' partition_definitions ')' 2842 { 2843 $$ = $2 2844 } 2845 2846 linear_opt: 2847 { 2848 $$ = "" 2849 } 2850 | LINEAR 2851 { 2852 $$ = string($1) 2853 } 2854 2855 algorithm_opt: 2856 { 2857 $$ = "" 2858 } 2859 | ALGORITHM '=' INTEGRAL 2860 { 2861 $$ = string($3) 2862 } 2863 2864 range_or_list: 2865 RANGE 2866 { 2867 $$ = string($1) 2868 } 2869 | LIST 2870 { 2871 $$ = string($1) 2872 } 2873 2874 expr_or_col: 2875 '(' expression ')' 2876 { 2877 $$ = &ExprOrColumns{Expr: $2} 2878 } 2879 | COLUMNS '(' column_list ')' 2880 { 2881 $$ = &ExprOrColumns{ColumnList: $3} 2882 } 2883 2884 partitions_opt: 2885 { 2886 $$ = "" 2887 } 2888 | PARTITIONS INTEGRAL 2889 { 2890 $$ = string($2) 2891 } 2892 2893 subpartitions_opt: 2894 { 2895 $$ = "" 2896 } 2897 | SUBPARTITIONS INTEGRAL 2898 { 2899 $$ = string($2) 2900 } 2901 2902 partition_operation: 2903 ADD PARTITION '(' partition_definition ')' 2904 { 2905 $$ = &PartitionSpec{Action: AddAction, Definitions: []*PartitionDefinition{$4}} 2906 } 2907 | DROP PARTITION partition_list 2908 { 2909 $$ = &PartitionSpec{Action:DropAction, Names:$3} 2910 } 2911 | REORGANIZE PARTITION partition_list INTO openb partition_definitions closeb 2912 { 2913 $$ = &PartitionSpec{Action: ReorganizeAction, Names: $3, Definitions: $6} 2914 } 2915 | DISCARD PARTITION partition_list TABLESPACE 2916 { 2917 $$ = &PartitionSpec{Action:DiscardAction, Names:$3} 2918 } 2919 | DISCARD PARTITION ALL TABLESPACE 2920 { 2921 $$ = &PartitionSpec{Action:DiscardAction, IsAll:true} 2922 } 2923 | IMPORT PARTITION partition_list TABLESPACE 2924 { 2925 $$ = &PartitionSpec{Action:ImportAction, Names:$3} 2926 } 2927 | IMPORT PARTITION ALL TABLESPACE 2928 { 2929 $$ = &PartitionSpec{Action:ImportAction, IsAll:true} 2930 } 2931 | TRUNCATE PARTITION partition_list 2932 { 2933 $$ = &PartitionSpec{Action:TruncateAction, Names:$3} 2934 } 2935 | TRUNCATE PARTITION ALL 2936 { 2937 $$ = &PartitionSpec{Action:TruncateAction, IsAll:true} 2938 } 2939 | COALESCE PARTITION INTEGRAL 2940 { 2941 $$ = &PartitionSpec{Action:CoalesceAction, Number:NewIntLiteral($3) } 2942 } 2943 | EXCHANGE PARTITION sql_id WITH TABLE table_name without_valid_opt 2944 { 2945 $$ = &PartitionSpec{Action:ExchangeAction, Names: Partitions{$3}, TableName: $6, WithoutValidation: $7} 2946 } 2947 | ANALYZE PARTITION partition_list 2948 { 2949 $$ = &PartitionSpec{Action:AnalyzeAction, Names:$3} 2950 } 2951 | ANALYZE PARTITION ALL 2952 { 2953 $$ = &PartitionSpec{Action:AnalyzeAction, IsAll:true} 2954 } 2955 | CHECK PARTITION partition_list 2956 { 2957 $$ = &PartitionSpec{Action:CheckAction, Names:$3} 2958 } 2959 | CHECK PARTITION ALL 2960 { 2961 $$ = &PartitionSpec{Action:CheckAction, IsAll:true} 2962 } 2963 | OPTIMIZE PARTITION partition_list 2964 { 2965 $$ = &PartitionSpec{Action:OptimizeAction, Names:$3} 2966 } 2967 | OPTIMIZE PARTITION ALL 2968 { 2969 $$ = &PartitionSpec{Action:OptimizeAction, IsAll:true} 2970 } 2971 | REBUILD PARTITION partition_list 2972 { 2973 $$ = &PartitionSpec{Action:RebuildAction, Names:$3} 2974 } 2975 | REBUILD PARTITION ALL 2976 { 2977 $$ = &PartitionSpec{Action:RebuildAction, IsAll:true} 2978 } 2979 | REPAIR PARTITION partition_list 2980 { 2981 $$ = &PartitionSpec{Action:RepairAction, Names:$3} 2982 } 2983 | REPAIR PARTITION ALL 2984 { 2985 $$ = &PartitionSpec{Action:RepairAction, IsAll:true} 2986 } 2987 | UPGRADE PARTITIONING 2988 { 2989 $$ = &PartitionSpec{Action:UpgradeAction} 2990 } 2991 2992 without_valid_opt: 2993 { 2994 $$ = false 2995 } 2996 | WITH VALIDATION 2997 { 2998 $$ = false 2999 } 3000 | WITHOUT VALIDATION 3001 { 3002 $$ = true 3003 } 3004 3005 3006 partition_definitions: 3007 partition_definition 3008 { 3009 $$ = []*PartitionDefinition{$1} 3010 } 3011 | partition_definitions ',' partition_definition 3012 { 3013 $$ = append($1, $3) 3014 } 3015 3016 partition_definition: 3017 PARTITION sql_id VALUES LESS THAN openb expression closeb 3018 { 3019 $$ = &PartitionDefinition{Name: $2, Limit: $7} 3020 } 3021 | PARTITION sql_id VALUES LESS THAN openb MAXVALUE closeb 3022 { 3023 $$ = &PartitionDefinition{Name: $2, Maxvalue: true} 3024 } 3025 3026 rename_statement: 3027 RENAME TABLE rename_list 3028 { 3029 $$ = &RenameTable{TablePairs: $3} 3030 } 3031 3032 rename_list: 3033 table_name TO table_name 3034 { 3035 $$ = []*RenameTablePair{{FromTable: $1, ToTable: $3}} 3036 } 3037 | rename_list ',' table_name TO table_name 3038 { 3039 $$ = append($1, &RenameTablePair{FromTable: $3, ToTable: $5}) 3040 } 3041 3042 drop_statement: 3043 DROP comment_opt temp_opt TABLE exists_opt table_name_list restrict_or_cascade_opt 3044 { 3045 $$ = &DropTable{FromTables: $6, IfExists: $5, Comments: Comments($2), Temp: $3} 3046 } 3047 | DROP comment_opt INDEX id_or_var ON table_name algorithm_lock_opt 3048 { 3049 // Change this to an alter statement 3050 if $4.Lowered() == "primary" { 3051 $$ = &AlterTable{FullyParsed:true, Table: $6,AlterOptions: append([]AlterOption{&DropKey{Type:PrimaryKeyType}},$7...)} 3052 } else { 3053 $$ = &AlterTable{FullyParsed: true, Table: $6,AlterOptions: append([]AlterOption{&DropKey{Type:NormalKeyType, Name:$4}},$7...)} 3054 } 3055 } 3056 | DROP comment_opt VIEW exists_opt view_name_list restrict_or_cascade_opt 3057 { 3058 $$ = &DropView{FromTables: $5, IfExists: $4} 3059 } 3060 | DROP comment_opt database_or_schema exists_opt table_id 3061 { 3062 $$ = &DropDatabase{Comments: Comments($2), DBName: $5, IfExists: $4} 3063 } 3064 3065 truncate_statement: 3066 TRUNCATE TABLE table_name 3067 { 3068 $$ = &TruncateTable{Table: $3} 3069 } 3070 | TRUNCATE table_name 3071 { 3072 $$ = &TruncateTable{Table: $2} 3073 } 3074 analyze_statement: 3075 ANALYZE TABLE table_name 3076 { 3077 $$ = &OtherRead{} 3078 } 3079 3080 show_statement: 3081 SHOW charset_or_character_set like_or_where_opt 3082 { 3083 $$ = &Show{&ShowBasic{Command: Charset, Filter: $3}} 3084 } 3085 | SHOW COLLATION like_or_where_opt 3086 { 3087 $$ = &Show{&ShowBasic{Command: Collation, Filter: $3}} 3088 } 3089 | SHOW full_opt columns_or_fields from_or_in table_name from_database_opt like_or_where_opt 3090 { 3091 $$ = &Show{&ShowBasic{Full: $2, Command: Column, Tbl: $5, DbName: $6, Filter: $7}} 3092 } 3093 | SHOW DATABASES like_or_where_opt 3094 { 3095 $$ = &Show{&ShowBasic{Command: Database, Filter: $3}} 3096 } 3097 | SHOW SCHEMAS like_or_where_opt 3098 { 3099 $$ = &Show{&ShowBasic{Command: Database, Filter: $3}} 3100 } 3101 | SHOW KEYSPACES like_or_where_opt 3102 { 3103 $$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}} 3104 } 3105 | SHOW VITESS_KEYSPACES like_or_where_opt 3106 { 3107 $$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}} 3108 } 3109 | SHOW FUNCTION STATUS like_or_where_opt 3110 { 3111 $$ = &Show{&ShowBasic{Command: Function, Filter: $4}} 3112 } 3113 | SHOW extended_opt index_symbols from_or_in table_name from_database_opt like_or_where_opt 3114 { 3115 $$ = &Show{&ShowBasic{Command: Index, Tbl: $5, DbName: $6, Filter: $7}} 3116 } 3117 | SHOW OPEN TABLES from_database_opt like_or_where_opt 3118 { 3119 $$ = &Show{&ShowBasic{Command: OpenTable, DbName:$4, Filter: $5}} 3120 } 3121 | SHOW PRIVILEGES 3122 { 3123 $$ = &Show{&ShowBasic{Command: Privilege}} 3124 } 3125 | SHOW PROCEDURE STATUS like_or_where_opt 3126 { 3127 $$ = &Show{&ShowBasic{Command: Procedure, Filter: $4}} 3128 } 3129 | SHOW session_or_local_opt STATUS like_or_where_opt 3130 { 3131 $$ = &Show{&ShowBasic{Command: StatusSession, Filter: $4}} 3132 } 3133 | SHOW GLOBAL STATUS like_or_where_opt 3134 { 3135 $$ = &Show{&ShowBasic{Command: StatusGlobal, Filter: $4}} 3136 } 3137 | SHOW session_or_local_opt VARIABLES like_or_where_opt 3138 { 3139 $$ = &Show{&ShowBasic{Command: VariableSession, Filter: $4}} 3140 } 3141 | SHOW GLOBAL VARIABLES like_or_where_opt 3142 { 3143 $$ = &Show{&ShowBasic{Command: VariableGlobal, Filter: $4}} 3144 } 3145 | SHOW TABLE STATUS from_database_opt like_or_where_opt 3146 { 3147 $$ = &Show{&ShowBasic{Command: TableStatus, DbName:$4, Filter: $5}} 3148 } 3149 | SHOW full_opt TABLES from_database_opt like_or_where_opt 3150 { 3151 $$ = &Show{&ShowBasic{Command: Table, Full: $2, DbName:$4, Filter: $5}} 3152 } 3153 | SHOW TRIGGERS from_database_opt like_or_where_opt 3154 { 3155 $$ = &Show{&ShowBasic{Command: Trigger, DbName:$3, Filter: $4}} 3156 } 3157 | SHOW CREATE DATABASE table_name 3158 { 3159 $$ = &Show{&ShowCreate{Command: CreateDb, Op: $4}} 3160 } 3161 | SHOW CREATE EVENT table_name 3162 { 3163 $$ = &Show{&ShowCreate{Command: CreateE, Op: $4}} 3164 } 3165 | SHOW CREATE FUNCTION table_name 3166 { 3167 $$ = &Show{&ShowCreate{Command: CreateF, Op: $4}} 3168 } 3169 | SHOW CREATE PROCEDURE table_name 3170 { 3171 $$ = &Show{&ShowCreate{Command: CreateProc, Op: $4}} 3172 } 3173 | SHOW CREATE TABLE table_name 3174 { 3175 $$ = &Show{&ShowCreate{Command: CreateTbl, Op: $4}} 3176 } 3177 | SHOW CREATE TRIGGER table_name 3178 { 3179 $$ = &Show{&ShowCreate{Command: CreateTr, Op: $4}} 3180 } 3181 | SHOW CREATE VIEW table_name 3182 { 3183 $$ = &Show{&ShowCreate{Command: CreateV, Op: $4}} 3184 } 3185 | SHOW CREATE USER ddl_skip_to_end 3186 { 3187 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Scope: ImplicitScope}} 3188 } 3189 | SHOW BINARY id_or_var ddl_skip_to_end /* SHOW BINARY ... */ 3190 { 3191 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3.String()), Scope: ImplicitScope}} 3192 } 3193 | SHOW BINARY LOGS ddl_skip_to_end /* SHOW BINARY LOGS */ 3194 { 3195 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Scope: ImplicitScope}} 3196 } 3197 | SHOW ENGINES 3198 { 3199 $$ = &Show{&ShowLegacy{Type: string($2), Scope: ImplicitScope}} 3200 } 3201 | SHOW FUNCTION CODE table_name 3202 { 3203 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Table: $4, Scope: ImplicitScope}} 3204 } 3205 | SHOW PLUGINS 3206 { 3207 $$ = &Show{&ShowLegacy{Type: string($2), Scope: ImplicitScope}} 3208 } 3209 | SHOW PROCEDURE CODE table_name 3210 { 3211 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Table: $4, Scope: ImplicitScope}} 3212 } 3213 | SHOW full_opt PROCESSLIST from_database_opt like_or_where_opt 3214 { 3215 $$ = &Show{&ShowLegacy{Type: string($3), Scope: ImplicitScope}} 3216 } 3217 | SHOW GLOBAL GTID_EXECUTED from_database_opt 3218 { 3219 $$ = &Show{&ShowBasic{Command: GtidExecGlobal, DbName: $4}} 3220 } 3221 | SHOW GLOBAL VGTID_EXECUTED from_database_opt 3222 { 3223 $$ = &Show{&ShowBasic{Command: VGtidExecGlobal, DbName: $4}} 3224 } 3225 | SHOW VITESS_METADATA VARIABLES like_opt 3226 { 3227 showTablesOpt := &ShowTablesOpt{Filter: $4} 3228 $$ = &Show{&ShowLegacy{Scope: VitessMetadataScope, Type: string($3), ShowTablesOpt: showTablesOpt}} 3229 } 3230 | SHOW VITESS_MIGRATIONS from_database_opt like_or_where_opt 3231 { 3232 $$ = &Show{&ShowBasic{Command: VitessMigrations, Filter: $4, DbName: $3}} 3233 } 3234 | SHOW VITESS_MIGRATION STRING LOGS 3235 { 3236 $$ = &ShowMigrationLogs{UUID: string($3)} 3237 } 3238 | SHOW VITESS_REPLICATION_STATUS like_opt 3239 { 3240 showTablesOpt := &ShowTablesOpt{Filter: $3} 3241 $$ = &Show{&ShowLegacy{Type: string($2), Scope: ImplicitScope, ShowTablesOpt: showTablesOpt}} 3242 } 3243 | SHOW VSCHEMA TABLES 3244 { 3245 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Scope: ImplicitScope}} 3246 } 3247 | SHOW VSCHEMA VINDEXES 3248 { 3249 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), Scope: ImplicitScope}} 3250 } 3251 | SHOW VSCHEMA VINDEXES ON table_name 3252 { 3253 $$ = &Show{&ShowLegacy{Type: string($2) + " " + string($3), OnTable: $5, Scope: ImplicitScope}} 3254 } 3255 | SHOW WARNINGS 3256 { 3257 $$ = &Show{&ShowBasic{Command: Warnings}} 3258 } 3259 /* vitess_topo supports SHOW VITESS_SHARDS / SHOW VITESS_TABLETS */ 3260 | SHOW vitess_topo like_or_where_opt 3261 { 3262 // This should probably be a different type (ShowVitessTopoOpt), but 3263 // just getting the thing working for now 3264 showTablesOpt := &ShowTablesOpt{Filter: $3} 3265 $$ = &Show{&ShowLegacy{Type: $2, ShowTablesOpt: showTablesOpt}} 3266 } 3267 /* 3268 * Catch-all for show statements without vitess keywords: 3269 * 3270 * SHOW BINARY LOGS 3271 * SHOW INVALID 3272 * SHOW VITESS_TARGET 3273 */ 3274 | SHOW id_or_var ddl_skip_to_end 3275 { 3276 $$ = &Show{&ShowLegacy{Type: string($2.String()), Scope: ImplicitScope}} 3277 } 3278 | SHOW ENGINE ddl_skip_to_end 3279 { 3280 $$ = &Show{&ShowLegacy{Type: string($2), Scope: ImplicitScope}} 3281 } 3282 | SHOW STORAGE ddl_skip_to_end 3283 { 3284 $$ = &Show{&ShowLegacy{Type: string($2), Scope: ImplicitScope}} 3285 } 3286 3287 vitess_topo: 3288 VITESS_TABLETS 3289 { 3290 $$ = string($1) 3291 } 3292 | VITESS_SHARDS 3293 { 3294 $$ = string($1) 3295 } 3296 3297 extended_opt: 3298 /* empty */ 3299 { 3300 $$ = "" 3301 } 3302 | EXTENDED 3303 { 3304 $$ = "extended " 3305 } 3306 3307 full_opt: 3308 /* empty */ 3309 { 3310 $$ = false 3311 } 3312 | FULL 3313 { 3314 $$ = true 3315 } 3316 3317 columns_or_fields: 3318 COLUMNS 3319 { 3320 $$ = string($1) 3321 } 3322 | FIELDS 3323 { 3324 $$ = string($1) 3325 } 3326 3327 from_database_opt: 3328 /* empty */ 3329 { 3330 $$ = NewTableIdent("") 3331 } 3332 | FROM table_id 3333 { 3334 $$ = $2 3335 } 3336 | IN table_id 3337 { 3338 $$ = $2 3339 } 3340 3341 like_or_where_opt: 3342 /* empty */ 3343 { 3344 $$ = nil 3345 } 3346 | LIKE STRING 3347 { 3348 $$ = &ShowFilter{Like:string($2)} 3349 } 3350 | WHERE expression 3351 { 3352 $$ = &ShowFilter{Filter:$2} 3353 } 3354 3355 like_opt: 3356 /* empty */ 3357 { 3358 $$ = nil 3359 } 3360 | LIKE STRING 3361 { 3362 $$ = &ShowFilter{Like:string($2)} 3363 } 3364 3365 session_or_local_opt: 3366 /* empty */ 3367 { 3368 $$ = struct{}{} 3369 } 3370 | SESSION 3371 { 3372 $$ = struct{}{} 3373 } 3374 | LOCAL 3375 { 3376 $$ = struct{}{} 3377 } 3378 3379 use_statement: 3380 USE table_id 3381 { 3382 $$ = &Use{DBName: $2} 3383 } 3384 | USE 3385 { 3386 $$ = &Use{DBName:TableIdent{v:""}} 3387 } 3388 3389 begin_statement: 3390 BEGIN 3391 { 3392 $$ = &Begin{} 3393 } 3394 | START TRANSACTION 3395 { 3396 $$ = &Begin{} 3397 } 3398 3399 commit_statement: 3400 COMMIT 3401 { 3402 $$ = &Commit{} 3403 } 3404 3405 rollback_statement: 3406 ROLLBACK 3407 { 3408 $$ = &Rollback{} 3409 } 3410 | ROLLBACK work_opt TO savepoint_opt sql_id 3411 { 3412 $$ = &SRollback{Name: $5} 3413 } 3414 3415 work_opt: 3416 { $$ = struct{}{} } 3417 | WORK 3418 { $$ = struct{}{} } 3419 3420 savepoint_opt: 3421 { $$ = struct{}{} } 3422 | SAVEPOINT 3423 { $$ = struct{}{} } 3424 3425 3426 savepoint_statement: 3427 SAVEPOINT sql_id 3428 { 3429 $$ = &Savepoint{Name: $2} 3430 } 3431 3432 release_statement: 3433 RELEASE SAVEPOINT sql_id 3434 { 3435 $$ = &Release{Name: $3} 3436 } 3437 3438 explain_format_opt: 3439 { 3440 $$ = EmptyType 3441 } 3442 | FORMAT '=' JSON 3443 { 3444 $$ = JSONType 3445 } 3446 | FORMAT '=' TREE 3447 { 3448 $$ = TreeType 3449 } 3450 | FORMAT '=' VITESS 3451 { 3452 $$ = VitessType 3453 } 3454 | FORMAT '=' TRADITIONAL 3455 { 3456 $$ = TraditionalType 3457 } 3458 | ANALYZE 3459 { 3460 $$ = AnalyzeType 3461 } 3462 3463 explain_synonyms: 3464 EXPLAIN 3465 { 3466 $$ = $1 3467 } 3468 | DESCRIBE 3469 { 3470 $$ = $1 3471 } 3472 | DESC 3473 { 3474 $$ = $1 3475 } 3476 3477 explainable_statement: 3478 select_statement 3479 { 3480 $$ = $1 3481 } 3482 | update_statement 3483 { 3484 $$ = $1 3485 } 3486 | insert_statement 3487 { 3488 $$ = $1 3489 } 3490 | delete_statement 3491 { 3492 $$ = $1 3493 } 3494 3495 wild_opt: 3496 { 3497 $$ = "" 3498 } 3499 | sql_id 3500 { 3501 $$ = $1.val 3502 } 3503 | STRING 3504 { 3505 $$ = encodeSQLString($1) 3506 } 3507 3508 explain_statement: 3509 explain_synonyms table_name wild_opt 3510 { 3511 $$ = &ExplainTab{Table: $2, Wild: $3} 3512 } 3513 | explain_synonyms explain_format_opt explainable_statement 3514 { 3515 $$ = &ExplainStmt{Type: $2, Statement: $3} 3516 } 3517 3518 other_statement: 3519 REPAIR skip_to_end 3520 { 3521 $$ = &OtherAdmin{} 3522 } 3523 | OPTIMIZE skip_to_end 3524 { 3525 $$ = &OtherAdmin{} 3526 } 3527 3528 lock_statement: 3529 LOCK TABLES lock_table_list 3530 { 3531 $$ = &LockTables{Tables: $3} 3532 } 3533 3534 lock_table_list: 3535 lock_table 3536 { 3537 $$ = TableAndLockTypes{$1} 3538 } 3539 | lock_table_list ',' lock_table 3540 { 3541 $$ = append($1, $3) 3542 } 3543 3544 lock_table: 3545 aliased_table_name lock_type 3546 { 3547 $$ = &TableAndLockType{Table:$1, Lock:$2} 3548 } 3549 3550 lock_type: 3551 READ 3552 { 3553 $$ = Read 3554 } 3555 | READ LOCAL 3556 { 3557 $$ = ReadLocal 3558 } 3559 | WRITE 3560 { 3561 $$ = Write 3562 } 3563 | LOW_PRIORITY WRITE 3564 { 3565 $$ = LowPriorityWrite 3566 } 3567 3568 unlock_statement: 3569 UNLOCK TABLES 3570 { 3571 $$ = &UnlockTables{} 3572 } 3573 3574 revert_statement: 3575 REVERT comment_opt VITESS_MIGRATION STRING 3576 { 3577 $$ = &RevertMigration{Comments: Comments($2), UUID: string($4)} 3578 } 3579 3580 flush_statement: 3581 FLUSH local_opt flush_option_list 3582 { 3583 $$ = &Flush{IsLocal: $2, FlushOptions:$3} 3584 } 3585 | FLUSH local_opt TABLES 3586 { 3587 $$ = &Flush{IsLocal: $2} 3588 } 3589 | FLUSH local_opt TABLES WITH READ LOCK 3590 { 3591 $$ = &Flush{IsLocal: $2, WithLock:true} 3592 } 3593 | FLUSH local_opt TABLES table_name_list 3594 { 3595 $$ = &Flush{IsLocal: $2, TableNames:$4} 3596 } 3597 | FLUSH local_opt TABLES table_name_list WITH READ LOCK 3598 { 3599 $$ = &Flush{IsLocal: $2, TableNames:$4, WithLock:true} 3600 } 3601 | FLUSH local_opt TABLES table_name_list FOR EXPORT 3602 { 3603 $$ = &Flush{IsLocal: $2, TableNames:$4, ForExport:true} 3604 } 3605 3606 flush_option_list: 3607 flush_option 3608 { 3609 $$ = []string{$1} 3610 } 3611 | flush_option_list ',' flush_option 3612 { 3613 $$ = append($1,$3) 3614 } 3615 3616 flush_option: 3617 BINARY LOGS 3618 { 3619 $$ = string($1) + " " + string($2) 3620 } 3621 | ENGINE LOGS 3622 { 3623 $$ = string($1) + " " + string($2) 3624 } 3625 | ERROR LOGS 3626 { 3627 $$ = string($1) + " " + string($2) 3628 } 3629 | GENERAL LOGS 3630 { 3631 $$ = string($1) + " " + string($2) 3632 } 3633 | HOSTS 3634 { 3635 $$ = string($1) 3636 } 3637 | LOGS 3638 { 3639 $$ = string($1) 3640 } 3641 | PRIVILEGES 3642 { 3643 $$ = string($1) 3644 } 3645 | RELAY LOGS for_channel_opt 3646 { 3647 $$ = string($1) + " " + string($2) + $3 3648 } 3649 | SLOW LOGS 3650 { 3651 $$ = string($1) + " " + string($2) 3652 } 3653 | OPTIMIZER_COSTS 3654 { 3655 $$ = string($1) 3656 } 3657 | STATUS 3658 { 3659 $$ = string($1) 3660 } 3661 | USER_RESOURCES 3662 { 3663 $$ = string($1) 3664 } 3665 3666 local_opt: 3667 { 3668 $$ = false 3669 } 3670 | LOCAL 3671 { 3672 $$ = true 3673 } 3674 | NO_WRITE_TO_BINLOG 3675 { 3676 $$ = true 3677 } 3678 3679 for_channel_opt: 3680 { 3681 $$ = "" 3682 } 3683 | FOR CHANNEL id_or_var 3684 { 3685 $$ = " " + string($1) + " " + string($2) + " " + $3.String() 3686 } 3687 3688 comment_opt: 3689 { 3690 setAllowComments(yylex, true) 3691 } 3692 comment_list 3693 { 3694 $$ = $2 3695 setAllowComments(yylex, false) 3696 } 3697 3698 comment_list: 3699 { 3700 $$ = nil 3701 } 3702 | comment_list COMMENT 3703 { 3704 $$ = append($1, $2) 3705 } 3706 3707 union_op: 3708 UNION 3709 { 3710 $$ = true 3711 } 3712 | UNION ALL 3713 { 3714 $$ = false 3715 } 3716 | UNION DISTINCT 3717 { 3718 $$ = true 3719 } 3720 3721 cache_opt: 3722 { 3723 $$ = "" 3724 } 3725 | SQL_NO_CACHE 3726 { 3727 $$ = SQLNoCacheStr 3728 } 3729 | SQL_CACHE 3730 { 3731 $$ = SQLCacheStr 3732 } 3733 3734 distinct_opt: 3735 { 3736 $$ = false 3737 } 3738 | DISTINCT 3739 { 3740 $$ = true 3741 } 3742 | DISTINCTROW 3743 { 3744 $$ = true 3745 } 3746 3747 select_expression_list_opt: 3748 { 3749 $$ = nil 3750 } 3751 | select_expression_list 3752 { 3753 $$ = $1 3754 } 3755 3756 select_options: 3757 { 3758 $$ = nil 3759 } 3760 | select_option 3761 { 3762 $$ = []string{$1} 3763 } 3764 | select_option select_option // TODO: figure out a way to do this recursively instead. 3765 { // TODO: This is a hack since I couldn't get it to work in a nicer way. I got 'conflicts: 8 shift/reduce' 3766 $$ = []string{$1, $2} 3767 } 3768 | select_option select_option select_option 3769 { 3770 $$ = []string{$1, $2, $3} 3771 } 3772 | select_option select_option select_option select_option 3773 { 3774 $$ = []string{$1, $2, $3, $4} 3775 } 3776 3777 select_option: 3778 SQL_NO_CACHE 3779 { 3780 $$ = SQLNoCacheStr 3781 } 3782 | SQL_CACHE 3783 { 3784 $$ = SQLCacheStr 3785 } 3786 | DISTINCT 3787 { 3788 $$ = DistinctStr 3789 } 3790 | DISTINCTROW 3791 { 3792 $$ = DistinctStr 3793 } 3794 | STRAIGHT_JOIN 3795 { 3796 $$ = StraightJoinHint 3797 } 3798 | SQL_CALC_FOUND_ROWS 3799 { 3800 $$ = SQLCalcFoundRowsStr 3801 } 3802 | ALL 3803 { 3804 $$ = AllStr // These are not picked up by NewSelect, and so ALL will be dropped. But this is OK, since it's redundant anyway 3805 } 3806 3807 select_expression_list: 3808 select_expression 3809 { 3810 $$ = SelectExprs{$1} 3811 } 3812 | select_expression_list ',' select_expression 3813 { 3814 $$ = append($$, $3) 3815 } 3816 3817 select_expression: 3818 '*' 3819 { 3820 $$ = &StarExpr{} 3821 } 3822 | expression as_ci_opt 3823 { 3824 $$ = &AliasedExpr{Expr: $1, As: $2} 3825 } 3826 | table_id '.' '*' 3827 { 3828 $$ = &StarExpr{TableName: TableName{Name: $1}} 3829 } 3830 | table_id '.' reserved_table_id '.' '*' 3831 { 3832 $$ = &StarExpr{TableName: TableName{Qualifier: $1, Name: $3}} 3833 } 3834 3835 as_ci_opt: 3836 { 3837 $$ = ColIdent{} 3838 } 3839 | col_alias 3840 { 3841 $$ = $1 3842 } 3843 | AS col_alias 3844 { 3845 $$ = $2 3846 } 3847 3848 col_alias: 3849 sql_id 3850 | STRING 3851 { 3852 $$ = NewColIdent(string($1)) 3853 } 3854 3855 from_opt: 3856 %prec EMPTY_FROM_CLAUSE { 3857 $$ = TableExprs{&AliasedTableExpr{Expr:TableName{Name: NewTableIdent("dual")}}} 3858 } 3859 | from_clause 3860 { 3861 $$ = $1 3862 } 3863 3864 from_clause: 3865 FROM table_references 3866 { 3867 $$ = $2 3868 } 3869 3870 table_references: 3871 table_reference 3872 { 3873 $$ = TableExprs{$1} 3874 } 3875 | table_references ',' table_reference 3876 { 3877 $$ = append($$, $3) 3878 } 3879 3880 table_reference: 3881 table_factor 3882 | join_table 3883 3884 table_factor: 3885 aliased_table_name 3886 { 3887 $$ = $1 3888 } 3889 | derived_table as_opt table_id column_list_opt 3890 { 3891 $$ = &AliasedTableExpr{Expr:$1, As: $3, Columns: $4} 3892 } 3893 | openb table_references closeb 3894 { 3895 $$ = &ParenTableExpr{Exprs: $2} 3896 } 3897 3898 derived_table: 3899 openb query_expression closeb 3900 { 3901 $$ = &DerivedTable{$2} 3902 } 3903 3904 aliased_table_name: 3905 table_name as_opt_id index_hint_list 3906 { 3907 $$ = &AliasedTableExpr{Expr:$1, As: $2, Hints: $3} 3908 } 3909 | table_name PARTITION openb partition_list closeb as_opt_id index_hint_list 3910 { 3911 $$ = &AliasedTableExpr{Expr:$1, Partitions: $4, As: $6, Hints: $7} 3912 } 3913 3914 column_list_opt: 3915 { 3916 $$ = nil 3917 } 3918 | '(' column_list ')' 3919 { 3920 $$ = $2 3921 } 3922 3923 column_list: 3924 sql_id 3925 { 3926 $$ = Columns{$1} 3927 } 3928 | column_list ',' sql_id 3929 { 3930 $$ = append($$, $3) 3931 } 3932 3933 index_list: 3934 sql_id 3935 { 3936 $$ = Columns{$1} 3937 } 3938 | PRIMARY 3939 { 3940 $$ = Columns{NewColIdent(string($1))} 3941 } 3942 | index_list ',' sql_id 3943 { 3944 $$ = append($$, $3) 3945 } 3946 | index_list ',' PRIMARY 3947 { 3948 $$ = append($$, NewColIdent(string($3))) 3949 } 3950 3951 partition_list: 3952 sql_id 3953 { 3954 $$ = Partitions{$1} 3955 } 3956 | partition_list ',' sql_id 3957 { 3958 $$ = append($$, $3) 3959 } 3960 3961 // There is a grammar conflict here: 3962 // 1: INSERT INTO a SELECT * FROM b JOIN c ON b.i = c.i 3963 // 2: INSERT INTO a SELECT * FROM b JOIN c ON DUPLICATE KEY UPDATE a.i = 1 3964 // When yacc encounters the ON clause, it cannot determine which way to 3965 // resolve. The %prec override below makes the parser choose the 3966 // first construct, which automatically makes the second construct a 3967 // syntax error. This is the same behavior as MySQL. 3968 join_table: 3969 table_reference inner_join table_factor join_condition_opt 3970 { 3971 $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4} 3972 } 3973 | table_reference straight_join table_factor on_expression_opt 3974 { 3975 $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4} 3976 } 3977 | table_reference outer_join table_reference join_condition 3978 { 3979 $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4} 3980 } 3981 | table_reference natural_join table_factor 3982 { 3983 $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3} 3984 } 3985 3986 join_condition: 3987 ON expression 3988 { $$ = &JoinCondition{On: $2} } 3989 | USING '(' column_list ')' 3990 { $$ = &JoinCondition{Using: $3} } 3991 3992 join_condition_opt: 3993 %prec JOIN 3994 { $$ = &JoinCondition{} } 3995 | join_condition 3996 { $$ = $1 } 3997 3998 on_expression_opt: 3999 %prec JOIN 4000 { $$ = &JoinCondition{} } 4001 | ON expression 4002 { $$ = &JoinCondition{On: $2} } 4003 4004 as_opt: 4005 { $$ = struct{}{} } 4006 | AS 4007 { $$ = struct{}{} } 4008 4009 as_opt_id: 4010 { 4011 $$ = NewTableIdent("") 4012 } 4013 | table_alias 4014 { 4015 $$ = $1 4016 } 4017 | AS table_alias 4018 { 4019 $$ = $2 4020 } 4021 4022 table_alias: 4023 table_id 4024 | STRING 4025 { 4026 $$ = NewTableIdent(string($1)) 4027 } 4028 4029 inner_join: 4030 JOIN 4031 { 4032 $$ = NormalJoinType 4033 } 4034 | INNER JOIN 4035 { 4036 $$ = NormalJoinType 4037 } 4038 | CROSS JOIN 4039 { 4040 $$ = NormalJoinType 4041 } 4042 4043 straight_join: 4044 STRAIGHT_JOIN 4045 { 4046 $$ = StraightJoinType 4047 } 4048 4049 outer_join: 4050 LEFT JOIN 4051 { 4052 $$ = LeftJoinType 4053 } 4054 | LEFT OUTER JOIN 4055 { 4056 $$ = LeftJoinType 4057 } 4058 | RIGHT JOIN 4059 { 4060 $$ = RightJoinType 4061 } 4062 | RIGHT OUTER JOIN 4063 { 4064 $$ = RightJoinType 4065 } 4066 4067 natural_join: 4068 NATURAL JOIN 4069 { 4070 $$ = NaturalJoinType 4071 } 4072 | NATURAL outer_join 4073 { 4074 if $2 == LeftJoinType { 4075 $$ = NaturalLeftJoinType 4076 } else { 4077 $$ = NaturalRightJoinType 4078 } 4079 } 4080 4081 into_table_name: 4082 INTO table_name 4083 { 4084 $$ = $2 4085 } 4086 | table_name 4087 { 4088 $$ = $1 4089 } 4090 4091 table_name: 4092 table_id 4093 { 4094 $$ = TableName{Name: $1} 4095 } 4096 | table_id '.' reserved_table_id 4097 { 4098 $$ = TableName{Qualifier: $1, Name: $3} 4099 } 4100 4101 delete_table_name: 4102 table_id '.' '*' 4103 { 4104 $$ = TableName{Name: $1} 4105 } 4106 4107 index_hint_list: 4108 { 4109 $$ = nil 4110 } 4111 | USE INDEX openb index_list closeb 4112 { 4113 $$ = &IndexHints{Type: UseOp, Indexes: $4} 4114 } 4115 | USE INDEX openb closeb 4116 { 4117 $$ = &IndexHints{Type: UseOp} 4118 } 4119 | IGNORE INDEX openb index_list closeb 4120 { 4121 $$ = &IndexHints{Type: IgnoreOp, Indexes: $4} 4122 } 4123 | FORCE INDEX openb index_list closeb 4124 { 4125 $$ = &IndexHints{Type: ForceOp, Indexes: $4} 4126 } 4127 4128 where_expression_opt: 4129 { 4130 $$ = nil 4131 } 4132 | WHERE expression 4133 { 4134 $$ = $2 4135 } 4136 4137 /* all possible expressions */ 4138 expression: 4139 expression OR expression %prec OR 4140 { 4141 $$ = &OrExpr{Left: $1, Right: $3} 4142 } 4143 | expression XOR expression %prec XOR 4144 { 4145 $$ = &XorExpr{Left: $1, Right: $3} 4146 } 4147 | expression AND expression %prec AND 4148 { 4149 $$ = &AndExpr{Left: $1, Right: $3} 4150 } 4151 | NOT expression %prec NOT 4152 { 4153 $$ = &NotExpr{Expr: $2} 4154 } 4155 | bool_pri IS is_suffix %prec IS 4156 { 4157 $$ = &IsExpr{Left: $1, Right: $3} 4158 } 4159 | bool_pri %prec EXPRESSION_PREC_SETTER 4160 { 4161 $$ = $1 4162 } 4163 4164 4165 bool_pri: 4166 bool_pri IS NULL %prec IS 4167 { 4168 $$ = &IsExpr{Left: $1, Right: IsNullOp} 4169 } 4170 | bool_pri IS NOT NULL %prec IS 4171 { 4172 $$ = &IsExpr{Left: $1, Right: IsNotNullOp} 4173 } 4174 | bool_pri compare predicate 4175 { 4176 $$ = &ComparisonExpr{Left: $1, Operator: $2, Right: $3} 4177 } 4178 | predicate %prec EXPRESSION_PREC_SETTER 4179 { 4180 $$ = $1 4181 } 4182 4183 predicate: 4184 bit_expr IN col_tuple 4185 { 4186 $$ = &ComparisonExpr{Left: $1, Operator: InOp, Right: $3} 4187 } 4188 | bit_expr NOT IN col_tuple 4189 { 4190 $$ = &ComparisonExpr{Left: $1, Operator: NotInOp, Right: $4} 4191 } 4192 | bit_expr BETWEEN bit_expr AND predicate 4193 { 4194 $$ = &BetweenExpr{Left: $1, IsBetween: true, From: $3, To: $5} 4195 } 4196 | bit_expr NOT BETWEEN bit_expr AND predicate 4197 { 4198 $$ = &BetweenExpr{Left: $1, IsBetween: false, From: $4, To: $6} 4199 } 4200 | bit_expr LIKE simple_expr 4201 { 4202 $$ = &ComparisonExpr{Left: $1, Operator: LikeOp, Right: $3} 4203 } 4204 | bit_expr NOT LIKE simple_expr 4205 { 4206 $$ = &ComparisonExpr{Left: $1, Operator: NotLikeOp, Right: $4} 4207 } 4208 | bit_expr LIKE simple_expr ESCAPE simple_expr %prec LIKE 4209 { 4210 $$ = &ComparisonExpr{Left: $1, Operator: LikeOp, Right: $3, Escape: $5} 4211 } 4212 | bit_expr NOT LIKE simple_expr ESCAPE simple_expr %prec LIKE 4213 { 4214 $$ = &ComparisonExpr{Left: $1, Operator: NotLikeOp, Right: $4, Escape: $6} 4215 } 4216 | bit_expr REGEXP bit_expr 4217 { 4218 $$ = &ComparisonExpr{Left: $1, Operator: RegexpOp, Right: $3} 4219 } 4220 | bit_expr NOT REGEXP bit_expr 4221 { 4222 $$ = &ComparisonExpr{Left: $1, Operator: NotRegexpOp, Right: $4} 4223 } 4224 | bit_expr %prec EXPRESSION_PREC_SETTER 4225 { 4226 $$ = $1 4227 } 4228 4229 bit_expr: 4230 bit_expr '|' bit_expr %prec '|' 4231 { 4232 $$ = &BinaryExpr{Left: $1, Operator: BitOrOp, Right: $3} 4233 } 4234 | bit_expr '&' bit_expr %prec '&' 4235 { 4236 $$ = &BinaryExpr{Left: $1, Operator: BitAndOp, Right: $3} 4237 } 4238 | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT 4239 { 4240 $$ = &BinaryExpr{Left: $1, Operator: ShiftLeftOp, Right: $3} 4241 } 4242 | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT 4243 { 4244 $$ = &BinaryExpr{Left: $1, Operator: ShiftRightOp, Right: $3} 4245 } 4246 | bit_expr '+' bit_expr %prec '+' 4247 { 4248 $$ = &BinaryExpr{Left: $1, Operator: PlusOp, Right: $3} 4249 } 4250 | bit_expr '-' bit_expr %prec '-' 4251 { 4252 $$ = &BinaryExpr{Left: $1, Operator: MinusOp, Right: $3} 4253 } 4254 | bit_expr '*' bit_expr %prec '*' 4255 { 4256 $$ = &BinaryExpr{Left: $1, Operator: MultOp, Right: $3} 4257 } 4258 | bit_expr '/' bit_expr %prec '/' 4259 { 4260 $$ = &BinaryExpr{Left: $1, Operator: DivOp, Right: $3} 4261 } 4262 | bit_expr '%' bit_expr %prec '%' 4263 { 4264 $$ = &BinaryExpr{Left: $1, Operator: ModOp, Right: $3} 4265 } 4266 | bit_expr DIV bit_expr %prec DIV 4267 { 4268 $$ = &BinaryExpr{Left: $1, Operator: IntDivOp, Right: $3} 4269 } 4270 | bit_expr MOD bit_expr %prec MOD 4271 { 4272 $$ = &BinaryExpr{Left: $1, Operator: ModOp, Right: $3} 4273 } 4274 | bit_expr '^' bit_expr %prec '^' 4275 { 4276 $$ = &BinaryExpr{Left: $1, Operator: BitXorOp, Right: $3} 4277 } 4278 | simple_expr %prec EXPRESSION_PREC_SETTER 4279 { 4280 $$ = $1 4281 } 4282 4283 simple_expr: 4284 function_call_keyword 4285 { 4286 $$ = $1 4287 } 4288 | function_call_nonkeyword 4289 { 4290 $$ = $1 4291 } 4292 | function_call_generic 4293 { 4294 $$ = $1 4295 } 4296 | function_call_conflict 4297 { 4298 $$ = $1 4299 } 4300 | simple_expr COLLATE charset %prec UNARY 4301 { 4302 $$ = &CollateExpr{Expr: $1, Collation: $3} 4303 } 4304 | literal_or_null 4305 { 4306 $$ = $1 4307 } 4308 | column_name 4309 { 4310 $$ = $1 4311 } 4312 | '+' simple_expr %prec UNARY 4313 { 4314 $$= $2; // TODO: do we really want to ignore unary '+' before any kind of literals? 4315 } 4316 | '-' simple_expr %prec UNARY 4317 { 4318 $$ = &UnaryExpr{Operator: UMinusOp, Expr: $2} 4319 } 4320 | '~' simple_expr %prec UNARY 4321 { 4322 $$ = &UnaryExpr{Operator: TildaOp, Expr: $2} 4323 } 4324 | '!' simple_expr %prec UNARY 4325 { 4326 $$ = &UnaryExpr{Operator: BangOp, Expr: $2} 4327 } 4328 | subquery 4329 { 4330 $$= $1 4331 } 4332 | tuple_expression 4333 { 4334 $$ = $1 4335 } 4336 | EXISTS subquery 4337 { 4338 $$ = &ExistsExpr{Subquery: $2} 4339 } 4340 | MATCH openb select_expression_list closeb AGAINST openb bit_expr match_option closeb 4341 { 4342 $$ = &MatchExpr{Columns: $3, Expr: $7, Option: $8} 4343 } 4344 | CAST openb expression AS convert_type closeb 4345 { 4346 $$ = &ConvertExpr{Expr: $3, Type: $5} 4347 } 4348 | CONVERT openb expression ',' convert_type closeb 4349 { 4350 $$ = &ConvertExpr{Expr: $3, Type: $5} 4351 } 4352 | CONVERT openb expression USING charset closeb 4353 { 4354 $$ = &ConvertUsingExpr{Expr: $3, Type: $5} 4355 } 4356 | BINARY simple_expr %prec UNARY 4357 { 4358 $$ = &UnaryExpr{Operator: BinaryOp, Expr: $2} 4359 } 4360 | DEFAULT default_opt 4361 { 4362 $$ = &Default{ColName: $2} 4363 } 4364 | INTERVAL simple_expr sql_id 4365 { 4366 // This rule prevents the usage of INTERVAL 4367 // as a function. If support is needed for that, 4368 // we'll need to revisit this. The solution 4369 // will be non-trivial because of grammar conflicts. 4370 $$ = &IntervalExpr{Expr: $2, Unit: $3.String()} 4371 } 4372 | column_name JSON_EXTRACT_OP text_literal_or_arg 4373 { 4374 $$ = &BinaryExpr{Left: $1, Operator: JSONExtractOp, Right: $3} 4375 } 4376 | column_name JSON_UNQUOTE_EXTRACT_OP text_literal_or_arg 4377 { 4378 $$ = &BinaryExpr{Left: $1, Operator: JSONUnquoteExtractOp, Right: $3} 4379 } 4380 4381 4382 default_opt: 4383 /* empty */ 4384 { 4385 $$ = "" 4386 } 4387 | openb id_or_var closeb 4388 { 4389 $$ = string($2.String()) 4390 } 4391 4392 boolean_value: 4393 TRUE 4394 { 4395 $$ = BoolVal(true) 4396 } 4397 | FALSE 4398 { 4399 $$ = BoolVal(false) 4400 } 4401 4402 4403 is_suffix: 4404 TRUE 4405 { 4406 $$ = IsTrueOp 4407 } 4408 | NOT TRUE 4409 { 4410 $$ = IsNotTrueOp 4411 } 4412 | FALSE 4413 { 4414 $$ = IsFalseOp 4415 } 4416 | NOT FALSE 4417 { 4418 $$ = IsNotFalseOp 4419 } 4420 4421 compare: 4422 '=' 4423 { 4424 $$ = EqualOp 4425 } 4426 | '<' 4427 { 4428 $$ = LessThanOp 4429 } 4430 | '>' 4431 { 4432 $$ = GreaterThanOp 4433 } 4434 | LE 4435 { 4436 $$ = LessEqualOp 4437 } 4438 | GE 4439 { 4440 $$ = GreaterEqualOp 4441 } 4442 | NE 4443 { 4444 $$ = NotEqualOp 4445 } 4446 | NULL_SAFE_EQUAL 4447 { 4448 $$ = NullSafeEqualOp 4449 } 4450 4451 col_tuple: 4452 row_tuple 4453 { 4454 $$ = $1 4455 } 4456 | subquery 4457 { 4458 $$ = $1 4459 } 4460 | LIST_ARG 4461 { 4462 $$ = ListArg($1[2:]) 4463 bindVariable(yylex, $1[2:]) 4464 } 4465 4466 subquery: 4467 query_expression_parens %prec SUBQUERY_AS_EXPR 4468 { 4469 $$ = &Subquery{$1} 4470 } 4471 4472 expression_list: 4473 expression 4474 { 4475 $$ = Exprs{$1} 4476 } 4477 | expression_list ',' expression 4478 { 4479 $$ = append($1, $3) 4480 } 4481 4482 /* 4483 Regular function calls without special token or syntax, guaranteed to not 4484 introduce side effects due to being a simple identifier 4485 */ 4486 function_call_generic: 4487 sql_id openb select_expression_list_opt closeb 4488 { 4489 $$ = &FuncExpr{Name: $1, Exprs: $3} 4490 } 4491 | sql_id openb DISTINCT select_expression_list closeb 4492 { 4493 $$ = &FuncExpr{Name: $1, Distinct: true, Exprs: $4} 4494 } 4495 | sql_id openb DISTINCTROW select_expression_list closeb 4496 { 4497 $$ = &FuncExpr{Name: $1, Distinct: true, Exprs: $4} 4498 } 4499 | table_id '.' reserved_sql_id openb select_expression_list_opt closeb 4500 { 4501 $$ = &FuncExpr{Qualifier: $1, Name: $3, Exprs: $5} 4502 } 4503 4504 /* 4505 Function calls using reserved keywords, with dedicated grammar rules 4506 as a result 4507 */ 4508 function_call_keyword: 4509 LEFT openb select_expression_list closeb 4510 { 4511 $$ = &FuncExpr{Name: NewColIdent("left"), Exprs: $3} 4512 } 4513 | RIGHT openb select_expression_list closeb 4514 { 4515 $$ = &FuncExpr{Name: NewColIdent("right"), Exprs: $3} 4516 } 4517 | SUBSTRING openb expression ',' expression ',' expression closeb 4518 { 4519 $$ = &SubstrExpr{Name: $3, From: $5, To: $7} 4520 } 4521 | SUBSTRING openb expression ',' expression closeb 4522 { 4523 $$ = &SubstrExpr{Name: $3, From: $5} 4524 } 4525 | SUBSTRING openb expression FROM expression FOR expression closeb 4526 { 4527 $$ = &SubstrExpr{Name: $3, From: $5, To: $7} 4528 } 4529 | SUBSTRING openb expression FROM expression closeb 4530 { 4531 $$ = &SubstrExpr{Name: $3, From: $5} 4532 } 4533 | GROUP_CONCAT openb distinct_opt select_expression_list order_by_opt separator_opt limit_opt closeb 4534 { 4535 $$ = &GroupConcatExpr{Distinct: $3, Exprs: $4, OrderBy: $5, Separator: $6, Limit: $7} 4536 } 4537 | CASE expression_opt when_expression_list else_expression_opt END 4538 { 4539 $$ = &CaseExpr{Expr: $2, Whens: $3, Else: $4} 4540 } 4541 | VALUES openb column_name closeb 4542 { 4543 $$ = &ValuesFuncExpr{Name: $3} 4544 } 4545 | CURRENT_USER func_paren_opt 4546 { 4547 $$ = &FuncExpr{Name: NewColIdent($1)} 4548 } 4549 4550 /* 4551 Function calls using non reserved keywords but with special syntax forms. 4552 Dedicated grammar rules are needed because of the special syntax 4553 */ 4554 function_call_nonkeyword: 4555 /* doesn't support fsp */ 4556 UTC_DATE func_paren_opt 4557 { 4558 $$ = &FuncExpr{Name:NewColIdent("utc_date")} 4559 } 4560 | now 4561 { 4562 $$ = $1 4563 } 4564 // curdate 4565 /* doesn't support fsp */ 4566 | CURRENT_DATE func_paren_opt 4567 { 4568 $$ = &FuncExpr{Name:NewColIdent("current_date")} 4569 } 4570 | UTC_TIME func_datetime_precision 4571 { 4572 $$ = &CurTimeFuncExpr{Name:NewColIdent("utc_time"), Fsp: $2} 4573 } 4574 // curtime 4575 | CURRENT_TIME func_datetime_precision 4576 { 4577 $$ = &CurTimeFuncExpr{Name:NewColIdent("current_time"), Fsp: $2} 4578 } 4579 | TIMESTAMPADD openb sql_id ',' expression ',' expression closeb 4580 { 4581 $$ = &TimestampFuncExpr{Name:string("timestampadd"), Unit:$3.String(), Expr1:$5, Expr2:$7} 4582 } 4583 | TIMESTAMPDIFF openb sql_id ',' expression ',' expression closeb 4584 { 4585 $$ = &TimestampFuncExpr{Name:string("timestampdiff"), Unit:$3.String(), Expr1:$5, Expr2:$7} 4586 } 4587 | EXTRACT openb interval FROM expression closeb 4588 { 4589 $$ = &ExtractFuncExpr{IntervalTypes: $3, Expr: $5} 4590 } 4591 4592 interval: 4593 interval_time_stamp 4594 {} 4595 | DAY_HOUR 4596 { 4597 $$=IntervalDayHour 4598 } 4599 | DAY_MICROSECOND 4600 { 4601 $$=IntervalDayMicrosecond 4602 } 4603 | DAY_MINUTE 4604 { 4605 $$=IntervalDayMinute 4606 } 4607 | DAY_SECOND 4608 { 4609 $$=IntervalDaySecond 4610 } 4611 | HOUR_MICROSECOND 4612 { 4613 $$=IntervalHourMicrosecond 4614 } 4615 | HOUR_MINUTE 4616 { 4617 $$=IntervalHourMinute 4618 } 4619 | HOUR_SECOND 4620 { 4621 $$=IntervalHourSecond 4622 } 4623 | MINUTE_MICROSECOND 4624 { 4625 $$=IntervalMinuteMicrosecond 4626 } 4627 | MINUTE_SECOND 4628 { 4629 $$=IntervalMinuteSecond 4630 } 4631 | SECOND_MICROSECOND 4632 { 4633 $$=IntervalSecondMicrosecond 4634 } 4635 | YEAR_MONTH 4636 { 4637 $$=IntervalYearMonth 4638 } 4639 4640 interval_time_stamp: 4641 DAY 4642 { 4643 $$=IntervalDay 4644 } 4645 | WEEK 4646 { 4647 $$=IntervalWeek 4648 } 4649 | HOUR 4650 { 4651 $$=IntervalHour 4652 } 4653 | MINUTE 4654 { 4655 $$=IntervalMinute 4656 } 4657 | MONTH 4658 { 4659 $$=IntervalMonth 4660 } 4661 | QUARTER 4662 { 4663 $$=IntervalQuarter 4664 } 4665 | SECOND 4666 { 4667 $$=IntervalSecond 4668 } 4669 | MICROSECOND 4670 { 4671 $$=IntervalMicrosecond 4672 } 4673 | YEAR 4674 { 4675 $$=IntervalYear 4676 } 4677 4678 func_paren_opt: 4679 /* empty */ 4680 | openb closeb 4681 4682 func_datetime_precision: 4683 /* empty */ 4684 { 4685 $$ = nil 4686 } 4687 | openb closeb 4688 { 4689 $$ = nil 4690 } 4691 | openb INTEGRAL closeb 4692 { 4693 $$ = NewIntLiteral($2) 4694 } 4695 | openb VALUE_ARG closeb 4696 { 4697 $$ = NewArgument($2[1:]) 4698 bindVariable(yylex, $2[1:]) 4699 } 4700 4701 /* 4702 Function calls using non reserved keywords with *normal* syntax forms. Because 4703 the names are non-reserved, they need a dedicated rule so as not to conflict 4704 */ 4705 function_call_conflict: 4706 IF openb select_expression_list closeb 4707 { 4708 $$ = &FuncExpr{Name: NewColIdent("if"), Exprs: $3} 4709 } 4710 | DATABASE openb select_expression_list_opt closeb 4711 { 4712 $$ = &FuncExpr{Name: NewColIdent("database"), Exprs: $3} 4713 } 4714 | SCHEMA openb select_expression_list_opt closeb 4715 { 4716 $$ = &FuncExpr{Name: NewColIdent("schema"), Exprs: $3} 4717 } 4718 | MOD openb select_expression_list closeb 4719 { 4720 $$ = &FuncExpr{Name: NewColIdent("mod"), Exprs: $3} 4721 } 4722 | REPLACE openb select_expression_list closeb 4723 { 4724 $$ = &FuncExpr{Name: NewColIdent("replace"), Exprs: $3} 4725 } 4726 4727 match_option: 4728 /*empty*/ 4729 { 4730 $$ = NoOption 4731 } 4732 | IN BOOLEAN MODE 4733 { 4734 $$ = BooleanModeOpt 4735 } 4736 | IN NATURAL LANGUAGE MODE 4737 { 4738 $$ = NaturalLanguageModeOpt 4739 } 4740 | IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION 4741 { 4742 $$ = NaturalLanguageModeWithQueryExpansionOpt 4743 } 4744 | WITH QUERY EXPANSION 4745 { 4746 $$ = QueryExpansionOpt 4747 } 4748 4749 charset: 4750 id_or_var 4751 { 4752 $$ = string($1.String()) 4753 } 4754 | STRING 4755 { 4756 $$ = string($1) 4757 } 4758 | BINARY 4759 { 4760 $$ = string($1) 4761 } 4762 4763 convert_type: 4764 BINARY length_opt 4765 { 4766 $$ = &ConvertType{Type: string($1), Length: $2} 4767 } 4768 | CHAR length_opt charset_opt 4769 { 4770 $$ = &ConvertType{Type: string($1), Length: $2, Charset: $3, Operator: CharacterSetOp} 4771 } 4772 | CHAR length_opt id_or_var 4773 { 4774 $$ = &ConvertType{Type: string($1), Length: $2, Charset: string($3.String())} 4775 } 4776 | DATE 4777 { 4778 $$ = &ConvertType{Type: string($1)} 4779 } 4780 | DATETIME length_opt 4781 { 4782 $$ = &ConvertType{Type: string($1), Length: $2} 4783 } 4784 | DECIMAL_TYPE decimal_length_opt 4785 { 4786 $$ = &ConvertType{Type: string($1)} 4787 $$.Length = $2.Length 4788 $$.Scale = $2.Scale 4789 } 4790 | JSON 4791 { 4792 $$ = &ConvertType{Type: string($1)} 4793 } 4794 | NCHAR length_opt 4795 { 4796 $$ = &ConvertType{Type: string($1), Length: $2} 4797 } 4798 | SIGNED 4799 { 4800 $$ = &ConvertType{Type: string($1)} 4801 } 4802 | SIGNED INTEGER 4803 { 4804 $$ = &ConvertType{Type: string($1)} 4805 } 4806 | TIME length_opt 4807 { 4808 $$ = &ConvertType{Type: string($1), Length: $2} 4809 } 4810 | UNSIGNED 4811 { 4812 $$ = &ConvertType{Type: string($1)} 4813 } 4814 | UNSIGNED INTEGER 4815 { 4816 $$ = &ConvertType{Type: string($1)} 4817 } 4818 4819 expression_opt: 4820 { 4821 $$ = nil 4822 } 4823 | expression 4824 { 4825 $$ = $1 4826 } 4827 4828 separator_opt: 4829 { 4830 $$ = string("") 4831 } 4832 | SEPARATOR STRING 4833 { 4834 $$ = " separator "+encodeSQLString($2) 4835 } 4836 4837 when_expression_list: 4838 when_expression 4839 { 4840 $$ = []*When{$1} 4841 } 4842 | when_expression_list when_expression 4843 { 4844 $$ = append($1, $2) 4845 } 4846 4847 when_expression: 4848 WHEN expression THEN expression 4849 { 4850 $$ = &When{Cond: $2, Val: $4} 4851 } 4852 4853 else_expression_opt: 4854 { 4855 $$ = nil 4856 } 4857 | ELSE expression 4858 { 4859 $$ = $2 4860 } 4861 4862 column_name: 4863 sql_id 4864 { 4865 $$ = &ColName{Name: $1} 4866 } 4867 | table_id '.' reserved_sql_id 4868 { 4869 $$ = &ColName{Qualifier: TableName{Name: $1}, Name: $3} 4870 } 4871 | table_id '.' reserved_table_id '.' reserved_sql_id 4872 { 4873 $$ = &ColName{Qualifier: TableName{Qualifier: $1, Name: $3}, Name: $5} 4874 } 4875 4876 num_val: 4877 sql_id 4878 { 4879 // TODO(sougou): Deprecate this construct. 4880 if $1.Lowered() != "value" { 4881 yylex.Error("expecting value after next") 4882 return 1 4883 } 4884 $$ = NewIntLiteral("1") 4885 } 4886 | INTEGRAL VALUES 4887 { 4888 $$ = NewIntLiteral($1) 4889 } 4890 | VALUE_ARG VALUES 4891 { 4892 $$ = NewArgument($1[1:]) 4893 bindVariable(yylex, $1[1:]) 4894 } 4895 4896 group_by_opt: 4897 { 4898 $$ = nil 4899 } 4900 | GROUP BY expression_list 4901 { 4902 $$ = $3 4903 } 4904 4905 having_opt: 4906 { 4907 $$ = nil 4908 } 4909 | HAVING expression 4910 { 4911 $$ = $2 4912 } 4913 4914 order_by_opt: 4915 { 4916 $$ = nil 4917 } 4918 | order_by_clause 4919 { 4920 $$ = $1 4921 } 4922 4923 order_by_clause: 4924 ORDER BY order_list 4925 { 4926 $$ = $3 4927 } 4928 4929 order_list: 4930 order 4931 { 4932 $$ = OrderBy{$1} 4933 } 4934 | order_list ',' order 4935 { 4936 $$ = append($1, $3) 4937 } 4938 4939 order: 4940 expression asc_desc_opt 4941 { 4942 $$ = &Order{Expr: $1, Direction: $2} 4943 } 4944 4945 asc_desc_opt: 4946 { 4947 $$ = AscOrder 4948 } 4949 | ASC 4950 { 4951 $$ = AscOrder 4952 } 4953 | DESC 4954 { 4955 $$ = DescOrder 4956 } 4957 4958 limit_opt: 4959 { 4960 $$ = nil 4961 } 4962 | limit_clause 4963 { 4964 $$ = $1 4965 } 4966 4967 limit_clause: 4968 LIMIT expression 4969 { 4970 $$ = &Limit{Rowcount: $2} 4971 } 4972 | LIMIT expression ',' expression 4973 { 4974 $$ = &Limit{Offset: $2, Rowcount: $4} 4975 } 4976 | LIMIT expression OFFSET expression 4977 { 4978 $$ = &Limit{Offset: $4, Rowcount: $2} 4979 } 4980 4981 algorithm_lock_opt: 4982 { 4983 $$ = nil 4984 } 4985 | lock_index algorithm_index 4986 { 4987 $$ = []AlterOption{$1,$2} 4988 } 4989 | algorithm_index lock_index 4990 { 4991 $$ = []AlterOption{$1,$2} 4992 } 4993 | algorithm_index 4994 { 4995 $$ = []AlterOption{$1} 4996 } 4997 | lock_index 4998 { 4999 $$ = []AlterOption{$1} 5000 } 5001 5002 5003 lock_index: 5004 LOCK equal_opt DEFAULT 5005 { 5006 $$ = &LockOption{Type:DefaultType} 5007 } 5008 | LOCK equal_opt NONE 5009 { 5010 $$ = &LockOption{Type:NoneType} 5011 } 5012 | LOCK equal_opt SHARED 5013 { 5014 $$ = &LockOption{Type:SharedType} 5015 } 5016 | LOCK equal_opt EXCLUSIVE 5017 { 5018 $$ = &LockOption{Type:ExclusiveType} 5019 } 5020 5021 algorithm_index: 5022 ALGORITHM equal_opt DEFAULT 5023 { 5024 $$ = AlgorithmValue($3) 5025 } 5026 | ALGORITHM equal_opt INPLACE 5027 { 5028 $$ = AlgorithmValue($3) 5029 } 5030 | ALGORITHM equal_opt COPY 5031 { 5032 $$ = AlgorithmValue($3) 5033 } 5034 5035 algorithm_view: 5036 { 5037 $$ = "" 5038 } 5039 | ALGORITHM '=' UNDEFINED 5040 { 5041 $$ = string($3) 5042 } 5043 | ALGORITHM '=' MERGE 5044 { 5045 $$ = string($3) 5046 } 5047 | ALGORITHM '=' TEMPTABLE 5048 { 5049 $$ = string($3) 5050 } 5051 5052 security_view_opt: 5053 { 5054 $$ = "" 5055 } 5056 | SQL SECURITY security_view 5057 { 5058 $$ = $3 5059 } 5060 5061 security_view: 5062 DEFINER 5063 { 5064 $$ = string($1) 5065 } 5066 | INVOKER 5067 { 5068 $$ = string($1) 5069 } 5070 5071 check_option_opt: 5072 { 5073 $$ = "" 5074 } 5075 | WITH cascade_or_local_opt CHECK OPTION 5076 { 5077 $$ = $2 5078 } 5079 5080 cascade_or_local_opt: 5081 { 5082 $$ = "cascaded" 5083 } 5084 | CASCADED 5085 { 5086 $$ = string($1) 5087 } 5088 | LOCAL 5089 { 5090 $$ = string($1) 5091 } 5092 5093 definer_opt: 5094 { 5095 $$ = "" 5096 } 5097 | DEFINER '=' user 5098 { 5099 $$ = $3 5100 } 5101 5102 user: 5103 CURRENT_USER 5104 { 5105 $$ = string($1) 5106 } 5107 | CURRENT_USER '(' ')' 5108 { 5109 $$ = string($1) 5110 } 5111 | STRING AT_ID 5112 { 5113 $$ = encodeSQLString($1) + "@" + string($2) 5114 } 5115 | ID 5116 { 5117 $$ = string($1) 5118 } 5119 5120 locking_clause: 5121 FOR UPDATE 5122 { 5123 $$ = ForUpdateLock 5124 } 5125 | LOCK IN SHARE MODE 5126 { 5127 $$ = ShareModeLock 5128 } 5129 5130 into_clause: 5131 INTO OUTFILE S3 STRING charset_opt format_opt export_options manifest_opt overwrite_opt 5132 { 5133 $$ = &SelectInto{Type:IntoOutfileS3, FileName:encodeSQLString($4), Charset:$5, FormatOption:$6, ExportOption:$7, Manifest:$8, Overwrite:$9} 5134 } 5135 | INTO DUMPFILE STRING 5136 { 5137 $$ = &SelectInto{Type:IntoDumpfile, FileName:encodeSQLString($3), Charset:"", FormatOption:"", ExportOption:"", Manifest:"", Overwrite:""} 5138 } 5139 | INTO OUTFILE STRING charset_opt export_options 5140 { 5141 $$ = &SelectInto{Type:IntoOutfile, FileName:encodeSQLString($3), Charset:$4, FormatOption:"", ExportOption:$5, Manifest:"", Overwrite:""} 5142 } 5143 5144 format_opt: 5145 { 5146 $$ = "" 5147 } 5148 | FORMAT CSV header_opt 5149 { 5150 $$ = " format csv" + $3 5151 } 5152 | FORMAT TEXT header_opt 5153 { 5154 $$ = " format text" + $3 5155 } 5156 5157 header_opt: 5158 { 5159 $$ = "" 5160 } 5161 | HEADER 5162 { 5163 $$ = " header" 5164 } 5165 5166 manifest_opt: 5167 { 5168 $$ = "" 5169 } 5170 | MANIFEST ON 5171 { 5172 $$ = " manifest on" 5173 } 5174 | MANIFEST OFF 5175 { 5176 $$ = " manifest off" 5177 } 5178 5179 overwrite_opt: 5180 { 5181 $$ = "" 5182 } 5183 | OVERWRITE ON 5184 { 5185 $$ = " overwrite on" 5186 } 5187 | OVERWRITE OFF 5188 { 5189 $$ = " overwrite off" 5190 } 5191 5192 export_options: 5193 fields_opts lines_opts 5194 { 5195 $$ = $1 + $2 5196 } 5197 5198 lines_opts: 5199 { 5200 $$ = "" 5201 } 5202 | LINES lines_opt_list 5203 { 5204 $$ = " lines" + $2 5205 } 5206 5207 lines_opt_list: 5208 lines_opt 5209 { 5210 $$ = $1 5211 } 5212 | lines_opt_list lines_opt 5213 { 5214 $$ = $1 + $2 5215 } 5216 5217 lines_opt: 5218 STARTING BY STRING 5219 { 5220 $$ = " starting by " + encodeSQLString($3) 5221 } 5222 | TERMINATED BY STRING 5223 { 5224 $$ = " terminated by " + encodeSQLString($3) 5225 } 5226 5227 fields_opts: 5228 { 5229 $$ = "" 5230 } 5231 | columns_or_fields fields_opt_list 5232 { 5233 $$ = " " + $1 + $2 5234 } 5235 5236 fields_opt_list: 5237 fields_opt 5238 { 5239 $$ = $1 5240 } 5241 | fields_opt_list fields_opt 5242 { 5243 $$ = $1 + $2 5244 } 5245 5246 fields_opt: 5247 TERMINATED BY STRING 5248 { 5249 $$ = " terminated by " + encodeSQLString($3) 5250 } 5251 | optionally_opt ENCLOSED BY STRING 5252 { 5253 $$ = $1 + " enclosed by " + encodeSQLString($4) 5254 } 5255 | ESCAPED BY STRING 5256 { 5257 $$ = " escaped by " + encodeSQLString($3) 5258 } 5259 5260 optionally_opt: 5261 { 5262 $$ = "" 5263 } 5264 | OPTIONALLY 5265 { 5266 $$ = " optionally" 5267 } 5268 5269 // insert_data expands all combinations into a single rule. 5270 // This avoids a shift/reduce conflict while encountering the 5271 // following two possible constructs: 5272 // insert into t1(a, b) (select * from t2) 5273 // insert into t1(select * from t2) 5274 // Because the rules are together, the parser can keep shifting 5275 // the tokens until it disambiguates a as sql_id and select as keyword. 5276 insert_data: 5277 VALUES tuple_list 5278 { 5279 $$ = &Insert{Rows: $2} 5280 } 5281 | select_statement 5282 { 5283 $$ = &Insert{Rows: $1} 5284 } 5285 | openb ins_column_list closeb VALUES tuple_list 5286 { 5287 $$ = &Insert{Columns: $2, Rows: $5} 5288 } 5289 | openb closeb VALUES tuple_list 5290 { 5291 $$ = &Insert{Rows: $4} 5292 } 5293 | openb ins_column_list closeb select_statement 5294 { 5295 $$ = &Insert{Columns: $2, Rows: $4} 5296 } 5297 5298 ins_column_list: 5299 sql_id 5300 { 5301 $$ = Columns{$1} 5302 } 5303 | sql_id '.' sql_id 5304 { 5305 $$ = Columns{$3} 5306 } 5307 | ins_column_list ',' sql_id 5308 { 5309 $$ = append($$, $3) 5310 } 5311 | ins_column_list ',' sql_id '.' sql_id 5312 { 5313 $$ = append($$, $5) 5314 } 5315 5316 on_dup_opt: 5317 { 5318 $$ = nil 5319 } 5320 | ON DUPLICATE KEY UPDATE update_list 5321 { 5322 $$ = $5 5323 } 5324 5325 tuple_list: 5326 tuple_or_empty 5327 { 5328 $$ = Values{$1} 5329 } 5330 | tuple_list ',' tuple_or_empty 5331 { 5332 $$ = append($1, $3) 5333 } 5334 5335 tuple_or_empty: 5336 row_tuple 5337 { 5338 $$ = $1 5339 } 5340 | openb closeb 5341 { 5342 $$ = ValTuple{} 5343 } 5344 5345 row_tuple: 5346 openb expression_list closeb 5347 { 5348 $$ = ValTuple($2) 5349 } 5350 tuple_expression: 5351 row_tuple 5352 { 5353 if len($1) == 1 { 5354 $$ = $1[0] 5355 } else { 5356 $$ = $1 5357 } 5358 } 5359 5360 update_list: 5361 update_expression 5362 { 5363 $$ = UpdateExprs{$1} 5364 } 5365 | update_list ',' update_expression 5366 { 5367 $$ = append($1, $3) 5368 } 5369 5370 update_expression: 5371 column_name '=' expression 5372 { 5373 $$ = &UpdateExpr{Name: $1, Expr: $3} 5374 } 5375 5376 set_list: 5377 set_expression 5378 { 5379 $$ = SetExprs{$1} 5380 } 5381 | set_list ',' set_expression 5382 { 5383 $$ = append($1, $3) 5384 } 5385 5386 set_expression: 5387 reserved_sql_id '=' ON 5388 { 5389 $$ = &SetExpr{Name: $1, Scope: ImplicitScope, Expr: NewStrLiteral("on")} 5390 } 5391 | reserved_sql_id '=' OFF 5392 { 5393 $$ = &SetExpr{Name: $1, Scope: ImplicitScope, Expr: NewStrLiteral("off")} 5394 } 5395 | reserved_sql_id '=' expression 5396 { 5397 $$ = &SetExpr{Name: $1, Scope: ImplicitScope, Expr: $3} 5398 } 5399 | charset_or_character_set_or_names charset_value collate_opt 5400 { 5401 $$ = &SetExpr{Name: NewColIdent(string($1)), Scope: ImplicitScope, Expr: $2} 5402 } 5403 | set_session_or_global set_expression 5404 { 5405 $2.Scope = $1 5406 $$ = $2 5407 } 5408 5409 charset_or_character_set: 5410 CHARSET 5411 | CHARACTER SET 5412 { 5413 $$ = "charset" 5414 } 5415 5416 charset_or_character_set_or_names: 5417 charset_or_character_set 5418 | NAMES 5419 5420 charset_value: 5421 sql_id 5422 { 5423 $$ = NewStrLiteral($1.String()) 5424 } 5425 | STRING 5426 { 5427 $$ = NewStrLiteral($1) 5428 } 5429 | DEFAULT 5430 { 5431 $$ = &Default{} 5432 } 5433 5434 for_from: 5435 FOR 5436 | FROM 5437 5438 temp_opt: 5439 { $$ = false } 5440 | TEMPORARY 5441 { $$ = true } 5442 5443 exists_opt: 5444 { $$ = false } 5445 | IF EXISTS 5446 { $$ = true } 5447 5448 not_exists_opt: 5449 { $$ = false } 5450 | IF NOT EXISTS 5451 { $$ = true } 5452 5453 ignore_opt: 5454 { $$ = false } 5455 | IGNORE 5456 { $$ = true } 5457 5458 to_opt: 5459 { $$ = struct{}{} } 5460 | TO 5461 { $$ = struct{}{} } 5462 | AS 5463 { $$ = struct{}{} } 5464 5465 call_statement: 5466 CALL table_name openb expression_list_opt closeb 5467 { 5468 $$ = &CallProc{Name: $2, Params: $4} 5469 } 5470 5471 expression_list_opt: 5472 { 5473 $$ = nil 5474 } 5475 | expression_list 5476 { 5477 $$ = $1 5478 } 5479 5480 using_opt: 5481 { $$ = nil } 5482 | using_index_type 5483 { $$ = []*IndexOption{$1} } 5484 5485 using_index_type: 5486 USING sql_id 5487 { 5488 $$ = &IndexOption{Name: string($1), String: string($2.String())} 5489 } 5490 5491 sql_id: 5492 id_or_var 5493 { 5494 $$ = $1 5495 } 5496 | non_reserved_keyword 5497 { 5498 $$ = NewColIdent(string($1)) 5499 } 5500 5501 reserved_sql_id: 5502 sql_id 5503 | reserved_keyword 5504 { 5505 $$ = NewColIdent(string($1)) 5506 } 5507 5508 table_id: 5509 id_or_var 5510 { 5511 $$ = NewTableIdent(string($1.String())) 5512 } 5513 | non_reserved_keyword 5514 { 5515 $$ = NewTableIdent(string($1)) 5516 } 5517 5518 table_id_opt: 5519 /* empty */ %prec LOWER_THAN_CHARSET 5520 { 5521 $$ = NewTableIdent("") 5522 } 5523 | table_id 5524 { 5525 $$ = $1 5526 } 5527 5528 reserved_table_id: 5529 table_id 5530 | reserved_keyword 5531 { 5532 $$ = NewTableIdent(string($1)) 5533 } 5534 /* 5535 These are not all necessarily reserved in MySQL, but some are. 5536 5537 These are more importantly reserved because they may conflict with our grammar. 5538 If you want to move one that is not reserved in MySQL (i.e. ESCAPE) to the 5539 non_reserved_keywords, you'll need to deal with any conflicts. 5540 5541 Sorted alphabetically 5542 */ 5543 reserved_keyword: 5544 ADD 5545 | ARRAY 5546 | AND 5547 | AS 5548 | ASC 5549 | BETWEEN 5550 | BINARY 5551 | BY 5552 | CASE 5553 | CALL 5554 | CHANGE 5555 | CHARACTER 5556 | CHECK 5557 | COLLATE 5558 | COLUMN 5559 | CONVERT 5560 | CREATE 5561 | CROSS 5562 | CUME_DIST 5563 | CURRENT_DATE 5564 | CURRENT_TIME 5565 | CURRENT_TIMESTAMP 5566 | CURRENT_USER 5567 | SUBSTR 5568 | SUBSTRING 5569 | DATABASE 5570 | DATABASES 5571 | DEFAULT 5572 | DELETE 5573 | DENSE_RANK 5574 | DESC 5575 | DESCRIBE 5576 | DISTINCT 5577 | DISTINCTROW 5578 | DIV 5579 | DROP 5580 | ELSE 5581 | ESCAPE 5582 | EXISTS 5583 | EXPLAIN 5584 | EXTRACT 5585 | FALSE 5586 | FIRST_VALUE 5587 | FOR 5588 | FORCE 5589 | FOREIGN 5590 | FROM 5591 | FULLTEXT 5592 | GENERATED 5593 | GROUP 5594 | GROUPING 5595 | GROUPS 5596 | HAVING 5597 | IF 5598 | IGNORE 5599 | IN 5600 | INDEX 5601 | INNER 5602 | INSERT 5603 | INTERVAL 5604 | INTO 5605 | IS 5606 | JOIN 5607 | JSON_TABLE 5608 | KEY 5609 | LAG 5610 | LAST_VALUE 5611 | LATERAL 5612 | LEAD 5613 | LEFT 5614 | LIKE 5615 | LIMIT 5616 | LINEAR 5617 | LOCALTIME 5618 | LOCALTIMESTAMP 5619 | LOCK 5620 | LOW_PRIORITY 5621 | MATCH 5622 | MAXVALUE 5623 | MOD 5624 | NATURAL 5625 | NEXT // next should be doable as non-reserved, but is not due to the special `select next num_val` query that vitess supports 5626 | NO_WRITE_TO_BINLOG 5627 | NOT 5628 | NOW 5629 | NTH_VALUE 5630 | NTILE 5631 | NULL 5632 | OF 5633 | OFF 5634 | ON 5635 | OPTIMIZER_COSTS 5636 | OR 5637 | ORDER 5638 | OUTER 5639 | OUTFILE 5640 | OVER 5641 | PARTITION 5642 | PERCENT_RANK 5643 | PRIMARY 5644 | RANGE 5645 | RANK 5646 | READ 5647 | RECURSIVE 5648 | REGEXP 5649 | RENAME 5650 | REPLACE 5651 | RIGHT 5652 | ROW_NUMBER 5653 | SCHEMA 5654 | SCHEMAS 5655 | SELECT 5656 | SEPARATOR 5657 | SET 5658 | SHOW 5659 | SPATIAL 5660 | STORED 5661 | STRAIGHT_JOIN 5662 | SYSTEM 5663 | TABLE 5664 | THEN 5665 | TIMESTAMPADD 5666 | TIMESTAMPDIFF 5667 | TO 5668 | TRUE 5669 | UNION 5670 | UNIQUE 5671 | UNLOCK 5672 | UPDATE 5673 | USE 5674 | USING 5675 | UTC_DATE 5676 | UTC_TIME 5677 | UTC_TIMESTAMP 5678 | VALUES 5679 | VIRTUAL 5680 | WITH 5681 | WHEN 5682 | WHERE 5683 | WINDOW 5684 | WRITE 5685 | XOR 5686 5687 /* 5688 These are non-reserved Vitess, because they don't cause conflicts in the grammar. 5689 Some of them may be reserved in MySQL. The good news is we backtick quote them 5690 when we rewrite the query, so no issue should arise. 5691 5692 Sorted alphabetically 5693 */ 5694 non_reserved_keyword: 5695 AGAINST 5696 | ACTION 5697 | ACTIVE 5698 | ADMIN 5699 | AFTER 5700 | ALGORITHM 5701 | ALWAYS 5702 | AUTO_INCREMENT 5703 | AVG_ROW_LENGTH 5704 | BEGIN 5705 | BIGINT 5706 | BIT 5707 | BLOB 5708 | BOOL 5709 | BOOLEAN 5710 | BUCKETS 5711 | CANCEL 5712 | CASCADE 5713 | CASCADED 5714 | CHANNEL 5715 | CHAR 5716 | CHARSET 5717 | CHECKSUM 5718 | CLEANUP 5719 | CLONE 5720 | COALESCE 5721 | CODE 5722 | COLLATION 5723 | COLUMNS 5724 | COMMENT_KEYWORD 5725 | COMMIT 5726 | COMMITTED 5727 | COMPACT 5728 | COMPLETE 5729 | COMPONENT 5730 | COMPRESSED 5731 | COMPRESSION 5732 | CONNECTION 5733 | COPY 5734 | CSV 5735 | DATA 5736 | DATE 5737 | DATETIME 5738 | DECIMAL_TYPE 5739 | DELAY_KEY_WRITE 5740 | DEFINER 5741 | DEFINITION 5742 | DESCRIPTION 5743 | DIRECTORY 5744 | DISABLE 5745 | DISCARD 5746 | DISK 5747 | DO 5748 | DOUBLE 5749 | DUMPFILE 5750 | DUPLICATE 5751 | DYNAMIC 5752 | ENABLE 5753 | ENCLOSED 5754 | ENCRYPTION 5755 | END 5756 | ENFORCED 5757 | ENGINE 5758 | ENGINES 5759 | ENUM 5760 | ERROR 5761 | ESCAPED 5762 | EVENT 5763 | EXCHANGE 5764 | EXCLUDE 5765 | EXCLUSIVE 5766 | EXPANSION 5767 | EXPORT 5768 | EXTENDED 5769 | FLOAT_TYPE 5770 | FIELDS 5771 | FIRST 5772 | FIXED 5773 | FLUSH 5774 | FOLLOWING 5775 | FORMAT 5776 | FULL 5777 | FUNCTION 5778 | GENERAL 5779 | GEOMCOLLECTION 5780 | GEOMETRY 5781 | GEOMETRYCOLLECTION 5782 | GET_MASTER_PUBLIC_KEY 5783 | GLOBAL 5784 | GTID_EXECUTED 5785 | HASH 5786 | HEADER 5787 | HISTOGRAM 5788 | HISTORY 5789 | HOSTS 5790 | IMPORT 5791 | INACTIVE 5792 | INPLACE 5793 | INSERT_METHOD 5794 | INT 5795 | INTEGER 5796 | INVISIBLE 5797 | INVOKER 5798 | INDEXES 5799 | ISOLATION 5800 | JSON 5801 | KEY_BLOCK_SIZE 5802 | KEYS 5803 | KEYSPACES 5804 | LANGUAGE 5805 | LAST 5806 | LAST_INSERT_ID 5807 | LESS 5808 | LEVEL 5809 | LINES 5810 | LINESTRING 5811 | LIST 5812 | LOAD 5813 | LOCAL 5814 | LOCKED 5815 | LOGS 5816 | LONGBLOB 5817 | LONGTEXT 5818 | MANIFEST 5819 | MASTER_COMPRESSION_ALGORITHMS 5820 | MASTER_PUBLIC_KEY_PATH 5821 | MASTER_TLS_CIPHERSUITES 5822 | MASTER_ZSTD_COMPRESSION_LEVEL 5823 | MAX_ROWS 5824 | MEDIUMBLOB 5825 | MEDIUMINT 5826 | MEDIUMTEXT 5827 | MEMORY 5828 | MEMBER 5829 | MERGE 5830 | MIN_ROWS 5831 | MODE 5832 | MODIFY 5833 | MULTILINESTRING 5834 | MULTIPOINT 5835 | MULTIPOLYGON 5836 | NAME 5837 | NAMES 5838 | NCHAR 5839 | NESTED 5840 | NETWORK_NAMESPACE 5841 | NOWAIT 5842 | NO 5843 | NONE 5844 | NULLS 5845 | NUMERIC 5846 | OFFSET 5847 | OJ 5848 | OLD 5849 | OPEN 5850 | OPTION 5851 | OPTIONAL 5852 | OPTIONALLY 5853 | ORDINALITY 5854 | ORGANIZATION 5855 | ONLY 5856 | OPTIMIZE 5857 | OTHERS 5858 | OVERWRITE 5859 | PACK_KEYS 5860 | PARSER 5861 | PARTITIONING 5862 | PARTITIONS 5863 | PASSWORD 5864 | PATH 5865 | PERSIST 5866 | PERSIST_ONLY 5867 | PRECEDING 5868 | PRIVILEGE_CHECKS_USER 5869 | PRIVILEGES 5870 | PROCESS 5871 | PLUGINS 5872 | POINT 5873 | POLYGON 5874 | PROCEDURE 5875 | PROCESSLIST 5876 | QUERY 5877 | RANDOM 5878 | REAL 5879 | REBUILD 5880 | REDUNDANT 5881 | REFERENCE 5882 | REFERENCES 5883 | RELAY 5884 | REMOVE 5885 | REORGANIZE 5886 | REPAIR 5887 | REPEATABLE 5888 | RESTRICT 5889 | REQUIRE_ROW_FORMAT 5890 | RESOURCE 5891 | RESPECT 5892 | RESTART 5893 | RETAIN 5894 | RETRY 5895 | REUSE 5896 | ROLE 5897 | ROLLBACK 5898 | ROW_FORMAT 5899 | S3 5900 | SECONDARY 5901 | SECONDARY_ENGINE 5902 | SECONDARY_LOAD 5903 | SECONDARY_UNLOAD 5904 | SECURITY 5905 | SEQUENCE 5906 | SESSION 5907 | SERIALIZABLE 5908 | SHARE 5909 | SHARED 5910 | SIGNED 5911 | SKIP 5912 | SLOW 5913 | SMALLINT 5914 | SQL 5915 | SRID 5916 | START 5917 | STARTING 5918 | STATS_AUTO_RECALC 5919 | STATS_PERSISTENT 5920 | STATS_SAMPLE_PAGES 5921 | STATUS 5922 | STORAGE 5923 | STREAM 5924 | SUBPARTITION 5925 | SUBPARTITIONS 5926 | TABLES 5927 | TABLESPACE 5928 | TEMPORARY 5929 | TEMPTABLE 5930 | TERMINATED 5931 | TEXT 5932 | THAN 5933 | THREAD_PRIORITY 5934 | TIES 5935 | TIME 5936 | TIMESTAMP 5937 | TINYBLOB 5938 | TINYINT 5939 | TINYTEXT 5940 | TRANSACTION 5941 | TREE 5942 | TRIGGER 5943 | TRIGGERS 5944 | TRUNCATE 5945 | UNBOUNDED 5946 | UNCOMMITTED 5947 | UNDEFINED 5948 | UNSIGNED 5949 | UNUSED 5950 | UPGRADE 5951 | USER 5952 | USER_RESOURCES 5953 | VALIDATION 5954 | VARBINARY 5955 | VARCHAR 5956 | VARIABLES 5957 | VCPU 5958 | VGTID_EXECUTED 5959 | VIEW 5960 | VINDEX 5961 | VINDEXES 5962 | VISIBLE 5963 | VITESS 5964 | VITESS_KEYSPACES 5965 | VITESS_METADATA 5966 | VITESS_MIGRATION 5967 | VITESS_MIGRATIONS 5968 | VITESS_REPLICATION_STATUS 5969 | VITESS_SHARDS 5970 | VITESS_TABLETS 5971 | VSCHEMA 5972 | WARNINGS 5973 | WITHOUT 5974 | WORK 5975 | YEAR 5976 | ZEROFILL 5977 | DAY 5978 | DAY_HOUR 5979 | DAY_MICROSECOND 5980 | DAY_MINUTE 5981 | DAY_SECOND 5982 | HOUR 5983 | HOUR_MICROSECOND 5984 | HOUR_MINUTE 5985 | HOUR_SECOND 5986 | MICROSECOND 5987 | MINUTE 5988 | MINUTE_MICROSECOND 5989 | MINUTE_SECOND 5990 | MONTH 5991 | QUARTER 5992 | SECOND 5993 | SECOND_MICROSECOND 5994 | YEAR_MONTH 5995 5996 openb: 5997 '(' 5998 { 5999 if incNesting(yylex) { 6000 yylex.Error("max nesting level reached") 6001 return 1 6002 } 6003 } 6004 6005 closeb: 6006 ')' 6007 { 6008 decNesting(yylex) 6009 } 6010 6011 skip_to_end: 6012 { 6013 skipToEnd(yylex) 6014 } 6015 6016 ddl_skip_to_end: 6017 { 6018 skipToEnd(yylex) 6019 } 6020 | openb 6021 { 6022 skipToEnd(yylex) 6023 } 6024 | reserved_sql_id 6025 { 6026 skipToEnd(yylex) 6027 }