github.com/pingcap/tidb/parser@v0.0.0-20231013125129-93a834a6bf8d/parser.y (about) 1 %{ 2 // Copyright 2013 The ql Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSES/QL-LICENSE file. 5 6 // Copyright 2015 PingCAP, Inc. 7 // 8 // Licensed under the Apache License, Version 2.0 (the "License"); 9 // you may not use this file except in compliance with the License. 10 // You may obtain a copy of the License at 11 // 12 // http://www.apache.org/licenses/LICENSE-2.0 13 // 14 // Unless required by applicable law or agreed to in writing, software 15 // distributed under the License is distributed on an "AS IS" BASIS, 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 19 // Initial yacc source generated by ebnf2y[1] 20 // at 2013-10-04 23:10:47.861401015 +0200 CEST 21 // 22 // $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _ 23 // 24 // [1]: http://github.com/cznic/ebnf2y 25 26 package parser 27 28 import ( 29 "strings" 30 "time" 31 32 "github.com/pingcap/tidb/parser/mysql" 33 "github.com/pingcap/tidb/parser/ast" 34 "github.com/pingcap/tidb/parser/model" 35 "github.com/pingcap/tidb/parser/opcode" 36 "github.com/pingcap/tidb/parser/auth" 37 "github.com/pingcap/tidb/parser/charset" 38 "github.com/pingcap/tidb/parser/types" 39 "github.com/pingcap/tidb/parser/duration" 40 ) 41 42 %} 43 44 %union { 45 offset int // offset 46 item interface{} 47 ident string 48 expr ast.ExprNode 49 statement ast.StmtNode 50 } 51 52 %token <ident> 53 54 /*yy:token "%c" */ 55 identifier "identifier" 56 asof "AS OF" 57 toTimestamp "TO TIMESTAMP" 58 memberof "MEMBER OF" 59 optionallyEnclosedBy "OPTIONALLY ENCLOSED BY" 60 61 /*yy:token "_%c" */ 62 underscoreCS "UNDERSCORE_CHARSET" 63 64 /*yy:token "\"%c\"" */ 65 stringLit "string literal" 66 singleAtIdentifier "identifier with single leading at" 67 doubleAtIdentifier "identifier with double leading at" 68 invalid "a special token never used by parser, used by lexer to indicate error" 69 hintComment "an optimizer hint" 70 andand "&&" 71 pipes "||" 72 73 /* The following tokens belong to ODBCDateTimeType. */ 74 odbcDateType "d" 75 odbcTimeType "t" 76 odbcTimestampType "ts" 77 78 /* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */ 79 add "ADD" 80 all "ALL" 81 alter "ALTER" 82 analyze "ANALYZE" 83 and "AND" 84 array "ARRAY" 85 as "AS" 86 asc "ASC" 87 between "BETWEEN" 88 bigIntType "BIGINT" 89 binaryType "BINARY" 90 blobType "BLOB" 91 both "BOTH" 92 by "BY" 93 call "CALL" 94 cascade "CASCADE" 95 caseKwd "CASE" 96 change "CHANGE" 97 character "CHARACTER" 98 charType "CHAR" 99 check "CHECK" 100 collate "COLLATE" 101 column "COLUMN" 102 constraint "CONSTRAINT" 103 continueKwd "CONTINUE" 104 convert "CONVERT" 105 create "CREATE" 106 cross "CROSS" 107 cumeDist "CUME_DIST" 108 currentDate "CURRENT_DATE" 109 currentTime "CURRENT_TIME" 110 currentTs "CURRENT_TIMESTAMP" 111 currentUser "CURRENT_USER" 112 currentRole "CURRENT_ROLE" 113 cursor "CURSOR" 114 database "DATABASE" 115 databases "DATABASES" 116 dayHour "DAY_HOUR" 117 dayMicrosecond "DAY_MICROSECOND" 118 dayMinute "DAY_MINUTE" 119 daySecond "DAY_SECOND" 120 decimalType "DECIMAL" 121 defaultKwd "DEFAULT" 122 delayed "DELAYED" 123 deleteKwd "DELETE" 124 denseRank "DENSE_RANK" 125 desc "DESC" 126 describe "DESCRIBE" 127 distinct "DISTINCT" 128 distinctRow "DISTINCTROW" 129 div "DIV" 130 doubleType "DOUBLE" 131 drop "DROP" 132 dual "DUAL" 133 elseIfKwd "ELSEIF" 134 elseKwd "ELSE" 135 enclosed "ENCLOSED" 136 escaped "ESCAPED" 137 exists "EXISTS" 138 exit "EXIT" 139 explain "EXPLAIN" 140 except "EXCEPT" 141 falseKwd "FALSE" 142 fetch "FETCH" 143 firstValue "FIRST_VALUE" 144 floatType "FLOAT" 145 float4Type "FLOAT4" 146 float8Type "FLOAT8" 147 forKwd "FOR" 148 force "FORCE" 149 foreign "FOREIGN" 150 from "FROM" 151 fulltext "FULLTEXT" 152 generated "GENERATED" 153 grant "GRANT" 154 group "GROUP" 155 groups "GROUPS" 156 having "HAVING" 157 highPriority "HIGH_PRIORITY" 158 hourMicrosecond "HOUR_MICROSECOND" 159 hourMinute "HOUR_MINUTE" 160 hourSecond "HOUR_SECOND" 161 ifKwd "IF" 162 ignore "IGNORE" 163 in "IN" 164 index "INDEX" 165 infile "INFILE" 166 inner "INNER" 167 inout "INOUT" 168 integerType "INTEGER" 169 intersect "INTERSECT" 170 interval "INTERVAL" 171 into "INTO" 172 outfile "OUTFILE" 173 is "IS" 174 insert "INSERT" 175 intType "INT" 176 int1Type "INT1" 177 int2Type "INT2" 178 int3Type "INT3" 179 int4Type "INT4" 180 int8Type "INT8" 181 iterate "ITERATE" 182 join "JOIN" 183 key "KEY" 184 keys "KEYS" 185 kill "KILL" 186 lag "LAG" 187 lastValue "LAST_VALUE" 188 lead "LEAD" 189 leading "LEADING" 190 leave "LEAVE" 191 left "LEFT" 192 like "LIKE" 193 ilike "ILIKE" 194 limit "LIMIT" 195 lines "LINES" 196 linear "LINEAR" 197 load "LOAD" 198 localTime "LOCALTIME" 199 localTs "LOCALTIMESTAMP" 200 lock "LOCK" 201 longblobType "LONGBLOB" 202 longtextType "LONGTEXT" 203 lowPriority "LOW_PRIORITY" 204 match "MATCH" 205 maxValue "MAXVALUE" 206 mediumblobType "MEDIUMBLOB" 207 mediumIntType "MEDIUMINT" 208 mediumtextType "MEDIUMTEXT" 209 middleIntType "MIDDLEINT" 210 minuteMicrosecond "MINUTE_MICROSECOND" 211 minuteSecond "MINUTE_SECOND" 212 mod "MOD" 213 not "NOT" 214 noWriteToBinLog "NO_WRITE_TO_BINLOG" 215 nthValue "NTH_VALUE" 216 ntile "NTILE" 217 null "NULL" 218 numericType "NUMERIC" 219 of "OF" 220 on "ON" 221 optimize "OPTIMIZE" 222 option "OPTION" 223 optionally "OPTIONALLY" 224 or "OR" 225 order "ORDER" 226 out "OUT" 227 outer "OUTER" 228 over "OVER" 229 partition "PARTITION" 230 percentRank "PERCENT_RANK" 231 precisionType "PRECISION" 232 primary "PRIMARY" 233 procedure "PROCEDURE" 234 rangeKwd "RANGE" 235 rank "RANK" 236 read "READ" 237 realType "REAL" 238 recursive "RECURSIVE" 239 references "REFERENCES" 240 regexpKwd "REGEXP" 241 release "RELEASE" 242 rename "RENAME" 243 repeat "REPEAT" 244 replace "REPLACE" 245 require "REQUIRE" 246 restrict "RESTRICT" 247 revoke "REVOKE" 248 right "RIGHT" 249 rlike "RLIKE" 250 row "ROW" 251 rows "ROWS" 252 rowNumber "ROW_NUMBER" 253 secondMicrosecond "SECOND_MICROSECOND" 254 selectKwd "SELECT" 255 set "SET" 256 show "SHOW" 257 smallIntType "SMALLINT" 258 spatial "SPATIAL" 259 sql "SQL" 260 sqlBigResult "SQL_BIG_RESULT" 261 sqlCalcFoundRows "SQL_CALC_FOUND_ROWS" 262 sqlSmallResult "SQL_SMALL_RESULT" 263 sqlexception "SQLEXCEPTION" 264 sqlstate "SQLSTATE" 265 sqlwarning "SQLWARNING" 266 ssl "SSL" 267 starting "STARTING" 268 statsExtended "STATS_EXTENDED" 269 straightJoin "STRAIGHT_JOIN" 270 tidbCurrentTSO "TiDB_CURRENT_TSO" 271 tableKwd "TABLE" 272 tableSample "TABLESAMPLE" 273 stored "STORED" 274 terminated "TERMINATED" 275 then "THEN" 276 tinyblobType "TINYBLOB" 277 tinyIntType "TINYINT" 278 tinytextType "TINYTEXT" 279 to "TO" 280 trailing "TRAILING" 281 trigger "TRIGGER" 282 trueKwd "TRUE" 283 unique "UNIQUE" 284 union "UNION" 285 unlock "UNLOCK" 286 unsigned "UNSIGNED" 287 until "UNTIL" 288 update "UPDATE" 289 usage "USAGE" 290 use "USE" 291 using "USING" 292 utcDate "UTC_DATE" 293 utcTimestamp "UTC_TIMESTAMP" 294 utcTime "UTC_TIME" 295 values "VALUES" 296 long "LONG" 297 varcharType "VARCHAR" 298 varcharacter "VARCHARACTER" 299 varbinaryType "VARBINARY" 300 varying "VARYING" 301 virtual "VIRTUAL" 302 when "WHEN" 303 where "WHERE" 304 while "WHILE" 305 write "WRITE" 306 window "WINDOW" 307 with "WITH" 308 xor "XOR" 309 yearMonth "YEAR_MONTH" 310 zerofill "ZEROFILL" 311 natural "NATURAL" 312 313 /* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */ 314 account "ACCOUNT" 315 action "ACTION" 316 advise "ADVISE" 317 after "AFTER" 318 against "AGAINST" 319 ago "AGO" 320 algorithm "ALGORITHM" 321 always "ALWAYS" 322 any "ANY" 323 ascii "ASCII" 324 attribute "ATTRIBUTE" 325 attributes "ATTRIBUTES" 326 statsOptions "STATS_OPTIONS" 327 statsSampleRate "STATS_SAMPLE_RATE" 328 statsColChoice "STATS_COL_CHOICE" 329 statsColList "STATS_COL_LIST" 330 autoIdCache "AUTO_ID_CACHE" 331 autoIncrement "AUTO_INCREMENT" 332 autoRandom "AUTO_RANDOM" 333 autoRandomBase "AUTO_RANDOM_BASE" 334 avg "AVG" 335 avgRowLength "AVG_ROW_LENGTH" 336 backend "BACKEND" 337 backup "BACKUP" 338 backups "BACKUPS" 339 begin "BEGIN" 340 bernoulli "BERNOULLI" 341 binding "BINDING" 342 bindingCache "BINDING_CACHE" 343 bindings "BINDINGS" 344 binlog "BINLOG" 345 bitType "BIT" 346 block "BLOCK" 347 booleanType "BOOLEAN" 348 boolType "BOOL" 349 btree "BTREE" 350 byteType "BYTE" 351 cache "CACHE" 352 calibrate "CALIBRATE" 353 capture "CAPTURE" 354 cascaded "CASCADED" 355 causal "CAUSAL" 356 chain "CHAIN" 357 charsetKwd "CHARSET" 358 checkpoint "CHECKPOINT" 359 checksum "CHECKSUM" 360 cipher "CIPHER" 361 cleanup "CLEANUP" 362 client "CLIENT" 363 clientErrorsSummary "CLIENT_ERRORS_SUMMARY" 364 coalesce "COALESCE" 365 collation "COLLATION" 366 columnFormat "COLUMN_FORMAT" 367 columns "COLUMNS" 368 config "CONFIG" 369 comment "COMMENT" 370 commit "COMMIT" 371 committed "COMMITTED" 372 compact "COMPACT" 373 compressed "COMPRESSED" 374 compression "COMPRESSION" 375 concurrency "CONCURRENCY" 376 connection "CONNECTION" 377 consistency "CONSISTENCY" 378 consistent "CONSISTENT" 379 context "CONTEXT" 380 cpu "CPU" 381 csvBackslashEscape "CSV_BACKSLASH_ESCAPE" 382 csvDelimiter "CSV_DELIMITER" 383 csvHeader "CSV_HEADER" 384 csvNotNull "CSV_NOT_NULL" 385 csvNull "CSV_NULL" 386 csvSeparator "CSV_SEPARATOR" 387 csvTrimLastSeparators "CSV_TRIM_LAST_SEPARATORS" 388 current "CURRENT" 389 close "CLOSE" 390 cluster "CLUSTER" 391 clustered "CLUSTERED" 392 cycle "CYCLE" 393 data "DATA" 394 datetimeType "DATETIME" 395 dateType "DATE" 396 day "DAY" 397 deallocate "DEALLOCATE" 398 declare "DECLARE" 399 definer "DEFINER" 400 delayKeyWrite "DELAY_KEY_WRITE" 401 digest "DIGEST" 402 directory "DIRECTORY" 403 disable "DISABLE" 404 disabled "DISABLED" 405 discard "DISCARD" 406 disk "DISK" 407 do "DO" 408 duplicate "DUPLICATE" 409 dynamic "DYNAMIC" 410 enable "ENABLE" 411 enabled "ENABLED" 412 encryption "ENCRYPTION" 413 end "END" 414 enforced "ENFORCED" 415 engine "ENGINE" 416 engines "ENGINES" 417 enum "ENUM" 418 errorKwd "ERROR" 419 escape "ESCAPE" 420 event "EVENT" 421 events "EVENTS" 422 evolve "EVOLVE" 423 exchange "EXCHANGE" 424 exclusive "EXCLUSIVE" 425 execute "EXECUTE" 426 expansion "EXPANSION" 427 expire "EXPIRE" 428 extended "EXTENDED" 429 faultsSym "FAULTS" 430 fields "FIELDS" 431 file "FILE" 432 first "FIRST" 433 fixed "FIXED" 434 flush "FLUSH" 435 found "FOUND" 436 following "FOLLOWING" 437 format "FORMAT" 438 full "FULL" 439 function "FUNCTION" 440 general "GENERAL" 441 global "GLOBAL" 442 grants "GRANTS" 443 handler "HANDLER" 444 hash "HASH" 445 help "HELP" 446 histogram "HISTOGRAM" 447 history "HISTORY" 448 hosts "HOSTS" 449 hour "HOUR" 450 identified "IDENTIFIED" 451 identSQLErrors "ERRORS" 452 importKwd "IMPORT" 453 imports "IMPORTS" 454 increment "INCREMENT" 455 incremental "INCREMENTAL" 456 indexes "INDEXES" 457 insertMethod "INSERT_METHOD" 458 instance "INSTANCE" 459 invisible "INVISIBLE" 460 invoker "INVOKER" 461 io "IO" 462 ipc "IPC" 463 isolation "ISOLATION" 464 issuer "ISSUER" 465 jsonType "JSON" 466 keyBlockSize "KEY_BLOCK_SIZE" 467 labels "LABELS" 468 language "LANGUAGE" 469 last "LAST" 470 lastBackup "LAST_BACKUP" 471 lastval "LASTVAL" 472 less "LESS" 473 level "LEVEL" 474 list "LIST" 475 local "LOCAL" 476 locked "LOCKED" 477 location "LOCATION" 478 logs "LOGS" 479 master "MASTER" 480 max_idxnum "MAX_IDXNUM" 481 max_minutes "MAX_MINUTES" 482 maxConnectionsPerHour "MAX_CONNECTIONS_PER_HOUR" 483 maxQueriesPerHour "MAX_QUERIES_PER_HOUR" 484 maxRows "MAX_ROWS" 485 maxUpdatesPerHour "MAX_UPDATES_PER_HOUR" 486 maxUserConnections "MAX_USER_CONNECTIONS" 487 mb "MB" 488 member "MEMBER" 489 memory "MEMORY" 490 merge "MERGE" 491 microsecond "MICROSECOND" 492 minRows "MIN_ROWS" 493 minute "MINUTE" 494 minValue "MINVALUE" 495 mode "MODE" 496 modify "MODIFY" 497 month "MONTH" 498 names "NAMES" 499 national "NATIONAL" 500 ncharType "NCHAR" 501 never "NEVER" 502 next "NEXT" 503 nextval "NEXTVAL" 504 no "NO" 505 nocache "NOCACHE" 506 nocycle "NOCYCLE" 507 nodegroup "NODEGROUP" 508 nomaxvalue "NOMAXVALUE" 509 nominvalue "NOMINVALUE" 510 nonclustered "NONCLUSTERED" 511 none "NONE" 512 nowait "NOWAIT" 513 nvarcharType "NVARCHAR" 514 nulls "NULLS" 515 off "OFF" 516 offset "OFFSET" 517 oltpReadOnly "OLTP_READ_ONLY" 518 oltpReadWrite "OLTP_READ_WRITE" 519 oltpWriteOnly "OLTP_WRITE_ONLY" 520 tpch10 "TPCH_10" 521 onDuplicate "ON_DUPLICATE" 522 online "ONLINE" 523 only "ONLY" 524 open "OPEN" 525 optional "OPTIONAL" 526 packKeys "PACK_KEYS" 527 pageSym "PAGE" 528 parser "PARSER" 529 partial "PARTIAL" 530 partitioning "PARTITIONING" 531 partitions "PARTITIONS" 532 password "PASSWORD" 533 pause "PAUSE" 534 percent "PERCENT" 535 per_db "PER_DB" 536 per_table "PER_TABLE" 537 pipesAsOr 538 plugins "PLUGINS" 539 point "POINT" 540 policy "POLICY" 541 preSplitRegions "PRE_SPLIT_REGIONS" 542 preceding "PRECEDING" 543 prepare "PREPARE" 544 preserve "PRESERVE" 545 privileges "PRIVILEGES" 546 process "PROCESS" 547 processlist "PROCESSLIST" 548 profile "PROFILE" 549 profiles "PROFILES" 550 proxy "PROXY" 551 purge "PURGE" 552 quarter "QUARTER" 553 queries "QUERIES" 554 query "QUERY" 555 quick "QUICK" 556 rateLimit "RATE_LIMIT" 557 rebuild "REBUILD" 558 recover "RECOVER" 559 redundant "REDUNDANT" 560 reload "RELOAD" 561 remove "REMOVE" 562 reorganize "REORGANIZE" 563 repair "REPAIR" 564 repeatable "REPEATABLE" 565 replica "REPLICA" 566 replicas "REPLICAS" 567 replication "REPLICATION" 568 required "REQUIRED" 569 resource "RESOURCE" 570 respect "RESPECT" 571 restart "RESTART" 572 restore "RESTORE" 573 restores "RESTORES" 574 resume "RESUME" 575 reuse "REUSE" 576 reverse "REVERSE" 577 role "ROLE" 578 rollback "ROLLBACK" 579 rollup "ROLLUP" 580 routine "ROUTINE" 581 rowCount "ROW_COUNT" 582 rowFormat "ROW_FORMAT" 583 rtree "RTREE" 584 hypo "HYPO" 585 san "SAN" 586 savepoint "SAVEPOINT" 587 second "SECOND" 588 secondaryEngine "SECONDARY_ENGINE" 589 secondaryLoad "SECONDARY_LOAD" 590 secondaryUnload "SECONDARY_UNLOAD" 591 security "SECURITY" 592 sendCredentialsToTiKV "SEND_CREDENTIALS_TO_TIKV" 593 separator "SEPARATOR" 594 sequence "SEQUENCE" 595 serial "SERIAL" 596 serializable "SERIALIZABLE" 597 session "SESSION" 598 setval "SETVAL" 599 shardRowIDBits "SHARD_ROW_ID_BITS" 600 share "SHARE" 601 shared "SHARED" 602 shutdown "SHUTDOWN" 603 signed "SIGNED" 604 simple "SIMPLE" 605 skip "SKIP" 606 skipSchemaFiles "SKIP_SCHEMA_FILES" 607 slave "SLAVE" 608 slow "SLOW" 609 snapshot "SNAPSHOT" 610 some "SOME" 611 source "SOURCE" 612 sqlBufferResult "SQL_BUFFER_RESULT" 613 sqlCache "SQL_CACHE" 614 sqlNoCache "SQL_NO_CACHE" 615 sqlTsiDay "SQL_TSI_DAY" 616 sqlTsiHour "SQL_TSI_HOUR" 617 sqlTsiMinute "SQL_TSI_MINUTE" 618 sqlTsiMonth "SQL_TSI_MONTH" 619 sqlTsiQuarter "SQL_TSI_QUARTER" 620 sqlTsiSecond "SQL_TSI_SECOND" 621 sqlTsiWeek "SQL_TSI_WEEK" 622 sqlTsiYear "SQL_TSI_YEAR" 623 start "START" 624 statsAutoRecalc "STATS_AUTO_RECALC" 625 statsPersistent "STATS_PERSISTENT" 626 statsSamplePages "STATS_SAMPLE_PAGES" 627 status "STATUS" 628 storage "STORAGE" 629 strictFormat "STRICT_FORMAT" 630 subject "SUBJECT" 631 subpartition "SUBPARTITION" 632 subpartitions "SUBPARTITIONS" 633 super "SUPER" 634 swaps "SWAPS" 635 switchesSym "SWITCHES" 636 system "SYSTEM" 637 systemTime "SYSTEM_TIME" 638 tableChecksum "TABLE_CHECKSUM" 639 tables "TABLES" 640 tablespace "TABLESPACE" 641 temporary "TEMPORARY" 642 temptable "TEMPTABLE" 643 textType "TEXT" 644 than "THAN" 645 tikvImporter "TIKV_IMPORTER" 646 timestampType "TIMESTAMP" 647 timeType "TIME" 648 tokenIssuer "TOKEN_ISSUER" 649 tp "TYPE" 650 tpcc "TPCC" 651 trace "TRACE" 652 traditional "TRADITIONAL" 653 transaction "TRANSACTION" 654 triggers "TRIGGERS" 655 truncate "TRUNCATE" 656 ttl "TTL" 657 ttlEnable "TTL_ENABLE" 658 ttlJobInterval "TTL_JOB_INTERVAL" 659 unbounded "UNBOUNDED" 660 uncommitted "UNCOMMITTED" 661 undefined "UNDEFINED" 662 unicodeSym "UNICODE" 663 unknown "UNKNOWN" 664 user "USER" 665 validation "VALIDATION" 666 value "VALUE" 667 variables "VARIABLES" 668 view "VIEW" 669 visible "VISIBLE" 670 warnings "WARNINGS" 671 week "WEEK" 672 weightString "WEIGHT_STRING" 673 without "WITHOUT" 674 workload "WORKLOAD" 675 x509 "X509" 676 yearType "YEAR" 677 wait "WAIT" 678 failedLoginAttempts "FAILED_LOGIN_ATTEMPTS" 679 passwordLockTime "PASSWORD_LOCK_TIME" 680 681 /* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */ 682 addDate "ADDDATE" 683 approxCountDistinct "APPROX_COUNT_DISTINCT" 684 approxPercentile "APPROX_PERCENTILE" 685 bitAnd "BIT_AND" 686 bitOr "BIT_OR" 687 bitXor "BIT_XOR" 688 bound "BOUND" 689 br "BR" 690 briefType "BRIEF" 691 burstable "BURSTABLE" 692 cast "CAST" 693 copyKwd "COPY" 694 constraints "CONSTRAINTS" 695 curTime "CURTIME" 696 curDate "CURDATE" 697 dateAdd "DATE_ADD" 698 dateSub "DATE_SUB" 699 defined "DEFINED" 700 dotType "DOT" 701 dump "DUMP" 702 timeDuration "DURATION" 703 endTime "END_TIME" 704 exact "EXACT" 705 exprPushdownBlacklist "EXPR_PUSHDOWN_BLACKLIST" 706 extract "EXTRACT" 707 flashback "FLASHBACK" 708 follower "FOLLOWER" 709 followerConstraints "FOLLOWER_CONSTRAINTS" 710 followers "FOLLOWERS" 711 fullBackupStorage "FULL_BACKUP_STORAGE" 712 getFormat "GET_FORMAT" 713 gcTTL "GC_TTL" 714 groupConcat "GROUP_CONCAT" 715 next_row_id "NEXT_ROW_ID" 716 inplace "INPLACE" 717 instant "INSTANT" 718 internal "INTERNAL" 719 jsonArrayagg "JSON_ARRAYAGG" 720 jsonObjectAgg "JSON_OBJECTAGG" 721 leader "LEADER" 722 leaderConstraints "LEADER_CONSTRAINTS" 723 learner "LEARNER" 724 learnerConstraints "LEARNER_CONSTRAINTS" 725 learners "LEARNERS" 726 min "MIN" 727 max "MAX" 728 metadata "METADATA" 729 now "NOW" 730 optRuleBlacklist "OPT_RULE_BLACKLIST" 731 placement "PLACEMENT" 732 plan "PLAN" 733 planCache "PLAN_CACHE" 734 position "POSITION" 735 predicate "PREDICATE" 736 primaryRegion "PRIMARY_REGION" 737 recent "RECENT" 738 replayer "REPLAYER" 739 restoredTS "RESTORED_TS" 740 running "RUNNING" 741 s3 "S3" 742 schedule "SCHEDULE" 743 staleness "STALENESS" 744 startTime "START_TIME" 745 startTS "START_TS" 746 std "STD" 747 stddev "STDDEV" 748 stddevPop "STDDEV_POP" 749 stddevSamp "STDDEV_SAMP" 750 stop "STOP" 751 strict "STRICT" 752 strong "STRONG" 753 subDate "SUBDATE" 754 sum "SUM" 755 substring "SUBSTRING" 756 survivalPreferences "SURVIVAL_PREFERENCES" 757 target "TARGET" 758 taskTypes "TASK_TYPES" 759 tidbJson "TIDB_JSON" 760 timestampAdd "TIMESTAMPADD" 761 timestampDiff "TIMESTAMPDIFF" 762 tls "TLS" 763 tokudbDefault "TOKUDB_DEFAULT" 764 tokudbFast "TOKUDB_FAST" 765 tokudbLzma "TOKUDB_LZMA" 766 tokudbQuickLZ "TOKUDB_QUICKLZ" 767 tokudbSnappy "TOKUDB_SNAPPY" 768 tokudbSmall "TOKUDB_SMALL" 769 tokudbUncompressed "TOKUDB_UNCOMPRESSED" 770 tokudbZlib "TOKUDB_ZLIB" 771 tokudbZstd "TOKUDB_ZSTD" 772 top "TOP" 773 trim "TRIM" 774 untilTS "UNTIL_TS" 775 variance "VARIANCE" 776 varPop "VAR_POP" 777 varSamp "VAR_SAMP" 778 verboseType "VERBOSE" 779 trueCardCost "TRUE_CARD_COST" 780 voter "VOTER" 781 voterConstraints "VOTER_CONSTRAINTS" 782 voters "VOTERS" 783 ruRate "RU_PER_SEC" 784 priority "PRIORITY" 785 high "HIGH" 786 medium "MEDIUM" 787 low "LOW" 788 ioReadBandwidth "IO_READ_BANDWIDTH" 789 ioWriteBandwidth "IO_WRITE_BANDWIDTH" 790 execElapsed "EXEC_ELAPSED" 791 dryRun "DRYRUN" 792 cooldown "COOLDOWN" 793 watch "WATCH" 794 similar "SIMILAR" 795 queryLimit "QUERY_LIMIT" 796 background "BACKGROUND" 797 unlimited "UNLIMITED" 798 799 /* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */ 800 admin "ADMIN" 801 batch "BATCH" 802 buckets "BUCKETS" 803 builtins "BUILTINS" 804 cancel "CANCEL" 805 cardinality "CARDINALITY" 806 cmSketch "CMSKETCH" 807 columnStatsUsage "COLUMN_STATS_USAGE" 808 correlation "CORRELATION" 809 ddl "DDL" 810 dependency "DEPENDENCY" 811 depth "DEPTH" 812 drainer "DRAINER" 813 dry "DRY" 814 jobs "JOBS" 815 job "JOB" 816 nodeID "NODE_ID" 817 nodeState "NODE_STATE" 818 optimistic "OPTIMISTIC" 819 pessimistic "PESSIMISTIC" 820 pump "PUMP" 821 run "RUN" 822 samples "SAMPLES" 823 sampleRate "SAMPLERATE" 824 sessionStates "SESSION_STATES" 825 statistics "STATISTICS" 826 stats "STATS" 827 statsMeta "STATS_META" 828 statsHistograms "STATS_HISTOGRAMS" 829 statsBuckets "STATS_BUCKETS" 830 statsHealthy "STATS_HEALTHY" 831 statsTopN "STATS_TOPN" 832 statsLocked "STATS_LOCKED" 833 histogramsInFlight "HISTOGRAMS_IN_FLIGHT" 834 telemetry "TELEMETRY" 835 telemetryID "TELEMETRY_ID" 836 tidb "TIDB" 837 tiFlash "TIFLASH" 838 topn "TOPN" 839 split "SPLIT" 840 width "WIDTH" 841 reset "RESET" 842 regions "REGIONS" 843 region "REGION" 844 builtinBitAnd 845 builtinBitOr 846 builtinBitXor 847 builtinCast 848 builtinCount 849 builtinApproxCountDistinct 850 builtinApproxPercentile 851 builtinCurDate 852 builtinCurTime 853 builtinDateAdd 854 builtinDateSub 855 builtinExtract 856 builtinGroupConcat 857 builtinMax 858 builtinMin 859 builtinNow 860 builtinPosition 861 builtinSubstring 862 builtinSum 863 builtinSysDate 864 builtinStddevPop 865 builtinStddevSamp 866 builtinTranslate 867 builtinTrim 868 builtinUser 869 builtinVarPop 870 builtinVarSamp 871 872 %token <item> 873 874 /*yy:token "1.%d" */ 875 floatLit "floating-point literal" 876 877 /*yy:token "1.%d" */ 878 decLit "decimal literal" 879 880 /*yy:token "%d" */ 881 intLit "integer literal" 882 883 /*yy:token "%x" */ 884 hexLit "hexadecimal literal" 885 886 /*yy:token "%b" */ 887 bitLit "bit literal" 888 andnot "&^" 889 assignmentEq ":=" 890 eq "=" 891 ge ">=" 892 le "<=" 893 jss "->" 894 juss "->>" 895 lsh "<<" 896 neq "!=" 897 neqSynonym "<>" 898 nulleq "<=>" 899 paramMarker "?" 900 rsh ">>" 901 902 %token not2 903 %type <expr> 904 Expression "expression" 905 MaxValueOrExpression "maxvalue or expression" 906 DefaultOrExpression "default or expression" 907 BoolPri "boolean primary expression" 908 ExprOrDefault "expression or default" 909 PredicateExpr "Predicate expression factor" 910 SetExpr "Set variable statement value's expression" 911 BitExpr "bit expression" 912 SimpleExpr "simple expression" 913 SimpleIdent "Simple Identifier expression" 914 SumExpr "aggregate functions" 915 FunctionCallGeneric "Function call with Identifier" 916 FunctionCallKeyword "Function call with keyword as function name" 917 FunctionCallNonKeyword "Function call with nonkeyword as function name" 918 Literal "literal value" 919 Variable "User or system variable" 920 SystemVariable "System defined variable name" 921 UserVariable "User defined variable name" 922 SubSelect "Sub Select" 923 StringLiteral "text literal" 924 ExpressionOpt "Optional expression" 925 SignedLiteral "Literal or NumLiteral with sign" 926 DefaultValueExpr "DefaultValueExpr(Now or Signed Literal)" 927 NowSymOptionFraction "NowSym with optional fraction part" 928 NowSymOptionFractionParentheses "NowSym with optional fraction part within potential parentheses" 929 CharsetNameOrDefault "Character set name or default" 930 NextValueForSequence "Default nextval expression" 931 BuiltinFunction "Default builtin functions for columns" 932 FunctionNameSequence "Function with sequence function call" 933 WindowFuncCall "WINDOW function call" 934 RepeatableOpt "Repeatable optional in sample clause" 935 ProcedureCall "Procedure call with Identifier or identifier" 936 937 %type <statement> 938 AdminStmt "Check table statement or show ddl statement" 939 AlterDatabaseStmt "Alter database statement" 940 AlterTableStmt "Alter table statement" 941 AlterUserStmt "Alter user statement" 942 AlterInstanceStmt "Alter instance statement" 943 AlterRangeStmt "Alter data range configuration statement" 944 AlterPolicyStmt "Alter Placement Policy statement" 945 AlterResourceGroupStmt "Alter Resource Group statement" 946 AlterSequenceStmt "Alter sequence statement" 947 AnalyzeTableStmt "Analyze table statement" 948 BeginTransactionStmt "BEGIN TRANSACTION statement" 949 BinlogStmt "Binlog base64 statement" 950 BRIEStmt "BACKUP or RESTORE statement" 951 CalibrateResourceStmt "CALIBRATE RESOURCE statement" 952 CommitStmt "COMMIT statement" 953 CreateTableStmt "CREATE TABLE statement" 954 CreateViewStmt "CREATE VIEW statement" 955 CreateUserStmt "CREATE User statement" 956 CreateRoleStmt "CREATE Role statement" 957 CreateDatabaseStmt "Create Database Statement" 958 CreateIndexStmt "CREATE INDEX statement" 959 CreateBindingStmt "CREATE BINDING statement" 960 CreatePolicyStmt "CREATE PLACEMENT POLICY statement" 961 CreateProcedureStmt "CREATE PROCEDURE statement" 962 AddQueryWatchStmt "ADD QUERY WATCH statement" 963 CreateResourceGroupStmt "CREATE RESOURCE GROUP statement" 964 CreateSequenceStmt "CREATE SEQUENCE statement" 965 CreateStatisticsStmt "CREATE STATISTICS statement" 966 DoStmt "Do statement" 967 DropDatabaseStmt "DROP DATABASE statement" 968 DropIndexStmt "DROP INDEX statement" 969 DropProcedureStmt "DROP PROCEDURE statement" 970 DropQueryWatchStmt "DROP QUERY WATCH statement" 971 DropResourceGroupStmt "DROP RESOURCE GROUP statement" 972 DropStatisticsStmt "DROP STATISTICS statement" 973 DropStatsStmt "DROP STATS statement" 974 DropTableStmt "DROP TABLE statement" 975 DropSequenceStmt "DROP SEQUENCE statement" 976 DropUserStmt "DROP USER" 977 DropRoleStmt "DROP ROLE" 978 DropViewStmt "DROP VIEW statement" 979 DropBindingStmt "DROP BINDING statement" 980 DropPolicyStmt "DROP PLACEMENT POLICY statement" 981 DeallocateStmt "Deallocate prepared statement" 982 DeleteFromStmt "DELETE FROM statement" 983 DeleteWithoutUsingStmt "Normal DELETE statement" 984 DeleteWithUsingStmt "DELETE USING statement" 985 EmptyStmt "empty statement" 986 ExecuteStmt "Execute statement" 987 ExplainStmt "EXPLAIN statement" 988 ExplainableStmt "explainable statement" 989 FlushStmt "Flush statement" 990 FlashbackTableStmt "Flashback table statement" 991 FlashbackToTimestampStmt "Flashback cluster statement" 992 FlashbackDatabaseStmt "Flashback Database statement" 993 GrantStmt "Grant statement" 994 GrantProxyStmt "Grant proxy statement" 995 GrantRoleStmt "Grant role statement" 996 InsertIntoStmt "INSERT INTO statement" 997 CallStmt "CALL statement" 998 IndexAdviseStmt "INDEX ADVISE statement" 999 ImportIntoStmt "IMPORT INTO statement" 1000 KillStmt "Kill statement" 1001 LoadDataStmt "Load data statement" 1002 LoadStatsStmt "Load statistic statement" 1003 LockStatsStmt "Lock statistic statement" 1004 UnlockStatsStmt "Unlock statistic statement" 1005 LockTablesStmt "Lock tables statement" 1006 NonTransactionalDMLStmt "Non-transactional DML statement" 1007 PlanReplayerStmt "Plan replayer statement" 1008 PreparedStmt "PreparedStmt" 1009 ProcedureProcStmt "The entrance of procedure statements which contains all kinds of statements in procedure" 1010 ProcedureStatementStmt "The normal statements in procedure, such as dml, select, set ..." 1011 SelectStmt "SELECT statement" 1012 SelectStmtWithClause "common table expression SELECT statement" 1013 RenameTableStmt "rename table statement" 1014 RenameUserStmt "rename user statement" 1015 ReplaceIntoStmt "REPLACE INTO statement" 1016 RecoverTableStmt "recover table statement" 1017 RevokeStmt "Revoke statement" 1018 RevokeRoleStmt "Revoke role statement" 1019 RollbackStmt "ROLLBACK statement" 1020 ReleaseSavepointStmt "RELEASE SAVEPOINT statement" 1021 SavepointStmt "SAVEPOINT statement" 1022 SplitRegionStmt "Split index region statement" 1023 SetStmt "Set variable statement" 1024 ChangeStmt "Change statement" 1025 SetBindingStmt "Set binding statement" 1026 SetRoleStmt "Set active role statement" 1027 SetDefaultRoleStmt "Set default statement for some user" 1028 ShowStmt "Show engines/databases/tables/user/columns/warnings/status statement" 1029 Statement "statement" 1030 TraceStmt "TRACE statement" 1031 TraceableStmt "traceable statement" 1032 TruncateTableStmt "TRUNCATE TABLE statement" 1033 UnlockTablesStmt "Unlock tables statement" 1034 UpdateStmt "UPDATE statement" 1035 SetOprStmt "Union/Except/Intersect select statement" 1036 SetOprStmtWithLimitOrderBy "Union/Except/Intersect select statement with limit and order by" 1037 SetOprStmtWoutLimitOrderBy "Union/Except/Intersect select statement without limit and order by" 1038 UseStmt "USE statement" 1039 ShutdownStmt "SHUTDOWN statement" 1040 RestartStmt "RESTART statement" 1041 CreateViewSelectOpt "Select/Union/Except/Intersect statement in CREATE VIEW ... AS SELECT" 1042 BindableStmt "Statement that can be created binding on" 1043 UpdateStmtNoWith "Update statement without CTE clause" 1044 HelpStmt "HELP statement" 1045 ShardableStmt "Shardable statement that can be used in non-transactional DMLs" 1046 PauseLoadDataStmt "PAUSE LOAD DATA JOB statement" 1047 ResumeLoadDataStmt "RESUME LOAD DATA JOB statement" 1048 CancelImportStmt "CANCEL IMPORT JOB statement" 1049 DropLoadDataStmt "DROP LOAD DATA JOB statement" 1050 ProcedureUnlabeledBlock "The statement block without label in procedure" 1051 ProcedureBlockContent "The statement block in procedure expressed with 'Begin ... End'" 1052 SimpleWhenThen "Procedure case when then" 1053 SearchWhenThen "Procedure search when then" 1054 ProcedureIfstmt "The if statement in procedure, expressed by if ... elseif .. else ... end if" 1055 procedurceElseIfs "The else block in procedure, expressed by elseif or else or nil" 1056 ProcedureIf "The if block in procedure, expressed by expr then statement procedurceElseIfs" 1057 ProcedureUnlabelLoopBlock "The loop block without label in procedure " 1058 ProcedureUnlabelLoopStmt "The loop statement in procedure, expressed by repeat/do while/loop" 1059 ProcedureCaseStmt "Case statement in procedure, expressed by `case ... when.. then ..`" 1060 ProcedureSimpleCase "The simpe case statement in procedure, expressed by `case expr when expr then statement ... end case`" 1061 ProcedureSearchedCase "The searched case statement in procedure, expressed by `case when expr then statement ... end case`" 1062 ProcedureCursorSelectStmt "The select stmt can used in procedure cursor." 1063 ProcedureOpenCur "The open cursor statement in procedure, expressed by `open ...`" 1064 ProcedureCloseCur "The close cursor statement in procedure, expressed by `close ...`" 1065 ProcedureFetchInto "The fetch into statement in procedure, expressed by `fetch ... into ...`" 1066 ProcedureHcond "The handler value statement in procedure, expressed by condition_value" 1067 ProcedurceCond "The handler code statement in procedure, expressed by code error num or `sqlstate ...`" 1068 ProcedureLabeledBlock "The statement block with label in procedure" 1069 ProcedurelabeledLoopStmt "The loop block with label in procedure" 1070 ProcedureIterate "The iterate statement in procedure, expressed by `iterate ...`" 1071 ProcedureLeave "The leave statement in procedure, expressed by `leave ...`" 1072 1073 %type <item> 1074 AdminShowSlow "Admin Show Slow statement" 1075 AdminStmtLimitOpt "Admin show ddl jobs limit option" 1076 AllOrPartitionNameList "All or partition name list" 1077 AlgorithmClause "Alter table algorithm" 1078 AlterTableSpecSingleOpt "Alter table single option" 1079 AlterTableSpec "Alter table specification" 1080 AlterTableSpecList "Alter table specification list" 1081 AlterTableSpecListOpt "Alter table specification list optional" 1082 AlterSequenceOption "Alter sequence option" 1083 AlterSequenceOptionList "Alter sequence option list" 1084 ArrayKwdOpt "Array options" 1085 AnalyzeOption "Analyze option" 1086 AnalyzeOptionList "Analyze option list" 1087 AnalyzeOptionListOpt "Optional analyze option list" 1088 AnyOrAll "Any or All for subquery" 1089 Assignment "assignment" 1090 AssignmentList "assignment list" 1091 AssignmentListOpt "assignment list opt" 1092 AuthOption "User auth option" 1093 AutoRandomOpt "Auto random option" 1094 Boolean "Boolean (0, 1, false, true)" 1095 OptionalBraces "optional braces" 1096 CastType "Cast function target type" 1097 CharsetOpt "CHARACTER SET option in LOAD DATA" 1098 ColumnDef "table column definition" 1099 ColumnDefList "table column definition list" 1100 ColumnName "column name" 1101 ColumnNameOrUserVariable "column name or user variable" 1102 ColumnNameList "column name list" 1103 ColumnNameOrUserVariableList "column name or user variable list" 1104 ColumnList "column list" 1105 ColumnNameListOpt "column name list opt" 1106 IdentList "identifier list" 1107 IdentListWithParenOpt "column name list opt with parentheses" 1108 ColumnNameOrUserVarListOpt "column name or user vairiabe list opt" 1109 ColumnNameOrUserVarListOptWithBrackets "column name or user variable list opt with brackets" 1110 ColumnSetValueList "insert statement set value by column name list" 1111 CompareOp "Compare opcode" 1112 ColumnOption "column definition option" 1113 ColumnOptionList "column definition option list" 1114 VirtualOrStored "indicate generated column is stored or not" 1115 ColumnOptionListOpt "optional column definition option list" 1116 CommonTableExpr "Common table expression" 1117 CompletionTypeWithinTransaction "overwrite system variable completion_type within current transaction" 1118 ConnectionOption "single connection options" 1119 ConnectionOptionList "connection options for CREATE USER statement" 1120 ConnectionOptions "optional connection options for CREATE USER statement" 1121 Constraint "table constraint" 1122 ConstraintElem "table constraint element" 1123 ConstraintKeywordOpt "Constraint Keyword or empty" 1124 CreateSequenceOptionListOpt "create sequence list opt" 1125 CreateTableOptionListOpt "create table option list opt" 1126 CreateTableSelectOpt "Select/Union statement in CREATE TABLE ... SELECT" 1127 DatabaseOption "CREATE Database specification" 1128 DatabaseOptionList "CREATE Database specification list" 1129 DatabaseOptionListOpt "CREATE Database specification list opt" 1130 DistinctOpt "Explicit distinct option" 1131 DefaultFalseDistinctOpt "Distinct option which defaults to false" 1132 DefaultTrueDistinctOpt "Distinct option which defaults to true" 1133 BuggyDefaultFalseDistinctOpt "Distinct option which accepts DISTINCT ALL and defaults to false" 1134 RequireClause "Encrypted connections options" 1135 RequireClauseOpt "optional Encrypted connections options" 1136 EqOpt "= or empty" 1137 EscapedTableRef "escaped table reference" 1138 ExpressionList "expression list" 1139 ExtendedPriv "Extended privileges like LOAD FROM S3 or dynamic privileges" 1140 MaxValueOrExpressionList "maxvalue or expression list" 1141 DefaultOrExpressionList "default or expression list" 1142 ExpressionListOpt "expression list opt" 1143 FetchFirstOpt "Fetch First/Next Option" 1144 FuncDatetimePrecListOpt "Function datetime precision list opt" 1145 FuncDatetimePrecList "Function datetime precision list" 1146 Field "field expression" 1147 Fields "Fields clause" 1148 FieldList "field expression list" 1149 FlushOption "Flush option" 1150 ForceOpt "Force opt" 1151 InstanceOption "Instance option" 1152 FulltextSearchModifierOpt "Fulltext modifier" 1153 PluginNameList "Plugin Name List" 1154 TableRefsClause "Table references clause" 1155 FieldItem "Field item for load data clause" 1156 FieldItemList "Field items for load data clause" 1157 FirstAndLastPartOpt "First and Last partition option" 1158 FuncDatetimePrec "Function datetime precision" 1159 GetFormatSelector "{DATE|DATETIME|TIME|TIMESTAMP}" 1160 GlobalScope "The scope of variable" 1161 StatementScope "The scope of statement" 1162 GroupByClause "GROUP BY clause" 1163 HavingClause "HAVING clause" 1164 AsOfClause "AS OF clause" 1165 AsOfClauseOpt "AS OF clause optional" 1166 HandleRange "handle range" 1167 HandleRangeList "handle range list" 1168 IfExists "If Exists" 1169 IfNotExists "If Not Exists" 1170 IgnoreOptional "IGNORE or empty" 1171 IndexHint "index hint" 1172 IndexHintList "index hint list" 1173 IndexHintListOpt "index hint list opt" 1174 IndexHintScope "index hint scope" 1175 IndexHintType "index hint type" 1176 IndexInvisible "index visible/invisible" 1177 IndexKeyTypeOpt "index key type" 1178 IndexLockAndAlgorithmOpt "index lock and algorithm" 1179 IndexNameAndTypeOpt "index name and index type" 1180 IndexNameList "index name list" 1181 IndexOption "Index Option" 1182 IndexOptionList "Index Option List or empty" 1183 IndexType "index type" 1184 IndexName "index name" 1185 IndexTypeName "index type name" 1186 IndexTypeOpt "optional index type" 1187 IndexPartSpecification "Index column name or expression" 1188 IndexPartSpecificationList "List of index column name or expression" 1189 IndexPartSpecificationListOpt "Optional list of index column name or expression" 1190 InsertValues "Rest part of INSERT/REPLACE INTO statement" 1191 IntervalExpr "Interval expression" 1192 JoinTable "join table" 1193 JoinType "join type" 1194 KillOrKillTiDB "Kill or Kill TiDB" 1195 LocationLabelList "location label name list" 1196 LikeTableWithOrWithoutParen "LIKE table_name or ( LIKE table_name )" 1197 LimitClause "LIMIT clause" 1198 LimitOption "Limit option could be integer or parameter marker." 1199 Lines "Lines clause" 1200 LinesTerminated "Lines terminated by" 1201 LoadDataSetSpecOpt "Optional load data specification" 1202 LoadDataOptionListOpt "Optional load data option list" 1203 LoadDataOptionList "Load data option list" 1204 LoadDataOption "Load data option" 1205 LoadDataSetList "Load data specifications" 1206 LoadDataSetItem "Single load data specification" 1207 LocalOpt "Local opt" 1208 LockClause "Alter table lock clause" 1209 LogTypeOpt "Optional log type used in FLUSH statements" 1210 MaxValPartOpt "MAXVALUE partition option" 1211 NullPartOpt "NULL Partition option" 1212 NumLiteral "Num/Int/Float/Decimal Literal" 1213 NoWriteToBinLogAliasOpt "NO_WRITE_TO_BINLOG alias LOCAL or empty" 1214 ObjectType "Grant statement object type" 1215 OnDuplicateKeyUpdate "ON DUPLICATE KEY UPDATE value list" 1216 OnCommitOpt "ON COMMIT DELETE |PRESERVE ROWS" 1217 DuplicateOpt "[IGNORE|REPLACE] in CREATE TABLE ... SELECT statement or LOAD DATA statement" 1218 FormatOpt "FORMAT 'SQL FILE'..." 1219 OfTablesOpt "OF table_name [, ...]" 1220 OptFull "Full or empty" 1221 OptTemporary "TEMPORARY or empty" 1222 OptOrder "Optional ordering keyword: ASC/DESC. Default to ASC" 1223 Order "Ordering keyword: ASC or DESC" 1224 OptionLevel "3 levels used by lightning config" 1225 OrderBy "ORDER BY clause" 1226 OrReplace "or replace" 1227 ByItem "BY item" 1228 OrderByOptional "Optional ORDER BY clause optional" 1229 ByList "BY list" 1230 AlterOrderItem "Alter Order item" 1231 AlterOrderList "Alter Order list" 1232 QuickOptional "QUICK or empty" 1233 PartitionDefinition "Partition definition" 1234 PartitionDefinitionList "Partition definition list" 1235 PartitionDefinitionListOpt "Partition definition list option" 1236 PartitionIntervalOpt "Partition interval option" 1237 PartitionKeyAlgorithmOpt "ALGORITHM = n option for KEY partition" 1238 PartitionMethod "Partition method" 1239 PartitionOpt "Partition option" 1240 PartitionNameList "Partition name list" 1241 PartitionNameListOpt "table partition names list optional" 1242 PartitionNumOpt "PARTITION NUM option" 1243 PartDefValuesOpt "VALUES {LESS THAN {(expr | value_list) | MAXVALUE} | IN {value_list}" 1244 PartDefOptionList "PartDefOption list" 1245 PartDefOption "COMMENT [=] xxx | TABLESPACE [=] tablespace_name | ENGINE [=] xxx" 1246 PasswordOrLockOption "Single password or lock option for create user statement" 1247 PasswordOrLockOptionList "Password or lock options for create user statement" 1248 PasswordOrLockOptions "Optional password or lock options for create user statement" 1249 PlanReplayerDumpOpt "Plan Replayer Dump option" 1250 CommentOrAttributeOption "Optional comment or attribute option for CREATE/ALTER USER statements" 1251 ColumnPosition "Column position [First|After ColumnName]" 1252 PrepareSQL "Prepare statement sql string" 1253 Priority "Statement priority" 1254 PriorityOpt "Statement priority option" 1255 PrivElem "Privilege element" 1256 PrivLevel "Privilege scope" 1257 PrivType "Privilege type" 1258 ReferDef "Reference definition" 1259 OnDelete "ON DELETE clause" 1260 OnUpdate "ON UPDATE clause" 1261 OnDeleteUpdateOpt "optional ON DELETE and UPDATE clause" 1262 OptGConcatSeparator "optional GROUP_CONCAT SEPARATOR" 1263 ReferOpt "reference option" 1264 ReorganizePartitionRuleOpt "optional reorganize partition partition list and definitions" 1265 RequireList "require list for tls options" 1266 RequireListElement "require list element for tls option" 1267 ResourceGroupNameOption "resource group name for user" 1268 Rolename "Rolename" 1269 RolenameComposed "Rolename that composed with more than 1 symbol" 1270 RolenameList "RolenameList" 1271 RolenameWithoutIdent "Rolename except identifier" 1272 RoleOrPrivElem "Element that may be a Rolename or PrivElem" 1273 RoleOrPrivElemList "RoleOrPrivElem list" 1274 RoleSpec "Rolename and auth option" 1275 RoleSpecList "Rolename and auth option list" 1276 RowFormat "Row format option" 1277 RowValue "Row value" 1278 RowStmt "Row constructor" 1279 SelectLockOpt "SELECT lock options" 1280 SelectStmtSQLCache "SELECT statement optional SQL_CAHCE/SQL_NO_CACHE" 1281 SelectStmtFieldList "SELECT statement field list" 1282 SelectStmtLimit "SELECT statement LIMIT clause" 1283 SelectStmtLimitOpt "SELECT statement optional LIMIT clause" 1284 SelectStmtOpt "Select statement option" 1285 SelectStmtOpts "Select statement options" 1286 SelectStmtOptsList "Select statement options list" 1287 SelectStmtBasic "SELECT statement from constant value" 1288 SelectStmtFromDualTable "SELECT statement from dual table" 1289 SelectStmtFromTable "SELECT statement from table" 1290 SelectStmtGroup "SELECT statement optional GROUP BY clause" 1291 SelectStmtIntoOption "SELECT statement into clause" 1292 SequenceOption "Create sequence option" 1293 SequenceOptionList "Create sequence option list" 1294 SetRoleOpt "Set role options" 1295 SetDefaultRoleOpt "Set default role options" 1296 SetOpr "Set operator contain UNION, EXCEPT and INTERSECT" 1297 SetOprClause "Union/Except/Intersect select clause" 1298 SetOprClauseList "Union/Except/Intersect select clause list" 1299 ShowTargetFilterable "Show target that can be filtered by WHERE or LIKE" 1300 ShowTableAliasOpt "Show table alias option" 1301 ShowLikeOrWhereOpt "Show like or where clause option" 1302 ShowPlacementTarget "Show placement target" 1303 ShowProfileArgsOpt "Show profile args option" 1304 ShowProfileTypesOpt "Show profile types option" 1305 ShowProfileType "Show profile type" 1306 ShowProfileTypes "Show profile types" 1307 SplitOption "Split Option" 1308 SplitSyntaxOption "Split syntax Option" 1309 Starting "Starting by" 1310 StatementList "statement list" 1311 StatsPersistentVal "stats_persistent value" 1312 StatsType "stats type value" 1313 BindingStatusType "binding status type value" 1314 StringList "string list" 1315 SubPartDefinition "SubPartition definition" 1316 SubPartDefinitionList "SubPartition definition list" 1317 SubPartDefinitionListOpt "SubPartition definition list optional" 1318 SubPartitionMethod "SubPartition method" 1319 SubPartitionOpt "SubPartition option" 1320 SubPartitionNumOpt "SubPartition NUM option" 1321 TableAliasRefList "table alias reference list" 1322 TableAsName "table alias name" 1323 TableAsNameOpt "table alias name optional" 1324 TableElement "table definition element" 1325 TableElementList "table definition element list" 1326 TableElementListOpt "table definition element list optional" 1327 TableFactor "table factor" 1328 TableLock "Table name and lock type" 1329 TableLockList "Table lock list" 1330 TableName "Table name" 1331 TableNameOptWild "Table name with optional wildcard" 1332 TableNameList "Table name list" 1333 TableNameListOpt "Table name list opt" 1334 TableNameListOpt2 "Optional table name list with a preceding TABLE" 1335 TableOption "create table option" 1336 TableOptionList "create table option list" 1337 TableRef "table reference" 1338 TableRefs "table references" 1339 TableSampleOpt "table sample clause optional" 1340 TableSampleMethodOpt "table sample method optional" 1341 TableSampleUnitOpt "table sample unit optional" 1342 TableToTable "rename table to table" 1343 TableToTableList "rename table to table by list" 1344 TextString "text string item" 1345 TextStringList "text string list" 1346 TimeUnit "Time unit for 'DATE_ADD', 'DATE_SUB', 'ADDDATE', 'SUBDATE', 'EXTRACT'" 1347 TimestampUnit "Time unit for 'TIMESTAMPADD' and 'TIMESTAMPDIFF'" 1348 LockType "Table locks type" 1349 TransactionChar "Transaction characteristic" 1350 TransactionChars "Transaction characteristic list" 1351 TrimDirection "Trim string direction" 1352 SetOprOpt "Union/Except/Intersect Option(empty/ALL/DISTINCT)" 1353 Username "Username" 1354 UsernameList "UsernameList" 1355 UserSpec "Username and auth option" 1356 UserSpecList "Username and auth option list" 1357 UserVariableList "User defined variable name list" 1358 UserToUser "rename user to user" 1359 UserToUserList "rename user to user by list" 1360 UsingRoles "UsingRoles is role option for SHOW GRANT" 1361 Values "values" 1362 ValuesList "values list" 1363 ValuesOpt "values optional" 1364 ValuesStmtList "VALUES statement field list" 1365 VariableAssignment "set variable value" 1366 VariableAssignmentList "set variable value list" 1367 ViewAlgorithm "view algorithm" 1368 ViewCheckOption "view check option" 1369 ViewDefiner "view definer" 1370 ViewName "view name" 1371 ViewFieldList "create view statement field list" 1372 ViewSQLSecurity "view sql security" 1373 WhereClause "WHERE clause" 1374 WhereClauseOptional "Optional WHERE clause" 1375 WhenClause "When clause" 1376 WhenClauseList "When clause list" 1377 WithClustered "With Clustered Index Enabled" 1378 WithClause "With Clause" 1379 WithList "With list" 1380 WithReadLockOpt "With Read Lock opt" 1381 WithGrantOptionOpt "With Grant Option opt" 1382 WithValidation "with validation" 1383 WithValidationOpt "optional with validation" 1384 Writeable "Table writeable status" 1385 ElseOpt "Optional else clause" 1386 Type "Types" 1387 OptExistingWindowName "Optional existing WINDOW name" 1388 OptFromFirstLast "Optional FROM FIRST/LAST" 1389 OptLLDefault "Optional LEAD/LAG default" 1390 OptLeadLagInfo "Optional LEAD/LAG info" 1391 OptNullTreatment "Optional NULL treatment" 1392 OptPartitionClause "Optional PARTITION clause" 1393 OptWild "Optional Wildcard" 1394 OptWindowOrderByClause "Optional ORDER BY clause in WINDOW" 1395 OptWindowFrameClause "Optional FRAME clause in WINDOW" 1396 OptWindowingClause "Optional OVER clause" 1397 WindowingClause "OVER clause" 1398 WindowClauseOptional "Optional WINDOW clause" 1399 WindowDefinitionList "WINDOW definition list" 1400 WindowDefinition "WINDOW definition" 1401 WindowFrameUnits "WINDOW frame units" 1402 WindowFrameBetween "WINDOW frame between" 1403 WindowFrameBound "WINDOW frame bound" 1404 WindowFrameExtent "WINDOW frame extent" 1405 WindowFrameStart "WINDOW frame start" 1406 WindowName "WINDOW name" 1407 WindowNameOrSpec "WINDOW name or spec" 1408 WindowSpec "WINDOW spec" 1409 WindowSpecDetails "WINDOW spec details" 1410 WithRollupClause "With rollup clause" 1411 BetweenOrNotOp "Between predicate" 1412 IsOrNotOp "Is predicate" 1413 InOrNotOp "In predicate" 1414 LikeOrNotOp "Like predicate" 1415 IlikeOrNotOp "Ilike predicate" 1416 RegexpOrNotOp "Regexp predicate" 1417 NumericType "Numeric types" 1418 IntegerType "Integer Types types" 1419 BooleanType "Boolean Types types" 1420 FixedPointType "Exact value types" 1421 FloatingPointType "Approximate value types" 1422 BitValueType "bit value types" 1423 StringType "String types" 1424 BlobType "Blob types" 1425 TextType "Text types" 1426 DateAndTimeType "Date and Time types" 1427 OptFieldLen "Field length or empty" 1428 FieldLen "Field length" 1429 FieldOpts "Field type definition option list" 1430 FieldOpt "Field type definition option" 1431 FloatOpt "Floating-point type option" 1432 Precision "Floating-point precision option" 1433 OptBinary "Optional BINARY" 1434 OptBinMod "Optional BINARY mode" 1435 OptCharsetWithOptBinary "Optional BINARY or ASCII or UNICODE or BYTE" 1436 IgnoreLines "Ignore num(int) lines" 1437 Int64Num "a number that can be safely converted to int64" 1438 NUM "A number" 1439 NumList "Some numbers" 1440 LengthNum "Field length num(uint64)" 1441 SignedNum "Signed num(int64)" 1442 TableOptimizerHints "Table level optimizer hints" 1443 TableOptimizerHintsOpt "Table level optimizer hints option" 1444 EnforcedOrNot "{ENFORCED|NOT ENFORCED}" 1445 EnforcedOrNotOpt "Optional {ENFORCED|NOT ENFORCED}" 1446 EnforcedOrNotOrNotNullOpt "{[ENFORCED|NOT ENFORCED|NOT NULL]}" 1447 Match "[MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]" 1448 MatchOpt "optional MATCH clause" 1449 MaxMinutesOpt "MAX_MINUTES num(int)" 1450 MaxIndexNumOpt "MAX_IDXNUM clause" 1451 PerTable "Max index number PER_TABLE" 1452 PerDB "Max index number PER_DB" 1453 BRIETables "List of tables or databases for BRIE statements" 1454 DBNameList "List of database names" 1455 BRIEOption "Single BRIE option" 1456 BRIEOptions "List of BRIE options" 1457 BRIEIntegerOptionName "Name of a BRIE option which takes an integer as input" 1458 BRIEBooleanOptionName "Name of a BRIE option which takes a boolean as input" 1459 BRIEStringOptionName "Name of a BRIE option which takes a string as input" 1460 BRIEKeywordOptionName "Name of a BRIE option which takes a case-insensitive string as input" 1461 PlacementPolicyOption "Anonymous or placement policy option" 1462 DirectPlacementOption "Subset of anonymous or direct placement option" 1463 PlacementOptionList "Anomymous or direct placement option list" 1464 DirectResourceGroupBackgroundOption "Subset of direct resource group background option" 1465 DirectResourceGroupRunawayOption "Subset of anonymous or direct resource group runaway option" 1466 ResourceGroupBackgroundOptionList "Direct resource group background option list" 1467 ResourceGroupRunawayActionOption "Resource group runaway action option" 1468 ResourceGroupRunawayWatchOption "Resource group runaway watch option" 1469 ResourceGroupRunawayOptionList "Anomymous or direct resource group runaway option list" 1470 WatchDurationOption "Runaway watch duration option" 1471 DirectResourceGroupOption "Subset of anonymous or direct resource group option" 1472 ResourceGroupOptionList "Anomymous or direct resource group option list" 1473 ResourceGroupPriorityOption "Resource group priority option" 1474 DynamicCalibrateResourceOption "Dynamic resource calibrate option" 1475 CalibrateOption "Dynamic or static calibrate option" 1476 DynamicCalibrateOptionList "Anomymous or direct dynamic resource calibrate option list" 1477 CalibrateResourceWorkloadOption "Calibrate Resource workload option" 1478 QueryWatchOptionList "Query watch option list" 1479 QueryWatchOption "Query watch option" 1480 QueryWatchTextOption "Query watch text option" 1481 AttributesOpt "Attributes options" 1482 AllColumnsOrPredicateColumnsOpt "all columns or predicate columns option" 1483 StatsOptionsOpt "Stats options" 1484 DryRunOptions "Dry run options" 1485 OptionalShardColumn "Optional shard column" 1486 SpOptInout "Optional procedure param type" 1487 OptSpPdparams "Optional procedure param list" 1488 SpPdparams "Procedure params" 1489 SpPdparam "Procedure param" 1490 ProcedureOptDefault "Optional procedure variable default value" 1491 ProcedureProcStmts "Procedure statement list" 1492 ProcedureProcStmt1s "One more procedure statement" 1493 ProcedureDecl "Procedure variable statement" 1494 ProcedureDecls "Procedure variable statements" 1495 ProcedureDeclsOpt "Optional procedure variable statements" 1496 ProcedureDeclIdents "Procedure variable name identifiers" 1497 SimpleWhenThenList "Procedure case WhenThen list" 1498 SearchedWhenThenList "Procedure search WhenThen list" 1499 ElseCaseOpt "Optional procedure else statement, expressed by `else .../nil`" 1500 ProcedureFetchList "Procedure fetch into variables" 1501 ProcedureHandlerType "Procedure handler operation type" 1502 ProcedureHcondList "Procedure handler condition value list" 1503 1504 %type <ident> 1505 AsOpt "AS or EmptyString" 1506 KeyOrIndex "{KEY|INDEX}" 1507 ColumnKeywordOpt "Column keyword or empty" 1508 PrimaryOpt "Optional primary keyword" 1509 NowSym "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP" 1510 NowSymFunc "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP/NOW" 1511 CurdateSym "CURDATE or CURRENT_DATE" 1512 DefaultKwdOpt "optional DEFAULT keyword" 1513 DatabaseSym "DATABASE or SCHEMA" 1514 ExplainSym "EXPLAIN or DESCRIBE or DESC" 1515 RegexpSym "REGEXP or RLIKE" 1516 IntoOpt "INTO or EmptyString" 1517 ValueSym "Value or Values" 1518 NotSym "Not token" 1519 Char "{CHAR|CHARACTER}" 1520 NChar "{NCHAR|NATIONAL CHARACTER|NATIONAL CHAR}" 1521 Varchar "{VARCHAR|VARCHARACTER|CHARACTER VARYING|CHAR VARYING}" 1522 NVarchar "{NATIONAL VARCHAR|NATIONAL VARCHARACTER|NVARCHAR|NCHAR VARCHAR|NATIONAL CHARACTER VARYING|NATIONAL CHAR VARYING|NCHAR VARYING}" 1523 Year "{YEAR|SQL_TSI_YEAR}" 1524 DeallocateSym "Deallocate or drop" 1525 OuterOpt "optional OUTER clause" 1526 CrossOpt "Cross join option" 1527 TablesTerminalSym "{TABLE|TABLES}" 1528 IsolationLevel "Isolation level" 1529 ShowIndexKwd "Show index/indexs/key keyword" 1530 DistinctKwd "DISTINCT/DISTINCTROW keyword" 1531 FromOrIn "From or In" 1532 OptTable "Optional table keyword" 1533 OptInteger "Optional Integer keyword" 1534 CharsetKw "charset or charater set" 1535 CommaOpt "optional comma" 1536 logAnd "logical and operator" 1537 logOr "logical or operator" 1538 LinearOpt "linear or empty" 1539 FieldsOrColumns "Fields or columns" 1540 StorageMedia "{DISK|MEMORY|DEFAULT}" 1541 EncryptionOpt "Encryption option 'Y' or 'N'" 1542 FirstOrNext "FIRST or NEXT" 1543 RowOrRows "ROW or ROWS" 1544 1545 %type <ident> 1546 Identifier "identifier or unreserved keyword" 1547 NotKeywordToken "Tokens not mysql keyword but treated specially" 1548 UnReservedKeyword "MySQL unreserved keywords" 1549 TiDBKeyword "TiDB added keywords" 1550 FunctionNameConflict "Built-in function call names which are conflict with keywords" 1551 FunctionNameOptionalBraces "Function with optional braces, all of them are reserved keywords." 1552 FunctionNameDatetimePrecision "Function with optional datetime precision, all of them are reserved keywords." 1553 FunctionNameDateArith "Date arith function call names (date_add or date_sub)" 1554 FunctionNameDateArithMultiForms "Date arith function call names (adddate or subdate)" 1555 VariableName "A simple Identifier like xx or the xx.xx form" 1556 ConfigItemName "A config item like aa or aa.bb or aa.bb-cc.dd" 1557 AuthString "Password string value" 1558 AuthPlugin "Authentication plugin name" 1559 CharsetName "Character set name" 1560 CollationName "Collation name" 1561 ColumnFormat "Column format" 1562 DBName "Database Name" 1563 PolicyName "Placement Policy Name" 1564 ResourceGroupName "Resource Group Name" 1565 ExplainFormatType "explain format type" 1566 FieldAsName "Field alias name" 1567 FieldAsNameOpt "Field alias name opt" 1568 FieldTerminator "Field terminator" 1569 FlashbackToNewName "Flashback to new name" 1570 HashString "Hashed string" 1571 LikeOrIlikeEscapeOpt "like or ilike escape option" 1572 OptCharset "Optional Character setting" 1573 OptCollate "Optional Collate setting" 1574 PasswordOpt "Password option" 1575 RoleNameString "role name string" 1576 ShowDatabaseNameOpt "Show tables/columns statement database name option" 1577 StringName "string literal or identifier" 1578 StringNameOrBRIEOptionKeyword "string literal or identifier or keyword used for BRIE options" 1579 Symbol "Constraint Symbol" 1580 ProcedurceLabelOpt "Optional Procedure label name" 1581 1582 %precedence empty 1583 %precedence as 1584 %precedence placement 1585 %precedence lowerThanSelectOpt 1586 %precedence sqlBufferResult 1587 %precedence sqlBigResult 1588 %precedence sqlSmallResult 1589 %precedence sqlCache sqlNoCache 1590 %precedence next 1591 %precedence lowerThanValueKeyword 1592 %precedence value 1593 %precedence lowerThanWith 1594 %precedence with 1595 %precedence lowerThanStringLitToken 1596 %precedence stringLit 1597 %precedence lowerThanSetKeyword 1598 %precedence set 1599 %precedence selectKwd 1600 %precedence lowerThanSelectStmt 1601 %precedence lowerThanInsertValues 1602 %precedence insertValues 1603 %precedence lowerThanCreateTableSelect 1604 %precedence createTableSelect 1605 %precedence lowerThanCharsetKwd 1606 %precedence charsetKwd 1607 %precedence lowerThanKey 1608 %precedence key 1609 %precedence lowerThanLocal 1610 %precedence local 1611 %precedence lowerThanRemove 1612 %precedence remove 1613 %precedence lowerThenOrder 1614 %precedence order 1615 %precedence lowerThanFunction 1616 %precedence function 1617 1618 /* A dummy token to force the priority of TableRef production in a join. */ 1619 %left tableRefPriority 1620 %precedence lowerThanParenthese 1621 %right '(' 1622 %left ')' 1623 %precedence higherThanParenthese 1624 %left join straightJoin inner cross left right full natural 1625 %precedence lowerThanOn 1626 %precedence on using 1627 %right assignmentEq 1628 %left pipes or pipesAsOr 1629 %left xor 1630 %left andand and 1631 %left between 1632 %precedence lowerThanEq 1633 %left eq ge le neq neqSynonym '>' '<' is like ilike in 1634 %left '|' 1635 %left '&' 1636 %left rsh lsh 1637 %left '-' '+' 1638 %left '*' '/' '%' div mod 1639 %left '^' 1640 %left '~' neg 1641 %precedence lowerThanNot 1642 %right not not2 1643 %right collate 1644 %left interval 1645 %right encryption 1646 %left labels 1647 %precedence quick 1648 %precedence escape 1649 %precedence lowerThanComma 1650 %precedence ',' 1651 %precedence higherThanComma 1652 1653 %start Start 1654 1655 %% 1656 1657 Start: 1658 StatementList 1659 1660 /**************************************AlterTableStmt*************************************** 1661 * See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html 1662 *******************************************************************************************/ 1663 AlterTableStmt: 1664 "ALTER" IgnoreOptional "TABLE" TableName AlterTableSpecListOpt AlterTableSpecSingleOpt 1665 { 1666 specs := $5.([]*ast.AlterTableSpec) 1667 if $6 != nil { 1668 specs = append(specs, $6.(*ast.AlterTableSpec)) 1669 } 1670 $$ = &ast.AlterTableStmt{ 1671 Table: $4.(*ast.TableName), 1672 Specs: specs, 1673 } 1674 } 1675 | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList AnalyzeOptionListOpt 1676 { 1677 $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, PartitionNames: $7.([]model.CIStr), AnalyzeOpts: $8.([]ast.AnalyzeOpt)} 1678 } 1679 | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt 1680 { 1681 $$ = &ast.AnalyzeTableStmt{ 1682 TableNames: []*ast.TableName{$4.(*ast.TableName)}, 1683 PartitionNames: $7.([]model.CIStr), 1684 IndexNames: $9.([]model.CIStr), 1685 IndexFlag: true, 1686 AnalyzeOpts: $10.([]ast.AnalyzeOpt), 1687 } 1688 } 1689 | "ALTER" IgnoreOptional "TABLE" TableName "COMPACT" 1690 { 1691 $$ = &ast.CompactTableStmt{ 1692 Table: $4.(*ast.TableName), 1693 ReplicaKind: ast.CompactReplicaKindAll, 1694 } 1695 } 1696 | "ALTER" IgnoreOptional "TABLE" TableName "COMPACT" "TIFLASH" "REPLICA" 1697 { 1698 $$ = &ast.CompactTableStmt{ 1699 Table: $4.(*ast.TableName), 1700 ReplicaKind: ast.CompactReplicaKindTiFlash, 1701 } 1702 } 1703 | "ALTER" IgnoreOptional "TABLE" TableName "COMPACT" "PARTITION" PartitionNameList 1704 { 1705 $$ = &ast.CompactTableStmt{ 1706 Table: $4.(*ast.TableName), 1707 PartitionNames: $7.([]model.CIStr), 1708 ReplicaKind: ast.CompactReplicaKindAll, 1709 } 1710 } 1711 | "ALTER" IgnoreOptional "TABLE" TableName "COMPACT" "PARTITION" PartitionNameList "TIFLASH" "REPLICA" 1712 { 1713 $$ = &ast.CompactTableStmt{ 1714 Table: $4.(*ast.TableName), 1715 PartitionNames: $7.([]model.CIStr), 1716 ReplicaKind: ast.CompactReplicaKindTiFlash, 1717 } 1718 } 1719 1720 ResourceGroupOptionList: 1721 DirectResourceGroupOption 1722 { 1723 $$ = []*ast.ResourceGroupOption{$1.(*ast.ResourceGroupOption)} 1724 } 1725 | ResourceGroupOptionList DirectResourceGroupOption 1726 { 1727 if !ast.CheckAppend($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption)) { 1728 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 1729 return 1 1730 } 1731 $$ = append($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption)) 1732 } 1733 | ResourceGroupOptionList ',' DirectResourceGroupOption 1734 { 1735 if !ast.CheckAppend($1.([]*ast.ResourceGroupOption), $3.(*ast.ResourceGroupOption)) { 1736 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 1737 return 1 1738 } 1739 $$ = append($1.([]*ast.ResourceGroupOption), $3.(*ast.ResourceGroupOption)) 1740 } 1741 1742 ResourceGroupPriorityOption: 1743 "LOW" 1744 { 1745 $$ = uint64(1) 1746 } 1747 | "MEDIUM" 1748 { 1749 $$ = uint64(8) 1750 } 1751 | "HIGH" 1752 { 1753 $$ = uint64(16) 1754 } 1755 1756 ResourceGroupRunawayOptionList: 1757 DirectResourceGroupRunawayOption 1758 { 1759 $$ = []*ast.ResourceGroupRunawayOption{$1.(*ast.ResourceGroupRunawayOption)} 1760 } 1761 | ResourceGroupRunawayOptionList DirectResourceGroupRunawayOption 1762 { 1763 if !ast.CheckRunawayAppend($1.([]*ast.ResourceGroupRunawayOption), $2.(*ast.ResourceGroupRunawayOption)) { 1764 yylex.AppendError(yylex.Errorf("Dupliated runaway options specified")) 1765 return 1 1766 } 1767 $$ = append($1.([]*ast.ResourceGroupRunawayOption), $2.(*ast.ResourceGroupRunawayOption)) 1768 } 1769 | ResourceGroupRunawayOptionList ',' DirectResourceGroupRunawayOption 1770 { 1771 if !ast.CheckRunawayAppend($1.([]*ast.ResourceGroupRunawayOption), $3.(*ast.ResourceGroupRunawayOption)) { 1772 yylex.AppendError(yylex.Errorf("Dupliated runaway options specified")) 1773 return 1 1774 } 1775 $$ = append($1.([]*ast.ResourceGroupRunawayOption), $3.(*ast.ResourceGroupRunawayOption)) 1776 } 1777 1778 ResourceGroupRunawayWatchOption: 1779 "EXACT" 1780 { 1781 $$ = int32(model.WatchExact) 1782 } 1783 | "SIMILAR" 1784 { 1785 $$ = int32(model.WatchSimilar) 1786 } 1787 | "PLAN" 1788 { 1789 $$ = int32(model.WatchPlan) 1790 } 1791 1792 ResourceGroupRunawayActionOption: 1793 "DRYRUN" 1794 { 1795 $$ = int32(model.RunawayActionDryRun) 1796 } 1797 | "COOLDOWN" 1798 { 1799 $$ = int32(model.RunawayActionCooldown) 1800 } 1801 | "KILL" 1802 { 1803 $$ = int32(model.RunawayActionKill) 1804 } 1805 1806 DirectResourceGroupRunawayOption: 1807 "EXEC_ELAPSED" EqOpt stringLit 1808 { 1809 _, err := time.ParseDuration($3) 1810 if err != nil { 1811 yylex.AppendError(yylex.Errorf("The EXEC_ELAPSED option is not a valid duration: %s", err.Error())) 1812 return 1 1813 } 1814 $$ = &ast.ResourceGroupRunawayOption{Tp: ast.RunawayRule, StrValue: $3} 1815 } 1816 | "ACTION" EqOpt ResourceGroupRunawayActionOption 1817 { 1818 $$ = &ast.ResourceGroupRunawayOption{Tp: ast.RunawayAction, IntValue: $3.(int32)} 1819 } 1820 | "WATCH" EqOpt ResourceGroupRunawayWatchOption WatchDurationOption 1821 { 1822 dur := strings.ToLower($4.(string)) 1823 if dur == "unlimited" { 1824 dur = "" 1825 } 1826 if len(dur) > 0 { 1827 _, err := time.ParseDuration(dur) 1828 if err != nil { 1829 yylex.AppendError(yylex.Errorf("The WATCH DURATION option is not a valid duration: %s", err.Error())) 1830 return 1 1831 } 1832 } 1833 $$ = &ast.ResourceGroupRunawayOption{Tp: ast.RunawayWatch, StrValue: dur, IntValue: $3.(int32)} 1834 } 1835 1836 WatchDurationOption: 1837 { 1838 $$ = "" 1839 } 1840 | "DURATION" EqOpt stringLit 1841 { 1842 $$ = $3 1843 } 1844 | "DURATION" EqOpt "UNLIMITED" 1845 { 1846 $$ = "" 1847 } 1848 1849 DirectResourceGroupOption: 1850 "RU_PER_SEC" EqOpt LengthNum 1851 { 1852 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceRURate, UintValue: $3.(uint64)} 1853 } 1854 | "PRIORITY" EqOpt ResourceGroupPriorityOption 1855 { 1856 $$ = &ast.ResourceGroupOption{Tp: ast.ResourcePriority, UintValue: $3.(uint64)} 1857 } 1858 | "BURSTABLE" 1859 { 1860 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceBurstableOpiton, BoolValue: true} 1861 } 1862 | "BURSTABLE" EqOpt Boolean 1863 { 1864 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceBurstableOpiton, BoolValue: $3.(bool)} 1865 } 1866 | "QUERY_LIMIT" EqOpt '(' ResourceGroupRunawayOptionList ')' 1867 { 1868 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupRunaway, RunawayOptionList: $4.([]*ast.ResourceGroupRunawayOption)} 1869 } 1870 | "QUERY_LIMIT" EqOpt '(' ')' 1871 { 1872 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupRunaway, RunawayOptionList: nil} 1873 } 1874 | "QUERY_LIMIT" EqOpt "NULL" 1875 { 1876 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupRunaway, RunawayOptionList: nil} 1877 } 1878 | "BACKGROUND" EqOpt '(' ResourceGroupBackgroundOptionList ')' 1879 { 1880 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupBackground, BackgroundOptions: $4.([]*ast.ResourceGroupBackgroundOption)} 1881 } 1882 | "BACKGROUND" EqOpt '(' ')' 1883 { 1884 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupBackground, BackgroundOptions: nil} 1885 } 1886 | "BACKGROUND" EqOpt "NULL" 1887 { 1888 $$ = &ast.ResourceGroupOption{Tp: ast.ResourceGroupBackground, BackgroundOptions: nil} 1889 } 1890 1891 ResourceGroupBackgroundOptionList: 1892 DirectResourceGroupBackgroundOption 1893 { 1894 $$ = []*ast.ResourceGroupBackgroundOption{$1.(*ast.ResourceGroupBackgroundOption)} 1895 } 1896 | ResourceGroupBackgroundOptionList DirectResourceGroupBackgroundOption 1897 { 1898 if !ast.CheckBackgroundAppend($1.([]*ast.ResourceGroupBackgroundOption), $2.(*ast.ResourceGroupBackgroundOption)) { 1899 yylex.AppendError(yylex.Errorf("Dupliated background options specified")) 1900 return 1 1901 } 1902 $$ = append($1.([]*ast.ResourceGroupBackgroundOption), $2.(*ast.ResourceGroupBackgroundOption)) 1903 } 1904 | ResourceGroupBackgroundOptionList ',' DirectResourceGroupBackgroundOption 1905 { 1906 if !ast.CheckBackgroundAppend($1.([]*ast.ResourceGroupBackgroundOption), $3.(*ast.ResourceGroupBackgroundOption)) { 1907 yylex.AppendError(yylex.Errorf("Dupliated background options specified")) 1908 return 1 1909 } 1910 $$ = append($1.([]*ast.ResourceGroupBackgroundOption), $3.(*ast.ResourceGroupBackgroundOption)) 1911 } 1912 1913 DirectResourceGroupBackgroundOption: 1914 "TASK_TYPES" EqOpt stringLit 1915 { 1916 $$ = &ast.ResourceGroupBackgroundOption{Type: ast.BackgroundOptionTaskNames, StrValue: $3} 1917 } 1918 1919 PlacementOptionList: 1920 DirectPlacementOption 1921 { 1922 $$ = []*ast.PlacementOption{$1.(*ast.PlacementOption)} 1923 } 1924 | PlacementOptionList DirectPlacementOption 1925 { 1926 $$ = append($1.([]*ast.PlacementOption), $2.(*ast.PlacementOption)) 1927 } 1928 | PlacementOptionList ',' DirectPlacementOption 1929 { 1930 $$ = append($1.([]*ast.PlacementOption), $3.(*ast.PlacementOption)) 1931 } 1932 1933 DirectPlacementOption: 1934 "PRIMARY_REGION" EqOpt stringLit 1935 { 1936 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionPrimaryRegion, StrValue: $3} 1937 } 1938 | "REGIONS" EqOpt stringLit 1939 { 1940 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionRegions, StrValue: $3} 1941 } 1942 | "FOLLOWERS" EqOpt LengthNum 1943 { 1944 cnt := $3.(uint64) 1945 if cnt == 0 { 1946 yylex.AppendError(yylex.Errorf("FOLLOWERS must be positive")) 1947 return 1 1948 } 1949 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionFollowerCount, UintValue: cnt} 1950 } 1951 | "VOTERS" EqOpt LengthNum 1952 { 1953 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionVoterCount, UintValue: $3.(uint64)} 1954 } 1955 | "LEARNERS" EqOpt LengthNum 1956 { 1957 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionLearnerCount, UintValue: $3.(uint64)} 1958 } 1959 | "SCHEDULE" EqOpt stringLit 1960 { 1961 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionSchedule, StrValue: $3} 1962 } 1963 | "CONSTRAINTS" EqOpt stringLit 1964 { 1965 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionConstraints, StrValue: $3} 1966 } 1967 | "LEADER_CONSTRAINTS" EqOpt stringLit 1968 { 1969 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionLeaderConstraints, StrValue: $3} 1970 } 1971 | "FOLLOWER_CONSTRAINTS" EqOpt stringLit 1972 { 1973 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionFollowerConstraints, StrValue: $3} 1974 } 1975 | "VOTER_CONSTRAINTS" EqOpt stringLit 1976 { 1977 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionVoterConstraints, StrValue: $3} 1978 } 1979 | "LEARNER_CONSTRAINTS" EqOpt stringLit 1980 { 1981 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionLearnerConstraints, StrValue: $3} 1982 } 1983 | "SURVIVAL_PREFERENCES" EqOpt stringLit 1984 { 1985 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionSurvivalPreferences, StrValue: $3} 1986 } 1987 1988 PlacementPolicyOption: 1989 "PLACEMENT" "POLICY" EqOpt stringLit 1990 { 1991 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionPolicy, StrValue: $4} 1992 } 1993 | "PLACEMENT" "POLICY" EqOpt PolicyName 1994 { 1995 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionPolicy, StrValue: $4} 1996 } 1997 | "PLACEMENT" "POLICY" EqOpt "DEFAULT" 1998 { 1999 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionPolicy, StrValue: $4} 2000 } 2001 | "PLACEMENT" "POLICY" "SET" "DEFAULT" 2002 { 2003 $$ = &ast.PlacementOption{Tp: ast.PlacementOptionPolicy, StrValue: $4} 2004 } 2005 2006 AttributesOpt: 2007 "ATTRIBUTES" EqOpt "DEFAULT" 2008 { 2009 $$ = &ast.AttributesSpec{Default: true} 2010 } 2011 | "ATTRIBUTES" EqOpt stringLit 2012 { 2013 $$ = &ast.AttributesSpec{Default: false, Attributes: $3} 2014 } 2015 2016 StatsOptionsOpt: 2017 "STATS_OPTIONS" EqOpt "DEFAULT" 2018 { 2019 $$ = &ast.StatsOptionsSpec{Default: true} 2020 } 2021 | "STATS_OPTIONS" EqOpt stringLit 2022 { 2023 $$ = &ast.StatsOptionsSpec{Default: false, StatsOptions: $3} 2024 } 2025 2026 // Some spec can only have one, but not in a list 2027 AlterTableSpecSingleOpt: 2028 PartitionOpt 2029 { 2030 if $1 != nil { 2031 $$ = &ast.AlterTableSpec{ 2032 Tp: ast.AlterTablePartition, 2033 Partition: $1.(*ast.PartitionOptions), 2034 } 2035 } else { 2036 $$ = nil 2037 } 2038 } 2039 | "REMOVE" "PARTITIONING" 2040 { 2041 $$ = &ast.AlterTableSpec{ 2042 Tp: ast.AlterTableRemovePartitioning, 2043 } 2044 } 2045 | "REORGANIZE" "PARTITION" NoWriteToBinLogAliasOpt ReorganizePartitionRuleOpt 2046 { 2047 ret := $4.(*ast.AlterTableSpec) 2048 ret.NoWriteToBinlog = $3.(bool) 2049 $$ = ret 2050 } 2051 | "SPLIT" "MAXVALUE" "PARTITION" "LESS" "THAN" '(' BitExpr ')' 2052 { 2053 partitionMethod := ast.PartitionMethod{Expr: $7} 2054 startOffset := parser.yyVAL.offset 2055 endOffset := parser.yylval.offset 2056 partitionMethod.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 2057 partitionMethod.SetOriginTextPosition(startOffset) 2058 $$ = &ast.AlterTableSpec{ 2059 Tp: ast.AlterTableReorganizeLastPartition, 2060 Partition: &ast.PartitionOptions{PartitionMethod: partitionMethod}, 2061 } 2062 } 2063 | "MERGE" "FIRST" "PARTITION" "LESS" "THAN" '(' BitExpr ')' 2064 { 2065 partitionMethod := ast.PartitionMethod{Expr: $7} 2066 startOffset := parser.yyVAL.offset 2067 endOffset := parser.yylval.offset 2068 partitionMethod.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 2069 // Needed for replacing syntactic sugar with generated partitioning definition string 2070 partitionMethod.SetOriginTextPosition(startOffset) 2071 $$ = &ast.AlterTableSpec{ 2072 Tp: ast.AlterTableReorganizeFirstPartition, 2073 Partition: &ast.PartitionOptions{PartitionMethod: partitionMethod}, 2074 } 2075 } 2076 | "PARTITION" Identifier AttributesOpt 2077 { 2078 $$ = &ast.AlterTableSpec{ 2079 Tp: ast.AlterTablePartitionAttributes, 2080 PartitionNames: []model.CIStr{model.NewCIStr($2)}, 2081 AttributesSpec: $3.(*ast.AttributesSpec), 2082 } 2083 } 2084 | "PARTITION" Identifier PartDefOptionList 2085 { 2086 $$ = &ast.AlterTableSpec{ 2087 Tp: ast.AlterTablePartitionOptions, 2088 PartitionNames: []model.CIStr{model.NewCIStr($2)}, 2089 Options: $3.([]*ast.TableOption), 2090 } 2091 } 2092 | "REMOVE" "TTL" 2093 { 2094 $$ = &ast.AlterTableSpec{ 2095 Tp: ast.AlterTableRemoveTTL, 2096 } 2097 } 2098 2099 LocationLabelList: 2100 { 2101 $$ = []string{} 2102 } 2103 | "LOCATION" "LABELS" StringList 2104 { 2105 $$ = $3 2106 } 2107 2108 AlterTableSpec: 2109 TableOptionList %prec higherThanComma 2110 { 2111 $$ = &ast.AlterTableSpec{ 2112 Tp: ast.AlterTableOption, 2113 Options: $1.([]*ast.TableOption), 2114 } 2115 } 2116 | "SET" "TIFLASH" "REPLICA" LengthNum LocationLabelList 2117 { 2118 tiflashReplicaSpec := &ast.TiFlashReplicaSpec{ 2119 Count: $4.(uint64), 2120 Labels: $5.([]string), 2121 } 2122 $$ = &ast.AlterTableSpec{ 2123 Tp: ast.AlterTableSetTiFlashReplica, 2124 TiFlashReplica: tiflashReplicaSpec, 2125 } 2126 } 2127 | "SET" "HYPO" "TIFLASH" "REPLICA" LengthNum LocationLabelList 2128 { 2129 tiflashReplicaSpec := &ast.TiFlashReplicaSpec{ 2130 Count: $5.(uint64), 2131 Labels: $6.([]string), 2132 Hypo: true, 2133 } 2134 $$ = &ast.AlterTableSpec{ 2135 Tp: ast.AlterTableSetTiFlashReplica, 2136 TiFlashReplica: tiflashReplicaSpec, 2137 } 2138 } 2139 | "CONVERT" "TO" CharsetKw CharsetName OptCollate 2140 { 2141 op := &ast.AlterTableSpec{ 2142 Tp: ast.AlterTableOption, 2143 Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, StrValue: $4, 2144 UintValue: ast.TableOptionCharsetWithConvertTo}}, 2145 } 2146 if $5 != "" { 2147 op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5}) 2148 } 2149 $$ = op 2150 } 2151 | "CONVERT" "TO" CharsetKw "DEFAULT" OptCollate 2152 { 2153 op := &ast.AlterTableSpec{ 2154 Tp: ast.AlterTableOption, 2155 Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, Default: true, 2156 UintValue: ast.TableOptionCharsetWithConvertTo}}, 2157 } 2158 if $5 != "" { 2159 op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5}) 2160 } 2161 $$ = op 2162 } 2163 | "ADD" ColumnKeywordOpt IfNotExists ColumnDef ColumnPosition 2164 { 2165 $$ = &ast.AlterTableSpec{ 2166 IfNotExists: $3.(bool), 2167 Tp: ast.AlterTableAddColumns, 2168 NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)}, 2169 Position: $5.(*ast.ColumnPosition), 2170 } 2171 } 2172 | "ADD" ColumnKeywordOpt IfNotExists '(' TableElementList ')' 2173 { 2174 tes := $5.([]interface{}) 2175 var columnDefs []*ast.ColumnDef 2176 var constraints []*ast.Constraint 2177 for _, te := range tes { 2178 switch te := te.(type) { 2179 case *ast.ColumnDef: 2180 columnDefs = append(columnDefs, te) 2181 case *ast.Constraint: 2182 constraints = append(constraints, te) 2183 } 2184 } 2185 $$ = &ast.AlterTableSpec{ 2186 IfNotExists: $3.(bool), 2187 Tp: ast.AlterTableAddColumns, 2188 NewColumns: columnDefs, 2189 NewConstraints: constraints, 2190 } 2191 } 2192 | "ADD" Constraint 2193 { 2194 constraint := $2.(*ast.Constraint) 2195 $$ = &ast.AlterTableSpec{ 2196 Tp: ast.AlterTableAddConstraint, 2197 Constraint: constraint, 2198 } 2199 } 2200 | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt PartitionDefinitionListOpt 2201 { 2202 var defs []*ast.PartitionDefinition 2203 if $5 != nil { 2204 defs = $5.([]*ast.PartitionDefinition) 2205 } 2206 noWriteToBinlog := $4.(bool) 2207 if noWriteToBinlog { 2208 yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now.")) 2209 parser.lastErrorAsWarn() 2210 } 2211 $$ = &ast.AlterTableSpec{ 2212 IfNotExists: $3.(bool), 2213 NoWriteToBinlog: noWriteToBinlog, 2214 Tp: ast.AlterTableAddPartitions, 2215 PartDefinitions: defs, 2216 } 2217 } 2218 | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt "PARTITIONS" NUM 2219 { 2220 noWriteToBinlog := $4.(bool) 2221 if noWriteToBinlog { 2222 yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now.")) 2223 parser.lastErrorAsWarn() 2224 } 2225 $$ = &ast.AlterTableSpec{ 2226 IfNotExists: $3.(bool), 2227 NoWriteToBinlog: noWriteToBinlog, 2228 Tp: ast.AlterTableAddPartitions, 2229 Num: getUint64FromNUM($6), 2230 } 2231 } 2232 | "LAST" "PARTITION" "LESS" "THAN" '(' BitExpr ')' NoWriteToBinLogAliasOpt 2233 { 2234 noWriteToBinlog := $8.(bool) 2235 if noWriteToBinlog { 2236 yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now.")) 2237 parser.lastErrorAsWarn() 2238 } 2239 partitionMethod := ast.PartitionMethod{Expr: $6} 2240 startOffset := parser.yyVAL.offset 2241 endOffset := parser.yylval.offset 2242 partitionMethod.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 2243 // Needed for replacing syntactic sugar with generated partitioning definition string 2244 partitionMethod.SetOriginTextPosition(startOffset) 2245 $$ = &ast.AlterTableSpec{ 2246 NoWriteToBinlog: noWriteToBinlog, 2247 Tp: ast.AlterTableAddLastPartition, 2248 Partition: &ast.PartitionOptions{PartitionMethod: partitionMethod}, 2249 } 2250 } 2251 | "ADD" "STATS_EXTENDED" IfNotExists Identifier StatsType '(' ColumnNameList ')' 2252 { 2253 statsSpec := &ast.StatisticsSpec{ 2254 StatsName: $4, 2255 StatsType: $5.(uint8), 2256 Columns: $7.([]*ast.ColumnName), 2257 } 2258 $$ = &ast.AlterTableSpec{ 2259 Tp: ast.AlterTableAddStatistics, 2260 IfNotExists: $3.(bool), 2261 Statistics: statsSpec, 2262 } 2263 } 2264 | AttributesOpt 2265 { 2266 $$ = &ast.AlterTableSpec{ 2267 Tp: ast.AlterTableAttributes, 2268 AttributesSpec: $1.(*ast.AttributesSpec), 2269 } 2270 } 2271 | StatsOptionsOpt 2272 { 2273 $$ = &ast.AlterTableSpec{ 2274 Tp: ast.AlterTableStatsOptions, 2275 StatsOptionsSpec: $1.(*ast.StatsOptionsSpec), 2276 } 2277 } 2278 | "CHECK" "PARTITION" AllOrPartitionNameList 2279 { 2280 yylex.AppendError(yylex.Errorf("The CHECK PARTITIONING clause is parsed but not implement yet.")) 2281 parser.lastErrorAsWarn() 2282 ret := &ast.AlterTableSpec{ 2283 Tp: ast.AlterTableCheckPartitions, 2284 } 2285 if $3 == nil { 2286 ret.OnAllPartitions = true 2287 } else { 2288 ret.PartitionNames = $3.([]model.CIStr) 2289 } 2290 $$ = ret 2291 } 2292 | "COALESCE" "PARTITION" NoWriteToBinLogAliasOpt NUM 2293 { 2294 noWriteToBinlog := $3.(bool) 2295 if noWriteToBinlog { 2296 yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now.")) 2297 parser.lastErrorAsWarn() 2298 } 2299 $$ = &ast.AlterTableSpec{ 2300 Tp: ast.AlterTableCoalescePartitions, 2301 NoWriteToBinlog: noWriteToBinlog, 2302 Num: getUint64FromNUM($4), 2303 } 2304 } 2305 | "DROP" ColumnKeywordOpt IfExists ColumnName RestrictOrCascadeOpt 2306 { 2307 $$ = &ast.AlterTableSpec{ 2308 IfExists: $3.(bool), 2309 Tp: ast.AlterTableDropColumn, 2310 OldColumnName: $4.(*ast.ColumnName), 2311 } 2312 } 2313 | "DROP" "PRIMARY" "KEY" 2314 { 2315 $$ = &ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey} 2316 } 2317 | "DROP" "PARTITION" IfExists PartitionNameList %prec lowerThanComma 2318 { 2319 $$ = &ast.AlterTableSpec{ 2320 IfExists: $3.(bool), 2321 Tp: ast.AlterTableDropPartition, 2322 PartitionNames: $4.([]model.CIStr), 2323 } 2324 } 2325 | "FIRST" "PARTITION" "LESS" "THAN" '(' BitExpr ')' IfExists 2326 { 2327 partitionMethod := ast.PartitionMethod{Expr: $6} 2328 startOffset := parser.yyVAL.offset 2329 endOffset := parser.yylval.offset 2330 partitionMethod.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 2331 // Needed for replacing syntactic sugar with generated partitioning definition string 2332 partitionMethod.SetOriginTextPosition(startOffset) 2333 $$ = &ast.AlterTableSpec{ 2334 IfExists: $8.(bool), 2335 Tp: ast.AlterTableDropFirstPartition, 2336 Partition: &ast.PartitionOptions{PartitionMethod: partitionMethod}, 2337 } 2338 } 2339 | "DROP" "STATS_EXTENDED" IfExists Identifier 2340 { 2341 statsSpec := &ast.StatisticsSpec{ 2342 StatsName: $4, 2343 } 2344 $$ = &ast.AlterTableSpec{ 2345 Tp: ast.AlterTableDropStatistics, 2346 IfExists: $3.(bool), 2347 Statistics: statsSpec, 2348 } 2349 } 2350 | "EXCHANGE" "PARTITION" Identifier "WITH" "TABLE" TableName WithValidationOpt 2351 { 2352 $$ = &ast.AlterTableSpec{ 2353 Tp: ast.AlterTableExchangePartition, 2354 PartitionNames: []model.CIStr{model.NewCIStr($3)}, 2355 NewTable: $6.(*ast.TableName), 2356 WithValidation: $7.(bool), 2357 } 2358 } 2359 | "TRUNCATE" "PARTITION" AllOrPartitionNameList 2360 { 2361 ret := &ast.AlterTableSpec{ 2362 Tp: ast.AlterTableTruncatePartition, 2363 } 2364 if $3 == nil { 2365 ret.OnAllPartitions = true 2366 } else { 2367 ret.PartitionNames = $3.([]model.CIStr) 2368 } 2369 $$ = ret 2370 } 2371 | "OPTIMIZE" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList 2372 { 2373 ret := &ast.AlterTableSpec{ 2374 NoWriteToBinlog: $3.(bool), 2375 Tp: ast.AlterTableOptimizePartition, 2376 } 2377 if $4 == nil { 2378 ret.OnAllPartitions = true 2379 } else { 2380 ret.PartitionNames = $4.([]model.CIStr) 2381 } 2382 $$ = ret 2383 } 2384 | "REPAIR" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList 2385 { 2386 ret := &ast.AlterTableSpec{ 2387 NoWriteToBinlog: $3.(bool), 2388 Tp: ast.AlterTableRepairPartition, 2389 } 2390 if $4 == nil { 2391 ret.OnAllPartitions = true 2392 } else { 2393 ret.PartitionNames = $4.([]model.CIStr) 2394 } 2395 $$ = ret 2396 } 2397 | "IMPORT" "PARTITION" AllOrPartitionNameList "TABLESPACE" 2398 { 2399 ret := &ast.AlterTableSpec{ 2400 Tp: ast.AlterTableImportPartitionTablespace, 2401 } 2402 if $3 == nil { 2403 ret.OnAllPartitions = true 2404 } else { 2405 ret.PartitionNames = $3.([]model.CIStr) 2406 } 2407 $$ = ret 2408 yylex.AppendError(yylex.Errorf("The IMPORT PARTITION TABLESPACE clause is parsed but ignored by all storage engines.")) 2409 parser.lastErrorAsWarn() 2410 } 2411 | "DISCARD" "PARTITION" AllOrPartitionNameList "TABLESPACE" 2412 { 2413 ret := &ast.AlterTableSpec{ 2414 Tp: ast.AlterTableDiscardPartitionTablespace, 2415 } 2416 if $3 == nil { 2417 ret.OnAllPartitions = true 2418 } else { 2419 ret.PartitionNames = $3.([]model.CIStr) 2420 } 2421 $$ = ret 2422 yylex.AppendError(yylex.Errorf("The DISCARD PARTITION TABLESPACE clause is parsed but ignored by all storage engines.")) 2423 parser.lastErrorAsWarn() 2424 } 2425 | "IMPORT" "TABLESPACE" 2426 { 2427 ret := &ast.AlterTableSpec{ 2428 Tp: ast.AlterTableImportTablespace, 2429 } 2430 $$ = ret 2431 yylex.AppendError(yylex.Errorf("The IMPORT TABLESPACE clause is parsed but ignored by all storage engines.")) 2432 parser.lastErrorAsWarn() 2433 } 2434 | "DISCARD" "TABLESPACE" 2435 { 2436 ret := &ast.AlterTableSpec{ 2437 Tp: ast.AlterTableDiscardTablespace, 2438 } 2439 $$ = ret 2440 yylex.AppendError(yylex.Errorf("The DISCARD TABLESPACE clause is parsed but ignored by all storage engines.")) 2441 parser.lastErrorAsWarn() 2442 } 2443 | "REBUILD" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList 2444 { 2445 ret := &ast.AlterTableSpec{ 2446 Tp: ast.AlterTableRebuildPartition, 2447 NoWriteToBinlog: $3.(bool), 2448 } 2449 if $4 == nil { 2450 ret.OnAllPartitions = true 2451 } else { 2452 ret.PartitionNames = $4.([]model.CIStr) 2453 } 2454 $$ = ret 2455 } 2456 | "DROP" KeyOrIndex IfExists Identifier 2457 { 2458 $$ = &ast.AlterTableSpec{ 2459 IfExists: $3.(bool), 2460 Tp: ast.AlterTableDropIndex, 2461 Name: $4, 2462 } 2463 } 2464 | "DROP" "FOREIGN" "KEY" IfExists Symbol 2465 { 2466 $$ = &ast.AlterTableSpec{ 2467 IfExists: $4.(bool), 2468 Tp: ast.AlterTableDropForeignKey, 2469 Name: $5, 2470 } 2471 } 2472 | "ORDER" "BY" AlterOrderList %prec lowerThenOrder 2473 { 2474 $$ = &ast.AlterTableSpec{ 2475 Tp: ast.AlterTableOrderByColumns, 2476 OrderByList: $3.([]*ast.AlterOrderItem), 2477 } 2478 } 2479 | "DISABLE" "KEYS" 2480 { 2481 $$ = &ast.AlterTableSpec{ 2482 Tp: ast.AlterTableDisableKeys, 2483 } 2484 } 2485 | "ENABLE" "KEYS" 2486 { 2487 $$ = &ast.AlterTableSpec{ 2488 Tp: ast.AlterTableEnableKeys, 2489 } 2490 } 2491 | "MODIFY" ColumnKeywordOpt IfExists ColumnDef ColumnPosition 2492 { 2493 $$ = &ast.AlterTableSpec{ 2494 IfExists: $3.(bool), 2495 Tp: ast.AlterTableModifyColumn, 2496 NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)}, 2497 Position: $5.(*ast.ColumnPosition), 2498 } 2499 } 2500 | "CHANGE" ColumnKeywordOpt IfExists ColumnName ColumnDef ColumnPosition 2501 { 2502 $$ = &ast.AlterTableSpec{ 2503 IfExists: $3.(bool), 2504 Tp: ast.AlterTableChangeColumn, 2505 OldColumnName: $4.(*ast.ColumnName), 2506 NewColumns: []*ast.ColumnDef{$5.(*ast.ColumnDef)}, 2507 Position: $6.(*ast.ColumnPosition), 2508 } 2509 } 2510 | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" SignedLiteral 2511 { 2512 option := &ast.ColumnOption{Expr: $6} 2513 colDef := &ast.ColumnDef{ 2514 Name: $3.(*ast.ColumnName), 2515 Options: []*ast.ColumnOption{option}, 2516 } 2517 $$ = &ast.AlterTableSpec{ 2518 Tp: ast.AlterTableAlterColumn, 2519 NewColumns: []*ast.ColumnDef{colDef}, 2520 } 2521 } 2522 | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" '(' Expression ')' 2523 { 2524 option := &ast.ColumnOption{Expr: $7} 2525 colDef := &ast.ColumnDef{ 2526 Name: $3.(*ast.ColumnName), 2527 Options: []*ast.ColumnOption{option}, 2528 } 2529 $$ = &ast.AlterTableSpec{ 2530 Tp: ast.AlterTableAlterColumn, 2531 NewColumns: []*ast.ColumnDef{colDef}, 2532 } 2533 } 2534 | "ALTER" ColumnKeywordOpt ColumnName "DROP" "DEFAULT" 2535 { 2536 colDef := &ast.ColumnDef{ 2537 Name: $3.(*ast.ColumnName), 2538 } 2539 $$ = &ast.AlterTableSpec{ 2540 Tp: ast.AlterTableAlterColumn, 2541 NewColumns: []*ast.ColumnDef{colDef}, 2542 } 2543 } 2544 | "RENAME" "COLUMN" Identifier "TO" Identifier 2545 { 2546 oldColName := &ast.ColumnName{Name: model.NewCIStr($3)} 2547 newColName := &ast.ColumnName{Name: model.NewCIStr($5)} 2548 $$ = &ast.AlterTableSpec{ 2549 Tp: ast.AlterTableRenameColumn, 2550 OldColumnName: oldColName, 2551 NewColumnName: newColName, 2552 } 2553 } 2554 | "RENAME" "TO" TableName 2555 { 2556 $$ = &ast.AlterTableSpec{ 2557 Tp: ast.AlterTableRenameTable, 2558 NewTable: $3.(*ast.TableName), 2559 } 2560 } 2561 | "RENAME" EqOpt TableName 2562 { 2563 $$ = &ast.AlterTableSpec{ 2564 Tp: ast.AlterTableRenameTable, 2565 NewTable: $3.(*ast.TableName), 2566 } 2567 } 2568 | "RENAME" "AS" TableName 2569 { 2570 $$ = &ast.AlterTableSpec{ 2571 Tp: ast.AlterTableRenameTable, 2572 NewTable: $3.(*ast.TableName), 2573 } 2574 } 2575 | "RENAME" KeyOrIndex Identifier "TO" Identifier 2576 { 2577 $$ = &ast.AlterTableSpec{ 2578 Tp: ast.AlterTableRenameIndex, 2579 FromKey: model.NewCIStr($3), 2580 ToKey: model.NewCIStr($5), 2581 } 2582 } 2583 | LockClause 2584 { 2585 $$ = &ast.AlterTableSpec{ 2586 Tp: ast.AlterTableLock, 2587 LockType: $1.(ast.LockType), 2588 } 2589 } 2590 | Writeable 2591 { 2592 $$ = &ast.AlterTableSpec{ 2593 Tp: ast.AlterTableWriteable, 2594 Writeable: $1.(bool), 2595 } 2596 } 2597 | AlgorithmClause 2598 { 2599 // Parse it and ignore it. Just for compatibility. 2600 $$ = &ast.AlterTableSpec{ 2601 Tp: ast.AlterTableAlgorithm, 2602 Algorithm: $1.(ast.AlgorithmType), 2603 } 2604 } 2605 | "FORCE" 2606 { 2607 // Parse it and ignore it. Just for compatibility. 2608 $$ = &ast.AlterTableSpec{ 2609 Tp: ast.AlterTableForce, 2610 } 2611 } 2612 | "WITH" "VALIDATION" 2613 { 2614 // Parse it and ignore it. Just for compatibility. 2615 $$ = &ast.AlterTableSpec{ 2616 Tp: ast.AlterTableWithValidation, 2617 } 2618 } 2619 | "WITHOUT" "VALIDATION" 2620 { 2621 // Parse it and ignore it. Just for compatibility. 2622 $$ = &ast.AlterTableSpec{ 2623 Tp: ast.AlterTableWithoutValidation, 2624 } 2625 } 2626 // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details 2627 | "SECONDARY_LOAD" 2628 { 2629 // Parse it and ignore it. Just for compatibility. 2630 $$ = &ast.AlterTableSpec{ 2631 Tp: ast.AlterTableSecondaryLoad, 2632 } 2633 yylex.AppendError(yylex.Errorf("The SECONDARY_LOAD clause is parsed but not implement yet.")) 2634 parser.lastErrorAsWarn() 2635 } 2636 // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details 2637 | "SECONDARY_UNLOAD" 2638 { 2639 // Parse it and ignore it. Just for compatibility. 2640 $$ = &ast.AlterTableSpec{ 2641 Tp: ast.AlterTableSecondaryUnload, 2642 } 2643 yylex.AppendError(yylex.Errorf("The SECONDARY_UNLOAD VALIDATION clause is parsed but not implement yet.")) 2644 parser.lastErrorAsWarn() 2645 } 2646 | "ALTER" CheckConstraintKeyword Identifier EnforcedOrNot 2647 { 2648 c := &ast.Constraint{ 2649 Name: $3, 2650 Enforced: $4.(bool), 2651 } 2652 $$ = &ast.AlterTableSpec{ 2653 Tp: ast.AlterTableAlterCheck, 2654 Constraint: c, 2655 } 2656 } 2657 | "DROP" CheckConstraintKeyword Identifier 2658 { 2659 // Parse it and ignore it. Just for compatibility. 2660 c := &ast.Constraint{ 2661 Name: $3, 2662 } 2663 $$ = &ast.AlterTableSpec{ 2664 Tp: ast.AlterTableDropCheck, 2665 Constraint: c, 2666 } 2667 } 2668 | "ALTER" "INDEX" Identifier IndexInvisible 2669 { 2670 $$ = &ast.AlterTableSpec{ 2671 Tp: ast.AlterTableIndexInvisible, 2672 IndexName: model.NewCIStr($3), 2673 Visibility: $4.(ast.IndexVisibility), 2674 } 2675 } 2676 // Support caching or non-caching a table in memory for tidb, It can be found in the official Oracle document, see: https://docs.oracle.com/database/121/SQLRF/statements_3001.htm 2677 | "CACHE" 2678 { 2679 $$ = &ast.AlterTableSpec{ 2680 Tp: ast.AlterTableCache, 2681 } 2682 } 2683 | "NOCACHE" 2684 { 2685 $$ = &ast.AlterTableSpec{ 2686 Tp: ast.AlterTableNoCache, 2687 } 2688 } 2689 2690 ReorganizePartitionRuleOpt: 2691 /* empty */ %prec lowerThanRemove 2692 { 2693 ret := &ast.AlterTableSpec{ 2694 Tp: ast.AlterTableReorganizePartition, 2695 OnAllPartitions: true, 2696 } 2697 $$ = ret 2698 } 2699 | PartitionNameList "INTO" '(' PartitionDefinitionList ')' 2700 { 2701 ret := &ast.AlterTableSpec{ 2702 Tp: ast.AlterTableReorganizePartition, 2703 PartitionNames: $1.([]model.CIStr), 2704 PartDefinitions: $4.([]*ast.PartitionDefinition), 2705 } 2706 $$ = ret 2707 } 2708 2709 AllOrPartitionNameList: 2710 "ALL" 2711 { 2712 $$ = nil 2713 } 2714 | PartitionNameList %prec lowerThanComma 2715 2716 WithValidationOpt: 2717 { 2718 $$ = true 2719 } 2720 | WithValidation 2721 2722 WithValidation: 2723 "WITH" "VALIDATION" 2724 { 2725 $$ = true 2726 } 2727 | "WITHOUT" "VALIDATION" 2728 { 2729 $$ = false 2730 } 2731 2732 WithClustered: 2733 "CLUSTERED" 2734 { 2735 $$ = model.PrimaryKeyTypeClustered 2736 } 2737 | "NONCLUSTERED" 2738 { 2739 $$ = model.PrimaryKeyTypeNonClustered 2740 } 2741 2742 AlgorithmClause: 2743 "ALGORITHM" EqOpt "DEFAULT" 2744 { 2745 $$ = ast.AlgorithmTypeDefault 2746 } 2747 | "ALGORITHM" EqOpt "COPY" 2748 { 2749 $$ = ast.AlgorithmTypeCopy 2750 } 2751 | "ALGORITHM" EqOpt "INPLACE" 2752 { 2753 $$ = ast.AlgorithmTypeInplace 2754 } 2755 | "ALGORITHM" EqOpt "INSTANT" 2756 { 2757 $$ = ast.AlgorithmTypeInstant 2758 } 2759 | "ALGORITHM" EqOpt identifier 2760 { 2761 yylex.AppendError(ErrUnknownAlterAlgorithm.GenWithStackByArgs($1)) 2762 return 1 2763 } 2764 2765 LockClause: 2766 "LOCK" EqOpt "DEFAULT" 2767 { 2768 $$ = ast.LockTypeDefault 2769 } 2770 | "LOCK" EqOpt Identifier 2771 { 2772 id := strings.ToUpper($3) 2773 2774 if id == "NONE" { 2775 $$ = ast.LockTypeNone 2776 } else if id == "SHARED" { 2777 $$ = ast.LockTypeShared 2778 } else if id == "EXCLUSIVE" { 2779 $$ = ast.LockTypeExclusive 2780 } else { 2781 yylex.AppendError(ErrUnknownAlterLock.GenWithStackByArgs($3)) 2782 return 1 2783 } 2784 } 2785 2786 Writeable: 2787 "READ" "WRITE" 2788 { 2789 $$ = true 2790 } 2791 | "READ" "ONLY" 2792 { 2793 $$ = false 2794 } 2795 2796 KeyOrIndex: 2797 "KEY" 2798 | "INDEX" 2799 2800 KeyOrIndexOpt: 2801 {} 2802 | KeyOrIndex 2803 2804 ColumnKeywordOpt: 2805 /* empty */ %prec empty 2806 {} 2807 | "COLUMN" 2808 2809 ColumnPosition: 2810 { 2811 $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionNone} 2812 } 2813 | "FIRST" 2814 { 2815 $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionFirst} 2816 } 2817 | "AFTER" ColumnName 2818 { 2819 $$ = &ast.ColumnPosition{ 2820 Tp: ast.ColumnPositionAfter, 2821 RelativeColumn: $2.(*ast.ColumnName), 2822 } 2823 } 2824 2825 AlterTableSpecListOpt: 2826 /* empty */ 2827 { 2828 $$ = make([]*ast.AlterTableSpec, 0, 1) 2829 } 2830 | AlterTableSpecList 2831 2832 AlterTableSpecList: 2833 AlterTableSpec 2834 { 2835 $$ = []*ast.AlterTableSpec{$1.(*ast.AlterTableSpec)} 2836 } 2837 | AlterTableSpecList ',' AlterTableSpec 2838 { 2839 $$ = append($1.([]*ast.AlterTableSpec), $3.(*ast.AlterTableSpec)) 2840 } 2841 2842 PartitionNameList: 2843 Identifier 2844 { 2845 $$ = []model.CIStr{model.NewCIStr($1)} 2846 } 2847 | PartitionNameList ',' Identifier 2848 { 2849 $$ = append($1.([]model.CIStr), model.NewCIStr($3)) 2850 } 2851 2852 ConstraintKeywordOpt: 2853 /* empty */ %prec empty 2854 { 2855 $$ = nil 2856 } 2857 | "CONSTRAINT" 2858 { 2859 $$ = nil 2860 } 2861 | "CONSTRAINT" Symbol 2862 { 2863 $$ = $2 2864 } 2865 2866 Symbol: 2867 Identifier 2868 2869 /**************************************RenameTableStmt*************************************** 2870 * See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html 2871 * 2872 * RENAME TABLE 2873 * tbl_name TO new_tbl_name 2874 * [, tbl_name2 TO new_tbl_name2] ... 2875 *******************************************************************************************/ 2876 RenameTableStmt: 2877 "RENAME" "TABLE" TableToTableList 2878 { 2879 $$ = &ast.RenameTableStmt{ 2880 TableToTables: $3.([]*ast.TableToTable), 2881 } 2882 } 2883 2884 TableToTableList: 2885 TableToTable 2886 { 2887 $$ = []*ast.TableToTable{$1.(*ast.TableToTable)} 2888 } 2889 | TableToTableList ',' TableToTable 2890 { 2891 $$ = append($1.([]*ast.TableToTable), $3.(*ast.TableToTable)) 2892 } 2893 2894 TableToTable: 2895 TableName "TO" TableName 2896 { 2897 $$ = &ast.TableToTable{ 2898 OldTable: $1.(*ast.TableName), 2899 NewTable: $3.(*ast.TableName), 2900 } 2901 } 2902 2903 /**************************************RenameUserStmt*************************************** 2904 * See https://dev.mysql.com/doc/refman/5.7/en/rename-user.html 2905 * 2906 * RENAME USER 2907 * old_user TO new_user 2908 * [, old_user2 TO new_user2] ... 2909 *******************************************************************************************/ 2910 RenameUserStmt: 2911 "RENAME" "USER" UserToUserList 2912 { 2913 $$ = &ast.RenameUserStmt{ 2914 UserToUsers: $3.([]*ast.UserToUser), 2915 } 2916 } 2917 2918 UserToUserList: 2919 UserToUser 2920 { 2921 $$ = []*ast.UserToUser{$1.(*ast.UserToUser)} 2922 } 2923 | UserToUserList ',' UserToUser 2924 { 2925 $$ = append($1.([]*ast.UserToUser), $3.(*ast.UserToUser)) 2926 } 2927 2928 UserToUser: 2929 Username "TO" Username 2930 { 2931 $$ = &ast.UserToUser{ 2932 OldUser: $1.(*auth.UserIdentity), 2933 NewUser: $3.(*auth.UserIdentity), 2934 } 2935 } 2936 2937 /******************************************************************* 2938 * 2939 * Recover Table Statement 2940 * 2941 * Example: 2942 * RECOVER TABLE t1; 2943 * RECOVER TABLE BY JOB 100; 2944 * 2945 *******************************************************************/ 2946 RecoverTableStmt: 2947 "RECOVER" "TABLE" "BY" "JOB" Int64Num 2948 { 2949 $$ = &ast.RecoverTableStmt{ 2950 JobID: $5.(int64), 2951 } 2952 } 2953 | "RECOVER" "TABLE" TableName 2954 { 2955 $$ = &ast.RecoverTableStmt{ 2956 Table: $3.(*ast.TableName), 2957 } 2958 } 2959 | "RECOVER" "TABLE" TableName Int64Num 2960 { 2961 $$ = &ast.RecoverTableStmt{ 2962 Table: $3.(*ast.TableName), 2963 JobNum: $4.(int64), 2964 } 2965 } 2966 2967 /******************************************************************* 2968 * 2969 * FLASHBACK [CLUSTER | DATABASE | TABLE] TO TIMESTAMP 2970 * 2971 * Example: 2972 * 2973 *******************************************************************/ 2974 FlashbackToTimestampStmt: 2975 "FLASHBACK" "CLUSTER" toTimestamp stringLit 2976 { 2977 $$ = &ast.FlashBackToTimestampStmt{ 2978 FlashbackTS: ast.NewValueExpr($4, "", ""), 2979 } 2980 } 2981 | "FLASHBACK" "TABLE" TableNameList toTimestamp stringLit 2982 { 2983 $$ = &ast.FlashBackToTimestampStmt{ 2984 Tables: $3.([]*ast.TableName), 2985 FlashbackTS: ast.NewValueExpr($5, "", ""), 2986 } 2987 } 2988 | "FLASHBACK" DatabaseSym DBName toTimestamp stringLit 2989 { 2990 $$ = &ast.FlashBackToTimestampStmt{ 2991 DBName: model.NewCIStr($3), 2992 FlashbackTS: ast.NewValueExpr($5, "", ""), 2993 } 2994 } 2995 2996 /******************************************************************* 2997 * 2998 * Flush Back Table Statement 2999 * 3000 * Example: 3001 * 3002 *******************************************************************/ 3003 FlashbackTableStmt: 3004 "FLASHBACK" "TABLE" TableName FlashbackToNewName 3005 { 3006 $$ = &ast.FlashBackTableStmt{ 3007 Table: $3.(*ast.TableName), 3008 NewName: $4, 3009 } 3010 } 3011 3012 FlashbackToNewName: 3013 { 3014 $$ = "" 3015 } 3016 | "TO" Identifier 3017 { 3018 $$ = $2 3019 } 3020 3021 /******************************************************************* 3022 * 3023 * Flush Back Database Statement 3024 * 3025 * Example: 3026 * FLASHBACK DATABASE/SCHEMA DBName TO newDBName 3027 * 3028 *******************************************************************/ 3029 FlashbackDatabaseStmt: 3030 "FLASHBACK" DatabaseSym DBName FlashbackToNewName 3031 { 3032 $$ = &ast.FlashBackDatabaseStmt{ 3033 DBName: model.NewCIStr($3), 3034 NewName: $4, 3035 } 3036 } 3037 3038 /******************************************************************* 3039 * 3040 * Split index region statement 3041 * 3042 * Example: 3043 * SPLIT TABLE table_name INDEX index_name BY (val1...),(val2...)... 3044 * 3045 *******************************************************************/ 3046 SplitRegionStmt: 3047 "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt SplitOption 3048 { 3049 $$ = &ast.SplitRegionStmt{ 3050 SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption), 3051 Table: $4.(*ast.TableName), 3052 PartitionNames: $5.([]model.CIStr), 3053 SplitOpt: $6.(*ast.SplitOption), 3054 } 3055 } 3056 | "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt "INDEX" Identifier SplitOption 3057 { 3058 $$ = &ast.SplitRegionStmt{ 3059 SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption), 3060 Table: $4.(*ast.TableName), 3061 PartitionNames: $5.([]model.CIStr), 3062 IndexName: model.NewCIStr($7), 3063 SplitOpt: $8.(*ast.SplitOption), 3064 } 3065 } 3066 3067 SplitOption: 3068 "BETWEEN" RowValue "AND" RowValue "REGIONS" Int64Num 3069 { 3070 $$ = &ast.SplitOption{ 3071 Lower: $2.([]ast.ExprNode), 3072 Upper: $4.([]ast.ExprNode), 3073 Num: $6.(int64), 3074 } 3075 } 3076 | "BY" ValuesList 3077 { 3078 $$ = &ast.SplitOption{ 3079 ValueLists: $2.([][]ast.ExprNode), 3080 } 3081 } 3082 3083 SplitSyntaxOption: 3084 /* empty */ 3085 { 3086 $$ = &ast.SplitSyntaxOption{} 3087 } 3088 | "REGION" "FOR" 3089 { 3090 $$ = &ast.SplitSyntaxOption{ 3091 HasRegionFor: true, 3092 } 3093 } 3094 | "PARTITION" 3095 { 3096 $$ = &ast.SplitSyntaxOption{ 3097 HasPartition: true, 3098 } 3099 } 3100 | "REGION" "FOR" "PARTITION" 3101 { 3102 $$ = &ast.SplitSyntaxOption{ 3103 HasRegionFor: true, 3104 HasPartition: true, 3105 } 3106 } 3107 3108 AnalyzeTableStmt: 3109 "ANALYZE" "TABLE" TableNameList AllColumnsOrPredicateColumnsOpt AnalyzeOptionListOpt 3110 { 3111 $$ = &ast.AnalyzeTableStmt{TableNames: $3.([]*ast.TableName), ColumnChoice: $4.(model.ColumnChoice), AnalyzeOpts: $5.([]ast.AnalyzeOpt)} 3112 } 3113 | "ANALYZE" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt 3114 { 3115 $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, IndexNames: $5.([]model.CIStr), IndexFlag: true, AnalyzeOpts: $6.([]ast.AnalyzeOpt)} 3116 } 3117 | "ANALYZE" "INCREMENTAL" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt 3118 { 3119 $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, IndexNames: $6.([]model.CIStr), IndexFlag: true, Incremental: true, AnalyzeOpts: $7.([]ast.AnalyzeOpt)} 3120 } 3121 | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList AllColumnsOrPredicateColumnsOpt AnalyzeOptionListOpt 3122 { 3123 $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, PartitionNames: $5.([]model.CIStr), ColumnChoice: $6.(model.ColumnChoice), AnalyzeOpts: $7.([]ast.AnalyzeOpt)} 3124 } 3125 | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt 3126 { 3127 $$ = &ast.AnalyzeTableStmt{ 3128 TableNames: []*ast.TableName{$3.(*ast.TableName)}, 3129 PartitionNames: $5.([]model.CIStr), 3130 IndexNames: $7.([]model.CIStr), 3131 IndexFlag: true, 3132 AnalyzeOpts: $8.([]ast.AnalyzeOpt), 3133 } 3134 } 3135 | "ANALYZE" "INCREMENTAL" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt 3136 { 3137 $$ = &ast.AnalyzeTableStmt{ 3138 TableNames: []*ast.TableName{$4.(*ast.TableName)}, 3139 PartitionNames: $6.([]model.CIStr), 3140 IndexNames: $8.([]model.CIStr), 3141 IndexFlag: true, 3142 Incremental: true, 3143 AnalyzeOpts: $9.([]ast.AnalyzeOpt), 3144 } 3145 } 3146 | "ANALYZE" "TABLE" TableName "UPDATE" "HISTOGRAM" "ON" IdentList AnalyzeOptionListOpt 3147 { 3148 $$ = &ast.AnalyzeTableStmt{ 3149 TableNames: []*ast.TableName{$3.(*ast.TableName)}, 3150 ColumnNames: $7.([]model.CIStr), 3151 AnalyzeOpts: $8.([]ast.AnalyzeOpt), 3152 HistogramOperation: ast.HistogramOperationUpdate, 3153 } 3154 } 3155 | "ANALYZE" "TABLE" TableName "DROP" "HISTOGRAM" "ON" IdentList 3156 { 3157 $$ = &ast.AnalyzeTableStmt{ 3158 TableNames: []*ast.TableName{$3.(*ast.TableName)}, 3159 ColumnNames: $7.([]model.CIStr), 3160 HistogramOperation: ast.HistogramOperationDrop, 3161 } 3162 } 3163 | "ANALYZE" "TABLE" TableName "COLUMNS" IdentList AnalyzeOptionListOpt 3164 { 3165 $$ = &ast.AnalyzeTableStmt{ 3166 TableNames: []*ast.TableName{$3.(*ast.TableName)}, 3167 ColumnNames: $5.([]model.CIStr), 3168 ColumnChoice: model.ColumnList, 3169 AnalyzeOpts: $6.([]ast.AnalyzeOpt)} 3170 } 3171 | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList "COLUMNS" IdentList AnalyzeOptionListOpt 3172 { 3173 $$ = &ast.AnalyzeTableStmt{ 3174 TableNames: []*ast.TableName{$3.(*ast.TableName)}, 3175 PartitionNames: $5.([]model.CIStr), 3176 ColumnNames: $7.([]model.CIStr), 3177 ColumnChoice: model.ColumnList, 3178 AnalyzeOpts: $8.([]ast.AnalyzeOpt)} 3179 } 3180 3181 AllColumnsOrPredicateColumnsOpt: 3182 /* empty */ 3183 { 3184 $$ = model.DefaultChoice 3185 } 3186 | "ALL" "COLUMNS" 3187 { 3188 $$ = model.AllColumns 3189 } 3190 | "PREDICATE" "COLUMNS" 3191 { 3192 $$ = model.PredicateColumns 3193 } 3194 3195 AnalyzeOptionListOpt: 3196 { 3197 $$ = []ast.AnalyzeOpt{} 3198 } 3199 | "WITH" AnalyzeOptionList 3200 { 3201 $$ = $2.([]ast.AnalyzeOpt) 3202 } 3203 3204 AnalyzeOptionList: 3205 AnalyzeOption 3206 { 3207 $$ = []ast.AnalyzeOpt{$1.(ast.AnalyzeOpt)} 3208 } 3209 | AnalyzeOptionList ',' AnalyzeOption 3210 { 3211 $$ = append($1.([]ast.AnalyzeOpt), $3.(ast.AnalyzeOpt)) 3212 } 3213 3214 AnalyzeOption: 3215 NUM "BUCKETS" 3216 { 3217 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumBuckets, Value: ast.NewValueExpr($1, "", "")} 3218 } 3219 | NUM "TOPN" 3220 { 3221 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumTopN, Value: ast.NewValueExpr($1, "", "")} 3222 } 3223 | NUM "CMSKETCH" "DEPTH" 3224 { 3225 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchDepth, Value: ast.NewValueExpr($1, "", "")} 3226 } 3227 | NUM "CMSKETCH" "WIDTH" 3228 { 3229 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchWidth, Value: ast.NewValueExpr($1, "", "")} 3230 } 3231 | NUM "SAMPLES" 3232 { 3233 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumSamples, Value: ast.NewValueExpr($1, "", "")} 3234 } 3235 | NumLiteral "SAMPLERATE" 3236 { 3237 $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptSampleRate, Value: ast.NewValueExpr($1, "", "")} 3238 } 3239 3240 /*******************************************************************************************/ 3241 Assignment: 3242 ColumnName EqOrAssignmentEq ExprOrDefault 3243 { 3244 $$ = &ast.Assignment{Column: $1.(*ast.ColumnName), Expr: $3} 3245 } 3246 3247 AssignmentList: 3248 Assignment 3249 { 3250 $$ = []*ast.Assignment{$1.(*ast.Assignment)} 3251 } 3252 | AssignmentList ',' Assignment 3253 { 3254 $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment)) 3255 } 3256 3257 AssignmentListOpt: 3258 /* EMPTY */ 3259 { 3260 $$ = []*ast.Assignment{} 3261 } 3262 | AssignmentList 3263 3264 BeginTransactionStmt: 3265 "BEGIN" 3266 { 3267 $$ = &ast.BeginStmt{} 3268 } 3269 | "BEGIN" "PESSIMISTIC" 3270 { 3271 $$ = &ast.BeginStmt{ 3272 Mode: ast.Pessimistic, 3273 } 3274 } 3275 | "BEGIN" "OPTIMISTIC" 3276 { 3277 $$ = &ast.BeginStmt{ 3278 Mode: ast.Optimistic, 3279 } 3280 } 3281 | "START" "TRANSACTION" 3282 { 3283 $$ = &ast.BeginStmt{} 3284 } 3285 | "START" "TRANSACTION" "READ" "WRITE" 3286 { 3287 $$ = &ast.BeginStmt{} 3288 } 3289 | "START" "TRANSACTION" "WITH" "CONSISTENT" "SNAPSHOT" 3290 { 3291 $$ = &ast.BeginStmt{} 3292 } 3293 | "START" "TRANSACTION" "WITH" "CAUSAL" "CONSISTENCY" "ONLY" 3294 { 3295 $$ = &ast.BeginStmt{ 3296 CausalConsistencyOnly: true, 3297 } 3298 } 3299 | "START" "TRANSACTION" "READ" "ONLY" 3300 { 3301 $$ = &ast.BeginStmt{ 3302 ReadOnly: true, 3303 } 3304 } 3305 | "START" "TRANSACTION" "READ" "ONLY" AsOfClause 3306 { 3307 $$ = &ast.BeginStmt{ 3308 ReadOnly: true, 3309 AsOf: $5.(*ast.AsOfClause), 3310 } 3311 } 3312 3313 BinlogStmt: 3314 "BINLOG" stringLit 3315 { 3316 $$ = &ast.BinlogStmt{Str: $2} 3317 } 3318 3319 ColumnDefList: 3320 ColumnDef 3321 { 3322 $$ = []*ast.ColumnDef{$1.(*ast.ColumnDef)} 3323 } 3324 | ColumnDefList ',' ColumnDef 3325 { 3326 $$ = append($1.([]*ast.ColumnDef), $3.(*ast.ColumnDef)) 3327 } 3328 3329 ColumnDef: 3330 ColumnName Type ColumnOptionListOpt 3331 { 3332 colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)} 3333 if err := colDef.Validate(); err != nil { 3334 yylex.AppendError(err) 3335 return 1 3336 } 3337 $$ = colDef 3338 } 3339 | ColumnName "SERIAL" ColumnOptionListOpt 3340 { 3341 // TODO: check flen 0 3342 tp := types.NewFieldType(mysql.TypeLonglong) 3343 options := []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}} 3344 options = append(options, $3.([]*ast.ColumnOption)...) 3345 tp.AddFlag(mysql.UnsignedFlag) 3346 colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: tp, Options: options} 3347 if err := colDef.Validate(); err != nil { 3348 yylex.AppendError(err) 3349 return 1 3350 } 3351 $$ = colDef 3352 } 3353 3354 ColumnName: 3355 Identifier 3356 { 3357 $$ = &ast.ColumnName{Name: model.NewCIStr($1)} 3358 } 3359 | Identifier '.' Identifier 3360 { 3361 $$ = &ast.ColumnName{Table: model.NewCIStr($1), Name: model.NewCIStr($3)} 3362 } 3363 | Identifier '.' Identifier '.' Identifier 3364 { 3365 $$ = &ast.ColumnName{Schema: model.NewCIStr($1), Table: model.NewCIStr($3), Name: model.NewCIStr($5)} 3366 } 3367 3368 ColumnNameList: 3369 ColumnName 3370 { 3371 $$ = []*ast.ColumnName{$1.(*ast.ColumnName)} 3372 } 3373 | ColumnNameList ',' ColumnName 3374 { 3375 $$ = append($1.([]*ast.ColumnName), $3.(*ast.ColumnName)) 3376 } 3377 3378 ColumnNameListOpt: 3379 /* EMPTY */ 3380 { 3381 $$ = []*ast.ColumnName{} 3382 } 3383 | ColumnNameList 3384 3385 IdentListWithParenOpt: 3386 /* EMPTY */ 3387 { 3388 $$ = []model.CIStr{} 3389 } 3390 | '(' IdentList ')' 3391 { 3392 $$ = $2 3393 } 3394 3395 IdentList: 3396 Identifier 3397 { 3398 $$ = []model.CIStr{model.NewCIStr($1)} 3399 } 3400 | IdentList ',' Identifier 3401 { 3402 $$ = append($1.([]model.CIStr), model.NewCIStr($3)) 3403 } 3404 3405 ColumnNameOrUserVarListOpt: 3406 /* EMPTY */ 3407 { 3408 $$ = []*ast.ColumnNameOrUserVar{} 3409 } 3410 | ColumnNameOrUserVariableList 3411 3412 ColumnNameOrUserVariableList: 3413 ColumnNameOrUserVariable 3414 { 3415 $$ = []*ast.ColumnNameOrUserVar{$1.(*ast.ColumnNameOrUserVar)} 3416 } 3417 | ColumnNameOrUserVariableList ',' ColumnNameOrUserVariable 3418 { 3419 $$ = append($1.([]*ast.ColumnNameOrUserVar), $3.(*ast.ColumnNameOrUserVar)) 3420 } 3421 3422 ColumnNameOrUserVariable: 3423 ColumnName 3424 { 3425 $$ = &ast.ColumnNameOrUserVar{ColumnName: $1.(*ast.ColumnName)} 3426 } 3427 | UserVariable 3428 { 3429 $$ = &ast.ColumnNameOrUserVar{UserVar: $1.(*ast.VariableExpr)} 3430 } 3431 3432 ColumnNameOrUserVarListOptWithBrackets: 3433 /* EMPTY */ 3434 { 3435 $$ = []*ast.ColumnNameOrUserVar{} 3436 } 3437 | '(' ColumnNameOrUserVarListOpt ')' 3438 { 3439 $$ = $2.([]*ast.ColumnNameOrUserVar) 3440 } 3441 3442 CommitStmt: 3443 "COMMIT" 3444 { 3445 $$ = &ast.CommitStmt{} 3446 } 3447 | "COMMIT" CompletionTypeWithinTransaction 3448 { 3449 $$ = &ast.CommitStmt{CompletionType: $2.(ast.CompletionType)} 3450 } 3451 3452 PrimaryOpt: 3453 {} 3454 | "PRIMARY" 3455 3456 NotSym: 3457 not 3458 | not2 3459 { 3460 $$ = "NOT" 3461 } 3462 3463 EnforcedOrNot: 3464 "ENFORCED" 3465 { 3466 $$ = true 3467 } 3468 | NotSym "ENFORCED" 3469 { 3470 $$ = false 3471 } 3472 3473 EnforcedOrNotOpt: 3474 %prec lowerThanNot 3475 { 3476 $$ = true 3477 } 3478 | EnforcedOrNot 3479 3480 EnforcedOrNotOrNotNullOpt: 3481 // This branch is needed to workaround the need of a lookahead of 2 for the grammar: 3482 // 3483 // { [NOT] NULL | CHECK(...) [NOT] ENFORCED } ... 3484 NotSym "NULL" 3485 { 3486 $$ = 0 3487 } 3488 | EnforcedOrNotOpt 3489 { 3490 if $1.(bool) { 3491 $$ = 1 3492 } else { 3493 $$ = 2 3494 } 3495 } 3496 3497 ColumnOption: 3498 NotSym "NULL" 3499 { 3500 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNotNull} 3501 } 3502 | "NULL" 3503 { 3504 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNull} 3505 } 3506 | "AUTO_INCREMENT" 3507 { 3508 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoIncrement} 3509 } 3510 | PrimaryOpt "KEY" 3511 { 3512 // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY 3513 // can also be specified as just KEY when given in a column definition. 3514 // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html 3515 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey} 3516 } 3517 | PrimaryOpt "KEY" WithClustered 3518 { 3519 // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY 3520 // can also be specified as just KEY when given in a column definition. 3521 // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html 3522 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey, PrimaryKeyTp: $3.(model.PrimaryKeyType)} 3523 } 3524 | "UNIQUE" %prec lowerThanKey 3525 { 3526 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey} 3527 } 3528 | "UNIQUE" "KEY" 3529 { 3530 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey} 3531 } 3532 | "DEFAULT" DefaultValueExpr 3533 { 3534 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionDefaultValue, Expr: $2} 3535 } 3536 | "SERIAL" "DEFAULT" "VALUE" 3537 { 3538 $$ = []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}} 3539 } 3540 | "ON" "UPDATE" NowSymOptionFraction 3541 { 3542 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionOnUpdate, Expr: $3} 3543 } 3544 | "COMMENT" stringLit 3545 { 3546 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionComment, Expr: ast.NewValueExpr($2, "", "")} 3547 } 3548 | ConstraintKeywordOpt "CHECK" '(' Expression ')' EnforcedOrNotOrNotNullOpt 3549 { 3550 // See https://dev.mysql.com/doc/refman/5.7/en/create-table.html 3551 // The CHECK clause is parsed but ignored by all storage engines. 3552 // See the branch named `EnforcedOrNotOrNotNullOpt`. 3553 3554 optionCheck := &ast.ColumnOption{ 3555 Tp: ast.ColumnOptionCheck, 3556 Expr: $4, 3557 Enforced: true, 3558 } 3559 // Keep the column type check constraint name. 3560 if $1 != nil { 3561 optionCheck.ConstraintName = $1.(string) 3562 } 3563 switch $6.(int) { 3564 case 0: 3565 $$ = []*ast.ColumnOption{optionCheck, {Tp: ast.ColumnOptionNotNull}} 3566 case 1: 3567 optionCheck.Enforced = true 3568 $$ = optionCheck 3569 case 2: 3570 optionCheck.Enforced = false 3571 $$ = optionCheck 3572 default: 3573 } 3574 } 3575 | GeneratedAlways "AS" '(' Expression ')' VirtualOrStored 3576 { 3577 startOffset := parser.startOffset(&yyS[yypt-2]) 3578 endOffset := parser.endOffset(&yyS[yypt-1]) 3579 expr := $4 3580 expr.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 3581 3582 $$ = &ast.ColumnOption{ 3583 Tp: ast.ColumnOptionGenerated, 3584 Expr: expr, 3585 Stored: $6.(bool), 3586 } 3587 } 3588 | ReferDef 3589 { 3590 $$ = &ast.ColumnOption{ 3591 Tp: ast.ColumnOptionReference, 3592 Refer: $1.(*ast.ReferenceDef), 3593 } 3594 } 3595 | "COLLATE" CollationName 3596 { 3597 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionCollate, StrValue: $2} 3598 } 3599 | "COLUMN_FORMAT" ColumnFormat 3600 { 3601 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionColumnFormat, StrValue: $2} 3602 } 3603 | "STORAGE" StorageMedia 3604 { 3605 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionStorage, StrValue: $2} 3606 yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines.")) 3607 parser.lastErrorAsWarn() 3608 } 3609 | "AUTO_RANDOM" AutoRandomOpt 3610 { 3611 $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoRandom, AutoRandOpt: $2.(ast.AutoRandomOption)} 3612 } 3613 3614 AutoRandomOpt: 3615 { 3616 $$ = ast.AutoRandomOption{ShardBits: types.UnspecifiedLength, RangeBits: types.UnspecifiedLength} 3617 } 3618 | '(' LengthNum ')' 3619 { 3620 $$ = ast.AutoRandomOption{ShardBits: int($2.(uint64)), RangeBits: types.UnspecifiedLength} 3621 } 3622 | '(' LengthNum ',' LengthNum ')' 3623 { 3624 $$ = ast.AutoRandomOption{ShardBits: int($2.(uint64)), RangeBits: int($4.(uint64))} 3625 } 3626 3627 StorageMedia: 3628 "DEFAULT" 3629 | "DISK" 3630 | "MEMORY" 3631 3632 ColumnFormat: 3633 "DEFAULT" 3634 { 3635 $$ = "DEFAULT" 3636 } 3637 | "FIXED" 3638 { 3639 $$ = "FIXED" 3640 } 3641 | "DYNAMIC" 3642 { 3643 $$ = "DYNAMIC" 3644 } 3645 3646 GeneratedAlways: 3647 3648 | "GENERATED" "ALWAYS" 3649 3650 VirtualOrStored: 3651 { 3652 $$ = false 3653 } 3654 | "VIRTUAL" 3655 { 3656 $$ = false 3657 } 3658 | "STORED" 3659 { 3660 $$ = true 3661 } 3662 3663 ColumnOptionList: 3664 ColumnOption 3665 { 3666 if columnOption, ok := $1.(*ast.ColumnOption); ok { 3667 $$ = []*ast.ColumnOption{columnOption} 3668 } else { 3669 $$ = $1 3670 } 3671 } 3672 | ColumnOptionList ColumnOption 3673 { 3674 if columnOption, ok := $2.(*ast.ColumnOption); ok { 3675 $$ = append($1.([]*ast.ColumnOption), columnOption) 3676 } else { 3677 $$ = append($1.([]*ast.ColumnOption), $2.([]*ast.ColumnOption)...) 3678 } 3679 } 3680 3681 ColumnOptionListOpt: 3682 { 3683 $$ = []*ast.ColumnOption{} 3684 } 3685 | ColumnOptionList 3686 3687 ConstraintElem: 3688 "PRIMARY" "KEY" IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList 3689 { 3690 c := &ast.Constraint{ 3691 Tp: ast.ConstraintPrimaryKey, 3692 Keys: $5.([]*ast.IndexPartSpecification), 3693 Name: $3.([]interface{})[0].(*ast.NullString).String, 3694 IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty, 3695 } 3696 if $7 != nil { 3697 c.Option = $7.(*ast.IndexOption) 3698 } 3699 if indexType := $3.([]interface{})[1]; indexType != nil { 3700 if c.Option == nil { 3701 c.Option = &ast.IndexOption{} 3702 } 3703 c.Option.Tp = indexType.(model.IndexType) 3704 } 3705 $$ = c 3706 } 3707 | "FULLTEXT" KeyOrIndexOpt IndexName '(' IndexPartSpecificationList ')' IndexOptionList 3708 { 3709 c := &ast.Constraint{ 3710 Tp: ast.ConstraintFulltext, 3711 Keys: $5.([]*ast.IndexPartSpecification), 3712 Name: $3.(*ast.NullString).String, 3713 IsEmptyIndex: $3.(*ast.NullString).Empty, 3714 } 3715 if $7 != nil { 3716 c.Option = $7.(*ast.IndexOption) 3717 } 3718 $$ = c 3719 } 3720 | KeyOrIndex IfNotExists IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList 3721 { 3722 c := &ast.Constraint{ 3723 IfNotExists: $2.(bool), 3724 Tp: ast.ConstraintIndex, 3725 Keys: $5.([]*ast.IndexPartSpecification), 3726 Name: $3.([]interface{})[0].(*ast.NullString).String, 3727 IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty, 3728 } 3729 if $7 != nil { 3730 c.Option = $7.(*ast.IndexOption) 3731 } 3732 if indexType := $3.([]interface{})[1]; indexType != nil { 3733 if c.Option == nil { 3734 c.Option = &ast.IndexOption{} 3735 } 3736 c.Option.Tp = indexType.(model.IndexType) 3737 } 3738 $$ = c 3739 } 3740 | "UNIQUE" KeyOrIndexOpt IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList 3741 { 3742 c := &ast.Constraint{ 3743 Tp: ast.ConstraintUniq, 3744 Keys: $5.([]*ast.IndexPartSpecification), 3745 Name: $3.([]interface{})[0].(*ast.NullString).String, 3746 IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty, 3747 } 3748 if $7 != nil { 3749 c.Option = $7.(*ast.IndexOption) 3750 } 3751 3752 if indexType := $3.([]interface{})[1]; indexType != nil { 3753 if c.Option == nil { 3754 c.Option = &ast.IndexOption{} 3755 } 3756 c.Option.Tp = indexType.(model.IndexType) 3757 } 3758 $$ = c 3759 } 3760 | "FOREIGN" "KEY" IfNotExists IndexName '(' IndexPartSpecificationList ')' ReferDef 3761 { 3762 $$ = &ast.Constraint{ 3763 IfNotExists: $3.(bool), 3764 Tp: ast.ConstraintForeignKey, 3765 Keys: $6.([]*ast.IndexPartSpecification), 3766 Name: $4.(*ast.NullString).String, 3767 Refer: $8.(*ast.ReferenceDef), 3768 IsEmptyIndex: $4.(*ast.NullString).Empty, 3769 } 3770 } 3771 | "CHECK" '(' Expression ')' EnforcedOrNotOpt 3772 { 3773 $$ = &ast.Constraint{ 3774 Tp: ast.ConstraintCheck, 3775 Expr: $3.(ast.ExprNode), 3776 Enforced: $5.(bool), 3777 } 3778 } 3779 3780 Match: 3781 "MATCH" "FULL" 3782 { 3783 $$ = ast.MatchFull 3784 } 3785 | "MATCH" "PARTIAL" 3786 { 3787 $$ = ast.MatchPartial 3788 } 3789 | "MATCH" "SIMPLE" 3790 { 3791 $$ = ast.MatchSimple 3792 } 3793 3794 MatchOpt: 3795 { 3796 $$ = ast.MatchNone 3797 } 3798 | Match 3799 { 3800 $$ = $1 3801 yylex.AppendError(yylex.Errorf("The MATCH clause is parsed but ignored by all storage engines.")) 3802 parser.lastErrorAsWarn() 3803 } 3804 3805 ReferDef: 3806 "REFERENCES" TableName IndexPartSpecificationListOpt MatchOpt OnDeleteUpdateOpt 3807 { 3808 onDeleteUpdate := $5.([2]interface{}) 3809 $$ = &ast.ReferenceDef{ 3810 Table: $2.(*ast.TableName), 3811 IndexPartSpecifications: $3.([]*ast.IndexPartSpecification), 3812 OnDelete: onDeleteUpdate[0].(*ast.OnDeleteOpt), 3813 OnUpdate: onDeleteUpdate[1].(*ast.OnUpdateOpt), 3814 Match: $4.(ast.MatchType), 3815 } 3816 } 3817 3818 OnDelete: 3819 "ON" "DELETE" ReferOpt 3820 { 3821 $$ = &ast.OnDeleteOpt{ReferOpt: $3.(model.ReferOptionType)} 3822 } 3823 3824 OnUpdate: 3825 "ON" "UPDATE" ReferOpt 3826 { 3827 $$ = &ast.OnUpdateOpt{ReferOpt: $3.(model.ReferOptionType)} 3828 } 3829 3830 OnDeleteUpdateOpt: 3831 %prec lowerThanOn 3832 { 3833 $$ = [2]interface{}{&ast.OnDeleteOpt{}, &ast.OnUpdateOpt{}} 3834 } 3835 | OnDelete %prec lowerThanOn 3836 { 3837 $$ = [2]interface{}{$1, &ast.OnUpdateOpt{}} 3838 } 3839 | OnUpdate %prec lowerThanOn 3840 { 3841 $$ = [2]interface{}{&ast.OnDeleteOpt{}, $1} 3842 } 3843 | OnDelete OnUpdate 3844 { 3845 $$ = [2]interface{}{$1, $2} 3846 } 3847 | OnUpdate OnDelete 3848 { 3849 $$ = [2]interface{}{$2, $1} 3850 } 3851 3852 ReferOpt: 3853 "RESTRICT" 3854 { 3855 $$ = model.ReferOptionRestrict 3856 } 3857 | "CASCADE" 3858 { 3859 $$ = model.ReferOptionCascade 3860 } 3861 | "SET" "NULL" 3862 { 3863 $$ = model.ReferOptionSetNull 3864 } 3865 | "NO" "ACTION" 3866 { 3867 $$ = model.ReferOptionNoAction 3868 } 3869 | "SET" "DEFAULT" 3870 { 3871 $$ = model.ReferOptionSetDefault 3872 yylex.AppendError(yylex.Errorf("The SET DEFAULT clause is parsed but ignored by all storage engines.")) 3873 parser.lastErrorAsWarn() 3874 } 3875 3876 /* 3877 * The DEFAULT clause specifies a default value for a column. 3878 * It can be a function or an expression. This means, for example, 3879 * that you can set the default for a date column to be the value of 3880 * a function such as NOW() or CURRENT_DATE. While in MySQL 8.0 3881 * expression default values are required to be enclosed in parentheses, 3882 * they are NOT required so in TiDB. 3883 * 3884 * See https://dev.mysql.com/doc/refman/8.0/en/create-table.html 3885 * https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html 3886 */ 3887 DefaultValueExpr: 3888 NowSymOptionFractionParentheses 3889 | SignedLiteral 3890 | NextValueForSequence 3891 | BuiltinFunction 3892 3893 BuiltinFunction: 3894 '(' BuiltinFunction ')' 3895 { 3896 $$ = $2.(*ast.FuncCallExpr) 3897 } 3898 | identifier '(' ')' 3899 { 3900 $$ = &ast.FuncCallExpr{ 3901 FnName: model.NewCIStr($1), 3902 } 3903 } 3904 | identifier '(' ExpressionList ')' 3905 { 3906 $$ = &ast.FuncCallExpr{ 3907 FnName: model.NewCIStr($1), 3908 Args: $3.([]ast.ExprNode), 3909 } 3910 } 3911 3912 NowSymOptionFractionParentheses: 3913 '(' NowSymOptionFractionParentheses ')' 3914 { 3915 $$ = $2.(*ast.FuncCallExpr) 3916 } 3917 | NowSymOptionFraction 3918 3919 NowSymOptionFraction: 3920 NowSym 3921 { 3922 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} 3923 } 3924 | NowSymFunc '(' ')' 3925 { 3926 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")} 3927 } 3928 | NowSymFunc '(' NUM ')' 3929 { 3930 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP"), Args: []ast.ExprNode{ast.NewValueExpr($3, parser.charset, parser.collation)}} 3931 } 3932 | CurdateSym '(' ')' 3933 { 3934 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_DATE")} 3935 } 3936 | "CURRENT_DATE" 3937 { 3938 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_DATE")} 3939 } 3940 3941 NextValueForSequence: 3942 "NEXT" "VALUE" forKwd TableName 3943 { 3944 objNameExpr := &ast.TableNameExpr{ 3945 Name: $4.(*ast.TableName), 3946 } 3947 $$ = &ast.FuncCallExpr{ 3948 FnName: model.NewCIStr(ast.NextVal), 3949 Args: []ast.ExprNode{objNameExpr}, 3950 } 3951 } 3952 | "NEXTVAL" '(' TableName ')' 3953 { 3954 objNameExpr := &ast.TableNameExpr{ 3955 Name: $3.(*ast.TableName), 3956 } 3957 $$ = &ast.FuncCallExpr{ 3958 FnName: model.NewCIStr(ast.NextVal), 3959 Args: []ast.ExprNode{objNameExpr}, 3960 } 3961 } 3962 3963 /* 3964 * See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_localtime 3965 * TODO: Process other three keywords 3966 */ 3967 NowSymFunc: 3968 "CURRENT_TIMESTAMP" 3969 | "LOCALTIME" 3970 | "LOCALTIMESTAMP" 3971 | builtinNow 3972 3973 NowSym: 3974 "CURRENT_TIMESTAMP" 3975 | "LOCALTIME" 3976 | "LOCALTIMESTAMP" 3977 3978 CurdateSym: 3979 builtinCurDate 3980 | "CURRENT_DATE" 3981 3982 SignedLiteral: 3983 Literal 3984 { 3985 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 3986 } 3987 | '+' NumLiteral 3988 { 3989 $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: ast.NewValueExpr($2, parser.charset, parser.collation)} 3990 } 3991 | '-' NumLiteral 3992 { 3993 $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: ast.NewValueExpr($2, parser.charset, parser.collation)} 3994 } 3995 3996 NumLiteral: 3997 intLit 3998 | floatLit 3999 | decLit 4000 4001 StatsType: 4002 "CARDINALITY" 4003 { 4004 $$ = ast.StatsTypeCardinality 4005 } 4006 | "DEPENDENCY" 4007 { 4008 $$ = ast.StatsTypeDependency 4009 } 4010 | "CORRELATION" 4011 { 4012 $$ = ast.StatsTypeCorrelation 4013 } 4014 4015 BindingStatusType: 4016 "ENABLED" 4017 { 4018 $$ = ast.BindingStatusTypeEnabled 4019 } 4020 | "DISABLED" 4021 { 4022 $$ = ast.BindingStatusTypeDisabled 4023 } 4024 4025 CreateStatisticsStmt: 4026 "CREATE" "STATISTICS" IfNotExists Identifier '(' StatsType ')' "ON" TableName '(' ColumnNameList ')' 4027 { 4028 $$ = &ast.CreateStatisticsStmt{ 4029 IfNotExists: $3.(bool), 4030 StatsName: $4, 4031 StatsType: $6.(uint8), 4032 Table: $9.(*ast.TableName), 4033 Columns: $11.([]*ast.ColumnName), 4034 } 4035 } 4036 4037 DropStatisticsStmt: 4038 "DROP" "STATISTICS" Identifier 4039 { 4040 $$ = &ast.DropStatisticsStmt{StatsName: $3} 4041 } 4042 4043 /**************************************CreateIndexStmt*************************************** 4044 * See https://dev.mysql.com/doc/refman/8.0/en/create-index.html 4045 * 4046 * TYPE type_name is recognized as a synonym for USING type_name. However, USING is the preferred form. 4047 * 4048 * CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name 4049 * [index_type] 4050 * ON tbl_name (key_part,...) 4051 * [index_option] 4052 * [algorithm_option | lock_option] ... 4053 * 4054 * key_part: {col_name [(length)] | (expr)} [ASC | DESC] 4055 * 4056 * index_option: 4057 * KEY_BLOCK_SIZE [=] value 4058 * | index_type 4059 * | WITH PARSER parser_name 4060 * | COMMENT 'string' 4061 * | {VISIBLE | INVISIBLE} 4062 * 4063 * index_type: 4064 * USING {BTREE | HASH} 4065 * 4066 * algorithm_option: 4067 * ALGORITHM [=] {DEFAULT | INPLACE | COPY} 4068 * 4069 * lock_option: 4070 * LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE} 4071 *******************************************************************************************/ 4072 CreateIndexStmt: 4073 "CREATE" IndexKeyTypeOpt "INDEX" IfNotExists Identifier IndexTypeOpt "ON" TableName '(' IndexPartSpecificationList ')' IndexOptionList IndexLockAndAlgorithmOpt 4074 { 4075 var indexOption *ast.IndexOption 4076 if $12 != nil { 4077 indexOption = $12.(*ast.IndexOption) 4078 if indexOption.Tp == model.IndexTypeInvalid { 4079 if $6 != nil { 4080 indexOption.Tp = $6.(model.IndexType) 4081 } 4082 } 4083 } else { 4084 indexOption = &ast.IndexOption{} 4085 if $6 != nil { 4086 indexOption.Tp = $6.(model.IndexType) 4087 } 4088 } 4089 var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm 4090 if $13 != nil { 4091 indexLockAndAlgorithm = $13.(*ast.IndexLockAndAlgorithm) 4092 if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault { 4093 indexLockAndAlgorithm = nil 4094 } 4095 } 4096 $$ = &ast.CreateIndexStmt{ 4097 IfNotExists: $4.(bool), 4098 IndexName: $5, 4099 Table: $8.(*ast.TableName), 4100 IndexPartSpecifications: $10.([]*ast.IndexPartSpecification), 4101 IndexOption: indexOption, 4102 KeyType: $2.(ast.IndexKeyType), 4103 LockAlg: indexLockAndAlgorithm, 4104 } 4105 } 4106 4107 IndexPartSpecificationListOpt: 4108 { 4109 $$ = ([]*ast.IndexPartSpecification)(nil) 4110 } 4111 | '(' IndexPartSpecificationList ')' 4112 { 4113 $$ = $2 4114 } 4115 4116 IndexPartSpecificationList: 4117 IndexPartSpecification 4118 { 4119 $$ = []*ast.IndexPartSpecification{$1.(*ast.IndexPartSpecification)} 4120 } 4121 | IndexPartSpecificationList ',' IndexPartSpecification 4122 { 4123 $$ = append($1.([]*ast.IndexPartSpecification), $3.(*ast.IndexPartSpecification)) 4124 } 4125 4126 IndexPartSpecification: 4127 ColumnName OptFieldLen OptOrder 4128 { 4129 $$ = &ast.IndexPartSpecification{Column: $1.(*ast.ColumnName), Length: $2.(int), Desc: $3.(bool)} 4130 } 4131 | '(' Expression ')' OptOrder 4132 { 4133 $$ = &ast.IndexPartSpecification{Expr: $2, Desc: $4.(bool)} 4134 } 4135 4136 IndexLockAndAlgorithmOpt: 4137 { 4138 $$ = nil 4139 } 4140 | LockClause 4141 { 4142 $$ = &ast.IndexLockAndAlgorithm{ 4143 LockTp: $1.(ast.LockType), 4144 AlgorithmTp: ast.AlgorithmTypeDefault, 4145 } 4146 } 4147 | AlgorithmClause 4148 { 4149 $$ = &ast.IndexLockAndAlgorithm{ 4150 LockTp: ast.LockTypeDefault, 4151 AlgorithmTp: $1.(ast.AlgorithmType), 4152 } 4153 } 4154 | LockClause AlgorithmClause 4155 { 4156 $$ = &ast.IndexLockAndAlgorithm{ 4157 LockTp: $1.(ast.LockType), 4158 AlgorithmTp: $2.(ast.AlgorithmType), 4159 } 4160 } 4161 | AlgorithmClause LockClause 4162 { 4163 $$ = &ast.IndexLockAndAlgorithm{ 4164 LockTp: $2.(ast.LockType), 4165 AlgorithmTp: $1.(ast.AlgorithmType), 4166 } 4167 } 4168 4169 IndexKeyTypeOpt: 4170 { 4171 $$ = ast.IndexKeyTypeNone 4172 } 4173 | "UNIQUE" 4174 { 4175 $$ = ast.IndexKeyTypeUnique 4176 } 4177 | "SPATIAL" 4178 { 4179 $$ = ast.IndexKeyTypeSpatial 4180 } 4181 | "FULLTEXT" 4182 { 4183 $$ = ast.IndexKeyTypeFullText 4184 } 4185 4186 /**************************************AlterDatabaseStmt*************************************** 4187 * See https://dev.mysql.com/doc/refman/5.7/en/alter-database.html 4188 * 'ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME' is not supported yet. 4189 * 4190 * ALTER {DATABASE | SCHEMA} [db_name] 4191 * alter_specification ... 4192 * 4193 * alter_specification: 4194 * [DEFAULT] CHARACTER SET [=] charset_name 4195 * | [DEFAULT] COLLATE [=] collation_name 4196 * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'} 4197 *******************************************************************************************/ 4198 AlterDatabaseStmt: 4199 "ALTER" DatabaseSym DBName DatabaseOptionList 4200 { 4201 $$ = &ast.AlterDatabaseStmt{ 4202 Name: model.NewCIStr($3), 4203 AlterDefaultDatabase: false, 4204 Options: $4.([]*ast.DatabaseOption), 4205 } 4206 } 4207 | "ALTER" DatabaseSym DatabaseOptionList 4208 { 4209 $$ = &ast.AlterDatabaseStmt{ 4210 Name: model.NewCIStr(""), 4211 AlterDefaultDatabase: true, 4212 Options: $3.([]*ast.DatabaseOption), 4213 } 4214 } 4215 4216 /******************************************************************* 4217 * 4218 * Create Database Statement 4219 * CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name 4220 * [create_specification] ... 4221 * 4222 * create_specification: 4223 * [DEFAULT] CHARACTER SET [=] charset_name 4224 * | [DEFAULT] COLLATE [=] collation_name 4225 * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'} 4226 *******************************************************************/ 4227 CreateDatabaseStmt: 4228 "CREATE" DatabaseSym IfNotExists DBName DatabaseOptionListOpt 4229 { 4230 $$ = &ast.CreateDatabaseStmt{ 4231 IfNotExists: $3.(bool), 4232 Name: model.NewCIStr($4), 4233 Options: $5.([]*ast.DatabaseOption), 4234 } 4235 } 4236 4237 DBName: 4238 Identifier 4239 4240 PolicyName: 4241 Identifier 4242 4243 ResourceGroupName: 4244 Identifier 4245 | "DEFAULT" 4246 4247 DatabaseOption: 4248 DefaultKwdOpt CharsetKw EqOpt CharsetName 4249 { 4250 $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCharset, Value: $4} 4251 } 4252 | DefaultKwdOpt "COLLATE" EqOpt CollationName 4253 { 4254 $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCollate, Value: $4} 4255 } 4256 | DefaultKwdOpt "ENCRYPTION" EqOpt EncryptionOpt 4257 { 4258 $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionEncryption, Value: $4} 4259 } 4260 | DefaultKwdOpt PlacementPolicyOption 4261 { 4262 placementOptions := $2.(*ast.PlacementOption) 4263 $$ = &ast.DatabaseOption{ 4264 // offset trick, enums are identical but of different type 4265 Tp: ast.DatabaseOptionType(placementOptions.Tp), 4266 Value: placementOptions.StrValue, 4267 UintValue: placementOptions.UintValue, 4268 } 4269 } 4270 | PlacementPolicyOption 4271 { 4272 placementOptions := $1.(*ast.PlacementOption) 4273 $$ = &ast.DatabaseOption{ 4274 // offset trick, enums are identical but of different type 4275 Tp: ast.DatabaseOptionType(placementOptions.Tp), 4276 Value: placementOptions.StrValue, 4277 UintValue: placementOptions.UintValue, 4278 } 4279 } 4280 | "SET" "TIFLASH" "REPLICA" LengthNum LocationLabelList 4281 { 4282 tiflashReplicaSpec := &ast.TiFlashReplicaSpec{ 4283 Count: $4.(uint64), 4284 Labels: $5.([]string), 4285 } 4286 $$ = &ast.DatabaseOption{ 4287 Tp: ast.DatabaseSetTiFlashReplica, 4288 TiFlashReplica: tiflashReplicaSpec, 4289 } 4290 } 4291 4292 DatabaseOptionListOpt: 4293 { 4294 $$ = []*ast.DatabaseOption{} 4295 } 4296 | DatabaseOptionList 4297 4298 DatabaseOptionList: 4299 DatabaseOption 4300 { 4301 $$ = []*ast.DatabaseOption{$1.(*ast.DatabaseOption)} 4302 } 4303 | DatabaseOptionList DatabaseOption 4304 { 4305 $$ = append($1.([]*ast.DatabaseOption), $2.(*ast.DatabaseOption)) 4306 } 4307 4308 /******************************************************************* 4309 * 4310 * Create Table Statement 4311 * 4312 * Example: 4313 * CREATE TABLE Persons 4314 * ( 4315 * P_Id int NOT NULL, 4316 * LastName varchar(255) NOT NULL, 4317 * FirstName varchar(255), 4318 * Address varchar(255), 4319 * City varchar(255), 4320 * PRIMARY KEY (P_Id) 4321 * ) 4322 *******************************************************************/ 4323 CreateTableStmt: 4324 "CREATE" OptTemporary "TABLE" IfNotExists TableName TableElementListOpt CreateTableOptionListOpt PartitionOpt DuplicateOpt AsOpt CreateTableSelectOpt OnCommitOpt 4325 { 4326 stmt := $6.(*ast.CreateTableStmt) 4327 stmt.Table = $5.(*ast.TableName) 4328 stmt.IfNotExists = $4.(bool) 4329 stmt.TemporaryKeyword = $2.(ast.TemporaryKeyword) 4330 stmt.Options = $7.([]*ast.TableOption) 4331 if $8 != nil { 4332 stmt.Partition = $8.(*ast.PartitionOptions) 4333 } 4334 stmt.OnDuplicate = $9.(ast.OnDuplicateKeyHandlingType) 4335 stmt.Select = $11.(*ast.CreateTableStmt).Select 4336 if ($12 != nil && stmt.TemporaryKeyword != ast.TemporaryGlobal) || (stmt.TemporaryKeyword == ast.TemporaryGlobal && $12 == nil) { 4337 yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together")) 4338 } else { 4339 if stmt.TemporaryKeyword == ast.TemporaryGlobal { 4340 stmt.OnCommitDelete = $12.(bool) 4341 } 4342 } 4343 $$ = stmt 4344 } 4345 | "CREATE" OptTemporary "TABLE" IfNotExists TableName LikeTableWithOrWithoutParen OnCommitOpt 4346 { 4347 tmp := &ast.CreateTableStmt{ 4348 Table: $5.(*ast.TableName), 4349 ReferTable: $6.(*ast.TableName), 4350 IfNotExists: $4.(bool), 4351 TemporaryKeyword: $2.(ast.TemporaryKeyword), 4352 } 4353 if ($7 != nil && tmp.TemporaryKeyword != ast.TemporaryGlobal) || (tmp.TemporaryKeyword == ast.TemporaryGlobal && $7 == nil) { 4354 yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together")) 4355 } else { 4356 if tmp.TemporaryKeyword == ast.TemporaryGlobal { 4357 tmp.OnCommitDelete = $7.(bool) 4358 } 4359 } 4360 $$ = tmp 4361 } 4362 4363 OnCommitOpt: 4364 { 4365 $$ = nil 4366 } 4367 | "ON" "COMMIT" "DELETE" "ROWS" 4368 { 4369 $$ = true 4370 } 4371 | "ON" "COMMIT" "PRESERVE" "ROWS" 4372 { 4373 $$ = false 4374 } 4375 4376 DefaultKwdOpt: 4377 %prec lowerThanCharsetKwd 4378 {} 4379 | "DEFAULT" 4380 4381 PartitionOpt: 4382 { 4383 $$ = nil 4384 } 4385 | "PARTITION" "BY" PartitionMethod PartitionNumOpt SubPartitionOpt PartitionDefinitionListOpt 4386 { 4387 method := $3.(*ast.PartitionMethod) 4388 method.Num = $4.(uint64) 4389 sub, _ := $5.(*ast.PartitionMethod) 4390 defs, _ := $6.([]*ast.PartitionDefinition) 4391 opt := &ast.PartitionOptions{ 4392 PartitionMethod: *method, 4393 Sub: sub, 4394 Definitions: defs, 4395 } 4396 if err := opt.Validate(); err != nil { 4397 yylex.AppendError(err) 4398 return 1 4399 } 4400 $$ = opt 4401 } 4402 4403 SubPartitionMethod: 4404 LinearOpt "KEY" PartitionKeyAlgorithmOpt '(' ColumnNameListOpt ')' 4405 { 4406 keyAlgorithm, _ := $3.(*ast.PartitionKeyAlgorithm) 4407 $$ = &ast.PartitionMethod{ 4408 Tp: model.PartitionTypeKey, 4409 Linear: len($1) != 0, 4410 ColumnNames: $5.([]*ast.ColumnName), 4411 KeyAlgorithm: keyAlgorithm, 4412 } 4413 } 4414 | LinearOpt "HASH" '(' BitExpr ')' 4415 { 4416 $$ = &ast.PartitionMethod{ 4417 Tp: model.PartitionTypeHash, 4418 Linear: len($1) != 0, 4419 Expr: $4.(ast.ExprNode), 4420 } 4421 } 4422 4423 PartitionKeyAlgorithmOpt: 4424 /* empty */ 4425 { 4426 $$ = nil 4427 } 4428 | "ALGORITHM" eq NUM 4429 { 4430 tp := getUint64FromNUM($3) 4431 if tp != 1 && tp != 2 { 4432 yylex.AppendError(ErrSyntax) 4433 return 1 4434 } 4435 $$ = &ast.PartitionKeyAlgorithm{ 4436 Type: tp, 4437 } 4438 } 4439 4440 PartitionMethod: 4441 SubPartitionMethod 4442 | "RANGE" '(' BitExpr ')' PartitionIntervalOpt 4443 { 4444 partitionInterval, _ := $5.(*ast.PartitionInterval) 4445 $$ = &ast.PartitionMethod{ 4446 Tp: model.PartitionTypeRange, 4447 Expr: $3.(ast.ExprNode), 4448 Interval: partitionInterval, 4449 } 4450 } 4451 | "RANGE" FieldsOrColumns '(' ColumnNameList ')' PartitionIntervalOpt 4452 { 4453 partitionInterval, _ := $6.(*ast.PartitionInterval) 4454 $$ = &ast.PartitionMethod{ 4455 Tp: model.PartitionTypeRange, 4456 ColumnNames: $4.([]*ast.ColumnName), 4457 Interval: partitionInterval, 4458 } 4459 } 4460 | "LIST" '(' BitExpr ')' 4461 { 4462 $$ = &ast.PartitionMethod{ 4463 Tp: model.PartitionTypeList, 4464 Expr: $3.(ast.ExprNode), 4465 } 4466 } 4467 | "LIST" FieldsOrColumns '(' ColumnNameList ')' 4468 { 4469 $$ = &ast.PartitionMethod{ 4470 Tp: model.PartitionTypeList, 4471 ColumnNames: $4.([]*ast.ColumnName), 4472 } 4473 } 4474 | "SYSTEM_TIME" "INTERVAL" Expression TimeUnit 4475 { 4476 $$ = &ast.PartitionMethod{ 4477 Tp: model.PartitionTypeSystemTime, 4478 Expr: $3.(ast.ExprNode), 4479 Unit: $4.(ast.TimeUnitType), 4480 } 4481 } 4482 | "SYSTEM_TIME" "LIMIT" LengthNum 4483 { 4484 $$ = &ast.PartitionMethod{ 4485 Tp: model.PartitionTypeSystemTime, 4486 Limit: $3.(uint64), 4487 } 4488 } 4489 | "SYSTEM_TIME" 4490 { 4491 $$ = &ast.PartitionMethod{ 4492 Tp: model.PartitionTypeSystemTime, 4493 } 4494 } 4495 4496 PartitionIntervalOpt: 4497 { 4498 $$ = nil 4499 } 4500 | "INTERVAL" '(' IntervalExpr ')' FirstAndLastPartOpt NullPartOpt MaxValPartOpt 4501 { 4502 partitionInterval := &ast.PartitionInterval{ 4503 IntervalExpr: $3.(ast.PartitionIntervalExpr), 4504 FirstRangeEnd: $5.(ast.PartitionInterval).FirstRangeEnd, 4505 LastRangeEnd: $5.(ast.PartitionInterval).LastRangeEnd, 4506 NullPart: $6.(bool), 4507 MaxValPart: $7.(bool), 4508 } 4509 startOffset := parser.yyVAL.offset 4510 endOffset := parser.yylval.offset 4511 partitionInterval.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 4512 // Needed for replacing syntactic sugar with generated partitioning definition string 4513 partitionInterval.SetOriginTextPosition(startOffset) 4514 $$ = partitionInterval 4515 } 4516 4517 IntervalExpr: 4518 BitExpr 4519 { 4520 $$ = ast.PartitionIntervalExpr{Expr: $1, TimeUnit: ast.TimeUnitInvalid} 4521 } 4522 | BitExpr TimeUnit 4523 { 4524 $$ = ast.PartitionIntervalExpr{Expr: $1, TimeUnit: $2.(ast.TimeUnitType)} 4525 } 4526 4527 NullPartOpt: 4528 { 4529 $$ = false 4530 } 4531 | "NULL" "PARTITION" 4532 { 4533 $$ = true 4534 } 4535 4536 MaxValPartOpt: 4537 { 4538 $$ = false 4539 } 4540 | "MAXVALUE" "PARTITION" 4541 { 4542 $$ = true 4543 } 4544 4545 FirstAndLastPartOpt: 4546 { 4547 $$ = ast.PartitionInterval{} // First/LastRangeEnd defaults to nil 4548 } 4549 | "FIRST" "PARTITION" "LESS" "THAN" '(' BitExpr ')' "LAST" "PARTITION" "LESS" "THAN" '(' BitExpr ')' 4550 { 4551 first := $6.(ast.ExprNode) 4552 last := $13.(ast.ExprNode) 4553 $$ = ast.PartitionInterval{ 4554 FirstRangeEnd: &first, 4555 LastRangeEnd: &last, 4556 } 4557 } 4558 4559 LinearOpt: 4560 { 4561 $$ = "" 4562 } 4563 | "LINEAR" 4564 4565 SubPartitionOpt: 4566 { 4567 $$ = nil 4568 } 4569 | "SUBPARTITION" "BY" SubPartitionMethod SubPartitionNumOpt 4570 { 4571 method := $3.(*ast.PartitionMethod) 4572 method.Num = $4.(uint64) 4573 $$ = method 4574 } 4575 4576 SubPartitionNumOpt: 4577 { 4578 $$ = uint64(0) 4579 } 4580 | "SUBPARTITIONS" LengthNum 4581 { 4582 res := $2.(uint64) 4583 if res == 0 { 4584 yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("subpartitions")) 4585 return 1 4586 } 4587 $$ = res 4588 } 4589 4590 PartitionNumOpt: 4591 { 4592 $$ = uint64(0) 4593 } 4594 | "PARTITIONS" LengthNum 4595 { 4596 res := $2.(uint64) 4597 if res == 0 { 4598 yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("partitions")) 4599 return 1 4600 } 4601 $$ = res 4602 } 4603 4604 PartitionDefinitionListOpt: 4605 /* empty */ %prec lowerThanCreateTableSelect 4606 { 4607 $$ = nil 4608 } 4609 | '(' PartitionDefinitionList ')' 4610 { 4611 $$ = $2.([]*ast.PartitionDefinition) 4612 } 4613 4614 PartitionDefinitionList: 4615 PartitionDefinition 4616 { 4617 $$ = []*ast.PartitionDefinition{$1.(*ast.PartitionDefinition)} 4618 } 4619 | PartitionDefinitionList ',' PartitionDefinition 4620 { 4621 $$ = append($1.([]*ast.PartitionDefinition), $3.(*ast.PartitionDefinition)) 4622 } 4623 4624 PartitionDefinition: 4625 "PARTITION" Identifier PartDefValuesOpt PartDefOptionList SubPartDefinitionListOpt 4626 { 4627 $$ = &ast.PartitionDefinition{ 4628 Name: model.NewCIStr($2), 4629 Clause: $3.(ast.PartitionDefinitionClause), 4630 Options: $4.([]*ast.TableOption), 4631 Sub: $5.([]*ast.SubPartitionDefinition), 4632 } 4633 } 4634 4635 SubPartDefinitionListOpt: 4636 /*empty*/ 4637 { 4638 $$ = make([]*ast.SubPartitionDefinition, 0) 4639 } 4640 | '(' SubPartDefinitionList ')' 4641 { 4642 $$ = $2 4643 } 4644 4645 SubPartDefinitionList: 4646 SubPartDefinition 4647 { 4648 $$ = []*ast.SubPartitionDefinition{$1.(*ast.SubPartitionDefinition)} 4649 } 4650 | SubPartDefinitionList ',' SubPartDefinition 4651 { 4652 list := $1.([]*ast.SubPartitionDefinition) 4653 $$ = append(list, $3.(*ast.SubPartitionDefinition)) 4654 } 4655 4656 SubPartDefinition: 4657 "SUBPARTITION" Identifier PartDefOptionList 4658 { 4659 $$ = &ast.SubPartitionDefinition{ 4660 Name: model.NewCIStr($2), 4661 Options: $3.([]*ast.TableOption), 4662 } 4663 } 4664 4665 PartDefOptionList: 4666 /*empty*/ 4667 { 4668 $$ = make([]*ast.TableOption, 0) 4669 } 4670 | PartDefOptionList PartDefOption 4671 { 4672 list := $1.([]*ast.TableOption) 4673 $$ = append(list, $2.(*ast.TableOption)) 4674 } 4675 4676 PartDefOption: 4677 "COMMENT" EqOpt stringLit 4678 { 4679 $$ = &ast.TableOption{Tp: ast.TableOptionComment, StrValue: $3} 4680 } 4681 | "ENGINE" EqOpt StringName 4682 { 4683 $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $3} 4684 } 4685 | "STORAGE" "ENGINE" EqOpt StringName 4686 { 4687 $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $4} 4688 } 4689 | "INSERT_METHOD" EqOpt StringName 4690 { 4691 $$ = &ast.TableOption{Tp: ast.TableOptionInsertMethod, StrValue: $3} 4692 } 4693 | "DATA" "DIRECTORY" EqOpt stringLit 4694 { 4695 $$ = &ast.TableOption{Tp: ast.TableOptionDataDirectory, StrValue: $4} 4696 } 4697 | "INDEX" "DIRECTORY" EqOpt stringLit 4698 { 4699 $$ = &ast.TableOption{Tp: ast.TableOptionIndexDirectory, StrValue: $4} 4700 } 4701 | "MAX_ROWS" EqOpt LengthNum 4702 { 4703 $$ = &ast.TableOption{Tp: ast.TableOptionMaxRows, UintValue: $3.(uint64)} 4704 } 4705 | "MIN_ROWS" EqOpt LengthNum 4706 { 4707 $$ = &ast.TableOption{Tp: ast.TableOptionMinRows, UintValue: $3.(uint64)} 4708 } 4709 | "TABLESPACE" EqOpt Identifier 4710 { 4711 $$ = &ast.TableOption{Tp: ast.TableOptionTablespace, StrValue: $3} 4712 } 4713 | "NODEGROUP" EqOpt LengthNum 4714 { 4715 $$ = &ast.TableOption{Tp: ast.TableOptionNodegroup, UintValue: $3.(uint64)} 4716 } 4717 | PlacementPolicyOption 4718 { 4719 placementOptions := $1.(*ast.PlacementOption) 4720 $$ = &ast.TableOption{ 4721 // offset trick, enums are identical but of different type 4722 Tp: ast.TableOptionType(placementOptions.Tp), 4723 StrValue: placementOptions.StrValue, 4724 UintValue: placementOptions.UintValue, 4725 } 4726 } 4727 4728 PartDefValuesOpt: 4729 { 4730 $$ = &ast.PartitionDefinitionClauseNone{} 4731 } 4732 | "VALUES" "LESS" "THAN" "MAXVALUE" 4733 { 4734 $$ = &ast.PartitionDefinitionClauseLessThan{ 4735 Exprs: []ast.ExprNode{&ast.MaxValueExpr{}}, 4736 } 4737 } 4738 | "VALUES" "LESS" "THAN" '(' MaxValueOrExpressionList ')' 4739 { 4740 $$ = &ast.PartitionDefinitionClauseLessThan{ 4741 Exprs: $5.([]ast.ExprNode), 4742 } 4743 } 4744 | "DEFAULT" 4745 { 4746 $$ = &ast.PartitionDefinitionClauseIn{ 4747 Values: [][]ast.ExprNode{{&ast.DefaultExpr{}}}, 4748 } 4749 } 4750 | "VALUES" "IN" '(' DefaultOrExpressionList ')' 4751 { 4752 exprs := $4.([]ast.ExprNode) 4753 values := make([][]ast.ExprNode, 0, len(exprs)) 4754 for _, expr := range exprs { 4755 if row, ok := expr.(*ast.RowExpr); ok { 4756 values = append(values, row.Values) 4757 } else { 4758 values = append(values, []ast.ExprNode{expr}) 4759 } 4760 } 4761 $$ = &ast.PartitionDefinitionClauseIn{Values: values} 4762 } 4763 | "HISTORY" 4764 { 4765 $$ = &ast.PartitionDefinitionClauseHistory{Current: false} 4766 } 4767 | "CURRENT" 4768 { 4769 $$ = &ast.PartitionDefinitionClauseHistory{Current: true} 4770 } 4771 4772 DuplicateOpt: 4773 { 4774 $$ = ast.OnDuplicateKeyHandlingError 4775 } 4776 | "IGNORE" 4777 { 4778 $$ = ast.OnDuplicateKeyHandlingIgnore 4779 } 4780 | "REPLACE" 4781 { 4782 $$ = ast.OnDuplicateKeyHandlingReplace 4783 } 4784 4785 AsOpt: 4786 {} 4787 | "AS" 4788 {} 4789 4790 CreateTableSelectOpt: 4791 /* empty */ 4792 { 4793 $$ = &ast.CreateTableStmt{} 4794 } 4795 | SetOprStmt 4796 { 4797 $$ = &ast.CreateTableStmt{Select: $1.(ast.ResultSetNode)} 4798 } 4799 | SelectStmt 4800 { 4801 $$ = &ast.CreateTableStmt{Select: $1.(ast.ResultSetNode)} 4802 } 4803 | SelectStmtWithClause 4804 { 4805 $$ = &ast.CreateTableStmt{Select: $1.(ast.ResultSetNode)} 4806 } 4807 | SubSelect 4808 { 4809 var sel ast.ResultSetNode 4810 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 4811 case *ast.SelectStmt: 4812 x.IsInBraces = true 4813 sel = x 4814 case *ast.SetOprStmt: 4815 x.IsInBraces = true 4816 sel = x 4817 } 4818 $$ = &ast.CreateTableStmt{Select: sel} 4819 } 4820 4821 CreateViewSelectOpt: 4822 SetOprStmt 4823 | SelectStmt 4824 | SelectStmtWithClause 4825 | SubSelect 4826 { 4827 var sel ast.StmtNode 4828 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 4829 case *ast.SelectStmt: 4830 x.IsInBraces = true 4831 sel = x 4832 case *ast.SetOprStmt: 4833 x.IsInBraces = true 4834 sel = x 4835 } 4836 $$ = sel 4837 } 4838 4839 LikeTableWithOrWithoutParen: 4840 "LIKE" TableName 4841 { 4842 $$ = $2 4843 } 4844 | '(' "LIKE" TableName ')' 4845 { 4846 $$ = $3 4847 } 4848 4849 /******************************************************************* 4850 * 4851 * Create View Statement 4852 * 4853 * Example: 4854 * CREATE VIEW OR REPLACE ALGORITHM = MERGE DEFINER="root@localhost" SQL SECURITY = definer view_name (col1,col2) 4855 * as select Col1,Col2 from table WITH LOCAL CHECK OPTION 4856 *******************************************************************/ 4857 CreateViewStmt: 4858 "CREATE" OrReplace ViewAlgorithm ViewDefiner ViewSQLSecurity "VIEW" ViewName ViewFieldList "AS" CreateViewSelectOpt ViewCheckOption 4859 { 4860 startOffset := parser.startOffset(&yyS[yypt-1]) 4861 selStmt := $10.(ast.StmtNode) 4862 selStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 4863 x := &ast.CreateViewStmt{ 4864 OrReplace: $2.(bool), 4865 ViewName: $7.(*ast.TableName), 4866 Select: selStmt, 4867 Algorithm: $3.(model.ViewAlgorithm), 4868 Definer: $4.(*auth.UserIdentity), 4869 Security: $5.(model.ViewSecurity), 4870 } 4871 if $8 != nil { 4872 x.Cols = $8.([]model.CIStr) 4873 } 4874 if $11 != nil { 4875 x.CheckOption = $11.(model.ViewCheckOption) 4876 endOffset := parser.startOffset(&yyS[yypt]) 4877 selStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:endOffset])) 4878 } else { 4879 x.CheckOption = model.CheckOptionCascaded 4880 } 4881 $$ = x 4882 } 4883 4884 OrReplace: 4885 /* EMPTY */ 4886 { 4887 $$ = false 4888 } 4889 | "OR" "REPLACE" 4890 { 4891 $$ = true 4892 } 4893 4894 ViewAlgorithm: 4895 /* EMPTY */ 4896 { 4897 $$ = model.AlgorithmUndefined 4898 } 4899 | "ALGORITHM" "=" "UNDEFINED" 4900 { 4901 $$ = model.AlgorithmUndefined 4902 } 4903 | "ALGORITHM" "=" "MERGE" 4904 { 4905 $$ = model.AlgorithmMerge 4906 } 4907 | "ALGORITHM" "=" "TEMPTABLE" 4908 { 4909 $$ = model.AlgorithmTemptable 4910 } 4911 4912 ViewDefiner: 4913 /* EMPTY */ 4914 { 4915 $$ = &auth.UserIdentity{CurrentUser: true} 4916 } 4917 | "DEFINER" "=" Username 4918 { 4919 $$ = $3 4920 } 4921 4922 ViewSQLSecurity: 4923 /* EMPTY */ 4924 { 4925 $$ = model.SecurityDefiner 4926 } 4927 | "SQL" "SECURITY" "DEFINER" 4928 { 4929 $$ = model.SecurityDefiner 4930 } 4931 | "SQL" "SECURITY" "INVOKER" 4932 { 4933 $$ = model.SecurityInvoker 4934 } 4935 4936 ViewName: 4937 TableName 4938 4939 ViewFieldList: 4940 /* Empty */ 4941 { 4942 $$ = nil 4943 } 4944 | '(' ColumnList ')' 4945 { 4946 $$ = $2.([]model.CIStr) 4947 } 4948 4949 ColumnList: 4950 Identifier 4951 { 4952 $$ = []model.CIStr{model.NewCIStr($1)} 4953 } 4954 | ColumnList ',' Identifier 4955 { 4956 $$ = append($1.([]model.CIStr), model.NewCIStr($3)) 4957 } 4958 4959 ViewCheckOption: 4960 /* EMPTY */ 4961 { 4962 $$ = nil 4963 } 4964 | "WITH" "CASCADED" "CHECK" "OPTION" 4965 { 4966 $$ = model.CheckOptionCascaded 4967 } 4968 | "WITH" "LOCAL" "CHECK" "OPTION" 4969 { 4970 $$ = model.CheckOptionLocal 4971 } 4972 4973 /****************************************************************** 4974 * Do statement 4975 * See https://dev.mysql.com/doc/refman/5.7/en/do.html 4976 ******************************************************************/ 4977 DoStmt: 4978 "DO" ExpressionList 4979 { 4980 $$ = &ast.DoStmt{ 4981 Exprs: $2.([]ast.ExprNode), 4982 } 4983 } 4984 4985 /******************************************************************* 4986 * 4987 * Delete Statement 4988 * 4989 *******************************************************************/ 4990 DeleteWithoutUsingStmt: 4991 "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt WhereClauseOptional OrderByOptional LimitClause 4992 { 4993 // Single Table 4994 tn := $7.(*ast.TableName) 4995 tn.IndexHints = $10.([]*ast.IndexHint) 4996 tn.PartitionNames = $8.([]model.CIStr) 4997 join := &ast.Join{Left: &ast.TableSource{Source: tn, AsName: $9.(model.CIStr)}, Right: nil} 4998 x := &ast.DeleteStmt{ 4999 TableRefs: &ast.TableRefsClause{TableRefs: join}, 5000 Priority: $3.(mysql.PriorityEnum), 5001 Quick: $4.(bool), 5002 IgnoreErr: $5.(bool), 5003 } 5004 if $2 != nil { 5005 x.TableHints = $2.([]*ast.TableOptimizerHint) 5006 } 5007 if $11 != nil { 5008 x.Where = $11.(ast.ExprNode) 5009 } 5010 if $12 != nil { 5011 x.Order = $12.(*ast.OrderByClause) 5012 } 5013 if $13 != nil { 5014 x.Limit = $13.(*ast.Limit) 5015 } 5016 5017 $$ = x 5018 } 5019 | "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional TableAliasRefList "FROM" TableRefs WhereClauseOptional 5020 { 5021 // Multiple Table 5022 x := &ast.DeleteStmt{ 5023 Priority: $3.(mysql.PriorityEnum), 5024 Quick: $4.(bool), 5025 IgnoreErr: $5.(bool), 5026 IsMultiTable: true, 5027 BeforeFrom: true, 5028 Tables: &ast.DeleteTableList{Tables: $6.([]*ast.TableName)}, 5029 TableRefs: &ast.TableRefsClause{TableRefs: $8.(*ast.Join)}, 5030 } 5031 if $2 != nil { 5032 x.TableHints = $2.([]*ast.TableOptimizerHint) 5033 } 5034 if $9 != nil { 5035 x.Where = $9.(ast.ExprNode) 5036 } 5037 $$ = x 5038 } 5039 5040 DeleteWithUsingStmt: 5041 "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableAliasRefList "USING" TableRefs WhereClauseOptional 5042 { 5043 // Multiple Table 5044 x := &ast.DeleteStmt{ 5045 Priority: $3.(mysql.PriorityEnum), 5046 Quick: $4.(bool), 5047 IgnoreErr: $5.(bool), 5048 IsMultiTable: true, 5049 Tables: &ast.DeleteTableList{Tables: $7.([]*ast.TableName)}, 5050 TableRefs: &ast.TableRefsClause{TableRefs: $9.(*ast.Join)}, 5051 } 5052 if $2 != nil { 5053 x.TableHints = $2.([]*ast.TableOptimizerHint) 5054 } 5055 if $10 != nil { 5056 x.Where = $10.(ast.ExprNode) 5057 } 5058 $$ = x 5059 } 5060 5061 DeleteFromStmt: 5062 DeleteWithoutUsingStmt 5063 | DeleteWithUsingStmt 5064 | WithClause DeleteWithoutUsingStmt 5065 { 5066 d := $2.(*ast.DeleteStmt) 5067 d.With = $1.(*ast.WithClause) 5068 $$ = d 5069 } 5070 | WithClause DeleteWithUsingStmt 5071 { 5072 d := $2.(*ast.DeleteStmt) 5073 d.With = $1.(*ast.WithClause) 5074 $$ = d 5075 } 5076 5077 DatabaseSym: 5078 "DATABASE" 5079 5080 DropDatabaseStmt: 5081 "DROP" DatabaseSym IfExists DBName 5082 { 5083 $$ = &ast.DropDatabaseStmt{IfExists: $3.(bool), Name: model.NewCIStr($4)} 5084 } 5085 5086 /****************************************************************** 5087 * Drop Index Statement 5088 * See https://dev.mysql.com/doc/refman/8.0/en/drop-index.html 5089 * 5090 * DROP INDEX index_name ON tbl_name 5091 * [algorithm_option | lock_option] ... 5092 * 5093 * algorithm_option: 5094 * ALGORITHM [=] {DEFAULT|INPLACE|COPY} 5095 * 5096 * lock_option: 5097 * LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} 5098 ******************************************************************/ 5099 DropIndexStmt: 5100 "DROP" "INDEX" IfExists Identifier "ON" TableName IndexLockAndAlgorithmOpt 5101 { 5102 var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm 5103 if $7 != nil { 5104 indexLockAndAlgorithm = $7.(*ast.IndexLockAndAlgorithm) 5105 if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault { 5106 indexLockAndAlgorithm = nil 5107 } 5108 } 5109 $$ = &ast.DropIndexStmt{IfExists: $3.(bool), IndexName: $4, Table: $6.(*ast.TableName), LockAlg: indexLockAndAlgorithm} 5110 } 5111 | "DROP" "HYPO" "INDEX" IfExists Identifier "ON" TableName 5112 { 5113 $$ = &ast.DropIndexStmt{IfExists: $4.(bool), IndexName: $5, Table: $7.(*ast.TableName), IsHypo: true} 5114 } 5115 5116 DropTableStmt: 5117 "DROP" OptTemporary TableOrTables IfExists TableNameList RestrictOrCascadeOpt 5118 { 5119 $$ = &ast.DropTableStmt{IfExists: $4.(bool), Tables: $5.([]*ast.TableName), IsView: false, TemporaryKeyword: $2.(ast.TemporaryKeyword)} 5120 } 5121 5122 OptTemporary: 5123 /* empty */ 5124 { 5125 $$ = ast.TemporaryNone 5126 } 5127 | "TEMPORARY" 5128 { 5129 $$ = ast.TemporaryLocal 5130 } 5131 | "GLOBAL" "TEMPORARY" 5132 { 5133 $$ = ast.TemporaryGlobal 5134 } 5135 5136 DropViewStmt: 5137 "DROP" "VIEW" TableNameList RestrictOrCascadeOpt 5138 { 5139 $$ = &ast.DropTableStmt{Tables: $3.([]*ast.TableName), IsView: true} 5140 } 5141 | "DROP" "VIEW" "IF" "EXISTS" TableNameList RestrictOrCascadeOpt 5142 { 5143 $$ = &ast.DropTableStmt{IfExists: true, Tables: $5.([]*ast.TableName), IsView: true} 5144 } 5145 5146 DropUserStmt: 5147 "DROP" "USER" UsernameList 5148 { 5149 $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: false, UserList: $3.([]*auth.UserIdentity)} 5150 } 5151 | "DROP" "USER" "IF" "EXISTS" UsernameList 5152 { 5153 $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: true, UserList: $5.([]*auth.UserIdentity)} 5154 } 5155 5156 DropRoleStmt: 5157 "DROP" "ROLE" RolenameList 5158 { 5159 tmp := make([]*auth.UserIdentity, 0, 10) 5160 roleList := $3.([]*auth.RoleIdentity) 5161 for _, r := range roleList { 5162 tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname}) 5163 } 5164 $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: false, UserList: tmp} 5165 } 5166 | "DROP" "ROLE" "IF" "EXISTS" RolenameList 5167 { 5168 tmp := make([]*auth.UserIdentity, 0, 10) 5169 roleList := $5.([]*auth.RoleIdentity) 5170 for _, r := range roleList { 5171 tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname}) 5172 } 5173 $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: true, UserList: tmp} 5174 } 5175 5176 DropStatsStmt: 5177 "DROP" "STATS" TableNameList 5178 { 5179 $$ = &ast.DropStatsStmt{Tables: $3.([]*ast.TableName)} 5180 } 5181 | "DROP" "STATS" TableName "PARTITION" PartitionNameList 5182 { 5183 yylex.AppendError(ErrWarnDeprecatedSyntaxNoReplacement.FastGenByArgs("'DROP STATS ... PARTITION ...'", "")) 5184 parser.lastErrorAsWarn() 5185 $$ = &ast.DropStatsStmt{ 5186 Tables: []*ast.TableName{$3.(*ast.TableName)}, 5187 PartitionNames: $5.([]model.CIStr), 5188 } 5189 } 5190 | "DROP" "STATS" TableName "GLOBAL" 5191 { 5192 yylex.AppendError(ErrWarnDeprecatedSyntax.FastGenByArgs("DROP STATS ... GLOBAL", "DROP STATS ...")) 5193 parser.lastErrorAsWarn() 5194 $$ = &ast.DropStatsStmt{ 5195 Tables: []*ast.TableName{$3.(*ast.TableName)}, 5196 IsGlobalStats: true, 5197 } 5198 } 5199 5200 RestrictOrCascadeOpt: 5201 {} 5202 | "RESTRICT" 5203 | "CASCADE" 5204 5205 TableOrTables: 5206 "TABLE" 5207 | "TABLES" 5208 5209 EqOpt: 5210 {} 5211 | eq 5212 5213 EmptyStmt: 5214 /* EMPTY */ 5215 { 5216 $$ = nil 5217 } 5218 5219 TraceStmt: 5220 "TRACE" TraceableStmt 5221 { 5222 $$ = &ast.TraceStmt{ 5223 Stmt: $2, 5224 Format: "row", 5225 TracePlan: false, 5226 } 5227 startOffset := parser.startOffset(&yyS[yypt]) 5228 $2.SetText(parser.lexer.client, string(parser.src[startOffset:])) 5229 } 5230 | "TRACE" "FORMAT" "=" stringLit TraceableStmt 5231 { 5232 $$ = &ast.TraceStmt{ 5233 Stmt: $5, 5234 Format: $4, 5235 TracePlan: false, 5236 } 5237 startOffset := parser.startOffset(&yyS[yypt]) 5238 $5.SetText(parser.lexer.client, string(parser.src[startOffset:])) 5239 } 5240 | "TRACE" "PLAN" TraceableStmt 5241 { 5242 $$ = &ast.TraceStmt{ 5243 Stmt: $3, 5244 TracePlan: true, 5245 } 5246 startOffset := parser.startOffset(&yyS[yypt]) 5247 $3.SetText(parser.lexer.client, string(parser.src[startOffset:])) 5248 } 5249 | "TRACE" "PLAN" "TARGET" "=" stringLit TraceableStmt 5250 { 5251 $$ = &ast.TraceStmt{ 5252 Stmt: $6, 5253 TracePlan: true, 5254 TracePlanTarget: $5, 5255 } 5256 startOffset := parser.startOffset(&yyS[yypt]) 5257 $6.SetText(parser.lexer.client, string(parser.src[startOffset:])) 5258 } 5259 5260 ExplainSym: 5261 "EXPLAIN" 5262 | "DESCRIBE" 5263 | "DESC" 5264 5265 ExplainStmt: 5266 ExplainSym TableName 5267 { 5268 $$ = &ast.ExplainStmt{ 5269 Stmt: &ast.ShowStmt{ 5270 Tp: ast.ShowColumns, 5271 Table: $2.(*ast.TableName), 5272 }, 5273 } 5274 } 5275 | ExplainSym TableName ColumnName 5276 { 5277 $$ = &ast.ExplainStmt{ 5278 Stmt: &ast.ShowStmt{ 5279 Tp: ast.ShowColumns, 5280 Table: $2.(*ast.TableName), 5281 Column: $3.(*ast.ColumnName), 5282 }, 5283 } 5284 } 5285 | ExplainSym ExplainableStmt 5286 { 5287 $$ = &ast.ExplainStmt{ 5288 Stmt: $2, 5289 Format: "row", 5290 } 5291 } 5292 | ExplainSym "FOR" "CONNECTION" NUM 5293 { 5294 $$ = &ast.ExplainForStmt{ 5295 Format: "row", 5296 ConnectionID: getUint64FromNUM($4), 5297 } 5298 } 5299 | ExplainSym "FORMAT" "=" stringLit "FOR" "CONNECTION" NUM 5300 { 5301 $$ = &ast.ExplainForStmt{ 5302 Format: $4, 5303 ConnectionID: getUint64FromNUM($7), 5304 } 5305 } 5306 | ExplainSym "FORMAT" "=" stringLit ExplainableStmt 5307 { 5308 $$ = &ast.ExplainStmt{ 5309 Stmt: $5, 5310 Format: $4, 5311 } 5312 } 5313 | ExplainSym "FORMAT" "=" ExplainFormatType "FOR" "CONNECTION" NUM 5314 { 5315 $$ = &ast.ExplainForStmt{ 5316 Format: $4, 5317 ConnectionID: getUint64FromNUM($7), 5318 } 5319 } 5320 | ExplainSym "FORMAT" "=" ExplainFormatType ExplainableStmt 5321 { 5322 $$ = &ast.ExplainStmt{ 5323 Stmt: $5, 5324 Format: $4, 5325 } 5326 } 5327 | ExplainSym "ANALYZE" ExplainableStmt 5328 { 5329 $$ = &ast.ExplainStmt{ 5330 Stmt: $3, 5331 Format: "row", 5332 Analyze: true, 5333 } 5334 } 5335 | ExplainSym "ANALYZE" "FORMAT" "=" ExplainFormatType ExplainableStmt 5336 { 5337 $$ = &ast.ExplainStmt{ 5338 Stmt: $6, 5339 Format: $5, 5340 Analyze: true, 5341 } 5342 } 5343 | ExplainSym "ANALYZE" "FORMAT" "=" stringLit ExplainableStmt 5344 { 5345 $$ = &ast.ExplainStmt{ 5346 Stmt: $6, 5347 Format: $5, 5348 Analyze: true, 5349 } 5350 } 5351 5352 ExplainFormatType: 5353 "TRADITIONAL" 5354 | "JSON" 5355 | "ROW" 5356 | "DOT" 5357 | "BRIEF" 5358 | "VERBOSE" 5359 | "TRUE_CARD_COST" 5360 | "TIDB_JSON" 5361 5362 SavepointStmt: 5363 "SAVEPOINT" Identifier 5364 { 5365 $$ = &ast.SavepointStmt{Name: $2} 5366 } 5367 5368 ReleaseSavepointStmt: 5369 "RELEASE" "SAVEPOINT" Identifier 5370 { 5371 $$ = &ast.ReleaseSavepointStmt{Name: $3} 5372 } 5373 5374 /******************************************************************* 5375 * Backup / restore / import statements 5376 * 5377 * BACKUP DATABASE [ * | db1, db2, db3 ] TO 'scheme://location' [ options... ] 5378 * BACKUP TABLE [ db1.tbl1, db2.tbl2 ] TO 'scheme://location' [ options... ] 5379 * RESTORE DATABASE [ * | db1, db2, db3 ] FROM 'scheme://location' [ options... ] 5380 * RESTORE TABLE [ db1.tbl1, db2.tbl2 ] FROM 'scheme://location' [ options... ] 5381 */ 5382 BRIEStmt: 5383 "BACKUP" BRIETables "TO" stringLit BRIEOptions 5384 { 5385 stmt := $2.(*ast.BRIEStmt) 5386 stmt.Kind = ast.BRIEKindBackup 5387 stmt.Storage = $4 5388 stmt.Options = $5.([]*ast.BRIEOption) 5389 $$ = stmt 5390 } 5391 | "BACKUP" "LOGS" "TO" stringLit BRIEOptions 5392 { 5393 stmt := &ast.BRIEStmt{} 5394 stmt.Kind = ast.BRIEKindStreamStart 5395 stmt.Storage = $4 5396 stmt.Options = $5.([]*ast.BRIEOption) 5397 $$ = stmt 5398 } 5399 | "STOP" "BACKUP" "LOGS" 5400 { 5401 stmt := &ast.BRIEStmt{} 5402 stmt.Kind = ast.BRIEKindStreamStop 5403 $$ = stmt 5404 } 5405 | "PAUSE" "BACKUP" "LOGS" BRIEOptions 5406 { 5407 stmt := &ast.BRIEStmt{} 5408 stmt.Kind = ast.BRIEKindStreamPause 5409 stmt.Options = $4.([]*ast.BRIEOption) 5410 $$ = stmt 5411 } 5412 | "RESUME" "BACKUP" "LOGS" 5413 { 5414 stmt := &ast.BRIEStmt{} 5415 stmt.Kind = ast.BRIEKindStreamResume 5416 $$ = stmt 5417 } 5418 | "PURGE" "BACKUP" "LOGS" "FROM" stringLit BRIEOptions 5419 { 5420 stmt := &ast.BRIEStmt{} 5421 stmt.Kind = ast.BRIEKindStreamPurge 5422 stmt.Storage = $5 5423 stmt.Options = $6.([]*ast.BRIEOption) 5424 $$ = stmt 5425 } 5426 | "SHOW" "BACKUP" "LOGS" "STATUS" 5427 { 5428 stmt := &ast.BRIEStmt{} 5429 stmt.Kind = ast.BRIEKindStreamStatus 5430 $$ = stmt 5431 } 5432 | "SHOW" "BACKUP" "LOGS" "METADATA" "FROM" stringLit 5433 { 5434 stmt := &ast.BRIEStmt{} 5435 stmt.Kind = ast.BRIEKindStreamMetaData 5436 stmt.Storage = $6 5437 $$ = stmt 5438 } 5439 | "SHOW" "BR" "JOB" Int64Num 5440 { 5441 stmt := &ast.BRIEStmt{} 5442 stmt.Kind = ast.BRIEKindShowJob 5443 stmt.JobID = $4.(int64) 5444 $$ = stmt 5445 } 5446 | "SHOW" "BR" "JOB" "QUERY" Int64Num 5447 { 5448 stmt := &ast.BRIEStmt{} 5449 stmt.Kind = ast.BRIEKindShowQuery 5450 stmt.JobID = $5.(int64) 5451 $$ = stmt 5452 } 5453 | "CANCEL" "BR" "JOB" Int64Num 5454 { 5455 stmt := &ast.BRIEStmt{} 5456 stmt.Kind = ast.BRIEKindCancelJob 5457 stmt.JobID = $4.(int64) 5458 $$ = stmt 5459 } 5460 | "SHOW" "BACKUP" "METADATA" "FROM" stringLit 5461 { 5462 stmt := &ast.BRIEStmt{} 5463 stmt.Kind = ast.BRIEKindShowBackupMeta 5464 stmt.Storage = $5 5465 $$ = stmt 5466 } 5467 | "RESTORE" BRIETables "FROM" stringLit BRIEOptions 5468 { 5469 stmt := $2.(*ast.BRIEStmt) 5470 stmt.Kind = ast.BRIEKindRestore 5471 stmt.Storage = $4 5472 stmt.Options = $5.([]*ast.BRIEOption) 5473 $$ = stmt 5474 } 5475 | "RESTORE" "POINT" "FROM" stringLit BRIEOptions 5476 { 5477 stmt := &ast.BRIEStmt{} 5478 stmt.Kind = ast.BRIEKindRestorePIT 5479 stmt.Storage = $4 5480 stmt.Options = $5.([]*ast.BRIEOption) 5481 $$ = stmt 5482 } 5483 5484 BRIETables: 5485 DatabaseSym '*' 5486 { 5487 $$ = &ast.BRIEStmt{} 5488 } 5489 | DatabaseSym DBNameList 5490 { 5491 $$ = &ast.BRIEStmt{Schemas: $2.([]string)} 5492 } 5493 | "TABLE" TableNameList 5494 { 5495 $$ = &ast.BRIEStmt{Tables: $2.([]*ast.TableName)} 5496 } 5497 5498 DBNameList: 5499 DBName 5500 { 5501 $$ = []string{$1} 5502 } 5503 | DBNameList ',' DBName 5504 { 5505 $$ = append($1.([]string), $3) 5506 } 5507 5508 BRIEOptions: 5509 %prec empty 5510 { 5511 $$ = []*ast.BRIEOption{} 5512 } 5513 | BRIEOptions BRIEOption 5514 { 5515 $$ = append($1.([]*ast.BRIEOption), $2.(*ast.BRIEOption)) 5516 } 5517 5518 BRIEIntegerOptionName: 5519 "CONCURRENCY" 5520 { 5521 $$ = ast.BRIEOptionConcurrency 5522 } 5523 | "RESUME" 5524 { 5525 $$ = ast.BRIEOptionResume 5526 } 5527 5528 BRIEBooleanOptionName: 5529 "SEND_CREDENTIALS_TO_TIKV" 5530 { 5531 $$ = ast.BRIEOptionSendCreds 5532 } 5533 | "ONLINE" 5534 { 5535 $$ = ast.BRIEOptionOnline 5536 } 5537 | "CHECKPOINT" 5538 { 5539 $$ = ast.BRIEOptionCheckpoint 5540 } 5541 | "SKIP_SCHEMA_FILES" 5542 { 5543 $$ = ast.BRIEOptionSkipSchemaFiles 5544 } 5545 | "STRICT_FORMAT" 5546 { 5547 $$ = ast.BRIEOptionStrictFormat 5548 } 5549 | "CSV_NOT_NULL" 5550 { 5551 $$ = ast.BRIEOptionCSVNotNull 5552 } 5553 | "CSV_BACKSLASH_ESCAPE" 5554 { 5555 $$ = ast.BRIEOptionCSVBackslashEscape 5556 } 5557 | "CSV_TRIM_LAST_SEPARATORS" 5558 { 5559 $$ = ast.BRIEOptionCSVTrimLastSeparators 5560 } 5561 5562 BRIEStringOptionName: 5563 "TIKV_IMPORTER" 5564 { 5565 $$ = ast.BRIEOptionTiKVImporter 5566 } 5567 | "CSV_SEPARATOR" 5568 { 5569 $$ = ast.BRIEOptionCSVSeparator 5570 } 5571 | "CSV_DELIMITER" 5572 { 5573 $$ = ast.BRIEOptionCSVDelimiter 5574 } 5575 | "CSV_NULL" 5576 { 5577 $$ = ast.BRIEOptionCSVNull 5578 } 5579 5580 BRIEKeywordOptionName: 5581 "BACKEND" 5582 { 5583 $$ = ast.BRIEOptionBackend 5584 } 5585 | "ON_DUPLICATE" 5586 { 5587 $$ = ast.BRIEOptionOnDuplicate 5588 } 5589 | "ON" "DUPLICATE" 5590 { 5591 $$ = ast.BRIEOptionOnDuplicate 5592 } 5593 5594 BRIEOption: 5595 BRIEIntegerOptionName EqOpt LengthNum 5596 { 5597 $$ = &ast.BRIEOption{ 5598 Tp: $1.(ast.BRIEOptionType), 5599 UintValue: $3.(uint64), 5600 } 5601 } 5602 | BRIEBooleanOptionName EqOpt Boolean 5603 { 5604 value := uint64(0) 5605 if $3.(bool) { 5606 value = 1 5607 } 5608 $$ = &ast.BRIEOption{ 5609 Tp: $1.(ast.BRIEOptionType), 5610 UintValue: value, 5611 } 5612 } 5613 | BRIEStringOptionName EqOpt stringLit 5614 { 5615 $$ = &ast.BRIEOption{ 5616 Tp: $1.(ast.BRIEOptionType), 5617 StrValue: $3, 5618 } 5619 } 5620 | BRIEKeywordOptionName EqOpt StringNameOrBRIEOptionKeyword 5621 { 5622 $$ = &ast.BRIEOption{ 5623 Tp: $1.(ast.BRIEOptionType), 5624 StrValue: strings.ToLower($3), 5625 } 5626 } 5627 | "SNAPSHOT" EqOpt LengthNum TimestampUnit "AGO" 5628 { 5629 unit, err := $4.(ast.TimeUnitType).Duration() 5630 if err != nil { 5631 yylex.AppendError(err) 5632 return 1 5633 } 5634 // TODO: check overflow? 5635 $$ = &ast.BRIEOption{ 5636 Tp: ast.BRIEOptionBackupTimeAgo, 5637 UintValue: $3.(uint64) * uint64(unit), 5638 } 5639 } 5640 | "SNAPSHOT" EqOpt stringLit 5641 // not including this into BRIEStringOptionName to avoid shift/reduce conflict 5642 { 5643 $$ = &ast.BRIEOption{ 5644 Tp: ast.BRIEOptionBackupTS, 5645 StrValue: $3, 5646 } 5647 } 5648 | "SNAPSHOT" EqOpt LengthNum 5649 // not including this into BRIEIntegerOptionName to avoid shift/reduce conflict 5650 { 5651 $$ = &ast.BRIEOption{ 5652 Tp: ast.BRIEOptionBackupTSO, 5653 UintValue: $3.(uint64), 5654 } 5655 } 5656 | "LAST_BACKUP" EqOpt stringLit 5657 { 5658 $$ = &ast.BRIEOption{ 5659 Tp: ast.BRIEOptionLastBackupTS, 5660 StrValue: $3, 5661 } 5662 } 5663 | "LAST_BACKUP" EqOpt LengthNum 5664 { 5665 $$ = &ast.BRIEOption{ 5666 Tp: ast.BRIEOptionLastBackupTSO, 5667 UintValue: $3.(uint64), 5668 } 5669 } 5670 | "RATE_LIMIT" EqOpt LengthNum "MB" '/' "SECOND" 5671 { 5672 // TODO: check overflow? 5673 $$ = &ast.BRIEOption{ 5674 Tp: ast.BRIEOptionRateLimit, 5675 UintValue: $3.(uint64) * 1048576, 5676 } 5677 } 5678 | "CSV_HEADER" EqOpt FieldsOrColumns 5679 { 5680 $$ = &ast.BRIEOption{ 5681 Tp: ast.BRIEOptionCSVHeader, 5682 UintValue: ast.BRIECSVHeaderIsColumns, 5683 } 5684 } 5685 | "CSV_HEADER" EqOpt LengthNum 5686 { 5687 $$ = &ast.BRIEOption{ 5688 Tp: ast.BRIEOptionCSVHeader, 5689 UintValue: $3.(uint64), 5690 } 5691 } 5692 | "CHECKSUM" EqOpt Boolean 5693 { 5694 value := uint64(0) 5695 if $3.(bool) { 5696 value = 1 5697 } 5698 $$ = &ast.BRIEOption{ 5699 Tp: ast.BRIEOptionChecksum, 5700 UintValue: value, 5701 } 5702 } 5703 | "CHECKSUM" EqOpt OptionLevel 5704 { 5705 $$ = &ast.BRIEOption{ 5706 Tp: ast.BRIEOptionChecksum, 5707 UintValue: uint64($3.(ast.BRIEOptionLevel)), 5708 } 5709 } 5710 | "ANALYZE" EqOpt Boolean 5711 { 5712 value := uint64(0) 5713 if $3.(bool) { 5714 value = 1 5715 } 5716 $$ = &ast.BRIEOption{ 5717 Tp: ast.BRIEOptionAnalyze, 5718 UintValue: value, 5719 } 5720 } 5721 | "ANALYZE" EqOpt OptionLevel 5722 { 5723 $$ = &ast.BRIEOption{ 5724 Tp: ast.BRIEOptionAnalyze, 5725 UintValue: uint64($3.(ast.BRIEOptionLevel)), 5726 } 5727 } 5728 | "FULL_BACKUP_STORAGE" EqOpt stringLit 5729 { 5730 $$ = &ast.BRIEOption{ 5731 Tp: ast.BRIEOptionFullBackupStorage, 5732 StrValue: $3, 5733 } 5734 } 5735 | "RESTORED_TS" EqOpt stringLit 5736 { 5737 $$ = &ast.BRIEOption{ 5738 Tp: ast.BRIEOptionRestoredTS, 5739 StrValue: $3, 5740 } 5741 } 5742 | "START_TS" EqOpt stringLit 5743 { 5744 $$ = &ast.BRIEOption{ 5745 Tp: ast.BRIEOptionStartTS, 5746 StrValue: $3, 5747 } 5748 } 5749 | "UNTIL_TS" EqOpt stringLit 5750 { 5751 $$ = &ast.BRIEOption{ 5752 Tp: ast.BRIEOptionUntilTS, 5753 StrValue: $3, 5754 } 5755 } 5756 | "GC_TTL" EqOpt stringLit 5757 { 5758 $$ = &ast.BRIEOption{ 5759 Tp: ast.BRIEOptionGCTTL, 5760 StrValue: $3, 5761 } 5762 } 5763 5764 LengthNum: 5765 NUM 5766 { 5767 $$ = getUint64FromNUM($1) 5768 } 5769 5770 Int64Num: 5771 NUM 5772 { 5773 v, rangeErrMsg := getInt64FromNUM($1) 5774 if len(rangeErrMsg) != 0 { 5775 yylex.AppendError(yylex.Errorf(rangeErrMsg)) 5776 return 1 5777 } 5778 $$ = v 5779 } 5780 5781 NUM: 5782 intLit 5783 5784 Boolean: 5785 NUM 5786 { 5787 $$ = $1.(int64) != 0 5788 } 5789 | "FALSE" 5790 { 5791 $$ = false 5792 } 5793 | "TRUE" 5794 { 5795 $$ = true 5796 } 5797 5798 OptionLevel: 5799 "OFF" 5800 { 5801 $$ = ast.BRIEOptionLevelOff 5802 } 5803 | "OPTIONAL" 5804 { 5805 $$ = ast.BRIEOptionLevelOptional 5806 } 5807 | "REQUIRED" 5808 { 5809 $$ = ast.BRIEOptionLevelRequired 5810 } 5811 5812 PauseLoadDataStmt: 5813 "PAUSE" "LOAD" "DATA" "JOB" Int64Num 5814 { 5815 $$ = &ast.LoadDataActionStmt{ 5816 Tp: ast.LoadDataPause, 5817 JobID: $5.(int64), 5818 } 5819 } 5820 5821 ResumeLoadDataStmt: 5822 "RESUME" "LOAD" "DATA" "JOB" Int64Num 5823 { 5824 $$ = &ast.LoadDataActionStmt{ 5825 Tp: ast.LoadDataResume, 5826 JobID: $5.(int64), 5827 } 5828 } 5829 5830 CancelImportStmt: 5831 "CANCEL" "IMPORT" "JOB" Int64Num 5832 { 5833 $$ = &ast.ImportIntoActionStmt{ 5834 Tp: ast.ImportIntoCancel, 5835 JobID: $4.(int64), 5836 } 5837 } 5838 5839 DropLoadDataStmt: 5840 "DROP" "LOAD" "DATA" "JOB" Int64Num 5841 { 5842 $$ = &ast.LoadDataActionStmt{ 5843 Tp: ast.LoadDataDrop, 5844 JobID: $5.(int64), 5845 } 5846 } 5847 5848 Expression: 5849 singleAtIdentifier assignmentEq Expression %prec assignmentEq 5850 { 5851 v := $1 5852 v = strings.TrimPrefix(v, "@") 5853 $$ = &ast.VariableExpr{ 5854 Name: v, 5855 IsGlobal: false, 5856 IsSystem: false, 5857 Value: $3, 5858 } 5859 } 5860 | Expression logOr Expression %prec pipes 5861 { 5862 $$ = &ast.BinaryOperationExpr{Op: opcode.LogicOr, L: $1, R: $3} 5863 } 5864 | Expression "XOR" Expression %prec xor 5865 { 5866 $$ = &ast.BinaryOperationExpr{Op: opcode.LogicXor, L: $1, R: $3} 5867 } 5868 | Expression logAnd Expression %prec andand 5869 { 5870 $$ = &ast.BinaryOperationExpr{Op: opcode.LogicAnd, L: $1, R: $3} 5871 } 5872 | "NOT" Expression %prec not 5873 { 5874 expr, ok := $2.(*ast.ExistsSubqueryExpr) 5875 if ok { 5876 expr.Not = !expr.Not 5877 $$ = $2 5878 } else { 5879 $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2} 5880 } 5881 } 5882 | "MATCH" '(' ColumnNameList ')' "AGAINST" '(' BitExpr FulltextSearchModifierOpt ')' 5883 { 5884 $$ = &ast.MatchAgainst{ 5885 ColumnNames: $3.([]*ast.ColumnName), 5886 Against: $7, 5887 Modifier: ast.FulltextSearchModifier($8.(int)), 5888 } 5889 } 5890 | BoolPri IsOrNotOp trueKwd %prec is 5891 { 5892 $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(1)} 5893 } 5894 | BoolPri IsOrNotOp falseKwd %prec is 5895 { 5896 $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(0)} 5897 } 5898 | BoolPri IsOrNotOp "UNKNOWN" %prec is 5899 { 5900 /* https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_is */ 5901 $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)} 5902 } 5903 | BoolPri 5904 5905 DefaultOrExpression: 5906 "DEFAULT" 5907 { 5908 $$ = &ast.DefaultExpr{} 5909 } 5910 | BitExpr 5911 5912 MaxValueOrExpression: 5913 "MAXVALUE" 5914 { 5915 $$ = &ast.MaxValueExpr{} 5916 } 5917 | BitExpr 5918 5919 FulltextSearchModifierOpt: 5920 /* empty */ 5921 { 5922 $$ = ast.FulltextSearchModifierNaturalLanguageMode 5923 } 5924 | "IN" "NATURAL" "LANGUAGE" "MODE" 5925 { 5926 $$ = ast.FulltextSearchModifierNaturalLanguageMode 5927 } 5928 | "IN" "NATURAL" "LANGUAGE" "MODE" "WITH" "QUERY" "EXPANSION" 5929 { 5930 $$ = ast.FulltextSearchModifierNaturalLanguageMode | ast.FulltextSearchModifierWithQueryExpansion 5931 } 5932 | "IN" "BOOLEAN" "MODE" 5933 { 5934 $$ = ast.FulltextSearchModifierBooleanMode 5935 } 5936 | "WITH" "QUERY" "EXPANSION" 5937 { 5938 $$ = ast.FulltextSearchModifierWithQueryExpansion 5939 } 5940 5941 logOr: 5942 pipesAsOr 5943 | "OR" 5944 5945 logAnd: 5946 "&&" 5947 | "AND" 5948 5949 ExpressionList: 5950 Expression 5951 { 5952 $$ = []ast.ExprNode{$1} 5953 } 5954 | ExpressionList ',' Expression 5955 { 5956 $$ = append($1.([]ast.ExprNode), $3) 5957 } 5958 5959 MaxValueOrExpressionList: 5960 MaxValueOrExpression 5961 { 5962 $$ = []ast.ExprNode{$1} 5963 } 5964 | MaxValueOrExpressionList ',' MaxValueOrExpression 5965 { 5966 $$ = append($1.([]ast.ExprNode), $3) 5967 } 5968 5969 DefaultOrExpressionList: 5970 DefaultOrExpression 5971 { 5972 $$ = []ast.ExprNode{$1} 5973 } 5974 | DefaultOrExpressionList ',' DefaultOrExpression 5975 { 5976 $$ = append($1.([]ast.ExprNode), $3) 5977 } 5978 5979 ExpressionListOpt: 5980 { 5981 $$ = []ast.ExprNode{} 5982 } 5983 | ExpressionList 5984 5985 FuncDatetimePrecListOpt: 5986 { 5987 $$ = []ast.ExprNode{} 5988 } 5989 | FuncDatetimePrecList 5990 5991 FuncDatetimePrecList: 5992 intLit 5993 { 5994 expr := ast.NewValueExpr($1, parser.charset, parser.collation) 5995 $$ = []ast.ExprNode{expr} 5996 } 5997 5998 BoolPri: 5999 BoolPri IsOrNotOp "NULL" %prec is 6000 { 6001 $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)} 6002 } 6003 | BoolPri CompareOp PredicateExpr %prec eq 6004 { 6005 $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: $3} 6006 } 6007 | BoolPri CompareOp AnyOrAll SubSelect %prec eq 6008 { 6009 sq := $4.(*ast.SubqueryExpr) 6010 sq.MultiRows = true 6011 $$ = &ast.CompareSubqueryExpr{Op: $2.(opcode.Op), L: $1, R: sq, All: $3.(bool)} 6012 } 6013 | BoolPri CompareOp singleAtIdentifier assignmentEq PredicateExpr %prec assignmentEq 6014 { 6015 v := $3 6016 v = strings.TrimPrefix(v, "@") 6017 variable := &ast.VariableExpr{ 6018 Name: v, 6019 IsGlobal: false, 6020 IsSystem: false, 6021 Value: $5, 6022 } 6023 $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: variable} 6024 } 6025 | PredicateExpr 6026 6027 CompareOp: 6028 ">=" 6029 { 6030 $$ = opcode.GE 6031 } 6032 | '>' 6033 { 6034 $$ = opcode.GT 6035 } 6036 | "<=" 6037 { 6038 $$ = opcode.LE 6039 } 6040 | '<' 6041 { 6042 $$ = opcode.LT 6043 } 6044 | "!=" 6045 { 6046 $$ = opcode.NE 6047 } 6048 | "<>" 6049 { 6050 $$ = opcode.NE 6051 } 6052 | "=" 6053 { 6054 $$ = opcode.EQ 6055 } 6056 | "<=>" 6057 { 6058 $$ = opcode.NullEQ 6059 } 6060 6061 BetweenOrNotOp: 6062 "BETWEEN" 6063 { 6064 $$ = true 6065 } 6066 | NotSym "BETWEEN" 6067 { 6068 $$ = false 6069 } 6070 6071 IsOrNotOp: 6072 "IS" 6073 { 6074 $$ = true 6075 } 6076 | "IS" NotSym 6077 { 6078 $$ = false 6079 } 6080 6081 InOrNotOp: 6082 "IN" 6083 { 6084 $$ = true 6085 } 6086 | NotSym "IN" 6087 { 6088 $$ = false 6089 } 6090 6091 LikeOrNotOp: 6092 "LIKE" 6093 { 6094 $$ = true 6095 } 6096 | NotSym "LIKE" 6097 { 6098 $$ = false 6099 } 6100 6101 IlikeOrNotOp: 6102 "ILIKE" 6103 { 6104 $$ = true 6105 } 6106 | NotSym "ILIKE" 6107 { 6108 $$ = false 6109 } 6110 6111 RegexpOrNotOp: 6112 RegexpSym 6113 { 6114 $$ = true 6115 } 6116 | NotSym RegexpSym 6117 { 6118 $$ = false 6119 } 6120 6121 AnyOrAll: 6122 "ANY" 6123 { 6124 $$ = false 6125 } 6126 | "SOME" 6127 { 6128 $$ = false 6129 } 6130 | "ALL" 6131 { 6132 $$ = true 6133 } 6134 6135 PredicateExpr: 6136 BitExpr InOrNotOp '(' ExpressionList ')' 6137 { 6138 $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), List: $4.([]ast.ExprNode)} 6139 } 6140 | BitExpr InOrNotOp SubSelect 6141 { 6142 sq := $3.(*ast.SubqueryExpr) 6143 sq.MultiRows = true 6144 $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), Sel: sq} 6145 } 6146 | BitExpr BetweenOrNotOp BitExpr "AND" PredicateExpr 6147 { 6148 $$ = &ast.BetweenExpr{ 6149 Expr: $1, 6150 Left: $3, 6151 Right: $5, 6152 Not: !$2.(bool), 6153 } 6154 } 6155 | BitExpr LikeOrNotOp SimpleExpr LikeOrIlikeEscapeOpt 6156 { 6157 escape := $4 6158 if len(escape) > 1 { 6159 yylex.AppendError(ErrWrongArguments.GenWithStackByArgs("ESCAPE")) 6160 return 1 6161 } else if len(escape) == 0 { 6162 escape = "\\" 6163 } 6164 $$ = &ast.PatternLikeOrIlikeExpr{ 6165 Expr: $1, 6166 Pattern: $3, 6167 Not: !$2.(bool), 6168 Escape: escape[0], 6169 IsLike: true, 6170 } 6171 } 6172 | BitExpr IlikeOrNotOp SimpleExpr LikeOrIlikeEscapeOpt 6173 { 6174 escape := $4 6175 if len(escape) > 1 { 6176 yylex.AppendError(ErrWrongArguments.GenWithStackByArgs("ESCAPE")) 6177 return 1 6178 } else if len(escape) == 0 { 6179 escape = "\\" 6180 } 6181 $$ = &ast.PatternLikeOrIlikeExpr{ 6182 Expr: $1, 6183 Pattern: $3, 6184 Not: !$2.(bool), 6185 Escape: escape[0], 6186 IsLike: false, 6187 } 6188 } 6189 | BitExpr RegexpOrNotOp SimpleExpr 6190 { 6191 $$ = &ast.PatternRegexpExpr{Expr: $1, Pattern: $3, Not: !$2.(bool)} 6192 } 6193 | BitExpr memberof '(' SimpleExpr ')' 6194 { 6195 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONMemberOf), Args: []ast.ExprNode{$1, $4}} 6196 } 6197 | BitExpr 6198 6199 RegexpSym: 6200 "REGEXP" 6201 | "RLIKE" 6202 6203 LikeOrIlikeEscapeOpt: 6204 %prec empty 6205 { 6206 $$ = "\\" 6207 } 6208 | "ESCAPE" stringLit 6209 { 6210 $$ = $2 6211 } 6212 6213 Field: 6214 '*' %prec '*' 6215 { 6216 $$ = &ast.SelectField{WildCard: &ast.WildCardField{}} 6217 } 6218 | Identifier '.' '*' %prec '*' 6219 { 6220 wildCard := &ast.WildCardField{Table: model.NewCIStr($1)} 6221 $$ = &ast.SelectField{WildCard: wildCard} 6222 } 6223 | Identifier '.' Identifier '.' '*' %prec '*' 6224 { 6225 wildCard := &ast.WildCardField{Schema: model.NewCIStr($1), Table: model.NewCIStr($3)} 6226 $$ = &ast.SelectField{WildCard: wildCard} 6227 } 6228 | Expression FieldAsNameOpt 6229 { 6230 expr := $1 6231 asName := $2 6232 $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)} 6233 } 6234 6235 FieldAsNameOpt: 6236 /* EMPTY */ 6237 { 6238 $$ = "" 6239 } 6240 | FieldAsName 6241 6242 FieldAsName: 6243 Identifier 6244 | "AS" Identifier 6245 { 6246 $$ = $2 6247 } 6248 | stringLit 6249 | "AS" stringLit 6250 { 6251 $$ = $2 6252 } 6253 6254 FieldList: 6255 Field 6256 { 6257 field := $1.(*ast.SelectField) 6258 field.Offset = parser.startOffset(&yyS[yypt]) 6259 if field.Expr != nil { 6260 endOffset := parser.yylval.offset 6261 field.SetText(parser.lexer.client, strings.TrimSpace(parser.src[field.Offset:endOffset])) 6262 } 6263 $$ = []*ast.SelectField{field} 6264 } 6265 | FieldList ',' Field 6266 { 6267 fl := $1.([]*ast.SelectField) 6268 field := $3.(*ast.SelectField) 6269 field.Offset = parser.startOffset(&yyS[yypt]) 6270 if field.Expr != nil { 6271 endOffset := parser.yylval.offset 6272 field.SetText(parser.lexer.client, strings.TrimSpace(parser.src[field.Offset:endOffset])) 6273 } 6274 $$ = append(fl, field) 6275 } 6276 6277 WithRollupClause: 6278 %prec lowerThanWith 6279 { 6280 $$ = false 6281 } 6282 | "WITH" "ROLLUP" 6283 { 6284 $$ = true 6285 } 6286 6287 GroupByClause: 6288 "GROUP" "BY" ByList WithRollupClause 6289 { 6290 $$ = &ast.GroupByClause{Items: $3.([]*ast.ByItem), Rollup: $4.(bool)} 6291 } 6292 6293 HavingClause: 6294 { 6295 $$ = nil 6296 } 6297 | "HAVING" Expression 6298 { 6299 $$ = &ast.HavingClause{Expr: $2} 6300 } 6301 6302 AsOfClauseOpt: 6303 %prec empty 6304 { 6305 $$ = nil 6306 } 6307 | AsOfClause 6308 6309 AsOfClause: 6310 asof "TIMESTAMP" Expression 6311 { 6312 $$ = &ast.AsOfClause{ 6313 TsExpr: $3.(ast.ExprNode), 6314 } 6315 } 6316 6317 IfExists: 6318 { 6319 $$ = false 6320 } 6321 | "IF" "EXISTS" 6322 { 6323 $$ = true 6324 } 6325 6326 IfNotExists: 6327 { 6328 $$ = false 6329 } 6330 | "IF" NotSym "EXISTS" 6331 { 6332 $$ = true 6333 } 6334 6335 IgnoreOptional: 6336 { 6337 $$ = false 6338 } 6339 | "IGNORE" 6340 { 6341 $$ = true 6342 } 6343 6344 IndexName: 6345 { 6346 $$ = &ast.NullString{ 6347 String: "", 6348 Empty: false, 6349 } 6350 } 6351 | Identifier 6352 { 6353 $$ = &ast.NullString{ 6354 String: $1, 6355 Empty: len($1) == 0, 6356 } 6357 } 6358 6359 IndexOptionList: 6360 { 6361 $$ = nil 6362 } 6363 | IndexOptionList IndexOption 6364 { 6365 // Merge the options 6366 if $1 == nil { 6367 $$ = $2 6368 } else { 6369 opt1 := $1.(*ast.IndexOption) 6370 opt2 := $2.(*ast.IndexOption) 6371 if len(opt2.Comment) > 0 { 6372 opt1.Comment = opt2.Comment 6373 } else if opt2.Tp != 0 { 6374 opt1.Tp = opt2.Tp 6375 } else if opt2.KeyBlockSize > 0 { 6376 opt1.KeyBlockSize = opt2.KeyBlockSize 6377 } else if len(opt2.ParserName.O) > 0 { 6378 opt1.ParserName = opt2.ParserName 6379 } else if opt2.Visibility != ast.IndexVisibilityDefault { 6380 opt1.Visibility = opt2.Visibility 6381 } else if opt2.PrimaryKeyTp != model.PrimaryKeyTypeDefault { 6382 opt1.PrimaryKeyTp = opt2.PrimaryKeyTp 6383 } 6384 $$ = opt1 6385 } 6386 } 6387 6388 IndexOption: 6389 "KEY_BLOCK_SIZE" EqOpt LengthNum 6390 { 6391 $$ = &ast.IndexOption{ 6392 KeyBlockSize: $3.(uint64), 6393 } 6394 } 6395 | IndexType 6396 { 6397 $$ = &ast.IndexOption{ 6398 Tp: $1.(model.IndexType), 6399 } 6400 } 6401 | "WITH" "PARSER" Identifier 6402 { 6403 $$ = &ast.IndexOption{ 6404 ParserName: model.NewCIStr($3), 6405 } 6406 yylex.AppendError(yylex.Errorf("The WITH PARASER clause is parsed but ignored by all storage engines.")) 6407 parser.lastErrorAsWarn() 6408 } 6409 | "COMMENT" stringLit 6410 { 6411 $$ = &ast.IndexOption{ 6412 Comment: $2, 6413 } 6414 } 6415 | IndexInvisible 6416 { 6417 $$ = &ast.IndexOption{ 6418 Visibility: $1.(ast.IndexVisibility), 6419 } 6420 } 6421 | WithClustered 6422 { 6423 $$ = &ast.IndexOption{ 6424 PrimaryKeyTp: $1.(model.PrimaryKeyType), 6425 } 6426 } 6427 6428 /* 6429 See: https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L7179 6430 6431 The syntax for defining an index is: 6432 6433 ... INDEX [index_name] [USING|TYPE] <index_type> ... 6434 6435 The problem is that whereas USING is a reserved word, TYPE is not. We can 6436 still handle it if an index name is supplied, i.e.: 6437 6438 ... INDEX type TYPE <index_type> ... 6439 6440 here the index's name is unmbiguously 'type', but for this: 6441 6442 ... INDEX TYPE <index_type> ... 6443 6444 it's impossible to know what this actually mean - is 'type' the name or the 6445 type? For this reason we accept the TYPE syntax only if a name is supplied. 6446 */ 6447 IndexNameAndTypeOpt: 6448 IndexName 6449 { 6450 $$ = []interface{}{$1, nil} 6451 } 6452 | IndexName "USING" IndexTypeName 6453 { 6454 $$ = []interface{}{$1, $3} 6455 } 6456 | Identifier "TYPE" IndexTypeName 6457 { 6458 $$ = []interface{}{&ast.NullString{String: $1, Empty: len($1) == 0}, $3} 6459 } 6460 6461 IndexTypeOpt: 6462 { 6463 $$ = nil 6464 } 6465 | IndexType 6466 6467 IndexType: 6468 "USING" IndexTypeName 6469 { 6470 $$ = $2 6471 } 6472 | "TYPE" IndexTypeName 6473 { 6474 $$ = $2 6475 } 6476 6477 IndexTypeName: 6478 "BTREE" 6479 { 6480 $$ = model.IndexTypeBtree 6481 } 6482 | "HASH" 6483 { 6484 $$ = model.IndexTypeHash 6485 } 6486 | "RTREE" 6487 { 6488 $$ = model.IndexTypeRtree 6489 } 6490 | "HYPO" 6491 { 6492 $$ = model.IndexTypeHypo 6493 } 6494 6495 IndexInvisible: 6496 "VISIBLE" 6497 { 6498 $$ = ast.IndexVisibilityVisible 6499 } 6500 | "INVISIBLE" 6501 { 6502 $$ = ast.IndexVisibilityInvisible 6503 } 6504 6505 /**********************************Identifier********************************************/ 6506 Identifier: 6507 identifier 6508 | UnReservedKeyword 6509 | NotKeywordToken 6510 | TiDBKeyword 6511 6512 UnReservedKeyword: 6513 "ACTION" 6514 | "ADVISE" 6515 | "ASCII" 6516 | "ATTRIBUTE" 6517 | "ATTRIBUTES" 6518 | "BINDING_CACHE" 6519 | "STATS_OPTIONS" 6520 | "STATS_SAMPLE_RATE" 6521 | "STATS_COL_CHOICE" 6522 | "STATS_COL_LIST" 6523 | "AUTO_ID_CACHE" 6524 | "AUTO_INCREMENT" 6525 | "AFTER" 6526 | "ALWAYS" 6527 | "AVG" 6528 | "BEGIN" 6529 | "BIT" 6530 | "BOOL" 6531 | "BOOLEAN" 6532 | "BTREE" 6533 | "BYTE" 6534 | "CAPTURE" 6535 | "CAUSAL" 6536 | "CLEANUP" 6537 | "CLOSE" 6538 | "CHAIN" 6539 | "CHARSET" 6540 | "COLUMNS" 6541 | "CONFIG" 6542 | "SAN" 6543 | "COMMIT" 6544 | "COMPACT" 6545 | "COMPRESSED" 6546 | "CONSISTENCY" 6547 | "CONSISTENT" 6548 | "CURRENT" 6549 | "DATA" 6550 | "DATE" %prec lowerThanStringLitToken 6551 | "DATETIME" 6552 | "DAY" 6553 | "DEALLOCATE" 6554 | "DO" 6555 | "DUPLICATE" 6556 | "DYNAMIC" 6557 | "ENCRYPTION" 6558 | "END" 6559 | "ENFORCED" 6560 | "ENGINE" 6561 | "ENGINES" 6562 | "ENUM" 6563 | "ERROR" 6564 | "ERRORS" 6565 | "ESCAPE" 6566 | "EVOLVE" 6567 | "EXECUTE" 6568 | "EXTENDED" 6569 | "FIELDS" 6570 | "FILE" 6571 | "FIRST" 6572 | "FIXED" 6573 | "FLUSH" 6574 | "FOLLOWING" 6575 | "FORMAT" 6576 | "FULL" 6577 | "GENERAL" 6578 | "GLOBAL" 6579 | "HASH" 6580 | "HELP" 6581 | "HOUR" 6582 | "INSERT_METHOD" 6583 | "LESS" 6584 | "LOCAL" 6585 | "LAST" 6586 | "NAMES" 6587 | "NVARCHAR" 6588 | "OFFSET" 6589 | "PACK_KEYS" 6590 | "PARSER" 6591 | "PASSWORD" %prec lowerThanEq 6592 | "PREPARE" 6593 | "PRE_SPLIT_REGIONS" 6594 | "PROXY" 6595 | "QUICK" 6596 | "REBUILD" 6597 | "REDUNDANT" 6598 | "REORGANIZE" 6599 | "RESOURCE" 6600 | "RESTART" 6601 | "ROLE" 6602 | "ROLLBACK" 6603 | "ROLLUP" 6604 | "SESSION" 6605 | "SIGNED" 6606 | "SHARD_ROW_ID_BITS" 6607 | "SHUTDOWN" 6608 | "SNAPSHOT" 6609 | "START" 6610 | "STATUS" 6611 | "OPEN" 6612 | "POINT" 6613 | "SUBPARTITIONS" 6614 | "SUBPARTITION" 6615 | "TABLES" 6616 | "TABLESPACE" 6617 | "TEXT" 6618 | "THAN" 6619 | "TIME" %prec lowerThanStringLitToken 6620 | "TIMESTAMP" %prec lowerThanStringLitToken 6621 | "TRACE" 6622 | "TRANSACTION" 6623 | "TRUNCATE" 6624 | "UNBOUNDED" 6625 | "UNKNOWN" 6626 | "VALUE" %prec lowerThanValueKeyword 6627 | "WARNINGS" 6628 | "YEAR" 6629 | "MODE" 6630 | "WEEK" 6631 | "WEIGHT_STRING" 6632 | "ANY" 6633 | "SOME" 6634 | "USER" 6635 | "IDENTIFIED" 6636 | "COLLATION" 6637 | "COMMENT" 6638 | "AVG_ROW_LENGTH" 6639 | "CONNECTION" 6640 | "CHECKSUM" 6641 | "COMPRESSION" 6642 | "KEY_BLOCK_SIZE" 6643 | "MASTER" 6644 | "MAX_ROWS" 6645 | "MIN_ROWS" 6646 | "NATIONAL" 6647 | "NCHAR" 6648 | "ROW_FORMAT" 6649 | "QUARTER" 6650 | "GRANTS" 6651 | "TRIGGERS" 6652 | "DELAY_KEY_WRITE" 6653 | "ISOLATION" 6654 | "JSON" 6655 | "REPEATABLE" 6656 | "RESPECT" 6657 | "COMMITTED" 6658 | "UNCOMMITTED" 6659 | "ONLY" 6660 | "SERIAL" 6661 | "SERIALIZABLE" 6662 | "LEVEL" 6663 | "VARIABLES" 6664 | "SQL_CACHE" 6665 | "INDEXES" 6666 | "PROCESSLIST" 6667 | "SQL_NO_CACHE" 6668 | "DISABLE" 6669 | "DISABLED" 6670 | "ENABLE" 6671 | "ENABLED" 6672 | "REVERSE" 6673 | "PRIVILEGES" 6674 | "NO" 6675 | "BINLOG" 6676 | "FUNCTION" 6677 | "VIEW" 6678 | "BINDING" 6679 | "BINDINGS" 6680 | "MODIFY" 6681 | "EVENTS" 6682 | "PARTITIONS" 6683 | "NONE" 6684 | "NULLS" 6685 | "SUPER" 6686 | "EXCLUSIVE" 6687 | "STATS_PERSISTENT" 6688 | "STATS_AUTO_RECALC" 6689 | "ROW_COUNT" 6690 | "COALESCE" 6691 | "MONTH" 6692 | "PROCESS" 6693 | "PROFILE" 6694 | "PROFILES" 6695 | "MICROSECOND" 6696 | "MINUTE" 6697 | "PLUGINS" 6698 | "PRECEDING" 6699 | "QUERY" 6700 | "QUERIES" 6701 | "SAVEPOINT" 6702 | "SECOND" 6703 | "SEPARATOR" 6704 | "SHARE" 6705 | "SHARED" 6706 | "SLOW" 6707 | "MAX_CONNECTIONS_PER_HOUR" 6708 | "MAX_QUERIES_PER_HOUR" 6709 | "MAX_UPDATES_PER_HOUR" 6710 | "MAX_USER_CONNECTIONS" 6711 | "REPLICATION" 6712 | "CLIENT" 6713 | "SLAVE" 6714 | "RELOAD" 6715 | "TEMPORARY" 6716 | "ROUTINE" 6717 | "EVENT" 6718 | "ALGORITHM" 6719 | "DEFINER" 6720 | "INVOKER" 6721 | "MERGE" 6722 | "TEMPTABLE" 6723 | "UNDEFINED" 6724 | "SECURITY" 6725 | "CASCADED" 6726 | "RECOVER" 6727 | "CIPHER" 6728 | "SUBJECT" 6729 | "ISSUER" 6730 | "X509" 6731 | "NEVER" 6732 | "EXPIRE" 6733 | "ACCOUNT" 6734 | "INCREMENTAL" 6735 | "CPU" 6736 | "MEMBER" 6737 | "MEMORY" 6738 | "BLOCK" 6739 | "IO" 6740 | "CONTEXT" 6741 | "SWITCHES" 6742 | "PAGE" 6743 | "FAULTS" 6744 | "IPC" 6745 | "SWAPS" 6746 | "SOURCE" 6747 | "TRADITIONAL" 6748 | "SQL_BUFFER_RESULT" 6749 | "DIRECTORY" 6750 | "HISTOGRAM" 6751 | "HISTORY" 6752 | "LIST" 6753 | "NODEGROUP" 6754 | "SYSTEM_TIME" 6755 | "PARTIAL" 6756 | "SIMPLE" 6757 | "REMOVE" 6758 | "PARTITIONING" 6759 | "STORAGE" 6760 | "DISK" 6761 | "STATS_SAMPLE_PAGES" 6762 | "SECONDARY_ENGINE" 6763 | "SECONDARY_LOAD" 6764 | "SECONDARY_UNLOAD" 6765 | "VALIDATION" 6766 | "WITHOUT" 6767 | "RTREE" 6768 | "HYPO" 6769 | "EXCHANGE" 6770 | "COLUMN_FORMAT" 6771 | "REPAIR" 6772 | "IMPORT" 6773 | "IMPORTS" 6774 | "DISCARD" 6775 | "TABLE_CHECKSUM" 6776 | "UNICODE" 6777 | "AUTO_RANDOM" 6778 | "AUTO_RANDOM_BASE" 6779 | "SQL_TSI_DAY" 6780 | "SQL_TSI_HOUR" 6781 | "SQL_TSI_MINUTE" 6782 | "SQL_TSI_MONTH" 6783 | "SQL_TSI_QUARTER" 6784 | "SQL_TSI_SECOND" 6785 | "LANGUAGE" 6786 | "SQL_TSI_WEEK" 6787 | "SQL_TSI_YEAR" 6788 | "INVISIBLE" 6789 | "VISIBLE" 6790 | "TYPE" 6791 | "NOWAIT" 6792 | "INSTANCE" 6793 | "REPLICA" 6794 | "LOCATION" 6795 | "LABELS" 6796 | "LOGS" 6797 | "HOSTS" 6798 | "AGAINST" 6799 | "EXPANSION" 6800 | "INCREMENT" 6801 | "MINVALUE" 6802 | "NOMAXVALUE" 6803 | "NOMINVALUE" 6804 | "NOCACHE" 6805 | "CACHE" 6806 | "CYCLE" 6807 | "NOCYCLE" 6808 | "SEQUENCE" 6809 | "MAX_MINUTES" 6810 | "MAX_IDXNUM" 6811 | "PER_TABLE" 6812 | "PER_DB" 6813 | "NEXT" 6814 | "NEXTVAL" 6815 | "LASTVAL" 6816 | "SETVAL" 6817 | "AGO" 6818 | "BACKUP" 6819 | "BACKUPS" 6820 | "CONCURRENCY" 6821 | "MB" 6822 | "ONLINE" 6823 | "RATE_LIMIT" 6824 | "RESTORE" 6825 | "RESTORES" 6826 | "SEND_CREDENTIALS_TO_TIKV" 6827 | "LAST_BACKUP" 6828 | "CHECKPOINT" 6829 | "SKIP_SCHEMA_FILES" 6830 | "STRICT_FORMAT" 6831 | "BACKEND" 6832 | "CSV_BACKSLASH_ESCAPE" 6833 | "CSV_NOT_NULL" 6834 | "CSV_TRIM_LAST_SEPARATORS" 6835 | "CSV_DELIMITER" 6836 | "CSV_HEADER" 6837 | "CSV_NULL" 6838 | "CSV_SEPARATOR" 6839 | "ON_DUPLICATE" 6840 | "TIKV_IMPORTER" 6841 | "REPLICAS" 6842 | "POLICY" 6843 | "WAIT" 6844 | "CLIENT_ERRORS_SUMMARY" 6845 | "BERNOULLI" 6846 | "SYSTEM" 6847 | "PERCENT" 6848 | "PAUSE" 6849 | "RESUME" 6850 | "OFF" 6851 | "OPTIONAL" 6852 | "REQUIRED" 6853 | "PURGE" 6854 | "SKIP" 6855 | "LOCKED" 6856 | "CLUSTER" 6857 | "CLUSTERED" 6858 | "NONCLUSTERED" 6859 | "PRESERVE" 6860 | "TOKEN_ISSUER" 6861 | "TTL" 6862 | "TTL_ENABLE" 6863 | "TTL_JOB_INTERVAL" 6864 | "FAILED_LOGIN_ATTEMPTS" 6865 | "PASSWORD_LOCK_TIME" 6866 | "DIGEST" 6867 | "REUSE" %prec lowerThanEq 6868 | "DECLARE" 6869 | "HANDLER" 6870 | "FOUND" 6871 | "CALIBRATE" 6872 | "WORKLOAD" 6873 | "TPCC" 6874 | "OLTP_READ_WRITE" 6875 | "OLTP_READ_ONLY" 6876 | "OLTP_WRITE_ONLY" 6877 | "TPCH_10" 6878 6879 TiDBKeyword: 6880 "ADMIN" 6881 | "BATCH" 6882 | "BUCKETS" 6883 | "BUILTINS" 6884 | "CANCEL" 6885 | "CARDINALITY" 6886 | "CMSKETCH" 6887 | "COLUMN_STATS_USAGE" 6888 | "CORRELATION" 6889 | "DDL" 6890 | "DEPENDENCY" 6891 | "DEPTH" 6892 | "DRAINER" 6893 | "JOBS" 6894 | "JOB" 6895 | "NODE_ID" 6896 | "NODE_STATE" 6897 | "PUMP" 6898 | "SAMPLES" 6899 | "SAMPLERATE" 6900 | "SESSION_STATES" 6901 | "STATISTICS" 6902 | "STATS" 6903 | "STATS_META" 6904 | "STATS_HISTOGRAMS" 6905 | "STATS_TOPN" 6906 | "STATS_BUCKETS" 6907 | "STATS_HEALTHY" 6908 | "STATS_LOCKED" 6909 | "HISTOGRAMS_IN_FLIGHT" 6910 | "TELEMETRY" 6911 | "TELEMETRY_ID" 6912 | "TIDB" 6913 | "TIFLASH" 6914 | "TOPN" 6915 | "SPLIT" 6916 | "OPTIMISTIC" 6917 | "PESSIMISTIC" 6918 | "WIDTH" 6919 | "REGIONS" 6920 | "REGION" 6921 | "RESET" 6922 | "DRY" 6923 | "RUN" 6924 6925 NotKeywordToken: 6926 "ADDDATE" 6927 | "APPROX_COUNT_DISTINCT" 6928 | "APPROX_PERCENTILE" 6929 | "BIT_AND" 6930 | "BIT_OR" 6931 | "BIT_XOR" 6932 | "BRIEF" 6933 | "CAST" 6934 | "COPY" 6935 | "CURTIME" 6936 | "CURDATE" 6937 | "DATE_ADD" 6938 | "DATE_SUB" 6939 | "DEFINED" 6940 | "DOT" 6941 | "DUMP" 6942 | "DURATION" 6943 | "EXTRACT" 6944 | "END_TIME" 6945 | "GET_FORMAT" 6946 | "GROUP_CONCAT" 6947 | "INPLACE" 6948 | "INSTANT" 6949 | "INTERNAL" 6950 | "MIN" 6951 | "MAX" 6952 | "NOW" 6953 | "RECENT" 6954 | "REPLAYER" 6955 | "RUNNING" 6956 | "PLACEMENT" 6957 | "PLAN" 6958 | "PLAN_CACHE" 6959 | "POSITION" 6960 | "PREDICATE" 6961 | "S3" 6962 | "STRICT" 6963 | "SUBDATE" 6964 | "SUBSTRING" 6965 | "SUM" 6966 | "START_TIME" 6967 | "STD" 6968 | "STDDEV" 6969 | "STDDEV_POP" 6970 | "STDDEV_SAMP" 6971 | "STOP" 6972 | "VARIANCE" 6973 | "VAR_POP" 6974 | "VAR_SAMP" 6975 | "TARGET" 6976 | "TIMESTAMPADD" 6977 | "TIMESTAMPDIFF" 6978 | "TOKUDB_DEFAULT" 6979 | "TOKUDB_FAST" 6980 | "TOKUDB_LZMA" 6981 | "TOKUDB_QUICKLZ" 6982 | "TOKUDB_SNAPPY" 6983 | "TOKUDB_SMALL" 6984 | "TOKUDB_UNCOMPRESSED" 6985 | "TOKUDB_ZLIB" 6986 | "TOKUDB_ZSTD" 6987 | "TOP" 6988 | "TRIM" 6989 | "NEXT_ROW_ID" 6990 | "EXPR_PUSHDOWN_BLACKLIST" 6991 | "OPT_RULE_BLACKLIST" 6992 | "BOUND" 6993 | "EXACT" %prec lowerThanStringLitToken 6994 | "STALENESS" 6995 | "STRONG" 6996 | "FLASHBACK" 6997 | "JSON_OBJECTAGG" 6998 | "JSON_ARRAYAGG" 6999 | "TLS" 7000 | "FOLLOWER" 7001 | "FOLLOWERS" 7002 | "LEADER" 7003 | "LEARNER" 7004 | "LEARNERS" 7005 | "VERBOSE" 7006 | "TRUE_CARD_COST" 7007 | "VOTER" 7008 | "VOTERS" 7009 | "CONSTRAINTS" 7010 | "PRIMARY_REGION" 7011 | "SCHEDULE" 7012 | "SURVIVAL_PREFERENCES" 7013 | "LEADER_CONSTRAINTS" 7014 | "FOLLOWER_CONSTRAINTS" 7015 | "LEARNER_CONSTRAINTS" 7016 | "VOTER_CONSTRAINTS" 7017 | "TIDB_JSON" 7018 | "IO_READ_BANDWIDTH" 7019 | "IO_WRITE_BANDWIDTH" 7020 | "RU_PER_SEC" 7021 | "PRIORITY" 7022 | "HIGH" 7023 | "MEDIUM" 7024 | "LOW" 7025 | "BURSTABLE" 7026 | "BR" 7027 | "GC_TTL" 7028 | "METADATA" 7029 | "START_TS" 7030 | "UNTIL_TS" 7031 | "RESTORED_TS" 7032 | "FULL_BACKUP_STORAGE" 7033 | "EXEC_ELAPSED" 7034 | "DRYRUN" 7035 | "COOLDOWN" 7036 | "WATCH" 7037 | "SIMILAR" 7038 | "QUERY_LIMIT" 7039 | "BACKGROUND" 7040 | "TASK_TYPES" 7041 | "UNLIMITED" 7042 7043 /************************************************************************************ 7044 * 7045 * Call Statements 7046 * 7047 **********************************************************************************/ 7048 CallStmt: 7049 "CALL" ProcedureCall 7050 { 7051 $$ = &ast.CallStmt{ 7052 Procedure: $2.(*ast.FuncCallExpr), 7053 } 7054 } 7055 7056 ProcedureCall: 7057 identifier 7058 { 7059 $$ = &ast.FuncCallExpr{ 7060 Tp: ast.FuncCallExprTypeGeneric, 7061 FnName: model.NewCIStr($1), 7062 Args: []ast.ExprNode{}, 7063 } 7064 } 7065 | Identifier '.' Identifier 7066 { 7067 $$ = &ast.FuncCallExpr{ 7068 Tp: ast.FuncCallExprTypeGeneric, 7069 Schema: model.NewCIStr($1), 7070 FnName: model.NewCIStr($3), 7071 Args: []ast.ExprNode{}, 7072 } 7073 } 7074 | identifier '(' ExpressionListOpt ')' 7075 { 7076 $$ = &ast.FuncCallExpr{ 7077 Tp: ast.FuncCallExprTypeGeneric, 7078 FnName: model.NewCIStr($1), 7079 Args: $3.([]ast.ExprNode), 7080 } 7081 } 7082 | Identifier '.' Identifier '(' ExpressionListOpt ')' 7083 { 7084 $$ = &ast.FuncCallExpr{ 7085 Tp: ast.FuncCallExprTypeGeneric, 7086 Schema: model.NewCIStr($1), 7087 FnName: model.NewCIStr($3), 7088 Args: $5.([]ast.ExprNode), 7089 } 7090 } 7091 7092 /************************************************************************************ 7093 * 7094 * Insert Statements 7095 * 7096 **********************************************************************************/ 7097 InsertIntoStmt: 7098 "INSERT" TableOptimizerHintsOpt PriorityOpt IgnoreOptional IntoOpt TableName PartitionNameListOpt InsertValues OnDuplicateKeyUpdate 7099 { 7100 x := $8.(*ast.InsertStmt) 7101 x.Priority = $3.(mysql.PriorityEnum) 7102 x.IgnoreErr = $4.(bool) 7103 // Wraps many layers here so that it can be processed the same way as select statement. 7104 ts := &ast.TableSource{Source: $6.(*ast.TableName)} 7105 x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}} 7106 if $9 != nil { 7107 x.OnDuplicate = $9.([]*ast.Assignment) 7108 } 7109 if $2 != nil { 7110 x.TableHints = $2.([]*ast.TableOptimizerHint) 7111 } 7112 x.PartitionNames = $7.([]model.CIStr) 7113 $$ = x 7114 } 7115 7116 IntoOpt: 7117 {} 7118 | "INTO" 7119 7120 InsertValues: 7121 '(' ColumnNameListOpt ')' ValueSym ValuesList 7122 { 7123 $$ = &ast.InsertStmt{ 7124 Columns: $2.([]*ast.ColumnName), 7125 Lists: $5.([][]ast.ExprNode), 7126 } 7127 } 7128 | '(' ColumnNameListOpt ')' SetOprStmt 7129 { 7130 $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(ast.ResultSetNode)} 7131 } 7132 | '(' ColumnNameListOpt ')' SelectStmt 7133 { 7134 $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(ast.ResultSetNode)} 7135 } 7136 | '(' ColumnNameListOpt ')' SelectStmtWithClause 7137 { 7138 $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(ast.ResultSetNode)} 7139 } 7140 | '(' ColumnNameListOpt ')' SubSelect 7141 { 7142 var sel ast.ResultSetNode 7143 switch x := $4.(*ast.SubqueryExpr).Query.(type) { 7144 case *ast.SelectStmt: 7145 x.IsInBraces = true 7146 sel = x 7147 case *ast.SetOprStmt: 7148 x.IsInBraces = true 7149 sel = x 7150 } 7151 $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: sel} 7152 } 7153 | ValueSym ValuesList %prec insertValues 7154 { 7155 $$ = &ast.InsertStmt{Lists: $2.([][]ast.ExprNode)} 7156 } 7157 | SetOprStmt 7158 { 7159 $$ = &ast.InsertStmt{Select: $1.(ast.ResultSetNode)} 7160 } 7161 | SelectStmt 7162 { 7163 $$ = &ast.InsertStmt{Select: $1.(ast.ResultSetNode)} 7164 } 7165 | SelectStmtWithClause 7166 { 7167 $$ = &ast.InsertStmt{Select: $1.(ast.ResultSetNode)} 7168 } 7169 | SubSelect 7170 { 7171 var sel ast.ResultSetNode 7172 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 7173 case *ast.SelectStmt: 7174 x.IsInBraces = true 7175 sel = x 7176 case *ast.SetOprStmt: 7177 x.IsInBraces = true 7178 sel = x 7179 } 7180 $$ = &ast.InsertStmt{Select: sel} 7181 } 7182 | "SET" ColumnSetValueList 7183 { 7184 $$ = $2.(*ast.InsertStmt) 7185 } 7186 7187 ValueSym: 7188 "VALUE" 7189 | "VALUES" 7190 7191 ValuesList: 7192 RowValue 7193 { 7194 $$ = [][]ast.ExprNode{$1.([]ast.ExprNode)} 7195 } 7196 | ValuesList ',' RowValue 7197 { 7198 $$ = append($1.([][]ast.ExprNode), $3.([]ast.ExprNode)) 7199 } 7200 7201 RowValue: 7202 '(' ValuesOpt ')' 7203 { 7204 $$ = $2 7205 } 7206 7207 ValuesOpt: 7208 { 7209 $$ = []ast.ExprNode{} 7210 } 7211 | Values 7212 7213 Values: 7214 Values ',' ExprOrDefault 7215 { 7216 $$ = append($1.([]ast.ExprNode), $3) 7217 } 7218 | ExprOrDefault 7219 { 7220 $$ = []ast.ExprNode{$1} 7221 } 7222 7223 ExprOrDefault: 7224 Expression 7225 | "DEFAULT" 7226 { 7227 $$ = &ast.DefaultExpr{} 7228 } 7229 7230 ColumnSetValueList: 7231 ColumnName EqOrAssignmentEq ExprOrDefault 7232 { 7233 $$ = &ast.InsertStmt{ 7234 Columns: []*ast.ColumnName{$1.(*ast.ColumnName)}, 7235 Lists: [][]ast.ExprNode{{$3.(ast.ExprNode)}}, 7236 Setlist: true, 7237 } 7238 } 7239 | ColumnSetValueList ',' ColumnName EqOrAssignmentEq ExprOrDefault 7240 { 7241 ins := $1.(*ast.InsertStmt) 7242 ins.Columns = append(ins.Columns, $3.(*ast.ColumnName)) 7243 ins.Lists[0] = append(ins.Lists[0], $5.(ast.ExprNode)) 7244 $$ = ins 7245 } 7246 7247 /* 7248 * ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... 7249 * See https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html 7250 */ 7251 OnDuplicateKeyUpdate: 7252 { 7253 $$ = nil 7254 } 7255 | "ON" "DUPLICATE" "KEY" "UPDATE" AssignmentList 7256 { 7257 $$ = $5 7258 } 7259 7260 /************************************************************************************ 7261 * Replace Statements 7262 * See https://dev.mysql.com/doc/refman/5.7/en/replace.html 7263 * 7264 **********************************************************************************/ 7265 ReplaceIntoStmt: 7266 "REPLACE" PriorityOpt IntoOpt TableName PartitionNameListOpt InsertValues 7267 { 7268 x := $6.(*ast.InsertStmt) 7269 x.IsReplace = true 7270 x.Priority = $2.(mysql.PriorityEnum) 7271 ts := &ast.TableSource{Source: $4.(*ast.TableName)} 7272 x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}} 7273 x.PartitionNames = $5.([]model.CIStr) 7274 $$ = x 7275 } 7276 7277 Literal: 7278 "FALSE" 7279 { 7280 $$ = ast.NewValueExpr(false, parser.charset, parser.collation) 7281 } 7282 | "NULL" 7283 { 7284 $$ = ast.NewValueExpr(nil, parser.charset, parser.collation) 7285 } 7286 | "TRUE" 7287 { 7288 $$ = ast.NewValueExpr(true, parser.charset, parser.collation) 7289 } 7290 | floatLit 7291 { 7292 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 7293 } 7294 | decLit 7295 { 7296 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 7297 } 7298 | intLit 7299 { 7300 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 7301 } 7302 | StringLiteral %prec lowerThanStringLitToken 7303 | "UNDERSCORE_CHARSET" stringLit 7304 { 7305 // See https://dev.mysql.com/doc/refman/5.7/en/charset-literal.html 7306 co, err := charset.GetDefaultCollationLegacy($1) 7307 if err != nil { 7308 yylex.AppendError(ast.ErrUnknownCharacterSet.GenWithStack("Unsupported character introducer: '%-.64s'", $1)) 7309 return 1 7310 } 7311 expr := ast.NewValueExpr($2, $1, co) 7312 tp := expr.GetType() 7313 tp.SetCharset($1) 7314 tp.SetCollate(co) 7315 tp.AddFlag(mysql.UnderScoreCharsetFlag) 7316 if tp.GetCollate() == charset.CollationBin { 7317 tp.AddFlag(mysql.BinaryFlag) 7318 } 7319 $$ = expr 7320 } 7321 | hexLit 7322 { 7323 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 7324 } 7325 | bitLit 7326 { 7327 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 7328 } 7329 | "UNDERSCORE_CHARSET" hexLit 7330 { 7331 co, err := charset.GetDefaultCollationLegacy($1) 7332 if err != nil { 7333 yylex.AppendError(ast.ErrUnknownCharacterSet.GenWithStack("Unsupported character introducer: '%-.64s'", $1)) 7334 return 1 7335 } 7336 expr := ast.NewValueExpr($2, $1, co) 7337 tp := expr.GetType() 7338 tp.SetCharset($1) 7339 tp.SetCollate(co) 7340 tp.AddFlag(mysql.UnderScoreCharsetFlag) 7341 if tp.GetCollate() == charset.CollationBin { 7342 tp.AddFlag(mysql.BinaryFlag) 7343 } 7344 $$ = expr 7345 } 7346 | "UNDERSCORE_CHARSET" bitLit 7347 { 7348 co, err := charset.GetDefaultCollationLegacy($1) 7349 if err != nil { 7350 yylex.AppendError(ast.ErrUnknownCharacterSet.GenWithStack("Unsupported character introducer: '%-.64s'", $1)) 7351 return 1 7352 } 7353 expr := ast.NewValueExpr($2, $1, co) 7354 tp := expr.GetType() 7355 tp.SetCharset($1) 7356 tp.SetCollate(co) 7357 tp.AddFlag(mysql.UnderScoreCharsetFlag) 7358 if tp.GetCollate() == charset.CollationBin { 7359 tp.AddFlag(mysql.BinaryFlag) 7360 } 7361 $$ = expr 7362 } 7363 7364 StringLiteral: 7365 stringLit 7366 { 7367 expr := ast.NewValueExpr($1, parser.charset, parser.collation) 7368 $$ = expr 7369 } 7370 | StringLiteral stringLit 7371 { 7372 valExpr := $1.(ast.ValueExpr) 7373 strLit := valExpr.GetString() 7374 expr := ast.NewValueExpr(strLit+$2, parser.charset, parser.collation) 7375 // Fix #4239, use first string literal as projection name. 7376 if valExpr.GetProjectionOffset() >= 0 { 7377 expr.SetProjectionOffset(valExpr.GetProjectionOffset()) 7378 } else { 7379 expr.SetProjectionOffset(len(strLit)) 7380 } 7381 $$ = expr 7382 } 7383 7384 AlterOrderList: 7385 AlterOrderItem 7386 { 7387 $$ = []*ast.AlterOrderItem{$1.(*ast.AlterOrderItem)} 7388 } 7389 | AlterOrderList ',' AlterOrderItem 7390 { 7391 $$ = append($1.([]*ast.AlterOrderItem), $3.(*ast.AlterOrderItem)) 7392 } 7393 7394 AlterOrderItem: 7395 ColumnName OptOrder 7396 { 7397 $$ = &ast.AlterOrderItem{Column: $1.(*ast.ColumnName), Desc: $2.(bool)} 7398 } 7399 7400 OrderBy: 7401 "ORDER" "BY" ByList 7402 { 7403 $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)} 7404 } 7405 7406 ByList: 7407 ByItem 7408 { 7409 $$ = []*ast.ByItem{$1.(*ast.ByItem)} 7410 } 7411 | ByList ',' ByItem 7412 { 7413 $$ = append($1.([]*ast.ByItem), $3.(*ast.ByItem)) 7414 } 7415 7416 ByItem: 7417 Expression 7418 { 7419 expr := $1 7420 valueExpr, ok := expr.(ast.ValueExpr) 7421 if ok { 7422 position, isPosition := valueExpr.GetValue().(int64) 7423 if isPosition { 7424 expr = &ast.PositionExpr{N: int(position)} 7425 } 7426 } 7427 $$ = &ast.ByItem{Expr: expr, NullOrder: true} 7428 } 7429 | Expression Order 7430 { 7431 expr := $1 7432 valueExpr, ok := expr.(ast.ValueExpr) 7433 if ok { 7434 position, isPosition := valueExpr.GetValue().(int64) 7435 if isPosition { 7436 expr = &ast.PositionExpr{N: int(position)} 7437 } 7438 } 7439 $$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)} 7440 } 7441 7442 Order: 7443 "ASC" 7444 { 7445 $$ = false 7446 } 7447 | "DESC" 7448 { 7449 $$ = true 7450 } 7451 7452 OptOrder: 7453 /* EMPTY */ 7454 { 7455 $$ = false // ASC by default 7456 } 7457 | "ASC" 7458 { 7459 $$ = false 7460 } 7461 | "DESC" 7462 { 7463 $$ = true 7464 } 7465 7466 OrderByOptional: 7467 { 7468 $$ = nil 7469 } 7470 | OrderBy 7471 7472 BitExpr: 7473 BitExpr '|' BitExpr %prec '|' 7474 { 7475 $$ = &ast.BinaryOperationExpr{Op: opcode.Or, L: $1, R: $3} 7476 } 7477 | BitExpr '&' BitExpr %prec '&' 7478 { 7479 $$ = &ast.BinaryOperationExpr{Op: opcode.And, L: $1, R: $3} 7480 } 7481 | BitExpr "<<" BitExpr %prec lsh 7482 { 7483 $$ = &ast.BinaryOperationExpr{Op: opcode.LeftShift, L: $1, R: $3} 7484 } 7485 | BitExpr ">>" BitExpr %prec rsh 7486 { 7487 $$ = &ast.BinaryOperationExpr{Op: opcode.RightShift, L: $1, R: $3} 7488 } 7489 | BitExpr '+' BitExpr %prec '+' 7490 { 7491 $$ = &ast.BinaryOperationExpr{Op: opcode.Plus, L: $1, R: $3} 7492 } 7493 | BitExpr '-' BitExpr %prec '-' 7494 { 7495 $$ = &ast.BinaryOperationExpr{Op: opcode.Minus, L: $1, R: $3} 7496 } 7497 | BitExpr '+' "INTERVAL" Expression TimeUnit %prec '+' 7498 { 7499 $$ = &ast.FuncCallExpr{ 7500 FnName: model.NewCIStr("DATE_ADD"), 7501 Args: []ast.ExprNode{ 7502 $1, 7503 $4, 7504 &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)}, 7505 }, 7506 } 7507 } 7508 | BitExpr '-' "INTERVAL" Expression TimeUnit %prec '+' 7509 { 7510 $$ = &ast.FuncCallExpr{ 7511 FnName: model.NewCIStr("DATE_SUB"), 7512 Args: []ast.ExprNode{ 7513 $1, 7514 $4, 7515 &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)}, 7516 }, 7517 } 7518 } 7519 | "INTERVAL" Expression TimeUnit '+' BitExpr %prec '+' 7520 { 7521 $$ = &ast.FuncCallExpr{ 7522 FnName: model.NewCIStr("DATE_ADD"), 7523 Args: []ast.ExprNode{ 7524 $5, 7525 $2, 7526 &ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, 7527 }, 7528 } 7529 } 7530 | BitExpr '*' BitExpr %prec '*' 7531 { 7532 $$ = &ast.BinaryOperationExpr{Op: opcode.Mul, L: $1, R: $3} 7533 } 7534 | BitExpr '/' BitExpr %prec '/' 7535 { 7536 $$ = &ast.BinaryOperationExpr{Op: opcode.Div, L: $1, R: $3} 7537 } 7538 | BitExpr '%' BitExpr %prec '%' 7539 { 7540 $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3} 7541 } 7542 | BitExpr "DIV" BitExpr %prec div 7543 { 7544 $$ = &ast.BinaryOperationExpr{Op: opcode.IntDiv, L: $1, R: $3} 7545 } 7546 | BitExpr "MOD" BitExpr %prec mod 7547 { 7548 $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3} 7549 } 7550 | BitExpr '^' BitExpr 7551 { 7552 $$ = &ast.BinaryOperationExpr{Op: opcode.Xor, L: $1, R: $3} 7553 } 7554 | SimpleExpr 7555 7556 SimpleIdent: 7557 Identifier 7558 { 7559 $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ 7560 Name: model.NewCIStr($1), 7561 }} 7562 } 7563 | Identifier '.' Identifier 7564 { 7565 $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ 7566 Table: model.NewCIStr($1), 7567 Name: model.NewCIStr($3), 7568 }} 7569 } 7570 | Identifier '.' Identifier '.' Identifier 7571 { 7572 $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{ 7573 Schema: model.NewCIStr($1), 7574 Table: model.NewCIStr($3), 7575 Name: model.NewCIStr($5), 7576 }} 7577 } 7578 7579 SimpleExpr: 7580 SimpleIdent 7581 | FunctionCallKeyword 7582 | FunctionCallNonKeyword 7583 | FunctionCallGeneric 7584 | SimpleExpr "COLLATE" CollationName 7585 { 7586 $$ = &ast.SetCollationExpr{Expr: $1, Collate: $3} 7587 } 7588 | WindowFuncCall 7589 | Literal 7590 | paramMarker 7591 { 7592 $$ = ast.NewParamMarkerExpr(yyS[yypt].offset) 7593 } 7594 | Variable 7595 | SumExpr 7596 | '!' SimpleExpr %prec neg 7597 { 7598 $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2} 7599 } 7600 | '~' SimpleExpr %prec neg 7601 { 7602 $$ = &ast.UnaryOperationExpr{Op: opcode.BitNeg, V: $2} 7603 } 7604 | '-' SimpleExpr %prec neg 7605 { 7606 $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: $2} 7607 } 7608 | '+' SimpleExpr %prec neg 7609 { 7610 $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: $2} 7611 } 7612 | SimpleExpr pipes SimpleExpr 7613 { 7614 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.Concat), Args: []ast.ExprNode{$1, $3}} 7615 } 7616 | not2 SimpleExpr %prec neg 7617 { 7618 $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2} 7619 } 7620 | SubSelect %prec neg 7621 | '(' Expression ')' 7622 { 7623 startOffset := parser.startOffset(&yyS[yypt-1]) 7624 endOffset := parser.endOffset(&yyS[yypt]) 7625 expr := $2 7626 expr.SetText(parser.lexer.client, parser.src[startOffset:endOffset]) 7627 $$ = &ast.ParenthesesExpr{Expr: expr} 7628 } 7629 | '(' ExpressionList ',' Expression ')' 7630 { 7631 values := append($2.([]ast.ExprNode), $4) 7632 $$ = &ast.RowExpr{Values: values} 7633 } 7634 | "ROW" '(' ExpressionList ',' Expression ')' 7635 { 7636 values := append($3.([]ast.ExprNode), $5) 7637 $$ = &ast.RowExpr{Values: values} 7638 } 7639 | "EXISTS" SubSelect 7640 { 7641 sq := $2.(*ast.SubqueryExpr) 7642 sq.Exists = true 7643 $$ = &ast.ExistsSubqueryExpr{Sel: sq} 7644 } 7645 | '{' Identifier Expression '}' 7646 { 7647 /* 7648 * ODBC escape syntax. 7649 * See https://dev.mysql.com/doc/refman/5.7/en/expressions.html 7650 */ 7651 tp := $3.GetType() 7652 switch $2 { 7653 case "d": 7654 tp.SetCharset("") 7655 tp.SetCollate("") 7656 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.DateLiteral), Args: []ast.ExprNode{$3}} 7657 case "t": 7658 tp.SetCharset("") 7659 tp.SetCollate("") 7660 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimeLiteral), Args: []ast.ExprNode{$3}} 7661 case "ts": 7662 tp.SetCharset("") 7663 tp.SetCollate("") 7664 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimestampLiteral), Args: []ast.ExprNode{$3}} 7665 default: 7666 $$ = $3 7667 } 7668 } 7669 | "BINARY" SimpleExpr %prec neg 7670 { 7671 // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary 7672 tp := types.NewFieldType(mysql.TypeString) 7673 tp.SetCharset(charset.CharsetBin) 7674 tp.SetCollate(charset.CharsetBin) 7675 tp.AddFlag(mysql.BinaryFlag) 7676 $$ = &ast.FuncCastExpr{ 7677 Expr: $2, 7678 Tp: tp, 7679 FunctionType: ast.CastBinaryOperator, 7680 } 7681 } 7682 | builtinCast '(' Expression "AS" CastType ArrayKwdOpt ')' 7683 { 7684 /* See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast */ 7685 tp := $5.(*types.FieldType) 7686 defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.GetType()) 7687 if tp.GetFlen() == types.UnspecifiedLength { 7688 tp.SetFlen(defaultFlen) 7689 } 7690 if tp.GetDecimal() == types.UnspecifiedLength { 7691 tp.SetDecimal(defaultDecimal) 7692 } 7693 isArray := $6.(bool) 7694 tp.SetArray(isArray) 7695 explicitCharset := parser.explicitCharset 7696 if isArray && !explicitCharset && tp.GetCharset() != charset.CharsetBin { 7697 tp.SetCharset(charset.CharsetUTF8MB4) 7698 tp.SetCollate(charset.CollationUTF8MB4) 7699 } 7700 parser.explicitCharset = false 7701 $$ = &ast.FuncCastExpr{ 7702 Expr: $3, 7703 Tp: tp, 7704 FunctionType: ast.CastFunction, 7705 ExplicitCharSet: explicitCharset, 7706 } 7707 } 7708 | "CASE" ExpressionOpt WhenClauseList ElseOpt "END" 7709 { 7710 x := &ast.CaseExpr{WhenClauses: $3.([]*ast.WhenClause)} 7711 if $2 != nil { 7712 x.Value = $2 7713 } 7714 if $4 != nil { 7715 x.ElseClause = $4.(ast.ExprNode) 7716 } 7717 $$ = x 7718 } 7719 | "CONVERT" '(' Expression ',' CastType ')' 7720 { 7721 // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert 7722 tp := $5.(*types.FieldType) 7723 defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.GetType()) 7724 if tp.GetFlen() == types.UnspecifiedLength { 7725 tp.SetFlen(defaultFlen) 7726 } 7727 if tp.GetDecimal() == types.UnspecifiedLength { 7728 tp.SetDecimal(defaultDecimal) 7729 } 7730 explicitCharset := parser.explicitCharset 7731 parser.explicitCharset = false 7732 $$ = &ast.FuncCastExpr{ 7733 Expr: $3, 7734 Tp: tp, 7735 FunctionType: ast.CastConvertFunction, 7736 ExplicitCharSet: explicitCharset, 7737 } 7738 } 7739 | "CONVERT" '(' Expression "USING" CharsetName ')' 7740 { 7741 // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert 7742 charset1 := ast.NewValueExpr($5, "", "") 7743 $$ = &ast.FuncCallExpr{ 7744 FnName: model.NewCIStr($1), 7745 Args: []ast.ExprNode{$3, charset1}, 7746 } 7747 } 7748 | "DEFAULT" '(' SimpleIdent ')' 7749 { 7750 $$ = &ast.DefaultExpr{Name: $3.(*ast.ColumnNameExpr).Name} 7751 } 7752 | "VALUES" '(' SimpleIdent ')' %prec lowerThanInsertValues 7753 { 7754 $$ = &ast.ValuesExpr{Column: $3.(*ast.ColumnNameExpr)} 7755 } 7756 | SimpleIdent jss stringLit 7757 { 7758 expr := ast.NewValueExpr($3, parser.charset, parser.collation) 7759 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}} 7760 } 7761 | SimpleIdent juss stringLit 7762 { 7763 expr := ast.NewValueExpr($3, parser.charset, parser.collation) 7764 extract := &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}} 7765 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONUnquote), Args: []ast.ExprNode{extract}} 7766 } 7767 7768 ArrayKwdOpt: 7769 { 7770 $$ = false 7771 } 7772 | "ARRAY" 7773 { 7774 $$ = true 7775 } 7776 7777 DistinctKwd: 7778 "DISTINCT" 7779 | "DISTINCTROW" 7780 7781 DistinctOpt: 7782 "ALL" 7783 { 7784 $$ = false 7785 } 7786 | DistinctKwd 7787 { 7788 $$ = true 7789 } 7790 7791 DefaultFalseDistinctOpt: 7792 { 7793 $$ = false 7794 } 7795 | DistinctOpt 7796 7797 DefaultTrueDistinctOpt: 7798 { 7799 $$ = true 7800 } 7801 | DistinctOpt 7802 7803 BuggyDefaultFalseDistinctOpt: 7804 DefaultFalseDistinctOpt 7805 | DistinctKwd "ALL" 7806 { 7807 $$ = true 7808 } 7809 7810 FunctionNameConflict: 7811 "ASCII" 7812 | "CHARSET" 7813 | "COALESCE" 7814 | "COLLATION" 7815 | "DATE" 7816 | "DATABASE" 7817 | "DAY" 7818 | "HOUR" 7819 | "IF" 7820 | "INTERVAL" 7821 | "FORMAT" 7822 | "LEFT" 7823 | "MICROSECOND" 7824 | "MINUTE" 7825 | "MONTH" 7826 | builtinNow 7827 | "POINT" 7828 | "QUARTER" 7829 | "REPEAT" 7830 | "REPLACE" 7831 | "REVERSE" 7832 | "RIGHT" 7833 | "ROW_COUNT" 7834 | "SECOND" 7835 | "TIME" 7836 | "TIMESTAMP" 7837 | "TRUNCATE" 7838 | "USER" 7839 | "WEEK" 7840 | "YEAR" 7841 7842 OptionalBraces: 7843 {} 7844 | '(' ')' 7845 {} 7846 7847 FunctionNameOptionalBraces: 7848 "CURRENT_USER" 7849 | "CURRENT_DATE" 7850 | "CURRENT_ROLE" 7851 | "UTC_DATE" 7852 | "TiDB_CURRENT_TSO" 7853 7854 FunctionNameDatetimePrecision: 7855 "CURRENT_TIME" 7856 | "CURRENT_TIMESTAMP" 7857 | "LOCALTIME" 7858 | "LOCALTIMESTAMP" 7859 | "UTC_TIME" 7860 | "UTC_TIMESTAMP" 7861 7862 FunctionCallKeyword: 7863 FunctionNameConflict '(' ExpressionListOpt ')' 7864 { 7865 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} 7866 } 7867 | builtinUser '(' ExpressionListOpt ')' 7868 { 7869 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} 7870 } 7871 | FunctionNameOptionalBraces OptionalBraces 7872 { 7873 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)} 7874 } 7875 | builtinCurDate '(' ')' 7876 { 7877 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)} 7878 } 7879 | FunctionNameDatetimePrecision FuncDatetimePrec 7880 { 7881 args := []ast.ExprNode{} 7882 if $2 != nil { 7883 args = append(args, $2.(ast.ExprNode)) 7884 } 7885 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args} 7886 } 7887 | "CHAR" '(' ExpressionList ')' 7888 { 7889 nilVal := ast.NewValueExpr(nil, parser.charset, parser.collation) 7890 args := $3.([]ast.ExprNode) 7891 $$ = &ast.FuncCallExpr{ 7892 FnName: model.NewCIStr(ast.CharFunc), 7893 Args: append(args, nilVal), 7894 } 7895 } 7896 | "CHAR" '(' ExpressionList "USING" CharsetName ')' 7897 { 7898 charset1 := ast.NewValueExpr($5, "", "") 7899 args := $3.([]ast.ExprNode) 7900 $$ = &ast.FuncCallExpr{ 7901 FnName: model.NewCIStr(ast.CharFunc), 7902 Args: append(args, charset1), 7903 } 7904 } 7905 | "DATE" stringLit 7906 { 7907 expr := ast.NewValueExpr($2, "", "") 7908 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.DateLiteral), Args: []ast.ExprNode{expr}} 7909 } 7910 | "TIME" stringLit 7911 { 7912 expr := ast.NewValueExpr($2, "", "") 7913 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimeLiteral), Args: []ast.ExprNode{expr}} 7914 } 7915 | "TIMESTAMP" stringLit 7916 { 7917 expr := ast.NewValueExpr($2, "", "") 7918 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimestampLiteral), Args: []ast.ExprNode{expr}} 7919 } 7920 | "INSERT" '(' ExpressionListOpt ')' 7921 { 7922 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.InsertFunc), Args: $3.([]ast.ExprNode)} 7923 } 7924 | "MOD" '(' BitExpr ',' BitExpr ')' 7925 { 7926 $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $3, R: $5} 7927 } 7928 | "PASSWORD" '(' ExpressionListOpt ')' 7929 { 7930 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.PasswordFunc), Args: $3.([]ast.ExprNode)} 7931 } 7932 7933 FunctionCallNonKeyword: 7934 builtinCurTime '(' FuncDatetimePrecListOpt ')' 7935 { 7936 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} 7937 } 7938 | builtinSysDate '(' FuncDatetimePrecListOpt ')' 7939 { 7940 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} 7941 } 7942 | FunctionNameDateArithMultiForms '(' Expression ',' Expression ')' 7943 { 7944 $$ = &ast.FuncCallExpr{ 7945 FnName: model.NewCIStr($1), 7946 Args: []ast.ExprNode{ 7947 $3, 7948 $5, 7949 &ast.TimeUnitExpr{Unit: ast.TimeUnitDay}, 7950 }, 7951 } 7952 } 7953 | FunctionNameDateArithMultiForms '(' Expression ',' "INTERVAL" Expression TimeUnit ')' 7954 { 7955 $$ = &ast.FuncCallExpr{ 7956 FnName: model.NewCIStr($1), 7957 Args: []ast.ExprNode{ 7958 $3, 7959 $6, 7960 &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)}, 7961 }, 7962 } 7963 } 7964 | FunctionNameDateArith '(' Expression ',' "INTERVAL" Expression TimeUnit ')' 7965 { 7966 $$ = &ast.FuncCallExpr{ 7967 FnName: model.NewCIStr($1), 7968 Args: []ast.ExprNode{ 7969 $3, 7970 $6, 7971 &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)}, 7972 }, 7973 } 7974 } 7975 | builtinExtract '(' TimeUnit "FROM" Expression ')' 7976 { 7977 timeUnit := &ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)} 7978 $$ = &ast.FuncCallExpr{ 7979 FnName: model.NewCIStr($1), 7980 Args: []ast.ExprNode{timeUnit, $5}, 7981 } 7982 } 7983 | "GET_FORMAT" '(' GetFormatSelector ',' Expression ')' 7984 { 7985 $$ = &ast.FuncCallExpr{ 7986 FnName: model.NewCIStr($1), 7987 Args: []ast.ExprNode{ 7988 &ast.GetFormatSelectorExpr{Selector: $3.(ast.GetFormatSelectorType)}, 7989 $5, 7990 }, 7991 } 7992 } 7993 | builtinPosition '(' BitExpr "IN" Expression ')' 7994 { 7995 $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: []ast.ExprNode{$3, $5}} 7996 } 7997 | builtinSubstring '(' Expression ',' Expression ')' 7998 { 7999 $$ = &ast.FuncCallExpr{ 8000 FnName: model.NewCIStr($1), 8001 Args: []ast.ExprNode{$3, $5}, 8002 } 8003 } 8004 | builtinSubstring '(' Expression "FROM" Expression ')' 8005 { 8006 $$ = &ast.FuncCallExpr{ 8007 FnName: model.NewCIStr($1), 8008 Args: []ast.ExprNode{$3, $5}, 8009 } 8010 } 8011 | builtinSubstring '(' Expression ',' Expression ',' Expression ')' 8012 { 8013 $$ = &ast.FuncCallExpr{ 8014 FnName: model.NewCIStr($1), 8015 Args: []ast.ExprNode{$3, $5, $7}, 8016 } 8017 } 8018 | builtinSubstring '(' Expression "FROM" Expression "FOR" Expression ')' 8019 { 8020 $$ = &ast.FuncCallExpr{ 8021 FnName: model.NewCIStr($1), 8022 Args: []ast.ExprNode{$3, $5, $7}, 8023 } 8024 } 8025 | "TIMESTAMPADD" '(' TimestampUnit ',' Expression ',' Expression ')' 8026 { 8027 $$ = &ast.FuncCallExpr{ 8028 FnName: model.NewCIStr($1), 8029 Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7}, 8030 } 8031 } 8032 | "TIMESTAMPDIFF" '(' TimestampUnit ',' Expression ',' Expression ')' 8033 { 8034 $$ = &ast.FuncCallExpr{ 8035 FnName: model.NewCIStr($1), 8036 Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7}, 8037 } 8038 } 8039 | builtinTrim '(' Expression ')' 8040 { 8041 $$ = &ast.FuncCallExpr{ 8042 FnName: model.NewCIStr($1), 8043 Args: []ast.ExprNode{$3}, 8044 } 8045 } 8046 | builtinTrim '(' Expression "FROM" Expression ')' 8047 { 8048 $$ = &ast.FuncCallExpr{ 8049 FnName: model.NewCIStr($1), 8050 Args: []ast.ExprNode{$5, $3}, 8051 } 8052 } 8053 | builtinTrim '(' TrimDirection "FROM" Expression ')' 8054 { 8055 spaceVal := ast.NewValueExpr(" ", parser.charset, parser.collation) 8056 direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)} 8057 $$ = &ast.FuncCallExpr{ 8058 FnName: model.NewCIStr($1), 8059 Args: []ast.ExprNode{$5, spaceVal, direction}, 8060 } 8061 } 8062 | builtinTrim '(' TrimDirection Expression "FROM" Expression ')' 8063 { 8064 direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)} 8065 $$ = &ast.FuncCallExpr{ 8066 FnName: model.NewCIStr($1), 8067 Args: []ast.ExprNode{$6, $4, direction}, 8068 } 8069 } 8070 | weightString '(' Expression ')' 8071 { 8072 $$ = &ast.FuncCallExpr{ 8073 FnName: model.NewCIStr($1), 8074 Args: []ast.ExprNode{$3}, 8075 } 8076 } 8077 | weightString '(' Expression "AS" Char FieldLen ')' 8078 { 8079 $$ = &ast.FuncCallExpr{ 8080 FnName: model.NewCIStr($1), 8081 Args: []ast.ExprNode{$3, ast.NewValueExpr("CHAR", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)}, 8082 } 8083 } 8084 | weightString '(' Expression "AS" "BINARY" FieldLen ')' 8085 { 8086 $$ = &ast.FuncCallExpr{ 8087 FnName: model.NewCIStr($1), 8088 Args: []ast.ExprNode{$3, ast.NewValueExpr("BINARY", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)}, 8089 } 8090 } 8091 | FunctionNameSequence 8092 | builtinTranslate '(' Expression ',' Expression ',' Expression ')' 8093 { 8094 $$ = &ast.FuncCallExpr{ 8095 FnName: model.NewCIStr($1), 8096 Args: []ast.ExprNode{$3, $5, $7}, 8097 } 8098 } 8099 8100 GetFormatSelector: 8101 "DATE" 8102 { 8103 $$ = ast.GetFormatSelectorDate 8104 } 8105 | "DATETIME" 8106 { 8107 $$ = ast.GetFormatSelectorDatetime 8108 } 8109 | "TIME" 8110 { 8111 $$ = ast.GetFormatSelectorTime 8112 } 8113 | "TIMESTAMP" 8114 { 8115 $$ = ast.GetFormatSelectorDatetime 8116 } 8117 8118 FunctionNameDateArith: 8119 builtinDateAdd 8120 | builtinDateSub 8121 8122 FunctionNameDateArithMultiForms: 8123 addDate 8124 | subDate 8125 8126 TrimDirection: 8127 "BOTH" 8128 { 8129 $$ = ast.TrimBoth 8130 } 8131 | "LEADING" 8132 { 8133 $$ = ast.TrimLeading 8134 } 8135 | "TRAILING" 8136 { 8137 $$ = ast.TrimTrailing 8138 } 8139 8140 FunctionNameSequence: 8141 "LASTVAL" '(' TableName ')' 8142 { 8143 objNameExpr := &ast.TableNameExpr{ 8144 Name: $3.(*ast.TableName), 8145 } 8146 $$ = &ast.FuncCallExpr{ 8147 FnName: model.NewCIStr(ast.LastVal), 8148 Args: []ast.ExprNode{objNameExpr}, 8149 } 8150 } 8151 | "SETVAL" '(' TableName ',' SignedNum ')' 8152 { 8153 objNameExpr := &ast.TableNameExpr{ 8154 Name: $3.(*ast.TableName), 8155 } 8156 valueExpr := ast.NewValueExpr($5, parser.charset, parser.collation) 8157 $$ = &ast.FuncCallExpr{ 8158 FnName: model.NewCIStr(ast.SetVal), 8159 Args: []ast.ExprNode{objNameExpr, valueExpr}, 8160 } 8161 } 8162 | NextValueForSequence 8163 8164 SumExpr: 8165 "AVG" '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8166 { 8167 if $6 != nil { 8168 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8169 } else { 8170 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8171 } 8172 } 8173 | builtinApproxCountDistinct '(' ExpressionList ')' 8174 { 8175 $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode), Distinct: false} 8176 } 8177 | builtinApproxPercentile '(' ExpressionList ')' 8178 { 8179 $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode)} 8180 } 8181 | builtinBitAnd '(' Expression ')' OptWindowingClause 8182 { 8183 if $5 != nil { 8184 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))} 8185 } else { 8186 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} 8187 } 8188 } 8189 | builtinBitAnd '(' "ALL" Expression ')' OptWindowingClause 8190 { 8191 if $6 != nil { 8192 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))} 8193 } else { 8194 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} 8195 } 8196 } 8197 | builtinBitOr '(' Expression ')' OptWindowingClause 8198 { 8199 if $5 != nil { 8200 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))} 8201 } else { 8202 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} 8203 } 8204 } 8205 | builtinBitOr '(' "ALL" Expression ')' OptWindowingClause 8206 { 8207 if $6 != nil { 8208 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))} 8209 } else { 8210 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} 8211 } 8212 } 8213 | builtinBitXor '(' Expression ')' OptWindowingClause 8214 { 8215 if $5 != nil { 8216 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))} 8217 } else { 8218 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} 8219 } 8220 } 8221 | builtinBitXor '(' "ALL" Expression ')' OptWindowingClause 8222 { 8223 if $6 != nil { 8224 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))} 8225 } else { 8226 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} 8227 } 8228 } 8229 | builtinCount '(' DistinctKwd ExpressionList ')' 8230 { 8231 $$ = &ast.AggregateFuncExpr{F: $1, Args: $4.([]ast.ExprNode), Distinct: true} 8232 } 8233 | builtinCount '(' "ALL" Expression ')' OptWindowingClause 8234 { 8235 if $6 != nil { 8236 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))} 8237 } else { 8238 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} 8239 } 8240 } 8241 | builtinCount '(' Expression ')' OptWindowingClause 8242 { 8243 if $5 != nil { 8244 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))} 8245 } else { 8246 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} 8247 } 8248 } 8249 | builtinCount '(' '*' ')' OptWindowingClause 8250 { 8251 args := []ast.ExprNode{ast.NewValueExpr(1, parser.charset, parser.collation)} 8252 if $5 != nil { 8253 $$ = &ast.WindowFuncExpr{Name: $1, Args: args, Spec: *($5.(*ast.WindowSpec))} 8254 } else { 8255 $$ = &ast.AggregateFuncExpr{F: $1, Args: args} 8256 } 8257 } 8258 | builtinGroupConcat '(' BuggyDefaultFalseDistinctOpt ExpressionList OrderByOptional OptGConcatSeparator ')' OptWindowingClause 8259 { 8260 args := $4.([]ast.ExprNode) 8261 args = append(args, $6.(ast.ExprNode)) 8262 if $8 != nil { 8263 $$ = &ast.WindowFuncExpr{Name: $1, Args: args, Distinct: $3.(bool), Spec: *($8.(*ast.WindowSpec))} 8264 } else { 8265 agg := &ast.AggregateFuncExpr{F: $1, Args: args, Distinct: $3.(bool)} 8266 if $5 != nil { 8267 agg.Order = $5.(*ast.OrderByClause) 8268 } 8269 $$ = agg 8270 } 8271 } 8272 | builtinMax '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8273 { 8274 if $6 != nil { 8275 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8276 } else { 8277 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8278 } 8279 } 8280 | builtinMin '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8281 { 8282 if $6 != nil { 8283 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8284 } else { 8285 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8286 } 8287 } 8288 | builtinSum '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8289 { 8290 if $6 != nil { 8291 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8292 } else { 8293 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8294 } 8295 } 8296 | builtinStddevPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8297 { 8298 if $6 != nil { 8299 $$ = &ast.WindowFuncExpr{Name: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8300 } else { 8301 $$ = &ast.AggregateFuncExpr{F: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8302 } 8303 } 8304 | builtinStddevSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8305 { 8306 if $6 != nil { 8307 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8308 } else { 8309 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8310 } 8311 } 8312 | builtinVarPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8313 { 8314 if $6 != nil { 8315 $$ = &ast.WindowFuncExpr{Name: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))} 8316 } else { 8317 $$ = &ast.AggregateFuncExpr{F: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8318 } 8319 } 8320 | builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause 8321 { 8322 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)} 8323 } 8324 | "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause 8325 { 8326 if $5 != nil { 8327 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))} 8328 } else { 8329 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}} 8330 } 8331 } 8332 | "JSON_ARRAYAGG" '(' "ALL" Expression ')' OptWindowingClause 8333 { 8334 if $6 != nil { 8335 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))} 8336 } else { 8337 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}} 8338 } 8339 } 8340 | "JSON_OBJECTAGG" '(' Expression ',' Expression ')' OptWindowingClause 8341 { 8342 if $7 != nil { 8343 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3, $5}, Spec: *($7.(*ast.WindowSpec))} 8344 } else { 8345 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}} 8346 } 8347 } 8348 | "JSON_OBJECTAGG" '(' "ALL" Expression ',' Expression ')' OptWindowingClause 8349 { 8350 if $8 != nil { 8351 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4, $6}, Spec: *($8.(*ast.WindowSpec))} 8352 } else { 8353 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $6}} 8354 } 8355 } 8356 | "JSON_OBJECTAGG" '(' Expression ',' "ALL" Expression ')' OptWindowingClause 8357 { 8358 if $8 != nil { 8359 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3, $6}, Spec: *($8.(*ast.WindowSpec))} 8360 } else { 8361 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $6}} 8362 } 8363 } 8364 | "JSON_OBJECTAGG" '(' "ALL" Expression ',' "ALL" Expression ')' OptWindowingClause 8365 { 8366 if $9 != nil { 8367 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$4, $7}, Spec: *($9.(*ast.WindowSpec))} 8368 } else { 8369 $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $7}} 8370 } 8371 } 8372 8373 OptGConcatSeparator: 8374 { 8375 $$ = ast.NewValueExpr(",", "", "") 8376 } 8377 | "SEPARATOR" stringLit 8378 { 8379 $$ = ast.NewValueExpr($2, "", "") 8380 } 8381 8382 FunctionCallGeneric: 8383 identifier '(' ExpressionListOpt ')' 8384 { 8385 $$ = &ast.FuncCallExpr{ 8386 FnName: model.NewCIStr($1), 8387 Args: $3.([]ast.ExprNode), 8388 } 8389 } 8390 | Identifier '.' Identifier '(' ExpressionListOpt ')' 8391 { 8392 var tp ast.FuncCallExprType 8393 if isInTokenMap($3) { 8394 tp = ast.FuncCallExprTypeKeyword 8395 } else { 8396 tp = ast.FuncCallExprTypeGeneric 8397 } 8398 $$ = &ast.FuncCallExpr{ 8399 Tp: tp, 8400 Schema: model.NewCIStr($1), 8401 FnName: model.NewCIStr($3), 8402 Args: $5.([]ast.ExprNode), 8403 } 8404 } 8405 8406 FuncDatetimePrec: 8407 { 8408 $$ = nil 8409 } 8410 | '(' ')' 8411 { 8412 $$ = nil 8413 } 8414 | '(' intLit ')' 8415 { 8416 expr := ast.NewValueExpr($2, parser.charset, parser.collation) 8417 $$ = expr 8418 } 8419 8420 TimeUnit: 8421 TimestampUnit 8422 | "SECOND_MICROSECOND" 8423 { 8424 $$ = ast.TimeUnitSecondMicrosecond 8425 } 8426 | "MINUTE_MICROSECOND" 8427 { 8428 $$ = ast.TimeUnitMinuteMicrosecond 8429 } 8430 | "MINUTE_SECOND" 8431 { 8432 $$ = ast.TimeUnitMinuteSecond 8433 } 8434 | "HOUR_MICROSECOND" 8435 { 8436 $$ = ast.TimeUnitHourMicrosecond 8437 } 8438 | "HOUR_SECOND" 8439 { 8440 $$ = ast.TimeUnitHourSecond 8441 } 8442 | "HOUR_MINUTE" 8443 { 8444 $$ = ast.TimeUnitHourMinute 8445 } 8446 | "DAY_MICROSECOND" 8447 { 8448 $$ = ast.TimeUnitDayMicrosecond 8449 } 8450 | "DAY_SECOND" 8451 { 8452 $$ = ast.TimeUnitDaySecond 8453 } 8454 | "DAY_MINUTE" 8455 { 8456 $$ = ast.TimeUnitDayMinute 8457 } 8458 | "DAY_HOUR" 8459 { 8460 $$ = ast.TimeUnitDayHour 8461 } 8462 | "YEAR_MONTH" 8463 { 8464 $$ = ast.TimeUnitYearMonth 8465 } 8466 8467 TimestampUnit: 8468 "MICROSECOND" 8469 { 8470 $$ = ast.TimeUnitMicrosecond 8471 } 8472 | "SECOND" 8473 { 8474 $$ = ast.TimeUnitSecond 8475 } 8476 | "MINUTE" 8477 { 8478 $$ = ast.TimeUnitMinute 8479 } 8480 | "HOUR" 8481 { 8482 $$ = ast.TimeUnitHour 8483 } 8484 | "DAY" 8485 { 8486 $$ = ast.TimeUnitDay 8487 } 8488 | "WEEK" 8489 { 8490 $$ = ast.TimeUnitWeek 8491 } 8492 | "MONTH" 8493 { 8494 $$ = ast.TimeUnitMonth 8495 } 8496 | "QUARTER" 8497 { 8498 $$ = ast.TimeUnitQuarter 8499 } 8500 | "YEAR" 8501 { 8502 $$ = ast.TimeUnitYear 8503 } 8504 | "SQL_TSI_SECOND" 8505 { 8506 $$ = ast.TimeUnitSecond 8507 } 8508 | "SQL_TSI_MINUTE" 8509 { 8510 $$ = ast.TimeUnitMinute 8511 } 8512 | "SQL_TSI_HOUR" 8513 { 8514 $$ = ast.TimeUnitHour 8515 } 8516 | "SQL_TSI_DAY" 8517 { 8518 $$ = ast.TimeUnitDay 8519 } 8520 | "SQL_TSI_WEEK" 8521 { 8522 $$ = ast.TimeUnitWeek 8523 } 8524 | "SQL_TSI_MONTH" 8525 { 8526 $$ = ast.TimeUnitMonth 8527 } 8528 | "SQL_TSI_QUARTER" 8529 { 8530 $$ = ast.TimeUnitQuarter 8531 } 8532 | "SQL_TSI_YEAR" 8533 { 8534 $$ = ast.TimeUnitYear 8535 } 8536 8537 ExpressionOpt: 8538 { 8539 $$ = nil 8540 } 8541 | Expression 8542 8543 WhenClauseList: 8544 WhenClause 8545 { 8546 $$ = []*ast.WhenClause{$1.(*ast.WhenClause)} 8547 } 8548 | WhenClauseList WhenClause 8549 { 8550 $$ = append($1.([]*ast.WhenClause), $2.(*ast.WhenClause)) 8551 } 8552 8553 WhenClause: 8554 "WHEN" Expression "THEN" Expression 8555 { 8556 $$ = &ast.WhenClause{ 8557 Expr: $2, 8558 Result: $4, 8559 } 8560 } 8561 8562 ElseOpt: 8563 /* empty */ 8564 { 8565 $$ = nil 8566 } 8567 | "ELSE" Expression 8568 { 8569 $$ = $2 8570 } 8571 8572 CastType: 8573 "BINARY" OptFieldLen 8574 { 8575 tp := types.NewFieldType(mysql.TypeVarString) 8576 tp.SetFlen($2.(int)) // TODO: Flen should be the flen of expression 8577 if tp.GetFlen() != types.UnspecifiedLength { 8578 tp.SetType(mysql.TypeString) 8579 } 8580 tp.SetCharset(charset.CharsetBin) 8581 tp.SetCollate(charset.CollationBin) 8582 tp.AddFlag(mysql.BinaryFlag) 8583 $$ = tp 8584 } 8585 | Char OptFieldLen OptBinary 8586 { 8587 tp := types.NewFieldType(mysql.TypeVarString) 8588 tp.SetFlen($2.(int)) // TODO: Flen should be the flen of expression 8589 tp.SetCharset($3.(*ast.OptBinary).Charset) 8590 if $3.(*ast.OptBinary).IsBinary { 8591 tp.AddFlag(mysql.BinaryFlag) 8592 tp.SetCharset(charset.CharsetBin) 8593 tp.SetCollate(charset.CollationBin) 8594 } else if tp.GetCharset() != "" { 8595 co, err := charset.GetDefaultCollation(tp.GetCharset()) 8596 if err != nil { 8597 yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", tp.GetCharset())) 8598 return 1 8599 } 8600 tp.SetCollate(co) 8601 parser.explicitCharset = true 8602 } else { 8603 tp.SetCharset(parser.charset) 8604 tp.SetCollate(parser.collation) 8605 } 8606 $$ = tp 8607 } 8608 | "DATE" 8609 { 8610 tp := types.NewFieldType(mysql.TypeDate) 8611 tp.SetCharset(charset.CharsetBin) 8612 tp.SetCollate(charset.CollationBin) 8613 tp.AddFlag(mysql.BinaryFlag) 8614 $$ = tp 8615 } 8616 | "YEAR" 8617 { 8618 tp := types.NewFieldType(mysql.TypeYear) 8619 tp.SetCharset(charset.CharsetBin) 8620 tp.SetCollate(charset.CollationBin) 8621 tp.AddFlag(mysql.BinaryFlag) 8622 $$ = tp 8623 } 8624 | "DATETIME" OptFieldLen 8625 { 8626 tp := types.NewFieldType(mysql.TypeDatetime) 8627 flen, _ := mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDatetime) 8628 tp.SetFlen(flen) 8629 tp.SetDecimal($2.(int)) 8630 if tp.GetDecimal() > 0 { 8631 tp.SetFlen(tp.GetFlen() + 1 + tp.GetDecimal()) 8632 } 8633 tp.SetCharset(charset.CharsetBin) 8634 tp.SetCollate(charset.CollationBin) 8635 tp.AddFlag(mysql.BinaryFlag) 8636 $$ = tp 8637 } 8638 | "DECIMAL" FloatOpt 8639 { 8640 fopt := $2.(*ast.FloatOpt) 8641 tp := types.NewFieldType(mysql.TypeNewDecimal) 8642 tp.SetFlen(fopt.Flen) 8643 tp.SetDecimal(fopt.Decimal) 8644 tp.SetCharset(charset.CharsetBin) 8645 tp.SetCollate(charset.CollationBin) 8646 tp.AddFlag(mysql.BinaryFlag) 8647 $$ = tp 8648 } 8649 | "TIME" OptFieldLen 8650 { 8651 tp := types.NewFieldType(mysql.TypeDuration) 8652 flen, _ := mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDuration) 8653 tp.SetFlen(flen) 8654 tp.SetDecimal($2.(int)) 8655 if tp.GetDecimal() > 0 { 8656 tp.SetFlen(tp.GetFlen() + 1 + tp.GetDecimal()) 8657 } 8658 tp.SetCharset(charset.CharsetBin) 8659 tp.SetCollate(charset.CollationBin) 8660 tp.AddFlag(mysql.BinaryFlag) 8661 $$ = tp 8662 } 8663 | "SIGNED" OptInteger 8664 { 8665 tp := types.NewFieldType(mysql.TypeLonglong) 8666 tp.SetCharset(charset.CharsetBin) 8667 tp.SetCollate(charset.CollationBin) 8668 tp.AddFlag(mysql.BinaryFlag) 8669 $$ = tp 8670 } 8671 | "UNSIGNED" OptInteger 8672 { 8673 tp := types.NewFieldType(mysql.TypeLonglong) 8674 tp.AddFlag(mysql.UnsignedFlag | mysql.BinaryFlag) 8675 tp.SetCharset(charset.CharsetBin) 8676 tp.SetCollate(charset.CollationBin) 8677 $$ = tp 8678 } 8679 | "JSON" 8680 { 8681 tp := types.NewFieldType(mysql.TypeJSON) 8682 tp.AddFlag(mysql.BinaryFlag | mysql.ParseToJSONFlag) 8683 tp.SetCharset(mysql.DefaultCharset) 8684 tp.SetCollate(mysql.DefaultCollationName) 8685 $$ = tp 8686 } 8687 | "DOUBLE" 8688 { 8689 tp := types.NewFieldType(mysql.TypeDouble) 8690 flen, decimal := mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDouble) 8691 tp.SetFlen(flen) 8692 tp.SetDecimal(decimal) 8693 tp.AddFlag(mysql.BinaryFlag) 8694 tp.SetCharset(charset.CharsetBin) 8695 tp.SetCollate(charset.CollationBin) 8696 $$ = tp 8697 } 8698 | "FLOAT" FloatOpt 8699 { 8700 tp := types.NewFieldType(mysql.TypeFloat) 8701 fopt := $2.(*ast.FloatOpt) 8702 if fopt.Flen >= 54 { 8703 yylex.AppendError(ErrTooBigPrecision.GenWithStackByArgs(fopt.Flen, "CAST", 53)) 8704 } else if fopt.Flen >= 25 { 8705 tp = types.NewFieldType(mysql.TypeDouble) 8706 } 8707 flen, decimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.GetType()) 8708 tp.SetFlen(flen) 8709 tp.SetDecimal(decimal) 8710 tp.AddFlag(mysql.BinaryFlag) 8711 tp.SetCharset(charset.CharsetBin) 8712 tp.SetCollate(charset.CollationBin) 8713 $$ = tp 8714 } 8715 | "REAL" 8716 { 8717 var tp *types.FieldType 8718 if parser.lexer.GetSQLMode().HasRealAsFloatMode() { 8719 tp = types.NewFieldType(mysql.TypeFloat) 8720 } else { 8721 tp = types.NewFieldType(mysql.TypeDouble) 8722 } 8723 flen, decimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.GetType()) 8724 tp.SetFlen(flen) 8725 tp.SetDecimal(decimal) 8726 tp.AddFlag(mysql.BinaryFlag) 8727 tp.SetCharset(charset.CharsetBin) 8728 tp.SetCollate(charset.CollationBin) 8729 $$ = tp 8730 } 8731 8732 Priority: 8733 "LOW_PRIORITY" 8734 { 8735 $$ = mysql.LowPriority 8736 } 8737 | "HIGH_PRIORITY" 8738 { 8739 $$ = mysql.HighPriority 8740 } 8741 | "DELAYED" 8742 { 8743 $$ = mysql.DelayedPriority 8744 } 8745 8746 PriorityOpt: 8747 { 8748 $$ = mysql.NoPriority 8749 } 8750 | Priority 8751 8752 TableName: 8753 Identifier 8754 { 8755 $$ = &ast.TableName{Name: model.NewCIStr($1)} 8756 } 8757 | Identifier '.' Identifier 8758 { 8759 $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)} 8760 } 8761 8762 TableNameList: 8763 TableName 8764 { 8765 tbl := []*ast.TableName{$1.(*ast.TableName)} 8766 $$ = tbl 8767 } 8768 | TableNameList ',' TableName 8769 { 8770 $$ = append($1.([]*ast.TableName), $3.(*ast.TableName)) 8771 } 8772 8773 TableNameOptWild: 8774 Identifier OptWild 8775 { 8776 $$ = &ast.TableName{Name: model.NewCIStr($1)} 8777 } 8778 | Identifier '.' Identifier OptWild 8779 { 8780 $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)} 8781 } 8782 8783 TableAliasRefList: 8784 TableNameOptWild 8785 { 8786 tbl := []*ast.TableName{$1.(*ast.TableName)} 8787 $$ = tbl 8788 } 8789 | TableAliasRefList ',' TableNameOptWild 8790 { 8791 $$ = append($1.([]*ast.TableName), $3.(*ast.TableName)) 8792 } 8793 8794 OptWild: 8795 %prec empty 8796 {} 8797 | '.' '*' 8798 {} 8799 8800 QuickOptional: 8801 %prec empty 8802 { 8803 $$ = false 8804 } 8805 | "QUICK" 8806 { 8807 $$ = true 8808 } 8809 8810 /***************************Prepared Statement Start****************************** 8811 * See https://dev.mysql.com/doc/refman/5.7/en/prepare.html 8812 * Example: 8813 * PREPARE stmt_name FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse'; 8814 * OR 8815 * SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse'; 8816 * PREPARE stmt_name FROM @s; 8817 */ 8818 PreparedStmt: 8819 "PREPARE" Identifier "FROM" PrepareSQL 8820 { 8821 var sqlText string 8822 var sqlVar *ast.VariableExpr 8823 switch x := $4.(type) { 8824 case string: 8825 sqlText = x 8826 case *ast.VariableExpr: 8827 sqlVar = x 8828 } 8829 $$ = &ast.PrepareStmt{ 8830 Name: $2, 8831 SQLText: sqlText, 8832 SQLVar: sqlVar, 8833 } 8834 } 8835 8836 PrepareSQL: 8837 stringLit 8838 { 8839 $$ = $1 8840 } 8841 | UserVariable 8842 { 8843 $$ = $1 8844 } 8845 8846 /* 8847 * See https://dev.mysql.com/doc/refman/5.7/en/execute.html 8848 * Example: 8849 * EXECUTE stmt1 USING @a, @b; 8850 * OR 8851 * EXECUTE stmt1; 8852 */ 8853 ExecuteStmt: 8854 "EXECUTE" Identifier 8855 { 8856 $$ = &ast.ExecuteStmt{Name: $2} 8857 } 8858 | "EXECUTE" Identifier "USING" UserVariableList 8859 { 8860 $$ = &ast.ExecuteStmt{ 8861 Name: $2, 8862 UsingVars: $4.([]ast.ExprNode), 8863 } 8864 } 8865 8866 UserVariableList: 8867 UserVariable 8868 { 8869 $$ = []ast.ExprNode{$1} 8870 } 8871 | UserVariableList ',' UserVariable 8872 { 8873 $$ = append($1.([]ast.ExprNode), $3) 8874 } 8875 8876 DeallocateStmt: 8877 DeallocateSym "PREPARE" Identifier 8878 { 8879 $$ = &ast.DeallocateStmt{Name: $3} 8880 } 8881 8882 DeallocateSym: 8883 "DEALLOCATE" 8884 | "DROP" 8885 8886 RollbackStmt: 8887 "ROLLBACK" 8888 { 8889 $$ = &ast.RollbackStmt{} 8890 } 8891 | "ROLLBACK" CompletionTypeWithinTransaction 8892 { 8893 $$ = &ast.RollbackStmt{CompletionType: $2.(ast.CompletionType)} 8894 } 8895 | "ROLLBACK" "TO" Identifier 8896 { 8897 $$ = &ast.RollbackStmt{SavepointName: $3} 8898 } 8899 | "ROLLBACK" "TO" "SAVEPOINT" Identifier 8900 { 8901 $$ = &ast.RollbackStmt{SavepointName: $4} 8902 } 8903 8904 CompletionTypeWithinTransaction: 8905 "AND" "CHAIN" "NO" "RELEASE" 8906 { 8907 $$ = ast.CompletionTypeChain 8908 } 8909 | "AND" "NO" "CHAIN" "RELEASE" 8910 { 8911 $$ = ast.CompletionTypeRelease 8912 } 8913 | "AND" "NO" "CHAIN" "NO" "RELEASE" 8914 { 8915 $$ = ast.CompletionTypeDefault 8916 } 8917 | "AND" "CHAIN" 8918 { 8919 $$ = ast.CompletionTypeChain 8920 } 8921 | "AND" "NO" "CHAIN" 8922 { 8923 $$ = ast.CompletionTypeDefault 8924 } 8925 | "RELEASE" 8926 { 8927 $$ = ast.CompletionTypeRelease 8928 } 8929 | "NO" "RELEASE" 8930 { 8931 $$ = ast.CompletionTypeDefault 8932 } 8933 8934 ShutdownStmt: 8935 "SHUTDOWN" 8936 { 8937 $$ = &ast.ShutdownStmt{} 8938 } 8939 8940 RestartStmt: 8941 "RESTART" 8942 { 8943 $$ = &ast.RestartStmt{} 8944 } 8945 8946 HelpStmt: 8947 "HELP" stringLit 8948 { 8949 $$ = &ast.HelpStmt{Topic: $2} 8950 } 8951 8952 SelectStmtBasic: 8953 "SELECT" SelectStmtOpts SelectStmtFieldList HavingClause 8954 { 8955 st := &ast.SelectStmt{ 8956 SelectStmtOpts: $2.(*ast.SelectStmtOpts), 8957 Distinct: $2.(*ast.SelectStmtOpts).Distinct, 8958 Fields: $3.(*ast.FieldList), 8959 Kind: ast.SelectStmtKindSelect, 8960 } 8961 if st.SelectStmtOpts.TableHints != nil { 8962 st.TableHints = st.SelectStmtOpts.TableHints 8963 } 8964 if $4 != nil { 8965 st.Having = $4.(*ast.HavingClause) 8966 } 8967 $$ = st 8968 } 8969 8970 SelectStmtFromDualTable: 8971 SelectStmtBasic FromDual WhereClauseOptional 8972 { 8973 st := $1.(*ast.SelectStmt) 8974 lastField := st.Fields.Fields[len(st.Fields.Fields)-1] 8975 if lastField.Expr != nil && lastField.AsName.O == "" { 8976 lastEnd := yyS[yypt-1].offset - 1 8977 lastField.SetText(parser.lexer.client, parser.src[lastField.Offset:lastEnd]) 8978 } 8979 if $3 != nil { 8980 st.Where = $3.(ast.ExprNode) 8981 } 8982 } 8983 8984 SelectStmtFromTable: 8985 SelectStmtBasic "FROM" TableRefsClause WhereClauseOptional SelectStmtGroup HavingClause WindowClauseOptional 8986 { 8987 st := $1.(*ast.SelectStmt) 8988 st.From = $3.(*ast.TableRefsClause) 8989 lastField := st.Fields.Fields[len(st.Fields.Fields)-1] 8990 if lastField.Expr != nil && lastField.AsName.O == "" { 8991 lastEnd := parser.endOffset(&yyS[yypt-5]) 8992 lastField.SetText(parser.lexer.client, parser.src[lastField.Offset:lastEnd]) 8993 } 8994 if $4 != nil { 8995 st.Where = $4.(ast.ExprNode) 8996 } 8997 if $5 != nil { 8998 st.GroupBy = $5.(*ast.GroupByClause) 8999 } 9000 if $6 != nil { 9001 st.Having = $6.(*ast.HavingClause) 9002 } 9003 if $7 != nil { 9004 st.WindowSpecs = ($7.([]ast.WindowSpec)) 9005 } 9006 $$ = st 9007 } 9008 9009 TableSampleOpt: 9010 %prec empty 9011 { 9012 $$ = nil 9013 } 9014 | "TABLESAMPLE" TableSampleMethodOpt '(' Expression TableSampleUnitOpt ')' RepeatableOpt 9015 { 9016 var repSeed ast.ExprNode 9017 if $7 != nil { 9018 repSeed = ast.NewValueExpr($7, parser.charset, parser.collation) 9019 } 9020 $$ = &ast.TableSample{ 9021 SampleMethod: $2.(ast.SampleMethodType), 9022 Expr: ast.NewValueExpr($4, parser.charset, parser.collation), 9023 SampleClauseUnit: $5.(ast.SampleClauseUnitType), 9024 RepeatableSeed: repSeed, 9025 } 9026 } 9027 | "TABLESAMPLE" TableSampleMethodOpt '(' ')' RepeatableOpt 9028 { 9029 var repSeed ast.ExprNode 9030 if $5 != nil { 9031 repSeed = ast.NewValueExpr($5, parser.charset, parser.collation) 9032 } 9033 $$ = &ast.TableSample{ 9034 SampleMethod: $2.(ast.SampleMethodType), 9035 RepeatableSeed: repSeed, 9036 } 9037 } 9038 9039 TableSampleMethodOpt: 9040 %prec empty 9041 { 9042 $$ = ast.SampleMethodTypeNone 9043 } 9044 | "SYSTEM" 9045 { 9046 $$ = ast.SampleMethodTypeSystem 9047 } 9048 | "BERNOULLI" 9049 { 9050 $$ = ast.SampleMethodTypeBernoulli 9051 } 9052 | "REGIONS" 9053 { 9054 $$ = ast.SampleMethodTypeTiDBRegion 9055 } 9056 9057 TableSampleUnitOpt: 9058 %prec empty 9059 { 9060 $$ = ast.SampleClauseUnitTypeDefault 9061 } 9062 | "ROWS" 9063 { 9064 $$ = ast.SampleClauseUnitTypeRow 9065 } 9066 | "PERCENT" 9067 { 9068 $$ = ast.SampleClauseUnitTypePercent 9069 } 9070 9071 RepeatableOpt: 9072 %prec empty 9073 { 9074 $$ = nil 9075 } 9076 | "REPEATABLE" '(' Expression ')' 9077 { 9078 $$ = $3 9079 } 9080 9081 SelectStmt: 9082 SelectStmtBasic WhereClauseOptional SelectStmtGroup OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption 9083 { 9084 st := $1.(*ast.SelectStmt) 9085 if $6 != nil { 9086 st.LockInfo = $6.(*ast.SelectLockInfo) 9087 } 9088 if $2 != nil { 9089 st.Where = $2.(ast.ExprNode) 9090 } 9091 if $3 != nil { 9092 st.GroupBy = $3.(*ast.GroupByClause) 9093 } 9094 if $4 != nil { 9095 st.OrderBy = $4.(*ast.OrderByClause) 9096 } 9097 if $5 != nil { 9098 st.Limit = $5.(*ast.Limit) 9099 } 9100 if $7 != nil { 9101 st.SelectIntoOpt = $7.(*ast.SelectIntoOption) 9102 } 9103 $$ = st 9104 } 9105 | SelectStmtFromDualTable SelectStmtGroup OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption 9106 { 9107 st := $1.(*ast.SelectStmt) 9108 if $2 != nil { 9109 st.GroupBy = $2.(*ast.GroupByClause) 9110 } 9111 if $3 != nil { 9112 st.OrderBy = $3.(*ast.OrderByClause) 9113 } 9114 if $4 != nil { 9115 st.Limit = $4.(*ast.Limit) 9116 } 9117 if $5 != nil { 9118 st.LockInfo = $5.(*ast.SelectLockInfo) 9119 } 9120 if $6 != nil { 9121 st.SelectIntoOpt = $6.(*ast.SelectIntoOption) 9122 } 9123 $$ = st 9124 } 9125 | SelectStmtFromTable OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption 9126 { 9127 st := $1.(*ast.SelectStmt) 9128 if $4 != nil { 9129 st.LockInfo = $4.(*ast.SelectLockInfo) 9130 } 9131 if $2 != nil { 9132 st.OrderBy = $2.(*ast.OrderByClause) 9133 } 9134 if $3 != nil { 9135 st.Limit = $3.(*ast.Limit) 9136 } 9137 if $5 != nil { 9138 st.SelectIntoOpt = $5.(*ast.SelectIntoOption) 9139 } 9140 $$ = st 9141 } 9142 | "TABLE" TableName OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption 9143 { 9144 st := &ast.SelectStmt{ 9145 Kind: ast.SelectStmtKindTable, 9146 Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}}, 9147 } 9148 ts := &ast.TableSource{Source: $2.(*ast.TableName)} 9149 st.From = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}} 9150 if $3 != nil { 9151 st.OrderBy = $3.(*ast.OrderByClause) 9152 } 9153 if $4 != nil { 9154 st.Limit = $4.(*ast.Limit) 9155 } 9156 if $5 != nil { 9157 st.LockInfo = $5.(*ast.SelectLockInfo) 9158 } 9159 if $6 != nil { 9160 st.SelectIntoOpt = $6.(*ast.SelectIntoOption) 9161 } 9162 $$ = st 9163 } 9164 | "VALUES" ValuesStmtList OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption 9165 { 9166 st := &ast.SelectStmt{ 9167 Kind: ast.SelectStmtKindValues, 9168 Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}}, 9169 Lists: $2.([]*ast.RowExpr), 9170 } 9171 if $3 != nil { 9172 st.OrderBy = $3.(*ast.OrderByClause) 9173 } 9174 if $4 != nil { 9175 st.Limit = $4.(*ast.Limit) 9176 } 9177 if $5 != nil { 9178 st.LockInfo = $5.(*ast.SelectLockInfo) 9179 } 9180 if $6 != nil { 9181 st.SelectIntoOpt = $6.(*ast.SelectIntoOption) 9182 } 9183 $$ = st 9184 } 9185 9186 SelectStmtWithClause: 9187 WithClause SelectStmt 9188 { 9189 sel := $2.(*ast.SelectStmt) 9190 sel.With = $1.(*ast.WithClause) 9191 $$ = sel 9192 } 9193 | WithClause SubSelect 9194 { 9195 var sel ast.StmtNode 9196 switch x := $2.(*ast.SubqueryExpr).Query.(type) { 9197 case *ast.SelectStmt: 9198 x.IsInBraces = true 9199 x.WithBeforeBraces = true 9200 x.With = $1.(*ast.WithClause) 9201 sel = x 9202 case *ast.SetOprStmt: 9203 x.IsInBraces = true 9204 x.With = $1.(*ast.WithClause) 9205 sel = x 9206 } 9207 $$ = sel 9208 } 9209 9210 WithClause: 9211 "WITH" WithList 9212 { 9213 $$ = $2 9214 } 9215 | "WITH" recursive WithList 9216 { 9217 ws := $3.(*ast.WithClause) 9218 ws.IsRecursive = true 9219 for _, cte := range ws.CTEs { 9220 cte.IsRecursive = true 9221 } 9222 $$ = ws 9223 } 9224 9225 WithList: 9226 WithList ',' CommonTableExpr 9227 { 9228 ws := $1.(*ast.WithClause) 9229 ws.CTEs = append(ws.CTEs, $3.(*ast.CommonTableExpression)) 9230 $$ = ws 9231 } 9232 | CommonTableExpr 9233 { 9234 ws := &ast.WithClause{} 9235 ws.CTEs = make([]*ast.CommonTableExpression, 0, 4) 9236 ws.CTEs = append(ws.CTEs, $1.(*ast.CommonTableExpression)) 9237 $$ = ws 9238 } 9239 9240 CommonTableExpr: 9241 Identifier IdentListWithParenOpt "AS" SubSelect 9242 { 9243 cte := &ast.CommonTableExpression{} 9244 cte.Name = model.NewCIStr($1) 9245 cte.ColNameList = $2.([]model.CIStr) 9246 cte.Query = $4.(*ast.SubqueryExpr) 9247 $$ = cte 9248 } 9249 9250 FromDual: 9251 "FROM" "DUAL" 9252 9253 WindowClauseOptional: 9254 { 9255 $$ = nil 9256 } 9257 | "WINDOW" WindowDefinitionList 9258 { 9259 $$ = $2.([]ast.WindowSpec) 9260 } 9261 9262 WindowDefinitionList: 9263 WindowDefinition 9264 { 9265 $$ = []ast.WindowSpec{$1.(ast.WindowSpec)} 9266 } 9267 | WindowDefinitionList ',' WindowDefinition 9268 { 9269 $$ = append($1.([]ast.WindowSpec), $3.(ast.WindowSpec)) 9270 } 9271 9272 WindowDefinition: 9273 WindowName "AS" WindowSpec 9274 { 9275 var spec = $3.(ast.WindowSpec) 9276 spec.Name = $1.(model.CIStr) 9277 $$ = spec 9278 } 9279 9280 WindowName: 9281 Identifier 9282 { 9283 $$ = model.NewCIStr($1) 9284 } 9285 9286 WindowSpec: 9287 '(' WindowSpecDetails ')' 9288 { 9289 $$ = $2.(ast.WindowSpec) 9290 } 9291 9292 WindowSpecDetails: 9293 OptExistingWindowName OptPartitionClause OptWindowOrderByClause OptWindowFrameClause 9294 { 9295 spec := ast.WindowSpec{Ref: $1.(model.CIStr)} 9296 if $2 != nil { 9297 spec.PartitionBy = $2.(*ast.PartitionByClause) 9298 } 9299 if $3 != nil { 9300 spec.OrderBy = $3.(*ast.OrderByClause) 9301 } 9302 if $4 != nil { 9303 spec.Frame = $4.(*ast.FrameClause) 9304 } 9305 $$ = spec 9306 } 9307 9308 OptExistingWindowName: 9309 { 9310 $$ = model.CIStr{} 9311 } 9312 | WindowName 9313 9314 OptPartitionClause: 9315 { 9316 $$ = nil 9317 } 9318 | "PARTITION" "BY" ByList 9319 { 9320 $$ = &ast.PartitionByClause{Items: $3.([]*ast.ByItem)} 9321 } 9322 9323 OptWindowOrderByClause: 9324 { 9325 $$ = nil 9326 } 9327 | "ORDER" "BY" ByList 9328 { 9329 $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)} 9330 } 9331 9332 OptWindowFrameClause: 9333 { 9334 $$ = nil 9335 } 9336 | WindowFrameUnits WindowFrameExtent 9337 { 9338 $$ = &ast.FrameClause{ 9339 Type: $1.(ast.FrameType), 9340 Extent: $2.(ast.FrameExtent), 9341 } 9342 } 9343 9344 WindowFrameUnits: 9345 "ROWS" 9346 { 9347 $$ = ast.FrameType(ast.Rows) 9348 } 9349 | "RANGE" 9350 { 9351 $$ = ast.FrameType(ast.Ranges) 9352 } 9353 | "GROUPS" 9354 { 9355 $$ = ast.FrameType(ast.Groups) 9356 } 9357 9358 WindowFrameExtent: 9359 WindowFrameStart 9360 { 9361 $$ = ast.FrameExtent{ 9362 Start: $1.(ast.FrameBound), 9363 End: ast.FrameBound{Type: ast.CurrentRow}, 9364 } 9365 } 9366 | WindowFrameBetween 9367 9368 WindowFrameStart: 9369 "UNBOUNDED" "PRECEDING" 9370 { 9371 $$ = ast.FrameBound{Type: ast.Preceding, UnBounded: true} 9372 } 9373 | NumLiteral "PRECEDING" 9374 { 9375 $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)} 9376 } 9377 | paramMarker "PRECEDING" 9378 { 9379 $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)} 9380 } 9381 | "INTERVAL" Expression TimeUnit "PRECEDING" 9382 { 9383 $$ = ast.FrameBound{Type: ast.Preceding, Expr: $2, Unit: $3.(ast.TimeUnitType)} 9384 } 9385 | "CURRENT" "ROW" 9386 { 9387 $$ = ast.FrameBound{Type: ast.CurrentRow} 9388 } 9389 9390 WindowFrameBetween: 9391 "BETWEEN" WindowFrameBound "AND" WindowFrameBound 9392 { 9393 $$ = ast.FrameExtent{Start: $2.(ast.FrameBound), End: $4.(ast.FrameBound)} 9394 } 9395 9396 WindowFrameBound: 9397 WindowFrameStart 9398 | "UNBOUNDED" "FOLLOWING" 9399 { 9400 $$ = ast.FrameBound{Type: ast.Following, UnBounded: true} 9401 } 9402 | NumLiteral "FOLLOWING" 9403 { 9404 $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)} 9405 } 9406 | paramMarker "FOLLOWING" 9407 { 9408 $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)} 9409 } 9410 | "INTERVAL" Expression TimeUnit "FOLLOWING" 9411 { 9412 $$ = ast.FrameBound{Type: ast.Following, Expr: $2, Unit: $3.(ast.TimeUnitType)} 9413 } 9414 9415 OptWindowingClause: 9416 { 9417 $$ = nil 9418 } 9419 | WindowingClause 9420 { 9421 spec := $1.(ast.WindowSpec) 9422 $$ = &spec 9423 } 9424 9425 WindowingClause: 9426 "OVER" WindowNameOrSpec 9427 { 9428 $$ = $2.(ast.WindowSpec) 9429 } 9430 9431 WindowNameOrSpec: 9432 WindowName 9433 { 9434 $$ = ast.WindowSpec{Name: $1.(model.CIStr), OnlyAlias: true} 9435 } 9436 | WindowSpec 9437 9438 WindowFuncCall: 9439 "ROW_NUMBER" '(' ')' WindowingClause 9440 { 9441 $$ = &ast.WindowFuncExpr{Name: $1, Spec: $4.(ast.WindowSpec)} 9442 } 9443 | "RANK" '(' ')' WindowingClause 9444 { 9445 $$ = &ast.WindowFuncExpr{Name: $1, Spec: $4.(ast.WindowSpec)} 9446 } 9447 | "DENSE_RANK" '(' ')' WindowingClause 9448 { 9449 $$ = &ast.WindowFuncExpr{Name: $1, Spec: $4.(ast.WindowSpec)} 9450 } 9451 | "CUME_DIST" '(' ')' WindowingClause 9452 { 9453 $$ = &ast.WindowFuncExpr{Name: $1, Spec: $4.(ast.WindowSpec)} 9454 } 9455 | "PERCENT_RANK" '(' ')' WindowingClause 9456 { 9457 $$ = &ast.WindowFuncExpr{Name: $1, Spec: $4.(ast.WindowSpec)} 9458 } 9459 | "NTILE" '(' SimpleExpr ')' WindowingClause 9460 { 9461 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, Spec: $5.(ast.WindowSpec)} 9462 } 9463 | "LEAD" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause 9464 { 9465 args := []ast.ExprNode{$3} 9466 if $4 != nil { 9467 args = append(args, $4.([]ast.ExprNode)...) 9468 } 9469 $$ = &ast.WindowFuncExpr{Name: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)} 9470 } 9471 | "LAG" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause 9472 { 9473 args := []ast.ExprNode{$3} 9474 if $4 != nil { 9475 args = append(args, $4.([]ast.ExprNode)...) 9476 } 9477 $$ = &ast.WindowFuncExpr{Name: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)} 9478 } 9479 | "FIRST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause 9480 { 9481 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)} 9482 } 9483 | "LAST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause 9484 { 9485 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)} 9486 } 9487 | "NTH_VALUE" '(' Expression ',' SimpleExpr ')' OptFromFirstLast OptNullTreatment WindowingClause 9488 { 9489 $$ = &ast.WindowFuncExpr{Name: $1, Args: []ast.ExprNode{$3, $5}, FromLast: $7.(bool), IgnoreNull: $8.(bool), Spec: $9.(ast.WindowSpec)} 9490 } 9491 9492 OptLeadLagInfo: 9493 { 9494 $$ = nil 9495 } 9496 | ',' NumLiteral OptLLDefault 9497 { 9498 args := []ast.ExprNode{ast.NewValueExpr($2, parser.charset, parser.collation)} 9499 if $3 != nil { 9500 args = append(args, $3.(ast.ExprNode)) 9501 } 9502 $$ = args 9503 } 9504 | ',' paramMarker OptLLDefault 9505 { 9506 args := []ast.ExprNode{ast.NewParamMarkerExpr(yyS[yypt-1].offset)} 9507 if $3 != nil { 9508 args = append(args, $3.(ast.ExprNode)) 9509 } 9510 $$ = args 9511 } 9512 9513 OptLLDefault: 9514 { 9515 $$ = nil 9516 } 9517 | ',' Expression 9518 { 9519 $$ = $2 9520 } 9521 9522 OptNullTreatment: 9523 { 9524 $$ = false 9525 } 9526 | "RESPECT" "NULLS" 9527 { 9528 $$ = false 9529 } 9530 | "IGNORE" "NULLS" 9531 { 9532 $$ = true 9533 } 9534 9535 OptFromFirstLast: 9536 { 9537 $$ = false 9538 } 9539 | "FROM" "FIRST" 9540 { 9541 $$ = false 9542 } 9543 | "FROM" "LAST" 9544 { 9545 $$ = true 9546 } 9547 9548 TableRefsClause: 9549 TableRefs 9550 { 9551 $$ = &ast.TableRefsClause{TableRefs: $1.(*ast.Join)} 9552 } 9553 9554 TableRefs: 9555 EscapedTableRef 9556 { 9557 if j, ok := $1.(*ast.Join); ok { 9558 // if $1 is Join, use it directly 9559 $$ = j 9560 } else { 9561 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: nil} 9562 } 9563 } 9564 | TableRefs ',' EscapedTableRef 9565 { 9566 /* from a, b is default cross join */ 9567 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin} 9568 } 9569 9570 EscapedTableRef: 9571 TableRef %prec lowerThanSetKeyword 9572 | '{' Identifier TableRef '}' 9573 { 9574 /* 9575 * ODBC escape syntax for outer join is { OJ join_table } 9576 * Use an Identifier for OJ 9577 */ 9578 $$ = $3 9579 } 9580 9581 TableRef: 9582 TableFactor 9583 | JoinTable 9584 9585 TableFactor: 9586 TableName PartitionNameListOpt TableAsNameOpt AsOfClauseOpt IndexHintListOpt TableSampleOpt 9587 { 9588 tn := $1.(*ast.TableName) 9589 tn.PartitionNames = $2.([]model.CIStr) 9590 tn.IndexHints = $5.([]*ast.IndexHint) 9591 if $6 != nil { 9592 tn.TableSample = $6.(*ast.TableSample) 9593 } 9594 if $4 != nil { 9595 tn.AsOf = $4.(*ast.AsOfClause) 9596 } 9597 $$ = &ast.TableSource{Source: tn, AsName: $3.(model.CIStr)} 9598 } 9599 | SubSelect TableAsNameOpt 9600 { 9601 resultNode := $1.(*ast.SubqueryExpr).Query 9602 $$ = &ast.TableSource{Source: resultNode, AsName: $2.(model.CIStr)} 9603 } 9604 | '(' TableRefs ')' 9605 { 9606 j := $2.(*ast.Join) 9607 j.ExplicitParens = true 9608 $$ = $2 9609 } 9610 9611 PartitionNameListOpt: 9612 /* empty */ 9613 { 9614 $$ = []model.CIStr{} 9615 } 9616 | "PARTITION" '(' PartitionNameList ')' 9617 { 9618 $$ = $3 9619 } 9620 9621 TableAsNameOpt: 9622 %prec empty 9623 { 9624 $$ = model.CIStr{} 9625 } 9626 | TableAsName 9627 9628 TableAsName: 9629 Identifier 9630 { 9631 $$ = model.NewCIStr($1) 9632 } 9633 | "AS" Identifier 9634 { 9635 $$ = model.NewCIStr($2) 9636 } 9637 9638 IndexHintType: 9639 "USE" KeyOrIndex 9640 { 9641 $$ = ast.HintUse 9642 } 9643 | "IGNORE" KeyOrIndex 9644 { 9645 $$ = ast.HintIgnore 9646 } 9647 | "FORCE" KeyOrIndex 9648 { 9649 $$ = ast.HintForce 9650 } 9651 9652 IndexHintScope: 9653 { 9654 $$ = ast.HintForScan 9655 } 9656 | "FOR" "JOIN" 9657 { 9658 $$ = ast.HintForJoin 9659 } 9660 | "FOR" "ORDER" "BY" 9661 { 9662 $$ = ast.HintForOrderBy 9663 } 9664 | "FOR" "GROUP" "BY" 9665 { 9666 $$ = ast.HintForGroupBy 9667 } 9668 9669 IndexHint: 9670 IndexHintType IndexHintScope '(' IndexNameList ')' 9671 { 9672 $$ = &ast.IndexHint{ 9673 IndexNames: $4.([]model.CIStr), 9674 HintType: $1.(ast.IndexHintType), 9675 HintScope: $2.(ast.IndexHintScope), 9676 } 9677 } 9678 9679 IndexNameList: 9680 { 9681 var nameList []model.CIStr 9682 $$ = nameList 9683 } 9684 | Identifier 9685 { 9686 $$ = []model.CIStr{model.NewCIStr($1)} 9687 } 9688 | IndexNameList ',' Identifier 9689 { 9690 $$ = append($1.([]model.CIStr), model.NewCIStr($3)) 9691 } 9692 | "PRIMARY" 9693 { 9694 $$ = []model.CIStr{model.NewCIStr($1)} 9695 } 9696 | IndexNameList ',' "PRIMARY" 9697 { 9698 $$ = append($1.([]model.CIStr), model.NewCIStr($3)) 9699 } 9700 9701 IndexHintList: 9702 IndexHint 9703 { 9704 $$ = []*ast.IndexHint{$1.(*ast.IndexHint)} 9705 } 9706 | IndexHintList IndexHint 9707 { 9708 $$ = append($1.([]*ast.IndexHint), $2.(*ast.IndexHint)) 9709 } 9710 9711 IndexHintListOpt: 9712 { 9713 $$ = []*ast.IndexHint{} 9714 } 9715 | IndexHintList 9716 9717 JoinTable: 9718 /* Use %prec to evaluate production TableRef before cross join */ 9719 TableRef CrossOpt TableRef %prec tableRefPriority 9720 { 9721 $$ = ast.NewCrossJoin($1.(ast.ResultSetNode), $3.(ast.ResultSetNode)) 9722 } 9723 | TableRef CrossOpt TableRef "ON" Expression 9724 { 9725 on := &ast.OnCondition{Expr: $5} 9726 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, On: on} 9727 } 9728 | TableRef CrossOpt TableRef "USING" '(' ColumnNameList ')' 9729 { 9730 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, Using: $6.([]*ast.ColumnName)} 9731 } 9732 | TableRef JoinType OuterOpt "JOIN" TableRef "ON" Expression 9733 { 9734 on := &ast.OnCondition{Expr: $7} 9735 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), On: on} 9736 } 9737 | TableRef JoinType OuterOpt "JOIN" TableRef "USING" '(' ColumnNameList ')' 9738 { 9739 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), Using: $8.([]*ast.ColumnName)} 9740 } 9741 | TableRef "NATURAL" "JOIN" TableRef 9742 { 9743 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $4.(ast.ResultSetNode), NaturalJoin: true} 9744 } 9745 | TableRef "NATURAL" JoinType OuterOpt "JOIN" TableRef 9746 { 9747 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $6.(ast.ResultSetNode), Tp: $3.(ast.JoinType), NaturalJoin: true} 9748 } 9749 | TableRef "STRAIGHT_JOIN" TableRef 9750 { 9751 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true} 9752 } 9753 | TableRef "STRAIGHT_JOIN" TableRef "ON" Expression 9754 { 9755 on := &ast.OnCondition{Expr: $5} 9756 $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true, On: on} 9757 } 9758 9759 JoinType: 9760 "LEFT" 9761 { 9762 $$ = ast.LeftJoin 9763 } 9764 | "RIGHT" 9765 { 9766 $$ = ast.RightJoin 9767 } 9768 9769 OuterOpt: 9770 {} 9771 | "OUTER" 9772 9773 CrossOpt: 9774 "JOIN" 9775 | "CROSS" "JOIN" 9776 | "INNER" "JOIN" 9777 9778 LimitClause: 9779 { 9780 $$ = nil 9781 } 9782 | "LIMIT" LimitOption 9783 { 9784 $$ = &ast.Limit{Count: $2.(ast.ValueExpr)} 9785 } 9786 9787 LimitOption: 9788 LengthNum 9789 { 9790 $$ = ast.NewValueExpr($1, parser.charset, parser.collation) 9791 } 9792 | paramMarker 9793 { 9794 $$ = ast.NewParamMarkerExpr(yyS[yypt].offset) 9795 } 9796 9797 RowOrRows: 9798 "ROW" 9799 | "ROWS" 9800 9801 FirstOrNext: 9802 "FIRST" 9803 | "NEXT" 9804 9805 FetchFirstOpt: 9806 { 9807 $$ = ast.NewValueExpr(uint64(1), parser.charset, parser.collation) 9808 } 9809 | LimitOption 9810 9811 SelectStmtLimit: 9812 "LIMIT" LimitOption 9813 { 9814 $$ = &ast.Limit{Count: $2.(ast.ExprNode)} 9815 } 9816 | "LIMIT" LimitOption ',' LimitOption 9817 { 9818 $$ = &ast.Limit{Offset: $2.(ast.ExprNode), Count: $4.(ast.ExprNode)} 9819 } 9820 | "LIMIT" LimitOption "OFFSET" LimitOption 9821 { 9822 $$ = &ast.Limit{Offset: $4.(ast.ExprNode), Count: $2.(ast.ExprNode)} 9823 } 9824 | "FETCH" FirstOrNext FetchFirstOpt RowOrRows "ONLY" 9825 { 9826 $$ = &ast.Limit{Count: $3.(ast.ExprNode)} 9827 } 9828 9829 SelectStmtLimitOpt: 9830 { 9831 $$ = nil 9832 } 9833 | SelectStmtLimit 9834 9835 SelectStmtOpt: 9836 TableOptimizerHints 9837 { 9838 opt := &ast.SelectStmtOpts{} 9839 opt.SQLCache = true 9840 opt.TableHints = $1.([]*ast.TableOptimizerHint) 9841 $$ = opt 9842 } 9843 | DistinctOpt 9844 { 9845 opt := &ast.SelectStmtOpts{} 9846 opt.SQLCache = true 9847 if $1.(bool) { 9848 opt.Distinct = true 9849 } else { 9850 opt.Distinct = false 9851 opt.ExplicitAll = true 9852 } 9853 $$ = opt 9854 } 9855 | Priority 9856 { 9857 opt := &ast.SelectStmtOpts{} 9858 opt.SQLCache = true 9859 opt.Priority = $1.(mysql.PriorityEnum) 9860 $$ = opt 9861 } 9862 | "SQL_SMALL_RESULT" 9863 { 9864 opt := &ast.SelectStmtOpts{} 9865 opt.SQLCache = true 9866 opt.SQLSmallResult = true 9867 $$ = opt 9868 } 9869 | "SQL_BIG_RESULT" 9870 { 9871 opt := &ast.SelectStmtOpts{} 9872 opt.SQLCache = true 9873 opt.SQLBigResult = true 9874 $$ = opt 9875 } 9876 | "SQL_BUFFER_RESULT" 9877 { 9878 opt := &ast.SelectStmtOpts{} 9879 opt.SQLCache = true 9880 opt.SQLBufferResult = true 9881 $$ = opt 9882 } 9883 | SelectStmtSQLCache 9884 { 9885 opt := &ast.SelectStmtOpts{} 9886 opt.SQLCache = $1.(bool) 9887 $$ = opt 9888 } 9889 | "SQL_CALC_FOUND_ROWS" 9890 { 9891 opt := &ast.SelectStmtOpts{} 9892 opt.SQLCache = true 9893 opt.CalcFoundRows = true 9894 $$ = opt 9895 } 9896 | "STRAIGHT_JOIN" 9897 { 9898 opt := &ast.SelectStmtOpts{} 9899 opt.SQLCache = true 9900 opt.StraightJoin = true 9901 $$ = opt 9902 } 9903 9904 SelectStmtOpts: 9905 %prec empty 9906 { 9907 opt := &ast.SelectStmtOpts{} 9908 opt.SQLCache = true 9909 $$ = opt 9910 } 9911 | SelectStmtOptsList %prec lowerThanSelectOpt 9912 9913 SelectStmtOptsList: 9914 SelectStmtOptsList SelectStmtOpt 9915 { 9916 opts := $1.(*ast.SelectStmtOpts) 9917 opt := $2.(*ast.SelectStmtOpts) 9918 9919 // Merge options. 9920 // Always use the first hint. 9921 if opt.TableHints != nil && opts.TableHints == nil { 9922 opts.TableHints = opt.TableHints 9923 } 9924 if opt.Distinct { 9925 opts.Distinct = true 9926 } 9927 if opt.Priority != mysql.NoPriority { 9928 opts.Priority = opt.Priority 9929 } 9930 if opt.SQLSmallResult { 9931 opts.SQLSmallResult = true 9932 } 9933 if opt.SQLBigResult { 9934 opts.SQLBigResult = true 9935 } 9936 if opt.SQLBufferResult { 9937 opts.SQLBufferResult = true 9938 } 9939 if !opt.SQLCache { 9940 opts.SQLCache = false 9941 } 9942 if opt.CalcFoundRows { 9943 opts.CalcFoundRows = true 9944 } 9945 if opt.StraightJoin { 9946 opts.StraightJoin = true 9947 } 9948 if opt.ExplicitAll { 9949 opts.ExplicitAll = true 9950 } 9951 9952 if opts.Distinct && opts.ExplicitAll { 9953 yylex.AppendError(ErrWrongUsage.GenWithStackByArgs("ALL", "DISTINCT")) 9954 return 1 9955 } 9956 9957 $$ = opts 9958 } 9959 | SelectStmtOpt 9960 9961 TableOptimizerHints: 9962 hintComment 9963 { 9964 hints, warns := parser.parseHint($1) 9965 for _, w := range warns { 9966 yylex.AppendError(w) 9967 parser.lastErrorAsWarn() 9968 } 9969 $$ = hints 9970 } 9971 9972 TableOptimizerHintsOpt: 9973 /* empty */ 9974 { 9975 $$ = nil 9976 } 9977 | TableOptimizerHints 9978 9979 SelectStmtSQLCache: 9980 "SQL_CACHE" 9981 { 9982 $$ = true 9983 } 9984 | "SQL_NO_CACHE" 9985 { 9986 $$ = false 9987 } 9988 9989 SelectStmtFieldList: 9990 FieldList 9991 { 9992 $$ = &ast.FieldList{Fields: $1.([]*ast.SelectField)} 9993 } 9994 9995 SelectStmtGroup: 9996 /* EMPTY */ 9997 { 9998 $$ = nil 9999 } 10000 | GroupByClause 10001 10002 SelectStmtIntoOption: 10003 { 10004 $$ = nil 10005 } 10006 | "INTO" "OUTFILE" stringLit Fields Lines 10007 { 10008 x := &ast.SelectIntoOption{ 10009 Tp: ast.SelectIntoOutfile, 10010 FileName: $3, 10011 } 10012 if $4 != nil { 10013 x.FieldsInfo = $4.(*ast.FieldsClause) 10014 } 10015 if $5 != nil { 10016 x.LinesInfo = $5.(*ast.LinesClause) 10017 } 10018 10019 $$ = x 10020 } 10021 10022 // See https://dev.mysql.com/doc/refman/5.7/en/subqueries.html 10023 SubSelect: 10024 '(' SelectStmt ')' 10025 { 10026 rs := $2.(*ast.SelectStmt) 10027 endOffset := parser.endOffset(&yyS[yypt]) 10028 parser.setLastSelectFieldText(rs, endOffset) 10029 src := parser.src 10030 // See the implementation of yyParse function 10031 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10032 $$ = &ast.SubqueryExpr{Query: rs} 10033 } 10034 | '(' SetOprStmt ')' 10035 { 10036 rs := $2.(*ast.SetOprStmt) 10037 src := parser.src 10038 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10039 $$ = &ast.SubqueryExpr{Query: rs} 10040 } 10041 | '(' SelectStmtWithClause ')' 10042 { 10043 switch rs := $2.(type) { 10044 case *ast.SelectStmt: 10045 endOffset := parser.endOffset(&yyS[yypt]) 10046 parser.setLastSelectFieldText(rs, endOffset) 10047 src := parser.src 10048 // See the implementation of yyParse function 10049 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10050 $$ = &ast.SubqueryExpr{Query: rs} 10051 case *ast.SetOprStmt: 10052 src := parser.src 10053 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10054 $$ = &ast.SubqueryExpr{Query: rs} 10055 } 10056 } 10057 | '(' SubSelect ')' 10058 { 10059 subQuery := $2.(*ast.SubqueryExpr).Query 10060 isRecursive := true 10061 // remove redundant brackets like '((select 1))' 10062 for isRecursive { 10063 if _, isRecursive = subQuery.(*ast.SubqueryExpr); isRecursive { 10064 subQuery = subQuery.(*ast.SubqueryExpr).Query 10065 } 10066 } 10067 switch rs := subQuery.(type) { 10068 case *ast.SelectStmt: 10069 endOffset := parser.endOffset(&yyS[yypt]) 10070 parser.setLastSelectFieldText(rs, endOffset) 10071 src := parser.src 10072 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10073 $$ = &ast.SubqueryExpr{Query: rs} 10074 case *ast.SetOprStmt: 10075 src := parser.src 10076 rs.SetText(parser.lexer.client, src[yyS[yypt-1].offset:yyS[yypt].offset]) 10077 $$ = &ast.SubqueryExpr{Query: rs} 10078 } 10079 } 10080 10081 // See https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html 10082 SelectLockOpt: 10083 /* empty */ 10084 { 10085 $$ = nil 10086 } 10087 | "FOR" "UPDATE" OfTablesOpt 10088 { 10089 $$ = &ast.SelectLockInfo{ 10090 LockType: ast.SelectLockForUpdate, 10091 Tables: $3.([]*ast.TableName), 10092 } 10093 } 10094 | "FOR" "SHARE" OfTablesOpt 10095 { 10096 $$ = &ast.SelectLockInfo{ 10097 LockType: ast.SelectLockForShare, 10098 Tables: $3.([]*ast.TableName), 10099 } 10100 } 10101 | "FOR" "UPDATE" OfTablesOpt "NOWAIT" 10102 { 10103 $$ = &ast.SelectLockInfo{ 10104 LockType: ast.SelectLockForUpdateNoWait, 10105 Tables: $3.([]*ast.TableName), 10106 } 10107 } 10108 | "FOR" "UPDATE" OfTablesOpt "WAIT" NUM 10109 { 10110 $$ = &ast.SelectLockInfo{ 10111 LockType: ast.SelectLockForUpdateWaitN, 10112 WaitSec: getUint64FromNUM($5), 10113 Tables: $3.([]*ast.TableName), 10114 } 10115 } 10116 | "FOR" "SHARE" OfTablesOpt "NOWAIT" 10117 { 10118 $$ = &ast.SelectLockInfo{ 10119 LockType: ast.SelectLockForShareNoWait, 10120 Tables: $3.([]*ast.TableName), 10121 } 10122 } 10123 | "FOR" "UPDATE" OfTablesOpt "SKIP" "LOCKED" 10124 { 10125 $$ = &ast.SelectLockInfo{ 10126 LockType: ast.SelectLockForUpdateSkipLocked, 10127 Tables: $3.([]*ast.TableName), 10128 } 10129 } 10130 | "FOR" "SHARE" OfTablesOpt "SKIP" "LOCKED" 10131 { 10132 $$ = &ast.SelectLockInfo{ 10133 LockType: ast.SelectLockForShareSkipLocked, 10134 Tables: $3.([]*ast.TableName), 10135 } 10136 } 10137 | "LOCK" "IN" "SHARE" "MODE" 10138 { 10139 $$ = &ast.SelectLockInfo{ 10140 LockType: ast.SelectLockForShare, 10141 Tables: []*ast.TableName{}, 10142 } 10143 } 10144 10145 OfTablesOpt: 10146 /* empty */ 10147 { 10148 $$ = []*ast.TableName{} 10149 } 10150 | "OF" TableNameList 10151 { 10152 $$ = $2.([]*ast.TableName) 10153 } 10154 10155 SetOprStmt: 10156 SetOprStmtWoutLimitOrderBy 10157 | SetOprStmtWithLimitOrderBy 10158 | WithClause SetOprStmtWithLimitOrderBy 10159 { 10160 setOpr := $2.(*ast.SetOprStmt) 10161 setOpr.With = $1.(*ast.WithClause) 10162 $$ = setOpr 10163 } 10164 | WithClause SetOprStmtWoutLimitOrderBy 10165 { 10166 setOpr := $2.(*ast.SetOprStmt) 10167 setOpr.With = $1.(*ast.WithClause) 10168 $$ = setOpr 10169 } 10170 10171 // See https://dev.mysql.com/doc/refman/5.7/en/union.html 10172 // See https://mariadb.com/kb/en/intersect/ 10173 // See https://mariadb.com/kb/en/except/ 10174 SetOprStmtWoutLimitOrderBy: 10175 SetOprClauseList SetOpr SelectStmt 10176 { 10177 setOprList1 := $1.([]ast.Node) 10178 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10179 endOffset := parser.endOffset(&yyS[yypt-1]) 10180 parser.setLastSelectFieldText(sel, endOffset) 10181 } 10182 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: $1.([]ast.Node)}} 10183 st := $3.(*ast.SelectStmt) 10184 setOpr.Limit = st.Limit 10185 setOpr.OrderBy = st.OrderBy 10186 st.Limit = nil 10187 st.OrderBy = nil 10188 st.AfterSetOperator = $2.(*ast.SetOprType) 10189 setOpr.SelectList.Selects = append(setOpr.SelectList.Selects, st) 10190 $$ = setOpr 10191 } 10192 | SetOprClauseList SetOpr SubSelect 10193 { 10194 setOprList1 := $1.([]ast.Node) 10195 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10196 endOffset := parser.endOffset(&yyS[yypt-1]) 10197 parser.setLastSelectFieldText(sel, endOffset) 10198 } 10199 var setOprList2 []ast.Node 10200 var with2 *ast.WithClause 10201 switch x := $3.(*ast.SubqueryExpr).Query.(type) { 10202 case *ast.SelectStmt: 10203 setOprList2 = []ast.Node{x} 10204 with2 = x.With 10205 case *ast.SetOprStmt: 10206 setOprList2 = x.SelectList.Selects 10207 with2 = x.With 10208 } 10209 nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2, With: with2} 10210 nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType) 10211 setOprList := append(setOprList1, nextSetOprList) 10212 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}} 10213 $$ = setOpr 10214 } 10215 10216 SetOprStmtWithLimitOrderBy: 10217 SetOprClauseList SetOpr SubSelect OrderBy 10218 { 10219 setOprList1 := $1.([]ast.Node) 10220 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10221 endOffset := parser.endOffset(&yyS[yypt-2]) 10222 parser.setLastSelectFieldText(sel, endOffset) 10223 } 10224 var setOprList2 []ast.Node 10225 var with2 *ast.WithClause 10226 switch x := $3.(*ast.SubqueryExpr).Query.(type) { 10227 case *ast.SelectStmt: 10228 setOprList2 = []ast.Node{x} 10229 with2 = x.With 10230 case *ast.SetOprStmt: 10231 setOprList2 = x.SelectList.Selects 10232 with2 = x.With 10233 } 10234 nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2, With: with2} 10235 nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType) 10236 setOprList := append(setOprList1, nextSetOprList) 10237 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}} 10238 setOpr.OrderBy = $4.(*ast.OrderByClause) 10239 $$ = setOpr 10240 } 10241 | SetOprClauseList SetOpr SubSelect SelectStmtLimit 10242 { 10243 setOprList1 := $1.([]ast.Node) 10244 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10245 endOffset := parser.endOffset(&yyS[yypt-2]) 10246 parser.setLastSelectFieldText(sel, endOffset) 10247 } 10248 var setOprList2 []ast.Node 10249 var with2 *ast.WithClause 10250 switch x := $3.(*ast.SubqueryExpr).Query.(type) { 10251 case *ast.SelectStmt: 10252 setOprList2 = []ast.Node{x} 10253 with2 = x.With 10254 case *ast.SetOprStmt: 10255 setOprList2 = x.SelectList.Selects 10256 with2 = x.With 10257 } 10258 nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2, With: with2} 10259 nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType) 10260 setOprList := append(setOprList1, nextSetOprList) 10261 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}} 10262 setOpr.Limit = $4.(*ast.Limit) 10263 $$ = setOpr 10264 } 10265 | SetOprClauseList SetOpr SubSelect OrderBy SelectStmtLimit 10266 { 10267 setOprList1 := $1.([]ast.Node) 10268 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10269 endOffset := parser.endOffset(&yyS[yypt-3]) 10270 parser.setLastSelectFieldText(sel, endOffset) 10271 } 10272 var setOprList2 []ast.Node 10273 var with2 *ast.WithClause 10274 switch x := $3.(*ast.SubqueryExpr).Query.(type) { 10275 case *ast.SelectStmt: 10276 setOprList2 = []ast.Node{x} 10277 with2 = x.With 10278 case *ast.SetOprStmt: 10279 setOprList2 = x.SelectList.Selects 10280 with2 = x.With 10281 } 10282 nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2, With: with2} 10283 nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType) 10284 setOprList := append(setOprList1, nextSetOprList) 10285 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}} 10286 setOpr.OrderBy = $4.(*ast.OrderByClause) 10287 setOpr.Limit = $5.(*ast.Limit) 10288 $$ = setOpr 10289 } 10290 | SubSelect OrderBy 10291 { 10292 var setOprList []ast.Node 10293 var with *ast.WithClause 10294 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 10295 case *ast.SelectStmt: 10296 setOprList = []ast.Node{x} 10297 with = x.With 10298 case *ast.SetOprStmt: 10299 setOprList = x.SelectList.Selects 10300 with = x.With 10301 } 10302 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}, With: with} 10303 setOpr.OrderBy = $2.(*ast.OrderByClause) 10304 $$ = setOpr 10305 } 10306 | SubSelect SelectStmtLimit 10307 { 10308 var setOprList []ast.Node 10309 var with *ast.WithClause 10310 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 10311 case *ast.SelectStmt: 10312 setOprList = []ast.Node{x} 10313 with = x.With 10314 case *ast.SetOprStmt: 10315 setOprList = x.SelectList.Selects 10316 with = x.With 10317 } 10318 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}, With: with} 10319 setOpr.Limit = $2.(*ast.Limit) 10320 $$ = setOpr 10321 } 10322 | SubSelect OrderBy SelectStmtLimit 10323 { 10324 var setOprList []ast.Node 10325 var with *ast.WithClause 10326 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 10327 case *ast.SelectStmt: 10328 setOprList = []ast.Node{x} 10329 with = x.With 10330 case *ast.SetOprStmt: 10331 setOprList = x.SelectList.Selects 10332 with = x.With 10333 } 10334 setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}, With: with} 10335 setOpr.OrderBy = $2.(*ast.OrderByClause) 10336 setOpr.Limit = $3.(*ast.Limit) 10337 $$ = setOpr 10338 } 10339 10340 SetOprClauseList: 10341 SetOprClause 10342 | SetOprClauseList SetOpr SetOprClause 10343 { 10344 setOprList1 := $1.([]ast.Node) 10345 setOprList2 := $3.([]ast.Node) 10346 if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces { 10347 endOffset := parser.endOffset(&yyS[yypt-1]) 10348 parser.setLastSelectFieldText(sel, endOffset) 10349 } 10350 switch x := setOprList2[0].(type) { 10351 case *ast.SelectStmt: 10352 x.AfterSetOperator = $2.(*ast.SetOprType) 10353 case *ast.SetOprSelectList: 10354 x.AfterSetOperator = $2.(*ast.SetOprType) 10355 } 10356 $$ = append(setOprList1, setOprList2...) 10357 } 10358 10359 SetOprClause: 10360 SelectStmt 10361 { 10362 $$ = []ast.Node{$1.(*ast.SelectStmt)} 10363 } 10364 | SubSelect 10365 { 10366 var setOprList []ast.Node 10367 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 10368 case *ast.SelectStmt: 10369 setOprList = []ast.Node{&ast.SetOprSelectList{Selects: []ast.Node{x}}} 10370 case *ast.SetOprStmt: 10371 setOprList = []ast.Node{&ast.SetOprSelectList{Selects: x.SelectList.Selects, With: x.With}} 10372 } 10373 $$ = setOprList 10374 } 10375 10376 SetOpr: 10377 "UNION" SetOprOpt 10378 { 10379 var tp ast.SetOprType 10380 tp = ast.Union 10381 if $2 == false { 10382 tp = ast.UnionAll 10383 } 10384 $$ = &tp 10385 } 10386 | "EXCEPT" SetOprOpt 10387 { 10388 var tp ast.SetOprType 10389 tp = ast.Except 10390 if $2 == false { 10391 tp = ast.ExceptAll 10392 } 10393 $$ = &tp 10394 } 10395 | "INTERSECT" SetOprOpt 10396 { 10397 var tp ast.SetOprType 10398 tp = ast.Intersect 10399 if $2 == false { 10400 tp = ast.IntersectAll 10401 } 10402 $$ = &tp 10403 } 10404 10405 SetOprOpt: 10406 DefaultTrueDistinctOpt 10407 10408 /********************Change Statement*******************************/ 10409 ChangeStmt: 10410 "CHANGE" "PUMP" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit 10411 { 10412 $$ = &ast.ChangeStmt{ 10413 NodeType: ast.PumpType, 10414 State: $6, 10415 NodeID: $9, 10416 } 10417 } 10418 | "CHANGE" "DRAINER" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit 10419 { 10420 $$ = &ast.ChangeStmt{ 10421 NodeType: ast.DrainerType, 10422 State: $6, 10423 NodeID: $9, 10424 } 10425 } 10426 10427 /********************Set Statement*******************************/ 10428 SetStmt: 10429 "SET" VariableAssignmentList 10430 { 10431 $$ = &ast.SetStmt{Variables: $2.([]*ast.VariableAssignment)} 10432 } 10433 | "SET" "PASSWORD" EqOrAssignmentEq PasswordOpt 10434 { 10435 $$ = &ast.SetPwdStmt{Password: $4} 10436 } 10437 | "SET" "PASSWORD" "FOR" Username EqOrAssignmentEq PasswordOpt 10438 { 10439 $$ = &ast.SetPwdStmt{User: $4.(*auth.UserIdentity), Password: $6} 10440 } 10441 | "SET" "GLOBAL" "TRANSACTION" TransactionChars 10442 { 10443 vars := $4.([]*ast.VariableAssignment) 10444 for _, v := range vars { 10445 v.IsGlobal = true 10446 } 10447 $$ = &ast.SetStmt{Variables: vars} 10448 } 10449 | "SET" "SESSION" "TRANSACTION" TransactionChars 10450 { 10451 $$ = &ast.SetStmt{Variables: $4.([]*ast.VariableAssignment)} 10452 } 10453 | "SET" "TRANSACTION" TransactionChars 10454 { 10455 assigns := $3.([]*ast.VariableAssignment) 10456 for i := 0; i < len(assigns); i++ { 10457 if assigns[i].Name == "tx_isolation" { 10458 // A special session variable that make setting tx_isolation take effect one time. 10459 assigns[i].Name = "tx_isolation_one_shot" 10460 } 10461 } 10462 $$ = &ast.SetStmt{Variables: assigns} 10463 } 10464 | "SET" "CONFIG" Identifier ConfigItemName EqOrAssignmentEq SetExpr 10465 { 10466 $$ = &ast.SetConfigStmt{Type: strings.ToLower($3), Name: $4, Value: $6} 10467 } 10468 | "SET" "CONFIG" stringLit ConfigItemName EqOrAssignmentEq SetExpr 10469 { 10470 $$ = &ast.SetConfigStmt{Instance: $3, Name: $4, Value: $6} 10471 } 10472 | "SET" "SESSION_STATES" stringLit 10473 { 10474 $$ = &ast.SetSessionStatesStmt{SessionStates: $3} 10475 } 10476 | "SET" "RESOURCE" "GROUP" ResourceGroupName 10477 { 10478 $$ = &ast.SetResourceGroupStmt{Name: model.NewCIStr($4)} 10479 } 10480 10481 SetRoleStmt: 10482 "SET" "ROLE" SetRoleOpt 10483 { 10484 $$ = $3.(*ast.SetRoleStmt) 10485 } 10486 10487 SetDefaultRoleStmt: 10488 "SET" "DEFAULT" "ROLE" SetDefaultRoleOpt "TO" UsernameList 10489 { 10490 tmp := $4.(*ast.SetRoleStmt) 10491 $$ = &ast.SetDefaultRoleStmt{ 10492 SetRoleOpt: tmp.SetRoleOpt, 10493 RoleList: tmp.RoleList, 10494 UserList: $6.([]*auth.UserIdentity), 10495 } 10496 } 10497 10498 SetDefaultRoleOpt: 10499 "NONE" 10500 { 10501 $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleNone, RoleList: nil} 10502 } 10503 | "ALL" 10504 { 10505 $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAll, RoleList: nil} 10506 } 10507 | RolenameList 10508 { 10509 $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleRegular, RoleList: $1.([]*auth.RoleIdentity)} 10510 } 10511 10512 SetRoleOpt: 10513 "ALL" "EXCEPT" RolenameList 10514 { 10515 $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAllExcept, RoleList: $3.([]*auth.RoleIdentity)} 10516 } 10517 | SetDefaultRoleOpt 10518 | "DEFAULT" 10519 { 10520 $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleDefault, RoleList: nil} 10521 } 10522 10523 TransactionChars: 10524 TransactionChar 10525 { 10526 if $1 != nil { 10527 $$ = $1 10528 } else { 10529 $$ = []*ast.VariableAssignment{} 10530 } 10531 } 10532 | TransactionChars ',' TransactionChar 10533 { 10534 if $3 != nil { 10535 varAssigns := $3.([]*ast.VariableAssignment) 10536 $$ = append($1.([]*ast.VariableAssignment), varAssigns...) 10537 } else { 10538 $$ = $1 10539 } 10540 } 10541 10542 TransactionChar: 10543 "ISOLATION" "LEVEL" IsolationLevel 10544 { 10545 varAssigns := []*ast.VariableAssignment{} 10546 expr := ast.NewValueExpr($3, parser.charset, parser.collation) 10547 varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_isolation", Value: expr, IsSystem: true}) 10548 $$ = varAssigns 10549 } 10550 | "READ" "WRITE" 10551 { 10552 varAssigns := []*ast.VariableAssignment{} 10553 expr := ast.NewValueExpr("0", parser.charset, parser.collation) 10554 varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true}) 10555 $$ = varAssigns 10556 } 10557 | "READ" "ONLY" 10558 { 10559 varAssigns := []*ast.VariableAssignment{} 10560 expr := ast.NewValueExpr("1", parser.charset, parser.collation) 10561 varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true}) 10562 $$ = varAssigns 10563 } 10564 | "READ" "ONLY" AsOfClause 10565 { 10566 varAssigns := []*ast.VariableAssignment{} 10567 asof := $3.(*ast.AsOfClause) 10568 if asof != nil { 10569 varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_ts", Value: asof.TsExpr, IsSystem: true}) 10570 } 10571 $$ = varAssigns 10572 } 10573 10574 IsolationLevel: 10575 "REPEATABLE" "READ" 10576 { 10577 $$ = ast.RepeatableRead 10578 } 10579 | "READ" "COMMITTED" 10580 { 10581 $$ = ast.ReadCommitted 10582 } 10583 | "READ" "UNCOMMITTED" 10584 { 10585 $$ = ast.ReadUncommitted 10586 } 10587 | "SERIALIZABLE" 10588 { 10589 $$ = ast.Serializable 10590 } 10591 10592 SetExpr: 10593 "ON" 10594 { 10595 $$ = ast.NewValueExpr("ON", parser.charset, parser.collation) 10596 } 10597 | "BINARY" 10598 { 10599 $$ = ast.NewValueExpr("BINARY", parser.charset, parser.collation) 10600 } 10601 | ExprOrDefault 10602 10603 EqOrAssignmentEq: 10604 eq 10605 | assignmentEq 10606 10607 VariableName: 10608 Identifier 10609 | Identifier '.' Identifier 10610 { 10611 $$ = $1 + "." + $3 10612 } 10613 10614 ConfigItemName: 10615 Identifier 10616 | Identifier '.' ConfigItemName 10617 { 10618 $$ = $1 + "." + $3 10619 } 10620 | Identifier '-' ConfigItemName 10621 { 10622 $$ = $1 + "-" + $3 10623 } 10624 10625 VariableAssignment: 10626 VariableName EqOrAssignmentEq SetExpr 10627 { 10628 $$ = &ast.VariableAssignment{Name: $1, Value: $3, IsSystem: true} 10629 } 10630 | "GLOBAL" VariableName EqOrAssignmentEq SetExpr 10631 { 10632 $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsGlobal: true, IsSystem: true} 10633 } 10634 | "SESSION" VariableName EqOrAssignmentEq SetExpr 10635 { 10636 $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true} 10637 } 10638 | "LOCAL" VariableName EqOrAssignmentEq SetExpr 10639 { 10640 $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true} 10641 } 10642 | doubleAtIdentifier EqOrAssignmentEq SetExpr 10643 { 10644 v := strings.ToLower($1) 10645 var isGlobal bool 10646 if strings.HasPrefix(v, "@@global.") { 10647 isGlobal = true 10648 v = strings.TrimPrefix(v, "@@global.") 10649 } else if strings.HasPrefix(v, "@@session.") { 10650 v = strings.TrimPrefix(v, "@@session.") 10651 } else if strings.HasPrefix(v, "@@local.") { 10652 v = strings.TrimPrefix(v, "@@local.") 10653 } else if strings.HasPrefix(v, "@@") { 10654 v = strings.TrimPrefix(v, "@@") 10655 } 10656 $$ = &ast.VariableAssignment{Name: v, Value: $3, IsGlobal: isGlobal, IsSystem: true} 10657 } 10658 | singleAtIdentifier EqOrAssignmentEq Expression 10659 { 10660 v := $1 10661 v = strings.TrimPrefix(v, "@") 10662 $$ = &ast.VariableAssignment{Name: v, Value: $3} 10663 } 10664 | "NAMES" CharsetName 10665 { 10666 $$ = &ast.VariableAssignment{ 10667 Name: ast.SetNames, 10668 Value: ast.NewValueExpr($2, "", ""), 10669 } 10670 } 10671 | "NAMES" CharsetName "COLLATE" "DEFAULT" 10672 { 10673 $$ = &ast.VariableAssignment{ 10674 Name: ast.SetNames, 10675 Value: ast.NewValueExpr($2, "", ""), 10676 } 10677 } 10678 | "NAMES" CharsetName "COLLATE" StringName 10679 { 10680 $$ = &ast.VariableAssignment{ 10681 Name: ast.SetNames, 10682 Value: ast.NewValueExpr($2, "", ""), 10683 ExtendValue: ast.NewValueExpr($4, "", ""), 10684 } 10685 } 10686 | "NAMES" "DEFAULT" 10687 { 10688 v := &ast.DefaultExpr{} 10689 $$ = &ast.VariableAssignment{Name: ast.SetNames, Value: v} 10690 } 10691 | CharsetKw CharsetNameOrDefault 10692 { 10693 $$ = &ast.VariableAssignment{Name: ast.SetCharset, Value: $2} 10694 } 10695 10696 CharsetNameOrDefault: 10697 CharsetName 10698 { 10699 $$ = ast.NewValueExpr($1, "", "") 10700 } 10701 | "DEFAULT" 10702 { 10703 $$ = &ast.DefaultExpr{} 10704 } 10705 10706 CharsetName: 10707 StringName 10708 { 10709 // Validate input charset name to keep the same behavior as parser of MySQL. 10710 cs, err := charset.GetCharsetInfo($1) 10711 if err != nil { 10712 yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs($1)) 10713 return 1 10714 } 10715 // Use charset name returned from charset.GetCharsetInfo(), 10716 // to keep lower case of input for generated column restore. 10717 $$ = cs.Name 10718 } 10719 | binaryType 10720 { 10721 $$ = charset.CharsetBin 10722 } 10723 10724 CollationName: 10725 StringName 10726 { 10727 info, err := charset.GetCollationByName($1) 10728 if err != nil { 10729 yylex.AppendError(err) 10730 return 1 10731 } 10732 $$ = info.Name 10733 } 10734 | binaryType 10735 { 10736 $$ = charset.CollationBin 10737 } 10738 10739 VariableAssignmentList: 10740 VariableAssignment 10741 { 10742 $$ = []*ast.VariableAssignment{$1.(*ast.VariableAssignment)} 10743 } 10744 | VariableAssignmentList ',' VariableAssignment 10745 { 10746 $$ = append($1.([]*ast.VariableAssignment), $3.(*ast.VariableAssignment)) 10747 } 10748 10749 Variable: 10750 SystemVariable 10751 | UserVariable 10752 10753 SystemVariable: 10754 doubleAtIdentifier 10755 { 10756 v := strings.ToLower($1) 10757 var isGlobal bool 10758 explicitScope := true 10759 if strings.HasPrefix(v, "@@global.") { 10760 isGlobal = true 10761 v = strings.TrimPrefix(v, "@@global.") 10762 } else if strings.HasPrefix(v, "@@session.") { 10763 v = strings.TrimPrefix(v, "@@session.") 10764 } else if strings.HasPrefix(v, "@@local.") { 10765 v = strings.TrimPrefix(v, "@@local.") 10766 } else if strings.HasPrefix(v, "@@") { 10767 v, explicitScope = strings.TrimPrefix(v, "@@"), false 10768 } 10769 $$ = &ast.VariableExpr{Name: v, IsGlobal: isGlobal, IsSystem: true, ExplicitScope: explicitScope} 10770 } 10771 10772 UserVariable: 10773 singleAtIdentifier 10774 { 10775 v := $1 10776 v = strings.TrimPrefix(v, "@") 10777 $$ = &ast.VariableExpr{Name: v, IsGlobal: false, IsSystem: false} 10778 } 10779 10780 Username: 10781 StringName 10782 { 10783 $$ = &auth.UserIdentity{Username: $1, Hostname: "%"} 10784 } 10785 | StringName '@' StringName 10786 { 10787 $$ = &auth.UserIdentity{Username: $1, Hostname: strings.ToLower($3)} 10788 } 10789 | StringName singleAtIdentifier 10790 { 10791 $$ = &auth.UserIdentity{Username: $1, Hostname: strings.ToLower(strings.TrimPrefix($2, "@"))} 10792 } 10793 | "CURRENT_USER" OptionalBraces 10794 { 10795 $$ = &auth.UserIdentity{CurrentUser: true} 10796 } 10797 10798 UsernameList: 10799 Username 10800 { 10801 $$ = []*auth.UserIdentity{$1.(*auth.UserIdentity)} 10802 } 10803 | UsernameList ',' Username 10804 { 10805 $$ = append($1.([]*auth.UserIdentity), $3.(*auth.UserIdentity)) 10806 } 10807 10808 PasswordOpt: 10809 stringLit 10810 | "PASSWORD" '(' AuthString ')' 10811 { 10812 $$ = $3 10813 } 10814 10815 AuthString: 10816 stringLit 10817 10818 RoleNameString: 10819 stringLit 10820 | identifier 10821 10822 RolenameComposed: 10823 StringName '@' StringName 10824 { 10825 $$ = &auth.RoleIdentity{Username: $1, Hostname: strings.ToLower($3)} 10826 } 10827 | StringName singleAtIdentifier 10828 { 10829 $$ = &auth.RoleIdentity{Username: $1, Hostname: strings.ToLower(strings.TrimPrefix($2, "@"))} 10830 } 10831 10832 RolenameWithoutIdent: 10833 stringLit 10834 { 10835 $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"} 10836 } 10837 | RolenameComposed 10838 { 10839 $$ = $1 10840 } 10841 10842 Rolename: 10843 RoleNameString 10844 { 10845 $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"} 10846 } 10847 | RolenameComposed 10848 { 10849 $$ = $1 10850 } 10851 10852 RolenameList: 10853 Rolename 10854 { 10855 $$ = []*auth.RoleIdentity{$1.(*auth.RoleIdentity)} 10856 } 10857 | RolenameList ',' Rolename 10858 { 10859 $$ = append($1.([]*auth.RoleIdentity), $3.(*auth.RoleIdentity)) 10860 } 10861 10862 /****************************Admin Statement*******************************/ 10863 AdminStmtLimitOpt: 10864 "LIMIT" LengthNum 10865 { 10866 $$ = &ast.LimitSimple{Offset: 0, Count: $2.(uint64)} 10867 } 10868 | "LIMIT" LengthNum ',' LengthNum 10869 { 10870 $$ = &ast.LimitSimple{Offset: $2.(uint64), Count: $4.(uint64)} 10871 } 10872 | "LIMIT" LengthNum "OFFSET" LengthNum 10873 { 10874 $$ = &ast.LimitSimple{Offset: $4.(uint64), Count: $2.(uint64)} 10875 } 10876 10877 AdminStmt: 10878 "ADMIN" "SHOW" "DDL" 10879 { 10880 $$ = &ast.AdminStmt{Tp: ast.AdminShowDDL} 10881 } 10882 | "ADMIN" "SHOW" "DDL" "JOBS" WhereClauseOptional 10883 { 10884 stmt := &ast.AdminStmt{Tp: ast.AdminShowDDLJobs} 10885 if $5 != nil { 10886 stmt.Where = $5.(ast.ExprNode) 10887 } 10888 $$ = stmt 10889 } 10890 | "ADMIN" "SHOW" "DDL" "JOBS" Int64Num WhereClauseOptional 10891 { 10892 stmt := &ast.AdminStmt{ 10893 Tp: ast.AdminShowDDLJobs, 10894 JobNumber: $5.(int64), 10895 } 10896 if $6 != nil { 10897 stmt.Where = $6.(ast.ExprNode) 10898 } 10899 $$ = stmt 10900 } 10901 | "ADMIN" "SHOW" TableName "NEXT_ROW_ID" 10902 { 10903 $$ = &ast.AdminStmt{ 10904 Tp: ast.AdminShowNextRowID, 10905 Tables: []*ast.TableName{$3.(*ast.TableName)}, 10906 } 10907 } 10908 | "ADMIN" "CHECK" "TABLE" TableNameList 10909 { 10910 $$ = &ast.AdminStmt{ 10911 Tp: ast.AdminCheckTable, 10912 Tables: $4.([]*ast.TableName), 10913 } 10914 } 10915 | "ADMIN" "CHECK" "INDEX" TableName Identifier 10916 { 10917 $$ = &ast.AdminStmt{ 10918 Tp: ast.AdminCheckIndex, 10919 Tables: []*ast.TableName{$4.(*ast.TableName)}, 10920 Index: string($5), 10921 } 10922 } 10923 | "ADMIN" "RECOVER" "INDEX" TableName Identifier 10924 { 10925 $$ = &ast.AdminStmt{ 10926 Tp: ast.AdminRecoverIndex, 10927 Tables: []*ast.TableName{$4.(*ast.TableName)}, 10928 Index: string($5), 10929 } 10930 } 10931 | "ADMIN" "CLEANUP" "INDEX" TableName Identifier 10932 { 10933 $$ = &ast.AdminStmt{ 10934 Tp: ast.AdminCleanupIndex, 10935 Tables: []*ast.TableName{$4.(*ast.TableName)}, 10936 Index: string($5), 10937 } 10938 } 10939 | "ADMIN" "CHECK" "INDEX" TableName Identifier HandleRangeList 10940 { 10941 $$ = &ast.AdminStmt{ 10942 Tp: ast.AdminCheckIndexRange, 10943 Tables: []*ast.TableName{$4.(*ast.TableName)}, 10944 Index: string($5), 10945 HandleRanges: $6.([]ast.HandleRange), 10946 } 10947 } 10948 | "ADMIN" "CHECKSUM" "TABLE" TableNameList 10949 { 10950 $$ = &ast.AdminStmt{ 10951 Tp: ast.AdminChecksumTable, 10952 Tables: $4.([]*ast.TableName), 10953 } 10954 } 10955 | "ADMIN" "CANCEL" "DDL" "JOBS" NumList 10956 { 10957 $$ = &ast.AdminStmt{ 10958 Tp: ast.AdminCancelDDLJobs, 10959 JobIDs: $5.([]int64), 10960 } 10961 } 10962 | "ADMIN" "PAUSE" "DDL" "JOBS" NumList 10963 { 10964 $$ = &ast.AdminStmt{ 10965 Tp: ast.AdminPauseDDLJobs, 10966 JobIDs: $5.([]int64), 10967 } 10968 } 10969 | "ADMIN" "RESUME" "DDL" "JOBS" NumList 10970 { 10971 $$ = &ast.AdminStmt{ 10972 Tp: ast.AdminResumeDDLJobs, 10973 JobIDs: $5.([]int64), 10974 } 10975 } 10976 | "ADMIN" "SHOW" "DDL" "JOB" "QUERIES" NumList 10977 { 10978 $$ = &ast.AdminStmt{ 10979 Tp: ast.AdminShowDDLJobQueries, 10980 JobIDs: $6.([]int64), 10981 } 10982 } 10983 | "ADMIN" "SHOW" "DDL" "JOB" "QUERIES" AdminStmtLimitOpt 10984 { 10985 ret := &ast.AdminStmt{ 10986 Tp: ast.AdminShowDDLJobQueriesWithRange, 10987 } 10988 ret.LimitSimple.Count = $6.(*ast.LimitSimple).Count 10989 ret.LimitSimple.Offset = $6.(*ast.LimitSimple).Offset 10990 $$ = ret 10991 } 10992 | "ADMIN" "SHOW" "SLOW" AdminShowSlow 10993 { 10994 $$ = &ast.AdminStmt{ 10995 Tp: ast.AdminShowSlow, 10996 ShowSlow: $4.(*ast.ShowSlow), 10997 } 10998 } 10999 | "ADMIN" "RELOAD" "EXPR_PUSHDOWN_BLACKLIST" 11000 { 11001 $$ = &ast.AdminStmt{ 11002 Tp: ast.AdminReloadExprPushdownBlacklist, 11003 } 11004 } 11005 | "ADMIN" "RELOAD" "OPT_RULE_BLACKLIST" 11006 { 11007 $$ = &ast.AdminStmt{ 11008 Tp: ast.AdminReloadOptRuleBlacklist, 11009 } 11010 } 11011 | "ADMIN" "PLUGINS" "ENABLE" PluginNameList 11012 { 11013 $$ = &ast.AdminStmt{ 11014 Tp: ast.AdminPluginEnable, 11015 Plugins: $4.([]string), 11016 } 11017 } 11018 | "ADMIN" "PLUGINS" "DISABLE" PluginNameList 11019 { 11020 $$ = &ast.AdminStmt{ 11021 Tp: ast.AdminPluginDisable, 11022 Plugins: $4.([]string), 11023 } 11024 } 11025 | "ADMIN" "CLEANUP" "TABLE" "LOCK" TableNameList 11026 { 11027 $$ = &ast.CleanupTableLockStmt{ 11028 Tables: $5.([]*ast.TableName), 11029 } 11030 } 11031 | "ADMIN" "REPAIR" "TABLE" TableName CreateTableStmt 11032 { 11033 $$ = &ast.RepairTableStmt{ 11034 Table: $4.(*ast.TableName), 11035 CreateStmt: $5.(*ast.CreateTableStmt), 11036 } 11037 } 11038 | "ADMIN" "FLUSH" "BINDINGS" 11039 { 11040 $$ = &ast.AdminStmt{ 11041 Tp: ast.AdminFlushBindings, 11042 } 11043 } 11044 | "ADMIN" "CAPTURE" "BINDINGS" 11045 { 11046 $$ = &ast.AdminStmt{ 11047 Tp: ast.AdminCaptureBindings, 11048 } 11049 } 11050 | "ADMIN" "EVOLVE" "BINDINGS" 11051 { 11052 $$ = &ast.AdminStmt{ 11053 Tp: ast.AdminEvolveBindings, 11054 } 11055 } 11056 | "ADMIN" "RELOAD" "BINDINGS" 11057 { 11058 $$ = &ast.AdminStmt{ 11059 Tp: ast.AdminReloadBindings, 11060 } 11061 } 11062 | "ADMIN" "RELOAD" "STATS_EXTENDED" 11063 { 11064 $$ = &ast.AdminStmt{ 11065 Tp: ast.AdminReloadStatistics, 11066 } 11067 } 11068 | "ADMIN" "RELOAD" "STATISTICS" 11069 { 11070 $$ = &ast.AdminStmt{ 11071 Tp: ast.AdminReloadStatistics, 11072 } 11073 } 11074 | "ADMIN" "SHOW" "TELEMETRY" 11075 { 11076 $$ = &ast.AdminStmt{ 11077 Tp: ast.AdminShowTelemetry, 11078 } 11079 } 11080 | "ADMIN" "RESET" "TELEMETRY_ID" 11081 { 11082 $$ = &ast.AdminStmt{ 11083 Tp: ast.AdminResetTelemetryID, 11084 } 11085 } 11086 | "ADMIN" "FLUSH" StatementScope "PLAN_CACHE" 11087 { 11088 $$ = &ast.AdminStmt{ 11089 Tp: ast.AdminFlushPlanCache, 11090 StatementScope: $3.(ast.StatementScope), 11091 } 11092 } 11093 11094 AdminShowSlow: 11095 "RECENT" NUM 11096 { 11097 $$ = &ast.ShowSlow{ 11098 Tp: ast.ShowSlowRecent, 11099 Count: getUint64FromNUM($2), 11100 } 11101 } 11102 | "TOP" NUM 11103 { 11104 $$ = &ast.ShowSlow{ 11105 Tp: ast.ShowSlowTop, 11106 Kind: ast.ShowSlowKindDefault, 11107 Count: getUint64FromNUM($2), 11108 } 11109 } 11110 | "TOP" "INTERNAL" NUM 11111 { 11112 $$ = &ast.ShowSlow{ 11113 Tp: ast.ShowSlowTop, 11114 Kind: ast.ShowSlowKindInternal, 11115 Count: getUint64FromNUM($3), 11116 } 11117 } 11118 | "TOP" "ALL" NUM 11119 { 11120 $$ = &ast.ShowSlow{ 11121 Tp: ast.ShowSlowTop, 11122 Kind: ast.ShowSlowKindAll, 11123 Count: getUint64FromNUM($3), 11124 } 11125 } 11126 11127 HandleRangeList: 11128 HandleRange 11129 { 11130 $$ = []ast.HandleRange{$1.(ast.HandleRange)} 11131 } 11132 | HandleRangeList ',' HandleRange 11133 { 11134 $$ = append($1.([]ast.HandleRange), $3.(ast.HandleRange)) 11135 } 11136 11137 HandleRange: 11138 '(' Int64Num ',' Int64Num ')' 11139 { 11140 $$ = ast.HandleRange{Begin: $2.(int64), End: $4.(int64)} 11141 } 11142 11143 NumList: 11144 Int64Num 11145 { 11146 $$ = []int64{$1.(int64)} 11147 } 11148 | NumList ',' Int64Num 11149 { 11150 $$ = append($1.([]int64), $3.(int64)) 11151 } 11152 11153 /****************************Show Statement*******************************/ 11154 ShowStmt: 11155 "SHOW" ShowTargetFilterable ShowLikeOrWhereOpt 11156 { 11157 stmt := $2.(*ast.ShowStmt) 11158 if $3 != nil { 11159 if x, ok := $3.(*ast.PatternLikeOrIlikeExpr); ok && x.Expr == nil { 11160 stmt.Pattern = x 11161 } else { 11162 stmt.Where = $3.(ast.ExprNode) 11163 } 11164 } 11165 $$ = stmt 11166 } 11167 | "SHOW" "CREATE" "TABLE" TableName 11168 { 11169 $$ = &ast.ShowStmt{ 11170 Tp: ast.ShowCreateTable, 11171 Table: $4.(*ast.TableName), 11172 } 11173 } 11174 | "SHOW" "CREATE" "VIEW" TableName 11175 { 11176 $$ = &ast.ShowStmt{ 11177 Tp: ast.ShowCreateView, 11178 Table: $4.(*ast.TableName), 11179 } 11180 } 11181 | "SHOW" "CREATE" "DATABASE" IfNotExists DBName 11182 { 11183 $$ = &ast.ShowStmt{ 11184 Tp: ast.ShowCreateDatabase, 11185 IfNotExists: $4.(bool), 11186 DBName: $5, 11187 } 11188 } 11189 | "SHOW" "CREATE" "SEQUENCE" TableName 11190 { 11191 $$ = &ast.ShowStmt{ 11192 Tp: ast.ShowCreateSequence, 11193 Table: $4.(*ast.TableName), 11194 } 11195 } 11196 | "SHOW" "CREATE" "PLACEMENT" "POLICY" PolicyName 11197 { 11198 $$ = &ast.ShowStmt{ 11199 Tp: ast.ShowCreatePlacementPolicy, 11200 DBName: $5, 11201 } 11202 } 11203 | "SHOW" "CREATE" "RESOURCE" "GROUP" ResourceGroupName 11204 { 11205 $$ = &ast.ShowStmt{ 11206 Tp: ast.ShowCreateResourceGroup, 11207 ResourceGroupName: $5, 11208 } 11209 } 11210 | "SHOW" "CREATE" "USER" Username 11211 { 11212 // See https://dev.mysql.com/doc/refman/5.7/en/show-create-user.html 11213 $$ = &ast.ShowStmt{ 11214 Tp: ast.ShowCreateUser, 11215 User: $4.(*auth.UserIdentity), 11216 } 11217 } 11218 | "SHOW" "TABLE" TableName PartitionNameListOpt "REGIONS" WhereClauseOptional 11219 { 11220 stmt := &ast.ShowStmt{ 11221 Tp: ast.ShowRegions, 11222 Table: $3.(*ast.TableName), 11223 } 11224 stmt.Table.PartitionNames = $4.([]model.CIStr) 11225 if $6 != nil { 11226 stmt.Where = $6.(ast.ExprNode) 11227 } 11228 $$ = stmt 11229 } 11230 | "SHOW" "TABLE" TableName "NEXT_ROW_ID" 11231 { 11232 $$ = &ast.ShowStmt{ 11233 Tp: ast.ShowTableNextRowId, 11234 Table: $3.(*ast.TableName), 11235 } 11236 } 11237 | "SHOW" "TABLE" TableName PartitionNameListOpt "INDEX" Identifier "REGIONS" WhereClauseOptional 11238 { 11239 stmt := &ast.ShowStmt{ 11240 Tp: ast.ShowRegions, 11241 Table: $3.(*ast.TableName), 11242 IndexName: model.NewCIStr($6), 11243 } 11244 stmt.Table.PartitionNames = $4.([]model.CIStr) 11245 if $8 != nil { 11246 stmt.Where = $8.(ast.ExprNode) 11247 } 11248 $$ = stmt 11249 } 11250 | "SHOW" "GRANTS" 11251 { 11252 // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html 11253 $$ = &ast.ShowStmt{Tp: ast.ShowGrants} 11254 } 11255 | "SHOW" "GRANTS" "FOR" Username UsingRoles 11256 { 11257 // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html 11258 if $5 != nil { 11259 $$ = &ast.ShowStmt{ 11260 Tp: ast.ShowGrants, 11261 User: $4.(*auth.UserIdentity), 11262 Roles: $5.([]*auth.RoleIdentity), 11263 } 11264 } else { 11265 $$ = &ast.ShowStmt{ 11266 Tp: ast.ShowGrants, 11267 User: $4.(*auth.UserIdentity), 11268 Roles: nil, 11269 } 11270 } 11271 } 11272 | "SHOW" "MASTER" "STATUS" 11273 { 11274 $$ = &ast.ShowStmt{ 11275 Tp: ast.ShowMasterStatus, 11276 } 11277 } 11278 | "SHOW" OptFull "PROCESSLIST" 11279 { 11280 $$ = &ast.ShowStmt{ 11281 Tp: ast.ShowProcessList, 11282 Full: $2.(bool), 11283 } 11284 } 11285 | "SHOW" "PROFILES" 11286 { 11287 $$ = &ast.ShowStmt{ 11288 Tp: ast.ShowProfiles, 11289 } 11290 } 11291 | "SHOW" "PROFILE" ShowProfileTypesOpt ShowProfileArgsOpt SelectStmtLimitOpt 11292 { 11293 v := &ast.ShowStmt{ 11294 Tp: ast.ShowProfile, 11295 } 11296 if $3 != nil { 11297 v.ShowProfileTypes = $3.([]int) 11298 } 11299 if $4 != nil { 11300 v.ShowProfileArgs = $4.(*int64) 11301 } 11302 if $5 != nil { 11303 v.ShowProfileLimit = $5.(*ast.Limit) 11304 } 11305 $$ = v 11306 } 11307 | "SHOW" "PRIVILEGES" 11308 { 11309 $$ = &ast.ShowStmt{ 11310 Tp: ast.ShowPrivileges, 11311 } 11312 } 11313 | "SHOW" "BUILTINS" 11314 { 11315 $$ = &ast.ShowStmt{ 11316 Tp: ast.ShowBuiltins, 11317 } 11318 } 11319 | "SHOW" "PLACEMENT" "FOR" ShowPlacementTarget 11320 { 11321 $$ = $4.(*ast.ShowStmt) 11322 } 11323 | "SHOW" "IMPORT" "JOB" Int64Num 11324 { 11325 v := $4.(int64) 11326 $$ = &ast.ShowStmt{ 11327 Tp: ast.ShowImportJobs, 11328 ImportJobID: &v, 11329 } 11330 } 11331 | "SHOW" "CREATE" "PROCEDURE" TableName 11332 { 11333 $$ = &ast.ShowStmt{ 11334 Tp: ast.ShowCreateProcedure, 11335 Procedure: $4.(*ast.TableName), 11336 } 11337 } 11338 11339 ShowPlacementTarget: 11340 DatabaseSym DBName 11341 { 11342 $$ = &ast.ShowStmt{ 11343 Tp: ast.ShowPlacementForDatabase, 11344 DBName: $2, 11345 } 11346 } 11347 | "TABLE" TableName 11348 { 11349 $$ = &ast.ShowStmt{ 11350 Tp: ast.ShowPlacementForTable, 11351 Table: $2.(*ast.TableName), 11352 } 11353 } 11354 | "TABLE" TableName "PARTITION" Identifier 11355 { 11356 $$ = &ast.ShowStmt{ 11357 Tp: ast.ShowPlacementForPartition, 11358 Table: $2.(*ast.TableName), 11359 Partition: model.NewCIStr($4), 11360 } 11361 } 11362 11363 ShowProfileTypesOpt: 11364 { 11365 $$ = nil 11366 } 11367 | ShowProfileTypes 11368 11369 ShowProfileTypes: 11370 ShowProfileType 11371 { 11372 $$ = []int{$1.(int)} 11373 } 11374 | ShowProfileTypes ',' ShowProfileType 11375 { 11376 l := $1.([]int) 11377 l = append(l, $3.(int)) 11378 $$ = l 11379 } 11380 11381 ShowProfileType: 11382 "CPU" 11383 { 11384 $$ = ast.ProfileTypeCPU 11385 } 11386 | "MEMORY" 11387 { 11388 $$ = ast.ProfileTypeMemory 11389 } 11390 | "BLOCK" "IO" 11391 { 11392 $$ = ast.ProfileTypeBlockIo 11393 } 11394 | "CONTEXT" "SWITCHES" 11395 { 11396 $$ = ast.ProfileTypeContextSwitch 11397 } 11398 | "PAGE" "FAULTS" 11399 { 11400 $$ = ast.ProfileTypePageFaults 11401 } 11402 | "IPC" 11403 { 11404 $$ = ast.ProfileTypeIpc 11405 } 11406 | "SWAPS" 11407 { 11408 $$ = ast.ProfileTypeSwaps 11409 } 11410 | "SOURCE" 11411 { 11412 $$ = ast.ProfileTypeSource 11413 } 11414 | "ALL" 11415 { 11416 $$ = ast.ProfileTypeAll 11417 } 11418 11419 ShowProfileArgsOpt: 11420 { 11421 $$ = nil 11422 } 11423 | "FOR" "QUERY" Int64Num 11424 { 11425 v := $3.(int64) 11426 $$ = &v 11427 } 11428 11429 UsingRoles: 11430 { 11431 $$ = nil 11432 } 11433 | "USING" RolenameList 11434 { 11435 $$ = $2.([]*auth.RoleIdentity) 11436 } 11437 11438 ShowIndexKwd: 11439 "INDEX" 11440 | "INDEXES" 11441 | "KEYS" 11442 11443 FromOrIn: 11444 "FROM" 11445 | "IN" 11446 11447 ShowTargetFilterable: 11448 "ENGINES" 11449 { 11450 $$ = &ast.ShowStmt{Tp: ast.ShowEngines} 11451 } 11452 | "DATABASES" 11453 { 11454 $$ = &ast.ShowStmt{Tp: ast.ShowDatabases} 11455 } 11456 | "CONFIG" 11457 { 11458 $$ = &ast.ShowStmt{Tp: ast.ShowConfig} 11459 } 11460 | CharsetKw 11461 { 11462 $$ = &ast.ShowStmt{Tp: ast.ShowCharset} 11463 } 11464 | OptFull "TABLES" ShowDatabaseNameOpt 11465 { 11466 $$ = &ast.ShowStmt{ 11467 Tp: ast.ShowTables, 11468 DBName: $3, 11469 Full: $1.(bool), 11470 } 11471 } 11472 | "OPEN" "TABLES" ShowDatabaseNameOpt 11473 { 11474 $$ = &ast.ShowStmt{ 11475 Tp: ast.ShowOpenTables, 11476 DBName: $3, 11477 } 11478 } 11479 | "TABLE" "STATUS" ShowDatabaseNameOpt 11480 { 11481 $$ = &ast.ShowStmt{ 11482 Tp: ast.ShowTableStatus, 11483 DBName: $3, 11484 } 11485 } 11486 | ShowIndexKwd FromOrIn TableName 11487 { 11488 $$ = &ast.ShowStmt{ 11489 Tp: ast.ShowIndex, 11490 Table: $3.(*ast.TableName), 11491 } 11492 } 11493 | ShowIndexKwd FromOrIn Identifier FromOrIn Identifier 11494 { 11495 show := &ast.ShowStmt{ 11496 Tp: ast.ShowIndex, 11497 Table: &ast.TableName{Name: model.NewCIStr($3), Schema: model.NewCIStr($5)}, 11498 } 11499 $$ = show 11500 } 11501 | OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt 11502 { 11503 $$ = &ast.ShowStmt{ 11504 Tp: ast.ShowColumns, 11505 Table: $3.(*ast.TableName), 11506 DBName: $4, 11507 Full: $1.(bool), 11508 } 11509 } 11510 | "EXTENDED" OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt 11511 { 11512 $$ = &ast.ShowStmt{ 11513 Tp: ast.ShowColumns, 11514 Table: $4.(*ast.TableName), 11515 DBName: $5, 11516 Full: $2.(bool), 11517 Extended: true, 11518 } 11519 } 11520 | builtinCount '(' '*' ')' "WARNINGS" 11521 { 11522 $$ = &ast.ShowStmt{Tp: ast.ShowWarnings, CountWarningsOrErrors: true} 11523 } 11524 | "WARNINGS" 11525 { 11526 $$ = &ast.ShowStmt{Tp: ast.ShowWarnings} 11527 } 11528 | builtinCount '(' '*' ')' "ERRORS" 11529 { 11530 $$ = &ast.ShowStmt{Tp: ast.ShowErrors, CountWarningsOrErrors: true} 11531 } 11532 | "ERRORS" 11533 { 11534 $$ = &ast.ShowStmt{Tp: ast.ShowErrors} 11535 } 11536 | GlobalScope "VARIABLES" 11537 { 11538 $$ = &ast.ShowStmt{ 11539 Tp: ast.ShowVariables, 11540 GlobalScope: $1.(bool), 11541 } 11542 } 11543 | GlobalScope "STATUS" 11544 { 11545 $$ = &ast.ShowStmt{ 11546 Tp: ast.ShowStatus, 11547 GlobalScope: $1.(bool), 11548 } 11549 } 11550 | GlobalScope "BINDINGS" 11551 { 11552 $$ = &ast.ShowStmt{ 11553 Tp: ast.ShowBindings, 11554 GlobalScope: $1.(bool), 11555 } 11556 } 11557 | "COLLATION" 11558 { 11559 $$ = &ast.ShowStmt{ 11560 Tp: ast.ShowCollation, 11561 } 11562 } 11563 | "TRIGGERS" ShowDatabaseNameOpt 11564 { 11565 $$ = &ast.ShowStmt{ 11566 Tp: ast.ShowTriggers, 11567 DBName: $2, 11568 } 11569 } 11570 | "BINDING_CACHE" "STATUS" 11571 { 11572 $$ = &ast.ShowStmt{ 11573 Tp: ast.ShowBindingCacheStatus, 11574 } 11575 } 11576 | "PROCEDURE" "STATUS" 11577 { 11578 $$ = &ast.ShowStmt{ 11579 Tp: ast.ShowProcedureStatus, 11580 } 11581 } 11582 | "PUMP" "STATUS" 11583 { 11584 $$ = &ast.ShowStmt{ 11585 Tp: ast.ShowPumpStatus, 11586 } 11587 } 11588 | "DRAINER" "STATUS" 11589 { 11590 $$ = &ast.ShowStmt{ 11591 Tp: ast.ShowDrainerStatus, 11592 } 11593 } 11594 | "FUNCTION" "STATUS" 11595 { 11596 // This statement is similar to SHOW PROCEDURE STATUS but for stored functions. 11597 // See http://dev.mysql.com/doc/refman/5.7/en/show-function-status.html 11598 // We do not support neither stored functions nor stored procedures. 11599 // So we reuse show procedure status process logic. 11600 $$ = &ast.ShowStmt{ 11601 Tp: ast.ShowFunctionStatus, 11602 } 11603 } 11604 | "EVENTS" ShowDatabaseNameOpt 11605 { 11606 $$ = &ast.ShowStmt{ 11607 Tp: ast.ShowEvents, 11608 DBName: $2, 11609 } 11610 } 11611 | "PLUGINS" 11612 { 11613 $$ = &ast.ShowStmt{ 11614 Tp: ast.ShowPlugins, 11615 } 11616 } 11617 | "SESSION_STATES" 11618 { 11619 $$ = &ast.ShowStmt{Tp: ast.ShowSessionStates} 11620 } 11621 | "STATS_EXTENDED" 11622 { 11623 $$ = &ast.ShowStmt{Tp: ast.ShowStatsExtended} 11624 } 11625 | "STATS_META" 11626 { 11627 $$ = &ast.ShowStmt{Tp: ast.ShowStatsMeta, Table: &ast.TableName{Name: model.NewCIStr("STATS_META"), Schema: model.NewCIStr(mysql.SystemDB)}} 11628 } 11629 | "STATS_HISTOGRAMS" 11630 { 11631 $$ = &ast.ShowStmt{Tp: ast.ShowStatsHistograms, Table: &ast.TableName{Name: model.NewCIStr("STATS_HISTOGRAMS"), Schema: model.NewCIStr(mysql.SystemDB)}} 11632 } 11633 | "STATS_TOPN" 11634 { 11635 $$ = &ast.ShowStmt{Tp: ast.ShowStatsTopN} 11636 } 11637 | "STATS_BUCKETS" 11638 { 11639 $$ = &ast.ShowStmt{Tp: ast.ShowStatsBuckets, Table: &ast.TableName{Name: model.NewCIStr("STATS_BUCKETS"), Schema: model.NewCIStr(mysql.SystemDB)}} 11640 } 11641 | "STATS_HEALTHY" 11642 { 11643 $$ = &ast.ShowStmt{Tp: ast.ShowStatsHealthy} 11644 } 11645 | "STATS_LOCKED" 11646 { 11647 $$ = &ast.ShowStmt{Tp: ast.ShowStatsLocked, Table: &ast.TableName{Name: model.NewCIStr("STATS_TABLE_LOCKED"), Schema: model.NewCIStr(mysql.SystemDB)}} 11648 } 11649 | "HISTOGRAMS_IN_FLIGHT" 11650 { 11651 $$ = &ast.ShowStmt{Tp: ast.ShowHistogramsInFlight} 11652 } 11653 | "COLUMN_STATS_USAGE" 11654 { 11655 $$ = &ast.ShowStmt{Tp: ast.ShowColumnStatsUsage} 11656 } 11657 | "ANALYZE" "STATUS" 11658 { 11659 $$ = &ast.ShowStmt{Tp: ast.ShowAnalyzeStatus} 11660 } 11661 | "BACKUPS" 11662 { 11663 $$ = &ast.ShowStmt{Tp: ast.ShowBackups} 11664 } 11665 | "RESTORES" 11666 { 11667 $$ = &ast.ShowStmt{Tp: ast.ShowRestores} 11668 } 11669 | "PLACEMENT" 11670 { 11671 $$ = &ast.ShowStmt{Tp: ast.ShowPlacement} 11672 } 11673 | "PLACEMENT" "LABELS" 11674 { 11675 $$ = &ast.ShowStmt{Tp: ast.ShowPlacementLabels} 11676 } 11677 | "IMPORT" "JOBS" 11678 { 11679 $$ = &ast.ShowStmt{Tp: ast.ShowImportJobs} 11680 } 11681 11682 ShowLikeOrWhereOpt: 11683 { 11684 $$ = nil 11685 } 11686 | "LIKE" SimpleExpr 11687 { 11688 $$ = &ast.PatternLikeOrIlikeExpr{ 11689 Pattern: $2, 11690 Escape: '\\', 11691 IsLike: true, 11692 } 11693 } 11694 | "WHERE" Expression 11695 { 11696 $$ = $2 11697 } 11698 11699 GlobalScope: 11700 { 11701 $$ = false 11702 } 11703 | "GLOBAL" 11704 { 11705 $$ = true 11706 } 11707 | "SESSION" 11708 { 11709 $$ = false 11710 } 11711 11712 StatementScope: 11713 { 11714 $$ = ast.StatementScopeSession 11715 } 11716 | "GLOBAL" 11717 { 11718 $$ = ast.StatementScopeGlobal 11719 } 11720 | "INSTANCE" 11721 { 11722 $$ = ast.StatementScopeInstance 11723 } 11724 | "SESSION" 11725 { 11726 $$ = ast.StatementScopeSession 11727 } 11728 11729 OptFull: 11730 { 11731 $$ = false 11732 } 11733 | "FULL" 11734 { 11735 $$ = true 11736 } 11737 11738 ShowDatabaseNameOpt: 11739 { 11740 $$ = "" 11741 } 11742 | FromOrIn DBName 11743 { 11744 $$ = $2 11745 } 11746 11747 ShowTableAliasOpt: 11748 FromOrIn TableName 11749 { 11750 $$ = $2.(*ast.TableName) 11751 } 11752 11753 FlushStmt: 11754 "FLUSH" NoWriteToBinLogAliasOpt FlushOption 11755 { 11756 tmp := $3.(*ast.FlushStmt) 11757 tmp.NoWriteToBinLog = $2.(bool) 11758 $$ = tmp 11759 } 11760 11761 PluginNameList: 11762 Identifier 11763 { 11764 $$ = []string{$1} 11765 } 11766 | PluginNameList ',' Identifier 11767 { 11768 $$ = append($1.([]string), $3) 11769 } 11770 11771 FlushOption: 11772 "PRIVILEGES" 11773 { 11774 $$ = &ast.FlushStmt{ 11775 Tp: ast.FlushPrivileges, 11776 } 11777 } 11778 | "STATUS" 11779 { 11780 $$ = &ast.FlushStmt{ 11781 Tp: ast.FlushStatus, 11782 } 11783 } 11784 | "TIDB" "PLUGINS" PluginNameList 11785 { 11786 $$ = &ast.FlushStmt{ 11787 Tp: ast.FlushTiDBPlugin, 11788 Plugins: $3.([]string), 11789 } 11790 } 11791 | "HOSTS" 11792 { 11793 $$ = &ast.FlushStmt{ 11794 Tp: ast.FlushHosts, 11795 } 11796 } 11797 | LogTypeOpt "LOGS" 11798 { 11799 $$ = &ast.FlushStmt{ 11800 Tp: ast.FlushLogs, 11801 LogType: $1.(ast.LogType), 11802 } 11803 } 11804 | TableOrTables TableNameListOpt WithReadLockOpt 11805 { 11806 $$ = &ast.FlushStmt{ 11807 Tp: ast.FlushTables, 11808 Tables: $2.([]*ast.TableName), 11809 ReadLock: $3.(bool), 11810 } 11811 } 11812 | "CLIENT_ERRORS_SUMMARY" 11813 { 11814 $$ = &ast.FlushStmt{ 11815 Tp: ast.FlushClientErrorsSummary, 11816 } 11817 } 11818 11819 LogTypeOpt: 11820 /* empty */ 11821 { 11822 $$ = ast.LogTypeDefault 11823 } 11824 | "BINARY" 11825 { 11826 $$ = ast.LogTypeBinary 11827 } 11828 | "ENGINE" 11829 { 11830 $$ = ast.LogTypeEngine 11831 } 11832 | "ERROR" 11833 { 11834 $$ = ast.LogTypeError 11835 } 11836 | "GENERAL" 11837 { 11838 $$ = ast.LogTypeGeneral 11839 } 11840 | "SLOW" 11841 { 11842 $$ = ast.LogTypeSlow 11843 } 11844 11845 NoWriteToBinLogAliasOpt: 11846 %prec lowerThanLocal 11847 { 11848 $$ = false 11849 } 11850 | "NO_WRITE_TO_BINLOG" 11851 { 11852 $$ = true 11853 } 11854 | "LOCAL" 11855 { 11856 $$ = true 11857 } 11858 11859 TableNameListOpt: 11860 %prec empty 11861 { 11862 $$ = []*ast.TableName{} 11863 } 11864 | TableNameList 11865 11866 TableNameListOpt2: 11867 %prec empty 11868 { 11869 $$ = []*ast.TableName{} 11870 } 11871 | "TABLE" TableNameList 11872 { 11873 $$ = $2 11874 } 11875 11876 WithReadLockOpt: 11877 { 11878 $$ = false 11879 } 11880 | "WITH" "READ" "LOCK" 11881 { 11882 $$ = true 11883 } 11884 11885 Statement: 11886 EmptyStmt 11887 | AdminStmt 11888 | AlterDatabaseStmt 11889 | AlterTableStmt 11890 | AlterUserStmt 11891 | AlterInstanceStmt 11892 | AlterRangeStmt 11893 | AlterSequenceStmt 11894 | AlterPolicyStmt 11895 | AlterResourceGroupStmt 11896 | AnalyzeTableStmt 11897 | BeginTransactionStmt 11898 | BinlogStmt 11899 | BRIEStmt 11900 | CommitStmt 11901 | DeallocateStmt 11902 | DeleteFromStmt 11903 | ExecuteStmt 11904 | ExplainStmt 11905 | CalibrateResourceStmt 11906 | ChangeStmt 11907 | CreateDatabaseStmt 11908 | CreateIndexStmt 11909 | CreateTableStmt 11910 | CreateViewStmt 11911 | CreateUserStmt 11912 | CreateRoleStmt 11913 | CreateBindingStmt 11914 | CreatePolicyStmt 11915 | CreateProcedureStmt 11916 | CreateResourceGroupStmt 11917 | AddQueryWatchStmt 11918 | CreateSequenceStmt 11919 | CreateStatisticsStmt 11920 | DoStmt 11921 | DropDatabaseStmt 11922 | DropIndexStmt 11923 | DropTableStmt 11924 | DropProcedureStmt 11925 | DropPolicyStmt 11926 | DropSequenceStmt 11927 | DropViewStmt 11928 | DropUserStmt 11929 | DropResourceGroupStmt 11930 | DropQueryWatchStmt 11931 | DropRoleStmt 11932 | DropStatisticsStmt 11933 | DropStatsStmt 11934 | DropBindingStmt 11935 | FlushStmt 11936 | FlashbackTableStmt 11937 | FlashbackToTimestampStmt 11938 | FlashbackDatabaseStmt 11939 | GrantStmt 11940 | GrantProxyStmt 11941 | GrantRoleStmt 11942 | CallStmt 11943 | ImportIntoStmt 11944 | InsertIntoStmt 11945 | IndexAdviseStmt 11946 | KillStmt 11947 | LoadDataStmt 11948 | LoadStatsStmt 11949 | LockStatsStmt 11950 | UnlockStatsStmt 11951 | PlanReplayerStmt 11952 | PreparedStmt 11953 | RollbackStmt 11954 | RenameTableStmt 11955 | RenameUserStmt 11956 | ReplaceIntoStmt 11957 | RecoverTableStmt 11958 | ReleaseSavepointStmt 11959 | RevokeStmt 11960 | RevokeRoleStmt 11961 | SavepointStmt 11962 | SetOprStmt 11963 | SelectStmt 11964 | SelectStmtWithClause 11965 | SubSelect 11966 { 11967 var sel ast.StmtNode 11968 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 11969 case *ast.SelectStmt: 11970 x.IsInBraces = true 11971 sel = x 11972 case *ast.SetOprStmt: 11973 x.IsInBraces = true 11974 sel = x 11975 } 11976 $$ = sel 11977 } 11978 | SetStmt 11979 | SetBindingStmt 11980 | SetRoleStmt 11981 | SetDefaultRoleStmt 11982 | SplitRegionStmt 11983 | ShowStmt 11984 | TraceStmt 11985 | TruncateTableStmt 11986 | UpdateStmt 11987 | UseStmt 11988 | UnlockTablesStmt 11989 | LockTablesStmt 11990 | ShutdownStmt 11991 | RestartStmt 11992 | HelpStmt 11993 | NonTransactionalDMLStmt 11994 | PauseLoadDataStmt 11995 | ResumeLoadDataStmt 11996 | CancelImportStmt 11997 | DropLoadDataStmt 11998 11999 TraceableStmt: 12000 DeleteFromStmt 12001 | UpdateStmt 12002 | InsertIntoStmt 12003 | ReplaceIntoStmt 12004 | SetOprStmt 12005 | SelectStmt 12006 | SelectStmtWithClause 12007 | SubSelect 12008 { 12009 var sel ast.StmtNode 12010 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 12011 case *ast.SelectStmt: 12012 x.IsInBraces = true 12013 sel = x 12014 case *ast.SetOprStmt: 12015 x.IsInBraces = true 12016 sel = x 12017 } 12018 $$ = sel 12019 } 12020 | LoadDataStmt 12021 | BeginTransactionStmt 12022 | CommitStmt 12023 | SavepointStmt 12024 | ReleaseSavepointStmt 12025 | RollbackStmt 12026 | SetStmt 12027 | AnalyzeTableStmt 12028 12029 ExplainableStmt: 12030 DeleteFromStmt 12031 | UpdateStmt 12032 | InsertIntoStmt 12033 | ReplaceIntoStmt 12034 | SetOprStmt 12035 | SelectStmt 12036 | SelectStmtWithClause 12037 | SubSelect 12038 { 12039 var sel ast.StmtNode 12040 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 12041 case *ast.SelectStmt: 12042 x.IsInBraces = true 12043 sel = x 12044 case *ast.SetOprStmt: 12045 x.IsInBraces = true 12046 sel = x 12047 } 12048 $$ = sel 12049 } 12050 | AlterTableStmt 12051 12052 StatementList: 12053 Statement 12054 { 12055 if $1 != nil { 12056 s := $1 12057 if lexer, ok := yylex.(stmtTexter); ok { 12058 s.SetText(parser.lexer.client, lexer.stmtText()) 12059 } 12060 parser.result = append(parser.result, s) 12061 } 12062 } 12063 | StatementList ';' Statement 12064 { 12065 if $3 != nil { 12066 s := $3 12067 if lexer, ok := yylex.(stmtTexter); ok { 12068 s.SetText(parser.lexer.client, lexer.stmtText()) 12069 } 12070 parser.result = append(parser.result, s) 12071 } 12072 } 12073 12074 Constraint: 12075 ConstraintKeywordOpt ConstraintElem 12076 { 12077 cst := $2.(*ast.Constraint) 12078 if $1 != nil { 12079 cst.Name = $1.(string) 12080 cst.IsEmptyIndex = len(cst.Name) == 0 12081 } 12082 $$ = cst 12083 } 12084 12085 CheckConstraintKeyword: 12086 "CHECK" 12087 | "CONSTRAINT" 12088 12089 TableElement: 12090 ColumnDef 12091 | Constraint 12092 12093 TableElementList: 12094 TableElement 12095 { 12096 if $1 != nil { 12097 $$ = []interface{}{$1.(interface{})} 12098 } else { 12099 $$ = []interface{}{} 12100 } 12101 } 12102 | TableElementList ',' TableElement 12103 { 12104 if $3 != nil { 12105 $$ = append($1.([]interface{}), $3) 12106 } else { 12107 $$ = $1 12108 } 12109 } 12110 12111 TableElementListOpt: 12112 /* empty */ %prec lowerThanCreateTableSelect 12113 { 12114 var columnDefs []*ast.ColumnDef 12115 var constraints []*ast.Constraint 12116 $$ = &ast.CreateTableStmt{ 12117 Cols: columnDefs, 12118 Constraints: constraints, 12119 } 12120 } 12121 | '(' TableElementList ')' 12122 { 12123 tes := $2.([]interface{}) 12124 var columnDefs []*ast.ColumnDef 12125 var constraints []*ast.Constraint 12126 for _, te := range tes { 12127 switch te := te.(type) { 12128 case *ast.ColumnDef: 12129 columnDefs = append(columnDefs, te) 12130 case *ast.Constraint: 12131 constraints = append(constraints, te) 12132 } 12133 } 12134 $$ = &ast.CreateTableStmt{ 12135 Cols: columnDefs, 12136 Constraints: constraints, 12137 } 12138 } 12139 12140 TableOption: 12141 PartDefOption 12142 | DefaultKwdOpt CharsetKw EqOpt CharsetName 12143 { 12144 $$ = &ast.TableOption{Tp: ast.TableOptionCharset, StrValue: $4, 12145 UintValue: ast.TableOptionCharsetWithoutConvertTo} 12146 } 12147 | DefaultKwdOpt "COLLATE" EqOpt CollationName 12148 { 12149 $$ = &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $4, 12150 UintValue: ast.TableOptionCharsetWithoutConvertTo} 12151 } 12152 | ForceOpt "AUTO_INCREMENT" EqOpt LengthNum 12153 { 12154 $$ = &ast.TableOption{Tp: ast.TableOptionAutoIncrement, UintValue: $4.(uint64), BoolValue: $1.(bool)} 12155 } 12156 | "AUTO_ID_CACHE" EqOpt LengthNum 12157 { 12158 $$ = &ast.TableOption{Tp: ast.TableOptionAutoIdCache, UintValue: $3.(uint64)} 12159 } 12160 | ForceOpt "AUTO_RANDOM_BASE" EqOpt LengthNum 12161 { 12162 $$ = &ast.TableOption{Tp: ast.TableOptionAutoRandomBase, UintValue: $4.(uint64), BoolValue: $1.(bool)} 12163 } 12164 | "AVG_ROW_LENGTH" EqOpt LengthNum 12165 { 12166 $$ = &ast.TableOption{Tp: ast.TableOptionAvgRowLength, UintValue: $3.(uint64)} 12167 } 12168 | "CONNECTION" EqOpt stringLit 12169 { 12170 $$ = &ast.TableOption{Tp: ast.TableOptionConnection, StrValue: $3} 12171 } 12172 | "CHECKSUM" EqOpt LengthNum 12173 { 12174 $$ = &ast.TableOption{Tp: ast.TableOptionCheckSum, UintValue: $3.(uint64)} 12175 } 12176 | "TABLE_CHECKSUM" EqOpt LengthNum 12177 { 12178 $$ = &ast.TableOption{Tp: ast.TableOptionTableCheckSum, UintValue: $3.(uint64)} 12179 } 12180 | "PASSWORD" EqOpt stringLit 12181 { 12182 $$ = &ast.TableOption{Tp: ast.TableOptionPassword, StrValue: $3} 12183 } 12184 | "COMPRESSION" EqOpt stringLit 12185 { 12186 $$ = &ast.TableOption{Tp: ast.TableOptionCompression, StrValue: $3} 12187 } 12188 | "KEY_BLOCK_SIZE" EqOpt LengthNum 12189 { 12190 $$ = &ast.TableOption{Tp: ast.TableOptionKeyBlockSize, UintValue: $3.(uint64)} 12191 } 12192 | "DELAY_KEY_WRITE" EqOpt LengthNum 12193 { 12194 $$ = &ast.TableOption{Tp: ast.TableOptionDelayKeyWrite, UintValue: $3.(uint64)} 12195 } 12196 | RowFormat 12197 { 12198 $$ = &ast.TableOption{Tp: ast.TableOptionRowFormat, UintValue: $1.(uint64)} 12199 } 12200 | "STATS_PERSISTENT" EqOpt StatsPersistentVal 12201 { 12202 $$ = &ast.TableOption{Tp: ast.TableOptionStatsPersistent} 12203 } 12204 | "STATS_AUTO_RECALC" EqOpt LengthNum 12205 { 12206 n := $3.(uint64) 12207 if n != 0 && n != 1 { 12208 yylex.AppendError(yylex.Errorf("The value of STATS_AUTO_RECALC must be one of [0|1|DEFAULT].")) 12209 return 1 12210 } 12211 $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, UintValue: n} 12212 yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines.")) 12213 parser.lastErrorAsWarn() 12214 } 12215 | "STATS_AUTO_RECALC" EqOpt "DEFAULT" 12216 { 12217 $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, Default: true} 12218 yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines.")) 12219 parser.lastErrorAsWarn() 12220 } 12221 | "STATS_SAMPLE_PAGES" EqOpt LengthNum 12222 { 12223 // Parse it but will ignore it. 12224 // In MySQL, STATS_SAMPLE_PAGES=N(Where 0<N<=65535) or STAS_SAMPLE_PAGES=DEFAULT. 12225 // Cause we don't support it, so we don't check range of the value. 12226 $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, UintValue: $3.(uint64)} 12227 yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines.")) 12228 parser.lastErrorAsWarn() 12229 } 12230 | "STATS_SAMPLE_PAGES" EqOpt "DEFAULT" 12231 { 12232 // Parse it but will ignore it. 12233 // In MySQL, default value of STATS_SAMPLE_PAGES is 0. 12234 $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, Default: true} 12235 yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines.")) 12236 parser.lastErrorAsWarn() 12237 } 12238 | "STATS_BUCKETS" EqOpt LengthNum 12239 { 12240 $$ = &ast.TableOption{Tp: ast.TableOptionStatsBuckets, UintValue: $3.(uint64)} 12241 } 12242 | "STATS_TOPN" EqOpt LengthNum 12243 { 12244 $$ = &ast.TableOption{Tp: ast.TableOptionStatsTopN, UintValue: $3.(uint64)} 12245 } 12246 | "STATS_SAMPLE_RATE" EqOpt NumLiteral 12247 { 12248 $$ = &ast.TableOption{Tp: ast.TableOptionStatsSampleRate, Value: ast.NewValueExpr($3, "", "")} 12249 } 12250 | "STATS_COL_CHOICE" EqOpt stringLit 12251 { 12252 $$ = &ast.TableOption{Tp: ast.TableOptionStatsColsChoice, StrValue: $3} 12253 } 12254 | "STATS_COL_LIST" EqOpt stringLit 12255 { 12256 $$ = &ast.TableOption{Tp: ast.TableOptionStatsColList, StrValue: $3} 12257 } 12258 | "SHARD_ROW_ID_BITS" EqOpt LengthNum 12259 { 12260 $$ = &ast.TableOption{Tp: ast.TableOptionShardRowID, UintValue: $3.(uint64)} 12261 } 12262 | "PRE_SPLIT_REGIONS" EqOpt LengthNum 12263 { 12264 $$ = &ast.TableOption{Tp: ast.TableOptionPreSplitRegion, UintValue: $3.(uint64)} 12265 } 12266 | "PACK_KEYS" EqOpt StatsPersistentVal 12267 { 12268 // Parse it but will ignore it. 12269 $$ = &ast.TableOption{Tp: ast.TableOptionPackKeys} 12270 } 12271 | "STORAGE" "MEMORY" 12272 { 12273 // Parse it but will ignore it. 12274 $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "MEMORY"} 12275 yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines.")) 12276 parser.lastErrorAsWarn() 12277 } 12278 | "STORAGE" "DISK" 12279 { 12280 // Parse it but will ignore it. 12281 $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "DISK"} 12282 yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines.")) 12283 parser.lastErrorAsWarn() 12284 } 12285 | "SECONDARY_ENGINE" EqOpt "NULL" 12286 { 12287 // Parse it but will ignore it 12288 // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984 12289 $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngineNull} 12290 yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines.")) 12291 parser.lastErrorAsWarn() 12292 } 12293 | "SECONDARY_ENGINE" EqOpt StringName 12294 { 12295 // Parse it but will ignore it 12296 // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984 12297 $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngine, StrValue: $3} 12298 yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines.")) 12299 parser.lastErrorAsWarn() 12300 } 12301 | "UNION" EqOpt '(' TableNameListOpt ')' 12302 { 12303 // Parse it but will ignore it 12304 $$ = &ast.TableOption{ 12305 Tp: ast.TableOptionUnion, 12306 TableNames: $4.([]*ast.TableName), 12307 } 12308 yylex.AppendError(yylex.Errorf("The UNION option is parsed but ignored by all storage engines.")) 12309 parser.lastErrorAsWarn() 12310 } 12311 | "ENCRYPTION" EqOpt EncryptionOpt 12312 { 12313 // Parse it but will ignore it 12314 $$ = &ast.TableOption{Tp: ast.TableOptionEncryption, StrValue: $3} 12315 } 12316 | "TTL" EqOpt Identifier '+' "INTERVAL" Literal TimeUnit 12317 { 12318 $$ = &ast.TableOption{ 12319 Tp: ast.TableOptionTTL, 12320 ColumnName: &ast.ColumnName{Name: model.NewCIStr($3)}, 12321 Value: ast.NewValueExpr($6, parser.charset, parser.collation), 12322 TimeUnitValue: &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)}, 12323 } 12324 } 12325 | "TTL_ENABLE" EqOpt stringLit 12326 { 12327 onOrOff := strings.ToLower($3) 12328 if onOrOff == "on" { 12329 $$ = &ast.TableOption{Tp: ast.TableOptionTTLEnable, BoolValue: true} 12330 } else if onOrOff == "off" { 12331 $$ = &ast.TableOption{Tp: ast.TableOptionTTLEnable, BoolValue: false} 12332 } else { 12333 yylex.AppendError(yylex.Errorf("The TTL_ENABLE option has to be set 'ON' or 'OFF'")) 12334 return 1 12335 } 12336 } 12337 | "TTL_JOB_INTERVAL" EqOpt stringLit 12338 { 12339 _, err := duration.ParseDuration($3) 12340 if err != nil { 12341 yylex.AppendError(yylex.Errorf("The TTL_JOB_INTERVAL option is not a valid duration: %s", err.Error())) 12342 return 1 12343 } 12344 $$ = &ast.TableOption{Tp: ast.TableOptionTTLJobInterval, StrValue: $3} 12345 } 12346 12347 ForceOpt: 12348 /* empty */ 12349 { 12350 $$ = false 12351 } 12352 | "FORCE" 12353 { 12354 $$ = true 12355 } 12356 12357 StatsPersistentVal: 12358 "DEFAULT" 12359 {} 12360 | LengthNum 12361 {} 12362 12363 CreateTableOptionListOpt: 12364 /* empty */ %prec lowerThanCreateTableSelect 12365 { 12366 $$ = []*ast.TableOption{} 12367 } 12368 | TableOptionList %prec lowerThanComma 12369 12370 TableOptionList: 12371 TableOption 12372 { 12373 $$ = []*ast.TableOption{$1.(*ast.TableOption)} 12374 } 12375 | TableOptionList TableOption 12376 { 12377 $$ = append($1.([]*ast.TableOption), $2.(*ast.TableOption)) 12378 } 12379 | TableOptionList ',' TableOption 12380 { 12381 $$ = append($1.([]*ast.TableOption), $3.(*ast.TableOption)) 12382 } 12383 12384 OptTable: 12385 {} 12386 | "TABLE" 12387 12388 TruncateTableStmt: 12389 "TRUNCATE" OptTable TableName 12390 { 12391 $$ = &ast.TruncateTableStmt{Table: $3.(*ast.TableName)} 12392 } 12393 12394 RowFormat: 12395 "ROW_FORMAT" EqOpt "DEFAULT" 12396 { 12397 $$ = ast.RowFormatDefault 12398 } 12399 | "ROW_FORMAT" EqOpt "DYNAMIC" 12400 { 12401 $$ = ast.RowFormatDynamic 12402 } 12403 | "ROW_FORMAT" EqOpt "FIXED" 12404 { 12405 $$ = ast.RowFormatFixed 12406 } 12407 | "ROW_FORMAT" EqOpt "COMPRESSED" 12408 { 12409 $$ = ast.RowFormatCompressed 12410 } 12411 | "ROW_FORMAT" EqOpt "REDUNDANT" 12412 { 12413 $$ = ast.RowFormatRedundant 12414 } 12415 | "ROW_FORMAT" EqOpt "COMPACT" 12416 { 12417 $$ = ast.RowFormatCompact 12418 } 12419 | "ROW_FORMAT" EqOpt "TOKUDB_DEFAULT" 12420 { 12421 $$ = ast.TokuDBRowFormatDefault 12422 } 12423 | "ROW_FORMAT" EqOpt "TOKUDB_FAST" 12424 { 12425 $$ = ast.TokuDBRowFormatFast 12426 } 12427 | "ROW_FORMAT" EqOpt "TOKUDB_SMALL" 12428 { 12429 $$ = ast.TokuDBRowFormatSmall 12430 } 12431 | "ROW_FORMAT" EqOpt "TOKUDB_ZLIB" 12432 { 12433 $$ = ast.TokuDBRowFormatZlib 12434 } 12435 | "ROW_FORMAT" EqOpt "TOKUDB_ZSTD" 12436 { 12437 $$ = ast.TokuDBRowFormatZstd 12438 } 12439 | "ROW_FORMAT" EqOpt "TOKUDB_QUICKLZ" 12440 { 12441 $$ = ast.TokuDBRowFormatQuickLZ 12442 } 12443 | "ROW_FORMAT" EqOpt "TOKUDB_LZMA" 12444 { 12445 $$ = ast.TokuDBRowFormatLzma 12446 } 12447 | "ROW_FORMAT" EqOpt "TOKUDB_SNAPPY" 12448 { 12449 $$ = ast.TokuDBRowFormatSnappy 12450 } 12451 | "ROW_FORMAT" EqOpt "TOKUDB_UNCOMPRESSED" 12452 { 12453 $$ = ast.TokuDBRowFormatUncompressed 12454 } 12455 12456 /*************************************Type Begin***************************************/ 12457 Type: 12458 NumericType 12459 | StringType 12460 | DateAndTimeType 12461 12462 NumericType: 12463 IntegerType OptFieldLen FieldOpts 12464 { 12465 // TODO: check flen 0 12466 tp := types.NewFieldType($1.(byte)) 12467 tp.SetFlen($2.(int)) 12468 for _, o := range $3.([]*ast.TypeOpt) { 12469 if o.IsUnsigned { 12470 tp.AddFlag(mysql.UnsignedFlag) 12471 } 12472 if o.IsZerofill { 12473 tp.AddFlag(mysql.ZerofillFlag) 12474 } 12475 } 12476 $$ = tp 12477 } 12478 | BooleanType FieldOpts 12479 { 12480 // TODO: check flen 0 12481 tp := types.NewFieldType($1.(byte)) 12482 tp.SetFlen(1) 12483 for _, o := range $2.([]*ast.TypeOpt) { 12484 if o.IsUnsigned { 12485 tp.AddFlag(mysql.UnsignedFlag) 12486 } 12487 if o.IsZerofill { 12488 tp.AddFlag(mysql.ZerofillFlag) 12489 } 12490 } 12491 $$ = tp 12492 } 12493 | FixedPointType FloatOpt FieldOpts 12494 { 12495 fopt := $2.(*ast.FloatOpt) 12496 tp := types.NewFieldType($1.(byte)) 12497 tp.SetFlen(fopt.Flen) 12498 tp.SetDecimal(fopt.Decimal) 12499 for _, o := range $3.([]*ast.TypeOpt) { 12500 if o.IsUnsigned { 12501 tp.AddFlag(mysql.UnsignedFlag) 12502 } 12503 if o.IsZerofill { 12504 tp.AddFlag(mysql.ZerofillFlag) 12505 } 12506 } 12507 $$ = tp 12508 } 12509 | FloatingPointType FloatOpt FieldOpts 12510 { 12511 fopt := $2.(*ast.FloatOpt) 12512 tp := types.NewFieldType($1.(byte)) 12513 // check for a double(10) for syntax error 12514 if tp.GetType() == mysql.TypeDouble && parser.strictDoubleFieldType { 12515 if fopt.Flen != types.UnspecifiedLength && fopt.Decimal == types.UnspecifiedLength { 12516 yylex.AppendError(ErrSyntax) 12517 return 1 12518 } 12519 } 12520 tp.SetFlen(fopt.Flen) 12521 if tp.GetType() == mysql.TypeFloat && fopt.Decimal == types.UnspecifiedLength && tp.GetFlen() <= mysql.MaxDoublePrecisionLength { 12522 if tp.GetFlen() > mysql.MaxFloatPrecisionLength { 12523 tp.SetType(mysql.TypeDouble) 12524 } 12525 tp.SetFlen(types.UnspecifiedLength) 12526 } 12527 tp.SetDecimal(fopt.Decimal) 12528 for _, o := range $3.([]*ast.TypeOpt) { 12529 if o.IsUnsigned { 12530 tp.AddFlag(mysql.UnsignedFlag) 12531 } 12532 if o.IsZerofill { 12533 tp.AddFlag(mysql.ZerofillFlag) 12534 } 12535 } 12536 $$ = tp 12537 } 12538 | BitValueType OptFieldLen 12539 { 12540 tp := types.NewFieldType($1.(byte)) 12541 tp.SetFlen($2.(int)) 12542 if tp.GetFlen() == types.UnspecifiedLength { 12543 tp.SetFlen(1) 12544 } 12545 $$ = tp 12546 } 12547 12548 IntegerType: 12549 "TINYINT" 12550 { 12551 $$ = mysql.TypeTiny 12552 } 12553 | "SMALLINT" 12554 { 12555 $$ = mysql.TypeShort 12556 } 12557 | "MEDIUMINT" 12558 { 12559 $$ = mysql.TypeInt24 12560 } 12561 | "MIDDLEINT" 12562 { 12563 $$ = mysql.TypeInt24 12564 } 12565 | "INT" 12566 { 12567 $$ = mysql.TypeLong 12568 } 12569 | "INT1" 12570 { 12571 $$ = mysql.TypeTiny 12572 } 12573 | "INT2" 12574 { 12575 $$ = mysql.TypeShort 12576 } 12577 | "INT3" 12578 { 12579 $$ = mysql.TypeInt24 12580 } 12581 | "INT4" 12582 { 12583 $$ = mysql.TypeLong 12584 } 12585 | "INT8" 12586 { 12587 $$ = mysql.TypeLonglong 12588 } 12589 | "INTEGER" 12590 { 12591 $$ = mysql.TypeLong 12592 } 12593 | "BIGINT" 12594 { 12595 $$ = mysql.TypeLonglong 12596 } 12597 12598 BooleanType: 12599 "BOOL" 12600 { 12601 $$ = mysql.TypeTiny 12602 } 12603 | "BOOLEAN" 12604 { 12605 $$ = mysql.TypeTiny 12606 } 12607 12608 OptInteger: 12609 {} 12610 | "INTEGER" 12611 | "INT" 12612 12613 FixedPointType: 12614 "DECIMAL" 12615 { 12616 $$ = mysql.TypeNewDecimal 12617 } 12618 | "NUMERIC" 12619 { 12620 $$ = mysql.TypeNewDecimal 12621 } 12622 | "FIXED" 12623 { 12624 $$ = mysql.TypeNewDecimal 12625 } 12626 12627 FloatingPointType: 12628 "FLOAT" 12629 { 12630 $$ = mysql.TypeFloat 12631 } 12632 | "REAL" 12633 { 12634 if parser.lexer.GetSQLMode().HasRealAsFloatMode() { 12635 $$ = mysql.TypeFloat 12636 } else { 12637 $$ = mysql.TypeDouble 12638 } 12639 } 12640 | "DOUBLE" 12641 { 12642 $$ = mysql.TypeDouble 12643 } 12644 | "DOUBLE" "PRECISION" 12645 { 12646 $$ = mysql.TypeDouble 12647 } 12648 | "FLOAT4" 12649 { 12650 $$ = mysql.TypeFloat 12651 } 12652 | "FLOAT8" 12653 { 12654 $$ = mysql.TypeDouble 12655 } 12656 12657 BitValueType: 12658 "BIT" 12659 { 12660 $$ = mysql.TypeBit 12661 } 12662 12663 StringType: 12664 Char FieldLen OptBinary 12665 { 12666 tp := types.NewFieldType(mysql.TypeString) 12667 tp.SetFlen($2.(int)) 12668 tp.SetCharset($3.(*ast.OptBinary).Charset) 12669 if $3.(*ast.OptBinary).IsBinary { 12670 tp.AddFlag(mysql.BinaryFlag) 12671 } 12672 $$ = tp 12673 } 12674 | Char OptBinary 12675 { 12676 tp := types.NewFieldType(mysql.TypeString) 12677 tp.SetCharset($2.(*ast.OptBinary).Charset) 12678 if $2.(*ast.OptBinary).IsBinary { 12679 tp.AddFlag(mysql.BinaryFlag) 12680 } 12681 $$ = tp 12682 } 12683 | NChar FieldLen OptBinary 12684 { 12685 tp := types.NewFieldType(mysql.TypeString) 12686 tp.SetFlen($2.(int)) 12687 tp.SetCharset($3.(*ast.OptBinary).Charset) 12688 if $3.(*ast.OptBinary).IsBinary { 12689 tp.AddFlag(mysql.BinaryFlag) 12690 } 12691 $$ = tp 12692 } 12693 | NChar OptBinary 12694 { 12695 tp := types.NewFieldType(mysql.TypeString) 12696 tp.SetCharset($2.(*ast.OptBinary).Charset) 12697 if $2.(*ast.OptBinary).IsBinary { 12698 tp.AddFlag(mysql.BinaryFlag) 12699 } 12700 $$ = tp 12701 } 12702 | Varchar FieldLen OptBinary 12703 { 12704 tp := types.NewFieldType(mysql.TypeVarchar) 12705 tp.SetFlen($2.(int)) 12706 tp.SetCharset($3.(*ast.OptBinary).Charset) 12707 if $3.(*ast.OptBinary).IsBinary { 12708 tp.AddFlag(mysql.BinaryFlag) 12709 } 12710 $$ = tp 12711 } 12712 | NVarchar FieldLen OptBinary 12713 { 12714 tp := types.NewFieldType(mysql.TypeVarchar) 12715 tp.SetFlen($2.(int)) 12716 tp.SetCharset($3.(*ast.OptBinary).Charset) 12717 if $3.(*ast.OptBinary).IsBinary { 12718 tp.AddFlag(mysql.BinaryFlag) 12719 } 12720 $$ = tp 12721 } 12722 | "BINARY" OptFieldLen 12723 { 12724 tp := types.NewFieldType(mysql.TypeString) 12725 tp.SetFlen($2.(int)) 12726 tp.SetCharset(charset.CharsetBin) 12727 tp.SetCollate(charset.CharsetBin) 12728 tp.AddFlag(mysql.BinaryFlag) 12729 $$ = tp 12730 } 12731 | "VARBINARY" FieldLen 12732 { 12733 tp := types.NewFieldType(mysql.TypeVarchar) 12734 tp.SetFlen($2.(int)) 12735 tp.SetCharset(charset.CharsetBin) 12736 tp.SetCollate(charset.CharsetBin) 12737 tp.AddFlag(mysql.BinaryFlag) 12738 $$ = tp 12739 } 12740 | BlobType 12741 { 12742 tp := $1.(*types.FieldType) 12743 tp.SetCharset(charset.CharsetBin) 12744 tp.SetCollate(charset.CharsetBin) 12745 tp.AddFlag(mysql.BinaryFlag) 12746 $$ = tp 12747 } 12748 | TextType OptCharsetWithOptBinary 12749 { 12750 tp := $1.(*types.FieldType) 12751 tp.SetCharset($2.(*ast.OptBinary).Charset) 12752 if $2.(*ast.OptBinary).Charset == charset.CharsetBin { 12753 tp.AddFlag(mysql.BinaryFlag) 12754 tp.SetCollate(charset.CollationBin) 12755 } 12756 if $2.(*ast.OptBinary).IsBinary { 12757 tp.AddFlag(mysql.BinaryFlag) 12758 } 12759 $$ = tp 12760 } 12761 | "ENUM" '(' TextStringList ')' OptCharsetWithOptBinary 12762 { 12763 tp := types.NewFieldType(mysql.TypeEnum) 12764 elems := $3.([]*ast.TextString) 12765 opt := $5.(*ast.OptBinary) 12766 tp.SetElems(make([]string, len(elems))) 12767 fieldLen := -1 // enum_flen = max(ele_flen) 12768 for i, e := range elems { 12769 trimmed := strings.TrimRight(e.Value, " ") 12770 tp.SetElemWithIsBinaryLit(i, trimmed, e.IsBinaryLiteral) 12771 if len(trimmed) > fieldLen { 12772 fieldLen = len(trimmed) 12773 } 12774 } 12775 tp.SetFlen(fieldLen) 12776 tp.SetCharset(opt.Charset) 12777 if opt.IsBinary { 12778 tp.AddFlag(mysql.BinaryFlag) 12779 } 12780 $$ = tp 12781 } 12782 | "SET" '(' TextStringList ')' OptCharsetWithOptBinary 12783 { 12784 tp := types.NewFieldType(mysql.TypeSet) 12785 elems := $3.([]*ast.TextString) 12786 opt := $5.(*ast.OptBinary) 12787 tp.SetElems(make([]string, len(elems))) 12788 fieldLen := len(elems) - 1 // set_flen = sum(ele_flen) + number_of_ele - 1 12789 for i, e := range elems { 12790 trimmed := strings.TrimRight(e.Value, " ") 12791 tp.SetElemWithIsBinaryLit(i, trimmed, e.IsBinaryLiteral) 12792 fieldLen += len(trimmed) 12793 } 12794 tp.SetFlen(fieldLen) 12795 tp.SetCharset(opt.Charset) 12796 if opt.IsBinary { 12797 tp.AddFlag(mysql.BinaryFlag) 12798 } 12799 $$ = tp 12800 } 12801 | "JSON" 12802 { 12803 tp := types.NewFieldType(mysql.TypeJSON) 12804 tp.SetDecimal(0) 12805 tp.SetCharset(charset.CharsetBin) 12806 tp.SetCollate(charset.CollationBin) 12807 $$ = tp 12808 } 12809 | "LONG" Varchar OptCharsetWithOptBinary 12810 { 12811 tp := types.NewFieldType(mysql.TypeMediumBlob) 12812 tp.SetCharset($3.(*ast.OptBinary).Charset) 12813 if $3.(*ast.OptBinary).Charset == charset.CharsetBin { 12814 tp.AddFlag(mysql.BinaryFlag) 12815 tp.SetCollate(charset.CollationBin) 12816 } 12817 if $3.(*ast.OptBinary).IsBinary { 12818 tp.AddFlag(mysql.BinaryFlag) 12819 } 12820 $$ = tp 12821 } 12822 | "LONG" OptCharsetWithOptBinary 12823 { 12824 tp := types.NewFieldType(mysql.TypeMediumBlob) 12825 tp.SetCharset($2.(*ast.OptBinary).Charset) 12826 if $2.(*ast.OptBinary).Charset == charset.CharsetBin { 12827 tp.AddFlag(mysql.BinaryFlag) 12828 tp.SetCollate(charset.CollationBin) 12829 } 12830 if $2.(*ast.OptBinary).IsBinary { 12831 tp.AddFlag(mysql.BinaryFlag) 12832 } 12833 $$ = tp 12834 } 12835 12836 Char: 12837 "CHARACTER" 12838 | "CHAR" 12839 12840 NChar: 12841 "NCHAR" 12842 | "NATIONAL" "CHARACTER" 12843 | "NATIONAL" "CHAR" 12844 12845 Varchar: 12846 "CHARACTER" "VARYING" 12847 | "CHAR" "VARYING" 12848 | "VARCHAR" 12849 | "VARCHARACTER" 12850 12851 NVarchar: 12852 "NATIONAL" "VARCHAR" 12853 | "NATIONAL" "VARCHARACTER" 12854 | "NVARCHAR" 12855 | "NCHAR" "VARCHAR" 12856 | "NCHAR" "VARCHARACTER" 12857 | "NATIONAL" "CHARACTER" "VARYING" 12858 | "NATIONAL" "CHAR" "VARYING" 12859 | "NCHAR" "VARYING" 12860 12861 Year: 12862 "YEAR" 12863 | "SQL_TSI_YEAR" 12864 12865 BlobType: 12866 "TINYBLOB" 12867 { 12868 tp := types.NewFieldType(mysql.TypeTinyBlob) 12869 $$ = tp 12870 } 12871 | "BLOB" OptFieldLen 12872 { 12873 tp := types.NewFieldType(mysql.TypeBlob) 12874 tp.SetFlen($2.(int)) 12875 $$ = tp 12876 } 12877 | "MEDIUMBLOB" 12878 { 12879 tp := types.NewFieldType(mysql.TypeMediumBlob) 12880 $$ = tp 12881 } 12882 | "LONGBLOB" 12883 { 12884 tp := types.NewFieldType(mysql.TypeLongBlob) 12885 $$ = tp 12886 } 12887 | "LONG" "VARBINARY" 12888 { 12889 tp := types.NewFieldType(mysql.TypeMediumBlob) 12890 $$ = tp 12891 } 12892 12893 TextType: 12894 "TINYTEXT" 12895 { 12896 tp := types.NewFieldType(mysql.TypeTinyBlob) 12897 $$ = tp 12898 } 12899 | "TEXT" OptFieldLen 12900 { 12901 tp := types.NewFieldType(mysql.TypeBlob) 12902 tp.SetFlen($2.(int)) 12903 $$ = tp 12904 } 12905 | "MEDIUMTEXT" 12906 { 12907 tp := types.NewFieldType(mysql.TypeMediumBlob) 12908 $$ = tp 12909 } 12910 | "LONGTEXT" 12911 { 12912 tp := types.NewFieldType(mysql.TypeLongBlob) 12913 $$ = tp 12914 } 12915 12916 OptCharsetWithOptBinary: 12917 OptBinary 12918 | "ASCII" 12919 { 12920 $$ = &ast.OptBinary{ 12921 IsBinary: false, 12922 Charset: charset.CharsetLatin1, 12923 } 12924 } 12925 | "UNICODE" 12926 { 12927 cs, err := charset.GetCharsetInfo("ucs2") 12928 if err != nil { 12929 yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs("ucs2")) 12930 return 1 12931 } 12932 $$ = &ast.OptBinary{ 12933 IsBinary: false, 12934 Charset: cs.Name, 12935 } 12936 } 12937 | "BYTE" 12938 { 12939 $$ = &ast.OptBinary{ 12940 IsBinary: false, 12941 Charset: charset.CharsetBin, 12942 } 12943 } 12944 12945 DateAndTimeType: 12946 "DATE" 12947 { 12948 tp := types.NewFieldType(mysql.TypeDate) 12949 $$ = tp 12950 } 12951 | "DATETIME" OptFieldLen 12952 { 12953 tp := types.NewFieldType(mysql.TypeDatetime) 12954 tp.SetFlen(mysql.MaxDatetimeWidthNoFsp) 12955 tp.SetDecimal($2.(int)) 12956 if tp.GetDecimal() > 0 { 12957 tp.SetFlen(tp.GetFlen() + 1 + tp.GetDecimal()) 12958 } 12959 $$ = tp 12960 } 12961 | "TIMESTAMP" OptFieldLen 12962 { 12963 tp := types.NewFieldType(mysql.TypeTimestamp) 12964 tp.SetFlen(mysql.MaxDatetimeWidthNoFsp) 12965 tp.SetDecimal($2.(int)) 12966 if tp.GetDecimal() > 0 { 12967 tp.SetFlen(tp.GetFlen() + 1 + tp.GetDecimal()) 12968 } 12969 $$ = tp 12970 } 12971 | "TIME" OptFieldLen 12972 { 12973 tp := types.NewFieldType(mysql.TypeDuration) 12974 tp.SetFlen(mysql.MaxDurationWidthNoFsp) 12975 tp.SetDecimal($2.(int)) 12976 if tp.GetDecimal() > 0 { 12977 tp.SetFlen(tp.GetFlen() + 1 + tp.GetDecimal()) 12978 } 12979 $$ = tp 12980 } 12981 | Year OptFieldLen FieldOpts 12982 { 12983 tp := types.NewFieldType(mysql.TypeYear) 12984 tp.SetFlen($2.(int)) 12985 if tp.GetFlen() != types.UnspecifiedLength && tp.GetFlen() != 4 { 12986 yylex.AppendError(ErrInvalidYearColumnLength.GenWithStackByArgs()) 12987 return -1 12988 } 12989 $$ = tp 12990 } 12991 12992 FieldLen: 12993 '(' LengthNum ')' 12994 { 12995 $$ = int($2.(uint64)) 12996 } 12997 12998 OptFieldLen: 12999 { 13000 $$ = types.UnspecifiedLength 13001 } 13002 | FieldLen 13003 13004 FieldOpt: 13005 "UNSIGNED" 13006 { 13007 $$ = &ast.TypeOpt{IsUnsigned: true} 13008 } 13009 | "SIGNED" 13010 { 13011 $$ = &ast.TypeOpt{IsUnsigned: false} 13012 } 13013 | "ZEROFILL" 13014 { 13015 $$ = &ast.TypeOpt{IsZerofill: true, IsUnsigned: true} 13016 } 13017 13018 FieldOpts: 13019 { 13020 $$ = []*ast.TypeOpt{} 13021 } 13022 | FieldOpts FieldOpt 13023 { 13024 $$ = append($1.([]*ast.TypeOpt), $2.(*ast.TypeOpt)) 13025 } 13026 13027 FloatOpt: 13028 { 13029 $$ = &ast.FloatOpt{Flen: types.UnspecifiedLength, Decimal: types.UnspecifiedLength} 13030 } 13031 | FieldLen 13032 { 13033 $$ = &ast.FloatOpt{Flen: $1.(int), Decimal: types.UnspecifiedLength} 13034 } 13035 | Precision 13036 13037 Precision: 13038 '(' LengthNum ',' LengthNum ')' 13039 { 13040 $$ = &ast.FloatOpt{Flen: int($2.(uint64)), Decimal: int($4.(uint64))} 13041 } 13042 13043 OptBinMod: 13044 { 13045 $$ = false 13046 } 13047 | "BINARY" 13048 { 13049 $$ = true 13050 } 13051 13052 OptBinary: 13053 { 13054 $$ = &ast.OptBinary{ 13055 IsBinary: false, 13056 Charset: "", 13057 } 13058 } 13059 | "BINARY" OptCharset 13060 { 13061 $$ = &ast.OptBinary{ 13062 IsBinary: true, 13063 Charset: $2, 13064 } 13065 } 13066 | CharsetKw CharsetName OptBinMod 13067 { 13068 $$ = &ast.OptBinary{ 13069 IsBinary: $3.(bool), 13070 Charset: $2, 13071 } 13072 } 13073 13074 OptCharset: 13075 { 13076 $$ = "" 13077 } 13078 | CharsetKw CharsetName 13079 { 13080 $$ = $2 13081 } 13082 13083 CharsetKw: 13084 "CHARACTER" "SET" 13085 | "CHARSET" 13086 | "CHAR" "SET" 13087 13088 OptCollate: 13089 { 13090 $$ = "" 13091 } 13092 | "COLLATE" CollationName 13093 { 13094 $$ = $2 13095 } 13096 13097 StringList: 13098 stringLit 13099 { 13100 $$ = []string{$1} 13101 } 13102 | StringList ',' stringLit 13103 { 13104 $$ = append($1.([]string), $3) 13105 } 13106 13107 TextString: 13108 stringLit 13109 { 13110 $$ = &ast.TextString{Value: $1} 13111 } 13112 | hexLit 13113 { 13114 $$ = &ast.TextString{Value: $1.(ast.BinaryLiteral).ToString(), IsBinaryLiteral: true} 13115 } 13116 | bitLit 13117 { 13118 $$ = &ast.TextString{Value: $1.(ast.BinaryLiteral).ToString(), IsBinaryLiteral: true} 13119 } 13120 13121 TextStringList: 13122 TextString 13123 { 13124 $$ = []*ast.TextString{$1.(*ast.TextString)} 13125 } 13126 | TextStringList ',' TextString 13127 { 13128 $$ = append($1.([]*ast.TextString), $3.(*ast.TextString)) 13129 } 13130 13131 StringName: 13132 stringLit 13133 | Identifier 13134 13135 StringNameOrBRIEOptionKeyword: 13136 StringName 13137 | "IGNORE" 13138 | "REPLACE" 13139 13140 /*********************************************************************************** 13141 * Update Statement 13142 * See https://dev.mysql.com/doc/refman/5.7/en/update.html 13143 ***********************************************************************************/ 13144 UpdateStmt: 13145 UpdateStmtNoWith 13146 | WithClause UpdateStmtNoWith 13147 { 13148 u := $2.(*ast.UpdateStmt) 13149 u.With = $1.(*ast.WithClause) 13150 $$ = u 13151 } 13152 13153 UpdateStmtNoWith: 13154 "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRef "SET" AssignmentList WhereClauseOptional OrderByOptional LimitClause 13155 { 13156 var refs *ast.Join 13157 if x, ok := $5.(*ast.Join); ok { 13158 refs = x 13159 } else { 13160 refs = &ast.Join{Left: $5.(ast.ResultSetNode)} 13161 } 13162 st := &ast.UpdateStmt{ 13163 Priority: $3.(mysql.PriorityEnum), 13164 TableRefs: &ast.TableRefsClause{TableRefs: refs}, 13165 List: $7.([]*ast.Assignment), 13166 IgnoreErr: $4.(bool), 13167 } 13168 if $2 != nil { 13169 st.TableHints = $2.([]*ast.TableOptimizerHint) 13170 } 13171 if $8 != nil { 13172 st.Where = $8.(ast.ExprNode) 13173 } 13174 if $9 != nil { 13175 st.Order = $9.(*ast.OrderByClause) 13176 } 13177 if $10 != nil { 13178 st.Limit = $10.(*ast.Limit) 13179 } 13180 $$ = st 13181 } 13182 | "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRefs "SET" AssignmentList WhereClauseOptional 13183 { 13184 st := &ast.UpdateStmt{ 13185 Priority: $3.(mysql.PriorityEnum), 13186 TableRefs: &ast.TableRefsClause{TableRefs: $5.(*ast.Join)}, 13187 List: $7.([]*ast.Assignment), 13188 IgnoreErr: $4.(bool), 13189 } 13190 if $2 != nil { 13191 st.TableHints = $2.([]*ast.TableOptimizerHint) 13192 } 13193 if $8 != nil { 13194 st.Where = $8.(ast.ExprNode) 13195 } 13196 $$ = st 13197 } 13198 13199 UseStmt: 13200 "USE" DBName 13201 { 13202 $$ = &ast.UseStmt{DBName: $2} 13203 } 13204 13205 WhereClause: 13206 "WHERE" Expression 13207 { 13208 $$ = $2 13209 } 13210 13211 WhereClauseOptional: 13212 { 13213 $$ = nil 13214 } 13215 | WhereClause 13216 13217 CommaOpt: 13218 {} 13219 | ',' 13220 {} 13221 13222 /************************************************************************************ 13223 * Account Management Statements 13224 * https://dev.mysql.com/doc/refman/5.7/en/account-management-sql.html 13225 ************************************************************************************/ 13226 CreateUserStmt: 13227 "CREATE" "USER" IfNotExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions CommentOrAttributeOption ResourceGroupNameOption 13228 { 13229 // See https://dev.mysql.com/doc/refman/8.0/en/create-user.html 13230 ret := &ast.CreateUserStmt{ 13231 IsCreateRole: false, 13232 IfNotExists: $3.(bool), 13233 Specs: $4.([]*ast.UserSpec), 13234 AuthTokenOrTLSOptions: $5.([]*ast.AuthTokenOrTLSOption), 13235 ResourceOptions: $6.([]*ast.ResourceOption), 13236 PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption), 13237 } 13238 if $8 != nil { 13239 ret.CommentOrAttributeOption = $8.(*ast.CommentOrAttributeOption) 13240 } 13241 if $9 != nil { 13242 ret.ResourceGroupNameOption = $9.(*ast.ResourceGroupNameOption) 13243 } 13244 $$ = ret 13245 } 13246 13247 CreateRoleStmt: 13248 "CREATE" "ROLE" IfNotExists RoleSpecList 13249 { 13250 // See https://dev.mysql.com/doc/refman/8.0/en/create-role.html 13251 $$ = &ast.CreateUserStmt{ 13252 IsCreateRole: true, 13253 IfNotExists: $3.(bool), 13254 Specs: $4.([]*ast.UserSpec), 13255 } 13256 } 13257 13258 /* See http://dev.mysql.com/doc/refman/8.0/en/alter-user.html */ 13259 AlterUserStmt: 13260 "ALTER" "USER" IfExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions CommentOrAttributeOption ResourceGroupNameOption 13261 { 13262 ret := &ast.AlterUserStmt{ 13263 IfExists: $3.(bool), 13264 Specs: $4.([]*ast.UserSpec), 13265 AuthTokenOrTLSOptions: $5.([]*ast.AuthTokenOrTLSOption), 13266 ResourceOptions: $6.([]*ast.ResourceOption), 13267 PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption), 13268 } 13269 if $8 != nil { 13270 ret.CommentOrAttributeOption = $8.(*ast.CommentOrAttributeOption) 13271 } 13272 if $9 != nil { 13273 ret.ResourceGroupNameOption = $9.(*ast.ResourceGroupNameOption) 13274 } 13275 $$ = ret 13276 } 13277 | "ALTER" "USER" IfExists "USER" '(' ')' "IDENTIFIED" "BY" AuthString 13278 { 13279 auth := &ast.AuthOption{ 13280 AuthString: $9, 13281 ByAuthString: true, 13282 } 13283 $$ = &ast.AlterUserStmt{ 13284 IfExists: $3.(bool), 13285 CurrentAuth: auth, 13286 } 13287 } 13288 13289 /* See https://dev.mysql.com/doc/refman/8.0/en/alter-instance.html */ 13290 AlterInstanceStmt: 13291 "ALTER" "INSTANCE" InstanceOption 13292 { 13293 $$ = $3.(*ast.AlterInstanceStmt) 13294 } 13295 13296 AlterRangeStmt: 13297 "ALTER" "RANGE" Identifier PlacementPolicyOption 13298 { 13299 option := $4.(*ast.PlacementOption) 13300 $$ = &ast.AlterRangeStmt{RangeName: model.NewCIStr($3), PlacementOption: option} 13301 } 13302 13303 InstanceOption: 13304 "RELOAD" "TLS" 13305 { 13306 $$ = &ast.AlterInstanceStmt{ 13307 ReloadTLS: true, 13308 } 13309 } 13310 | "RELOAD" "TLS" "NO" "ROLLBACK" "ON" "ERROR" 13311 { 13312 $$ = &ast.AlterInstanceStmt{ 13313 ReloadTLS: true, 13314 NoRollbackOnError: true, 13315 } 13316 } 13317 13318 UserSpec: 13319 Username AuthOption 13320 { 13321 userSpec := &ast.UserSpec{ 13322 User: $1.(*auth.UserIdentity), 13323 } 13324 if $2 != nil { 13325 userSpec.AuthOpt = $2.(*ast.AuthOption) 13326 } 13327 $$ = userSpec 13328 } 13329 13330 UserSpecList: 13331 UserSpec 13332 { 13333 $$ = []*ast.UserSpec{$1.(*ast.UserSpec)} 13334 } 13335 | UserSpecList ',' UserSpec 13336 { 13337 $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec)) 13338 } 13339 13340 ConnectionOptions: 13341 { 13342 l := []*ast.ResourceOption{} 13343 $$ = l 13344 } 13345 | "WITH" ConnectionOptionList 13346 { 13347 $$ = $2 13348 yylex.AppendError(yylex.Errorf("TiDB does not support WITH ConnectionOptions now, they would be parsed but ignored.")) 13349 parser.lastErrorAsWarn() 13350 } 13351 13352 ConnectionOptionList: 13353 ConnectionOption 13354 { 13355 $$ = []*ast.ResourceOption{$1.(*ast.ResourceOption)} 13356 } 13357 | ConnectionOptionList ConnectionOption 13358 { 13359 l := $1.([]*ast.ResourceOption) 13360 l = append(l, $2.(*ast.ResourceOption)) 13361 $$ = l 13362 } 13363 13364 ConnectionOption: 13365 "MAX_QUERIES_PER_HOUR" Int64Num 13366 { 13367 $$ = &ast.ResourceOption{ 13368 Type: ast.MaxQueriesPerHour, 13369 Count: $2.(int64), 13370 } 13371 } 13372 | "MAX_UPDATES_PER_HOUR" Int64Num 13373 { 13374 $$ = &ast.ResourceOption{ 13375 Type: ast.MaxUpdatesPerHour, 13376 Count: $2.(int64), 13377 } 13378 } 13379 | "MAX_CONNECTIONS_PER_HOUR" Int64Num 13380 { 13381 $$ = &ast.ResourceOption{ 13382 Type: ast.MaxConnectionsPerHour, 13383 Count: $2.(int64), 13384 } 13385 } 13386 | "MAX_USER_CONNECTIONS" Int64Num 13387 { 13388 $$ = &ast.ResourceOption{ 13389 Type: ast.MaxUserConnections, 13390 Count: $2.(int64), 13391 } 13392 } 13393 13394 RequireClauseOpt: 13395 { 13396 $$ = []*ast.AuthTokenOrTLSOption{} 13397 } 13398 | RequireClause 13399 13400 RequireClause: 13401 "REQUIRE" "NONE" 13402 { 13403 t := &ast.AuthTokenOrTLSOption{ 13404 Type: ast.TlsNone, 13405 } 13406 $$ = []*ast.AuthTokenOrTLSOption{t} 13407 } 13408 | "REQUIRE" "SSL" 13409 { 13410 t := &ast.AuthTokenOrTLSOption{ 13411 Type: ast.Ssl, 13412 } 13413 $$ = []*ast.AuthTokenOrTLSOption{t} 13414 } 13415 | "REQUIRE" "X509" 13416 { 13417 t := &ast.AuthTokenOrTLSOption{ 13418 Type: ast.X509, 13419 } 13420 $$ = []*ast.AuthTokenOrTLSOption{t} 13421 } 13422 | "REQUIRE" RequireList 13423 { 13424 $$ = $2 13425 } 13426 13427 RequireList: 13428 RequireListElement 13429 { 13430 $$ = []*ast.AuthTokenOrTLSOption{$1.(*ast.AuthTokenOrTLSOption)} 13431 } 13432 | RequireList "AND" RequireListElement 13433 { 13434 l := $1.([]*ast.AuthTokenOrTLSOption) 13435 l = append(l, $3.(*ast.AuthTokenOrTLSOption)) 13436 $$ = l 13437 } 13438 | RequireList RequireListElement 13439 { 13440 l := $1.([]*ast.AuthTokenOrTLSOption) 13441 l = append(l, $2.(*ast.AuthTokenOrTLSOption)) 13442 $$ = l 13443 } 13444 13445 RequireListElement: 13446 "ISSUER" stringLit 13447 { 13448 $$ = &ast.AuthTokenOrTLSOption{ 13449 Type: ast.Issuer, 13450 Value: $2, 13451 } 13452 } 13453 | "SUBJECT" stringLit 13454 { 13455 $$ = &ast.AuthTokenOrTLSOption{ 13456 Type: ast.Subject, 13457 Value: $2, 13458 } 13459 } 13460 | "CIPHER" stringLit 13461 { 13462 $$ = &ast.AuthTokenOrTLSOption{ 13463 Type: ast.Cipher, 13464 Value: $2, 13465 } 13466 } 13467 | "SAN" stringLit 13468 { 13469 $$ = &ast.AuthTokenOrTLSOption{ 13470 Type: ast.SAN, 13471 Value: $2, 13472 } 13473 } 13474 | "TOKEN_ISSUER" stringLit 13475 { 13476 $$ = &ast.AuthTokenOrTLSOption{ 13477 Type: ast.TokenIssuer, 13478 Value: $2, 13479 } 13480 } 13481 13482 CommentOrAttributeOption: 13483 { 13484 $$ = nil 13485 } 13486 | "COMMENT" stringLit 13487 { 13488 $$ = &ast.CommentOrAttributeOption{Type: ast.UserCommentType, Value: $2} 13489 } 13490 | "ATTRIBUTE" stringLit 13491 { 13492 $$ = &ast.CommentOrAttributeOption{Type: ast.UserAttributeType, Value: $2} 13493 } 13494 13495 ResourceGroupNameOption: 13496 { 13497 $$ = nil 13498 } 13499 | "RESOURCE" "GROUP" ResourceGroupName 13500 { 13501 $$ = &ast.ResourceGroupNameOption{Value: $3} 13502 } 13503 13504 PasswordOrLockOptions: 13505 { 13506 $$ = []*ast.PasswordOrLockOption{} 13507 } 13508 | PasswordOrLockOptionList 13509 { 13510 $$ = $1 13511 } 13512 13513 PasswordOrLockOptionList: 13514 PasswordOrLockOption 13515 { 13516 $$ = []*ast.PasswordOrLockOption{$1.(*ast.PasswordOrLockOption)} 13517 } 13518 | PasswordOrLockOptionList PasswordOrLockOption 13519 { 13520 l := $1.([]*ast.PasswordOrLockOption) 13521 l = append(l, $2.(*ast.PasswordOrLockOption)) 13522 $$ = l 13523 } 13524 13525 PasswordOrLockOption: 13526 "ACCOUNT" "UNLOCK" 13527 { 13528 $$ = &ast.PasswordOrLockOption{ 13529 Type: ast.Unlock, 13530 } 13531 } 13532 | "ACCOUNT" "LOCK" 13533 { 13534 $$ = &ast.PasswordOrLockOption{ 13535 Type: ast.Lock, 13536 } 13537 } 13538 | "PASSWORD" "HISTORY" "DEFAULT" 13539 { 13540 $$ = &ast.PasswordOrLockOption{ 13541 Type: ast.PasswordHistoryDefault, 13542 } 13543 } 13544 | "PASSWORD" "HISTORY" NUM 13545 { 13546 $$ = &ast.PasswordOrLockOption{ 13547 Type: ast.PasswordHistory, 13548 Count: $3.(int64), 13549 } 13550 } 13551 | "PASSWORD" "REUSE" "INTERVAL" "DEFAULT" 13552 { 13553 $$ = &ast.PasswordOrLockOption{ 13554 Type: ast.PasswordReuseDefault, 13555 } 13556 } 13557 | "PASSWORD" "REUSE" "INTERVAL" NUM "DAY" 13558 { 13559 $$ = &ast.PasswordOrLockOption{ 13560 Type: ast.PasswordReuseInterval, 13561 Count: $4.(int64), 13562 } 13563 } 13564 | "PASSWORD" "EXPIRE" 13565 { 13566 $$ = &ast.PasswordOrLockOption{ 13567 Type: ast.PasswordExpire, 13568 } 13569 } 13570 | "PASSWORD" "EXPIRE" "INTERVAL" Int64Num "DAY" 13571 { 13572 $$ = &ast.PasswordOrLockOption{ 13573 Type: ast.PasswordExpireInterval, 13574 Count: $4.(int64), 13575 } 13576 } 13577 | "PASSWORD" "EXPIRE" "NEVER" 13578 { 13579 $$ = &ast.PasswordOrLockOption{ 13580 Type: ast.PasswordExpireNever, 13581 } 13582 } 13583 | "PASSWORD" "EXPIRE" "DEFAULT" 13584 { 13585 $$ = &ast.PasswordOrLockOption{ 13586 Type: ast.PasswordExpireDefault, 13587 } 13588 } 13589 | "FAILED_LOGIN_ATTEMPTS" Int64Num 13590 { 13591 $$ = &ast.PasswordOrLockOption{ 13592 Type: ast.FailedLoginAttempts, 13593 Count: $2.(int64), 13594 } 13595 } 13596 | "PASSWORD_LOCK_TIME" Int64Num 13597 { 13598 $$ = &ast.PasswordOrLockOption{ 13599 Type: ast.PasswordLockTime, 13600 Count: $2.(int64), 13601 } 13602 } 13603 | "PASSWORD_LOCK_TIME" "UNBOUNDED" 13604 { 13605 $$ = &ast.PasswordOrLockOption{ 13606 Type: ast.PasswordLockTimeUnbounded, 13607 } 13608 } 13609 13610 AuthOption: 13611 { 13612 $$ = nil 13613 } 13614 | "IDENTIFIED" "BY" AuthString 13615 { 13616 $$ = &ast.AuthOption{ 13617 AuthString: $3, 13618 ByAuthString: true, 13619 } 13620 } 13621 | "IDENTIFIED" "WITH" AuthPlugin 13622 { 13623 $$ = &ast.AuthOption{ 13624 AuthPlugin: $3, 13625 } 13626 } 13627 | "IDENTIFIED" "WITH" AuthPlugin "BY" AuthString 13628 { 13629 $$ = &ast.AuthOption{ 13630 AuthPlugin: $3, 13631 AuthString: $5, 13632 ByAuthString: true, 13633 } 13634 } 13635 | "IDENTIFIED" "WITH" AuthPlugin "AS" HashString 13636 { 13637 $$ = &ast.AuthOption{ 13638 AuthPlugin: $3, 13639 HashString: $5, 13640 ByHashString: true, 13641 } 13642 } 13643 | "IDENTIFIED" "BY" "PASSWORD" HashString 13644 { 13645 $$ = &ast.AuthOption{ 13646 AuthPlugin: mysql.AuthNativePassword, 13647 HashString: $4, 13648 ByHashString: true, 13649 } 13650 } 13651 13652 AuthPlugin: 13653 StringName 13654 13655 HashString: 13656 stringLit 13657 | hexLit 13658 { 13659 $$ = $1.(ast.BinaryLiteral).ToString() 13660 } 13661 13662 RoleSpec: 13663 Rolename 13664 { 13665 role := $1.(*auth.RoleIdentity) 13666 roleSpec := &ast.UserSpec{ 13667 User: &auth.UserIdentity{ 13668 Username: role.Username, 13669 Hostname: role.Hostname, 13670 }, 13671 IsRole: true, 13672 } 13673 $$ = roleSpec 13674 } 13675 13676 RoleSpecList: 13677 RoleSpec 13678 { 13679 $$ = []*ast.UserSpec{$1.(*ast.UserSpec)} 13680 } 13681 | RoleSpecList ',' RoleSpec 13682 { 13683 $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec)) 13684 } 13685 13686 BindableStmt: 13687 SetOprStmt 13688 | SelectStmt 13689 | SelectStmtWithClause 13690 | SubSelect 13691 { 13692 var sel ast.StmtNode 13693 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 13694 case *ast.SelectStmt: 13695 x.IsInBraces = true 13696 sel = x 13697 case *ast.SetOprStmt: 13698 x.IsInBraces = true 13699 sel = x 13700 } 13701 $$ = sel 13702 } 13703 | UpdateStmt 13704 | DeleteWithoutUsingStmt 13705 | InsertIntoStmt 13706 | ReplaceIntoStmt 13707 13708 /******************************************************************* 13709 * 13710 * Create Binding Statement 13711 * 13712 * Example: 13713 * CREATE GLOBAL BINDING FOR select Col1,Col2 from table USING select Col1,Col2 from table use index(Col1) 13714 *******************************************************************/ 13715 CreateBindingStmt: 13716 "CREATE" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt 13717 { 13718 startOffset := parser.startOffset(&yyS[yypt-2]) 13719 endOffset := parser.startOffset(&yyS[yypt-1]) 13720 originStmt := $5 13721 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:endOffset])) 13722 13723 startOffset = parser.startOffset(&yyS[yypt]) 13724 hintedStmt := $7 13725 hintedStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 13726 13727 x := &ast.CreateBindingStmt{ 13728 OriginNode: originStmt, 13729 HintedNode: hintedStmt, 13730 GlobalScope: $2.(bool), 13731 } 13732 13733 $$ = x 13734 } 13735 | "CREATE" GlobalScope "BINDING" "FROM" "HISTORY" "USING" "PLAN" "DIGEST" stringLit 13736 { 13737 x := &ast.CreateBindingStmt{ 13738 GlobalScope: $2.(bool), 13739 PlanDigest: $9, 13740 } 13741 13742 $$ = x 13743 } 13744 13745 /******************************************************************* 13746 * 13747 * Drop Binding Statement 13748 * 13749 * Example: 13750 * DROP GLOBAL BINDING FOR select Col1,Col2 from table 13751 *******************************************************************/ 13752 DropBindingStmt: 13753 "DROP" GlobalScope "BINDING" "FOR" BindableStmt 13754 { 13755 startOffset := parser.startOffset(&yyS[yypt]) 13756 originStmt := $5 13757 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 13758 13759 x := &ast.DropBindingStmt{ 13760 OriginNode: originStmt, 13761 GlobalScope: $2.(bool), 13762 } 13763 13764 $$ = x 13765 } 13766 | "DROP" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt 13767 { 13768 startOffset := parser.startOffset(&yyS[yypt-2]) 13769 endOffset := parser.startOffset(&yyS[yypt-1]) 13770 originStmt := $5 13771 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:endOffset])) 13772 13773 startOffset = parser.startOffset(&yyS[yypt]) 13774 hintedStmt := $7 13775 hintedStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 13776 13777 x := &ast.DropBindingStmt{ 13778 OriginNode: originStmt, 13779 HintedNode: hintedStmt, 13780 GlobalScope: $2.(bool), 13781 } 13782 13783 $$ = x 13784 } 13785 | "DROP" GlobalScope "BINDING" "FOR" "SQL" "DIGEST" stringLit 13786 { 13787 x := &ast.DropBindingStmt{ 13788 GlobalScope: $2.(bool), 13789 SQLDigest: $7, 13790 } 13791 13792 $$ = x 13793 } 13794 13795 SetBindingStmt: 13796 "SET" "BINDING" BindingStatusType "FOR" BindableStmt 13797 { 13798 startOffset := parser.startOffset(&yyS[yypt]) 13799 originStmt := $5 13800 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 13801 13802 x := &ast.SetBindingStmt{ 13803 BindingStatusType: $3.(ast.BindingStatusType), 13804 OriginNode: originStmt, 13805 } 13806 13807 $$ = x 13808 } 13809 | "SET" "BINDING" BindingStatusType "FOR" BindableStmt "USING" BindableStmt 13810 { 13811 startOffset := parser.startOffset(&yyS[yypt-2]) 13812 endOffset := parser.startOffset(&yyS[yypt-1]) 13813 originStmt := $5 13814 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:endOffset])) 13815 13816 startOffset = parser.startOffset(&yyS[yypt]) 13817 hintedStmt := $7 13818 hintedStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 13819 13820 x := &ast.SetBindingStmt{ 13821 BindingStatusType: $3.(ast.BindingStatusType), 13822 OriginNode: originStmt, 13823 HintedNode: hintedStmt, 13824 } 13825 13826 $$ = x 13827 } 13828 | "SET" "BINDING" BindingStatusType "FOR" "SQL" "DIGEST" stringLit 13829 { 13830 x := &ast.SetBindingStmt{ 13831 BindingStatusType: $3.(ast.BindingStatusType), 13832 SQLDigest: $7, 13833 } 13834 13835 $$ = x 13836 } 13837 13838 /************************************************************************************* 13839 * Grant statement 13840 * See https://dev.mysql.com/doc/refman/5.7/en/grant.html 13841 *************************************************************************************/ 13842 GrantStmt: 13843 "GRANT" RoleOrPrivElemList "ON" ObjectType PrivLevel "TO" UserSpecList RequireClauseOpt WithGrantOptionOpt 13844 { 13845 p, err := convertToPriv($2.([]*ast.RoleOrPriv)) 13846 if err != nil { 13847 yylex.AppendError(err) 13848 return 1 13849 } 13850 $$ = &ast.GrantStmt{ 13851 Privs: p, 13852 ObjectType: $4.(ast.ObjectTypeType), 13853 Level: $5.(*ast.GrantLevel), 13854 Users: $7.([]*ast.UserSpec), 13855 AuthTokenOrTLSOptions: $8.([]*ast.AuthTokenOrTLSOption), 13856 WithGrant: $9.(bool), 13857 } 13858 } 13859 13860 GrantProxyStmt: 13861 "GRANT" "PROXY" "ON" Username "TO" UsernameList WithGrantOptionOpt 13862 { 13863 $$ = &ast.GrantProxyStmt{ 13864 LocalUser: $4.(*auth.UserIdentity), 13865 ExternalUsers: $6.([]*auth.UserIdentity), 13866 WithGrant: $7.(bool), 13867 } 13868 } 13869 13870 GrantRoleStmt: 13871 "GRANT" RoleOrPrivElemList "TO" UsernameList 13872 { 13873 r, err := convertToRole($2.([]*ast.RoleOrPriv)) 13874 if err != nil { 13875 yylex.AppendError(err) 13876 return 1 13877 } 13878 $$ = &ast.GrantRoleStmt{ 13879 Roles: r, 13880 Users: $4.([]*auth.UserIdentity), 13881 } 13882 } 13883 13884 WithGrantOptionOpt: 13885 { 13886 $$ = false 13887 } 13888 | "WITH" "GRANT" "OPTION" 13889 { 13890 $$ = true 13891 } 13892 | "WITH" "MAX_QUERIES_PER_HOUR" NUM 13893 { 13894 $$ = false 13895 } 13896 | "WITH" "MAX_UPDATES_PER_HOUR" NUM 13897 { 13898 $$ = false 13899 } 13900 | "WITH" "MAX_CONNECTIONS_PER_HOUR" NUM 13901 { 13902 $$ = false 13903 } 13904 | "WITH" "MAX_USER_CONNECTIONS" NUM 13905 { 13906 $$ = false 13907 } 13908 13909 ExtendedPriv: 13910 identifier 13911 { 13912 $$ = []string{$1} 13913 } 13914 | ExtendedPriv identifier 13915 { 13916 $$ = append($1.([]string), $2) 13917 } 13918 13919 RoleOrPrivElem: 13920 PrivElem 13921 { 13922 $$ = &ast.RoleOrPriv{ 13923 Node: $1, 13924 } 13925 } 13926 | RolenameWithoutIdent 13927 { 13928 $$ = &ast.RoleOrPriv{ 13929 Node: $1, 13930 } 13931 } 13932 | ExtendedPriv 13933 { 13934 $$ = &ast.RoleOrPriv{ 13935 Symbols: strings.Join($1.([]string), " "), 13936 } 13937 } 13938 | "LOAD" "FROM" "S3" 13939 { 13940 $$ = &ast.RoleOrPriv{ 13941 Symbols: "LOAD FROM S3", 13942 } 13943 } 13944 | "SELECT" "INTO" "S3" 13945 { 13946 $$ = &ast.RoleOrPriv{ 13947 Symbols: "SELECT INTO S3", 13948 } 13949 } 13950 13951 RoleOrPrivElemList: 13952 RoleOrPrivElem 13953 { 13954 $$ = []*ast.RoleOrPriv{$1.(*ast.RoleOrPriv)} 13955 } 13956 | RoleOrPrivElemList ',' RoleOrPrivElem 13957 { 13958 $$ = append($1.([]*ast.RoleOrPriv), $3.(*ast.RoleOrPriv)) 13959 } 13960 13961 PrivElem: 13962 PrivType 13963 { 13964 $$ = &ast.PrivElem{ 13965 Priv: $1.(mysql.PrivilegeType), 13966 } 13967 } 13968 | PrivType '(' ColumnNameList ')' 13969 { 13970 $$ = &ast.PrivElem{ 13971 Priv: $1.(mysql.PrivilegeType), 13972 Cols: $3.([]*ast.ColumnName), 13973 } 13974 } 13975 13976 PrivType: 13977 "ALL" 13978 { 13979 $$ = mysql.AllPriv 13980 } 13981 | "ALL" "PRIVILEGES" 13982 { 13983 $$ = mysql.AllPriv 13984 } 13985 | "ALTER" 13986 { 13987 $$ = mysql.AlterPriv 13988 } 13989 | "CREATE" 13990 { 13991 $$ = mysql.CreatePriv 13992 } 13993 | "CREATE" "USER" 13994 { 13995 $$ = mysql.CreateUserPriv 13996 } 13997 | "CREATE" "TABLESPACE" 13998 { 13999 $$ = mysql.CreateTablespacePriv 14000 } 14001 | "TRIGGER" 14002 { 14003 $$ = mysql.TriggerPriv 14004 } 14005 | "DELETE" 14006 { 14007 $$ = mysql.DeletePriv 14008 } 14009 | "DROP" 14010 { 14011 $$ = mysql.DropPriv 14012 } 14013 | "PROCESS" 14014 { 14015 $$ = mysql.ProcessPriv 14016 } 14017 | "EXECUTE" 14018 { 14019 $$ = mysql.ExecutePriv 14020 } 14021 | "INDEX" 14022 { 14023 $$ = mysql.IndexPriv 14024 } 14025 | "INSERT" 14026 { 14027 $$ = mysql.InsertPriv 14028 } 14029 | "SELECT" 14030 { 14031 $$ = mysql.SelectPriv 14032 } 14033 | "SUPER" 14034 { 14035 $$ = mysql.SuperPriv 14036 } 14037 | "SHOW" "DATABASES" 14038 { 14039 $$ = mysql.ShowDBPriv 14040 } 14041 | "UPDATE" 14042 { 14043 $$ = mysql.UpdatePriv 14044 } 14045 | "GRANT" "OPTION" 14046 { 14047 $$ = mysql.GrantPriv 14048 } 14049 | "REFERENCES" 14050 { 14051 $$ = mysql.ReferencesPriv 14052 } 14053 | "REPLICATION" "SLAVE" 14054 { 14055 $$ = mysql.ReplicationSlavePriv 14056 } 14057 | "REPLICATION" "CLIENT" 14058 { 14059 $$ = mysql.ReplicationClientPriv 14060 } 14061 | "USAGE" 14062 { 14063 $$ = mysql.UsagePriv 14064 } 14065 | "RELOAD" 14066 { 14067 $$ = mysql.ReloadPriv 14068 } 14069 | "FILE" 14070 { 14071 $$ = mysql.FilePriv 14072 } 14073 | "CONFIG" 14074 { 14075 $$ = mysql.ConfigPriv 14076 } 14077 | "CREATE" "TEMPORARY" "TABLES" 14078 { 14079 $$ = mysql.CreateTMPTablePriv 14080 } 14081 | "LOCK" "TABLES" 14082 { 14083 $$ = mysql.LockTablesPriv 14084 } 14085 | "CREATE" "VIEW" 14086 { 14087 $$ = mysql.CreateViewPriv 14088 } 14089 | "SHOW" "VIEW" 14090 { 14091 $$ = mysql.ShowViewPriv 14092 } 14093 | "CREATE" "ROLE" 14094 { 14095 $$ = mysql.CreateRolePriv 14096 } 14097 | "DROP" "ROLE" 14098 { 14099 $$ = mysql.DropRolePriv 14100 } 14101 | "CREATE" "ROUTINE" 14102 { 14103 $$ = mysql.CreateRoutinePriv 14104 } 14105 | "ALTER" "ROUTINE" 14106 { 14107 $$ = mysql.AlterRoutinePriv 14108 } 14109 | "EVENT" 14110 { 14111 $$ = mysql.EventPriv 14112 } 14113 | "SHUTDOWN" 14114 { 14115 $$ = mysql.ShutdownPriv 14116 } 14117 14118 ObjectType: 14119 %prec lowerThanFunction 14120 { 14121 $$ = ast.ObjectTypeNone 14122 } 14123 | "TABLE" 14124 { 14125 $$ = ast.ObjectTypeTable 14126 } 14127 | "FUNCTION" 14128 { 14129 $$ = ast.ObjectTypeFunction 14130 } 14131 | "PROCEDURE" 14132 { 14133 $$ = ast.ObjectTypeProcedure 14134 } 14135 14136 PrivLevel: 14137 '*' 14138 { 14139 $$ = &ast.GrantLevel{ 14140 Level: ast.GrantLevelDB, 14141 } 14142 } 14143 | '*' '.' '*' 14144 { 14145 $$ = &ast.GrantLevel{ 14146 Level: ast.GrantLevelGlobal, 14147 } 14148 } 14149 | Identifier '.' '*' 14150 { 14151 $$ = &ast.GrantLevel{ 14152 Level: ast.GrantLevelDB, 14153 DBName: $1, 14154 } 14155 } 14156 | Identifier '.' Identifier 14157 { 14158 $$ = &ast.GrantLevel{ 14159 Level: ast.GrantLevelTable, 14160 DBName: $1, 14161 TableName: $3, 14162 } 14163 } 14164 | Identifier 14165 { 14166 $$ = &ast.GrantLevel{ 14167 Level: ast.GrantLevelTable, 14168 TableName: $1, 14169 } 14170 } 14171 14172 /**************************************RevokeStmt******************************************* 14173 * See https://dev.mysql.com/doc/refman/5.7/en/revoke.html 14174 *******************************************************************************************/ 14175 RevokeStmt: 14176 "REVOKE" RoleOrPrivElemList "ON" ObjectType PrivLevel "FROM" UserSpecList 14177 { 14178 p, err := convertToPriv($2.([]*ast.RoleOrPriv)) 14179 if err != nil { 14180 yylex.AppendError(err) 14181 return 1 14182 } 14183 $$ = &ast.RevokeStmt{ 14184 Privs: p, 14185 ObjectType: $4.(ast.ObjectTypeType), 14186 Level: $5.(*ast.GrantLevel), 14187 Users: $7.([]*ast.UserSpec), 14188 } 14189 } 14190 14191 RevokeRoleStmt: 14192 "REVOKE" RoleOrPrivElemList "FROM" UsernameList 14193 { 14194 // MySQL has special syntax for REVOKE ALL [PRIVILEGES], GRANT OPTION 14195 // which uses the RevokeRoleStmt syntax but is of type RevokeStmt. 14196 // It is documented at https://dev.mysql.com/doc/refman/5.7/en/revoke.html 14197 // as the "second syntax" for REVOKE. It is only valid if *both* 14198 // ALL PRIVILEGES + GRANT OPTION are specified in that order. 14199 if isRevokeAllGrant($2.([]*ast.RoleOrPriv)) { 14200 var users []*ast.UserSpec 14201 for _, u := range $4.([]*auth.UserIdentity) { 14202 users = append(users, &ast.UserSpec{ 14203 User: u, 14204 }) 14205 } 14206 $$ = &ast.RevokeStmt{ 14207 Privs: []*ast.PrivElem{{Priv: mysql.AllPriv}, {Priv: mysql.GrantPriv}}, 14208 ObjectType: ast.ObjectTypeNone, 14209 Level: &ast.GrantLevel{Level: ast.GrantLevelGlobal}, 14210 Users: users, 14211 } 14212 } else { 14213 r, err := convertToRole($2.([]*ast.RoleOrPriv)) 14214 if err != nil { 14215 yylex.AppendError(err) 14216 return 1 14217 } 14218 $$ = &ast.RevokeRoleStmt{ 14219 Roles: r, 14220 Users: $4.([]*auth.UserIdentity), 14221 } 14222 } 14223 } 14224 14225 /**************************************LoadDataStmt***************************************** 14226 * See https://dev.mysql.com/doc/refman/5.7/en/load-data.html 14227 * for load stmt with format see https://github.com/pingcap/tidb/issues/40499 14228 *******************************************************************************************/ 14229 LoadDataStmt: 14230 "LOAD" "DATA" LocalOpt "INFILE" stringLit FormatOpt DuplicateOpt "INTO" "TABLE" TableName CharsetOpt Fields Lines IgnoreLines ColumnNameOrUserVarListOptWithBrackets LoadDataSetSpecOpt LoadDataOptionListOpt 14231 { 14232 x := &ast.LoadDataStmt{ 14233 FileLocRef: ast.FileLocServerOrRemote, 14234 Path: $5, 14235 Format: $6.(*string), 14236 OnDuplicate: $7.(ast.OnDuplicateKeyHandlingType), 14237 Table: $10.(*ast.TableName), 14238 Charset: $11.(*string), 14239 FieldsInfo: $12.(*ast.FieldsClause), 14240 LinesInfo: $13.(*ast.LinesClause), 14241 IgnoreLines: $14.(*uint64), 14242 ColumnsAndUserVars: $15.([]*ast.ColumnNameOrUserVar), 14243 ColumnAssignments: $16.([]*ast.Assignment), 14244 Options: $17.([]*ast.LoadDataOpt), 14245 } 14246 if $3 != nil { 14247 x.FileLocRef = ast.FileLocClient 14248 // See https://dev.mysql.com/doc/refman/5.7/en/load-data.html#load-data-duplicate-key-handling 14249 // If you do not specify IGNORE or REPLACE modifier , then we set default behavior to IGNORE when LOCAL modifier is specified 14250 if x.OnDuplicate == ast.OnDuplicateKeyHandlingError { 14251 x.OnDuplicate = ast.OnDuplicateKeyHandlingIgnore 14252 } 14253 } 14254 columns := []*ast.ColumnName{} 14255 for _, v := range x.ColumnsAndUserVars { 14256 if v.ColumnName != nil { 14257 columns = append(columns, v.ColumnName) 14258 } 14259 } 14260 x.Columns = columns 14261 14262 $$ = x 14263 } 14264 14265 FormatOpt: 14266 { 14267 $$ = (*string)(nil) 14268 } 14269 | "FORMAT" stringLit 14270 { 14271 str := $2 14272 $$ = &str 14273 } 14274 14275 IgnoreLines: 14276 { 14277 $$ = (*uint64)(nil) 14278 } 14279 | "IGNORE" NUM "LINES" 14280 { 14281 v := getUint64FromNUM($2) 14282 $$ = &v 14283 } 14284 14285 CharsetOpt: 14286 { 14287 $$ = (*string)(nil) 14288 } 14289 | "CHARACTER" "SET" CharsetName 14290 { 14291 v := $3 14292 $$ = &v 14293 } 14294 14295 LocalOpt: 14296 { 14297 $$ = nil 14298 } 14299 | "LOCAL" 14300 { 14301 $$ = $1 14302 } 14303 14304 Fields: 14305 { 14306 $$ = (*ast.FieldsClause)(nil) 14307 } 14308 | FieldsOrColumns FieldItemList 14309 { 14310 fieldsClause := &ast.FieldsClause{} 14311 fieldItems := $2.([]*ast.FieldItem) 14312 for _, item := range fieldItems { 14313 switch item.Type { 14314 case ast.Terminated: 14315 fieldsClause.Terminated = &item.Value 14316 case ast.Enclosed: 14317 fieldsClause.Enclosed = &item.Value 14318 fieldsClause.OptEnclosed = item.OptEnclosed 14319 case ast.Escaped: 14320 fieldsClause.Escaped = &item.Value 14321 case ast.DefinedNullBy: 14322 fieldsClause.DefinedNullBy = &item.Value 14323 fieldsClause.NullValueOptEnclosed = item.OptEnclosed 14324 } 14325 } 14326 $$ = fieldsClause 14327 } 14328 14329 FieldsOrColumns: 14330 "FIELDS" 14331 | "COLUMNS" 14332 14333 FieldItemList: 14334 FieldItemList FieldItem 14335 { 14336 fieldItems := $1.([]*ast.FieldItem) 14337 $$ = append(fieldItems, $2.(*ast.FieldItem)) 14338 } 14339 | FieldItem 14340 { 14341 fieldItems := make([]*ast.FieldItem, 1, 1) 14342 fieldItems[0] = $1.(*ast.FieldItem) 14343 $$ = fieldItems 14344 } 14345 14346 FieldItem: 14347 "TERMINATED" "BY" FieldTerminator 14348 { 14349 $$ = &ast.FieldItem{ 14350 Type: ast.Terminated, 14351 Value: $3, 14352 } 14353 } 14354 | optionallyEnclosedBy FieldTerminator 14355 { 14356 str := $2 14357 if str != "\\" && len(str) > 1 { 14358 yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs()) 14359 return 1 14360 } 14361 $$ = &ast.FieldItem{ 14362 Type: ast.Enclosed, 14363 Value: str, 14364 OptEnclosed: true, 14365 } 14366 } 14367 | "ENCLOSED" "BY" FieldTerminator 14368 { 14369 str := $3 14370 if str != "\\" && len(str) > 1 { 14371 yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs()) 14372 return 1 14373 } 14374 $$ = &ast.FieldItem{ 14375 Type: ast.Enclosed, 14376 Value: str, 14377 } 14378 } 14379 | "ESCAPED" "BY" FieldTerminator 14380 { 14381 str := $3 14382 if str != "\\" && len(str) > 1 { 14383 yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs()) 14384 return 1 14385 } 14386 $$ = &ast.FieldItem{ 14387 Type: ast.Escaped, 14388 Value: str, 14389 } 14390 } 14391 | "DEFINED" "NULL" "BY" TextString 14392 { 14393 $$ = &ast.FieldItem{ 14394 Type: ast.DefinedNullBy, 14395 Value: $4.(*ast.TextString).Value, 14396 } 14397 } 14398 | "DEFINED" "NULL" "BY" TextString "OPTIONALLY" "ENCLOSED" 14399 { 14400 $$ = &ast.FieldItem{ 14401 Type: ast.DefinedNullBy, 14402 Value: $4.(*ast.TextString).Value, 14403 OptEnclosed: true, 14404 } 14405 } 14406 14407 FieldTerminator: 14408 stringLit 14409 | hexLit 14410 { 14411 $$ = $1.(ast.BinaryLiteral).ToString() 14412 } 14413 | bitLit 14414 { 14415 $$ = $1.(ast.BinaryLiteral).ToString() 14416 } 14417 14418 Lines: 14419 { 14420 $$ = (*ast.LinesClause)(nil) 14421 } 14422 | "LINES" Starting LinesTerminated 14423 { 14424 $$ = &ast.LinesClause{Starting: $2.(*string), Terminated: $3.(*string)} 14425 } 14426 14427 Starting: 14428 { 14429 $$ = (*string)(nil) 14430 } 14431 | "STARTING" "BY" FieldTerminator 14432 { 14433 s := $3 14434 $$ = &s 14435 } 14436 14437 LinesTerminated: 14438 { 14439 $$ = (*string)(nil) 14440 } 14441 | "TERMINATED" "BY" FieldTerminator 14442 { 14443 s := $3 14444 $$ = &s 14445 } 14446 14447 LoadDataSetSpecOpt: 14448 { 14449 $$ = ([]*ast.Assignment)(nil) 14450 } 14451 | "SET" LoadDataSetList 14452 { 14453 $$ = $2 14454 } 14455 14456 LoadDataSetList: 14457 LoadDataSetList ',' LoadDataSetItem 14458 { 14459 l := $1.([]*ast.Assignment) 14460 $$ = append(l, $3.(*ast.Assignment)) 14461 } 14462 | LoadDataSetItem 14463 { 14464 $$ = []*ast.Assignment{$1.(*ast.Assignment)} 14465 } 14466 14467 LoadDataSetItem: 14468 SimpleIdent "=" ExprOrDefault 14469 { 14470 $$ = &ast.Assignment{ 14471 Column: $1.(*ast.ColumnNameExpr).Name, 14472 Expr: $3, 14473 } 14474 } 14475 14476 LoadDataOptionListOpt: 14477 { 14478 $$ = []*ast.LoadDataOpt{} 14479 } 14480 | "WITH" LoadDataOptionList 14481 { 14482 $$ = $2.([]*ast.LoadDataOpt) 14483 } 14484 14485 LoadDataOptionList: 14486 LoadDataOption 14487 { 14488 $$ = []*ast.LoadDataOpt{$1.(*ast.LoadDataOpt)} 14489 } 14490 | LoadDataOptionList ',' LoadDataOption 14491 { 14492 $$ = append($1.([]*ast.LoadDataOpt), $3.(*ast.LoadDataOpt)) 14493 } 14494 14495 LoadDataOption: 14496 identifier 14497 { 14498 $$ = &ast.LoadDataOpt{Name: strings.ToLower($1)} 14499 } 14500 | identifier "=" SignedLiteral 14501 { 14502 $$ = &ast.LoadDataOpt{Name: strings.ToLower($1), Value: $3.(ast.ExprNode)} 14503 } 14504 14505 ImportIntoStmt: 14506 "IMPORT" "INTO" TableName ColumnNameOrUserVarListOptWithBrackets LoadDataSetSpecOpt "FROM" stringLit FormatOpt LoadDataOptionListOpt 14507 { 14508 $$ = &ast.ImportIntoStmt{ 14509 Table: $3.(*ast.TableName), 14510 ColumnsAndUserVars: $4.([]*ast.ColumnNameOrUserVar), 14511 ColumnAssignments: $5.([]*ast.Assignment), 14512 Path: $7, 14513 Format: $8.(*string), 14514 Options: $9.([]*ast.LoadDataOpt), 14515 } 14516 } 14517 14518 /********************************************************************* 14519 * Lock/Unlock Tables 14520 * See http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html 14521 * All the statement leaves empty. This is used to prevent mysqldump error. 14522 *********************************************************************/ 14523 UnlockTablesStmt: 14524 "UNLOCK" TablesTerminalSym 14525 { 14526 $$ = &ast.UnlockTablesStmt{} 14527 } 14528 14529 LockTablesStmt: 14530 "LOCK" TablesTerminalSym TableLockList 14531 { 14532 $$ = &ast.LockTablesStmt{ 14533 TableLocks: $3.([]ast.TableLock), 14534 } 14535 } 14536 14537 TablesTerminalSym: 14538 "TABLES" 14539 | "TABLE" 14540 14541 TableLock: 14542 TableName LockType 14543 { 14544 $$ = ast.TableLock{ 14545 Table: $1.(*ast.TableName), 14546 Type: $2.(model.TableLockType), 14547 } 14548 } 14549 14550 LockType: 14551 "READ" 14552 { 14553 $$ = model.TableLockRead 14554 } 14555 | "READ" "LOCAL" 14556 { 14557 $$ = model.TableLockReadLocal 14558 } 14559 | "WRITE" 14560 { 14561 $$ = model.TableLockWrite 14562 } 14563 | "WRITE" "LOCAL" 14564 { 14565 $$ = model.TableLockWriteLocal 14566 } 14567 14568 TableLockList: 14569 TableLock 14570 { 14571 $$ = []ast.TableLock{$1.(ast.TableLock)} 14572 } 14573 | TableLockList ',' TableLock 14574 { 14575 $$ = append($1.([]ast.TableLock), $3.(ast.TableLock)) 14576 } 14577 14578 /******************************************************************** 14579 * Non-transactional Delete Statement 14580 * Split a SQL on a column. Used for bulk delete that doesn't need ACID. 14581 *******************************************************************/ 14582 NonTransactionalDMLStmt: 14583 "BATCH" OptionalShardColumn "LIMIT" NUM DryRunOptions ShardableStmt 14584 { 14585 $$ = &ast.NonTransactionalDMLStmt{ 14586 DryRun: $5.(int), 14587 ShardColumn: $2.(*ast.ColumnName), 14588 Limit: getUint64FromNUM($4), 14589 DMLStmt: $6.(ast.ShardableDMLStmt), 14590 } 14591 } 14592 14593 ShardableStmt: 14594 DeleteFromStmt 14595 | UpdateStmt 14596 | InsertIntoStmt 14597 | ReplaceIntoStmt 14598 14599 DryRunOptions: 14600 { 14601 $$ = ast.NoDryRun 14602 } 14603 | "DRY" "RUN" 14604 { 14605 $$ = ast.DryRunSplitDml 14606 } 14607 | "DRY" "RUN" "QUERY" 14608 { 14609 $$ = ast.DryRunQuery 14610 } 14611 14612 OptionalShardColumn: 14613 { 14614 $$ = (*ast.ColumnName)(nil) 14615 } 14616 | "ON" ColumnName 14617 { 14618 $$ = $2.(*ast.ColumnName) 14619 } 14620 14621 /******************************************************************** 14622 * Kill Statement 14623 * See https://dev.mysql.com/doc/refman/5.7/en/kill.html 14624 *******************************************************************/ 14625 KillStmt: 14626 KillOrKillTiDB NUM 14627 { 14628 $$ = &ast.KillStmt{ 14629 ConnectionID: getUint64FromNUM($2), 14630 TiDBExtension: $1.(bool), 14631 } 14632 } 14633 | KillOrKillTiDB "CONNECTION" NUM 14634 { 14635 $$ = &ast.KillStmt{ 14636 ConnectionID: getUint64FromNUM($3), 14637 TiDBExtension: $1.(bool), 14638 } 14639 } 14640 | KillOrKillTiDB "QUERY" NUM 14641 { 14642 $$ = &ast.KillStmt{ 14643 ConnectionID: getUint64FromNUM($3), 14644 Query: true, 14645 TiDBExtension: $1.(bool), 14646 } 14647 } 14648 | KillOrKillTiDB BuiltinFunction 14649 { 14650 $$ = &ast.KillStmt{ 14651 TiDBExtension: $1.(bool), 14652 Expr: $2, 14653 } 14654 } 14655 14656 KillOrKillTiDB: 14657 "KILL" 14658 { 14659 $$ = false 14660 } 14661 /* KILL TIDB is a special grammar extension in TiDB, it can be used only when 14662 the client connect to TiDB directly, not proxied under LVS. */ 14663 | "KILL" "TIDB" 14664 { 14665 $$ = true 14666 } 14667 14668 LoadStatsStmt: 14669 "LOAD" "STATS" stringLit 14670 { 14671 $$ = &ast.LoadStatsStmt{ 14672 Path: $3, 14673 } 14674 } 14675 14676 LockStatsStmt: 14677 "LOCK" "STATS" TableNameList 14678 { 14679 $$ = &ast.LockStatsStmt{ 14680 Tables: $3.([]*ast.TableName), 14681 } 14682 } 14683 | "LOCK" "STATS" TableName "PARTITION" PartitionNameList 14684 { 14685 x := $3.(*ast.TableName) 14686 x.PartitionNames = $5.([]model.CIStr) 14687 $$ = &ast.LockStatsStmt{ 14688 Tables: []*ast.TableName{x}, 14689 } 14690 } 14691 | "LOCK" "STATS" TableName "PARTITION" '(' PartitionNameList ')' 14692 { 14693 x := $3.(*ast.TableName) 14694 x.PartitionNames = $6.([]model.CIStr) 14695 $$ = &ast.LockStatsStmt{ 14696 Tables: []*ast.TableName{x}, 14697 } 14698 } 14699 14700 UnlockStatsStmt: 14701 "UNLOCK" "STATS" TableNameList 14702 { 14703 $$ = &ast.UnlockStatsStmt{ 14704 Tables: $3.([]*ast.TableName), 14705 } 14706 } 14707 | "UNLOCK" "STATS" TableName "PARTITION" PartitionNameList 14708 { 14709 x := $3.(*ast.TableName) 14710 x.PartitionNames = $5.([]model.CIStr) 14711 $$ = &ast.UnlockStatsStmt{ 14712 Tables: []*ast.TableName{x}, 14713 } 14714 } 14715 | "UNLOCK" "STATS" TableName "PARTITION" '(' PartitionNameList ')' 14716 { 14717 x := $3.(*ast.TableName) 14718 x.PartitionNames = $6.([]model.CIStr) 14719 $$ = &ast.UnlockStatsStmt{ 14720 Tables: []*ast.TableName{x}, 14721 } 14722 } 14723 14724 DropPolicyStmt: 14725 "DROP" "PLACEMENT" "POLICY" IfExists PolicyName 14726 { 14727 $$ = &ast.DropPlacementPolicyStmt{ 14728 IfExists: $4.(bool), 14729 PolicyName: model.NewCIStr($5), 14730 } 14731 } 14732 14733 CreateResourceGroupStmt: 14734 "CREATE" "RESOURCE" "GROUP" IfNotExists ResourceGroupName ResourceGroupOptionList 14735 { 14736 $$ = &ast.CreateResourceGroupStmt{ 14737 IfNotExists: $4.(bool), 14738 ResourceGroupName: model.NewCIStr($5), 14739 ResourceGroupOptionList: $6.([]*ast.ResourceGroupOption), 14740 } 14741 } 14742 14743 AlterResourceGroupStmt: 14744 "ALTER" "RESOURCE" "GROUP" IfExists ResourceGroupName ResourceGroupOptionList 14745 { 14746 $$ = &ast.AlterResourceGroupStmt{ 14747 IfExists: $4.(bool), 14748 ResourceGroupName: model.NewCIStr($5), 14749 ResourceGroupOptionList: $6.([]*ast.ResourceGroupOption), 14750 } 14751 } 14752 14753 DropResourceGroupStmt: 14754 "DROP" "RESOURCE" "GROUP" IfExists ResourceGroupName 14755 { 14756 $$ = &ast.DropResourceGroupStmt{ 14757 IfExists: $4.(bool), 14758 ResourceGroupName: model.NewCIStr($5), 14759 } 14760 } 14761 14762 CreatePolicyStmt: 14763 "CREATE" OrReplace "PLACEMENT" "POLICY" IfNotExists PolicyName PlacementOptionList 14764 { 14765 $$ = &ast.CreatePlacementPolicyStmt{ 14766 OrReplace: $2.(bool), 14767 IfNotExists: $5.(bool), 14768 PolicyName: model.NewCIStr($6), 14769 PlacementOptions: $7.([]*ast.PlacementOption), 14770 } 14771 } 14772 14773 AlterPolicyStmt: 14774 "ALTER" "PLACEMENT" "POLICY" IfExists PolicyName PlacementOptionList 14775 { 14776 $$ = &ast.AlterPlacementPolicyStmt{ 14777 IfExists: $4.(bool), 14778 PolicyName: model.NewCIStr($5), 14779 PlacementOptions: $6.([]*ast.PlacementOption), 14780 } 14781 } 14782 14783 /******************************************************************************************** 14784 * 14785 * Create Sequence Statement 14786 * 14787 * Example: 14788 * CREATE [TEMPORARY] SEQUENCE [IF NOT EXISTS] sequence_name 14789 * [ INCREMENT [ BY | = ] increment ] 14790 * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ] 14791 * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ] 14792 * [ START [ WITH | = ] start ] 14793 * [ CACHE [=] cache | NOCACHE | NO CACHE] 14794 * [ CYCLE | NOCYCLE | NO CYCLE] 14795 * [table_options] 14796 ********************************************************************************************/ 14797 CreateSequenceStmt: 14798 "CREATE" "SEQUENCE" IfNotExists TableName CreateSequenceOptionListOpt CreateTableOptionListOpt 14799 { 14800 $$ = &ast.CreateSequenceStmt{ 14801 IfNotExists: $3.(bool), 14802 Name: $4.(*ast.TableName), 14803 SeqOptions: $5.([]*ast.SequenceOption), 14804 TblOptions: $6.([]*ast.TableOption), 14805 } 14806 } 14807 14808 CreateSequenceOptionListOpt: 14809 { 14810 $$ = []*ast.SequenceOption{} 14811 } 14812 | SequenceOptionList 14813 14814 SequenceOptionList: 14815 SequenceOption 14816 { 14817 $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)} 14818 } 14819 | SequenceOptionList SequenceOption 14820 { 14821 $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption)) 14822 } 14823 14824 SequenceOption: 14825 "INCREMENT" EqOpt SignedNum 14826 { 14827 $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)} 14828 } 14829 | "INCREMENT" "BY" SignedNum 14830 { 14831 $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)} 14832 } 14833 | "START" EqOpt SignedNum 14834 { 14835 $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)} 14836 } 14837 | "START" "WITH" SignedNum 14838 { 14839 $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)} 14840 } 14841 | "MINVALUE" EqOpt SignedNum 14842 { 14843 $$ = &ast.SequenceOption{Tp: ast.SequenceMinValue, IntValue: $3.(int64)} 14844 } 14845 | "NOMINVALUE" 14846 { 14847 $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue} 14848 } 14849 | "NO" "MINVALUE" 14850 { 14851 $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue} 14852 } 14853 | "MAXVALUE" EqOpt SignedNum 14854 { 14855 $$ = &ast.SequenceOption{Tp: ast.SequenceMaxValue, IntValue: $3.(int64)} 14856 } 14857 | "NOMAXVALUE" 14858 { 14859 $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue} 14860 } 14861 | "NO" "MAXVALUE" 14862 { 14863 $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue} 14864 } 14865 | "CACHE" EqOpt SignedNum 14866 { 14867 $$ = &ast.SequenceOption{Tp: ast.SequenceCache, IntValue: $3.(int64)} 14868 } 14869 | "NOCACHE" 14870 { 14871 $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache} 14872 } 14873 | "NO" "CACHE" 14874 { 14875 $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache} 14876 } 14877 | "CYCLE" 14878 { 14879 $$ = &ast.SequenceOption{Tp: ast.SequenceCycle} 14880 } 14881 | "NOCYCLE" 14882 { 14883 $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle} 14884 } 14885 | "NO" "CYCLE" 14886 { 14887 $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle} 14888 } 14889 14890 SignedNum: 14891 Int64Num 14892 | '+' Int64Num 14893 { 14894 $$ = $2 14895 } 14896 | '-' NUM 14897 { 14898 unsigned_num := getUint64FromNUM($2) 14899 if unsigned_num > 9223372036854775808 { 14900 yylex.AppendError(yylex.Errorf("the Signed Value should be at the range of [-9223372036854775808, 9223372036854775807].")) 14901 return 1 14902 } else if unsigned_num == 9223372036854775808 { 14903 signed_one := int64(1) 14904 $$ = signed_one << 63 14905 } else { 14906 $$ = -int64(unsigned_num) 14907 } 14908 } 14909 14910 DropSequenceStmt: 14911 "DROP" "SEQUENCE" IfExists TableNameList 14912 { 14913 $$ = &ast.DropSequenceStmt{ 14914 IfExists: $3.(bool), 14915 Sequences: $4.([]*ast.TableName), 14916 } 14917 } 14918 14919 /******************************************************************************************** 14920 * 14921 * Alter Sequence Statement 14922 * 14923 * Example: 14924 * ALTER SEQUENCE [IF EXISTS] sequence_name 14925 * [ INCREMENT [ BY | = ] increment ] 14926 * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ] 14927 * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ] 14928 * [ START [ WITH | = ] start ] 14929 * [ CACHE [=] cache | NOCACHE | NO CACHE] 14930 * [ CYCLE | NOCYCLE | NO CYCLE] 14931 * [ RESTART [WITH | = ] restart ] 14932 ********************************************************************************************/ 14933 AlterSequenceStmt: 14934 "ALTER" "SEQUENCE" IfExists TableName AlterSequenceOptionList 14935 { 14936 $$ = &ast.AlterSequenceStmt{ 14937 IfExists: $3.(bool), 14938 Name: $4.(*ast.TableName), 14939 SeqOptions: $5.([]*ast.SequenceOption), 14940 } 14941 } 14942 14943 AlterSequenceOptionList: 14944 AlterSequenceOption 14945 { 14946 $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)} 14947 } 14948 | AlterSequenceOptionList AlterSequenceOption 14949 { 14950 $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption)) 14951 } 14952 14953 AlterSequenceOption: 14954 SequenceOption 14955 | "RESTART" 14956 { 14957 $$ = &ast.SequenceOption{Tp: ast.SequenceRestart} 14958 } 14959 | "RESTART" EqOpt SignedNum 14960 { 14961 $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)} 14962 } 14963 | "RESTART" "WITH" SignedNum 14964 { 14965 $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)} 14966 } 14967 14968 /******************************************************************** 14969 * Index Advisor Statement 14970 * 14971 * INDEX ADVISE 14972 * [LOCAL] 14973 * INFILE 'file_name' 14974 * [MAX_MINUTES number] 14975 * [MAX_IDXNUM 14976 * [PER_TABLE number] 14977 * [PER_DB number] 14978 * ] 14979 * [LINES 14980 * [STARTING BY 'string'] 14981 * [TERMINATED BY 'string'] 14982 * ] 14983 *******************************************************************/ 14984 IndexAdviseStmt: 14985 "INDEX" "ADVISE" LocalOpt "INFILE" stringLit MaxMinutesOpt MaxIndexNumOpt Lines 14986 { 14987 x := &ast.IndexAdviseStmt{ 14988 Path: $5, 14989 MaxMinutes: $6.(uint64), 14990 } 14991 if $3 != nil { 14992 x.IsLocal = true 14993 } 14994 if $7 != nil { 14995 x.MaxIndexNum = $7.(*ast.MaxIndexNumClause) 14996 } 14997 if $8 != nil { 14998 x.LinesInfo = $8.(*ast.LinesClause) 14999 } 15000 $$ = x 15001 } 15002 15003 MaxMinutesOpt: 15004 { 15005 $$ = uint64(ast.UnspecifiedSize) 15006 } 15007 | "MAX_MINUTES" NUM 15008 { 15009 $$ = getUint64FromNUM($2) 15010 } 15011 15012 MaxIndexNumOpt: 15013 { 15014 $$ = nil 15015 } 15016 | "MAX_IDXNUM" PerTable PerDB 15017 { 15018 $$ = &ast.MaxIndexNumClause{ 15019 PerTable: $2.(uint64), 15020 PerDB: $3.(uint64), 15021 } 15022 } 15023 15024 PerTable: 15025 { 15026 $$ = uint64(ast.UnspecifiedSize) 15027 } 15028 | "PER_TABLE" NUM 15029 { 15030 $$ = getUint64FromNUM($2) 15031 } 15032 15033 PerDB: 15034 { 15035 $$ = uint64(ast.UnspecifiedSize) 15036 } 15037 | "PER_DB" NUM 15038 { 15039 $$ = getUint64FromNUM($2) 15040 } 15041 15042 EncryptionOpt: 15043 stringLit 15044 { 15045 // Parse it but will ignore it 15046 switch $1 { 15047 case "Y", "y": 15048 yylex.AppendError(yylex.Errorf("The ENCRYPTION clause is parsed but ignored by all storage engines.")) 15049 parser.lastErrorAsWarn() 15050 case "N", "n": 15051 break 15052 default: 15053 yylex.AppendError(ErrWrongValue.GenWithStackByArgs("argument (should be Y or N)", $1)) 15054 return 1 15055 } 15056 $$ = $1 15057 } 15058 15059 ValuesStmtList: 15060 RowStmt 15061 { 15062 $$ = append([]*ast.RowExpr{}, $1.(*ast.RowExpr)) 15063 } 15064 | ValuesStmtList ',' RowStmt 15065 { 15066 $$ = append($1.([]*ast.RowExpr), $3.(*ast.RowExpr)) 15067 } 15068 15069 RowStmt: 15070 "ROW" RowValue 15071 { 15072 $$ = &ast.RowExpr{Values: $2.([]ast.ExprNode)} 15073 } 15074 15075 /******************************************************************** 15076 * 15077 * Plan Replayer Statement 15078 * 15079 * PLAN REPLAYER 15080 * [DUMP EXPLAIN 15081 * [ANALYZE] 15082 * {ExplainableStmt 15083 * | [WHERE where_condition] 15084 * [ORDER BY {col_name | expr | position} 15085 * [ASC | DESC], ... [WITH ROLLUP]] 15086 * [LIMIT {[offset,] row_count | row_count OFFSET offset}]} 15087 * | 'file_name' 15088 * | LOAD 'file_name' 15089 * | CAPTURE `sql_digest` `plan_digest`] 15090 *******************************************************************/ 15091 PlanReplayerStmt: 15092 "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" ExplainableStmt 15093 { 15094 x := &ast.PlanReplayerStmt{ 15095 Stmt: $6, 15096 Analyze: false, 15097 Load: false, 15098 File: "", 15099 Where: nil, 15100 OrderBy: nil, 15101 Limit: nil, 15102 } 15103 if $4 != nil { 15104 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15105 } 15106 startOffset := parser.startOffset(&yyS[yypt]) 15107 x.Stmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 15108 15109 $$ = x 15110 } 15111 | "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" "ANALYZE" ExplainableStmt 15112 { 15113 x := &ast.PlanReplayerStmt{ 15114 Stmt: $7, 15115 Analyze: true, 15116 Load: false, 15117 File: "", 15118 Where: nil, 15119 OrderBy: nil, 15120 Limit: nil, 15121 } 15122 if $4 != nil { 15123 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15124 } 15125 startOffset := parser.startOffset(&yyS[yypt]) 15126 x.Stmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:])) 15127 15128 $$ = x 15129 } 15130 | "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" "SLOW" "QUERY" WhereClauseOptional OrderByOptional SelectStmtLimitOpt 15131 { 15132 x := &ast.PlanReplayerStmt{ 15133 Stmt: nil, 15134 Analyze: false, 15135 Load: false, 15136 File: "", 15137 } 15138 if $4 != nil { 15139 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15140 } 15141 if $8 != nil { 15142 x.Where = $8.(ast.ExprNode) 15143 } 15144 if $9 != nil { 15145 x.OrderBy = $9.(*ast.OrderByClause) 15146 } 15147 if $10 != nil { 15148 x.Limit = $10.(*ast.Limit) 15149 } 15150 15151 $$ = x 15152 } 15153 | "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" "ANALYZE" "SLOW" "QUERY" WhereClauseOptional OrderByOptional SelectStmtLimitOpt 15154 { 15155 x := &ast.PlanReplayerStmt{ 15156 Stmt: nil, 15157 Analyze: true, 15158 Load: false, 15159 File: "", 15160 } 15161 if $4 != nil { 15162 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15163 } 15164 if $9 != nil { 15165 x.Where = $9.(ast.ExprNode) 15166 } 15167 if $10 != nil { 15168 x.OrderBy = $10.(*ast.OrderByClause) 15169 } 15170 if $11 != nil { 15171 x.Limit = $11.(*ast.Limit) 15172 } 15173 15174 $$ = x 15175 } 15176 | "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" stringLit 15177 { 15178 x := &ast.PlanReplayerStmt{ 15179 Stmt: nil, 15180 Analyze: false, 15181 Load: false, 15182 File: $6, 15183 } 15184 if $4 != nil { 15185 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15186 } 15187 $$ = x 15188 } 15189 | "PLAN" "REPLAYER" "DUMP" PlanReplayerDumpOpt "EXPLAIN" "ANALYZE" stringLit 15190 { 15191 x := &ast.PlanReplayerStmt{ 15192 Stmt: nil, 15193 Analyze: true, 15194 Load: false, 15195 File: $7, 15196 } 15197 if $4 != nil { 15198 x.HistoricalStatsInfo = $4.(*ast.AsOfClause) 15199 } 15200 $$ = x 15201 } 15202 | "PLAN" "REPLAYER" "LOAD" stringLit 15203 { 15204 x := &ast.PlanReplayerStmt{ 15205 Stmt: nil, 15206 Analyze: false, 15207 Load: true, 15208 File: $4, 15209 Where: nil, 15210 OrderBy: nil, 15211 Limit: nil, 15212 } 15213 15214 $$ = x 15215 } 15216 | "PLAN" "REPLAYER" "CAPTURE" stringLit stringLit 15217 { 15218 x := &ast.PlanReplayerStmt{ 15219 Stmt: nil, 15220 Analyze: false, 15221 Capture: true, 15222 SQLDigest: $4, 15223 PlanDigest: $5, 15224 Where: nil, 15225 OrderBy: nil, 15226 Limit: nil, 15227 } 15228 15229 $$ = x 15230 } 15231 | "PLAN" "REPLAYER" "CAPTURE" "REMOVE" stringLit stringLit 15232 { 15233 x := &ast.PlanReplayerStmt{ 15234 Stmt: nil, 15235 Analyze: false, 15236 Remove: true, 15237 SQLDigest: $5, 15238 PlanDigest: $6, 15239 Where: nil, 15240 OrderBy: nil, 15241 Limit: nil, 15242 } 15243 15244 $$ = x 15245 } 15246 15247 PlanReplayerDumpOpt: 15248 { 15249 $$ = nil 15250 } 15251 | "WITH" "STATS" AsOfClause 15252 { 15253 $$ = $3.(*ast.AsOfClause) 15254 } 15255 15256 /* Stored PROCEDURE parameter declaration list */ 15257 OptSpPdparams: 15258 /* Empty */ 15259 { 15260 $$ = []*ast.StoreParameter{} 15261 } 15262 | SpPdparams 15263 { 15264 $$ = $1 15265 } 15266 15267 SpPdparams: 15268 SpPdparams ',' SpPdparam 15269 { 15270 l := $1.([]*ast.StoreParameter) 15271 l = append(l, $3.(*ast.StoreParameter)) 15272 $$ = l 15273 } 15274 | SpPdparam 15275 { 15276 $$ = []*ast.StoreParameter{$1.(*ast.StoreParameter)} 15277 } 15278 15279 SpPdparam: 15280 SpOptInout Identifier Type 15281 { 15282 x := &ast.StoreParameter{ 15283 Paramstatus: $1.(int), 15284 ParamType: $3.(*types.FieldType), 15285 ParamName: $2, 15286 } 15287 $$ = x 15288 } 15289 15290 SpOptInout: 15291 /* Empty */ 15292 { 15293 $$ = ast.MODE_IN 15294 } 15295 | "IN" 15296 { 15297 $$ = ast.MODE_IN 15298 } 15299 | "OUT" 15300 { 15301 $$ = ast.MODE_OUT 15302 } 15303 | "INOUT" 15304 { 15305 $$ = ast.MODE_INOUT 15306 } 15307 15308 ProcedureStatementStmt: 15309 SelectStmt 15310 | SelectStmtWithClause 15311 | SubSelect 15312 { 15313 var sel ast.StmtNode 15314 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 15315 case *ast.SelectStmt: 15316 x.IsInBraces = true 15317 sel = x 15318 case *ast.SetOprStmt: 15319 x.IsInBraces = true 15320 sel = x 15321 } 15322 $$ = sel 15323 } 15324 | SetStmt 15325 | UpdateStmt 15326 | UseStmt 15327 | InsertIntoStmt 15328 | ReplaceIntoStmt 15329 | CommitStmt 15330 | RollbackStmt 15331 | ExplainStmt 15332 | SetOprStmt 15333 | DeleteFromStmt 15334 | AnalyzeTableStmt 15335 | TruncateTableStmt 15336 15337 ProcedureCursorSelectStmt: 15338 SelectStmt 15339 | SelectStmtWithClause 15340 | SubSelect 15341 { 15342 var sel ast.StmtNode 15343 switch x := $1.(*ast.SubqueryExpr).Query.(type) { 15344 case *ast.SelectStmt: 15345 x.IsInBraces = true 15346 sel = x 15347 case *ast.SetOprStmt: 15348 x.IsInBraces = true 15349 sel = x 15350 } 15351 $$ = sel 15352 } 15353 | SetOprStmt 15354 15355 ProcedureUnlabeledBlock: 15356 ProcedureBlockContent 15357 { 15358 $$ = $1 15359 } 15360 15361 ProcedureDeclIdents: 15362 Identifier 15363 { 15364 $$ = []string{strings.ToLower($1)} 15365 } 15366 | ProcedureDeclIdents ',' Identifier 15367 { 15368 l := $1.([]string) 15369 l = append(l, strings.ToLower($3)) 15370 $$ = l 15371 } 15372 15373 ProcedureOptDefault: 15374 /* Empty */ 15375 { 15376 $$ = nil 15377 } 15378 | "DEFAULT" Expression 15379 { 15380 $$ = $2 15381 } 15382 15383 ProcedureDecl: 15384 "DECLARE" ProcedureDeclIdents Type ProcedureOptDefault 15385 { 15386 x := &ast.ProcedureDecl{ 15387 DeclNames: $2.([]string), 15388 DeclType: $3.(*types.FieldType), 15389 } 15390 if $4 != nil { 15391 x.DeclDefault = $4.(ast.ExprNode) 15392 } 15393 $$ = x 15394 } 15395 | "DECLARE" identifier "CURSOR" "FOR" ProcedureCursorSelectStmt 15396 { 15397 name := strings.ToLower($2) 15398 $$ = &ast.ProcedureCursor{ 15399 CurName: name, 15400 Selectstring: $5.(ast.StmtNode), 15401 } 15402 } 15403 | "DECLARE" ProcedureHandlerType "HANDLER" "FOR" ProcedureHcondList ProcedureProcStmt 15404 { 15405 $$ = &ast.ProcedureErrorControl{ 15406 ControlHandle: $2.(int), 15407 ErrorCon: $5.([]ast.ErrNode), 15408 Operate: $6.(ast.StmtNode), 15409 } 15410 } 15411 15412 ProcedureHandlerType: 15413 "CONTINUE" 15414 { 15415 $$ = ast.PROCEDUR_CONTINUE 15416 } 15417 | "EXIT" 15418 { 15419 $$ = ast.PROCEDUR_EXIT 15420 } 15421 15422 ProcedureHcondList: 15423 ProcedureHcond 15424 { 15425 $$ = []ast.ErrNode{$1.(ast.ErrNode)} 15426 } 15427 | ProcedureHcondList ',' ProcedureHcond 15428 { 15429 l := $1.([]ast.ErrNode) 15430 l = append(l, $3.(ast.ErrNode)) 15431 $$ = l 15432 } 15433 15434 ProcedureHcond: 15435 ProcedurceCond 15436 { 15437 $$ = $1.(ast.ErrNode) 15438 } 15439 | "SQLWARNING" 15440 /* SQLSTATEs 01??? */ 15441 { 15442 $$ = &ast.ProcedureErrorCon{ 15443 ErrorCon: ast.PROCEDUR_SQLWARNING, 15444 } 15445 } 15446 | "NOT" "FOUND" 15447 /* SQLSTATEs 02??? */ 15448 { 15449 $$ = &ast.ProcedureErrorCon{ 15450 ErrorCon: ast.PROCEDUR_NOT_FOUND, 15451 } 15452 } 15453 | "SQLEXCEPTION" 15454 /* All other SQLSTATEs */ 15455 { 15456 $$ = &ast.ProcedureErrorCon{ 15457 ErrorCon: ast.PROCEDUR_SQLEXCEPTION, 15458 } 15459 } 15460 15461 ProcedurceCond: 15462 NUM 15463 { 15464 $$ = &ast.ProcedureErrorVal{ 15465 ErrorNum: getUint64FromNUM($1), 15466 } 15467 } 15468 | "SQLSTATE" optValue stringLit 15469 { 15470 $$ = &ast.ProcedureErrorState{ 15471 CodeStatus: $3, 15472 } 15473 } 15474 15475 optValue: 15476 {} 15477 | "VALUE" 15478 15479 ProcedureOpenCur: 15480 "OPEN" identifier 15481 { 15482 name := strings.ToLower($2) 15483 $$ = &ast.ProcedureOpenCur{ 15484 CurName: name, 15485 } 15486 } 15487 15488 ProcedureFetchInto: 15489 "FETCH" ProcedureOptFetchNo identifier "INTO" ProcedureFetchList 15490 { 15491 name := strings.ToLower($3) 15492 $$ = &ast.ProcedureFetchInto{ 15493 CurName: name, 15494 Variables: $5.([]string), 15495 } 15496 } 15497 15498 ProcedureCloseCur: 15499 "CLOSE" identifier 15500 { 15501 name := strings.ToLower($2) 15502 $$ = &ast.ProcedureCloseCur{ 15503 CurName: name, 15504 } 15505 } 15506 15507 ProcedureOptFetchNo: 15508 15509 /* Empty */ 15510 | "NEXT" "FROM" 15511 | "FROM" 15512 15513 ProcedureFetchList: 15514 identifier 15515 { 15516 $$ = []string{strings.ToLower($1)} 15517 } 15518 | ProcedureFetchList ',' identifier 15519 { 15520 l := $1.([]string) 15521 l = append(l, strings.ToLower($3)) 15522 $$ = l 15523 } 15524 15525 ProcedureDeclsOpt: 15526 /* Empty */ 15527 { 15528 $$ = []ast.DeclNode{} 15529 } 15530 | ProcedureDecls 15531 { 15532 $$ = $1 15533 } 15534 15535 ProcedureDecls: 15536 ProcedureDecl ';' 15537 { 15538 $$ = []ast.DeclNode{$1.(ast.DeclNode)} 15539 } 15540 | ProcedureDecls ProcedureDecl ';' 15541 { 15542 l := $1.([]ast.DeclNode) 15543 l = append(l, $2.(ast.DeclNode)) 15544 $$ = l 15545 } 15546 15547 ProcedureProcStmts: 15548 /* Empty */ 15549 { 15550 $$ = []ast.StmtNode{} 15551 } 15552 | ProcedureProcStmts ProcedureProcStmt ';' 15553 { 15554 l := $1.([]ast.StmtNode) 15555 l = append(l, $2.(ast.StmtNode)) 15556 $$ = l 15557 } 15558 15559 ProcedureProcStmt1s: 15560 ProcedureProcStmt ';' 15561 { 15562 $$ = []ast.StmtNode{$1.(ast.StmtNode)} 15563 } 15564 | ProcedureProcStmt1s ProcedureProcStmt ';' 15565 { 15566 l := $1.([]ast.StmtNode) 15567 l = append(l, $2.(ast.StmtNode)) 15568 $$ = l 15569 } 15570 15571 ProcedureBlockContent: 15572 "BEGIN" ProcedureDeclsOpt ProcedureProcStmts "END" 15573 { 15574 x := &ast.ProcedureBlock{ 15575 ProcedureVars: $2.([]ast.DeclNode), 15576 ProcedureProcStmts: $3.([]ast.StmtNode), 15577 } 15578 $$ = x 15579 } 15580 15581 ProcedureIfstmt: 15582 "IF" ProcedureIf "END" "IF" 15583 { 15584 $$ = &ast.ProcedureIfInfo{ 15585 IfBody: $2.(*ast.ProcedureIfBlock), 15586 } 15587 } 15588 15589 ProcedureIf: 15590 Expression "THEN" ProcedureProcStmt1s procedurceElseIfs 15591 { 15592 ifBlock := &ast.ProcedureIfBlock{ 15593 IfExpr: $1.(ast.ExprNode), 15594 ProcedureIfStmts: $3.([]ast.StmtNode), 15595 } 15596 if $4 != nil { 15597 ifBlock.ProcedureElseStmt = $4.(ast.StmtNode) 15598 } 15599 $$ = ifBlock 15600 } 15601 15602 procedurceElseIfs: 15603 { 15604 $$ = nil 15605 } 15606 | "ELSEIF" ProcedureIf 15607 { 15608 $$ = &ast.ProcedureElseIfBlock{ 15609 ProcedureIfStmt: $2.(*ast.ProcedureIfBlock), 15610 } 15611 } 15612 | "ELSE" ProcedureProcStmt1s 15613 { 15614 $$ = &ast.ProcedureElseBlock{ 15615 ProcedureIfStmts: $2.([]ast.StmtNode), 15616 } 15617 } 15618 15619 ProcedureCaseStmt: 15620 ProcedureSimpleCase 15621 { 15622 $$ = $1 15623 } 15624 | ProcedureSearchedCase 15625 { 15626 $$ = $1 15627 } 15628 15629 SimpleWhenThenList: 15630 SimpleWhenThen 15631 { 15632 $$ = []*ast.SimpleWhenThenStmt{$1.(*ast.SimpleWhenThenStmt)} 15633 } 15634 | SimpleWhenThenList SimpleWhenThen 15635 { 15636 l := $1.([]*ast.SimpleWhenThenStmt) 15637 l = append(l, $2.(*ast.SimpleWhenThenStmt)) 15638 $$ = l 15639 } 15640 15641 SearchedWhenThenList: 15642 SearchWhenThen 15643 { 15644 $$ = []*ast.SearchWhenThenStmt{$1.(*ast.SearchWhenThenStmt)} 15645 } 15646 | SearchedWhenThenList SearchWhenThen 15647 { 15648 l := $1.([]*ast.SearchWhenThenStmt) 15649 l = append(l, $2.(*ast.SearchWhenThenStmt)) 15650 $$ = l 15651 } 15652 15653 SimpleWhenThen: 15654 "WHEN" Expression "THEN" ProcedureProcStmt1s 15655 { 15656 $$ = &ast.SimpleWhenThenStmt{ 15657 Expr: $2.(ast.ExprNode), 15658 ProcedureStmts: $4.([]ast.StmtNode), 15659 } 15660 } 15661 15662 SearchWhenThen: 15663 "WHEN" Expression "THEN" ProcedureProcStmt1s 15664 { 15665 $$ = &ast.SearchWhenThenStmt{ 15666 Expr: $2.(ast.ExprNode), 15667 ProcedureStmts: $4.([]ast.StmtNode), 15668 } 15669 } 15670 15671 ElseCaseOpt: 15672 { 15673 $$ = nil 15674 } 15675 | "ELSE" ProcedureProcStmt1s 15676 { 15677 $$ = $2.([]ast.StmtNode) 15678 } 15679 15680 ProcedureSimpleCase: 15681 "CASE" Expression SimpleWhenThenList ElseCaseOpt "END" "CASE" 15682 { 15683 caseStmt := &ast.SimpleCaseStmt{ 15684 Condition: $2.(ast.ExprNode), 15685 WhenCases: $3.([]*ast.SimpleWhenThenStmt), 15686 } 15687 if $4 != nil { 15688 caseStmt.ElseCases = $4.([]ast.StmtNode) 15689 } 15690 $$ = caseStmt 15691 } 15692 15693 ProcedureSearchedCase: 15694 "CASE" SearchedWhenThenList ElseCaseOpt "END" "CASE" 15695 { 15696 caseStmt := &ast.SearchCaseStmt{ 15697 WhenCases: $2.([]*ast.SearchWhenThenStmt), 15698 } 15699 if $3 != nil { 15700 caseStmt.ElseCases = $3.([]ast.StmtNode) 15701 } 15702 $$ = caseStmt 15703 } 15704 15705 ProcedureUnlabelLoopBlock: 15706 ProcedureUnlabelLoopStmt 15707 { 15708 $$ = $1 15709 } 15710 15711 ProcedureUnlabelLoopStmt: 15712 "WHILE" Expression "DO" ProcedureProcStmt1s "END" "WHILE" 15713 { 15714 $$ = &ast.ProcedureWhileStmt{ 15715 Condition: $2.(ast.ExprNode), 15716 Body: $4.([]ast.StmtNode), 15717 } 15718 } 15719 | "REPEAT" ProcedureProcStmt1s "UNTIL" Expression "END" "REPEAT" 15720 { 15721 $$ = &ast.ProcedureRepeatStmt{ 15722 Body: $2.([]ast.StmtNode), 15723 Condition: $4.(ast.ExprNode), 15724 } 15725 } 15726 15727 ProcedureLabeledBlock: 15728 identifier ':' ProcedureBlockContent ProcedurceLabelOpt 15729 { 15730 labelBlock := &ast.ProcedureLabelBlock{ 15731 LabelName: $1, 15732 Block: $3.(*ast.ProcedureBlock), 15733 } 15734 if $4 != "" && ($1 != $4) { 15735 labelBlock.LabelError = true 15736 labelBlock.LabelEnd = $4 15737 } 15738 $$ = labelBlock 15739 } 15740 15741 ProcedurceLabelOpt: 15742 /* Empty */ 15743 { 15744 $$ = "" 15745 } 15746 | identifier 15747 { 15748 $$ = $1 15749 } 15750 15751 ProcedurelabeledLoopStmt: 15752 identifier ':' ProcedureUnlabelLoopStmt ProcedurceLabelOpt 15753 { 15754 labelLoop := &ast.ProcedureLabelLoop{ 15755 LabelName: $1, 15756 Block: $3.(ast.StmtNode), 15757 } 15758 if $4 != "" && ($1 != $4) { 15759 labelLoop.LabelError = true 15760 labelLoop.LabelEnd = $4 15761 } 15762 $$ = labelLoop 15763 } 15764 15765 ProcedureIterate: 15766 "ITERATE" identifier 15767 { 15768 $$ = &ast.ProcedureJump{ 15769 Name: $2, 15770 IsLeave: false, 15771 } 15772 } 15773 15774 ProcedureLeave: 15775 "LEAVE" identifier 15776 { 15777 $$ = &ast.ProcedureJump{ 15778 Name: $2, 15779 IsLeave: true, 15780 } 15781 } 15782 15783 ProcedureProcStmt: 15784 ProcedureStatementStmt 15785 | ProcedureUnlabeledBlock 15786 | ProcedureIfstmt 15787 | ProcedureCaseStmt 15788 | ProcedureUnlabelLoopBlock 15789 | ProcedureOpenCur 15790 | ProcedureCloseCur 15791 | ProcedureFetchInto 15792 | ProcedureLabeledBlock 15793 | ProcedurelabeledLoopStmt 15794 | ProcedureIterate 15795 | ProcedureLeave 15796 15797 /******************************************************************************************** 15798 * 15799 * Create Procedure Statement 15800 * 15801 * Example: 15802 * CREATE 15803 * [DEFINER = user] 15804 * PROCEDURE [IF NOT EXISTS] sp_name ([proc_parameter[,...]]) 15805 * routine_body 15806 * proc_parameter: 15807 * [ IN | OUT | INOUT ] param_name type 15808 * func_parameter: 15809 * param_name type 15810 * type: 15811 * Any valid MySQL data type 15812 * routine_body: 15813 * Valid SQL routine statement 15814 ********************************************************************************************/ 15815 CreateProcedureStmt: 15816 "CREATE" "PROCEDURE" IfNotExists TableName '(' OptSpPdparams ')' ProcedureProcStmt 15817 { 15818 x := &ast.ProcedureInfo{ 15819 IfNotExists: $3.(bool), 15820 ProcedureName: $4.(*ast.TableName), 15821 ProcedureParam: $6.([]*ast.StoreParameter), 15822 ProcedureBody: $8, 15823 } 15824 startOffset := parser.startOffset(&yyS[yypt]) 15825 originStmt := $8 15826 originStmt.SetText(parser.lexer.client, strings.TrimSpace(parser.src[startOffset:parser.yylval.offset])) 15827 startOffset = parser.startOffset(&yyS[yypt-3]) 15828 if parser.src[startOffset] == '(' { 15829 startOffset++ 15830 } 15831 endOffset := parser.startOffset(&yyS[yypt-1]) 15832 x.ProcedureParamStr = strings.TrimSpace(parser.src[startOffset:endOffset]) 15833 $$ = x 15834 } 15835 15836 /******************************************************************************************** 15837 * DROP PROCEDURE [IF EXISTS] sp_name 15838 ********************************************************************************************/ 15839 DropProcedureStmt: 15840 "DROP" "PROCEDURE" IfExists TableName 15841 { 15842 $$ = &ast.DropProcedureStmt{ 15843 IfExists: $3.(bool), 15844 ProcedureName: $4.(*ast.TableName), 15845 } 15846 } 15847 15848 /******************************************************************** 15849 * 15850 * Calibrate Resource Statement 15851 * 15852 * CALIBRATE RESOURCE 15853 *******************************************************************/ 15854 CalibrateResourceStmt: 15855 "CALIBRATE" "RESOURCE" CalibrateOption 15856 { 15857 $$ = $3.(*ast.CalibrateResourceStmt) 15858 } 15859 15860 CalibrateOption: 15861 { 15862 $$ = &ast.CalibrateResourceStmt{} 15863 } 15864 | DynamicCalibrateOptionList 15865 { 15866 $$ = &ast.CalibrateResourceStmt{ 15867 DynamicCalibrateResourceOptionList: $1.([]*ast.DynamicCalibrateResourceOption), 15868 } 15869 } 15870 | CalibrateResourceWorkloadOption 15871 { 15872 $$ = &ast.CalibrateResourceStmt{ 15873 Tp: $1.(ast.CalibrateResourceType), 15874 } 15875 } 15876 15877 DynamicCalibrateOptionList: 15878 DynamicCalibrateResourceOption 15879 { 15880 $$ = []*ast.DynamicCalibrateResourceOption{$1.(*ast.DynamicCalibrateResourceOption)} 15881 } 15882 | DynamicCalibrateOptionList DynamicCalibrateResourceOption 15883 { 15884 if $1.([]*ast.DynamicCalibrateResourceOption)[0].Tp == $2.(*ast.DynamicCalibrateResourceOption).Tp || 15885 (len($1.([]*ast.DynamicCalibrateResourceOption)) > 1 && $1.([]*ast.DynamicCalibrateResourceOption)[1].Tp == $2.(*ast.DynamicCalibrateResourceOption).Tp) { 15886 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 15887 return 1 15888 } 15889 $$ = append($1.([]*ast.DynamicCalibrateResourceOption), $2.(*ast.DynamicCalibrateResourceOption)) 15890 } 15891 | DynamicCalibrateOptionList ',' DynamicCalibrateResourceOption 15892 { 15893 if $1.([]*ast.DynamicCalibrateResourceOption)[0].Tp == $3.(*ast.DynamicCalibrateResourceOption).Tp || 15894 (len($1.([]*ast.DynamicCalibrateResourceOption)) > 1 && $1.([]*ast.DynamicCalibrateResourceOption)[1].Tp == $3.(*ast.DynamicCalibrateResourceOption).Tp) { 15895 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 15896 return 1 15897 } 15898 $$ = append($1.([]*ast.DynamicCalibrateResourceOption), $3.(*ast.DynamicCalibrateResourceOption)) 15899 } 15900 15901 DynamicCalibrateResourceOption: 15902 "START_TIME" EqOpt Expression 15903 { 15904 $$ = &ast.DynamicCalibrateResourceOption{Tp: ast.CalibrateStartTime, Ts: $3.(ast.ExprNode)} 15905 } 15906 | "END_TIME" EqOpt Expression 15907 { 15908 $$ = &ast.DynamicCalibrateResourceOption{Tp: ast.CalibrateEndTime, Ts: $3.(ast.ExprNode)} 15909 } 15910 | "DURATION" EqOpt stringLit 15911 { 15912 _, err := duration.ParseDuration($3) 15913 if err != nil { 15914 yylex.AppendError(yylex.Errorf("The DURATION option is not a valid duration: %s", err.Error())) 15915 return 1 15916 } 15917 $$ = &ast.DynamicCalibrateResourceOption{Tp: ast.CalibrateDuration, StrValue: $3} 15918 } 15919 | "DURATION" EqOpt "INTERVAL" Expression TimeUnit 15920 { 15921 $$ = &ast.DynamicCalibrateResourceOption{Tp: ast.CalibrateDuration, Ts: $4.(ast.ExprNode), Unit: $5.(ast.TimeUnitType)} 15922 } 15923 15924 CalibrateResourceWorkloadOption: 15925 "WORKLOAD" "TPCC" 15926 { 15927 $$ = ast.TPCC 15928 } 15929 | "WORKLOAD" "OLTP_READ_WRITE" 15930 { 15931 $$ = ast.OLTPREADWRITE 15932 } 15933 | "WORKLOAD" "OLTP_READ_ONLY" 15934 { 15935 $$ = ast.OLTPREADONLY 15936 } 15937 | "WORKLOAD" "OLTP_WRITE_ONLY" 15938 { 15939 $$ = ast.OLTPWRITEONLY 15940 } 15941 | "WORKLOAD" "TPCH_10" 15942 { 15943 $$ = ast.TPCH10 15944 } 15945 15946 /******************************************************************** 15947 * 15948 * Query Watch Statement 15949 * 15950 * Query Watch 15951 *******************************************************************/ 15952 AddQueryWatchStmt: 15953 "QUERY" "WATCH" "ADD" QueryWatchOptionList 15954 { 15955 $$ = &ast.AddQueryWatchStmt{ 15956 QueryWatchOptionList: $4.([]*ast.QueryWatchOption), 15957 } 15958 } 15959 15960 QueryWatchOptionList: 15961 QueryWatchOption 15962 { 15963 $$ = []*ast.QueryWatchOption{$1.(*ast.QueryWatchOption)} 15964 } 15965 | QueryWatchOptionList QueryWatchOption 15966 { 15967 if !ast.CheckQueryWatchAppend($1.([]*ast.QueryWatchOption), $2.(*ast.QueryWatchOption)) { 15968 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 15969 return 1 15970 } 15971 $$ = append($1.([]*ast.QueryWatchOption), $2.(*ast.QueryWatchOption)) 15972 } 15973 | QueryWatchOptionList ',' QueryWatchOption 15974 { 15975 if !ast.CheckQueryWatchAppend($1.([]*ast.QueryWatchOption), $3.(*ast.QueryWatchOption)) { 15976 yylex.AppendError(yylex.Errorf("Dupliated options specified")) 15977 return 1 15978 } 15979 $$ = append($1.([]*ast.QueryWatchOption), $3.(*ast.QueryWatchOption)) 15980 } 15981 15982 QueryWatchOption: 15983 "RESOURCE" "GROUP" ResourceGroupName 15984 { 15985 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchResourceGroup, StrValue: model.NewCIStr($3)} 15986 } 15987 | "RESOURCE" "GROUP" UserVariable 15988 { 15989 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchResourceGroup, ExprValue: $3} 15990 } 15991 | "ACTION" EqOpt ResourceGroupRunawayActionOption 15992 { 15993 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchAction, IntValue: $3.(int32)} 15994 } 15995 | QueryWatchTextOption 15996 { 15997 $$ = $1.(*ast.QueryWatchOption) 15998 } 15999 16000 QueryWatchTextOption: 16001 "SQL" "DIGEST" SimpleExpr 16002 { 16003 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchType, IntValue: int32(model.WatchSimilar), ExprValue: $3} 16004 } 16005 | "PLAN" "DIGEST" SimpleExpr 16006 { 16007 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchType, IntValue: int32(model.WatchPlan), ExprValue: $3} 16008 } 16009 | "SQL" "TEXT" ResourceGroupRunawayWatchOption "TO" SimpleExpr 16010 { 16011 $$ = &ast.QueryWatchOption{Tp: ast.QueryWatchType, IntValue: $3.(int32), ExprValue: $5, BoolValue: true} 16012 } 16013 16014 DropQueryWatchStmt: 16015 "QUERY" "WATCH" "REMOVE" NUM 16016 { 16017 $$ = &ast.DropQueryWatchStmt{ 16018 IntValue: $4.(int64), 16019 } 16020 } 16021 %%