vitess.io/vitess@v0.16.2/go/vt/sqlparser/sql.y (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  You may obtain a copy of the License at
     6  
     7      http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  %{
    17  package sqlparser
    18  
    19  func setParseTree(yylex yyLexer, stmt Statement) {
    20    yylex.(*Tokenizer).ParseTree = stmt
    21  }
    22  
    23  func setAllowComments(yylex yyLexer, allow bool) {
    24    yylex.(*Tokenizer).AllowComments = allow
    25  }
    26  
    27  func setDDL(yylex yyLexer, node Statement) {
    28    yylex.(*Tokenizer).partialDDL = node
    29  }
    30  
    31  func incNesting(yylex yyLexer) bool {
    32    yylex.(*Tokenizer).nesting++
    33    if yylex.(*Tokenizer).nesting == 200 {
    34      return true
    35    }
    36    return false
    37  }
    38  
    39  func decNesting(yylex yyLexer) {
    40    yylex.(*Tokenizer).nesting--
    41  }
    42  
    43  // skipToEnd forces the lexer to end prematurely. Not all SQL statements
    44  // are supported by the Parser, thus calling skipToEnd will make the lexer
    45  // return EOF early.
    46  func skipToEnd(yylex yyLexer) {
    47    yylex.(*Tokenizer).SkipToEnd = true
    48  }
    49  
    50  func bindVariable(yylex yyLexer, bvar string) {
    51    yylex.(*Tokenizer).BindVars[bvar] = struct{}{}
    52  }
    53  
    54  %}
    55  
    56  %struct {
    57    empty         struct{}
    58    LengthScaleOption LengthScaleOption
    59    tableName     TableName
    60    identifierCS    IdentifierCS
    61    str           string
    62    strs          []string
    63    vindexParam   VindexParam
    64    jsonObjectParam *JSONObjectParam
    65    identifierCI      IdentifierCI
    66    joinCondition *JoinCondition
    67    databaseOption DatabaseOption
    68    columnType    *ColumnType
    69    columnCharset ColumnCharset
    70  }
    71  
    72  %union {
    73    statement     Statement
    74    selStmt       SelectStatement
    75    tableExpr     TableExpr
    76    expr          Expr
    77    colTuple      ColTuple
    78    optVal        Expr
    79    constraintInfo ConstraintInfo
    80    alterOption      AlterOption
    81  
    82    ins           *Insert
    83    colName       *ColName
    84    colNames      []*ColName
    85    indexHint    *IndexHint
    86    indexHints    IndexHints
    87    indexHintForType IndexHintForType
    88    literal        *Literal
    89    subquery      *Subquery
    90    derivedTable  *DerivedTable
    91    when          *When
    92    with          *With
    93    cte           *CommonTableExpr
    94    ctes          []*CommonTableExpr
    95    order         *Order
    96    limit         *Limit
    97  
    98    updateExpr    *UpdateExpr
    99    setExpr       *SetExpr
   100    convertType   *ConvertType
   101    aliasedTableName *AliasedTableExpr
   102    tableSpec  *TableSpec
   103    columnDefinition *ColumnDefinition
   104    indexDefinition *IndexDefinition
   105    indexInfo     *IndexInfo
   106    indexOption   *IndexOption
   107    indexColumn   *IndexColumn
   108    partDef       *PartitionDefinition
   109    partSpec      *PartitionSpec
   110    showFilter    *ShowFilter
   111    optLike       *OptLike
   112    selectInto	  *SelectInto
   113    createDatabase  *CreateDatabase
   114    alterDatabase  *AlterDatabase
   115    createTable      *CreateTable
   116    tableAndLockType *TableAndLockType
   117    alterTable       *AlterTable
   118    tableOption      *TableOption
   119    columnTypeOptions *ColumnTypeOptions
   120    partitionDefinitionOptions *PartitionDefinitionOptions
   121    subPartitionDefinition *SubPartitionDefinition
   122    subPartitionDefinitions SubPartitionDefinitions
   123    subPartitionDefinitionOptions *SubPartitionDefinitionOptions
   124    constraintDefinition *ConstraintDefinition
   125    revertMigration *RevertMigration
   126    alterMigration  *AlterMigration
   127    trimType        TrimType
   128    frameClause     *FrameClause
   129    framePoint 	  *FramePoint
   130    frameUnitType   FrameUnitType
   131    framePointType  FramePointType
   132    argumentLessWindowExprType ArgumentLessWindowExprType
   133    windowSpecification *WindowSpecification
   134    overClause *OverClause
   135    nullTreatmentClause *NullTreatmentClause
   136    nullTreatmentType NullTreatmentType
   137    firstOrLastValueExprType FirstOrLastValueExprType
   138    fromFirstLastType FromFirstLastType
   139    fromFirstLastClause *FromFirstLastClause
   140    lagLeadExprType LagLeadExprType
   141    windowDefinition *WindowDefinition
   142    windowDefinitions WindowDefinitions
   143    namedWindow *NamedWindow
   144    namedWindows NamedWindows
   145  
   146    whens         []*When
   147    columnDefinitions []*ColumnDefinition
   148    indexOptions  []*IndexOption
   149    indexColumns  []*IndexColumn
   150    databaseOptions []DatabaseOption
   151    tableAndLockTypes TableAndLockTypes
   152    renameTablePairs []*RenameTablePair
   153    alterOptions	   []AlterOption
   154    vindexParams  []VindexParam
   155    jsonObjectParams []*JSONObjectParam
   156    partDefs      []*PartitionDefinition
   157    partitionValueRange	*PartitionValueRange
   158    partitionEngine *PartitionEngine
   159    partSpecs     []*PartitionSpec
   160    selectExpr    SelectExpr
   161    columns       Columns
   162    partitions    Partitions
   163    tableExprs    TableExprs
   164    tableNames    TableNames
   165    exprs         Exprs
   166    values        Values
   167    valTuple      ValTuple
   168    orderBy       OrderBy
   169    updateExprs   UpdateExprs
   170    setExprs      SetExprs
   171    selectExprs   SelectExprs
   172    tableOptions     TableOptions
   173    starExpr      StarExpr
   174  
   175    colKeyOpt     ColumnKeyOption
   176    referenceAction ReferenceAction
   177    matchAction MatchAction
   178    insertAction InsertAction
   179    scope 	Scope
   180    lock 		Lock
   181    joinType  	JoinType
   182    comparisonExprOperator ComparisonExprOperator
   183    isExprOperator IsExprOperator
   184    matchExprOption MatchExprOption
   185    orderDirection  OrderDirection
   186    explainType 	  ExplainType
   187    vexplainType 	  VExplainType
   188    intervalType	  IntervalTypes
   189    lockType LockType
   190    referenceDefinition *ReferenceDefinition
   191    txAccessModes []TxAccessMode
   192    txAccessMode TxAccessMode
   193  
   194    columnStorage ColumnStorage
   195    columnFormat ColumnFormat
   196  
   197    boolean bool
   198    boolVal BoolVal
   199    ignore Ignore
   200    partitionOption *PartitionOption
   201    subPartition  *SubPartition
   202    partitionByType PartitionByType
   203    definer 	*Definer
   204    integer 	int
   205  
   206    JSONTableExpr	*JSONTableExpr
   207    jtColumnDefinition *JtColumnDefinition
   208    jtColumnList	[]*JtColumnDefinition
   209    jtOnResponse	*JtOnResponse
   210    variables      []*Variable
   211    variable       *Variable
   212  }
   213  
   214  // These precedence rules are there to handle shift-reduce conflicts.
   215  %nonassoc <str> MEMBER
   216  // FUNCTION_CALL_NON_KEYWORD is used to resolve shift-reduce conflicts occuring due to function_call_generic symbol and
   217  // having special parsing for functions whose names are non-reserved keywords. The shift-reduce conflict occurrs because
   218  // after seeing a non-reserved keyword, if we see '(', then we can either shift to use the special parsing grammar rule or
   219  // reduce the non-reserved keyword into sql_id and eventually use a rule from function_call_generic.
   220  // The way to fix this conflict is to give shifting higher precedence than reducing.
   221  // Adding no precedence also works, since shifting is the default, but it reports a large number of conflicts
   222  // Shifting on '(' already has an assigned precedence.
   223  // All we need to add is a lower precedence to reducing the grammar symbol to non-reserved keywords.
   224  // In order to ensure lower precedence of reduction, this rule has to come before the precedence declaration of '('.
   225  // This precedence should not be used anywhere else other than with function names that are non-reserved-keywords.
   226  %nonassoc <str> FUNCTION_CALL_NON_KEYWORD
   227  // STRING_TYPE_PREFIX_NON_KEYWORD is used to resolve shift-reduce conflicts occuring due to column_name symbol and
   228  // being able to use keywords like DATE and TIME as prefixes to strings to denote their type. The shift-reduce conflict occurrs because
   229  // after seeing one of these non-reserved keywords, if we see a STRING, then we can either shift to use the STRING typed rule in literal or
   230  // reduce the non-reserved keyword into column_name and eventually use a rule from simple_expr.
   231  // The way to fix this conflict is to give shifting higher precedence than reducing.
   232  // Adding no precedence also works, since shifting is the default, but it reports some conflicts
   233  // Precedence is also assined to shifting on STRING.
   234  // We also need to add a lower precedence to reducing the grammar symbol to non-reserved keywords.
   235  // In order to ensure lower precedence of reduction, this rule has to come before the precedence declaration of STRING.
   236  // This precedence should not be used anywhere else other than with non-reserved-keywords that are also used for type-casting a STRING.
   237  %nonassoc <str> STRING_TYPE_PREFIX_NON_KEYWORD
   238  
   239  %token LEX_ERROR
   240  %left <str> UNION
   241  %token <str> SELECT STREAM VSTREAM INSERT UPDATE DELETE FROM WHERE GROUP HAVING ORDER BY LIMIT OFFSET FOR
   242  %token <str> ALL DISTINCT AS EXISTS ASC DESC INTO DUPLICATE DEFAULT SET LOCK UNLOCK KEYS DO CALL
   243  %token <str> DISTINCTROW PARSER GENERATED ALWAYS
   244  %token <str> OUTFILE S3 DATA LOAD LINES TERMINATED ESCAPED ENCLOSED
   245  %token <str> DUMPFILE CSV HEADER MANIFEST OVERWRITE STARTING OPTIONALLY
   246  %token <str> VALUES LAST_INSERT_ID
   247  %token <str> NEXT VALUE SHARE MODE
   248  %token <str> SQL_NO_CACHE SQL_CACHE SQL_CALC_FOUND_ROWS
   249  %left <str> JOIN STRAIGHT_JOIN LEFT RIGHT INNER OUTER CROSS NATURAL USE FORCE
   250  %left <str> ON USING INPLACE COPY INSTANT ALGORITHM NONE SHARED EXCLUSIVE
   251  %left <str> SUBQUERY_AS_EXPR
   252  %left <str> '(' ',' ')'
   253  %nonassoc <str> STRING
   254  %token <str> ID AT_ID AT_AT_ID HEX NCHAR_STRING INTEGRAL FLOAT DECIMAL HEXNUM COMMENT COMMENT_KEYWORD BITNUM BIT_LITERAL COMPRESSION
   255  %token <str> VALUE_ARG LIST_ARG OFFSET_ARG
   256  %token <str> JSON_PRETTY JSON_STORAGE_SIZE JSON_STORAGE_FREE JSON_CONTAINS JSON_CONTAINS_PATH JSON_EXTRACT JSON_KEYS JSON_OVERLAPS JSON_SEARCH JSON_VALUE
   257  %token <str> EXTRACT
   258  %token <str> NULL TRUE FALSE OFF
   259  %token <str> DISCARD IMPORT ENABLE DISABLE TABLESPACE
   260  %token <str> VIRTUAL STORED
   261  %token <str> BOTH LEADING TRAILING
   262  
   263  %left EMPTY_FROM_CLAUSE
   264  %right INTO
   265  
   266  // Precedence dictated by mysql. But the vitess grammar is simplified.
   267  // Some of these operators don't conflict in our situation. Nevertheless,
   268  // it's better to have these listed in the correct order. Also, we don't
   269  // support all operators yet.
   270  // * NOTE: If you change anything here, update precedence.go as well *
   271  %nonassoc <str> LOWER_THAN_CHARSET
   272  %nonassoc <str> CHARSET
   273  // Resolve column attribute ambiguity.
   274  %right <str> UNIQUE KEY
   275  %left <str> EXPRESSION_PREC_SETTER
   276  %left <str> OR '|'
   277  %left <str> XOR
   278  %left <str> AND
   279  %right <str> NOT '!'
   280  %left <str> BETWEEN CASE WHEN THEN ELSE END
   281  %left <str> '=' '<' '>' LE GE NE NULL_SAFE_EQUAL IS LIKE REGEXP RLIKE IN
   282  %left <str> '&'
   283  %left <str> SHIFT_LEFT SHIFT_RIGHT
   284  %left <str> '+' '-'
   285  %left <str> '*' '/' DIV '%' MOD
   286  %left <str> '^'
   287  %right <str> '~' UNARY
   288  %left <str> COLLATE
   289  %right <str> BINARY UNDERSCORE_ARMSCII8 UNDERSCORE_ASCII UNDERSCORE_BIG5 UNDERSCORE_BINARY UNDERSCORE_CP1250 UNDERSCORE_CP1251
   290  %right <str> UNDERSCORE_CP1256 UNDERSCORE_CP1257 UNDERSCORE_CP850 UNDERSCORE_CP852 UNDERSCORE_CP866 UNDERSCORE_CP932
   291  %right <str> UNDERSCORE_DEC8 UNDERSCORE_EUCJPMS UNDERSCORE_EUCKR UNDERSCORE_GB18030 UNDERSCORE_GB2312 UNDERSCORE_GBK UNDERSCORE_GEOSTD8
   292  %right <str> UNDERSCORE_GREEK UNDERSCORE_HEBREW UNDERSCORE_HP8 UNDERSCORE_KEYBCS2 UNDERSCORE_KOI8R UNDERSCORE_KOI8U UNDERSCORE_LATIN1 UNDERSCORE_LATIN2 UNDERSCORE_LATIN5
   293  %right <str> UNDERSCORE_LATIN7 UNDERSCORE_MACCE UNDERSCORE_MACROMAN UNDERSCORE_SJIS UNDERSCORE_SWE7 UNDERSCORE_TIS620 UNDERSCORE_UCS2 UNDERSCORE_UJIS UNDERSCORE_UTF16
   294  %right <str> UNDERSCORE_UTF16LE UNDERSCORE_UTF32 UNDERSCORE_UTF8 UNDERSCORE_UTF8MB4 UNDERSCORE_UTF8MB3
   295  %right <str> INTERVAL
   296  %nonassoc <str> '.'
   297  %left <str> WINDOW_EXPR
   298  
   299  // There is no need to define precedence for the JSON
   300  // operators because the syntax is restricted enough that
   301  // they don't cause conflicts.
   302  %token <empty> JSON_EXTRACT_OP JSON_UNQUOTE_EXTRACT_OP
   303  
   304  // DDL Tokens
   305  %token <str> CREATE ALTER DROP RENAME ANALYZE ADD FLUSH CHANGE MODIFY DEALLOCATE
   306  %token <str> REVERT QUERIES
   307  %token <str> SCHEMA TABLE INDEX VIEW TO IGNORE IF PRIMARY COLUMN SPATIAL FULLTEXT KEY_BLOCK_SIZE CHECK INDEXES
   308  %token <str> ACTION CASCADE CONSTRAINT FOREIGN NO REFERENCES RESTRICT
   309  %token <str> SHOW DESCRIBE EXPLAIN DATE ESCAPE REPAIR OPTIMIZE TRUNCATE COALESCE EXCHANGE REBUILD PARTITIONING REMOVE PREPARE EXECUTE
   310  %token <str> MAXVALUE PARTITION REORGANIZE LESS THAN PROCEDURE TRIGGER
   311  %token <str> VINDEX VINDEXES DIRECTORY NAME UPGRADE
   312  %token <str> STATUS VARIABLES WARNINGS CASCADED DEFINER OPTION SQL UNDEFINED
   313  %token <str> SEQUENCE MERGE TEMPORARY TEMPTABLE INVOKER SECURITY FIRST AFTER LAST
   314  
   315  // Migration tokens
   316  %token <str> VITESS_MIGRATION CANCEL RETRY LAUNCH COMPLETE CLEANUP THROTTLE UNTHROTTLE EXPIRE RATIO
   317  // Throttler tokens
   318  %token <str> VITESS_THROTTLER
   319  
   320  // Transaction Tokens
   321  %token <str> BEGIN START TRANSACTION COMMIT ROLLBACK SAVEPOINT RELEASE WORK
   322  %token <str> CONSISTENT SNAPSHOT
   323  
   324  // Type Tokens
   325  %token <str> BIT TINYINT SMALLINT MEDIUMINT INT INTEGER BIGINT INTNUM
   326  %token <str> REAL DOUBLE FLOAT_TYPE FLOAT4_TYPE FLOAT8_TYPE DECIMAL_TYPE NUMERIC
   327  %token <str> TIME TIMESTAMP DATETIME YEAR
   328  %token <str> CHAR VARCHAR BOOL CHARACTER VARBINARY NCHAR
   329  %token <str> TEXT TINYTEXT MEDIUMTEXT LONGTEXT
   330  %token <str> BLOB TINYBLOB MEDIUMBLOB LONGBLOB JSON JSON_SCHEMA_VALID JSON_SCHEMA_VALIDATION_REPORT ENUM
   331  %token <str> GEOMETRY POINT LINESTRING POLYGON GEOMCOLLECTION GEOMETRYCOLLECTION MULTIPOINT MULTILINESTRING MULTIPOLYGON
   332  %token <str> ASCII UNICODE // used in CONVERT/CAST types
   333  
   334  // Type Modifiers
   335  %token <str> NULLX AUTO_INCREMENT APPROXNUM SIGNED UNSIGNED ZEROFILL
   336  
   337  // SHOW tokens
   338  %token <str> CODE COLLATION COLUMNS DATABASES ENGINES EVENT EXTENDED FIELDS FULL FUNCTION GTID_EXECUTED
   339  %token <str> KEYSPACES OPEN PLUGINS PRIVILEGES PROCESSLIST SCHEMAS TABLES TRIGGERS USER
   340  %token <str> VGTID_EXECUTED VITESS_KEYSPACES VITESS_METADATA VITESS_MIGRATIONS VITESS_REPLICATION_STATUS VITESS_SHARDS VITESS_TABLETS VITESS_TARGET VSCHEMA VITESS_THROTTLED_APPS
   341  
   342  // SET tokens
   343  %token <str> NAMES GLOBAL SESSION ISOLATION LEVEL READ WRITE ONLY REPEATABLE COMMITTED UNCOMMITTED SERIALIZABLE
   344  
   345  // Functions
   346  %token <str> CURRENT_TIMESTAMP DATABASE CURRENT_DATE NOW
   347  %token <str> CURRENT_TIME LOCALTIME LOCALTIMESTAMP CURRENT_USER
   348  %token <str> UTC_DATE UTC_TIME UTC_TIMESTAMP
   349  %token <str> DAY DAY_HOUR DAY_MICROSECOND DAY_MINUTE DAY_SECOND HOUR HOUR_MICROSECOND HOUR_MINUTE HOUR_SECOND MICROSECOND MINUTE MINUTE_MICROSECOND MINUTE_SECOND MONTH QUARTER SECOND SECOND_MICROSECOND YEAR_MONTH WEEK
   350  %token <str> REPLACE
   351  %token <str> CONVERT CAST
   352  %token <str> SUBSTR SUBSTRING
   353  %token <str> SEPARATOR
   354  %token <str> TIMESTAMPADD TIMESTAMPDIFF
   355  %token <str> WEIGHT_STRING
   356  %token <str> LTRIM RTRIM TRIM
   357  %token <str> JSON_ARRAY JSON_OBJECT JSON_QUOTE
   358  %token <str> JSON_DEPTH JSON_TYPE JSON_LENGTH JSON_VALID
   359  %token <str> JSON_ARRAY_APPEND JSON_ARRAY_INSERT JSON_INSERT JSON_MERGE JSON_MERGE_PATCH JSON_MERGE_PRESERVE JSON_REMOVE JSON_REPLACE JSON_SET JSON_UNQUOTE
   360  %token <str> COUNT AVG MAX MIN SUM GROUP_CONCAT BIT_AND BIT_OR BIT_XOR STD STDDEV STDDEV_POP STDDEV_SAMP VAR_POP VAR_SAMP VARIANCE
   361  %token <str> REGEXP_INSTR REGEXP_LIKE REGEXP_REPLACE REGEXP_SUBSTR
   362  %token <str> ExtractValue UpdateXML
   363  %token <str> GET_LOCK RELEASE_LOCK RELEASE_ALL_LOCKS IS_FREE_LOCK IS_USED_LOCK
   364  %token <str> LOCATE POSITION
   365  
   366  // Match
   367  %token <str> MATCH AGAINST BOOLEAN LANGUAGE WITH QUERY EXPANSION WITHOUT VALIDATION
   368  
   369  // MySQL reserved words that are unused by this grammar will map to this token.
   370  %token <str> UNUSED ARRAY BYTE CUME_DIST DESCRIPTION DENSE_RANK EMPTY EXCEPT FIRST_VALUE GROUPING GROUPS JSON_TABLE LAG LAST_VALUE LATERAL LEAD
   371  %token <str> NTH_VALUE NTILE OF OVER PERCENT_RANK RANK RECURSIVE ROW_NUMBER SYSTEM WINDOW
   372  %token <str> ACTIVE ADMIN AUTOEXTEND_SIZE BUCKETS CLONE COLUMN_FORMAT COMPONENT DEFINITION ENFORCED ENGINE_ATTRIBUTE EXCLUDE FOLLOWING GET_MASTER_PUBLIC_KEY HISTOGRAM HISTORY
   373  %token <str> INACTIVE INVISIBLE LOCKED MASTER_COMPRESSION_ALGORITHMS MASTER_PUBLIC_KEY_PATH MASTER_TLS_CIPHERSUITES MASTER_ZSTD_COMPRESSION_LEVEL
   374  %token <str> NESTED NETWORK_NAMESPACE NOWAIT NULLS OJ OLD OPTIONAL ORDINALITY ORGANIZATION OTHERS PARTIAL PATH PERSIST PERSIST_ONLY PRECEDING PRIVILEGE_CHECKS_USER PROCESS
   375  %token <str> RANDOM REFERENCE REQUIRE_ROW_FORMAT RESOURCE RESPECT RESTART RETAIN REUSE ROLE SECONDARY SECONDARY_ENGINE SECONDARY_ENGINE_ATTRIBUTE SECONDARY_LOAD SECONDARY_UNLOAD SIMPLE SKIP SRID
   376  %token <str> THREAD_PRIORITY TIES UNBOUNDED VCPU VISIBLE RETURNING
   377  
   378  // Performance Schema Functions
   379  %token <str> FORMAT_BYTES FORMAT_PICO_TIME PS_CURRENT_THREAD_ID PS_THREAD_ID
   380  
   381  // GTID Functions
   382  %token <str> GTID_SUBSET GTID_SUBTRACT WAIT_FOR_EXECUTED_GTID_SET WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS
   383  
   384  // Explain tokens
   385  %token <str> FORMAT TREE VITESS TRADITIONAL VTEXPLAIN VEXPLAIN PLAN
   386  
   387  // Lock type tokens
   388  %token <str> LOCAL LOW_PRIORITY
   389  
   390  // Flush tokens
   391  %token <str> NO_WRITE_TO_BINLOG LOGS ERROR GENERAL HOSTS OPTIMIZER_COSTS USER_RESOURCES SLOW CHANNEL RELAY EXPORT
   392  
   393  // Window Functions Token
   394  %token <str> CURRENT ROW ROWS
   395  
   396  // TableOptions tokens
   397  %token <str> AVG_ROW_LENGTH CONNECTION CHECKSUM DELAY_KEY_WRITE ENCRYPTION ENGINE INSERT_METHOD MAX_ROWS MIN_ROWS PACK_KEYS PASSWORD
   398  %token <str> FIXED DYNAMIC COMPRESSED REDUNDANT COMPACT ROW_FORMAT STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES STORAGE MEMORY DISK
   399  
   400  // Partitions tokens
   401  %token <str> PARTITIONS LINEAR RANGE LIST SUBPARTITION SUBPARTITIONS HASH
   402  
   403  %type <partitionByType> range_or_list
   404  %type <integer> partitions_opt algorithm_opt subpartitions_opt partition_max_rows partition_min_rows
   405  %type <statement> command
   406  %type <selStmt> query_expression_parens query_expression query_expression_body select_statement query_primary select_stmt_with_into
   407  %type <statement> explain_statement explainable_statement
   408  %type <statement> prepare_statement
   409  %type <statement> vexplain_statement
   410  %type <statement> execute_statement deallocate_statement
   411  %type <statement> stream_statement vstream_statement insert_statement update_statement delete_statement set_statement set_transaction_statement
   412  %type <statement> create_statement alter_statement rename_statement drop_statement truncate_statement flush_statement do_statement
   413  %type <with> with_clause_opt with_clause
   414  %type <cte> common_table_expr
   415  %type <ctes> with_list
   416  %type <renameTablePairs> rename_list
   417  %type <createTable> create_table_prefix
   418  %type <alterTable> alter_table_prefix
   419  %type <alterOption> alter_option alter_commands_modifier lock_index algorithm_index
   420  %type <alterOptions> alter_options alter_commands_list alter_commands_modifier_list algorithm_lock_opt
   421  %type <alterTable> create_index_prefix
   422  %type <createDatabase> create_database_prefix
   423  %type <alterDatabase> alter_database_prefix
   424  %type <databaseOption> collate character_set encryption
   425  %type <databaseOptions> create_options create_options_opt
   426  %type <boolean> default_optional first_opt linear_opt jt_exists_opt jt_path_opt partition_storage_opt
   427  %type <statement> analyze_statement show_statement use_statement other_statement
   428  %type <statement> begin_statement commit_statement rollback_statement savepoint_statement release_statement load_statement
   429  %type <statement> lock_statement unlock_statement call_statement
   430  %type <statement> revert_statement
   431  %type <strs> comment_opt comment_list
   432  %type <str> wild_opt check_option_opt cascade_or_local_opt restrict_or_cascade_opt
   433  %type <explainType> explain_format_opt
   434  %type <vexplainType> vexplain_type_opt
   435  %type <trimType> trim_type
   436  %type <frameUnitType> frame_units
   437  %type <argumentLessWindowExprType> argument_less_window_expr_type
   438  %type <framePoint> frame_point
   439  %type <frameClause> frame_clause frame_clause_opt
   440  %type <windowSpecification> window_spec
   441  %type <overClause> over_clause
   442  %type <nullTreatmentType> null_treatment_type
   443  %type <nullTreatmentClause> null_treatment_clause null_treatment_clause_opt
   444  %type <fromFirstLastType> from_first_last_type
   445  %type <fromFirstLastClause> from_first_last_clause from_first_last_clause_opt
   446  %type <firstOrLastValueExprType> first_or_last_value_expr_type
   447  %type <lagLeadExprType> lag_lead_expr_type
   448  %type <windowDefinition> window_definition
   449  %type <windowDefinitions> window_definition_list
   450  %type <namedWindow> named_window
   451  %type <namedWindows> named_windows_list named_windows_list_opt
   452  %type <insertAction> insert_or_replace
   453  %type <str> explain_synonyms
   454  %type <partitionOption> partitions_options_opt partitions_options_beginning
   455  %type <partitionDefinitionOptions> partition_definition_attribute_list_opt
   456  %type <subPartition> subpartition_opt
   457  %type <subPartitionDefinition> subpartition_definition
   458  %type <subPartitionDefinitions> subpartition_definition_list subpartition_definition_list_with_brackets
   459  %type <subPartitionDefinitionOptions> subpartition_definition_attribute_list_opt
   460  %type <intervalType> interval_time_stamp interval
   461  %type <str> cache_opt separator_opt flush_option for_channel_opt maxvalue
   462  %type <matchExprOption> match_option
   463  %type <boolean> distinct_opt union_op replace_opt local_opt
   464  %type <selectExprs> select_expression_list select_expression_list_opt
   465  %type <selectExpr> select_expression
   466  %type <strs> select_options flush_option_list
   467  %type <str> select_option algorithm_view security_view security_view_opt
   468  %type <str> generated_always_opt user_username address_opt
   469  %type <definer> definer_opt user
   470  %type <expr> expression frame_expression signed_literal signed_literal_or_null null_as_literal now_or_signed_literal signed_literal bit_expr regular_expressions xml_expressions
   471  %type <expr> interval_value simple_expr literal NUM_literal text_literal text_literal_or_arg bool_pri literal_or_null now predicate tuple_expression null_int_variable_arg performance_schema_function_expressions gtid_function_expressions
   472  %type <tableExprs> from_opt table_references from_clause
   473  %type <tableExpr> table_reference table_factor join_table json_table_function
   474  %type <jtColumnDefinition> jt_column
   475  %type <jtColumnList> jt_columns_clause columns_list
   476  %type <jtOnResponse> on_error on_empty json_on_response
   477  %type <joinCondition> join_condition join_condition_opt on_expression_opt
   478  %type <tableNames> table_name_list delete_table_list view_name_list
   479  %type <joinType> inner_join outer_join straight_join natural_join
   480  %type <tableName> table_name into_table_name delete_table_name
   481  %type <aliasedTableName> aliased_table_name
   482  %type <indexHint> index_hint
   483  %type <indexHintForType> index_hint_for_opt
   484  %type <indexHints> index_hint_list index_hint_list_opt
   485  %type <expr> where_expression_opt
   486  %type <boolVal> boolean_value
   487  %type <comparisonExprOperator> compare
   488  %type <ins> insert_data
   489  %type <expr> num_val
   490  %type <expr> function_call_keyword function_call_nonkeyword function_call_generic function_call_conflict
   491  %type <isExprOperator> is_suffix
   492  %type <colTuple> col_tuple
   493  %type <exprs> expression_list expression_list_opt window_partition_clause_opt
   494  %type <values> tuple_list
   495  %type <valTuple> row_tuple tuple_or_empty
   496  %type <subquery> subquery
   497  %type <derivedTable> derived_table
   498  %type <colName> column_name after_opt
   499  %type <expr> column_name_or_offset
   500  %type <colNames> column_names column_names_opt_paren
   501  %type <whens> when_expression_list
   502  %type <when> when_expression
   503  %type <expr> expression_opt else_expression_opt default_with_comma_opt
   504  %type <exprs> group_by_opt
   505  %type <expr> having_opt
   506  %type <orderBy> order_by_opt order_list order_by_clause
   507  %type <order> order
   508  %type <orderDirection> asc_desc_opt
   509  %type <limit> limit_opt limit_clause
   510  %type <selectInto> into_clause
   511  %type <columnTypeOptions> column_attribute_list_opt generated_column_attribute_list_opt
   512  %type <str> header_opt export_options manifest_opt overwrite_opt format_opt optionally_opt regexp_symbol
   513  %type <str> fields_opts fields_opt_list fields_opt lines_opts lines_opt lines_opt_list
   514  %type <lock> locking_clause
   515  %type <columns> ins_column_list column_list column_list_opt column_list_empty index_list
   516  %type <variable> variable_expr set_variable user_defined_variable
   517  %type <variables> at_id_list execute_statement_list_opt
   518  %type <partitions> opt_partition_clause partition_list
   519  %type <updateExprs> on_dup_opt
   520  %type <updateExprs> update_list
   521  %type <setExprs> set_list transaction_chars
   522  %type <setExpr> set_expression transaction_char
   523  %type <str> charset_or_character_set charset_or_character_set_or_names isolation_level
   524  %type <updateExpr> update_expression
   525  %type <str> for_from from_or_on
   526  %type <str> default_opt
   527  %type <ignore> ignore_opt
   528  %type <str> columns_or_fields extended_opt storage_opt
   529  %type <showFilter> like_or_where_opt like_opt
   530  %type <boolean> exists_opt not_exists_opt enforced enforced_opt temp_opt full_opt
   531  %type <empty> to_opt
   532  %type <str> reserved_keyword non_reserved_keyword
   533  %type <identifierCI> sql_id sql_id_opt reserved_sql_id col_alias as_ci_opt
   534  %type <expr> charset_value
   535  %type <identifierCS> table_id reserved_table_id table_alias as_opt_id table_id_opt from_database_opt use_table_name
   536  %type <empty> as_opt work_opt savepoint_opt
   537  %type <empty> skip_to_end ddl_skip_to_end
   538  %type <str> charset
   539  %type <scope> set_session_or_global
   540  %type <convertType> convert_type returning_type_opt convert_type_weight_string
   541  %type <boolean> array_opt
   542  %type <columnType> column_type
   543  %type <columnType> int_type decimal_type numeric_type time_type char_type spatial_type
   544  %type <literal> length_opt partition_comment partition_data_directory partition_index_directory
   545  %type <expr> func_datetime_precision
   546  %type <columnCharset> charset_opt
   547  %type <str> collate_opt
   548  %type <boolean> binary_opt
   549  %type <LengthScaleOption> double_length_opt float_length_opt decimal_length_opt
   550  %type <boolean> unsigned_opt zero_fill_opt without_valid_opt
   551  %type <strs> enum_values
   552  %type <columnDefinition> column_definition
   553  %type <columnDefinitions> column_definition_list
   554  %type <indexDefinition> index_definition
   555  %type <constraintDefinition> constraint_definition check_constraint_definition
   556  %type <str> index_or_key index_symbols from_or_in index_or_key_opt
   557  %type <str> name_opt constraint_name_opt
   558  %type <str> equal_opt partition_tablespace_name
   559  %type <tableSpec> table_spec table_column_list
   560  %type <optLike> create_like
   561  %type <str> table_opt_value
   562  %type <tableOption> table_option
   563  %type <tableOptions> table_option_list table_option_list_opt space_separated_table_option_list
   564  %type <indexInfo> index_info
   565  %type <indexColumn> index_column
   566  %type <indexColumns> index_column_list
   567  %type <indexOption> index_option using_index_type
   568  %type <indexOptions> index_option_list index_option_list_opt using_opt
   569  %type <constraintInfo> constraint_info check_constraint_info
   570  %type <partDefs> partition_definitions partition_definitions_opt
   571  %type <partDef> partition_definition partition_name
   572  %type <partitionValueRange> partition_value_range
   573  %type <partitionEngine> partition_engine
   574  %type <partSpec> partition_operation
   575  %type <vindexParam> vindex_param
   576  %type <vindexParams> vindex_param_list vindex_params_opt
   577  %type <jsonObjectParam> json_object_param
   578  %type <jsonObjectParams> json_object_param_list json_object_param_opt
   579  %type <identifierCI> ci_identifier ci_identifier_opt vindex_type vindex_type_opt
   580  %type <str> database_or_schema column_opt insert_method_options row_format_options
   581  %type <referenceAction> fk_reference_action fk_on_delete fk_on_update
   582  %type <matchAction> fk_match fk_match_opt fk_match_action
   583  %type <tableAndLockTypes> lock_table_list
   584  %type <tableAndLockType> lock_table
   585  %type <lockType> lock_type
   586  %type <empty> session_or_local_opt
   587  %type <columnStorage> column_storage
   588  %type <columnFormat> column_format
   589  %type <colKeyOpt> keys
   590  %type <referenceDefinition> reference_definition reference_definition_opt
   591  %type <str> underscore_charsets
   592  %type <str> expire_opt
   593  %type <literal> ratio_opt
   594  %type <txAccessModes> tx_chacteristics_opt tx_chars
   595  %type <txAccessMode> tx_char
   596  %start any_command
   597  
   598  %%
   599  
   600  any_command:
   601    comment_opt command semicolon_opt
   602    {
   603      stmt := $2
   604      // If the statement is empty and we have comments
   605      // then we create a special struct which stores them.
   606      // This is required because we need to update the rows_returned
   607      // and other query stats and not return a `query was empty` error
   608      if stmt == nil && $1 != nil {
   609         stmt = &CommentOnly{Comments: $1}
   610      }
   611      setParseTree(yylex, stmt)
   612    }
   613  
   614  semicolon_opt:
   615  /*empty*/ {}
   616  | ';' {}
   617  
   618  command:
   619    select_statement
   620    {
   621      $$ = $1
   622    }
   623  | stream_statement
   624  | vstream_statement
   625  | insert_statement
   626  | update_statement
   627  | delete_statement
   628  | set_statement
   629  | set_transaction_statement
   630  | create_statement
   631  | alter_statement
   632  | rename_statement
   633  | drop_statement
   634  | truncate_statement
   635  | analyze_statement
   636  | show_statement
   637  | use_statement
   638  | begin_statement
   639  | commit_statement
   640  | rollback_statement
   641  | savepoint_statement
   642  | release_statement
   643  | explain_statement
   644  | vexplain_statement
   645  | other_statement
   646  | flush_statement
   647  | do_statement
   648  | load_statement
   649  | lock_statement
   650  | unlock_statement
   651  | call_statement
   652  | revert_statement
   653  | prepare_statement
   654  | execute_statement
   655  | deallocate_statement
   656  | /*empty*/
   657  {
   658    setParseTree(yylex, nil)
   659  }
   660  
   661  user_defined_variable:
   662    AT_ID
   663    {
   664      $$ = NewVariableExpression($1, SingleAt)
   665    }
   666  
   667  ci_identifier:
   668    ID
   669    {
   670      $$ = NewIdentifierCI(string($1))
   671    }
   672  
   673  ci_identifier_opt:
   674    {
   675      $$ = NewIdentifierCI("")
   676    }
   677  | ci_identifier
   678    {
   679      $$ = $1
   680    }
   681  
   682  variable_expr:
   683    AT_ID
   684    {
   685      $$ = NewVariableExpression(string($1), SingleAt)
   686    }
   687  | AT_AT_ID
   688    {
   689      $$ = NewVariableExpression(string($1), DoubleAt)
   690    }
   691  
   692  do_statement:
   693    DO expression_list
   694    {
   695      $$ = &OtherAdmin{}
   696    }
   697  
   698  load_statement:
   699    LOAD DATA skip_to_end
   700    {
   701      $$ = &Load{}
   702    }
   703  
   704  with_clause:
   705    WITH with_list
   706    {
   707  	$$ = &With{ctes: $2, Recursive: false}
   708    }
   709  | WITH RECURSIVE with_list
   710    {
   711  	$$ = &With{ctes: $3, Recursive: true}
   712    }
   713  
   714  with_clause_opt:
   715    {
   716      $$ = nil
   717    }
   718   | with_clause
   719   {
   720   	$$ = $1
   721   }
   722  
   723  with_list:
   724    with_list ',' common_table_expr
   725    {
   726  	$$ = append($1, $3)
   727    }
   728  | common_table_expr
   729    {
   730  	$$ = []*CommonTableExpr{$1}
   731    }
   732  
   733  common_table_expr:
   734    table_id column_list_opt AS subquery
   735    {
   736  	$$ = &CommonTableExpr{ID: $1, Columns: $2, Subquery: $4}
   737    }
   738  
   739  query_expression_parens:
   740    openb query_expression_parens closeb
   741    {
   742    	$$ = $2
   743    }
   744  | openb query_expression closeb
   745    {
   746       $$ = $2
   747    }
   748  | openb query_expression locking_clause closeb
   749    {
   750      setLockInSelect($2, $3)
   751      $$ = $2
   752    }
   753  
   754  // TODO; (Manan, Ritwiz) : Use this in create, insert statements
   755  //query_expression_or_parens:
   756  //	query_expression
   757  //	{
   758  //		$$ = $1
   759  //	}
   760  //	| query_expression locking_clause
   761  //	{
   762  //		setLockInSelect($1, $2)
   763  //		$$ = $1
   764  //	}
   765  //	| query_expression_parens
   766  //	{
   767  //		$$ = $1
   768  //	}
   769  
   770  query_expression:
   771   query_expression_body order_by_opt limit_opt
   772    {
   773  	$1.SetOrderBy($2)
   774  	$1.SetLimit($3)
   775  	$$ = $1
   776    }
   777  | query_expression_parens limit_clause
   778    {
   779  	$1.SetLimit($2)
   780  	$$ = $1
   781    }
   782  | query_expression_parens order_by_clause limit_opt
   783    {
   784  	$1.SetOrderBy($2)
   785  	$1.SetLimit($3)
   786  	$$ = $1
   787    }
   788  | with_clause query_expression_body order_by_opt limit_opt
   789    {
   790    		$2.SetWith($1)
   791  		$2.SetOrderBy($3)
   792  		$2.SetLimit($4)
   793  		$$ = $2
   794    }
   795  | with_clause query_expression_parens limit_clause
   796    {
   797    		$2.SetWith($1)
   798  		$2.SetLimit($3)
   799  		$$ = $2
   800    }
   801  | with_clause query_expression_parens order_by_clause limit_opt
   802    {
   803    		$2.SetWith($1)
   804  		$2.SetOrderBy($3)
   805  		$2.SetLimit($4)
   806  		$$ = $2
   807    }
   808  | with_clause query_expression_parens
   809    {
   810  	$2.SetWith($1)
   811    }
   812  | SELECT comment_opt cache_opt NEXT num_val for_from table_name
   813    {
   814  	$$ = NewSelect(Comments($2), SelectExprs{&Nextval{Expr: $5}}, []string{$3}/*options*/, nil, TableExprs{&AliasedTableExpr{Expr: $7}}, nil/*where*/, nil/*groupBy*/, nil/*having*/, nil)
   815    }
   816  
   817  query_expression_body:
   818   query_primary
   819    {
   820  	$$ = $1
   821    }
   822  | query_expression_body union_op query_primary
   823    {
   824   	$$ = &Union{Left: $1, Distinct: $2, Right: $3}
   825    }
   826  | query_expression_parens union_op query_primary
   827    {
   828  	$$ = &Union{Left: $1, Distinct: $2, Right: $3}
   829    }
   830  | query_expression_body union_op query_expression_parens
   831    {
   832    	$$ = &Union{Left: $1, Distinct: $2, Right: $3}
   833    }
   834  | query_expression_parens union_op query_expression_parens
   835    {
   836  	$$ = &Union{Left: $1, Distinct: $2, Right: $3}
   837    }
   838  
   839  select_statement:
   840  query_expression
   841    {
   842  	$$ = $1
   843    }
   844  | query_expression locking_clause
   845    {
   846  	setLockInSelect($1, $2)
   847  	$$ = $1
   848    }
   849  | query_expression_parens
   850    {
   851  	$$ = $1
   852    }
   853  | select_stmt_with_into
   854    {
   855  	$$ = $1
   856    }
   857  
   858  select_stmt_with_into:
   859    openb select_stmt_with_into closeb
   860    {
   861  	$$ = $2;
   862    }
   863  | query_expression into_clause
   864    {
   865  	$1.SetInto($2)
   866  	$$ = $1
   867    }
   868  | query_expression into_clause locking_clause
   869    {
   870  	$1.SetInto($2)
   871  	$1.SetLock($3)
   872  	$$ = $1
   873    }
   874  | query_expression locking_clause into_clause
   875    {
   876  	$1.SetInto($3)
   877  	$1.SetLock($2)
   878  	$$ = $1
   879    }
   880  | query_expression_parens into_clause
   881    {
   882   	$1.SetInto($2)
   883  	$$ = $1
   884    }
   885  
   886  stream_statement:
   887    STREAM comment_opt select_expression FROM table_name
   888    {
   889      $$ = &Stream{Comments: Comments($2).Parsed(), SelectExpr: $3, Table: $5}
   890    }
   891  
   892  vstream_statement:
   893    VSTREAM comment_opt select_expression FROM table_name where_expression_opt limit_opt
   894    {
   895      $$ = &VStream{Comments: Comments($2).Parsed(), SelectExpr: $3, Table: $5, Where: NewWhere(WhereClause, $6), Limit: $7}
   896    }
   897  
   898  // query_primary is an unparenthesized SELECT with no order by clause or beyond.
   899  query_primary:
   900  //  1         2            3              4                    5             6                7           8            9           10
   901    SELECT comment_opt select_options select_expression_list into_clause from_opt where_expression_opt group_by_opt having_opt named_windows_list_opt
   902    {
   903      $$ = NewSelect(Comments($2), $4/*SelectExprs*/, $3/*options*/, $5/*into*/, $6/*from*/, NewWhere(WhereClause, $7), GroupBy($8), NewWhere(HavingClause, $9), $10)
   904    }
   905  | SELECT comment_opt select_options select_expression_list from_opt where_expression_opt group_by_opt having_opt named_windows_list_opt
   906    {
   907      $$ = NewSelect(Comments($2), $4/*SelectExprs*/, $3/*options*/, nil, $5/*from*/, NewWhere(WhereClause, $6), GroupBy($7), NewWhere(HavingClause, $8), $9)
   908    }
   909  
   910  insert_statement:
   911    insert_or_replace comment_opt ignore_opt into_table_name opt_partition_clause insert_data on_dup_opt
   912    {
   913      // insert_data returns a *Insert pre-filled with Columns & Values
   914      ins := $6
   915      ins.Action = $1
   916      ins.Comments = Comments($2).Parsed()
   917      ins.Ignore = $3
   918      ins.Table = $4
   919      ins.Partitions = $5
   920      ins.OnDup = OnDup($7)
   921      $$ = ins
   922    }
   923  | insert_or_replace comment_opt ignore_opt into_table_name opt_partition_clause SET update_list on_dup_opt
   924    {
   925      cols := make(Columns, 0, len($7))
   926      vals := make(ValTuple, 0, len($8))
   927      for _, updateList := range $7 {
   928        cols = append(cols, updateList.Name.Name)
   929        vals = append(vals, updateList.Expr)
   930      }
   931      $$ = &Insert{Action: $1, Comments: Comments($2).Parsed(), Ignore: $3, Table: $4, Partitions: $5, Columns: cols, Rows: Values{vals}, OnDup: OnDup($8)}
   932    }
   933  
   934  insert_or_replace:
   935    INSERT
   936    {
   937      $$ = InsertAct
   938    }
   939  | REPLACE
   940    {
   941      $$ = ReplaceAct
   942    }
   943  
   944  update_statement:
   945    with_clause_opt UPDATE comment_opt ignore_opt table_references SET update_list where_expression_opt order_by_opt limit_opt
   946    {
   947      $$ = &Update{With: $1, Comments: Comments($3).Parsed(), Ignore: $4, TableExprs: $5, Exprs: $7, Where: NewWhere(WhereClause, $8), OrderBy: $9, Limit: $10}
   948    }
   949  
   950  delete_statement:
   951    with_clause_opt DELETE comment_opt ignore_opt FROM table_name as_opt_id opt_partition_clause where_expression_opt order_by_opt limit_opt
   952    {
   953      $$ = &Delete{With: $1, Comments: Comments($3).Parsed(), Ignore: $4, TableExprs: TableExprs{&AliasedTableExpr{Expr:$6, As: $7}}, Partitions: $8, Where: NewWhere(WhereClause, $9), OrderBy: $10, Limit: $11}
   954    }
   955  | with_clause_opt DELETE comment_opt ignore_opt FROM table_name_list USING table_references where_expression_opt
   956    {
   957      $$ = &Delete{With: $1, Comments: Comments($3).Parsed(), Ignore: $4, Targets: $6, TableExprs: $8, Where: NewWhere(WhereClause, $9)}
   958    }
   959  | with_clause_opt DELETE comment_opt ignore_opt table_name_list from_or_using table_references where_expression_opt
   960    {
   961      $$ = &Delete{With: $1, Comments: Comments($3).Parsed(), Ignore: $4, Targets: $5, TableExprs: $7, Where: NewWhere(WhereClause, $8)}
   962    }
   963  | with_clause_opt DELETE comment_opt ignore_opt delete_table_list from_or_using table_references where_expression_opt
   964    {
   965      $$ = &Delete{With: $1, Comments: Comments($3).Parsed(), Ignore: $4, Targets: $5, TableExprs: $7, Where: NewWhere(WhereClause, $8)}
   966    }
   967  
   968  from_or_using:
   969    FROM {}
   970  | USING {}
   971  
   972  view_name_list:
   973    table_name
   974    {
   975      $$ = TableNames{$1.ToViewName()}
   976    }
   977  | view_name_list ',' table_name
   978    {
   979      $$ = append($$, $3.ToViewName())
   980    }
   981  
   982  table_name_list:
   983    table_name
   984    {
   985      $$ = TableNames{$1}
   986    }
   987  | table_name_list ',' table_name
   988    {
   989      $$ = append($$, $3)
   990    }
   991  
   992  delete_table_list:
   993    delete_table_name
   994    {
   995      $$ = TableNames{$1}
   996    }
   997  | delete_table_list ',' delete_table_name
   998    {
   999      $$ = append($$, $3)
  1000    }
  1001  
  1002  opt_partition_clause:
  1003    {
  1004      $$ = nil
  1005    }
  1006  | PARTITION openb partition_list closeb
  1007    {
  1008    $$ = $3
  1009    }
  1010  
  1011  set_statement:
  1012    SET comment_opt set_list
  1013    {
  1014      $$ = NewSetStatement(Comments($2).Parsed(), $3)
  1015    }
  1016  
  1017  set_list:
  1018    set_expression
  1019    {
  1020      $$ = SetExprs{$1}
  1021    }
  1022  | set_list ',' set_expression
  1023    {
  1024      $$ = append($1, $3)
  1025    }
  1026  
  1027  set_expression:
  1028    set_variable '=' ON
  1029    {
  1030      $$ = &SetExpr{Var: $1, Expr: NewStrLiteral("on")}
  1031    }
  1032  | set_variable '=' OFF
  1033    {
  1034      $$ = &SetExpr{Var: $1, Expr: NewStrLiteral("off")}
  1035    }
  1036  | set_variable '=' expression
  1037    {
  1038      $$ = &SetExpr{Var: $1, Expr: $3}
  1039    }
  1040  | charset_or_character_set_or_names charset_value collate_opt
  1041    {
  1042      $$ = &SetExpr{Var: NewSetVariable(string($1), SessionScope), Expr: $2}
  1043    }
  1044  
  1045  set_variable:
  1046    ID
  1047    {
  1048      $$ = NewSetVariable(string($1), SessionScope)
  1049    }
  1050  | variable_expr
  1051    {
  1052      $$ = $1
  1053    }
  1054  | set_session_or_global ID
  1055    {
  1056      $$ = NewSetVariable(string($2), $1)
  1057    }
  1058  
  1059  set_transaction_statement:
  1060    SET comment_opt set_session_or_global TRANSACTION transaction_chars
  1061    {
  1062      $$ = NewSetStatement(Comments($2).Parsed(), UpdateSetExprsScope($5, $3))
  1063    }
  1064  | SET comment_opt TRANSACTION transaction_chars
  1065    {
  1066      $$ = NewSetStatement(Comments($2).Parsed(), $4)
  1067    }
  1068  
  1069  transaction_chars:
  1070    transaction_char
  1071    {
  1072      $$ = SetExprs{$1}
  1073    }
  1074  | transaction_chars ',' transaction_char
  1075    {
  1076      $$ = append($1, $3)
  1077    }
  1078  
  1079  transaction_char:
  1080    ISOLATION LEVEL isolation_level
  1081    {
  1082      $$ = &SetExpr{Var: NewSetVariable(TransactionIsolationStr, NextTxScope), Expr: NewStrLiteral($3)}
  1083    }
  1084  | READ WRITE
  1085    {
  1086      $$ = &SetExpr{Var: NewSetVariable(TransactionReadOnlyStr, NextTxScope), Expr: NewStrLiteral("off")}
  1087    }
  1088  | READ ONLY
  1089    {
  1090      $$ = &SetExpr{Var: NewSetVariable(TransactionReadOnlyStr, NextTxScope), Expr: NewStrLiteral("on")}
  1091    }
  1092  
  1093  isolation_level:
  1094    REPEATABLE READ
  1095    {
  1096      $$ = RepeatableReadStr
  1097    }
  1098  | READ COMMITTED
  1099    {
  1100      $$ = ReadCommittedStr
  1101    }
  1102  | READ UNCOMMITTED
  1103    {
  1104      $$ = ReadUncommittedStr
  1105    }
  1106  | SERIALIZABLE
  1107    {
  1108      $$ = SerializableStr
  1109    }
  1110  
  1111  set_session_or_global:
  1112    SESSION
  1113    {
  1114      $$ = SessionScope
  1115    }
  1116  | LOCAL
  1117    {
  1118      $$ = SessionScope
  1119    }
  1120  | GLOBAL
  1121    {
  1122      $$ = GlobalScope
  1123    }
  1124  
  1125  create_statement:
  1126    create_table_prefix table_spec
  1127    {
  1128      $1.TableSpec = $2
  1129      $1.FullyParsed = true
  1130      $$ = $1
  1131    }
  1132  | create_table_prefix create_like
  1133    {
  1134      // Create table [name] like [name]
  1135      $1.OptLike = $2
  1136      $1.FullyParsed = true
  1137      $$ = $1
  1138    }
  1139  | create_index_prefix '(' index_column_list ')' index_option_list_opt algorithm_lock_opt
  1140    {
  1141      indexDef := $1.AlterOptions[0].(*AddIndexDefinition).IndexDefinition
  1142      indexDef.Columns = $3
  1143      indexDef.Options = append(indexDef.Options,$5...)
  1144      $1.AlterOptions = append($1.AlterOptions,$6...)
  1145      $1.FullyParsed = true
  1146      $$ = $1
  1147    }
  1148  | CREATE comment_opt replace_opt algorithm_view definer_opt security_view_opt VIEW table_name column_list_opt AS select_statement check_option_opt
  1149    {
  1150      $$ = &CreateView{ViewName: $8.ToViewName(), Comments: Comments($2).Parsed(), IsReplace:$3, Algorithm:$4, Definer: $5 ,Security:$6, Columns:$9, Select: $11, CheckOption: $12 }
  1151    }
  1152  | create_database_prefix create_options_opt
  1153    {
  1154      $1.FullyParsed = true
  1155      $1.CreateOptions = $2
  1156      $$ = $1
  1157    }
  1158  
  1159  replace_opt:
  1160    {
  1161      $$ = false
  1162    }
  1163  | OR REPLACE
  1164    {
  1165      $$ = true
  1166    }
  1167  
  1168  vindex_type_opt:
  1169    {
  1170      $$ = NewIdentifierCI("")
  1171    }
  1172  | USING vindex_type
  1173    {
  1174      $$ = $2
  1175    }
  1176  
  1177  vindex_type:
  1178    sql_id
  1179    {
  1180      $$ = $1
  1181    }
  1182  
  1183  vindex_params_opt:
  1184    {
  1185      var v []VindexParam
  1186      $$ = v
  1187    }
  1188  | WITH vindex_param_list
  1189    {
  1190      $$ = $2
  1191    }
  1192  
  1193  vindex_param_list:
  1194    vindex_param
  1195    {
  1196      $$ = make([]VindexParam, 0, 4)
  1197      $$ = append($$, $1)
  1198    }
  1199  | vindex_param_list ',' vindex_param
  1200    {
  1201      $$ = append($$, $3)
  1202    }
  1203  
  1204  vindex_param:
  1205    reserved_sql_id '=' table_opt_value
  1206    {
  1207      $$ = VindexParam{Key: $1, Val: $3}
  1208    }
  1209  
  1210  json_object_param_opt:
  1211    {
  1212      $$ = nil
  1213    }
  1214  | json_object_param_list
  1215    {
  1216      $$ = $1
  1217    }
  1218  
  1219  json_object_param_list:
  1220    json_object_param
  1221    {
  1222      $$ = []*JSONObjectParam{$1}
  1223    }
  1224  | json_object_param_list ',' json_object_param
  1225    {
  1226      $$ = append($$, $3)
  1227    }
  1228  
  1229  json_object_param:
  1230    expression ',' expression
  1231    {
  1232      $$ = &JSONObjectParam{Key:$1, Value:$3}
  1233    }
  1234  
  1235  create_table_prefix:
  1236    CREATE comment_opt temp_opt TABLE not_exists_opt table_name
  1237    {
  1238      $$ = &CreateTable{Comments: Comments($2).Parsed(), Table: $6, IfNotExists: $5, Temp: $3}
  1239      setDDL(yylex, $$)
  1240    }
  1241  
  1242  alter_table_prefix:
  1243    ALTER comment_opt TABLE table_name
  1244    {
  1245      $$ = &AlterTable{Comments: Comments($2).Parsed(), Table: $4}
  1246      setDDL(yylex, $$)
  1247    }
  1248  
  1249  create_index_prefix:
  1250    CREATE comment_opt INDEX ci_identifier using_opt ON table_name
  1251    {
  1252      $$ = &AlterTable{Table: $7, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$4, Type:string($3)}, Options:$5}}}}
  1253      setDDL(yylex, $$)
  1254    }
  1255  | CREATE comment_opt FULLTEXT INDEX ci_identifier using_opt ON table_name
  1256    {
  1257      $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Fulltext:true}, Options:$6}}}}
  1258      setDDL(yylex, $$)
  1259    }
  1260  | CREATE comment_opt SPATIAL INDEX ci_identifier using_opt ON table_name
  1261    {
  1262      $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Spatial:true}, Options:$6}}}}
  1263      setDDL(yylex, $$)
  1264    }
  1265  | CREATE comment_opt UNIQUE INDEX ci_identifier using_opt ON table_name
  1266    {
  1267      $$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type:string($3)+" "+string($4), Unique:true}, Options:$6}}}}
  1268      setDDL(yylex, $$)
  1269    }
  1270  
  1271  create_database_prefix:
  1272    CREATE comment_opt database_or_schema comment_opt not_exists_opt table_id
  1273    {
  1274      $$ = &CreateDatabase{Comments: Comments($4).Parsed(), DBName: $6, IfNotExists: $5}
  1275      setDDL(yylex,$$)
  1276    }
  1277  
  1278  alter_database_prefix:
  1279    ALTER comment_opt database_or_schema
  1280    {
  1281      $$ = &AlterDatabase{}
  1282      setDDL(yylex,$$)
  1283    }
  1284  
  1285  database_or_schema:
  1286    DATABASE
  1287  | SCHEMA
  1288  
  1289  table_spec:
  1290    '(' table_column_list ')' table_option_list_opt partitions_options_opt
  1291    {
  1292      $$ = $2
  1293      $$.Options = $4
  1294      $$.PartitionOption = $5
  1295    }
  1296  
  1297  create_options_opt:
  1298    {
  1299      $$ = nil
  1300    }
  1301  | create_options
  1302    {
  1303      $$ = $1
  1304    }
  1305  
  1306  create_options:
  1307    character_set
  1308    {
  1309      $$ = []DatabaseOption{$1}
  1310    }
  1311  | collate
  1312    {
  1313      $$ = []DatabaseOption{$1}
  1314    }
  1315  | encryption
  1316    {
  1317      $$ = []DatabaseOption{$1}
  1318    }
  1319  | create_options collate
  1320    {
  1321      $$ = append($1,$2)
  1322    }
  1323  | create_options character_set
  1324    {
  1325      $$ = append($1,$2)
  1326    }
  1327  | create_options encryption
  1328    {
  1329      $$ = append($1,$2)
  1330    }
  1331  
  1332  default_optional:
  1333    /* empty */ %prec LOWER_THAN_CHARSET
  1334    {
  1335      $$ = false
  1336    }
  1337  | DEFAULT
  1338    {
  1339      $$ = true
  1340    }
  1341  
  1342  character_set:
  1343    default_optional charset_or_character_set equal_opt ID
  1344    {
  1345      $$ = DatabaseOption{Type:CharacterSetType, Value:string($4), IsDefault:$1}
  1346    }
  1347  | default_optional charset_or_character_set equal_opt STRING
  1348    {
  1349      $$ = DatabaseOption{Type:CharacterSetType, Value:encodeSQLString($4), IsDefault:$1}
  1350    }
  1351  
  1352  collate:
  1353    default_optional COLLATE equal_opt ID
  1354    {
  1355      $$ = DatabaseOption{Type:CollateType, Value:string($4), IsDefault:$1}
  1356    }
  1357  | default_optional COLLATE equal_opt STRING
  1358    {
  1359      $$ = DatabaseOption{Type:CollateType, Value:encodeSQLString($4), IsDefault:$1}
  1360    }
  1361  
  1362  encryption:
  1363    default_optional ENCRYPTION equal_opt ID
  1364    {
  1365      $$ = DatabaseOption{Type:EncryptionType, Value:string($4), IsDefault:$1}
  1366    }
  1367  | default_optional ENCRYPTION equal_opt STRING
  1368    {
  1369      $$ = DatabaseOption{Type:EncryptionType, Value:encodeSQLString($4), IsDefault:$1}
  1370    }
  1371  
  1372  create_like:
  1373    LIKE table_name
  1374    {
  1375      $$ = &OptLike{LikeTable: $2}
  1376    }
  1377  | '(' LIKE table_name ')'
  1378    {
  1379      $$ = &OptLike{LikeTable: $3}
  1380    }
  1381  
  1382  column_definition_list:
  1383    column_definition
  1384    {
  1385      $$ = []*ColumnDefinition{$1}
  1386    }
  1387  | column_definition_list ',' column_definition
  1388    {
  1389      $$ = append($1,$3)
  1390    }
  1391  
  1392  table_column_list:
  1393    column_definition
  1394    {
  1395      $$ = &TableSpec{}
  1396      $$.AddColumn($1)
  1397    }
  1398  | check_constraint_definition
  1399    {
  1400      $$ = &TableSpec{}
  1401      $$.AddConstraint($1)
  1402    }
  1403  | table_column_list ',' column_definition
  1404    {
  1405      $$.AddColumn($3)
  1406    }
  1407  | table_column_list ',' column_definition check_constraint_definition
  1408    {
  1409      $$.AddColumn($3)
  1410      $$.AddConstraint($4)
  1411    }
  1412  | table_column_list ',' index_definition
  1413    {
  1414      $$.AddIndex($3)
  1415    }
  1416  | table_column_list ',' constraint_definition
  1417    {
  1418      $$.AddConstraint($3)
  1419    }
  1420  | table_column_list ',' check_constraint_definition
  1421    {
  1422      $$.AddConstraint($3)
  1423    }
  1424  
  1425  // collate_opt has to be in the first rule so that we don't have a shift reduce conflict when seeing a COLLATE
  1426  // with column_attribute_list_opt. Always shifting there would have meant that we would have always ended up using the
  1427  // second rule in the grammar whenever COLLATE was specified.
  1428  // We now have a shift reduce conflict between COLLATE and collate_opt. Shifting there is fine. Essentially, we have
  1429  // postponed the decision of which rule to use until we have consumed the COLLATE id/string tokens.
  1430  column_definition:
  1431    sql_id column_type collate_opt column_attribute_list_opt reference_definition_opt
  1432    {
  1433      $2.Options = $4
  1434      if $2.Options.Collate == "" {
  1435      	$2.Options.Collate = $3
  1436      }
  1437      $2.Options.Reference = $5
  1438      $$ = &ColumnDefinition{Name: $1, Type: $2}
  1439    }
  1440  | sql_id column_type collate_opt generated_always_opt AS '(' expression ')' generated_column_attribute_list_opt reference_definition_opt
  1441    {
  1442      $2.Options = $9
  1443      $2.Options.As = $7
  1444      $2.Options.Reference = $10
  1445      $2.Options.Collate = $3
  1446      $$ = &ColumnDefinition{Name: $1, Type: $2}
  1447    }
  1448  
  1449  generated_always_opt:
  1450    {
  1451      $$ = ""
  1452    }
  1453  |  GENERATED ALWAYS
  1454    {
  1455      $$ = ""
  1456    }
  1457  
  1458  // There is a shift reduce conflict that arises here because UNIQUE and KEY are column_type_option and so is UNIQUE KEY.
  1459  // So in the state "column_type_options UNIQUE. KEY" there is a shift-reduce conflict(resovled by "%rigth <str> UNIQUE KEY").
  1460  // This has been added to emulate what MySQL does. The previous architecture was such that the order of the column options
  1461  // was specific (as stated in the MySQL guide) and did not accept arbitrary order options. For example NOT NULL DEFAULT 1 and not DEFAULT 1 NOT NULL
  1462  column_attribute_list_opt:
  1463    {
  1464      $$ = &ColumnTypeOptions{Null: nil, Default: nil, OnUpdate: nil, Autoincrement: false, KeyOpt: ColKeyNone, Comment: nil, As: nil, Invisible: nil, Format: UnspecifiedFormat, EngineAttribute: nil, SecondaryEngineAttribute: nil }
  1465    }
  1466  | column_attribute_list_opt NULL
  1467    {
  1468      val := true
  1469      $1.Null = &val
  1470      $$ = $1
  1471    }
  1472  | column_attribute_list_opt NOT NULL
  1473    {
  1474      val := false
  1475      $1.Null = &val
  1476      $$ = $1
  1477    }
  1478  | column_attribute_list_opt DEFAULT openb expression closeb
  1479    {
  1480  	$1.Default = $4
  1481  	$$ = $1
  1482    }
  1483  | column_attribute_list_opt DEFAULT now_or_signed_literal
  1484    {
  1485      $1.Default = $3
  1486      $$ = $1
  1487    }
  1488  | column_attribute_list_opt ON UPDATE function_call_nonkeyword
  1489    {
  1490      $1.OnUpdate = $4
  1491      $$ = $1
  1492    }
  1493  | column_attribute_list_opt AUTO_INCREMENT
  1494    {
  1495      $1.Autoincrement = true
  1496      $$ = $1
  1497    }
  1498  | column_attribute_list_opt COMMENT_KEYWORD STRING
  1499    {
  1500      $1.Comment = NewStrLiteral($3)
  1501      $$ = $1
  1502    }
  1503  | column_attribute_list_opt keys
  1504    {
  1505      $1.KeyOpt = $2
  1506      $$ = $1
  1507    }
  1508  | column_attribute_list_opt COLLATE STRING
  1509    {
  1510      $1.Collate = encodeSQLString($3)
  1511    }
  1512  | column_attribute_list_opt COLLATE ci_identifier
  1513    {
  1514      $1.Collate = string($3.String())
  1515      $$ = $1
  1516    }
  1517  | column_attribute_list_opt COLUMN_FORMAT column_format
  1518    {
  1519      $1.Format = $3
  1520    }
  1521  | column_attribute_list_opt SRID INTEGRAL
  1522    {
  1523      $1.SRID = NewIntLiteral($3)
  1524      $$ = $1
  1525    }
  1526  | column_attribute_list_opt VISIBLE
  1527    {
  1528      val := false
  1529      $1.Invisible = &val
  1530      $$ = $1
  1531    }
  1532  | column_attribute_list_opt INVISIBLE
  1533    {
  1534      val := true
  1535      $1.Invisible = &val
  1536      $$ = $1
  1537    }
  1538  | column_attribute_list_opt ENGINE_ATTRIBUTE equal_opt STRING
  1539    {
  1540      $1.EngineAttribute = NewStrLiteral($4)
  1541    }
  1542  | column_attribute_list_opt SECONDARY_ENGINE_ATTRIBUTE equal_opt STRING
  1543    {
  1544      $1.SecondaryEngineAttribute = NewStrLiteral($4)
  1545    }
  1546  
  1547  column_format:
  1548    FIXED
  1549  {
  1550    $$ = FixedFormat
  1551  }
  1552  | DYNAMIC
  1553  {
  1554    $$ = DynamicFormat
  1555  }
  1556  | DEFAULT
  1557  {
  1558    $$ = DefaultFormat
  1559  }
  1560  
  1561  column_storage:
  1562    VIRTUAL
  1563  {
  1564    $$ = VirtualStorage
  1565  }
  1566  | STORED
  1567  {
  1568    $$ = StoredStorage
  1569  }
  1570  
  1571  generated_column_attribute_list_opt:
  1572    {
  1573      $$ = &ColumnTypeOptions{}
  1574    }
  1575  | generated_column_attribute_list_opt column_storage
  1576    {
  1577      $1.Storage = $2
  1578      $$ = $1
  1579    }
  1580  | generated_column_attribute_list_opt NULL
  1581    {
  1582      val := true
  1583      $1.Null = &val
  1584      $$ = $1
  1585    }
  1586  | generated_column_attribute_list_opt NOT NULL
  1587    {
  1588      val := false
  1589      $1.Null = &val
  1590      $$ = $1
  1591    }
  1592  | generated_column_attribute_list_opt COMMENT_KEYWORD STRING
  1593    {
  1594      $1.Comment = NewStrLiteral($3)
  1595      $$ = $1
  1596    }
  1597  | generated_column_attribute_list_opt keys
  1598    {
  1599      $1.KeyOpt = $2
  1600      $$ = $1
  1601    }
  1602  | generated_column_attribute_list_opt VISIBLE
  1603    {
  1604      val := false
  1605      $1.Invisible = &val
  1606      $$ = $1
  1607    }
  1608  | generated_column_attribute_list_opt INVISIBLE
  1609    {
  1610      val := true
  1611      $1.Invisible = &val
  1612      $$ = $1
  1613    }
  1614  
  1615  now_or_signed_literal:
  1616  now
  1617    {
  1618    	$$ = $1
  1619    }
  1620  | signed_literal_or_null
  1621  
  1622  now:
  1623  CURRENT_TIMESTAMP func_datetime_precision
  1624    {
  1625      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("current_timestamp"), Fsp: $2}
  1626    }
  1627  | LOCALTIME func_datetime_precision
  1628    {
  1629      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("localtime"), Fsp: $2}
  1630    }
  1631  | LOCALTIMESTAMP func_datetime_precision
  1632    {
  1633      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("localtimestamp"), Fsp: $2}
  1634    }
  1635  | UTC_TIMESTAMP func_datetime_precision
  1636    {
  1637      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("utc_timestamp"), Fsp:$2}
  1638    }
  1639  | NOW func_datetime_precision
  1640    {
  1641      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("now"), Fsp: $2}
  1642    }
  1643  
  1644  signed_literal_or_null:
  1645  signed_literal
  1646  | null_as_literal
  1647  
  1648   null_as_literal:
  1649  NULL
  1650   {
  1651      $$ = &NullVal{}
  1652   }
  1653  
  1654   signed_literal:
  1655   literal
  1656  | '+' NUM_literal
  1657     {
  1658   	$$= $2
  1659     }
  1660  | '-' NUM_literal
  1661     {
  1662     	$$ = &UnaryExpr{Operator: UMinusOp, Expr: $2}
  1663     }
  1664  
  1665  literal:
  1666  text_literal
  1667    {
  1668     $$= $1
  1669    }
  1670  | NUM_literal
  1671    {
  1672    	$$= $1
  1673    }
  1674  | boolean_value
  1675    {
  1676    	$$ = $1
  1677    }
  1678  | HEX
  1679    {
  1680  	$$ = NewHexLiteral($1)
  1681    }
  1682  | HEXNUM
  1683    {
  1684    	$$ = NewHexNumLiteral($1)
  1685    }
  1686  | BITNUM
  1687    {
  1688    	$$ = NewBitLiteral($1[2:])
  1689    }
  1690  | BIT_LITERAL
  1691    {
  1692  	$$ = NewBitLiteral($1)
  1693    }
  1694  | VALUE_ARG
  1695    {
  1696      $$ = NewArgument($1[1:])
  1697      bindVariable(yylex, $1[1:])
  1698    }
  1699  | underscore_charsets BIT_LITERAL %prec UNARY
  1700    {
  1701    	$$ = &IntroducerExpr{CharacterSet: $1, Expr: NewBitLiteral($2)}
  1702    }
  1703  | underscore_charsets HEXNUM %prec UNARY
  1704    {
  1705    	$$ = &IntroducerExpr{CharacterSet: $1, Expr: NewHexNumLiteral($2)}
  1706    }
  1707  | underscore_charsets BITNUM %prec UNARY
  1708    {
  1709    	$$ = &IntroducerExpr{CharacterSet: $1, Expr: NewBitLiteral($2[2:])}
  1710    }
  1711  | underscore_charsets HEX %prec UNARY
  1712    {
  1713     	$$ = &IntroducerExpr{CharacterSet: $1, Expr: NewHexLiteral($2)}
  1714    }
  1715  | underscore_charsets column_name_or_offset %prec UNARY
  1716    {
  1717      $$ = &IntroducerExpr{CharacterSet: $1, Expr: $2}
  1718    }
  1719  | underscore_charsets VALUE_ARG %prec UNARY
  1720    {
  1721      bindVariable(yylex, $2[1:])
  1722      $$ = &IntroducerExpr{CharacterSet: $1, Expr: NewArgument($2[1:])}
  1723    }
  1724  | DATE STRING
  1725    {
  1726    $$ = NewDateLiteral($2)
  1727    }
  1728  | TIME STRING
  1729    {
  1730    $$ = NewTimeLiteral($2)
  1731    }
  1732  | TIMESTAMP STRING
  1733    {
  1734    $$ = NewTimestampLiteral($2)
  1735    }
  1736  
  1737  underscore_charsets:
  1738    UNDERSCORE_ARMSCII8
  1739    {
  1740      $$ = Armscii8Str
  1741    }
  1742  | UNDERSCORE_ASCII
  1743    {
  1744      $$ = ASCIIStr
  1745    }
  1746  | UNDERSCORE_BIG5
  1747    {
  1748      $$ = Big5Str
  1749    }
  1750  | UNDERSCORE_BINARY
  1751    {
  1752      $$ = UBinaryStr
  1753    }
  1754  | UNDERSCORE_CP1250
  1755    {
  1756      $$ = Cp1250Str
  1757    }
  1758  | UNDERSCORE_CP1251
  1759    {
  1760      $$ = Cp1251Str
  1761    }
  1762  | UNDERSCORE_CP1256
  1763    {
  1764      $$ = Cp1256Str
  1765    }
  1766  | UNDERSCORE_CP1257
  1767    {
  1768      $$ = Cp1257Str
  1769    }
  1770  | UNDERSCORE_CP850
  1771    {
  1772      $$ = Cp850Str
  1773    }
  1774  | UNDERSCORE_CP852
  1775    {
  1776      $$ = Cp852Str
  1777    }
  1778  | UNDERSCORE_CP866
  1779    {
  1780      $$ = Cp866Str
  1781    }
  1782  | UNDERSCORE_CP932
  1783    {
  1784      $$ = Cp932Str
  1785    }
  1786  | UNDERSCORE_DEC8
  1787    {
  1788      $$ = Dec8Str
  1789    }
  1790  | UNDERSCORE_EUCJPMS
  1791    {
  1792      $$ = EucjpmsStr
  1793    }
  1794  | UNDERSCORE_EUCKR
  1795    {
  1796      $$ = EuckrStr
  1797    }
  1798  | UNDERSCORE_GB18030
  1799    {
  1800      $$ = Gb18030Str
  1801    }
  1802  | UNDERSCORE_GB2312
  1803    {
  1804      $$ = Gb2312Str
  1805    }
  1806  | UNDERSCORE_GBK
  1807    {
  1808      $$ = GbkStr
  1809    }
  1810  | UNDERSCORE_GEOSTD8
  1811    {
  1812      $$ = Geostd8Str
  1813    }
  1814  | UNDERSCORE_GREEK
  1815    {
  1816      $$ = GreekStr
  1817    }
  1818  | UNDERSCORE_HEBREW
  1819    {
  1820      $$ = HebrewStr
  1821    }
  1822  | UNDERSCORE_HP8
  1823    {
  1824      $$ = Hp8Str
  1825    }
  1826  | UNDERSCORE_KEYBCS2
  1827    {
  1828      $$ = Keybcs2Str
  1829    }
  1830  | UNDERSCORE_KOI8R
  1831    {
  1832      $$ = Koi8rStr
  1833    }
  1834  | UNDERSCORE_KOI8U
  1835    {
  1836      $$ = Koi8uStr
  1837    }
  1838  | UNDERSCORE_LATIN1
  1839    {
  1840      $$ = Latin1Str
  1841    }
  1842  | UNDERSCORE_LATIN2
  1843    {
  1844      $$ = Latin2Str
  1845    }
  1846  | UNDERSCORE_LATIN5
  1847    {
  1848      $$ = Latin5Str
  1849    }
  1850  | UNDERSCORE_LATIN7
  1851    {
  1852      $$ = Latin7Str
  1853    }
  1854  | UNDERSCORE_MACCE
  1855    {
  1856      $$ = MacceStr
  1857    }
  1858  | UNDERSCORE_MACROMAN
  1859    {
  1860      $$ = MacromanStr
  1861    }
  1862  | UNDERSCORE_SJIS
  1863    {
  1864      $$ = SjisStr
  1865    }
  1866  | UNDERSCORE_SWE7
  1867    {
  1868      $$ = Swe7Str
  1869    }
  1870  | UNDERSCORE_TIS620
  1871    {
  1872      $$ = Tis620Str
  1873    }
  1874  | UNDERSCORE_UCS2
  1875    {
  1876      $$ = Ucs2Str
  1877    }
  1878  | UNDERSCORE_UJIS
  1879    {
  1880      $$ = UjisStr
  1881    }
  1882  | UNDERSCORE_UTF16
  1883    {
  1884      $$ = Utf16Str
  1885    }
  1886  | UNDERSCORE_UTF16LE
  1887    {
  1888      $$ = Utf16leStr
  1889    }
  1890  | UNDERSCORE_UTF32
  1891    {
  1892      $$ = Utf32Str
  1893    }
  1894  | UNDERSCORE_UTF8
  1895    {
  1896      $$ = Utf8Str
  1897    }
  1898  | UNDERSCORE_UTF8MB4
  1899    {
  1900      $$ = Utf8mb4Str
  1901    }
  1902  | UNDERSCORE_UTF8MB3
  1903    {
  1904      $$ = Utf8Str
  1905    }
  1906  
  1907  literal_or_null:
  1908  literal
  1909  | null_as_literal
  1910  
  1911  NUM_literal:
  1912  INTEGRAL
  1913    {
  1914      $$ = NewIntLiteral($1)
  1915    }
  1916  | FLOAT
  1917    {
  1918      $$ = NewFloatLiteral($1)
  1919    }
  1920  | DECIMAL
  1921    {
  1922      $$ = NewDecimalLiteral($1)
  1923    }
  1924  
  1925  text_literal:
  1926  STRING
  1927    {
  1928  	$$ = NewStrLiteral($1)
  1929    }
  1930  | NCHAR_STRING
  1931    {
  1932  	$$ = &UnaryExpr{Operator: NStringOp, Expr: NewStrLiteral($1)}
  1933    }
  1934   | underscore_charsets STRING %prec UNARY
  1935     {
  1936     	$$ = &IntroducerExpr{CharacterSet: $1, Expr: NewStrLiteral($2)}
  1937     }
  1938  
  1939  text_literal_or_arg:
  1940    text_literal
  1941    {
  1942      $$ = $1
  1943    }
  1944  | VALUE_ARG
  1945    {
  1946      $$ = NewArgument($1[1:])
  1947      bindVariable(yylex, $1[1:])
  1948    }
  1949  
  1950  keys:
  1951    PRIMARY KEY
  1952    {
  1953      $$ = ColKeyPrimary
  1954    }
  1955  | UNIQUE
  1956    {
  1957      $$ = ColKeyUnique
  1958    }
  1959  | UNIQUE KEY
  1960    {
  1961      $$ = ColKeyUniqueKey
  1962    }
  1963  | KEY
  1964    {
  1965      $$ = ColKey
  1966    }
  1967  
  1968  column_type:
  1969    numeric_type unsigned_opt zero_fill_opt
  1970    {
  1971      $$ = $1
  1972      $$.Unsigned = $2
  1973      $$.Zerofill = $3
  1974    }
  1975  | char_type
  1976  | time_type
  1977  | spatial_type
  1978  
  1979  numeric_type:
  1980    int_type length_opt
  1981    {
  1982      $$ = $1
  1983      $$.Length = $2
  1984    }
  1985  | decimal_type
  1986    {
  1987      $$ = $1
  1988    }
  1989  
  1990  int_type:
  1991    BIT
  1992    {
  1993      $$ = &ColumnType{Type: string($1)}
  1994    }
  1995  | BOOL
  1996    {
  1997      $$ = &ColumnType{Type: string($1)}
  1998    }
  1999  | BOOLEAN
  2000    {
  2001      $$ = &ColumnType{Type: string($1)}
  2002    }
  2003  | TINYINT
  2004    {
  2005      $$ = &ColumnType{Type: string($1)}
  2006    }
  2007  | SMALLINT
  2008    {
  2009      $$ = &ColumnType{Type: string($1)}
  2010    }
  2011  | MEDIUMINT
  2012    {
  2013      $$ = &ColumnType{Type: string($1)}
  2014    }
  2015  | INT
  2016    {
  2017      $$ = &ColumnType{Type: string($1)}
  2018    }
  2019  | INTEGER
  2020    {
  2021      $$ = &ColumnType{Type: string($1)}
  2022    }
  2023  | BIGINT
  2024    {
  2025      $$ = &ColumnType{Type: string($1)}
  2026    }
  2027  
  2028  decimal_type:
  2029  REAL double_length_opt
  2030    {
  2031      $$ = &ColumnType{Type: string($1)}
  2032      $$.Length = $2.Length
  2033      $$.Scale = $2.Scale
  2034    }
  2035  | DOUBLE double_length_opt
  2036    {
  2037      $$ = &ColumnType{Type: string($1)}
  2038      $$.Length = $2.Length
  2039      $$.Scale = $2.Scale
  2040    }
  2041  | FLOAT8_TYPE double_length_opt
  2042    {
  2043      $$ = &ColumnType{Type: string($1)}
  2044      $$.Length = $2.Length
  2045      $$.Scale = $2.Scale
  2046    }
  2047  | FLOAT_TYPE float_length_opt
  2048    {
  2049      $$ = &ColumnType{Type: string($1)}
  2050      $$.Length = $2.Length
  2051      $$.Scale = $2.Scale
  2052    }
  2053  | FLOAT4_TYPE float_length_opt
  2054    {
  2055      $$ = &ColumnType{Type: string($1)}
  2056      $$.Length = $2.Length
  2057      $$.Scale = $2.Scale
  2058    }
  2059  | DECIMAL_TYPE decimal_length_opt
  2060    {
  2061      $$ = &ColumnType{Type: string($1)}
  2062      $$.Length = $2.Length
  2063      $$.Scale = $2.Scale
  2064    }
  2065  | NUMERIC decimal_length_opt
  2066    {
  2067      $$ = &ColumnType{Type: string($1)}
  2068      $$.Length = $2.Length
  2069      $$.Scale = $2.Scale
  2070    }
  2071  
  2072  time_type:
  2073    DATE
  2074    {
  2075      $$ = &ColumnType{Type: string($1)}
  2076    }
  2077  | TIME length_opt
  2078    {
  2079      $$ = &ColumnType{Type: string($1), Length: $2}
  2080    }
  2081  | TIMESTAMP length_opt
  2082    {
  2083      $$ = &ColumnType{Type: string($1), Length: $2}
  2084    }
  2085  | DATETIME length_opt
  2086    {
  2087      $$ = &ColumnType{Type: string($1), Length: $2}
  2088    }
  2089  | YEAR length_opt
  2090    {
  2091      $$ = &ColumnType{Type: string($1), Length: $2}
  2092    }
  2093  
  2094  char_type:
  2095    CHAR length_opt charset_opt
  2096    {
  2097      $$ = &ColumnType{Type: string($1), Length: $2, Charset: $3}
  2098    }
  2099  | CHAR length_opt BYTE
  2100    {
  2101      // CHAR BYTE is an alias for binary. See also:
  2102      // https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html
  2103      $$ = &ColumnType{Type: "binary", Length: $2}
  2104    }
  2105  | VARCHAR length_opt charset_opt
  2106    {
  2107      $$ = &ColumnType{Type: string($1), Length: $2, Charset: $3}
  2108    }
  2109  | BINARY length_opt
  2110    {
  2111      $$ = &ColumnType{Type: string($1), Length: $2}
  2112    }
  2113  | VARBINARY length_opt
  2114    {
  2115      $$ = &ColumnType{Type: string($1), Length: $2}
  2116    }
  2117  | TEXT charset_opt
  2118    {
  2119      $$ = &ColumnType{Type: string($1), Charset: $2}
  2120    }
  2121  | TINYTEXT charset_opt
  2122    {
  2123      $$ = &ColumnType{Type: string($1), Charset: $2}
  2124    }
  2125  | MEDIUMTEXT charset_opt
  2126    {
  2127      $$ = &ColumnType{Type: string($1), Charset: $2}
  2128    }
  2129  | LONGTEXT charset_opt
  2130    {
  2131      $$ = &ColumnType{Type: string($1), Charset: $2}
  2132    }
  2133  | BLOB
  2134    {
  2135      $$ = &ColumnType{Type: string($1)}
  2136    }
  2137  | TINYBLOB
  2138    {
  2139      $$ = &ColumnType{Type: string($1)}
  2140    }
  2141  | MEDIUMBLOB
  2142    {
  2143      $$ = &ColumnType{Type: string($1)}
  2144    }
  2145  | LONGBLOB
  2146    {
  2147      $$ = &ColumnType{Type: string($1)}
  2148    }
  2149  | JSON
  2150    {
  2151      $$ = &ColumnType{Type: string($1)}
  2152    }
  2153  | ENUM '(' enum_values ')' charset_opt
  2154    {
  2155      $$ = &ColumnType{Type: string($1), EnumValues: $3, Charset: $5}
  2156    }
  2157  // need set_values / SetValues ?
  2158  | SET '(' enum_values ')' charset_opt
  2159    {
  2160      $$ = &ColumnType{Type: string($1), EnumValues: $3, Charset: $5}
  2161    }
  2162  
  2163  spatial_type:
  2164    GEOMETRY
  2165    {
  2166      $$ = &ColumnType{Type: string($1)}
  2167    }
  2168  | POINT
  2169    {
  2170      $$ = &ColumnType{Type: string($1)}
  2171    }
  2172  | LINESTRING
  2173    {
  2174      $$ = &ColumnType{Type: string($1)}
  2175    }
  2176  | POLYGON
  2177    {
  2178      $$ = &ColumnType{Type: string($1)}
  2179    }
  2180  | GEOMETRYCOLLECTION
  2181    {
  2182      $$ = &ColumnType{Type: string($1)}
  2183    }
  2184  | MULTIPOINT
  2185    {
  2186      $$ = &ColumnType{Type: string($1)}
  2187    }
  2188  | MULTILINESTRING
  2189    {
  2190      $$ = &ColumnType{Type: string($1)}
  2191    }
  2192  | MULTIPOLYGON
  2193    {
  2194      $$ = &ColumnType{Type: string($1)}
  2195    }
  2196  
  2197  enum_values:
  2198    STRING
  2199    {
  2200      $$ = make([]string, 0, 4)
  2201      $$ = append($$, encodeSQLString($1))
  2202    }
  2203  | enum_values ',' STRING
  2204    {
  2205      $$ = append($1, encodeSQLString($3))
  2206    }
  2207  
  2208  length_opt:
  2209    {
  2210      $$ = nil
  2211    }
  2212  | '(' INTEGRAL ')'
  2213    {
  2214      $$ = NewIntLiteral($2)
  2215    }
  2216  
  2217  double_length_opt:
  2218    {
  2219      $$ = LengthScaleOption{}
  2220    }
  2221  | '(' INTEGRAL ',' INTEGRAL ')'
  2222    {
  2223      $$ = LengthScaleOption{
  2224          Length: NewIntLiteral($2),
  2225          Scale: NewIntLiteral($4),
  2226      }
  2227    }
  2228  
  2229  float_length_opt:
  2230  double_length_opt
  2231    {
  2232      $$ = $1
  2233    }
  2234  | '(' INTEGRAL ')'
  2235    {
  2236      $$ = LengthScaleOption{
  2237          Length: NewIntLiteral($2),
  2238      }
  2239    }
  2240  
  2241  decimal_length_opt:
  2242    {
  2243      $$ = LengthScaleOption{}
  2244    }
  2245  | '(' INTEGRAL ')'
  2246    {
  2247      $$ = LengthScaleOption{
  2248          Length: NewIntLiteral($2),
  2249      }
  2250    }
  2251  | '(' INTEGRAL ',' INTEGRAL ')'
  2252    {
  2253      $$ = LengthScaleOption{
  2254          Length: NewIntLiteral($2),
  2255          Scale: NewIntLiteral($4),
  2256      }
  2257    }
  2258  
  2259  unsigned_opt:
  2260    {
  2261      $$ = false
  2262    }
  2263  | UNSIGNED
  2264    {
  2265      $$ = true
  2266    }
  2267  | SIGNED
  2268    {
  2269      $$ = false
  2270    }
  2271  
  2272  zero_fill_opt:
  2273    {
  2274      $$ = false
  2275    }
  2276  | ZEROFILL
  2277    {
  2278      $$ = true
  2279    }
  2280  
  2281  charset_opt:
  2282    {
  2283      $$ = ColumnCharset{}
  2284    }
  2285  | charset_or_character_set sql_id binary_opt
  2286    {
  2287      $$ = ColumnCharset{Name: string($2.String()), Binary: $3}
  2288    }
  2289  | charset_or_character_set STRING binary_opt
  2290    {
  2291      $$ = ColumnCharset{Name: encodeSQLString($2), Binary: $3}
  2292    }
  2293  | charset_or_character_set BINARY
  2294    {
  2295      $$ = ColumnCharset{Name: string($2)}
  2296    }
  2297  | ASCII binary_opt
  2298    {
  2299      // ASCII: Shorthand for CHARACTER SET latin1.
  2300      $$ = ColumnCharset{Name: "latin1", Binary: $2}
  2301    }
  2302  | UNICODE binary_opt
  2303    {
  2304      // UNICODE: Shorthand for CHARACTER SET ucs2.
  2305      $$ = ColumnCharset{Name: "ucs2", Binary: $2}
  2306    }
  2307  | BINARY
  2308    {
  2309      // BINARY: Shorthand for default CHARACTER SET but with binary collation
  2310      $$ = ColumnCharset{Name: "", Binary: true}
  2311    }
  2312  | BINARY ASCII
  2313    {
  2314      // BINARY ASCII: Shorthand for CHARACTER SET latin1 with binary collation
  2315      $$ = ColumnCharset{Name: "latin1", Binary: true}
  2316    }
  2317  | BINARY UNICODE
  2318    {
  2319      // BINARY UNICODE: Shorthand for CHARACTER SET ucs2 with binary collation
  2320      $$ = ColumnCharset{Name: "ucs2", Binary: true}
  2321    }
  2322  
  2323  binary_opt:
  2324    {
  2325      $$ = false
  2326    }
  2327  | BINARY
  2328    {
  2329      $$ = true
  2330    }
  2331  
  2332  collate_opt:
  2333    {
  2334      $$ = ""
  2335    }
  2336  | COLLATE ci_identifier
  2337    {
  2338      $$ = string($2.String())
  2339    }
  2340  | COLLATE STRING
  2341    {
  2342      $$ = encodeSQLString($2)
  2343    }
  2344  
  2345  index_definition:
  2346    index_info '(' index_column_list ')' index_option_list_opt
  2347    {
  2348      $$ = &IndexDefinition{Info: $1, Columns: $3, Options: $5}
  2349    }
  2350  
  2351  index_option_list_opt:
  2352    {
  2353      $$ = nil
  2354    }
  2355  | index_option_list
  2356    {
  2357      $$ = $1
  2358    }
  2359  
  2360  index_option_list:
  2361    index_option
  2362    {
  2363      $$ = []*IndexOption{$1}
  2364    }
  2365  | index_option_list index_option
  2366    {
  2367      $$ = append($$, $2)
  2368    }
  2369  
  2370  index_option:
  2371    using_index_type
  2372    {
  2373      $$ = $1
  2374    }
  2375  | KEY_BLOCK_SIZE equal_opt INTEGRAL
  2376    {
  2377      // should not be string
  2378      $$ = &IndexOption{Name: string($1), Value: NewIntLiteral($3)}
  2379    }
  2380  | COMMENT_KEYWORD STRING
  2381    {
  2382      $$ = &IndexOption{Name: string($1), Value: NewStrLiteral($2)}
  2383    }
  2384  | VISIBLE
  2385    {
  2386      $$ = &IndexOption{Name: string($1) }
  2387    }
  2388  | INVISIBLE
  2389    {
  2390      $$ = &IndexOption{Name: string($1) }
  2391    }
  2392  | WITH PARSER ci_identifier
  2393    {
  2394      $$ = &IndexOption{Name: string($1) + " " + string($2), String: $3.String()}
  2395    }
  2396  | ENGINE_ATTRIBUTE equal_opt STRING
  2397    {
  2398      $$ = &IndexOption{Name: string($1), Value: NewStrLiteral($3)}
  2399    }
  2400  | SECONDARY_ENGINE_ATTRIBUTE equal_opt STRING
  2401    {
  2402      $$ = &IndexOption{Name: string($1), Value: NewStrLiteral($3)}
  2403    }
  2404  
  2405  equal_opt:
  2406    /* empty */
  2407    {
  2408      $$ = ""
  2409    }
  2410  | '='
  2411    {
  2412      $$ = string($1)
  2413    }
  2414  
  2415  index_info:
  2416    constraint_name_opt PRIMARY KEY name_opt
  2417    {
  2418      $$ = &IndexInfo{Type: string($2) + " " + string($3), ConstraintName: NewIdentifierCI($1), Name: NewIdentifierCI("PRIMARY"), Primary: true, Unique: true}
  2419    }
  2420  | SPATIAL index_or_key_opt name_opt
  2421    {
  2422      $$ = &IndexInfo{Type: string($1) + " " + string($2), Name: NewIdentifierCI($3), Spatial: true, Unique: false}
  2423    }
  2424  | FULLTEXT index_or_key_opt name_opt
  2425    {
  2426      $$ = &IndexInfo{Type: string($1) + " " + string($2), Name: NewIdentifierCI($3), Fulltext: true, Unique: false}
  2427    }
  2428  | constraint_name_opt UNIQUE index_or_key_opt name_opt
  2429    {
  2430      $$ = &IndexInfo{Type: string($2) + " " + string($3), ConstraintName: NewIdentifierCI($1), Name: NewIdentifierCI($4), Unique: true}
  2431    }
  2432  | index_or_key name_opt
  2433    {
  2434      $$ = &IndexInfo{Type: string($1), Name: NewIdentifierCI($2), Unique: false}
  2435    }
  2436  
  2437  constraint_name_opt:
  2438    {
  2439      $$ = ""
  2440    }
  2441  | CONSTRAINT name_opt
  2442    {
  2443      $$ = $2
  2444    }
  2445  
  2446  index_symbols:
  2447    INDEX
  2448    {
  2449      $$ = string($1)
  2450    }
  2451  | KEYS
  2452    {
  2453      $$ = string($1)
  2454    }
  2455  | INDEXES
  2456    {
  2457      $$ = string($1)
  2458    }
  2459  
  2460  from_or_in:
  2461    FROM
  2462    {
  2463      $$ = string($1)
  2464    }
  2465  | IN
  2466    {
  2467      $$ = string($1)
  2468    }
  2469  
  2470  index_or_key_opt:
  2471    {
  2472      $$ = "key"
  2473    }
  2474  | index_or_key
  2475    {
  2476      $$ = $1
  2477    }
  2478  
  2479  index_or_key:
  2480    INDEX
  2481    {
  2482      $$ = string($1)
  2483    }
  2484    | KEY
  2485    {
  2486      $$ = string($1)
  2487    }
  2488  
  2489  name_opt:
  2490    {
  2491      $$ = ""
  2492    }
  2493  | ci_identifier
  2494    {
  2495      $$ = string($1.String())
  2496    }
  2497  
  2498  index_column_list:
  2499    index_column
  2500    {
  2501      $$ = []*IndexColumn{$1}
  2502    }
  2503  | index_column_list ',' index_column
  2504    {
  2505      $$ = append($$, $3)
  2506    }
  2507  
  2508  index_column:
  2509    sql_id length_opt asc_desc_opt
  2510    {
  2511      $$ = &IndexColumn{Column: $1, Length: $2, Direction: $3}
  2512    }
  2513  | openb expression closeb asc_desc_opt
  2514    {
  2515      $$ = &IndexColumn{Expression: $2, Direction: $4}
  2516    }
  2517  
  2518  constraint_definition:
  2519    CONSTRAINT ci_identifier_opt constraint_info
  2520    {
  2521      $$ = &ConstraintDefinition{Name: $2, Details: $3}
  2522    }
  2523  |  constraint_info
  2524    {
  2525      $$ = &ConstraintDefinition{Details: $1}
  2526    }
  2527  
  2528  check_constraint_definition:
  2529    CONSTRAINT ci_identifier_opt check_constraint_info
  2530    {
  2531      $$ = &ConstraintDefinition{Name: $2, Details: $3}
  2532    }
  2533  |  check_constraint_info
  2534    {
  2535      $$ = &ConstraintDefinition{Details: $1}
  2536    }
  2537  
  2538  constraint_info:
  2539    FOREIGN KEY name_opt '(' column_list ')' reference_definition
  2540    {
  2541      $$ = &ForeignKeyDefinition{IndexName: NewIdentifierCI($3), Source: $5, ReferenceDefinition: $7}
  2542    }
  2543  
  2544  reference_definition:
  2545    REFERENCES table_name '(' column_list ')' fk_match_opt
  2546    {
  2547      $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, Match: $6}
  2548    }
  2549  | REFERENCES table_name '(' column_list ')' fk_match_opt fk_on_delete
  2550    {
  2551      $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, Match: $6, OnDelete: $7}
  2552    }
  2553  | REFERENCES table_name '(' column_list ')' fk_match_opt fk_on_update
  2554    {
  2555      $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, Match: $6, OnUpdate: $7}
  2556    }
  2557  | REFERENCES table_name '(' column_list ')' fk_match_opt fk_on_delete fk_on_update
  2558    {
  2559      $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, Match: $6, OnDelete: $7, OnUpdate: $8}
  2560    }
  2561  | REFERENCES table_name '(' column_list ')' fk_match_opt fk_on_update fk_on_delete
  2562    {
  2563      $$ = &ReferenceDefinition{ReferencedTable: $2, ReferencedColumns: $4, Match: $6, OnUpdate: $7, OnDelete: $8}
  2564    }
  2565  
  2566  reference_definition_opt:
  2567    {
  2568      $$ = nil
  2569    }
  2570  | reference_definition
  2571    {
  2572      $$ = $1
  2573    }
  2574  
  2575  check_constraint_info:
  2576    CHECK '(' expression ')' enforced_opt
  2577    {
  2578      $$ = &CheckConstraintDefinition{Expr: $3, Enforced: $5}
  2579    }
  2580  
  2581  fk_match:
  2582    MATCH fk_match_action
  2583    {
  2584      $$ = $2
  2585    }
  2586  
  2587  fk_match_action:
  2588    FULL
  2589    {
  2590      $$ = Full
  2591    }
  2592  | PARTIAL
  2593    {
  2594      $$ = Partial
  2595    }
  2596  | SIMPLE
  2597    {
  2598      $$ = Simple
  2599    }
  2600  
  2601  fk_match_opt:
  2602    {
  2603      $$ = DefaultMatch
  2604    }
  2605  | fk_match
  2606    {
  2607      $$ = $1
  2608    }
  2609  
  2610  fk_on_delete:
  2611    ON DELETE fk_reference_action
  2612    {
  2613      $$ = $3
  2614    }
  2615  
  2616  fk_on_update:
  2617    ON UPDATE fk_reference_action
  2618    {
  2619      $$ = $3
  2620    }
  2621  
  2622  fk_reference_action:
  2623    RESTRICT
  2624    {
  2625      $$ = Restrict
  2626    }
  2627  | CASCADE
  2628    {
  2629      $$ = Cascade
  2630    }
  2631  | NO ACTION
  2632    {
  2633      $$ = NoAction
  2634    }
  2635  | SET DEFAULT
  2636    {
  2637      $$ = SetDefault
  2638    }
  2639  | SET NULL
  2640    {
  2641      $$ = SetNull
  2642    }
  2643  
  2644  restrict_or_cascade_opt:
  2645    {
  2646      $$ = ""
  2647    }
  2648  | RESTRICT
  2649    {
  2650      $$ = string($1)
  2651    }
  2652  | CASCADE
  2653    {
  2654      $$ = string($1)
  2655    }
  2656  
  2657  enforced:
  2658    ENFORCED
  2659    {
  2660      $$ = true
  2661    }
  2662  | NOT ENFORCED
  2663    {
  2664      $$ = false
  2665    }
  2666  
  2667  enforced_opt:
  2668    {
  2669      $$ = true
  2670    }
  2671  | enforced
  2672    {
  2673      $$ = $1
  2674    }
  2675  
  2676  table_option_list_opt:
  2677    {
  2678      $$ = nil
  2679    }
  2680  | table_option_list
  2681    {
  2682      $$ = $1
  2683    }
  2684  
  2685  table_option_list:
  2686    table_option
  2687    {
  2688      $$ = TableOptions{$1}
  2689    }
  2690  | table_option_list ',' table_option
  2691    {
  2692      $$ = append($1,$3)
  2693    }
  2694  | table_option_list table_option
  2695    {
  2696      $$ = append($1,$2)
  2697    }
  2698  
  2699  space_separated_table_option_list:
  2700    table_option
  2701    {
  2702      $$ = TableOptions{$1}
  2703    }
  2704  | space_separated_table_option_list table_option
  2705    {
  2706      $$ = append($1,$2)
  2707    }
  2708  
  2709  table_option:
  2710    AUTO_INCREMENT equal_opt INTEGRAL
  2711    {
  2712      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2713    }
  2714  | AUTOEXTEND_SIZE equal_opt INTEGRAL
  2715    {
  2716      $$ = &TableOption{Name: string($1), Value: NewIntLiteral($3)}
  2717    }
  2718  | AVG_ROW_LENGTH equal_opt INTEGRAL
  2719    {
  2720      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2721    }
  2722  | default_optional charset_or_character_set equal_opt charset
  2723    {
  2724      $$ = &TableOption{Name:(string($2)), String:$4, CaseSensitive: true}
  2725    }
  2726  | default_optional COLLATE equal_opt charset
  2727    {
  2728      $$ = &TableOption{Name:string($2), String:$4, CaseSensitive: true}
  2729    }
  2730  | CHECKSUM equal_opt INTEGRAL
  2731    {
  2732      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2733    }
  2734  | COMMENT_KEYWORD equal_opt STRING
  2735    {
  2736      $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)}
  2737    }
  2738  | COMPRESSION equal_opt STRING
  2739    {
  2740      $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)}
  2741    }
  2742  | CONNECTION equal_opt STRING
  2743    {
  2744      $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)}
  2745    }
  2746  | DATA DIRECTORY equal_opt STRING
  2747    {
  2748      $$ = &TableOption{Name:(string($1)+" "+string($2)), Value:NewStrLiteral($4)}
  2749    }
  2750  | INDEX DIRECTORY equal_opt STRING
  2751    {
  2752      $$ = &TableOption{Name:(string($1)+" "+string($2)), Value:NewStrLiteral($4)}
  2753    }
  2754  | DELAY_KEY_WRITE equal_opt INTEGRAL
  2755    {
  2756      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2757    }
  2758  | ENCRYPTION equal_opt STRING
  2759    {
  2760      $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)}
  2761    }
  2762  | ENGINE equal_opt table_alias
  2763    {
  2764      $$ = &TableOption{Name:string($1), String:$3.String(), CaseSensitive: true}
  2765    }
  2766  | ENGINE_ATTRIBUTE equal_opt STRING
  2767    {
  2768      $$ = &TableOption{Name: string($1), Value: NewStrLiteral($3)}
  2769    }
  2770  | INSERT_METHOD equal_opt insert_method_options
  2771    {
  2772      $$ = &TableOption{Name:string($1), String:string($3)}
  2773    }
  2774  | KEY_BLOCK_SIZE equal_opt INTEGRAL
  2775    {
  2776      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2777    }
  2778  | MAX_ROWS equal_opt INTEGRAL
  2779    {
  2780      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2781    }
  2782  | MIN_ROWS equal_opt INTEGRAL
  2783    {
  2784      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2785    }
  2786  | PACK_KEYS equal_opt INTEGRAL
  2787    {
  2788      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2789    }
  2790  | PACK_KEYS equal_opt DEFAULT
  2791    {
  2792      $$ = &TableOption{Name:string($1), String:string($3)}
  2793    }
  2794  | PASSWORD equal_opt STRING
  2795    {
  2796      $$ = &TableOption{Name:string($1), Value:NewStrLiteral($3)}
  2797    }
  2798  | ROW_FORMAT equal_opt row_format_options
  2799    {
  2800      $$ = &TableOption{Name:string($1), String:string($3)}
  2801    }
  2802  | SECONDARY_ENGINE_ATTRIBUTE equal_opt STRING
  2803    {
  2804      $$ = &TableOption{Name: string($1), Value: NewStrLiteral($3)}
  2805    }
  2806  | STATS_AUTO_RECALC equal_opt INTEGRAL
  2807    {
  2808      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2809    }
  2810  | STATS_AUTO_RECALC equal_opt DEFAULT
  2811    {
  2812      $$ = &TableOption{Name:string($1), String:string($3)}
  2813    }
  2814  | STATS_PERSISTENT equal_opt INTEGRAL
  2815    {
  2816      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2817    }
  2818  | STATS_PERSISTENT equal_opt DEFAULT
  2819    {
  2820      $$ = &TableOption{Name:string($1), String:string($3)}
  2821    }
  2822  | STATS_SAMPLE_PAGES equal_opt INTEGRAL
  2823    {
  2824      $$ = &TableOption{Name:string($1), Value:NewIntLiteral($3)}
  2825    }
  2826  | TABLESPACE equal_opt sql_id storage_opt
  2827    {
  2828      $$ = &TableOption{Name:string($1), String: ($3.String() + $4)}
  2829    }
  2830  | UNION equal_opt '(' table_name_list ')'
  2831    {
  2832      $$ = &TableOption{Name:string($1), Tables: $4}
  2833    }
  2834  
  2835  storage_opt:
  2836    {
  2837      $$ = ""
  2838    }
  2839  | STORAGE DISK
  2840    {
  2841      $$ = " " + string($1) + " " + string($2)
  2842    }
  2843  | STORAGE MEMORY
  2844    {
  2845      $$ = " " + string($1) + " " + string($2)
  2846    }
  2847  
  2848  row_format_options:
  2849    DEFAULT
  2850  | DYNAMIC
  2851  | FIXED
  2852  | COMPRESSED
  2853  | REDUNDANT
  2854  | COMPACT
  2855  
  2856  insert_method_options:
  2857    NO
  2858  | FIRST
  2859  | LAST
  2860  
  2861  table_opt_value:
  2862    table_id '.' reserved_table_id
  2863    {
  2864      $$ = String(TableName{Qualifier: $1, Name: $3})
  2865    }
  2866  | reserved_sql_id
  2867    {
  2868      $$ = $1.String()
  2869    }
  2870  | STRING
  2871    {
  2872      $$ = encodeSQLString($1)
  2873    }
  2874  | INTEGRAL
  2875    {
  2876      $$ = string($1)
  2877    }
  2878  
  2879  column_opt:
  2880    {
  2881      $$ = ""
  2882    }
  2883  | COLUMN
  2884  
  2885  first_opt:
  2886    {
  2887      $$ = false
  2888    }
  2889  | FIRST
  2890    {
  2891      $$ = true
  2892    }
  2893  
  2894  after_opt:
  2895    {
  2896      $$ = nil
  2897    }
  2898  | AFTER column_name
  2899    {
  2900      $$ = $2
  2901    }
  2902  
  2903  expire_opt:
  2904    {
  2905      $$ = ""
  2906    }
  2907  | EXPIRE STRING
  2908    {
  2909      $$ = string($2)
  2910    }
  2911  
  2912  ratio_opt:
  2913    {
  2914      $$ = nil
  2915    }
  2916  | RATIO INTEGRAL
  2917    {
  2918      $$ = NewIntLiteral($2)
  2919    }
  2920  | RATIO DECIMAL
  2921    {
  2922      $$ = NewDecimalLiteral($2)
  2923    }
  2924  
  2925  alter_commands_list:
  2926    {
  2927      $$ = nil
  2928    }
  2929  | alter_options
  2930    {
  2931      $$ = $1
  2932    }
  2933  | alter_options ',' ORDER BY column_list
  2934    {
  2935      $$ = append($1,&OrderByOption{Cols:$5})
  2936    }
  2937  | alter_commands_modifier_list
  2938    {
  2939      $$ = $1
  2940    }
  2941  | alter_commands_modifier_list ',' alter_options
  2942    {
  2943      $$ = append($1,$3...)
  2944    }
  2945  | alter_commands_modifier_list ',' alter_options ',' ORDER BY column_list
  2946    {
  2947      $$ = append(append($1,$3...),&OrderByOption{Cols:$7})
  2948    }
  2949  
  2950  alter_options:
  2951    alter_option
  2952    {
  2953      $$ = []AlterOption{$1}
  2954    }
  2955  | alter_options ',' alter_option
  2956    {
  2957      $$ = append($1,$3)
  2958    }
  2959  | alter_options ',' alter_commands_modifier
  2960    {
  2961      $$ = append($1,$3)
  2962    }
  2963  
  2964  alter_option:
  2965    space_separated_table_option_list
  2966    {
  2967      $$ = $1
  2968    }
  2969  | ADD check_constraint_definition
  2970    {
  2971      $$ = &AddConstraintDefinition{ConstraintDefinition: $2}
  2972    }
  2973  | ADD constraint_definition
  2974    {
  2975      $$ = &AddConstraintDefinition{ConstraintDefinition: $2}
  2976    }
  2977  | ADD index_definition
  2978    {
  2979      $$ = &AddIndexDefinition{IndexDefinition: $2}
  2980    }
  2981  | ADD column_opt '(' column_definition_list ')'
  2982    {
  2983      $$ = &AddColumns{Columns: $4}
  2984    }
  2985  | ADD column_opt column_definition first_opt after_opt
  2986    {
  2987      $$ = &AddColumns{Columns: []*ColumnDefinition{$3}, First:$4, After:$5}
  2988    }
  2989  | ALTER column_opt column_name DROP DEFAULT
  2990    {
  2991      $$ = &AlterColumn{Column: $3, DropDefault:true}
  2992    }
  2993  | ALTER column_opt column_name SET DEFAULT signed_literal_or_null
  2994    {
  2995      $$ = &AlterColumn{Column: $3, DropDefault:false, DefaultVal:$6}
  2996    }
  2997  | ALTER column_opt column_name SET DEFAULT openb expression closeb
  2998    {
  2999  	$$ = &AlterColumn{Column: $3, DropDefault:false, DefaultVal:$7}
  3000    }
  3001  | ALTER column_opt column_name SET VISIBLE
  3002    {
  3003      val := false
  3004      $$ = &AlterColumn{Column: $3, Invisible:&val}
  3005    }
  3006  | ALTER column_opt column_name SET INVISIBLE
  3007    {
  3008      val := true
  3009      $$ = &AlterColumn{Column: $3, Invisible:&val}
  3010    }
  3011  | ALTER CHECK ci_identifier enforced
  3012    {
  3013      $$ = &AlterCheck{Name: $3, Enforced: $4}
  3014    }
  3015  | ALTER INDEX ci_identifier VISIBLE
  3016    {
  3017      $$ = &AlterIndex{Name: $3, Invisible: false}
  3018    }
  3019  | ALTER INDEX ci_identifier INVISIBLE
  3020    {
  3021      $$ = &AlterIndex{Name: $3, Invisible: true}
  3022    }
  3023  | CHANGE column_opt column_name column_definition first_opt after_opt
  3024    {
  3025      $$ = &ChangeColumn{OldColumn:$3, NewColDefinition:$4, First:$5, After:$6}
  3026    }
  3027  | MODIFY column_opt column_definition first_opt after_opt
  3028    {
  3029      $$ = &ModifyColumn{NewColDefinition:$3, First:$4, After:$5}
  3030    }
  3031  | RENAME COLUMN column_name TO column_name
  3032    {
  3033      $$ = &RenameColumn{OldName: $3, NewName: $5}
  3034    }
  3035  | CONVERT TO charset_or_character_set charset collate_opt
  3036    {
  3037      $$ = &AlterCharset{CharacterSet:$4, Collate:$5}
  3038    }
  3039  | DISABLE KEYS
  3040    {
  3041      $$ = &KeyState{Enable:false}
  3042    }
  3043  | ENABLE KEYS
  3044    {
  3045      $$ = &KeyState{Enable:true}
  3046    }
  3047  | DISCARD TABLESPACE
  3048    {
  3049      $$ = &TablespaceOperation{Import:false}
  3050    }
  3051  | IMPORT TABLESPACE
  3052    {
  3053      $$ = &TablespaceOperation{Import:true}
  3054    }
  3055  | DROP column_opt column_name
  3056    {
  3057      $$ = &DropColumn{Name:$3}
  3058    }
  3059  | DROP index_or_key ci_identifier
  3060    {
  3061      $$ = &DropKey{Type:NormalKeyType, Name:$3}
  3062    }
  3063  | DROP PRIMARY KEY
  3064    {
  3065      $$ = &DropKey{Type:PrimaryKeyType}
  3066    }
  3067  | DROP FOREIGN KEY ci_identifier
  3068    {
  3069      $$ = &DropKey{Type:ForeignKeyType, Name:$4}
  3070    }
  3071  | DROP CHECK ci_identifier
  3072    {
  3073      $$ = &DropKey{Type:CheckKeyType, Name:$3}
  3074    }
  3075  | DROP CONSTRAINT ci_identifier
  3076    {
  3077      $$ = &DropKey{Type:CheckKeyType, Name:$3}
  3078    }
  3079  | FORCE
  3080    {
  3081      $$ = &Force{}
  3082    }
  3083  | RENAME to_opt table_name
  3084    {
  3085      $$ = &RenameTableName{Table:$3}
  3086    }
  3087  | RENAME index_or_key ci_identifier TO ci_identifier
  3088    {
  3089      $$ = &RenameIndex{OldName:$3, NewName:$5}
  3090    }
  3091  
  3092  alter_commands_modifier_list:
  3093    alter_commands_modifier
  3094    {
  3095      $$ = []AlterOption{$1}
  3096    }
  3097  | alter_commands_modifier_list ',' alter_commands_modifier
  3098    {
  3099      $$ = append($1,$3)
  3100    }
  3101  
  3102  alter_commands_modifier:
  3103    ALGORITHM equal_opt DEFAULT
  3104      {
  3105        $$ = AlgorithmValue(string($3))
  3106      }
  3107    | ALGORITHM equal_opt INPLACE
  3108      {
  3109        $$ = AlgorithmValue(string($3))
  3110      }
  3111    | ALGORITHM equal_opt COPY
  3112      {
  3113        $$ = AlgorithmValue(string($3))
  3114      }
  3115    | ALGORITHM equal_opt INSTANT
  3116      {
  3117        $$ = AlgorithmValue(string($3))
  3118      }
  3119    | LOCK equal_opt DEFAULT
  3120      {
  3121        $$ = &LockOption{Type:DefaultType}
  3122      }
  3123    | LOCK equal_opt NONE
  3124      {
  3125        $$ = &LockOption{Type:NoneType}
  3126      }
  3127    | LOCK equal_opt SHARED
  3128      {
  3129        $$ = &LockOption{Type:SharedType}
  3130      }
  3131    | LOCK equal_opt EXCLUSIVE
  3132      {
  3133        $$ = &LockOption{Type:ExclusiveType}
  3134      }
  3135    | WITH VALIDATION
  3136      {
  3137        $$ = &Validation{With:true}
  3138      }
  3139    | WITHOUT VALIDATION
  3140      {
  3141        $$ = &Validation{With:false}
  3142      }
  3143  
  3144  alter_statement:
  3145    alter_table_prefix alter_commands_list partitions_options_opt
  3146    {
  3147      $1.FullyParsed = true
  3148      $1.AlterOptions = $2
  3149      $1.PartitionOption = $3
  3150      $$ = $1
  3151    }
  3152  | alter_table_prefix alter_commands_list REMOVE PARTITIONING
  3153    {
  3154      $1.FullyParsed = true
  3155      $1.AlterOptions = $2
  3156      $1.PartitionSpec = &PartitionSpec{Action:RemoveAction}
  3157      $$ = $1
  3158    }
  3159  | alter_table_prefix alter_commands_modifier_list ',' partition_operation
  3160    {
  3161      $1.FullyParsed = true
  3162      $1.AlterOptions = $2
  3163      $1.PartitionSpec = $4
  3164      $$ = $1
  3165    }
  3166  | alter_table_prefix partition_operation
  3167    {
  3168      $1.FullyParsed = true
  3169      $1.PartitionSpec = $2
  3170      $$ = $1
  3171    }
  3172  | ALTER comment_opt algorithm_view definer_opt security_view_opt VIEW table_name column_list_opt AS select_statement check_option_opt
  3173    {
  3174      $$ = &AlterView{ViewName: $7.ToViewName(), Comments: Comments($2).Parsed(), Algorithm:$3, Definer: $4 ,Security:$5, Columns:$8, Select: $10, CheckOption: $11 }
  3175    }
  3176  // The syntax here causes a shift / reduce issue, because ENCRYPTION is a non reserved keyword
  3177  // and the database identifier is optional. When no identifier is given, the current database
  3178  // is used. This means though that `alter database encryption` is ambiguous whether it means
  3179  // the encryption keyword, or the encryption database name, resulting in the conflict.
  3180  // The preference here is to shift, so it is treated as a database name. This matches the MySQL
  3181  // behavior as well.
  3182  | alter_database_prefix table_id_opt create_options
  3183    {
  3184      $1.FullyParsed = true
  3185      $1.DBName = $2
  3186      $1.AlterOptions = $3
  3187      $$ = $1
  3188    }
  3189  | alter_database_prefix table_id UPGRADE DATA DIRECTORY NAME
  3190    {
  3191      $1.FullyParsed = true
  3192      $1.DBName = $2
  3193      $1.UpdateDataDirectory = true
  3194      $$ = $1
  3195    }
  3196  | ALTER comment_opt VSCHEMA CREATE VINDEX table_name vindex_type_opt vindex_params_opt
  3197    {
  3198      $$ = &AlterVschema{
  3199          Action: CreateVindexDDLAction,
  3200          Table: $6,
  3201          VindexSpec: &VindexSpec{
  3202            Name: NewIdentifierCI($6.Name.String()),
  3203            Type: $7,
  3204            Params: $8,
  3205          },
  3206        }
  3207    }
  3208  | ALTER comment_opt VSCHEMA DROP VINDEX table_name
  3209    {
  3210      $$ = &AlterVschema{
  3211          Action: DropVindexDDLAction,
  3212          Table: $6,
  3213          VindexSpec: &VindexSpec{
  3214            Name: NewIdentifierCI($6.Name.String()),
  3215          },
  3216        }
  3217    }
  3218  | ALTER comment_opt VSCHEMA ADD TABLE table_name
  3219    {
  3220      $$ = &AlterVschema{Action: AddVschemaTableDDLAction, Table: $6}
  3221    }
  3222  | ALTER comment_opt VSCHEMA DROP TABLE table_name
  3223    {
  3224      $$ = &AlterVschema{Action: DropVschemaTableDDLAction, Table: $6}
  3225    }
  3226  | ALTER comment_opt VSCHEMA ON table_name ADD VINDEX sql_id '(' column_list ')' vindex_type_opt vindex_params_opt
  3227    {
  3228      $$ = &AlterVschema{
  3229          Action: AddColVindexDDLAction,
  3230          Table: $5,
  3231          VindexSpec: &VindexSpec{
  3232              Name: $8,
  3233              Type: $12,
  3234              Params: $13,
  3235          },
  3236          VindexCols: $10,
  3237        }
  3238    }
  3239  | ALTER comment_opt VSCHEMA ON table_name DROP VINDEX sql_id
  3240    {
  3241      $$ = &AlterVschema{
  3242          Action: DropColVindexDDLAction,
  3243          Table: $5,
  3244          VindexSpec: &VindexSpec{
  3245              Name: $8,
  3246          },
  3247        }
  3248    }
  3249  | ALTER comment_opt VSCHEMA ADD SEQUENCE table_name
  3250    {
  3251      $$ = &AlterVschema{Action: AddSequenceDDLAction, Table: $6}
  3252    }
  3253  | ALTER comment_opt VSCHEMA ON table_name ADD AUTO_INCREMENT sql_id USING table_name
  3254    {
  3255      $$ = &AlterVschema{
  3256          Action: AddAutoIncDDLAction,
  3257          Table: $5,
  3258          AutoIncSpec: &AutoIncSpec{
  3259              Column: $8,
  3260              Sequence: $10,
  3261          },
  3262      }
  3263    }
  3264  | ALTER comment_opt VITESS_MIGRATION STRING RETRY
  3265    {
  3266      $$ = &AlterMigration{
  3267        Type: RetryMigrationType,
  3268        UUID: string($4),
  3269      }
  3270    }
  3271  | ALTER comment_opt VITESS_MIGRATION STRING CLEANUP
  3272    {
  3273      $$ = &AlterMigration{
  3274        Type: CleanupMigrationType,
  3275        UUID: string($4),
  3276      }
  3277    }
  3278  | ALTER comment_opt VITESS_MIGRATION STRING LAUNCH
  3279    {
  3280      $$ = &AlterMigration{
  3281        Type: LaunchMigrationType,
  3282        UUID: string($4),
  3283      }
  3284    }
  3285  | ALTER comment_opt VITESS_MIGRATION STRING LAUNCH VITESS_SHARDS STRING
  3286    {
  3287      $$ = &AlterMigration{
  3288        Type: LaunchMigrationType,
  3289        UUID: string($4),
  3290        Shards: string($7),
  3291      }
  3292    }
  3293  | ALTER comment_opt VITESS_MIGRATION LAUNCH ALL
  3294    {
  3295      $$ = &AlterMigration{
  3296        Type: LaunchAllMigrationType,
  3297      }
  3298    }
  3299  | ALTER comment_opt VITESS_MIGRATION STRING COMPLETE
  3300    {
  3301      $$ = &AlterMigration{
  3302        Type: CompleteMigrationType,
  3303        UUID: string($4),
  3304      }
  3305    }
  3306  | ALTER comment_opt VITESS_MIGRATION COMPLETE ALL
  3307    {
  3308      $$ = &AlterMigration{
  3309        Type: CompleteAllMigrationType,
  3310      }
  3311    }
  3312  | ALTER comment_opt VITESS_MIGRATION STRING CANCEL
  3313    {
  3314      $$ = &AlterMigration{
  3315        Type: CancelMigrationType,
  3316        UUID: string($4),
  3317      }
  3318    }
  3319  | ALTER comment_opt VITESS_MIGRATION CANCEL ALL
  3320    {
  3321      $$ = &AlterMigration{
  3322        Type: CancelAllMigrationType,
  3323      }
  3324    }
  3325  | ALTER comment_opt VITESS_MIGRATION STRING THROTTLE expire_opt ratio_opt
  3326    {
  3327      $$ = &AlterMigration{
  3328        Type: ThrottleMigrationType,
  3329        UUID: string($4),
  3330        Expire: $6,
  3331        Ratio: $7,
  3332      }
  3333    }
  3334  | ALTER comment_opt VITESS_MIGRATION THROTTLE ALL expire_opt ratio_opt
  3335    {
  3336      $$ = &AlterMigration{
  3337        Type: ThrottleAllMigrationType,
  3338        Expire: $6,
  3339        Ratio: $7,
  3340      }
  3341    }
  3342  | ALTER comment_opt VITESS_MIGRATION STRING UNTHROTTLE
  3343    {
  3344      $$ = &AlterMigration{
  3345        Type: UnthrottleMigrationType,
  3346        UUID: string($4),
  3347      }
  3348    }
  3349  | ALTER comment_opt VITESS_MIGRATION UNTHROTTLE ALL
  3350    {
  3351      $$ = &AlterMigration{
  3352        Type: UnthrottleAllMigrationType,
  3353      }
  3354    }
  3355  
  3356  partitions_options_opt:
  3357    {
  3358      $$ = nil
  3359    }
  3360  | PARTITION BY partitions_options_beginning partitions_opt subpartition_opt partition_definitions_opt
  3361      {
  3362        $3.Partitions = $4
  3363        $3.SubPartition = $5
  3364        $3.Definitions = $6
  3365        $$ = $3
  3366      }
  3367  
  3368  partitions_options_beginning:
  3369    linear_opt HASH '(' expression ')'
  3370      {
  3371        $$ = &PartitionOption {
  3372          IsLinear: $1,
  3373          Type: HashType,
  3374          Expr: $4,
  3375        }
  3376      }
  3377  | linear_opt KEY algorithm_opt '(' column_list_empty ')'
  3378      {
  3379        $$ = &PartitionOption {
  3380          IsLinear: $1,
  3381          Type: KeyType,
  3382          KeyAlgorithm: $3,
  3383          ColList: $5,
  3384        }
  3385      }
  3386  | range_or_list '(' expression ')'
  3387      {
  3388        $$ = &PartitionOption {
  3389          Type: $1,
  3390          Expr: $3,
  3391        }
  3392      }
  3393  | range_or_list COLUMNS '(' column_list ')'
  3394    {
  3395      $$ = &PartitionOption {
  3396          Type: $1,
  3397          ColList: $4,
  3398      }
  3399    }
  3400  
  3401  subpartition_opt:
  3402    {
  3403      $$ = nil
  3404    }
  3405  | SUBPARTITION BY linear_opt HASH '(' expression ')' subpartitions_opt
  3406    {
  3407      $$ = &SubPartition {
  3408        IsLinear: $3,
  3409        Type: HashType,
  3410        Expr: $6,
  3411        SubPartitions: $8,
  3412      }
  3413    }
  3414  | SUBPARTITION BY linear_opt KEY algorithm_opt '(' column_list ')' subpartitions_opt
  3415    {
  3416      $$ = &SubPartition {
  3417        IsLinear: $3,
  3418        Type: KeyType,
  3419        KeyAlgorithm: $5,
  3420        ColList: $7,
  3421        SubPartitions: $9,
  3422      }
  3423    }
  3424  
  3425  partition_definitions_opt:
  3426    {
  3427      $$ = nil
  3428    }
  3429  | '(' partition_definitions ')'
  3430    {
  3431      $$ = $2
  3432    }
  3433  
  3434  linear_opt:
  3435    {
  3436      $$ = false
  3437    }
  3438  | LINEAR
  3439    {
  3440      $$ = true
  3441    }
  3442  
  3443  algorithm_opt:
  3444    {
  3445      $$ = 0
  3446    }
  3447  | ALGORITHM '=' INTEGRAL
  3448    {
  3449      $$ = convertStringToInt($3)
  3450    }
  3451  
  3452  json_table_function:
  3453    JSON_TABLE openb expression ',' text_literal_or_arg jt_columns_clause closeb as_opt_id
  3454    {
  3455      $$ = &JSONTableExpr{Expr: $3, Filter: $5, Columns: $6, Alias: $8}
  3456    }
  3457  
  3458  jt_columns_clause:
  3459    COLUMNS openb columns_list closeb
  3460    {
  3461      $$= $3
  3462    }
  3463  
  3464  columns_list:
  3465    jt_column
  3466    {
  3467      $$= []*JtColumnDefinition{$1}
  3468    }
  3469  | columns_list ',' jt_column
  3470    {
  3471      $$ = append($1, $3)
  3472    }
  3473  
  3474  jt_column:
  3475   sql_id FOR ORDINALITY
  3476    {
  3477      $$ = &JtColumnDefinition{JtOrdinal: &JtOrdinalColDef{Name: $1}}
  3478    }
  3479  | sql_id column_type collate_opt jt_exists_opt PATH text_literal_or_arg
  3480    {
  3481      $2.Options= &ColumnTypeOptions{Collate:$3}
  3482      jtPath := &JtPathColDef{Name: $1, Type: $2, JtColExists: $4, Path: $6}
  3483      $$ = &JtColumnDefinition{JtPath: jtPath}
  3484    }
  3485  | sql_id column_type collate_opt jt_exists_opt PATH text_literal_or_arg on_empty
  3486    {
  3487      $2.Options= &ColumnTypeOptions{Collate:$3}
  3488      jtPath := &JtPathColDef{Name: $1, Type: $2, JtColExists: $4, Path: $6, EmptyOnResponse: $7}
  3489      $$ = &JtColumnDefinition{JtPath: jtPath}
  3490    }
  3491  | sql_id column_type collate_opt jt_exists_opt PATH text_literal_or_arg on_error
  3492    {
  3493      $2.Options= &ColumnTypeOptions{Collate:$3}
  3494      jtPath := &JtPathColDef{Name: $1, Type: $2, JtColExists: $4, Path: $6, ErrorOnResponse: $7}
  3495      $$ = &JtColumnDefinition{JtPath: jtPath}
  3496    }
  3497  | sql_id column_type collate_opt jt_exists_opt PATH text_literal_or_arg on_empty on_error
  3498    {
  3499      $2.Options= &ColumnTypeOptions{Collate:$3}
  3500      jtPath := &JtPathColDef{Name: $1, Type: $2, JtColExists: $4, Path: $6, EmptyOnResponse: $7, ErrorOnResponse: $8}
  3501      $$ = &JtColumnDefinition{JtPath: jtPath}
  3502    }
  3503  | NESTED jt_path_opt text_literal_or_arg jt_columns_clause
  3504    {
  3505      jtNestedPath := &JtNestedPathColDef{Path: $3, Columns: $4}
  3506      $$ = &JtColumnDefinition{JtNestedPath: jtNestedPath}
  3507    }
  3508  
  3509  jt_path_opt:
  3510    {
  3511      $$ = false
  3512    }
  3513  | PATH
  3514    {
  3515      $$ = true
  3516    }
  3517  jt_exists_opt:
  3518    {
  3519      $$=false
  3520    }
  3521  | EXISTS
  3522    {
  3523      $$=true
  3524    }
  3525  
  3526  on_empty:
  3527    json_on_response ON EMPTY
  3528    {
  3529      $$= $1
  3530    }
  3531  
  3532  on_error:
  3533    json_on_response ON ERROR
  3534    {
  3535      $$= $1
  3536    }
  3537  
  3538  json_on_response:
  3539    ERROR
  3540    {
  3541      $$ = &JtOnResponse{ResponseType: ErrorJSONType}
  3542    }
  3543  | NULL
  3544    {
  3545      $$ = &JtOnResponse{ResponseType: NullJSONType}
  3546    }
  3547  | DEFAULT text_literal_or_arg
  3548    {
  3549      $$ = &JtOnResponse{ResponseType: DefaultJSONType, Expr: $2}
  3550    }
  3551  
  3552  range_or_list:
  3553    RANGE
  3554    {
  3555      $$ = RangeType
  3556    }
  3557  | LIST
  3558    {
  3559      $$ = ListType
  3560    }
  3561  
  3562  partitions_opt:
  3563    {
  3564      $$ = -1
  3565    }
  3566  | PARTITIONS INTEGRAL
  3567    {
  3568      $$ = convertStringToInt($2)
  3569    }
  3570  
  3571  subpartitions_opt:
  3572    {
  3573      $$ = -1
  3574    }
  3575  | SUBPARTITIONS INTEGRAL
  3576    {
  3577      $$ = convertStringToInt($2)
  3578    }
  3579  
  3580  partition_operation:
  3581    ADD PARTITION '(' partition_definition ')'
  3582    {
  3583      $$ = &PartitionSpec{Action: AddAction, Definitions: []*PartitionDefinition{$4}}
  3584    }
  3585  | DROP PARTITION partition_list
  3586    {
  3587      $$ = &PartitionSpec{Action:DropAction, Names:$3}
  3588    }
  3589  | REORGANIZE PARTITION partition_list INTO openb partition_definitions closeb
  3590    {
  3591      $$ = &PartitionSpec{Action: ReorganizeAction, Names: $3, Definitions: $6}
  3592    }
  3593  | DISCARD PARTITION partition_list TABLESPACE
  3594    {
  3595      $$ = &PartitionSpec{Action:DiscardAction, Names:$3}
  3596    }
  3597  | DISCARD PARTITION ALL TABLESPACE
  3598    {
  3599      $$ = &PartitionSpec{Action:DiscardAction, IsAll:true}
  3600    }
  3601  | IMPORT PARTITION partition_list TABLESPACE
  3602    {
  3603      $$ = &PartitionSpec{Action:ImportAction, Names:$3}
  3604    }
  3605  | IMPORT PARTITION ALL TABLESPACE
  3606    {
  3607      $$ = &PartitionSpec{Action:ImportAction, IsAll:true}
  3608    }
  3609  | TRUNCATE PARTITION partition_list
  3610    {
  3611      $$ = &PartitionSpec{Action:TruncateAction, Names:$3}
  3612    }
  3613  | TRUNCATE PARTITION ALL
  3614    {
  3615      $$ = &PartitionSpec{Action:TruncateAction, IsAll:true}
  3616    }
  3617  | COALESCE PARTITION INTEGRAL
  3618    {
  3619      $$ = &PartitionSpec{Action:CoalesceAction, Number:NewIntLiteral($3) }
  3620    }
  3621  | EXCHANGE PARTITION sql_id WITH TABLE table_name without_valid_opt
  3622    {
  3623      $$ = &PartitionSpec{Action:ExchangeAction, Names: Partitions{$3}, TableName: $6, WithoutValidation: $7}
  3624    }
  3625  | ANALYZE PARTITION partition_list
  3626    {
  3627      $$ = &PartitionSpec{Action:AnalyzeAction, Names:$3}
  3628    }
  3629  | ANALYZE PARTITION ALL
  3630    {
  3631      $$ = &PartitionSpec{Action:AnalyzeAction, IsAll:true}
  3632    }
  3633  | CHECK PARTITION partition_list
  3634    {
  3635      $$ = &PartitionSpec{Action:CheckAction, Names:$3}
  3636    }
  3637  | CHECK PARTITION ALL
  3638    {
  3639      $$ = &PartitionSpec{Action:CheckAction, IsAll:true}
  3640    }
  3641  | OPTIMIZE PARTITION partition_list
  3642    {
  3643      $$ = &PartitionSpec{Action:OptimizeAction, Names:$3}
  3644    }
  3645  | OPTIMIZE PARTITION ALL
  3646    {
  3647      $$ = &PartitionSpec{Action:OptimizeAction, IsAll:true}
  3648    }
  3649  | REBUILD PARTITION partition_list
  3650    {
  3651      $$ = &PartitionSpec{Action:RebuildAction, Names:$3}
  3652    }
  3653  | REBUILD PARTITION ALL
  3654    {
  3655      $$ = &PartitionSpec{Action:RebuildAction, IsAll:true}
  3656    }
  3657  | REPAIR PARTITION partition_list
  3658    {
  3659      $$ = &PartitionSpec{Action:RepairAction, Names:$3}
  3660    }
  3661  | REPAIR PARTITION ALL
  3662    {
  3663      $$ = &PartitionSpec{Action:RepairAction, IsAll:true}
  3664    }
  3665  | UPGRADE PARTITIONING
  3666    {
  3667      $$ = &PartitionSpec{Action:UpgradeAction}
  3668    }
  3669  
  3670  without_valid_opt:
  3671    {
  3672      $$ = false
  3673    }
  3674  | WITH VALIDATION
  3675    {
  3676      $$ = false
  3677    }
  3678  | WITHOUT VALIDATION
  3679    {
  3680      $$ = true
  3681    }
  3682  
  3683  partition_definitions:
  3684    partition_definition
  3685    {
  3686      $$ = []*PartitionDefinition{$1}
  3687    }
  3688  | partition_definitions ',' partition_definition
  3689    {
  3690      $$ = append($1, $3)
  3691    }
  3692  
  3693  partition_definition:
  3694    partition_name partition_definition_attribute_list_opt
  3695    {
  3696      $$.Options = $2
  3697    }
  3698  
  3699  partition_definition_attribute_list_opt:
  3700    {
  3701      $$ = &PartitionDefinitionOptions{}
  3702    }
  3703  | partition_definition_attribute_list_opt partition_value_range
  3704    {
  3705      $1.ValueRange = $2
  3706      $$ = $1
  3707    }
  3708  | partition_definition_attribute_list_opt partition_comment
  3709    {
  3710      $1.Comment = $2
  3711      $$ = $1
  3712    }
  3713  | partition_definition_attribute_list_opt partition_engine
  3714    {
  3715      $1.Engine = $2
  3716      $$ = $1
  3717    }
  3718  | partition_definition_attribute_list_opt partition_data_directory
  3719    {
  3720      $1.DataDirectory = $2
  3721      $$ = $1
  3722    }
  3723  | partition_definition_attribute_list_opt partition_index_directory
  3724    {
  3725      $1.IndexDirectory = $2
  3726      $$ = $1
  3727    }
  3728  | partition_definition_attribute_list_opt partition_max_rows
  3729    {
  3730      val := $2
  3731      $1.MaxRows = &val
  3732      $$ = $1
  3733    }
  3734  | partition_definition_attribute_list_opt partition_min_rows
  3735    {
  3736      val := $2
  3737      $1.MinRows = &val
  3738      $$ = $1
  3739    }
  3740  | partition_definition_attribute_list_opt partition_tablespace_name
  3741    {
  3742      $1.TableSpace = $2
  3743      $$ = $1
  3744    }
  3745  | partition_definition_attribute_list_opt subpartition_definition_list_with_brackets
  3746    {
  3747      $1.SubPartitionDefinitions = $2
  3748      $$ = $1
  3749    }
  3750  
  3751  subpartition_definition_list_with_brackets:
  3752    openb subpartition_definition_list closeb{
  3753      $$ = $2
  3754    }
  3755  
  3756  subpartition_definition_list:
  3757    subpartition_definition
  3758    {
  3759      $$ = SubPartitionDefinitions{$1}
  3760    }
  3761  | subpartition_definition_list ',' subpartition_definition
  3762    {
  3763      $$ = append($1, $3)
  3764    }
  3765  
  3766  subpartition_definition:
  3767    SUBPARTITION sql_id subpartition_definition_attribute_list_opt
  3768    {
  3769      $$ = &SubPartitionDefinition{Name:$2, Options: $3}
  3770    }
  3771  
  3772  subpartition_definition_attribute_list_opt:
  3773    {
  3774      $$ = &SubPartitionDefinitionOptions{}
  3775    }
  3776  | subpartition_definition_attribute_list_opt partition_comment
  3777    {
  3778      $1.Comment = $2
  3779      $$ = $1
  3780    }
  3781  | subpartition_definition_attribute_list_opt partition_engine
  3782    {
  3783      $1.Engine = $2
  3784      $$ = $1
  3785    }
  3786  | subpartition_definition_attribute_list_opt partition_data_directory
  3787    {
  3788      $1.DataDirectory = $2
  3789      $$ = $1
  3790    }
  3791  | subpartition_definition_attribute_list_opt partition_index_directory
  3792    {
  3793      $1.IndexDirectory = $2
  3794      $$ = $1
  3795    }
  3796  | subpartition_definition_attribute_list_opt partition_max_rows
  3797    {
  3798      val := $2
  3799      $1.MaxRows = &val
  3800      $$ = $1
  3801    }
  3802  | subpartition_definition_attribute_list_opt partition_min_rows
  3803    {
  3804      val := $2
  3805      $1.MinRows = &val
  3806      $$ = $1
  3807    }
  3808  | subpartition_definition_attribute_list_opt partition_tablespace_name
  3809    {
  3810      $1.TableSpace = $2
  3811      $$ = $1
  3812    }
  3813  
  3814  partition_value_range:
  3815    VALUES LESS THAN row_tuple
  3816    {
  3817      $$ = &PartitionValueRange{
  3818      	Type: LessThanType,
  3819      	Range: $4,
  3820      }
  3821    }
  3822  | VALUES LESS THAN maxvalue
  3823    {
  3824      $$ = &PartitionValueRange{
  3825      	Type: LessThanType,
  3826      	Maxvalue: true,
  3827      }
  3828    }
  3829  | VALUES IN row_tuple
  3830    {
  3831      $$ = &PartitionValueRange{
  3832      	Type: InType,
  3833      	Range: $3,
  3834      }
  3835    }
  3836  
  3837  partition_storage_opt:
  3838    {
  3839      $$ = false
  3840    }
  3841  | STORAGE
  3842    {
  3843      $$ = true
  3844    }
  3845  
  3846  partition_engine:
  3847    partition_storage_opt ENGINE equal_opt table_alias
  3848    {
  3849      $$ = &PartitionEngine{Storage:$1, Name: $4.String()}
  3850    }
  3851  
  3852  partition_comment:
  3853    COMMENT_KEYWORD equal_opt STRING
  3854    {
  3855      $$ = NewStrLiteral($3)
  3856    }
  3857  
  3858  partition_data_directory:
  3859    DATA DIRECTORY equal_opt STRING
  3860    {
  3861      $$ = NewStrLiteral($4)
  3862    }
  3863  
  3864  partition_index_directory:
  3865    INDEX DIRECTORY equal_opt STRING
  3866    {
  3867      $$ = NewStrLiteral($4)
  3868    }
  3869  
  3870  partition_max_rows:
  3871    MAX_ROWS equal_opt INTEGRAL
  3872    {
  3873      $$ = convertStringToInt($3)
  3874    }
  3875  
  3876  partition_min_rows:
  3877    MIN_ROWS equal_opt INTEGRAL
  3878    {
  3879      $$ = convertStringToInt($3)
  3880    }
  3881  
  3882  partition_tablespace_name:
  3883    TABLESPACE equal_opt table_alias
  3884    {
  3885      $$ = $3.String()
  3886    }
  3887  
  3888  partition_name:
  3889    PARTITION sql_id
  3890    {
  3891      $$ = &PartitionDefinition{Name: $2}
  3892    }
  3893  
  3894  maxvalue:
  3895    MAXVALUE
  3896    {
  3897      $$ = ""
  3898    }
  3899  | openb MAXVALUE closeb
  3900    {
  3901      $$ = ""
  3902    }
  3903  
  3904  rename_statement:
  3905    RENAME TABLE rename_list
  3906    {
  3907      $$ = &RenameTable{TablePairs: $3}
  3908    }
  3909  
  3910  rename_list:
  3911    table_name TO table_name
  3912    {
  3913      $$ = []*RenameTablePair{{FromTable: $1, ToTable: $3}}
  3914    }
  3915  | rename_list ',' table_name TO table_name
  3916    {
  3917      $$ = append($1, &RenameTablePair{FromTable: $3, ToTable: $5})
  3918    }
  3919  
  3920  drop_statement:
  3921    DROP comment_opt temp_opt TABLE exists_opt table_name_list restrict_or_cascade_opt
  3922    {
  3923      $$ = &DropTable{FromTables: $6, IfExists: $5, Comments: Comments($2).Parsed(), Temp: $3}
  3924    }
  3925  | DROP comment_opt INDEX ci_identifier ON table_name algorithm_lock_opt
  3926    {
  3927      // Change this to an alter statement
  3928      if $4.Lowered() == "primary" {
  3929        $$ = &AlterTable{FullyParsed:true, Table: $6,AlterOptions: append([]AlterOption{&DropKey{Type:PrimaryKeyType}},$7...)}
  3930      } else {
  3931        $$ = &AlterTable{FullyParsed: true, Table: $6,AlterOptions: append([]AlterOption{&DropKey{Type:NormalKeyType, Name:$4}},$7...)}
  3932      }
  3933    }
  3934  | DROP comment_opt VIEW exists_opt view_name_list restrict_or_cascade_opt
  3935    {
  3936      $$ = &DropView{FromTables: $5, Comments: Comments($2).Parsed(), IfExists: $4}
  3937    }
  3938  | DROP comment_opt database_or_schema exists_opt table_id
  3939    {
  3940      $$ = &DropDatabase{Comments: Comments($2).Parsed(), DBName: $5, IfExists: $4}
  3941    }
  3942  
  3943  truncate_statement:
  3944    TRUNCATE TABLE table_name
  3945    {
  3946      $$ = &TruncateTable{Table: $3}
  3947    }
  3948  | TRUNCATE table_name
  3949    {
  3950      $$ = &TruncateTable{Table: $2}
  3951    }
  3952  
  3953  analyze_statement:
  3954    ANALYZE TABLE table_name
  3955    {
  3956      $$ = &OtherRead{}
  3957    }
  3958  
  3959  show_statement:
  3960    SHOW charset_or_character_set like_or_where_opt
  3961    {
  3962      $$ = &Show{&ShowBasic{Command: Charset, Filter: $3}}
  3963    }
  3964  | SHOW COLLATION like_or_where_opt
  3965    {
  3966      $$ = &Show{&ShowBasic{Command: Collation, Filter: $3}}
  3967    }
  3968  | SHOW full_opt columns_or_fields from_or_in table_name from_database_opt like_or_where_opt
  3969    {
  3970      $$ = &Show{&ShowBasic{Full: $2, Command: Column, Tbl: $5, DbName: $6, Filter: $7}}
  3971    }
  3972  | SHOW DATABASES like_or_where_opt
  3973    {
  3974      $$ = &Show{&ShowBasic{Command: Database, Filter: $3}}
  3975    }
  3976  | SHOW SCHEMAS like_or_where_opt
  3977    {
  3978      $$ = &Show{&ShowBasic{Command: Database, Filter: $3}}
  3979    }
  3980  | SHOW KEYSPACES like_or_where_opt
  3981    {
  3982      $$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}}
  3983    }
  3984  | SHOW VITESS_KEYSPACES like_or_where_opt
  3985    {
  3986      $$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}}
  3987    }
  3988  | SHOW FUNCTION STATUS like_or_where_opt
  3989    {
  3990      $$ = &Show{&ShowBasic{Command: Function, Filter: $4}}
  3991    }
  3992  | SHOW extended_opt index_symbols from_or_in table_name from_database_opt like_or_where_opt
  3993    {
  3994      $$ = &Show{&ShowBasic{Command: Index, Tbl: $5, DbName: $6, Filter: $7}}
  3995    }
  3996  | SHOW OPEN TABLES from_database_opt like_or_where_opt
  3997    {
  3998      $$ = &Show{&ShowBasic{Command: OpenTable, DbName:$4, Filter: $5}}
  3999    }
  4000  | SHOW PRIVILEGES
  4001    {
  4002      $$ = &Show{&ShowBasic{Command: Privilege}}
  4003    }
  4004  | SHOW PROCEDURE STATUS like_or_where_opt
  4005    {
  4006      $$ = &Show{&ShowBasic{Command: Procedure, Filter: $4}}
  4007    }
  4008  | SHOW session_or_local_opt STATUS like_or_where_opt
  4009    {
  4010      $$ = &Show{&ShowBasic{Command: StatusSession, Filter: $4}}
  4011    }
  4012  | SHOW GLOBAL STATUS like_or_where_opt
  4013    {
  4014      $$ = &Show{&ShowBasic{Command: StatusGlobal, Filter: $4}}
  4015    }
  4016  | SHOW session_or_local_opt VARIABLES like_or_where_opt
  4017    {
  4018      $$ = &Show{&ShowBasic{Command: VariableSession, Filter: $4}}
  4019    }
  4020  | SHOW GLOBAL VARIABLES like_or_where_opt
  4021    {
  4022      $$ = &Show{&ShowBasic{Command: VariableGlobal, Filter: $4}}
  4023    }
  4024  | SHOW TABLE STATUS from_database_opt like_or_where_opt
  4025    {
  4026      $$ = &Show{&ShowBasic{Command: TableStatus, DbName:$4, Filter: $5}}
  4027    }
  4028  | SHOW full_opt TABLES from_database_opt like_or_where_opt
  4029    {
  4030      $$ = &Show{&ShowBasic{Command: Table, Full: $2, DbName:$4, Filter: $5}}
  4031    }
  4032  | SHOW TRIGGERS from_database_opt like_or_where_opt
  4033    {
  4034      $$ = &Show{&ShowBasic{Command: Trigger, DbName:$3, Filter: $4}}
  4035    }
  4036  | SHOW CREATE DATABASE table_name
  4037    {
  4038      $$ = &Show{&ShowCreate{Command: CreateDb, Op: $4}}
  4039    }
  4040  | SHOW CREATE EVENT table_name
  4041    {
  4042      $$ = &Show{&ShowCreate{Command: CreateE, Op: $4}}
  4043    }
  4044  | SHOW CREATE FUNCTION table_name
  4045    {
  4046      $$ = &Show{&ShowCreate{Command: CreateF, Op: $4}}
  4047    }
  4048  | SHOW CREATE PROCEDURE table_name
  4049    {
  4050      $$ = &Show{&ShowCreate{Command: CreateProc, Op: $4}}
  4051    }
  4052  | SHOW CREATE TABLE table_name
  4053    {
  4054      $$ = &Show{&ShowCreate{Command: CreateTbl, Op: $4}}
  4055    }
  4056  | SHOW CREATE TRIGGER table_name
  4057    {
  4058      $$ = &Show{&ShowCreate{Command: CreateTr, Op: $4}}
  4059    }
  4060  | SHOW CREATE VIEW table_name
  4061    {
  4062      $$ = &Show{&ShowCreate{Command: CreateV, Op: $4}}
  4063    }
  4064  | SHOW ENGINES
  4065    {
  4066      $$ = &Show{&ShowBasic{Command: Engines}}
  4067    }
  4068  | SHOW PLUGINS
  4069    {
  4070      $$ = &Show{&ShowBasic{Command: Plugins}}
  4071    }
  4072  | SHOW GLOBAL GTID_EXECUTED from_database_opt
  4073    {
  4074      $$ = &Show{&ShowBasic{Command: GtidExecGlobal, DbName: $4}}
  4075    }
  4076  | SHOW GLOBAL VGTID_EXECUTED from_database_opt
  4077    {
  4078      $$ = &Show{&ShowBasic{Command: VGtidExecGlobal, DbName: $4}}
  4079    }
  4080  | SHOW VITESS_METADATA VARIABLES like_opt
  4081    {
  4082      $$ = &Show{&ShowBasic{Command: VitessVariables, Filter: $4}}
  4083    }
  4084  | SHOW VITESS_MIGRATIONS from_database_opt like_or_where_opt
  4085    {
  4086      $$ = &Show{&ShowBasic{Command: VitessMigrations, Filter: $4, DbName: $3}}
  4087    }
  4088  | SHOW VITESS_MIGRATION STRING LOGS
  4089    {
  4090      $$ = &ShowMigrationLogs{UUID: string($3)}
  4091    }
  4092  | SHOW VITESS_THROTTLED_APPS
  4093    {
  4094      $$ = &ShowThrottledApps{}
  4095    }
  4096  | SHOW VITESS_REPLICATION_STATUS like_opt
  4097    {
  4098      $$ = &Show{&ShowBasic{Command: VitessReplicationStatus, Filter: $3}}
  4099    }
  4100  | SHOW VITESS_THROTTLER STATUS
  4101    {
  4102      $$ = &ShowThrottlerStatus{}
  4103    }
  4104  | SHOW VSCHEMA TABLES
  4105    {
  4106      $$ = &Show{&ShowBasic{Command: VschemaTables}}
  4107    }
  4108  | SHOW VSCHEMA VINDEXES
  4109    {
  4110      $$ = &Show{&ShowBasic{Command: VschemaVindexes}}
  4111    }
  4112  | SHOW VSCHEMA VINDEXES from_or_on table_name
  4113    {
  4114      $$ = &Show{&ShowBasic{Command: VschemaVindexes, Tbl: $5}}
  4115    }
  4116  | SHOW WARNINGS
  4117    {
  4118      $$ = &Show{&ShowBasic{Command: Warnings}}
  4119    }
  4120  | SHOW VITESS_SHARDS like_or_where_opt
  4121    {
  4122      $$ = &Show{&ShowBasic{Command: VitessShards, Filter: $3}}
  4123    }
  4124  | SHOW VITESS_TABLETS like_or_where_opt
  4125    {
  4126      $$ = &Show{&ShowBasic{Command: VitessTablets, Filter: $3}}
  4127    }
  4128  | SHOW VITESS_TARGET
  4129    {
  4130      $$ = &Show{&ShowBasic{Command: VitessTarget}}
  4131    }
  4132  /*
  4133   * Catch-all for show statements without vitess keywords:
  4134   */
  4135  | SHOW ci_identifier ddl_skip_to_end
  4136    {
  4137      $$ = &Show{&ShowOther{Command: string($2.String())}}
  4138    }
  4139  | SHOW CREATE USER ddl_skip_to_end
  4140    {
  4141      $$ = &Show{&ShowOther{Command: string($2) + " " + string($3)}}
  4142     }
  4143  | SHOW BINARY ci_identifier ddl_skip_to_end /* SHOW BINARY ... */
  4144    {
  4145      $$ = &Show{&ShowOther{Command: string($2) + " " + $3.String()}}
  4146    }
  4147  | SHOW BINARY LOGS ddl_skip_to_end /* SHOW BINARY LOGS */
  4148    {
  4149      $$ = &Show{&ShowOther{Command: string($2) + " " + string($3)}}
  4150    }
  4151  | SHOW ENGINE ddl_skip_to_end
  4152    {
  4153      $$ = &Show{&ShowOther{Command: string($2)}}
  4154    }
  4155  | SHOW FUNCTION CODE table_name
  4156    {
  4157      $$ = &Show{&ShowOther{Command: string($2) + " " + string($3) + " " + String($4)}}
  4158    }
  4159  | SHOW PROCEDURE CODE table_name
  4160    {
  4161      $$ = &Show{&ShowOther{Command: string($2) + " " + string($3) + " " + String($4)}}
  4162    }
  4163  | SHOW full_opt PROCESSLIST from_database_opt like_or_where_opt
  4164    {
  4165      $$ = &Show{&ShowOther{Command: string($3)}}
  4166    }
  4167  | SHOW STORAGE ddl_skip_to_end
  4168    {
  4169      $$ = &Show{&ShowOther{Command: string($2)}}
  4170    }
  4171  
  4172  extended_opt:
  4173    /* empty */
  4174    {
  4175      $$ = ""
  4176    }
  4177    | EXTENDED
  4178    {
  4179      $$ = "extended "
  4180    }
  4181  
  4182  full_opt:
  4183    /* empty */
  4184    {
  4185      $$ = false
  4186    }
  4187  | FULL
  4188    {
  4189      $$ = true
  4190    }
  4191  
  4192  columns_or_fields:
  4193    COLUMNS
  4194    {
  4195        $$ = string($1)
  4196    }
  4197  | FIELDS
  4198    {
  4199        $$ = string($1)
  4200    }
  4201  
  4202  from_database_opt:
  4203    /* empty */
  4204    {
  4205      $$ = NewIdentifierCS("")
  4206    }
  4207  | FROM table_id
  4208    {
  4209      $$ = $2
  4210    }
  4211  | IN table_id
  4212    {
  4213      $$ = $2
  4214    }
  4215  
  4216  like_or_where_opt:
  4217    /* empty */
  4218    {
  4219      $$ = nil
  4220    }
  4221  | LIKE STRING
  4222    {
  4223      $$ = &ShowFilter{Like:string($2)}
  4224    }
  4225  | WHERE expression
  4226    {
  4227      $$ = &ShowFilter{Filter:$2}
  4228    }
  4229  
  4230  like_opt:
  4231    /* empty */
  4232      {
  4233        $$ = nil
  4234      }
  4235    | LIKE STRING
  4236      {
  4237        $$ = &ShowFilter{Like:string($2)}
  4238      }
  4239  
  4240  session_or_local_opt:
  4241    /* empty */
  4242    {
  4243      $$ = struct{}{}
  4244    }
  4245  | SESSION
  4246    {
  4247      $$ = struct{}{}
  4248    }
  4249  | LOCAL
  4250    {
  4251      $$ = struct{}{}
  4252    }
  4253  
  4254  from_or_on:
  4255    FROM
  4256    {
  4257      $$ = string($1)
  4258    }
  4259  | ON
  4260    {
  4261      $$ = string($1)
  4262    }
  4263  
  4264  use_statement:
  4265    USE use_table_name
  4266    {
  4267      $$ = &Use{DBName: $2}
  4268    }
  4269  | USE
  4270    {
  4271      $$ = &Use{DBName:IdentifierCS{v:""}}
  4272    }
  4273  | USE use_table_name AT_ID
  4274    {
  4275      $$ = &Use{DBName:NewIdentifierCS($2.String()+"@"+string($3))}
  4276    }
  4277  
  4278  // We use this because what is legal in `USE <tbl>` is not the same as in `SELECT ... FROM <tbl>`
  4279  use_table_name:
  4280    ID
  4281    {
  4282      $$ = NewIdentifierCS(string($1))
  4283    }
  4284  | AT_ID
  4285    {
  4286      $$ = NewIdentifierCS("@"+string($1))
  4287    }
  4288  | AT_AT_ID
  4289    {
  4290      $$ = NewIdentifierCS("@@"+string($1))
  4291    }
  4292  | non_reserved_keyword
  4293    {
  4294      $$ = NewIdentifierCS(string($1))
  4295    }
  4296  
  4297  
  4298  begin_statement:
  4299    BEGIN
  4300    {
  4301      $$ = &Begin{}
  4302    }
  4303  | START TRANSACTION tx_chacteristics_opt
  4304    {
  4305      $$ = &Begin{TxAccessModes: $3}
  4306    }
  4307  
  4308  tx_chacteristics_opt:
  4309    {
  4310      $$ = nil
  4311    }
  4312  | tx_chars
  4313    {
  4314      $$ = $1
  4315    }
  4316  
  4317  tx_chars:
  4318    tx_char
  4319    {
  4320      $$ = []TxAccessMode{$1}
  4321    }
  4322  | tx_chars ',' tx_char
  4323    {
  4324      $$ = append($1, $3)
  4325    }
  4326  
  4327  tx_char:
  4328    WITH CONSISTENT SNAPSHOT
  4329    {
  4330      $$ = WithConsistentSnapshot
  4331    }
  4332  | READ WRITE
  4333    {
  4334      $$ = ReadWrite
  4335    }
  4336  | READ ONLY
  4337    {
  4338      $$ = ReadOnly
  4339    }
  4340  
  4341  
  4342  commit_statement:
  4343    COMMIT
  4344    {
  4345      $$ = &Commit{}
  4346    }
  4347  
  4348  rollback_statement:
  4349    ROLLBACK
  4350    {
  4351      $$ = &Rollback{}
  4352    }
  4353  | ROLLBACK work_opt TO savepoint_opt sql_id
  4354    {
  4355      $$ = &SRollback{Name: $5}
  4356    }
  4357  
  4358  work_opt:
  4359    { $$ = struct{}{} }
  4360  | WORK
  4361    { $$ = struct{}{} }
  4362  
  4363  savepoint_opt:
  4364    { $$ = struct{}{} }
  4365  | SAVEPOINT
  4366    { $$ = struct{}{} }
  4367  
  4368  savepoint_statement:
  4369    SAVEPOINT sql_id
  4370    {
  4371      $$ = &Savepoint{Name: $2}
  4372    }
  4373  
  4374  release_statement:
  4375    RELEASE SAVEPOINT sql_id
  4376    {
  4377      $$ = &Release{Name: $3}
  4378    }
  4379  
  4380  explain_format_opt:
  4381    {
  4382      $$ = EmptyType
  4383    }
  4384  | FORMAT '=' JSON
  4385    {
  4386      $$ = JSONType
  4387    }
  4388  | FORMAT '=' TREE
  4389    {
  4390      $$ = TreeType
  4391    }
  4392  | FORMAT '=' VITESS
  4393    {
  4394      $$ = VitessType
  4395    }
  4396  | FORMAT '=' VTEXPLAIN
  4397    {
  4398      $$ = VTExplainType
  4399    }
  4400  | FORMAT '=' TRADITIONAL
  4401    {
  4402      $$ = TraditionalType
  4403    }
  4404  | ANALYZE
  4405    {
  4406      $$ = AnalyzeType
  4407    }
  4408  
  4409  vexplain_type_opt:
  4410    {
  4411      $$ = PlanVExplainType
  4412    }
  4413  | PLAN
  4414    {
  4415      $$ = PlanVExplainType
  4416    }
  4417  | ALL
  4418    {
  4419      $$ = AllVExplainType
  4420    }
  4421  | QUERIES
  4422    {
  4423      $$ = QueriesVExplainType
  4424    }
  4425  
  4426  explain_synonyms:
  4427    EXPLAIN
  4428    {
  4429      $$ = $1
  4430    }
  4431  | DESCRIBE
  4432    {
  4433      $$ = $1
  4434    }
  4435  | DESC
  4436    {
  4437      $$ = $1
  4438    }
  4439  
  4440  explainable_statement:
  4441    select_statement
  4442    {
  4443      $$ = $1
  4444    }
  4445  | update_statement
  4446    {
  4447      $$ = $1
  4448    }
  4449  | insert_statement
  4450    {
  4451      $$ = $1
  4452    }
  4453  | delete_statement
  4454    {
  4455      $$ = $1
  4456    }
  4457  
  4458  wild_opt:
  4459    {
  4460      $$ = ""
  4461    }
  4462  | sql_id
  4463    {
  4464      $$ = $1.val
  4465    }
  4466  | STRING
  4467    {
  4468      $$ = encodeSQLString($1)
  4469    }
  4470  
  4471  explain_statement:
  4472    explain_synonyms comment_opt table_name wild_opt
  4473    {
  4474      $$ = &ExplainTab{Table: $3, Wild: $4}
  4475    }
  4476  | explain_synonyms comment_opt explain_format_opt explainable_statement
  4477    {
  4478      $$ = &ExplainStmt{Type: $3, Statement: $4, Comments: Comments($2).Parsed()}
  4479    }
  4480  
  4481  vexplain_statement:
  4482    VEXPLAIN comment_opt vexplain_type_opt explainable_statement
  4483    {
  4484      $$ = &VExplainStmt{Type: $3, Statement: $4, Comments: Comments($2).Parsed()}
  4485    }
  4486  
  4487  other_statement:
  4488    REPAIR skip_to_end
  4489    {
  4490      $$ = &OtherAdmin{}
  4491    }
  4492  | OPTIMIZE skip_to_end
  4493    {
  4494      $$ = &OtherAdmin{}
  4495    }
  4496  
  4497  lock_statement:
  4498    LOCK TABLES lock_table_list
  4499    {
  4500      $$ = &LockTables{Tables: $3}
  4501    }
  4502  
  4503  lock_table_list:
  4504    lock_table
  4505    {
  4506      $$ = TableAndLockTypes{$1}
  4507    }
  4508  | lock_table_list ',' lock_table
  4509    {
  4510      $$ = append($1, $3)
  4511    }
  4512  
  4513  lock_table:
  4514    aliased_table_name lock_type
  4515    {
  4516      $$ = &TableAndLockType{Table:$1, Lock:$2}
  4517    }
  4518  
  4519  lock_type:
  4520    READ
  4521    {
  4522      $$ = Read
  4523    }
  4524  | READ LOCAL
  4525    {
  4526      $$ = ReadLocal
  4527    }
  4528  | WRITE
  4529    {
  4530      $$ = Write
  4531    }
  4532  | LOW_PRIORITY WRITE
  4533    {
  4534      $$ = LowPriorityWrite
  4535    }
  4536  
  4537  unlock_statement:
  4538    UNLOCK TABLES
  4539    {
  4540      $$ = &UnlockTables{}
  4541    }
  4542  
  4543  revert_statement:
  4544    REVERT comment_opt VITESS_MIGRATION STRING
  4545    {
  4546      $$ = &RevertMigration{Comments: Comments($2).Parsed(), UUID: string($4)}
  4547    }
  4548  
  4549  flush_statement:
  4550    FLUSH local_opt flush_option_list
  4551    {
  4552      $$ = &Flush{IsLocal: $2, FlushOptions:$3}
  4553    }
  4554  | FLUSH local_opt TABLES
  4555    {
  4556      $$ = &Flush{IsLocal: $2}
  4557    }
  4558  | FLUSH local_opt TABLES WITH READ LOCK
  4559    {
  4560      $$ = &Flush{IsLocal: $2, WithLock:true}
  4561    }
  4562  | FLUSH local_opt TABLES table_name_list
  4563    {
  4564      $$ = &Flush{IsLocal: $2, TableNames:$4}
  4565    }
  4566  | FLUSH local_opt TABLES table_name_list WITH READ LOCK
  4567    {
  4568      $$ = &Flush{IsLocal: $2, TableNames:$4, WithLock:true}
  4569    }
  4570  | FLUSH local_opt TABLES table_name_list FOR EXPORT
  4571    {
  4572      $$ = &Flush{IsLocal: $2, TableNames:$4, ForExport:true}
  4573    }
  4574  
  4575  flush_option_list:
  4576    flush_option
  4577    {
  4578      $$ = []string{$1}
  4579    }
  4580  | flush_option_list ',' flush_option
  4581    {
  4582      $$ = append($1,$3)
  4583    }
  4584  
  4585  flush_option:
  4586    BINARY LOGS
  4587    {
  4588      $$ = string($1) + " " + string($2)
  4589    }
  4590  | ENGINE LOGS
  4591    {
  4592      $$ = string($1) + " " + string($2)
  4593    }
  4594  | ERROR LOGS
  4595    {
  4596      $$ = string($1) + " " + string($2)
  4597    }
  4598  | GENERAL LOGS
  4599    {
  4600      $$ = string($1) + " " + string($2)
  4601    }
  4602  | HOSTS
  4603    {
  4604      $$ = string($1)
  4605    }
  4606  | LOGS
  4607    {
  4608      $$ = string($1)
  4609    }
  4610  | PRIVILEGES
  4611    {
  4612      $$ = string($1)
  4613    }
  4614  | RELAY LOGS for_channel_opt
  4615    {
  4616      $$ = string($1) + " " + string($2) + $3
  4617    }
  4618  | SLOW LOGS
  4619    {
  4620      $$ = string($1) + " " + string($2)
  4621    }
  4622  | OPTIMIZER_COSTS
  4623    {
  4624      $$ = string($1)
  4625    }
  4626  | STATUS
  4627    {
  4628      $$ = string($1)
  4629    }
  4630  | USER_RESOURCES
  4631    {
  4632      $$ = string($1)
  4633    }
  4634  
  4635  local_opt:
  4636    {
  4637      $$ = false
  4638    }
  4639  | LOCAL
  4640    {
  4641      $$ = true
  4642    }
  4643  | NO_WRITE_TO_BINLOG
  4644    {
  4645      $$ = true
  4646    }
  4647  
  4648  for_channel_opt:
  4649    {
  4650      $$ = ""
  4651    }
  4652  | FOR CHANNEL ci_identifier
  4653    {
  4654      $$ = " " + string($1) + " " + string($2) + " " + $3.String()
  4655    }
  4656  
  4657  comment_opt:
  4658    {
  4659      setAllowComments(yylex, true)
  4660    }
  4661    comment_list
  4662    {
  4663      $$ = $2
  4664      setAllowComments(yylex, false)
  4665    }
  4666  
  4667  comment_list:
  4668    {
  4669      $$ = nil
  4670    }
  4671  | comment_list COMMENT
  4672    {
  4673      $$ = append($1, $2)
  4674    }
  4675  
  4676  union_op:
  4677    UNION
  4678    {
  4679      $$ = true
  4680    }
  4681  | UNION ALL
  4682    {
  4683      $$ = false
  4684    }
  4685  | UNION DISTINCT
  4686    {
  4687      $$ = true
  4688    }
  4689  
  4690  cache_opt:
  4691  {
  4692    $$ = ""
  4693  }
  4694  | SQL_NO_CACHE
  4695  {
  4696    $$ = SQLNoCacheStr
  4697  }
  4698  | SQL_CACHE
  4699  {
  4700    $$ = SQLCacheStr
  4701  }
  4702  
  4703  distinct_opt:
  4704    {
  4705      $$ = false
  4706    }
  4707  | DISTINCT
  4708    {
  4709      $$ = true
  4710    }
  4711  | DISTINCTROW
  4712    {
  4713      $$ = true
  4714    }
  4715  
  4716  prepare_statement:
  4717    PREPARE comment_opt sql_id FROM text_literal_or_arg
  4718    {
  4719      $$ = &PrepareStmt{Name:$3, Comments: Comments($2).Parsed(), Statement:$5}
  4720    }
  4721  | PREPARE comment_opt sql_id FROM user_defined_variable
  4722    {
  4723      $$ = &PrepareStmt{
  4724      	Name:$3,
  4725      	Comments: Comments($2).Parsed(),
  4726      	Statement: $5,
  4727      }
  4728    }
  4729  
  4730  execute_statement:
  4731    EXECUTE comment_opt sql_id execute_statement_list_opt
  4732    {
  4733      $$ = &ExecuteStmt{Name:$3, Comments: Comments($2).Parsed(), Arguments: $4}
  4734    }
  4735  
  4736  execute_statement_list_opt: // execute db.foo(@apa) using @foo, @bar
  4737    {
  4738      $$ = nil
  4739    }
  4740  | USING at_id_list
  4741    {
  4742      $$ = $2
  4743    }
  4744  
  4745  deallocate_statement:
  4746    DEALLOCATE comment_opt PREPARE sql_id
  4747    {
  4748      $$ = &DeallocateStmt{Type:DeallocateType, Comments: Comments($2).Parsed(), Name:$4}
  4749    }
  4750  | DROP comment_opt PREPARE sql_id
  4751    {
  4752      $$ = &DeallocateStmt{Type: DropType, Comments: Comments($2).Parsed(), Name: $4}
  4753    }
  4754  
  4755  select_expression_list_opt:
  4756    {
  4757      $$ = nil
  4758    }
  4759  | select_expression_list
  4760    {
  4761      $$ = $1
  4762    }
  4763  
  4764  select_options:
  4765    {
  4766      $$ = nil
  4767    }
  4768  | select_option
  4769    {
  4770      $$ = []string{$1}
  4771    }
  4772  | select_option select_option // TODO: figure out a way to do this recursively instead.
  4773    {                           // TODO: This is a hack since I couldn't get it to work in a nicer way. I got 'conflicts: 8 shift/reduce'
  4774      $$ = []string{$1, $2}
  4775    }
  4776  | select_option select_option select_option
  4777    {
  4778      $$ = []string{$1, $2, $3}
  4779    }
  4780  | select_option select_option select_option select_option
  4781    {
  4782      $$ = []string{$1, $2, $3, $4}
  4783    }
  4784  
  4785  select_option:
  4786    SQL_NO_CACHE
  4787    {
  4788      $$ = SQLNoCacheStr
  4789    }
  4790  | SQL_CACHE
  4791    {
  4792      $$ = SQLCacheStr
  4793    }
  4794  | DISTINCT
  4795    {
  4796      $$ = DistinctStr
  4797    }
  4798  | DISTINCTROW
  4799    {
  4800      $$ = DistinctStr
  4801    }
  4802  | STRAIGHT_JOIN
  4803    {
  4804      $$ = StraightJoinHint
  4805    }
  4806  | SQL_CALC_FOUND_ROWS
  4807    {
  4808      $$ = SQLCalcFoundRowsStr
  4809    }
  4810  | ALL
  4811    {
  4812      $$ = AllStr // These are not picked up by NewSelect, and so ALL will be dropped. But this is OK, since it's redundant anyway
  4813    }
  4814  
  4815  select_expression_list:
  4816    select_expression
  4817    {
  4818      $$ = SelectExprs{$1}
  4819    }
  4820  | select_expression_list ',' select_expression
  4821    {
  4822      $$ = append($$, $3)
  4823    }
  4824  
  4825  select_expression:
  4826    '*'
  4827    {
  4828      $$ = &StarExpr{}
  4829    }
  4830  | expression as_ci_opt
  4831    {
  4832      $$ = &AliasedExpr{Expr: $1, As: $2}
  4833    }
  4834  | table_id '.' '*'
  4835    {
  4836      $$ = &StarExpr{TableName: TableName{Name: $1}}
  4837    }
  4838  | table_id '.' reserved_table_id '.' '*'
  4839    {
  4840      $$ = &StarExpr{TableName: TableName{Qualifier: $1, Name: $3}}
  4841    }
  4842  
  4843  as_ci_opt:
  4844    {
  4845      $$ = IdentifierCI{}
  4846    }
  4847  | col_alias
  4848    {
  4849      $$ = $1
  4850    }
  4851  | AS col_alias
  4852    {
  4853      $$ = $2
  4854    }
  4855  
  4856  col_alias:
  4857    sql_id
  4858  | STRING
  4859    {
  4860      $$ = NewIdentifierCI(string($1))
  4861    }
  4862  
  4863  from_opt:
  4864    %prec EMPTY_FROM_CLAUSE {
  4865      $$ = TableExprs{&AliasedTableExpr{Expr:TableName{Name: NewIdentifierCS("dual")}}}
  4866    }
  4867    | from_clause
  4868    {
  4869    	$$ = $1
  4870    }
  4871  
  4872  from_clause:
  4873  FROM table_references
  4874    {
  4875      $$ = $2
  4876    }
  4877  
  4878  table_references:
  4879    table_reference
  4880    {
  4881      $$ = TableExprs{$1}
  4882    }
  4883  | table_references ',' table_reference
  4884    {
  4885      $$ = append($$, $3)
  4886    }
  4887  
  4888  table_reference:
  4889    table_factor
  4890  | join_table
  4891  
  4892  table_factor:
  4893    aliased_table_name
  4894    {
  4895      $$ = $1
  4896    }
  4897  | derived_table as_opt table_id column_list_opt
  4898    {
  4899      $$ = &AliasedTableExpr{Expr:$1, As: $3, Columns: $4}
  4900    }
  4901  | openb table_references closeb
  4902    {
  4903      $$ = &ParenTableExpr{Exprs: $2}
  4904    }
  4905  | json_table_function
  4906    {
  4907      $$ = $1
  4908    }
  4909  
  4910  derived_table:
  4911    query_expression_parens
  4912    {
  4913      $$ = &DerivedTable{Lateral: false, Select: $1}
  4914    }
  4915  | LATERAL query_expression_parens
  4916    {
  4917      $$ = &DerivedTable{Lateral: true, Select: $2}
  4918    }
  4919  
  4920  aliased_table_name:
  4921  table_name as_opt_id index_hint_list_opt
  4922    {
  4923      $$ = &AliasedTableExpr{Expr:$1, As: $2, Hints: $3}
  4924    }
  4925  | table_name PARTITION openb partition_list closeb as_opt_id index_hint_list_opt
  4926    {
  4927      $$ = &AliasedTableExpr{Expr:$1, Partitions: $4, As: $6, Hints: $7}
  4928    }
  4929  
  4930  column_list_opt:
  4931    {
  4932      $$ = nil
  4933    }
  4934  | '(' column_list ')'
  4935    {
  4936      $$ = $2
  4937    }
  4938  
  4939  column_list_empty:
  4940    {
  4941      $$ = nil
  4942    }
  4943  | column_list
  4944    {
  4945      $$ = $1
  4946    }
  4947  
  4948  column_list:
  4949    sql_id
  4950    {
  4951      $$ = Columns{$1}
  4952    }
  4953  | column_list ',' sql_id
  4954    {
  4955      $$ = append($$, $3)
  4956    }
  4957  
  4958  at_id_list:
  4959    user_defined_variable
  4960    {
  4961      $$ = []*Variable{$1}
  4962    }
  4963  | at_id_list ',' user_defined_variable
  4964    {
  4965      $$ = append($$, $3)
  4966    }
  4967  
  4968  index_list:
  4969    sql_id
  4970    {
  4971      $$ = Columns{$1}
  4972    }
  4973  | PRIMARY
  4974    {
  4975      $$ = Columns{NewIdentifierCI(string($1))}
  4976    }
  4977  | index_list ',' sql_id
  4978    {
  4979      $$ = append($$, $3)
  4980    }
  4981  | index_list ',' PRIMARY
  4982    {
  4983      $$ = append($$, NewIdentifierCI(string($3)))
  4984    }
  4985  
  4986  partition_list:
  4987    sql_id
  4988    {
  4989      $$ = Partitions{$1}
  4990    }
  4991  | partition_list ',' sql_id
  4992    {
  4993      $$ = append($$, $3)
  4994    }
  4995  
  4996  // There is a grammar conflict here:
  4997  // 1: INSERT INTO a SELECT * FROM b JOIN c ON b.i = c.i
  4998  // 2: INSERT INTO a SELECT * FROM b JOIN c ON DUPLICATE KEY UPDATE a.i = 1
  4999  // When yacc encounters the ON clause, it cannot determine which way to
  5000  // resolve. The %prec override below makes the parser choose the
  5001  // first construct, which automatically makes the second construct a
  5002  // syntax error. This is the same behavior as MySQL.
  5003  join_table:
  5004    table_reference inner_join table_factor join_condition_opt
  5005    {
  5006      $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4}
  5007    }
  5008  | table_reference straight_join table_factor on_expression_opt
  5009    {
  5010      $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4}
  5011    }
  5012  | table_reference outer_join table_reference join_condition
  5013    {
  5014      $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, Condition: $4}
  5015    }
  5016  | table_reference natural_join table_factor
  5017    {
  5018      $$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3}
  5019    }
  5020  
  5021  join_condition:
  5022    ON expression
  5023    { $$ = &JoinCondition{On: $2} }
  5024  | USING '(' column_list ')'
  5025    { $$ = &JoinCondition{Using: $3} }
  5026  
  5027  join_condition_opt:
  5028  %prec JOIN
  5029    { $$ = &JoinCondition{} }
  5030  | join_condition
  5031    { $$ = $1 }
  5032  
  5033  on_expression_opt:
  5034  %prec JOIN
  5035    { $$ = &JoinCondition{} }
  5036  | ON expression
  5037    { $$ = &JoinCondition{On: $2} }
  5038  
  5039  as_opt:
  5040    { $$ = struct{}{} }
  5041  | AS
  5042    { $$ = struct{}{} }
  5043  
  5044  as_opt_id:
  5045    {
  5046      $$ = NewIdentifierCS("")
  5047    }
  5048  | table_alias
  5049    {
  5050      $$ = $1
  5051    }
  5052  | AS table_alias
  5053    {
  5054      $$ = $2
  5055    }
  5056  
  5057  table_alias:
  5058    table_id
  5059  | STRING
  5060    {
  5061      $$ = NewIdentifierCS(string($1))
  5062    }
  5063  
  5064  inner_join:
  5065    JOIN
  5066    {
  5067      $$ = NormalJoinType
  5068    }
  5069  | INNER JOIN
  5070    {
  5071      $$ = NormalJoinType
  5072    }
  5073  | CROSS JOIN
  5074    {
  5075      $$ = NormalJoinType
  5076    }
  5077  
  5078  straight_join:
  5079    STRAIGHT_JOIN
  5080    {
  5081      $$ = StraightJoinType
  5082    }
  5083  
  5084  outer_join:
  5085    LEFT JOIN
  5086    {
  5087      $$ = LeftJoinType
  5088    }
  5089  | LEFT OUTER JOIN
  5090    {
  5091      $$ = LeftJoinType
  5092    }
  5093  | RIGHT JOIN
  5094    {
  5095      $$ = RightJoinType
  5096    }
  5097  | RIGHT OUTER JOIN
  5098    {
  5099      $$ = RightJoinType
  5100    }
  5101  
  5102  natural_join:
  5103   NATURAL JOIN
  5104    {
  5105      $$ = NaturalJoinType
  5106    }
  5107  | NATURAL outer_join
  5108    {
  5109      if $2 == LeftJoinType {
  5110        $$ = NaturalLeftJoinType
  5111      } else {
  5112        $$ = NaturalRightJoinType
  5113      }
  5114    }
  5115  
  5116  into_table_name:
  5117    INTO table_name
  5118    {
  5119      $$ = $2
  5120    }
  5121  | table_name
  5122    {
  5123      $$ = $1
  5124    }
  5125  
  5126  table_name:
  5127    table_id
  5128    {
  5129      $$ = TableName{Name: $1}
  5130    }
  5131  | table_id '.' reserved_table_id
  5132    {
  5133      $$ = TableName{Qualifier: $1, Name: $3}
  5134    }
  5135  
  5136  delete_table_name:
  5137  table_id '.' '*'
  5138    {
  5139      $$ = TableName{Name: $1}
  5140    }
  5141  
  5142  index_hint_list_opt:
  5143    {
  5144      $$ = nil
  5145    }
  5146  | index_hint_list
  5147    {
  5148      $$ = $1
  5149    }
  5150  
  5151  index_hint_list:
  5152  index_hint
  5153    {
  5154      $$ = IndexHints{$1}
  5155    }
  5156  | index_hint_list index_hint
  5157    {
  5158      $$ = append($1,$2)
  5159    }
  5160  
  5161  index_hint:
  5162    USE index_or_key index_hint_for_opt openb index_list closeb
  5163    {
  5164      $$ = &IndexHint{Type: UseOp, ForType:$3, Indexes: $5}
  5165    }
  5166  | USE index_or_key index_hint_for_opt openb closeb
  5167    {
  5168      $$ = &IndexHint{Type: UseOp, ForType: $3}
  5169    }
  5170  | IGNORE index_or_key index_hint_for_opt openb index_list closeb
  5171    {
  5172      $$ = &IndexHint{Type: IgnoreOp, ForType: $3, Indexes: $5}
  5173    }
  5174  | FORCE index_or_key index_hint_for_opt openb index_list closeb
  5175    {
  5176      $$ = &IndexHint{Type: ForceOp, ForType: $3, Indexes: $5}
  5177    }
  5178  
  5179  index_hint_for_opt:
  5180    {
  5181      $$ = NoForType
  5182    }
  5183  | FOR JOIN
  5184    {
  5185      $$ = JoinForType
  5186    }
  5187  | FOR ORDER BY
  5188    {
  5189      $$ = OrderByForType
  5190    }
  5191  | FOR GROUP BY
  5192    {
  5193      $$ = GroupByForType
  5194    }
  5195  
  5196  
  5197  where_expression_opt:
  5198    {
  5199      $$ = nil
  5200    }
  5201  | WHERE expression
  5202    {
  5203      $$ = $2
  5204    }
  5205  
  5206  /* all possible expressions */
  5207  expression:
  5208    expression OR expression %prec OR
  5209    {
  5210  	$$ = &OrExpr{Left: $1, Right: $3}
  5211    }
  5212  | expression XOR expression %prec XOR
  5213    {
  5214  	$$ = &XorExpr{Left: $1, Right: $3}
  5215    }
  5216  | expression AND expression %prec AND
  5217    {
  5218  	$$ = &AndExpr{Left: $1, Right: $3}
  5219    }
  5220  | NOT expression %prec NOT
  5221    {
  5222  	  $$ = &NotExpr{Expr: $2}
  5223    }
  5224  | bool_pri IS is_suffix %prec IS
  5225    {
  5226  	 $$ = &IsExpr{Left: $1, Right: $3}
  5227    }
  5228  | bool_pri %prec EXPRESSION_PREC_SETTER
  5229    {
  5230  	$$ = $1
  5231    }
  5232  | expression MEMBER OF openb expression closeb
  5233    {
  5234      $$ = &MemberOfExpr{Value: $1, JSONArr:$5 }
  5235    }
  5236  
  5237  bool_pri:
  5238  bool_pri IS NULL %prec IS
  5239    {
  5240  	 $$ = &IsExpr{Left: $1, Right: IsNullOp}
  5241    }
  5242  | bool_pri IS NOT NULL %prec IS
  5243    {
  5244    	$$ = &IsExpr{Left: $1, Right: IsNotNullOp}
  5245    }
  5246  | bool_pri compare predicate
  5247    {
  5248  	$$ = &ComparisonExpr{Left: $1, Operator: $2, Right: $3}
  5249    }
  5250  | predicate %prec EXPRESSION_PREC_SETTER
  5251    {
  5252  	$$ = $1
  5253    }
  5254  
  5255  predicate:
  5256  bit_expr IN col_tuple
  5257    {
  5258  	$$ = &ComparisonExpr{Left: $1, Operator: InOp, Right: $3}
  5259    }
  5260  | bit_expr NOT IN col_tuple
  5261    {
  5262  	$$ = &ComparisonExpr{Left: $1, Operator: NotInOp, Right: $4}
  5263    }
  5264  | bit_expr BETWEEN bit_expr AND predicate
  5265    {
  5266  	 $$ = &BetweenExpr{Left: $1, IsBetween: true, From: $3, To: $5}
  5267    }
  5268  | bit_expr NOT BETWEEN bit_expr AND predicate
  5269    {
  5270  	$$ = &BetweenExpr{Left: $1, IsBetween: false, From: $4, To: $6}
  5271    }
  5272  | bit_expr LIKE simple_expr
  5273    {
  5274  	  $$ = &ComparisonExpr{Left: $1, Operator: LikeOp, Right: $3}
  5275    }
  5276  | bit_expr NOT LIKE simple_expr
  5277    {
  5278  	$$ = &ComparisonExpr{Left: $1, Operator: NotLikeOp, Right: $4}
  5279    }
  5280  | bit_expr LIKE simple_expr ESCAPE simple_expr %prec LIKE
  5281    {
  5282  	  $$ = &ComparisonExpr{Left: $1, Operator: LikeOp, Right: $3, Escape: $5}
  5283    }
  5284  | bit_expr NOT LIKE simple_expr ESCAPE simple_expr %prec LIKE
  5285    {
  5286  	$$ = &ComparisonExpr{Left: $1, Operator: NotLikeOp, Right: $4, Escape: $6}
  5287    }
  5288  | bit_expr regexp_symbol bit_expr
  5289    {
  5290  	$$ = &ComparisonExpr{Left: $1, Operator: RegexpOp, Right: $3}
  5291    }
  5292  | bit_expr NOT regexp_symbol bit_expr
  5293    {
  5294  	 $$ = &ComparisonExpr{Left: $1, Operator: NotRegexpOp, Right: $4}
  5295    }
  5296  | bit_expr %prec EXPRESSION_PREC_SETTER
  5297   {
  5298  	$$ = $1
  5299   }
  5300  
  5301  regexp_symbol:
  5302    REGEXP
  5303    {
  5304    }
  5305  | RLIKE
  5306    {
  5307    }
  5308  
  5309  
  5310  bit_expr:
  5311  bit_expr '|' bit_expr %prec '|'
  5312    {
  5313  	  $$ = &BinaryExpr{Left: $1, Operator: BitOrOp, Right: $3}
  5314    }
  5315  | bit_expr '&' bit_expr %prec '&'
  5316    {
  5317  	  $$ = &BinaryExpr{Left: $1, Operator: BitAndOp, Right: $3}
  5318    }
  5319  | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
  5320    {
  5321  	  $$ = &BinaryExpr{Left: $1, Operator: ShiftLeftOp, Right: $3}
  5322    }
  5323  | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
  5324    {
  5325  	  $$ = &BinaryExpr{Left: $1, Operator: ShiftRightOp, Right: $3}
  5326    }
  5327  | bit_expr '+' bit_expr %prec '+'
  5328    {
  5329  	  $$ = &BinaryExpr{Left: $1, Operator: PlusOp, Right: $3}
  5330    }
  5331  | bit_expr '-' bit_expr %prec '-'
  5332    {
  5333  	  $$ = &BinaryExpr{Left: $1, Operator: MinusOp, Right: $3}
  5334    }
  5335  | bit_expr '*' bit_expr %prec '*'
  5336    {
  5337  	  $$ = &BinaryExpr{Left: $1, Operator: MultOp, Right: $3}
  5338    }
  5339  | bit_expr '/' bit_expr %prec '/'
  5340    {
  5341  	  $$ = &BinaryExpr{Left: $1, Operator: DivOp, Right: $3}
  5342    }
  5343  | bit_expr '%' bit_expr %prec '%'
  5344    {
  5345  	  $$ = &BinaryExpr{Left: $1, Operator: ModOp, Right: $3}
  5346    }
  5347  | bit_expr DIV bit_expr %prec DIV
  5348    {
  5349  	  $$ = &BinaryExpr{Left: $1, Operator: IntDivOp, Right: $3}
  5350    }
  5351  | bit_expr MOD bit_expr %prec MOD
  5352    {
  5353  	  $$ = &BinaryExpr{Left: $1, Operator: ModOp, Right: $3}
  5354    }
  5355  | bit_expr '^' bit_expr %prec '^'
  5356    {
  5357  	  $$ = &BinaryExpr{Left: $1, Operator: BitXorOp, Right: $3}
  5358    }
  5359  | simple_expr %prec EXPRESSION_PREC_SETTER
  5360    {
  5361  	$$ = $1
  5362    }
  5363  
  5364  simple_expr:
  5365  function_call_keyword
  5366    {
  5367    	$$ = $1
  5368    }
  5369  | function_call_nonkeyword
  5370    {
  5371    	$$ = $1
  5372    }
  5373  | function_call_generic
  5374    {
  5375    	$$ = $1
  5376    }
  5377  | function_call_conflict
  5378    {
  5379    	$$ = $1
  5380    }
  5381  | simple_expr COLLATE charset %prec UNARY
  5382    {
  5383  	$$ = &CollateExpr{Expr: $1, Collation: $3}
  5384    }
  5385  | literal_or_null
  5386    {
  5387    	$$ = $1
  5388    }
  5389  | column_name_or_offset
  5390    {
  5391    	$$ = $1
  5392    }
  5393  | variable_expr
  5394    {
  5395    	$$ = $1
  5396    }
  5397  | '+' simple_expr %prec UNARY
  5398    {
  5399  	$$= $2; // TODO: do we really want to ignore unary '+' before any kind of literals?
  5400    }
  5401  | '-' simple_expr %prec UNARY
  5402    {
  5403  	$$ = &UnaryExpr{Operator: UMinusOp, Expr: $2}
  5404    }
  5405  | '~' simple_expr %prec UNARY
  5406    {
  5407  	$$ = &UnaryExpr{Operator: TildaOp, Expr: $2}
  5408    }
  5409  | '!' simple_expr %prec UNARY
  5410    {
  5411      $$ = &UnaryExpr{Operator: BangOp, Expr: $2}
  5412    }
  5413  | subquery
  5414    {
  5415  	$$= $1
  5416    }
  5417  | tuple_expression
  5418    {
  5419  	$$ = $1
  5420    }
  5421  | EXISTS subquery
  5422    {
  5423  	$$ = &ExistsExpr{Subquery: $2}
  5424    }
  5425  | MATCH column_names_opt_paren AGAINST openb bit_expr match_option closeb
  5426    {
  5427    $$ = &MatchExpr{Columns: $2, Expr: $5, Option: $6}
  5428    }
  5429  | CAST openb expression AS convert_type array_opt closeb
  5430    {
  5431      $$ = &CastExpr{Expr: $3, Type: $5, Array: $6}
  5432    }
  5433  | CONVERT openb expression ',' convert_type closeb
  5434    {
  5435      $$ = &ConvertExpr{Expr: $3, Type: $5}
  5436    }
  5437  | CONVERT openb expression USING charset closeb
  5438    {
  5439      $$ = &ConvertUsingExpr{Expr: $3, Type: $5}
  5440    }
  5441  | BINARY simple_expr %prec UNARY
  5442    {
  5443      // From: https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary
  5444      // To convert a string expression to a binary string, these constructs are equivalent:
  5445      //    CAST(expr AS BINARY)
  5446      //    BINARY expr
  5447      $$ = &ConvertExpr{Expr: $2, Type: &ConvertType{Type: $1}}
  5448    }
  5449  | DEFAULT default_opt
  5450    {
  5451  	 $$ = &Default{ColName: $2}
  5452    }
  5453  | interval_value
  5454    {
  5455  	// INTERVAL can trigger a shift / reduce conflict. We want
  5456  	// to shift here for the interval rule. In case we do have
  5457  	// the additional expression_list below, we'd pick that path
  5458  	// and thus properly parse it as a function when needed.
  5459  	$$ = $1
  5460    }
  5461  | INTERVAL openb expression ',' expression_list closeb
  5462  {
  5463         $$ = &IntervalFuncExpr{Expr: $3, Exprs: $5}
  5464  }
  5465  | column_name_or_offset JSON_EXTRACT_OP text_literal_or_arg
  5466    {
  5467  	$$ = &BinaryExpr{Left: $1, Operator: JSONExtractOp, Right: $3}
  5468    }
  5469  | column_name_or_offset JSON_UNQUOTE_EXTRACT_OP text_literal_or_arg
  5470    {
  5471  	$$ = &BinaryExpr{Left: $1, Operator: JSONUnquoteExtractOp, Right: $3}
  5472    }
  5473  
  5474  interval_value:
  5475    INTERVAL bit_expr sql_id
  5476    {
  5477       $$ = &IntervalExpr{Expr: $2, Unit: $3.String()}
  5478    }
  5479  
  5480  column_names_opt_paren:
  5481    column_names
  5482    {
  5483      $$ = $1
  5484    }
  5485  | openb column_names closeb
  5486    {
  5487      $$ = $2
  5488    }
  5489  
  5490  column_names:
  5491    column_name
  5492    {
  5493      $$ = []*ColName{$1}
  5494    }
  5495  | column_names ',' column_name
  5496    {
  5497      $$ = append($1, $3)
  5498    }
  5499  
  5500  trim_type:
  5501    BOTH
  5502    {
  5503      $$ = BothTrimType
  5504    }
  5505  | LEADING
  5506    {
  5507      $$ = LeadingTrimType
  5508    }
  5509  | TRAILING
  5510    {
  5511      $$ = TrailingTrimType
  5512    }
  5513  
  5514  frame_units:
  5515    ROWS
  5516    {
  5517      $$ = FrameRowsType
  5518    }
  5519  | RANGE
  5520    {
  5521      $$ = FrameRangeType
  5522    }
  5523  
  5524  
  5525  argument_less_window_expr_type:
  5526    CUME_DIST
  5527    {
  5528      $$ = CumeDistExprType
  5529    }
  5530  | DENSE_RANK
  5531    {
  5532      $$ = DenseRankExprType
  5533    }
  5534  | PERCENT_RANK
  5535    {
  5536      $$ = PercentRankExprType
  5537    }
  5538  | RANK
  5539    {
  5540      $$ = RankExprType
  5541    }
  5542  | ROW_NUMBER
  5543    {
  5544      $$ = RowNumberExprType
  5545    }
  5546  
  5547  frame_point:
  5548    CURRENT ROW
  5549    {
  5550      $$ = &FramePoint{Type:CurrentRowType}
  5551    }
  5552  | UNBOUNDED PRECEDING
  5553    {
  5554      $$ = &FramePoint{Type:UnboundedPrecedingType}
  5555    }
  5556  | UNBOUNDED FOLLOWING
  5557    {
  5558      $$ = &FramePoint{Type:UnboundedFollowingType}
  5559    }
  5560  | frame_expression PRECEDING
  5561    {
  5562      $$ = &FramePoint{Type:ExprPrecedingType, Expr:$1}
  5563    }
  5564  | frame_expression FOLLOWING
  5565    {
  5566      $$ = &FramePoint{Type:ExprFollowingType, Expr:$1}
  5567    }
  5568  
  5569  frame_expression:
  5570    NUM_literal
  5571    {
  5572      $$ = $1
  5573    }
  5574  | interval_value
  5575    {
  5576      $$ = $1
  5577    }
  5578  
  5579  frame_clause_opt:
  5580    {
  5581      $$ = nil
  5582    }
  5583  | frame_clause
  5584    {
  5585      $$ = $1
  5586    }
  5587  
  5588  frame_clause:
  5589    frame_units frame_point
  5590    {
  5591      $$ = &FrameClause{ Unit: $1, Start: $2 }
  5592    }
  5593  | frame_units BETWEEN frame_point AND frame_point
  5594    {
  5595      $$ = &FrameClause{ Unit: $1, Start: $3, End: $5 }
  5596    }
  5597  
  5598  window_partition_clause_opt:
  5599    {
  5600      $$= nil
  5601    }
  5602  | PARTITION BY expression_list
  5603    {
  5604      $$ = $3
  5605    }
  5606  
  5607  sql_id_opt:
  5608    {
  5609    }
  5610  | sql_id
  5611    {
  5612      $$ = $1
  5613    }
  5614  
  5615  window_spec:
  5616  sql_id_opt window_partition_clause_opt order_by_opt frame_clause_opt
  5617    {
  5618      $$ = &WindowSpecification{ Name: $1, PartitionClause: $2, OrderClause: $3, FrameClause: $4}
  5619    }
  5620  
  5621  over_clause:
  5622    OVER openb window_spec closeb
  5623    {
  5624      $$ = &OverClause{ WindowSpec: $3 }
  5625    }
  5626  | OVER sql_id
  5627    {
  5628      $$ = &OverClause{WindowName: $2}
  5629    }
  5630  
  5631  null_treatment_clause_opt:
  5632    {
  5633      $$ = nil
  5634    }
  5635  | null_treatment_clause
  5636  
  5637  null_treatment_clause:
  5638    null_treatment_type
  5639    {
  5640      $$ = &NullTreatmentClause{$1}
  5641    }
  5642  
  5643  null_treatment_type:
  5644    RESPECT NULLS
  5645    {
  5646      $$ = RespectNullsType
  5647    }
  5648  | IGNORE NULLS
  5649    {
  5650      $$ = IgnoreNullsType
  5651    }
  5652  
  5653  first_or_last_value_expr_type:
  5654    FIRST_VALUE
  5655    {
  5656      $$ = FirstValueExprType
  5657    }
  5658  | LAST_VALUE
  5659    {
  5660      $$ = LastValueExprType
  5661    }
  5662  
  5663  from_first_last_type:
  5664    FROM FIRST
  5665    {
  5666      $$ = FromFirstType
  5667    }
  5668  | FROM LAST
  5669    {
  5670      $$ = FromLastType
  5671    }
  5672  
  5673  from_first_last_clause_opt:
  5674    {
  5675      $$ = nil
  5676    }
  5677  | from_first_last_clause
  5678  
  5679  from_first_last_clause:
  5680    from_first_last_type
  5681    {
  5682      $$ = &FromFirstLastClause{$1}
  5683    }
  5684  
  5685  lag_lead_expr_type:
  5686    LAG
  5687    {
  5688      $$ = LagExprType
  5689    }
  5690  | LEAD
  5691    {
  5692      $$ = LeadExprType
  5693    }
  5694  
  5695  window_definition:
  5696    sql_id AS openb window_spec closeb
  5697    {
  5698      $$ = &WindowDefinition{Name:$1, WindowSpec:$4}
  5699    }
  5700  
  5701  window_definition_list:
  5702    window_definition
  5703    {
  5704      $$ = WindowDefinitions{$1}
  5705    }
  5706  | window_definition_list ',' window_definition
  5707    {
  5708      $$ = append($1,$3)
  5709    }
  5710  
  5711  default_opt:
  5712    /* empty */
  5713    {
  5714      $$ = ""
  5715    }
  5716  | openb ci_identifier closeb
  5717    {
  5718      $$ = string($2.String())
  5719    }
  5720  
  5721  boolean_value:
  5722    TRUE
  5723    {
  5724      $$ = BoolVal(true)
  5725    }
  5726  | FALSE
  5727    {
  5728      $$ = BoolVal(false)
  5729    }
  5730  
  5731  
  5732  is_suffix:
  5733   TRUE
  5734    {
  5735      $$ = IsTrueOp
  5736    }
  5737  | NOT TRUE
  5738    {
  5739      $$ = IsNotTrueOp
  5740    }
  5741  | FALSE
  5742    {
  5743      $$ = IsFalseOp
  5744    }
  5745  | NOT FALSE
  5746    {
  5747      $$ = IsNotFalseOp
  5748    }
  5749  
  5750  compare:
  5751    '='
  5752    {
  5753      $$ = EqualOp
  5754    }
  5755  | '<'
  5756    {
  5757      $$ = LessThanOp
  5758    }
  5759  | '>'
  5760    {
  5761      $$ = GreaterThanOp
  5762    }
  5763  | LE
  5764    {
  5765      $$ = LessEqualOp
  5766    }
  5767  | GE
  5768    {
  5769      $$ = GreaterEqualOp
  5770    }
  5771  | NE
  5772    {
  5773      $$ = NotEqualOp
  5774    }
  5775  | NULL_SAFE_EQUAL
  5776    {
  5777      $$ = NullSafeEqualOp
  5778    }
  5779  
  5780  col_tuple:
  5781    row_tuple
  5782    {
  5783      $$ = $1
  5784    }
  5785  | subquery
  5786    {
  5787      $$ = $1
  5788    }
  5789  | LIST_ARG
  5790    {
  5791      $$ = ListArg($1[2:])
  5792      bindVariable(yylex, $1[2:])
  5793    }
  5794  
  5795  subquery:
  5796    query_expression_parens %prec SUBQUERY_AS_EXPR
  5797    {
  5798    	$$ = &Subquery{$1}
  5799    }
  5800  
  5801  expression_list:
  5802    expression
  5803    {
  5804      $$ = Exprs{$1}
  5805    }
  5806  | expression_list ',' expression
  5807    {
  5808      $$ = append($1, $3)
  5809    }
  5810  
  5811  /*
  5812    Regular function calls without special token or syntax, guaranteed to not
  5813    introduce side effects due to being a simple identifier
  5814  */
  5815  function_call_generic:
  5816    sql_id openb select_expression_list_opt closeb
  5817    {
  5818      $$ = &FuncExpr{Name: $1, Exprs: $3}
  5819    }
  5820  | table_id '.' reserved_sql_id openb select_expression_list_opt closeb
  5821    {
  5822      $$ = &FuncExpr{Qualifier: $1, Name: $3, Exprs: $5}
  5823    }
  5824  
  5825  /*
  5826    Function calls using reserved keywords, with dedicated grammar rules
  5827    as a result
  5828  */
  5829  function_call_keyword:
  5830    LEFT openb select_expression_list closeb
  5831    {
  5832      $$ = &FuncExpr{Name: NewIdentifierCI("left"), Exprs: $3}
  5833    }
  5834  | RIGHT openb select_expression_list closeb
  5835    {
  5836      $$ = &FuncExpr{Name: NewIdentifierCI("right"), Exprs: $3}
  5837    }
  5838  | SUBSTRING openb expression ',' expression ',' expression closeb
  5839    {
  5840      $$ = &SubstrExpr{Name: $3, From: $5, To: $7}
  5841    }
  5842  | SUBSTRING openb expression ',' expression closeb
  5843    {
  5844      $$ = &SubstrExpr{Name: $3, From: $5}
  5845    }
  5846  | SUBSTRING openb expression FROM expression FOR expression closeb
  5847    {
  5848    	$$ = &SubstrExpr{Name: $3, From: $5, To: $7}
  5849    }
  5850  | SUBSTRING openb expression FROM expression closeb
  5851    {
  5852    	$$ = &SubstrExpr{Name: $3, From: $5}
  5853    }
  5854  | CASE expression_opt when_expression_list else_expression_opt END
  5855    {
  5856      $$ = &CaseExpr{Expr: $2, Whens: $3, Else: $4}
  5857    }
  5858  | VALUES openb column_name closeb
  5859    {
  5860      $$ = &ValuesFuncExpr{Name: $3}
  5861    }
  5862  | INSERT openb expression ',' expression ',' expression ',' expression closeb
  5863    {
  5864      $$ = &InsertExpr{Str: $3, Pos: $5, Len: $7, NewStr: $9}
  5865    }
  5866  | CURRENT_USER func_paren_opt
  5867    {
  5868      $$ =  &FuncExpr{Name: NewIdentifierCI($1)}
  5869    }
  5870  
  5871  /*
  5872    Function calls using non reserved keywords but with special syntax forms.
  5873    Dedicated grammar rules are needed because of the special syntax
  5874  */
  5875  function_call_nonkeyword:
  5876  /* doesn't support fsp */
  5877  UTC_DATE func_paren_opt
  5878    {
  5879      $$ = &FuncExpr{Name:NewIdentifierCI("utc_date")}
  5880    }
  5881  | now
  5882    {
  5883    	$$ = $1
  5884    }
  5885    // curdate
  5886  /* doesn't support fsp */
  5887  | CURRENT_DATE func_paren_opt
  5888    {
  5889      $$ = &FuncExpr{Name:NewIdentifierCI("current_date")}
  5890    }
  5891  | UTC_TIME func_datetime_precision
  5892    {
  5893      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("utc_time"), Fsp: $2}
  5894    }
  5895    // curtime
  5896  | CURRENT_TIME func_datetime_precision
  5897    {
  5898      $$ = &CurTimeFuncExpr{Name:NewIdentifierCI("current_time"), Fsp: $2}
  5899    }
  5900  | COUNT openb '*' closeb
  5901    {
  5902      $$ = &CountStar{}
  5903    }
  5904  | COUNT openb distinct_opt expression_list closeb
  5905    {
  5906      $$ = &Count{Distinct:$3, Args:$4}
  5907    }
  5908  | MAX openb distinct_opt expression closeb
  5909    {
  5910      $$ = &Max{Distinct:$3, Arg:$4}
  5911    }
  5912  | MIN openb distinct_opt expression closeb
  5913    {
  5914      $$ = &Min{Distinct:$3, Arg:$4}
  5915    }
  5916  | SUM openb distinct_opt expression closeb
  5917    {
  5918      $$ = &Sum{Distinct:$3, Arg:$4}
  5919    }
  5920  | AVG openb distinct_opt expression closeb
  5921    {
  5922      $$ = &Avg{Distinct:$3, Arg:$4}
  5923    }
  5924  | BIT_AND openb expression closeb
  5925    {
  5926      $$ = &BitAnd{Arg:$3}
  5927    }
  5928  | BIT_OR openb expression closeb
  5929    {
  5930      $$ = &BitOr{Arg:$3}
  5931    }
  5932  | BIT_XOR openb expression closeb
  5933     {
  5934       $$ = &BitXor{Arg:$3}
  5935     }
  5936  | STD openb expression closeb
  5937      {
  5938        $$ = &Std{Arg:$3}
  5939      }
  5940  | STDDEV openb expression closeb
  5941      {
  5942        $$ = &StdDev{Arg:$3}
  5943      }
  5944  | STDDEV_POP openb expression closeb
  5945      {
  5946        $$ = &StdPop{Arg:$3}
  5947      }
  5948  | STDDEV_SAMP openb expression closeb
  5949      {
  5950        $$ = &StdSamp{Arg:$3}
  5951      }
  5952  | VAR_POP openb expression closeb
  5953       {
  5954         $$ = &VarPop{Arg:$3}
  5955       }
  5956  | VAR_SAMP openb expression closeb
  5957       {
  5958         $$ = &VarSamp{Arg:$3}
  5959       }
  5960  | VARIANCE openb expression closeb
  5961       {
  5962         $$ = &Variance{Arg:$3}
  5963       }
  5964  | GROUP_CONCAT openb distinct_opt expression_list order_by_opt separator_opt limit_opt closeb
  5965    {
  5966      $$ = &GroupConcatExpr{Distinct: $3, Exprs: $4, OrderBy: $5, Separator: $6, Limit: $7}
  5967    }
  5968  | TIMESTAMPADD openb sql_id ',' expression ',' expression closeb
  5969    {
  5970      $$ = &TimestampFuncExpr{Name:string("timestampadd"), Unit:$3.String(), Expr1:$5, Expr2:$7}
  5971    }
  5972  | TIMESTAMPDIFF openb sql_id ',' expression ',' expression closeb
  5973    {
  5974      $$ = &TimestampFuncExpr{Name:string("timestampdiff"), Unit:$3.String(), Expr1:$5, Expr2:$7}
  5975    }
  5976  | EXTRACT openb interval FROM expression closeb
  5977    {
  5978  	$$ = &ExtractFuncExpr{IntervalTypes: $3, Expr: $5}
  5979    }
  5980  | WEIGHT_STRING openb expression convert_type_weight_string closeb
  5981    {
  5982      $$ = &WeightStringFuncExpr{Expr: $3, As: $4}
  5983    }
  5984  | JSON_PRETTY openb expression closeb
  5985    {
  5986      $$ = &JSONPrettyExpr{JSONVal: $3}
  5987    }
  5988  | JSON_STORAGE_FREE openb expression closeb
  5989    {
  5990      $$ = &JSONStorageFreeExpr{ JSONVal: $3}
  5991    }
  5992  | JSON_STORAGE_SIZE openb expression closeb
  5993    {
  5994      $$ = &JSONStorageSizeExpr{ JSONVal: $3}
  5995    }
  5996  | LTRIM openb expression closeb
  5997    {
  5998      $$ = &TrimFuncExpr{TrimFuncType:LTrimType, StringArg: $3}
  5999    }
  6000  | RTRIM openb expression closeb
  6001    {
  6002      $$ = &TrimFuncExpr{TrimFuncType:RTrimType, StringArg: $3}
  6003    }
  6004  | TRIM openb trim_type expression_opt FROM expression closeb
  6005    {
  6006      $$ = &TrimFuncExpr{Type:$3, TrimArg:$4, StringArg: $6}
  6007    }
  6008  | TRIM openb expression closeb
  6009    {
  6010      $$ = &TrimFuncExpr{StringArg: $3}
  6011    }
  6012  | CHAR openb expression_list closeb
  6013    {
  6014      $$ = &CharExpr{Exprs: $3}
  6015    }
  6016  | CHAR openb expression_list USING charset closeb
  6017    {
  6018      $$ = &CharExpr{Exprs: $3, Charset: $5}
  6019    }
  6020  | TRIM openb expression FROM expression closeb
  6021    {
  6022      $$ = &TrimFuncExpr{TrimArg:$3, StringArg: $5}
  6023    }
  6024  | LOCATE openb expression ',' expression closeb
  6025    {
  6026      $$ = &LocateExpr{SubStr: $3, Str: $5}
  6027    }
  6028  | LOCATE openb expression ',' expression ',' expression closeb
  6029    {
  6030      $$ = &LocateExpr{SubStr: $3, Str: $5, Pos: $7}
  6031    }
  6032  | POSITION openb bit_expr IN expression closeb
  6033    {
  6034      $$ = &LocateExpr{SubStr: $3, Str: $5}
  6035    }
  6036  | GET_LOCK openb expression ',' expression closeb
  6037    {
  6038      $$ = &LockingFunc{Type: GetLock, Name:$3, Timeout:$5}
  6039    }
  6040  | IS_FREE_LOCK openb expression closeb
  6041    {
  6042      $$ = &LockingFunc{Type: IsFreeLock, Name:$3}
  6043    }
  6044  | IS_USED_LOCK openb expression closeb
  6045    {
  6046      $$ = &LockingFunc{Type: IsUsedLock, Name:$3}
  6047    }
  6048  | RELEASE_ALL_LOCKS openb closeb
  6049    {
  6050      $$ = &LockingFunc{Type: ReleaseAllLocks}
  6051    }
  6052  | RELEASE_LOCK openb expression closeb
  6053    {
  6054      $$ = &LockingFunc{Type: ReleaseLock, Name:$3}
  6055    }
  6056  | JSON_SCHEMA_VALID openb expression ',' expression closeb
  6057    {
  6058      $$ = &JSONSchemaValidFuncExpr{ Schema: $3, Document: $5}
  6059    }
  6060  | JSON_SCHEMA_VALIDATION_REPORT openb expression ',' expression closeb
  6061    {
  6062      $$ = &JSONSchemaValidationReportFuncExpr{ Schema: $3, Document: $5}
  6063    }
  6064  | JSON_ARRAY openb expression_list_opt closeb
  6065    {
  6066      $$ = &JSONArrayExpr{ Params:$3 }
  6067    }
  6068  | JSON_OBJECT openb json_object_param_opt closeb
  6069    {
  6070      $$ = &JSONObjectExpr{ Params:$3 }
  6071    }
  6072  | JSON_QUOTE openb expression closeb
  6073    {
  6074      $$ = &JSONQuoteExpr{ StringArg:$3 }
  6075    }
  6076  | JSON_CONTAINS openb expression ',' expression_list closeb
  6077    {
  6078      $$ = &JSONContainsExpr{Target: $3, Candidate: $5[0], PathList: $5[1:]}
  6079    }
  6080  | JSON_CONTAINS_PATH openb expression ',' expression ',' expression_list closeb
  6081    {
  6082      $$ = &JSONContainsPathExpr{JSONDoc: $3, OneOrAll: $5, PathList: $7}
  6083    }
  6084  | JSON_EXTRACT openb expression ',' expression_list closeb
  6085    {
  6086      $$ = &JSONExtractExpr{JSONDoc: $3, PathList: $5}
  6087    }
  6088  | JSON_KEYS openb expression closeb
  6089    {
  6090      $$ = &JSONKeysExpr{JSONDoc: $3}
  6091    }
  6092  | JSON_KEYS openb expression ',' expression closeb
  6093    {
  6094      $$ = &JSONKeysExpr{JSONDoc: $3, Path: $5}
  6095    }
  6096  | JSON_OVERLAPS openb expression ',' expression closeb
  6097    {
  6098      $$ = &JSONOverlapsExpr{JSONDoc1:$3, JSONDoc2:$5}
  6099    }
  6100  | JSON_SEARCH openb expression ',' expression ',' expression closeb
  6101    {
  6102      $$ = &JSONSearchExpr{JSONDoc: $3, OneOrAll: $5, SearchStr: $7 }
  6103    }
  6104  | JSON_SEARCH openb expression ',' expression ',' expression ',' expression_list closeb
  6105    {
  6106      $$ = &JSONSearchExpr{JSONDoc: $3, OneOrAll: $5, SearchStr: $7, EscapeChar: $9[0], PathList:$9[1:] }
  6107    }
  6108  | JSON_VALUE openb expression ',' expression returning_type_opt closeb
  6109    {
  6110      $$ = &JSONValueExpr{JSONDoc: $3, Path: $5, ReturningType: $6}
  6111    }
  6112  | JSON_VALUE openb expression ',' expression returning_type_opt on_empty closeb
  6113    {
  6114      $$ = &JSONValueExpr{JSONDoc: $3, Path: $5, ReturningType: $6, EmptyOnResponse: $7}
  6115    }
  6116  | JSON_VALUE openb expression ',' expression returning_type_opt on_error closeb
  6117    {
  6118      $$ = &JSONValueExpr{JSONDoc: $3, Path: $5, ReturningType: $6, ErrorOnResponse: $7}
  6119    }
  6120  | JSON_VALUE openb expression ',' expression returning_type_opt on_empty on_error closeb
  6121    {
  6122      $$ = &JSONValueExpr{JSONDoc: $3, Path: $5, ReturningType: $6, EmptyOnResponse: $7, ErrorOnResponse: $8}
  6123    }
  6124  | JSON_DEPTH openb expression closeb
  6125    {
  6126      $$ = &JSONAttributesExpr{Type:DepthAttributeType, JSONDoc:$3}
  6127    }
  6128  | JSON_VALID openb expression closeb
  6129    {
  6130      $$ = &JSONAttributesExpr{Type:ValidAttributeType, JSONDoc:$3}
  6131    }
  6132  | JSON_TYPE openb expression closeb
  6133    {
  6134      $$ = &JSONAttributesExpr{Type:TypeAttributeType, JSONDoc:$3}
  6135    }
  6136  | JSON_LENGTH openb expression closeb
  6137    {
  6138      $$ = &JSONAttributesExpr{Type:LengthAttributeType, JSONDoc:$3 }
  6139    }
  6140  | JSON_LENGTH openb expression ',' expression closeb
  6141    {
  6142      $$ = &JSONAttributesExpr{Type:LengthAttributeType, JSONDoc:$3, Path: $5 }
  6143    }
  6144  | JSON_ARRAY_APPEND openb expression ',' json_object_param_list closeb
  6145    {
  6146      $$ = &JSONValueModifierExpr{Type:JSONArrayAppendType ,JSONDoc:$3, Params:$5}
  6147    }
  6148  | JSON_ARRAY_INSERT openb expression ',' json_object_param_list closeb
  6149    {
  6150      $$ = &JSONValueModifierExpr{Type:JSONArrayInsertType ,JSONDoc:$3, Params:$5}
  6151    }
  6152  | JSON_INSERT openb expression ',' json_object_param_list closeb
  6153    {
  6154      $$ = &JSONValueModifierExpr{Type:JSONInsertType ,JSONDoc:$3, Params:$5}
  6155    }
  6156  | JSON_REPLACE openb expression ',' json_object_param_list closeb
  6157    {
  6158      $$ = &JSONValueModifierExpr{Type:JSONReplaceType ,JSONDoc:$3, Params:$5}
  6159    }
  6160  | JSON_SET openb expression ',' json_object_param_list closeb
  6161    {
  6162      $$ = &JSONValueModifierExpr{Type:JSONSetType ,JSONDoc:$3, Params:$5}
  6163    }
  6164  | JSON_MERGE openb expression ',' expression_list closeb
  6165    {
  6166      $$ = &JSONValueMergeExpr{Type: JSONMergeType, JSONDoc: $3, JSONDocList: $5}
  6167    }
  6168  | JSON_MERGE_PATCH openb expression ',' expression_list closeb
  6169    {
  6170      $$ = &JSONValueMergeExpr{Type: JSONMergePatchType, JSONDoc: $3, JSONDocList: $5}
  6171    }
  6172  | JSON_MERGE_PRESERVE openb expression ',' expression_list closeb
  6173    {
  6174      $$ = &JSONValueMergeExpr{Type: JSONMergePreserveType, JSONDoc: $3, JSONDocList: $5}
  6175    }
  6176  | JSON_REMOVE openb expression ',' expression_list closeb
  6177    {
  6178      $$ = &JSONRemoveExpr{JSONDoc:$3, PathList: $5}
  6179    }
  6180  | JSON_UNQUOTE openb expression closeb
  6181    {
  6182      $$ = &JSONUnquoteExpr{JSONValue:$3}
  6183    }
  6184  | argument_less_window_expr_type openb closeb over_clause
  6185    {
  6186      $$ = &ArgumentLessWindowExpr{ Type: $1, OverClause : $4 }
  6187    }
  6188  | first_or_last_value_expr_type openb expression closeb null_treatment_clause_opt over_clause
  6189    {
  6190      $$ = &FirstOrLastValueExpr{ Type: $1, Expr : $3 , NullTreatmentClause:$5 ,OverClause:$6 }
  6191    }
  6192  | NTILE openb null_int_variable_arg closeb over_clause
  6193    {
  6194      $$ =  &NtileExpr{N: $3, OverClause: $5}
  6195    }
  6196  | NTH_VALUE openb expression ',' null_int_variable_arg closeb from_first_last_clause_opt null_treatment_clause_opt over_clause
  6197    {
  6198      $$ =  &NTHValueExpr{ Expr: $3, N: $5, FromFirstLastClause:$7, NullTreatmentClause:$8, OverClause: $9}
  6199    }
  6200  | lag_lead_expr_type openb expression closeb null_treatment_clause_opt over_clause
  6201    {
  6202      $$ = &LagLeadExpr{ Type:$1 , Expr: $3, NullTreatmentClause:$5, OverClause: $6 }
  6203    }
  6204  | lag_lead_expr_type openb expression ',' null_int_variable_arg default_with_comma_opt closeb null_treatment_clause_opt over_clause
  6205    {
  6206      $$ =  &LagLeadExpr{ Type:$1 , Expr: $3, N: $5, Default: $6, NullTreatmentClause:$8, OverClause: $9}
  6207    }
  6208  | regular_expressions
  6209  | xml_expressions
  6210  | performance_schema_function_expressions
  6211  | gtid_function_expressions
  6212  
  6213  null_int_variable_arg:
  6214    null_as_literal
  6215    {
  6216      $$ = $1
  6217    }
  6218  | INTEGRAL
  6219    {
  6220      $$ = NewIntLiteral($1)
  6221    }
  6222  | user_defined_variable
  6223    {
  6224      $$ = $1
  6225    }
  6226  | VALUE_ARG
  6227    {
  6228      $$ = NewArgument($1[1:])
  6229      bindVariable(yylex, $1[1:])
  6230    }
  6231  
  6232  default_with_comma_opt:
  6233    {
  6234      $$ = nil
  6235    }
  6236  | ',' expression
  6237    {
  6238      $$ = $2
  6239    }
  6240  
  6241  regular_expressions:
  6242    REGEXP_INSTR openb expression ',' expression closeb
  6243    {
  6244      $$ = &RegexpInstrExpr{Expr:$3, Pattern:$5}
  6245    }
  6246  | REGEXP_INSTR openb expression ',' expression ',' expression closeb
  6247    {
  6248      $$ = &RegexpInstrExpr{Expr:$3, Pattern:$5, Position: $7}
  6249    }
  6250  | REGEXP_INSTR openb expression ',' expression ',' expression ',' expression closeb
  6251    {
  6252      $$ = &RegexpInstrExpr{Expr:$3, Pattern:$5, Position: $7, Occurrence: $9}
  6253    }
  6254  | REGEXP_INSTR openb expression ',' expression ',' expression ',' expression ',' expression closeb
  6255    {
  6256      $$ = &RegexpInstrExpr{Expr:$3, Pattern:$5, Position: $7, Occurrence: $9, ReturnOption: $11}
  6257    }
  6258  | REGEXP_INSTR openb expression ',' expression ',' expression ',' expression ',' expression ',' expression closeb
  6259    {
  6260      // Match type is kept expression as TRIM( ' m  ') is accepted
  6261      $$ = &RegexpInstrExpr{Expr:$3, Pattern:$5, Position: $7, Occurrence: $9, ReturnOption: $11, MatchType: $13}
  6262    }
  6263  | REGEXP_LIKE openb expression ',' expression closeb
  6264    {
  6265      $$ = &RegexpLikeExpr{Expr:$3, Pattern:$5}
  6266    }
  6267  | REGEXP_LIKE openb expression ',' expression ',' expression closeb
  6268    {
  6269      $$ = &RegexpLikeExpr{Expr:$3, Pattern:$5, MatchType: $7}
  6270    }
  6271  | REGEXP_REPLACE openb expression ',' expression ',' expression closeb
  6272    {
  6273      $$ = &RegexpReplaceExpr{Expr:$3, Pattern:$5, Repl: $7}
  6274    }
  6275  | REGEXP_REPLACE openb expression ',' expression ',' expression ',' expression closeb
  6276    {
  6277      $$ = &RegexpReplaceExpr{Expr:$3, Pattern:$5, Repl: $7, Position: $9}
  6278    }
  6279  | REGEXP_REPLACE openb expression ',' expression ',' expression ',' expression ',' expression closeb
  6280    {
  6281      $$ = &RegexpReplaceExpr{Expr:$3, Pattern:$5, Repl: $7, Position: $9, Occurrence: $11}
  6282    }
  6283  | REGEXP_REPLACE openb expression ',' expression ',' expression ',' expression ',' expression ',' expression closeb
  6284    {
  6285      // Match type is kept expression as TRIM( ' m  ') is accepted
  6286      $$ = &RegexpReplaceExpr{Expr:$3, Pattern:$5, Repl: $7, Position: $9, Occurrence: $11, MatchType: $13}
  6287    }
  6288  | REGEXP_SUBSTR openb expression ',' expression closeb
  6289    {
  6290      $$ = &RegexpSubstrExpr{Expr:$3, Pattern:$5 }
  6291    }
  6292  | REGEXP_SUBSTR openb expression ',' expression ',' expression closeb
  6293    {
  6294      $$ = &RegexpSubstrExpr{Expr:$3, Pattern:$5, Position: $7}
  6295    }
  6296  | REGEXP_SUBSTR openb expression ',' expression ',' expression ',' expression closeb
  6297    {
  6298      $$ = &RegexpSubstrExpr{Expr:$3, Pattern:$5, Position: $7, Occurrence: $9}
  6299    }
  6300  | REGEXP_SUBSTR openb expression ',' expression ',' expression ',' expression ',' expression closeb
  6301    {
  6302      // Match type is kept expression as TRIM( ' m  ') is accepted
  6303      $$ = &RegexpSubstrExpr{Expr:$3, Pattern:$5, Position: $7, Occurrence: $9, MatchType: $11}
  6304    }
  6305  
  6306  xml_expressions:
  6307    ExtractValue openb expression ',' expression closeb
  6308    {
  6309      $$ = &ExtractValueExpr{Fragment:$3, XPathExpr:$5}
  6310    }
  6311  | UpdateXML openb expression ',' expression ',' expression closeb
  6312    {
  6313      $$ = &UpdateXMLExpr{ Target:$3, XPathExpr:$5, NewXML:$7 }
  6314    }
  6315  
  6316  performance_schema_function_expressions:
  6317    FORMAT_BYTES openb expression closeb
  6318    {
  6319      $$ = &PerformanceSchemaFuncExpr{Type: FormatBytesType, Argument:$3}
  6320    }
  6321  | FORMAT_PICO_TIME openb expression closeb
  6322    {
  6323      $$ = &PerformanceSchemaFuncExpr{Type: FormatPicoTimeType, Argument:$3}
  6324    }
  6325  | PS_CURRENT_THREAD_ID openb closeb
  6326    {
  6327      $$ = &PerformanceSchemaFuncExpr{Type: PsCurrentThreadIDType}
  6328    }
  6329  | PS_THREAD_ID openb expression closeb
  6330    {
  6331      $$ = &PerformanceSchemaFuncExpr{Type: PsThreadIDType, Argument:$3}
  6332    }
  6333  
  6334  gtid_function_expressions:
  6335    GTID_SUBSET openb expression ',' expression closeb
  6336    {
  6337      $$ = &GTIDFuncExpr{Type: GTIDSubsetType, Set1:$3, Set2: $5 }
  6338    }
  6339  | GTID_SUBTRACT openb expression ',' expression closeb
  6340    {
  6341      $$ = &GTIDFuncExpr{Type: GTIDSubtractType, Set1:$3, Set2: $5 }
  6342    }
  6343  | WAIT_FOR_EXECUTED_GTID_SET openb expression closeb
  6344    {
  6345      $$ = &GTIDFuncExpr{Type: WaitForExecutedGTIDSetType, Set1: $3}
  6346    }
  6347  | WAIT_FOR_EXECUTED_GTID_SET openb expression ',' expression closeb
  6348    {
  6349      $$ = &GTIDFuncExpr{Type: WaitForExecutedGTIDSetType, Set1: $3, Timeout: $5 }
  6350    }
  6351  | WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS openb expression closeb
  6352    {
  6353      $$ = &GTIDFuncExpr{Type: WaitUntilSQLThreadAfterGTIDSType, Set1: $3 }
  6354    }
  6355  | WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS openb expression ',' expression closeb
  6356    {
  6357      $$ = &GTIDFuncExpr{Type: WaitUntilSQLThreadAfterGTIDSType, Set1: $3, Timeout: $5 }
  6358    }
  6359  | WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS openb expression ',' expression ',' expression closeb
  6360    {
  6361      $$ = &GTIDFuncExpr{Type: WaitUntilSQLThreadAfterGTIDSType, Set1: $3, Timeout: $5, Channel: $7 }
  6362    }
  6363  
  6364  returning_type_opt:
  6365    {
  6366      $$ = nil
  6367    }
  6368  | RETURNING convert_type
  6369    {
  6370      $$ = $2
  6371    }
  6372  
  6373  interval:
  6374   interval_time_stamp
  6375   {}
  6376  | DAY_HOUR
  6377    {
  6378  	$$=IntervalDayHour
  6379    }
  6380  | DAY_MICROSECOND
  6381    {
  6382  	$$=IntervalDayMicrosecond
  6383    }
  6384  | DAY_MINUTE
  6385    {
  6386  	$$=IntervalDayMinute
  6387    }
  6388  | DAY_SECOND
  6389    {
  6390  	$$=IntervalDaySecond
  6391    }
  6392  | HOUR_MICROSECOND
  6393    {
  6394  	$$=IntervalHourMicrosecond
  6395    }
  6396  | HOUR_MINUTE
  6397    {
  6398  	$$=IntervalHourMinute
  6399    }
  6400  | HOUR_SECOND
  6401    {
  6402  	$$=IntervalHourSecond
  6403    }
  6404  | MINUTE_MICROSECOND
  6405    {
  6406  	$$=IntervalMinuteMicrosecond
  6407    }
  6408  | MINUTE_SECOND
  6409    {
  6410  	$$=IntervalMinuteSecond
  6411    }
  6412  | SECOND_MICROSECOND
  6413    {
  6414  	$$=IntervalSecondMicrosecond
  6415    }
  6416  | YEAR_MONTH
  6417    {
  6418  	$$=IntervalYearMonth
  6419    }
  6420  
  6421  interval_time_stamp:
  6422   DAY
  6423    {
  6424   	$$=IntervalDay
  6425    }
  6426  | WEEK
  6427    {
  6428    	$$=IntervalWeek
  6429    }
  6430  | HOUR
  6431    {
  6432   	$$=IntervalHour
  6433    }
  6434  | MINUTE
  6435    {
  6436   	$$=IntervalMinute
  6437    }
  6438  | MONTH
  6439    {
  6440  	$$=IntervalMonth
  6441    }
  6442  | QUARTER
  6443    {
  6444  	$$=IntervalQuarter
  6445    }
  6446  | SECOND
  6447    {
  6448  	$$=IntervalSecond
  6449    }
  6450  | MICROSECOND
  6451    {
  6452  	$$=IntervalMicrosecond
  6453    }
  6454  | YEAR
  6455    {
  6456  	$$=IntervalYear
  6457    }
  6458  
  6459  func_paren_opt:
  6460    /* empty */
  6461  | openb closeb
  6462  
  6463  func_datetime_precision:
  6464    /* empty */
  6465    {
  6466    	$$ = nil
  6467    }
  6468  | openb closeb
  6469    {
  6470      $$ = nil
  6471    }
  6472  | openb INTEGRAL closeb
  6473    {
  6474    	$$ = NewIntLiteral($2)
  6475    }
  6476  | openb VALUE_ARG closeb
  6477    {
  6478      $$ = NewArgument($2[1:])
  6479      bindVariable(yylex, $2[1:])
  6480    }
  6481  
  6482  /*
  6483    Function calls using non reserved keywords with *normal* syntax forms. Because
  6484    the names are non-reserved, they need a dedicated rule so as not to conflict
  6485  */
  6486  function_call_conflict:
  6487    IF openb select_expression_list closeb
  6488    {
  6489      $$ = &FuncExpr{Name: NewIdentifierCI("if"), Exprs: $3}
  6490    }
  6491  | DATABASE openb select_expression_list_opt closeb
  6492    {
  6493      $$ = &FuncExpr{Name: NewIdentifierCI("database"), Exprs: $3}
  6494    }
  6495  | SCHEMA openb select_expression_list_opt closeb
  6496    {
  6497      $$ = &FuncExpr{Name: NewIdentifierCI("schema"), Exprs: $3}
  6498    }
  6499  | MOD openb select_expression_list closeb
  6500    {
  6501      $$ = &FuncExpr{Name: NewIdentifierCI("mod"), Exprs: $3}
  6502    }
  6503  | REPLACE openb select_expression_list closeb
  6504    {
  6505      $$ = &FuncExpr{Name: NewIdentifierCI("replace"), Exprs: $3}
  6506    }
  6507  
  6508  match_option:
  6509  /*empty*/
  6510    {
  6511      $$ = NoOption
  6512    }
  6513  | IN BOOLEAN MODE
  6514    {
  6515      $$ = BooleanModeOpt
  6516    }
  6517  | IN NATURAL LANGUAGE MODE
  6518   {
  6519      $$ = NaturalLanguageModeOpt
  6520   }
  6521  | IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
  6522   {
  6523      $$ = NaturalLanguageModeWithQueryExpansionOpt
  6524   }
  6525  | WITH QUERY EXPANSION
  6526   {
  6527      $$ = QueryExpansionOpt
  6528   }
  6529  
  6530  charset:
  6531    sql_id
  6532    {
  6533      $$ = string($1.String())
  6534    }
  6535  | STRING
  6536    {
  6537      $$ = string($1)
  6538    }
  6539  | BINARY
  6540    {
  6541      $$ = string($1)
  6542    }
  6543  
  6544  convert_type_weight_string:
  6545    /* empty */
  6546    {
  6547      $$ = nil
  6548    }
  6549  | AS BINARY '(' INTEGRAL ')'
  6550    {
  6551      $$ = &ConvertType{Type: string($2), Length: NewIntLiteral($4)}
  6552    }
  6553  | AS CHAR '(' INTEGRAL ')'
  6554    {
  6555      $$ = &ConvertType{Type: string($2), Length: NewIntLiteral($4)}
  6556    }
  6557  
  6558  convert_type:
  6559    BINARY length_opt
  6560    {
  6561      $$ = &ConvertType{Type: string($1), Length: $2}
  6562    }
  6563  | CHAR length_opt charset_opt
  6564    {
  6565      $$ = &ConvertType{Type: string($1), Length: $2, Charset: $3}
  6566    }
  6567  | DATE
  6568    {
  6569      $$ = &ConvertType{Type: string($1)}
  6570    }
  6571  | DATETIME length_opt
  6572    {
  6573      $$ = &ConvertType{Type: string($1), Length: $2}
  6574    }
  6575  | DECIMAL_TYPE decimal_length_opt
  6576    {
  6577      $$ = &ConvertType{Type: string($1)}
  6578      $$.Length = $2.Length
  6579      $$.Scale = $2.Scale
  6580    }
  6581  | JSON
  6582    {
  6583      $$ = &ConvertType{Type: string($1)}
  6584    }
  6585  | NCHAR length_opt
  6586    {
  6587      $$ = &ConvertType{Type: string($1), Length: $2}
  6588    }
  6589  | SIGNED
  6590    {
  6591      $$ = &ConvertType{Type: string($1)}
  6592    }
  6593  | SIGNED INTEGER
  6594    {
  6595      $$ = &ConvertType{Type: string($1)}
  6596    }
  6597  | TIME length_opt
  6598    {
  6599      $$ = &ConvertType{Type: string($1), Length: $2}
  6600    }
  6601  | UNSIGNED
  6602    {
  6603      $$ = &ConvertType{Type: string($1)}
  6604    }
  6605  | UNSIGNED INTEGER
  6606    {
  6607      $$ = &ConvertType{Type: string($1)}
  6608    }
  6609  | FLOAT_TYPE length_opt
  6610    {
  6611      $$ = &ConvertType{Type: string($1), Length: $2}
  6612    }
  6613  | DOUBLE
  6614    {
  6615      $$ = &ConvertType{Type: string($1)}
  6616    }
  6617  | REAL
  6618    {
  6619      $$ = &ConvertType{Type: string($1)}
  6620    }
  6621  
  6622  array_opt:
  6623    /* empty */
  6624    {
  6625      $$ = false
  6626    }
  6627  | ARRAY
  6628    {
  6629      $$ = true
  6630    }
  6631  
  6632  expression_opt:
  6633    {
  6634      $$ = nil
  6635    }
  6636  | expression
  6637    {
  6638      $$ = $1
  6639    }
  6640  
  6641  separator_opt:
  6642    {
  6643      $$ = string("")
  6644    }
  6645  | SEPARATOR STRING
  6646    {
  6647      $$ = " separator "+encodeSQLString($2)
  6648    }
  6649  
  6650  when_expression_list:
  6651    when_expression
  6652    {
  6653      $$ = []*When{$1}
  6654    }
  6655  | when_expression_list when_expression
  6656    {
  6657      $$ = append($1, $2)
  6658    }
  6659  
  6660  when_expression:
  6661    WHEN expression THEN expression
  6662    {
  6663      $$ = &When{Cond: $2, Val: $4}
  6664    }
  6665  
  6666  else_expression_opt:
  6667    {
  6668      $$ = nil
  6669    }
  6670  | ELSE expression
  6671    {
  6672      $$ = $2
  6673    }
  6674  
  6675  column_name:
  6676    ci_identifier
  6677    {
  6678      $$ = &ColName{Name: $1}
  6679    }
  6680  | non_reserved_keyword
  6681    {
  6682      $$ = &ColName{Name: NewIdentifierCI(string($1))}
  6683    }
  6684  | table_id '.' reserved_sql_id
  6685    {
  6686      $$ = &ColName{Qualifier: TableName{Name: $1}, Name: $3}
  6687    }
  6688  | table_id '.' reserved_table_id '.' reserved_sql_id
  6689    {
  6690      $$ = &ColName{Qualifier: TableName{Qualifier: $1, Name: $3}, Name: $5}
  6691    }
  6692  
  6693  column_name_or_offset:
  6694    column_name
  6695    {
  6696      $$ = $1
  6697    }
  6698  | OFFSET_ARG
  6699    {
  6700      $$ = &Offset{V: convertStringToInt($1)}
  6701    }
  6702  
  6703  num_val:
  6704    sql_id
  6705    {
  6706      // TODO(sougou): Deprecate this construct.
  6707      if $1.Lowered() != "value" {
  6708        yylex.Error("expecting value after next")
  6709        return 1
  6710      }
  6711      $$ = NewIntLiteral("1")
  6712    }
  6713  | INTEGRAL VALUES
  6714    {
  6715      $$ = NewIntLiteral($1)
  6716    }
  6717  | VALUE_ARG VALUES
  6718    {
  6719      $$ = NewArgument($1[1:])
  6720      bindVariable(yylex, $1[1:])
  6721    }
  6722  
  6723  group_by_opt:
  6724    {
  6725      $$ = nil
  6726    }
  6727  | GROUP BY expression_list
  6728    {
  6729      $$ = $3
  6730    }
  6731  
  6732  having_opt:
  6733    {
  6734      $$ = nil
  6735    }
  6736  | HAVING expression
  6737    {
  6738      $$ = $2
  6739    }
  6740  
  6741  named_window:
  6742    WINDOW window_definition_list %prec WINDOW_EXPR
  6743    {
  6744      $$ = &NamedWindow{$2}
  6745    }
  6746  
  6747  named_windows_list:
  6748    named_window
  6749    {
  6750      $$ = NamedWindows{$1}
  6751    }
  6752  | named_windows_list ',' named_window
  6753    {
  6754      $$ = append($1,$3)
  6755    }
  6756  
  6757  named_windows_list_opt:
  6758    {
  6759      $$ = nil
  6760    }
  6761  | named_windows_list
  6762    {
  6763      $$ = $1
  6764    }
  6765  
  6766  order_by_opt:
  6767    {
  6768      $$ = nil
  6769    }
  6770   | order_by_clause
  6771   {
  6772   	$$ = $1
  6773   }
  6774  
  6775  order_by_clause:
  6776  ORDER BY order_list
  6777    {
  6778      $$ = $3
  6779    }
  6780  
  6781  order_list:
  6782    order
  6783    {
  6784      $$ = OrderBy{$1}
  6785    }
  6786  | order_list ',' order
  6787    {
  6788      $$ = append($1, $3)
  6789    }
  6790  
  6791  order:
  6792    expression asc_desc_opt
  6793    {
  6794      $$ = &Order{Expr: $1, Direction: $2}
  6795    }
  6796  
  6797  asc_desc_opt:
  6798    {
  6799      $$ = AscOrder
  6800    }
  6801  | ASC
  6802    {
  6803      $$ = AscOrder
  6804    }
  6805  | DESC
  6806    {
  6807      $$ = DescOrder
  6808    }
  6809  
  6810  limit_opt:
  6811    {
  6812      $$ = nil
  6813    }
  6814   | limit_clause
  6815   {
  6816   	$$ = $1
  6817   }
  6818  
  6819  limit_clause:
  6820  LIMIT expression
  6821    {
  6822      $$ = &Limit{Rowcount: $2}
  6823    }
  6824  | LIMIT expression ',' expression
  6825    {
  6826      $$ = &Limit{Offset: $2, Rowcount: $4}
  6827    }
  6828  | LIMIT expression OFFSET expression
  6829    {
  6830      $$ = &Limit{Offset: $4, Rowcount: $2}
  6831    }
  6832  
  6833  algorithm_lock_opt:
  6834    {
  6835      $$ = nil
  6836    }
  6837  | lock_index algorithm_index
  6838    {
  6839       $$ = []AlterOption{$1,$2}
  6840    }
  6841  | algorithm_index lock_index
  6842    {
  6843       $$ = []AlterOption{$1,$2}
  6844    }
  6845  | algorithm_index
  6846    {
  6847       $$ = []AlterOption{$1}
  6848    }
  6849  | lock_index
  6850    {
  6851       $$ = []AlterOption{$1}
  6852    }
  6853  
  6854  
  6855  lock_index:
  6856    LOCK equal_opt DEFAULT
  6857    {
  6858      $$ = &LockOption{Type:DefaultType}
  6859    }
  6860  | LOCK equal_opt NONE
  6861    {
  6862      $$ = &LockOption{Type:NoneType}
  6863    }
  6864  | LOCK equal_opt SHARED
  6865    {
  6866      $$ = &LockOption{Type:SharedType}
  6867    }
  6868  | LOCK equal_opt EXCLUSIVE
  6869    {
  6870      $$ = &LockOption{Type:ExclusiveType}
  6871    }
  6872  
  6873  algorithm_index:
  6874    ALGORITHM equal_opt DEFAULT
  6875    {
  6876      $$ = AlgorithmValue($3)
  6877    }
  6878  | ALGORITHM equal_opt INPLACE
  6879    {
  6880      $$ = AlgorithmValue($3)
  6881    }
  6882  | ALGORITHM equal_opt COPY
  6883    {
  6884      $$ = AlgorithmValue($3)
  6885    }
  6886  | ALGORITHM equal_opt INSTANT
  6887    {
  6888      $$ = AlgorithmValue($3)
  6889    }
  6890  
  6891  algorithm_view:
  6892    {
  6893      $$ = ""
  6894    }
  6895  | ALGORITHM '=' UNDEFINED
  6896    {
  6897      $$ = string($3)
  6898    }
  6899  | ALGORITHM '=' MERGE
  6900    {
  6901      $$ = string($3)
  6902    }
  6903  | ALGORITHM '=' TEMPTABLE
  6904    {
  6905      $$ = string($3)
  6906    }
  6907  
  6908  security_view_opt:
  6909    {
  6910      $$ = ""
  6911    }
  6912  | SQL SECURITY security_view
  6913    {
  6914      $$ = $3
  6915    }
  6916  
  6917  security_view:
  6918    DEFINER
  6919    {
  6920      $$ = string($1)
  6921    }
  6922  | INVOKER
  6923    {
  6924      $$ = string($1)
  6925    }
  6926  
  6927  check_option_opt:
  6928    {
  6929      $$ = ""
  6930    }
  6931  | WITH cascade_or_local_opt CHECK OPTION
  6932    {
  6933      $$ = $2
  6934    }
  6935  
  6936  cascade_or_local_opt:
  6937    {
  6938      $$ = "cascaded"
  6939    }
  6940  | CASCADED
  6941    {
  6942      $$ = string($1)
  6943    }
  6944  | LOCAL
  6945    {
  6946      $$ = string($1)
  6947    }
  6948  
  6949  definer_opt:
  6950    {
  6951      $$ = nil
  6952    }
  6953  | DEFINER '=' user
  6954    {
  6955      $$ = $3
  6956    }
  6957  
  6958  user:
  6959  CURRENT_USER
  6960    {
  6961      $$ = &Definer{
  6962      	Name: string($1),
  6963      }
  6964    }
  6965  | CURRENT_USER '(' ')'
  6966    {
  6967      $$ = &Definer{
  6968          Name: string($1),
  6969      }
  6970    }
  6971  | user_username address_opt
  6972    {
  6973      $$ = &Definer{
  6974          Name: $1,
  6975          Address: $2,
  6976      }
  6977    }
  6978  
  6979  user_username:
  6980    STRING
  6981    {
  6982      $$ = encodeSQLString($1)
  6983    }
  6984  | ID
  6985    {
  6986      $$ = formatIdentifier($1)
  6987    }
  6988  
  6989  address_opt:
  6990    {
  6991      $$ = ""
  6992    }
  6993  | AT_ID
  6994    {
  6995      $$ = formatAddress($1)
  6996    }
  6997  
  6998  locking_clause:
  6999  FOR UPDATE
  7000    {
  7001      $$ = ForUpdateLock
  7002    }
  7003  | LOCK IN SHARE MODE
  7004    {
  7005      $$ = ShareModeLock
  7006    }
  7007  
  7008  into_clause:
  7009  INTO OUTFILE S3 STRING charset_opt format_opt export_options manifest_opt overwrite_opt
  7010  {
  7011  $$ = &SelectInto{Type:IntoOutfileS3, FileName:encodeSQLString($4), Charset:$5, FormatOption:$6, ExportOption:$7, Manifest:$8, Overwrite:$9}
  7012  }
  7013  | INTO DUMPFILE STRING
  7014  {
  7015  $$ = &SelectInto{Type:IntoDumpfile, FileName:encodeSQLString($3), Charset:ColumnCharset{}, FormatOption:"", ExportOption:"", Manifest:"", Overwrite:""}
  7016  }
  7017  | INTO OUTFILE STRING charset_opt export_options
  7018  {
  7019  $$ = &SelectInto{Type:IntoOutfile, FileName:encodeSQLString($3), Charset:$4, FormatOption:"", ExportOption:$5, Manifest:"", Overwrite:""}
  7020  }
  7021  
  7022  format_opt:
  7023    {
  7024      $$ = ""
  7025    }
  7026  | FORMAT CSV header_opt
  7027    {
  7028      $$ = " format csv" + $3
  7029    }
  7030  | FORMAT TEXT header_opt
  7031    {
  7032      $$ = " format text" + $3
  7033    }
  7034  
  7035  header_opt:
  7036    {
  7037      $$ = ""
  7038    }
  7039  | HEADER
  7040    {
  7041      $$ = " header"
  7042    }
  7043  
  7044  manifest_opt:
  7045    {
  7046      $$ = ""
  7047    }
  7048  | MANIFEST ON
  7049    {
  7050      $$ = " manifest on"
  7051    }
  7052  | MANIFEST OFF
  7053    {
  7054      $$ = " manifest off"
  7055    }
  7056  
  7057  overwrite_opt:
  7058    {
  7059      $$ = ""
  7060    }
  7061  | OVERWRITE ON
  7062    {
  7063      $$ = " overwrite on"
  7064    }
  7065  | OVERWRITE OFF
  7066    {
  7067      $$ = " overwrite off"
  7068    }
  7069  
  7070  export_options:
  7071    fields_opts lines_opts
  7072    {
  7073      $$ = $1 + $2
  7074    }
  7075  
  7076  lines_opts:
  7077    {
  7078      $$ = ""
  7079    }
  7080  | LINES lines_opt_list
  7081    {
  7082      $$ = " lines" + $2
  7083    }
  7084  
  7085  lines_opt_list:
  7086    lines_opt
  7087    {
  7088      $$ = $1
  7089    }
  7090  | lines_opt_list lines_opt
  7091    {
  7092      $$ = $1 + $2
  7093    }
  7094  
  7095  lines_opt:
  7096    STARTING BY STRING
  7097    {
  7098      $$ = " starting by " + encodeSQLString($3)
  7099    }
  7100  | TERMINATED BY STRING
  7101    {
  7102      $$ = " terminated by " + encodeSQLString($3)
  7103    }
  7104  
  7105  fields_opts:
  7106    {
  7107      $$ = ""
  7108    }
  7109  | columns_or_fields fields_opt_list
  7110    {
  7111      $$ = " " + $1 + $2
  7112    }
  7113  
  7114  fields_opt_list:
  7115    fields_opt
  7116    {
  7117      $$ = $1
  7118    }
  7119  | fields_opt_list fields_opt
  7120    {
  7121      $$ = $1 + $2
  7122    }
  7123  
  7124  fields_opt:
  7125    TERMINATED BY STRING
  7126    {
  7127      $$ = " terminated by " + encodeSQLString($3)
  7128    }
  7129  | optionally_opt ENCLOSED BY STRING
  7130    {
  7131      $$ = $1 + " enclosed by " + encodeSQLString($4)
  7132    }
  7133  | ESCAPED BY STRING
  7134    {
  7135      $$ = " escaped by " + encodeSQLString($3)
  7136    }
  7137  
  7138  optionally_opt:
  7139    {
  7140      $$ = ""
  7141    }
  7142  | OPTIONALLY
  7143    {
  7144      $$ = " optionally"
  7145    }
  7146  
  7147  // insert_data expands all combinations into a single rule.
  7148  // This avoids a shift/reduce conflict while encountering the
  7149  // following two possible constructs:
  7150  // insert into t1(a, b) (select * from t2)
  7151  // insert into t1(select * from t2)
  7152  // Because the rules are together, the parser can keep shifting
  7153  // the tokens until it disambiguates a as sql_id and select as keyword.
  7154  insert_data:
  7155    VALUES tuple_list
  7156    {
  7157      $$ = &Insert{Rows: $2}
  7158    }
  7159  | select_statement
  7160    {
  7161      $$ = &Insert{Rows: $1}
  7162    }
  7163  | openb ins_column_list closeb VALUES tuple_list
  7164    {
  7165      $$ = &Insert{Columns: $2, Rows: $5}
  7166    }
  7167  | openb closeb VALUES tuple_list
  7168    {
  7169      $$ = &Insert{Columns: []IdentifierCI{}, Rows: $4}
  7170    }
  7171  | openb ins_column_list closeb select_statement
  7172    {
  7173      $$ = &Insert{Columns: $2, Rows: $4}
  7174    }
  7175  
  7176  ins_column_list:
  7177    sql_id
  7178    {
  7179      $$ = Columns{$1}
  7180    }
  7181  | sql_id '.' sql_id
  7182    {
  7183      $$ = Columns{$3}
  7184    }
  7185  | ins_column_list ',' sql_id
  7186    {
  7187      $$ = append($$, $3)
  7188    }
  7189  | ins_column_list ',' sql_id '.' sql_id
  7190    {
  7191      $$ = append($$, $5)
  7192    }
  7193  
  7194  on_dup_opt:
  7195    {
  7196      $$ = nil
  7197    }
  7198  | ON DUPLICATE KEY UPDATE update_list
  7199    {
  7200      $$ = $5
  7201    }
  7202  
  7203  tuple_list:
  7204    tuple_or_empty
  7205    {
  7206      $$ = Values{$1}
  7207    }
  7208  | tuple_list ',' tuple_or_empty
  7209    {
  7210      $$ = append($1, $3)
  7211    }
  7212  
  7213  tuple_or_empty:
  7214    row_tuple
  7215    {
  7216      $$ = $1
  7217    }
  7218  | openb closeb
  7219    {
  7220      $$ = ValTuple{}
  7221    }
  7222  
  7223  row_tuple:
  7224    openb expression_list closeb
  7225    {
  7226      $$ = ValTuple($2)
  7227    }
  7228  | ROW openb expression_list closeb
  7229    {
  7230      $$ = ValTuple($3)
  7231    }
  7232  tuple_expression:
  7233   row_tuple
  7234    {
  7235      if len($1) == 1 {
  7236        $$ = $1[0]
  7237      } else {
  7238        $$ = $1
  7239      }
  7240    }
  7241  
  7242  update_list:
  7243    update_expression
  7244    {
  7245      $$ = UpdateExprs{$1}
  7246    }
  7247  | update_list ',' update_expression
  7248    {
  7249      $$ = append($1, $3)
  7250    }
  7251  
  7252  update_expression:
  7253    column_name '=' expression
  7254    {
  7255      $$ = &UpdateExpr{Name: $1, Expr: $3}
  7256    }
  7257  
  7258  charset_or_character_set:
  7259    CHARSET
  7260  | CHARACTER SET
  7261    {
  7262      $$ = "charset"
  7263    }
  7264  
  7265  charset_or_character_set_or_names:
  7266    charset_or_character_set
  7267  | NAMES
  7268  
  7269  charset_value:
  7270    sql_id
  7271    {
  7272      $$ = NewStrLiteral($1.String())
  7273    }
  7274  | STRING
  7275    {
  7276      $$ = NewStrLiteral($1)
  7277    }
  7278  | DEFAULT
  7279    {
  7280      $$ = &Default{}
  7281    }
  7282  
  7283  for_from:
  7284    FOR
  7285  | FROM
  7286  
  7287  temp_opt:
  7288    { $$ = false }
  7289  | TEMPORARY
  7290    { $$ = true }
  7291  
  7292  exists_opt:
  7293    { $$ = false }
  7294  | IF EXISTS
  7295    { $$ = true }
  7296  
  7297  not_exists_opt:
  7298    { $$ = false }
  7299  | IF NOT EXISTS
  7300    { $$ = true }
  7301  
  7302  ignore_opt:
  7303    { $$ = false }
  7304  | IGNORE
  7305    { $$ = true }
  7306  
  7307  to_opt:
  7308    { $$ = struct{}{} }
  7309  | TO
  7310    { $$ = struct{}{} }
  7311  | AS
  7312    { $$ = struct{}{} }
  7313  
  7314  call_statement:
  7315    CALL table_name openb expression_list_opt closeb
  7316    {
  7317      $$ = &CallProc{Name: $2, Params: $4}
  7318    }
  7319  
  7320  expression_list_opt:
  7321    {
  7322      $$ = nil
  7323    }
  7324  | expression_list
  7325    {
  7326      $$ = $1
  7327    }
  7328  
  7329  using_opt:
  7330    { $$ = nil }
  7331  | using_index_type
  7332    { $$ = []*IndexOption{$1} }
  7333  
  7334  using_index_type:
  7335    USING sql_id
  7336    {
  7337      $$ = &IndexOption{Name: string($1), String: string($2.String())}
  7338    }
  7339  
  7340  sql_id:
  7341    ci_identifier
  7342    {
  7343      $$ = $1
  7344    }
  7345  | non_reserved_keyword
  7346    {
  7347      $$ = NewIdentifierCI(string($1))
  7348    }
  7349  
  7350  reserved_sql_id:
  7351    sql_id
  7352  | reserved_keyword
  7353    {
  7354      $$ = NewIdentifierCI(string($1))
  7355    }
  7356  
  7357  table_id:
  7358    ID
  7359    {
  7360      $$ = NewIdentifierCS(string($1))
  7361    }
  7362  | non_reserved_keyword
  7363    {
  7364      $$ = NewIdentifierCS(string($1))
  7365    }
  7366  
  7367  table_id_opt:
  7368    /* empty */ %prec LOWER_THAN_CHARSET
  7369    {
  7370      $$ = NewIdentifierCS("")
  7371    }
  7372  | table_id
  7373    {
  7374      $$ = $1
  7375    }
  7376  
  7377  reserved_table_id:
  7378    table_id
  7379  | reserved_keyword
  7380    {
  7381      $$ = NewIdentifierCS(string($1))
  7382    }
  7383  /*
  7384    These are not all necessarily reserved in MySQL, but some are.
  7385  
  7386    These are more importantly reserved because they may conflict with our grammar.
  7387    If you want to move one that is not reserved in MySQL (i.e. ESCAPE) to the
  7388    non_reserved_keywords, you'll need to deal with any conflicts.
  7389  
  7390    Sorted alphabetically
  7391  */
  7392  reserved_keyword:
  7393    ADD
  7394  | ALL
  7395  | AND
  7396  | AS
  7397  | ASC
  7398  | BETWEEN
  7399  | BINARY
  7400  | BOTH
  7401  | BY
  7402  | CASE
  7403  | CALL
  7404  | CHANGE
  7405  | CHARACTER
  7406  | CHECK
  7407  | COLLATE
  7408  | COLUMN
  7409  | CONVERT
  7410  | CREATE
  7411  | CROSS
  7412  | CUME_DIST
  7413  | CURRENT_DATE
  7414  | CURRENT_TIME
  7415  | CURRENT_TIMESTAMP
  7416  | CURRENT_USER
  7417  | SUBSTR
  7418  | SUBSTRING
  7419  | DATABASE
  7420  | DATABASES
  7421  | DEFAULT
  7422  | DELETE
  7423  | DENSE_RANK
  7424  | DESC
  7425  | DESCRIBE
  7426  | DISTINCT
  7427  | DISTINCTROW
  7428  | DIV
  7429  | DROP
  7430  | ELSE
  7431  | EMPTY
  7432  | ESCAPE
  7433  | EXISTS
  7434  | EXPLAIN
  7435  | EXTRACT
  7436  | FALSE
  7437  | FIRST_VALUE
  7438  | FOR
  7439  | FORCE
  7440  | FOREIGN
  7441  | FROM
  7442  | FULLTEXT
  7443  | GENERATED
  7444  | GROUP
  7445  | GROUPING
  7446  | GROUPS
  7447  | HAVING
  7448  | IF
  7449  | IGNORE
  7450  | IN
  7451  | INDEX
  7452  | INNER
  7453  | INSERT
  7454  | INTERVAL
  7455  | INTO
  7456  | IS
  7457  | JOIN
  7458  | JSON_TABLE
  7459  | KEY
  7460  | LAG
  7461  | LAST_VALUE
  7462  | LATERAL
  7463  | LEAD
  7464  | LEADING
  7465  | LEFT
  7466  | LIKE
  7467  | LIMIT
  7468  | LINEAR
  7469  | LOCALTIME
  7470  | LOCALTIMESTAMP
  7471  | LOCK
  7472  | LOW_PRIORITY
  7473  | MATCH
  7474  | MAXVALUE
  7475  | MOD
  7476  | NATURAL
  7477  | NEXT // next should be doable as non-reserved, but is not due to the special `select next num_val` query that vitess supports
  7478  | NO_WRITE_TO_BINLOG
  7479  | NOT
  7480  | NOW
  7481  | NTH_VALUE
  7482  | NTILE
  7483  | NULL
  7484  | OF
  7485  | OFF
  7486  | ON
  7487  | OPTIMIZER_COSTS
  7488  | OR
  7489  | ORDER
  7490  | OUTER
  7491  | OUTFILE
  7492  | OVER
  7493  | PARTITION
  7494  | PERCENT_RANK
  7495  | PRIMARY
  7496  | RANGE
  7497  | RANK
  7498  | READ
  7499  | RECURSIVE
  7500  | REGEXP
  7501  | RENAME
  7502  | REPLACE
  7503  | RIGHT
  7504  | RLIKE
  7505  | ROW
  7506  | ROW_NUMBER
  7507  | ROWS
  7508  | SCHEMA
  7509  | SCHEMAS
  7510  | SELECT
  7511  | SEPARATOR
  7512  | SET
  7513  | SHOW
  7514  | SPATIAL
  7515  | STORED
  7516  | STRAIGHT_JOIN
  7517  | SYSTEM
  7518  | TABLE
  7519  | THEN
  7520  | TIMESTAMPADD
  7521  | TIMESTAMPDIFF
  7522  | TO
  7523  | TRAILING
  7524  | TRUE
  7525  | UNION
  7526  | UNIQUE
  7527  | UNLOCK
  7528  | UPDATE
  7529  | USE
  7530  | USING
  7531  | UTC_DATE
  7532  | UTC_TIME
  7533  | UTC_TIMESTAMP
  7534  | VALUES
  7535  | VIRTUAL
  7536  | WITH
  7537  | WHEN
  7538  | WHERE
  7539  | WINDOW
  7540  | WRITE
  7541  | XOR
  7542  
  7543  /*
  7544    These are non-reserved Vitess, because they don't cause conflicts in the grammar.
  7545    Some of them may be reserved in MySQL. The good news is we backtick quote them
  7546    when we rewrite the query, so no issue should arise.
  7547  
  7548    Sorted alphabetically
  7549  */
  7550  non_reserved_keyword:
  7551    AGAINST
  7552  | ACTION
  7553  | ACTIVE
  7554  | ADMIN
  7555  | AFTER
  7556  | ALGORITHM
  7557  | ALWAYS
  7558  | ARRAY
  7559  | ASCII
  7560  | AUTO_INCREMENT
  7561  | AUTOEXTEND_SIZE
  7562  | AVG %prec FUNCTION_CALL_NON_KEYWORD
  7563  | AVG_ROW_LENGTH
  7564  | BEGIN
  7565  | BIGINT
  7566  | BIT
  7567  | BIT_AND %prec FUNCTION_CALL_NON_KEYWORD
  7568  | BIT_OR %prec FUNCTION_CALL_NON_KEYWORD
  7569  | BIT_XOR %prec FUNCTION_CALL_NON_KEYWORD
  7570  | BLOB
  7571  | BOOL
  7572  | BOOLEAN
  7573  | BUCKETS
  7574  | BYTE
  7575  | CANCEL
  7576  | CASCADE
  7577  | CASCADED
  7578  | CHANNEL
  7579  | CHAR %prec FUNCTION_CALL_NON_KEYWORD
  7580  | CHARSET
  7581  | CHECKSUM
  7582  | CLEANUP
  7583  | CLONE
  7584  | COALESCE
  7585  | CODE
  7586  | COLLATION
  7587  | COLUMN_FORMAT
  7588  | COLUMNS
  7589  | COMMENT_KEYWORD
  7590  | COMMIT
  7591  | COMMITTED
  7592  | COMPACT
  7593  | COMPLETE
  7594  | COMPONENT
  7595  | COMPRESSED
  7596  | COMPRESSION
  7597  | CONNECTION
  7598  | CONSISTENT
  7599  | COPY
  7600  | COUNT %prec FUNCTION_CALL_NON_KEYWORD
  7601  | CSV
  7602  | CURRENT
  7603  | DATA
  7604  | DATE %prec STRING_TYPE_PREFIX_NON_KEYWORD
  7605  | DATETIME
  7606  | DEALLOCATE
  7607  | DECIMAL_TYPE
  7608  | DELAY_KEY_WRITE
  7609  | DEFINER
  7610  | DEFINITION
  7611  | DESCRIPTION
  7612  | DIRECTORY
  7613  | DISABLE
  7614  | DISCARD
  7615  | DISK
  7616  | DO
  7617  | DOUBLE
  7618  | DUMPFILE
  7619  | DUPLICATE
  7620  | DYNAMIC
  7621  | ENABLE
  7622  | ENCLOSED
  7623  | ENCRYPTION
  7624  | END
  7625  | ENFORCED
  7626  | ENGINE
  7627  | ENGINE_ATTRIBUTE
  7628  | ENGINES
  7629  | ENUM
  7630  | ERROR
  7631  | ESCAPED
  7632  | EVENT
  7633  | EXCHANGE
  7634  | EXCLUDE
  7635  | EXCLUSIVE
  7636  | EXECUTE
  7637  | EXPANSION
  7638  | EXPIRE
  7639  | EXPORT
  7640  | EXTENDED
  7641  | ExtractValue %prec FUNCTION_CALL_NON_KEYWORD
  7642  | FLOAT_TYPE
  7643  | FIELDS
  7644  | FIRST
  7645  | FIXED
  7646  | FLUSH
  7647  | FOLLOWING
  7648  | FORMAT
  7649  | FORMAT_BYTES %prec FUNCTION_CALL_NON_KEYWORD
  7650  | FORMAT_PICO_TIME %prec FUNCTION_CALL_NON_KEYWORD
  7651  | FULL
  7652  | FUNCTION
  7653  | GENERAL
  7654  | GEOMCOLLECTION
  7655  | GEOMETRY
  7656  | GEOMETRYCOLLECTION
  7657  | GET_LOCK %prec FUNCTION_CALL_NON_KEYWORD
  7658  | GET_MASTER_PUBLIC_KEY
  7659  | GLOBAL
  7660  | GROUP_CONCAT %prec FUNCTION_CALL_NON_KEYWORD
  7661  | GTID_EXECUTED
  7662  | GTID_SUBSET %prec FUNCTION_CALL_NON_KEYWORD
  7663  | GTID_SUBTRACT %prec FUNCTION_CALL_NON_KEYWORD
  7664  | HASH
  7665  | HEADER
  7666  | HISTOGRAM
  7667  | HISTORY
  7668  | HOSTS
  7669  | IMPORT
  7670  | INACTIVE
  7671  | INPLACE
  7672  | INSERT_METHOD
  7673  | INSTANT
  7674  | INT
  7675  | INTEGER
  7676  | INVISIBLE
  7677  | INVOKER
  7678  | INDEXES
  7679  | IS_FREE_LOCK %prec FUNCTION_CALL_NON_KEYWORD
  7680  | IS_USED_LOCK %prec FUNCTION_CALL_NON_KEYWORD
  7681  | ISOLATION
  7682  | JSON
  7683  | JSON_ARRAY %prec FUNCTION_CALL_NON_KEYWORD
  7684  | JSON_ARRAY_APPEND %prec FUNCTION_CALL_NON_KEYWORD
  7685  | JSON_ARRAY_INSERT %prec FUNCTION_CALL_NON_KEYWORD
  7686  | JSON_CONTAINS %prec FUNCTION_CALL_NON_KEYWORD
  7687  | JSON_CONTAINS_PATH %prec FUNCTION_CALL_NON_KEYWORD
  7688  | JSON_DEPTH %prec FUNCTION_CALL_NON_KEYWORD
  7689  | JSON_EXTRACT %prec FUNCTION_CALL_NON_KEYWORD
  7690  | JSON_INSERT %prec FUNCTION_CALL_NON_KEYWORD
  7691  | JSON_KEYS %prec FUNCTION_CALL_NON_KEYWORD
  7692  | JSON_MERGE %prec FUNCTION_CALL_NON_KEYWORD
  7693  | JSON_MERGE_PATCH %prec FUNCTION_CALL_NON_KEYWORD
  7694  | JSON_MERGE_PRESERVE %prec FUNCTION_CALL_NON_KEYWORD
  7695  | JSON_OBJECT %prec FUNCTION_CALL_NON_KEYWORD
  7696  | JSON_OVERLAPS %prec FUNCTION_CALL_NON_KEYWORD
  7697  | JSON_PRETTY %prec FUNCTION_CALL_NON_KEYWORD
  7698  | JSON_QUOTE %prec FUNCTION_CALL_NON_KEYWORD
  7699  | JSON_REMOVE %prec FUNCTION_CALL_NON_KEYWORD
  7700  | JSON_REPLACE %prec FUNCTION_CALL_NON_KEYWORD
  7701  | JSON_SCHEMA_VALID %prec FUNCTION_CALL_NON_KEYWORD
  7702  | JSON_SCHEMA_VALIDATION_REPORT %prec FUNCTION_CALL_NON_KEYWORD
  7703  | JSON_SEARCH %prec FUNCTION_CALL_NON_KEYWORD
  7704  | JSON_SET %prec FUNCTION_CALL_NON_KEYWORD
  7705  | JSON_STORAGE_FREE %prec FUNCTION_CALL_NON_KEYWORD
  7706  | JSON_STORAGE_SIZE %prec FUNCTION_CALL_NON_KEYWORD
  7707  | JSON_TYPE %prec FUNCTION_CALL_NON_KEYWORD
  7708  | JSON_VALID %prec FUNCTION_CALL_NON_KEYWORD
  7709  | JSON_VALUE %prec FUNCTION_CALL_NON_KEYWORD
  7710  | JSON_UNQUOTE %prec FUNCTION_CALL_NON_KEYWORD
  7711  | KEY_BLOCK_SIZE
  7712  | KEYS
  7713  | KEYSPACES
  7714  | LANGUAGE
  7715  | LAST
  7716  | LAST_INSERT_ID
  7717  | LAUNCH
  7718  | LESS
  7719  | LEVEL
  7720  | LINES
  7721  | LINESTRING
  7722  | LIST
  7723  | LOAD
  7724  | LOCAL
  7725  | LOCATE %prec FUNCTION_CALL_NON_KEYWORD
  7726  | LOCKED
  7727  | LOGS
  7728  | LONGBLOB
  7729  | LONGTEXT
  7730  | LTRIM %prec FUNCTION_CALL_NON_KEYWORD
  7731  | MANIFEST
  7732  | MASTER_COMPRESSION_ALGORITHMS
  7733  | MASTER_PUBLIC_KEY_PATH
  7734  | MASTER_TLS_CIPHERSUITES
  7735  | MASTER_ZSTD_COMPRESSION_LEVEL
  7736  | MAX %prec FUNCTION_CALL_NON_KEYWORD
  7737  | MAX_ROWS
  7738  | MEDIUMBLOB
  7739  | MEDIUMINT
  7740  | MEDIUMTEXT
  7741  | MEMORY
  7742  | MEMBER
  7743  | MERGE
  7744  | MIN %prec FUNCTION_CALL_NON_KEYWORD
  7745  | MIN_ROWS
  7746  | MODE
  7747  | MODIFY
  7748  | MULTILINESTRING
  7749  | MULTIPOINT
  7750  | MULTIPOLYGON
  7751  | NAME
  7752  | NAMES
  7753  | NCHAR
  7754  | NESTED
  7755  | NETWORK_NAMESPACE
  7756  | NOWAIT
  7757  | NO
  7758  | NONE
  7759  | NULLS
  7760  | NUMERIC
  7761  | OFFSET
  7762  | OJ
  7763  | OLD
  7764  | OPEN
  7765  | OPTION
  7766  | OPTIONAL
  7767  | OPTIONALLY
  7768  | ORDINALITY
  7769  | ORGANIZATION
  7770  | ONLY
  7771  | OPTIMIZE
  7772  | OTHERS
  7773  | OVERWRITE
  7774  | PACK_KEYS
  7775  | PARSER
  7776  | PARTIAL
  7777  | PARTITIONING
  7778  | PARTITIONS
  7779  | PASSWORD
  7780  | PATH
  7781  | PERSIST
  7782  | PERSIST_ONLY
  7783  | PLAN
  7784  | PRECEDING
  7785  | PREPARE
  7786  | PRIVILEGE_CHECKS_USER
  7787  | PRIVILEGES
  7788  | PROCESS
  7789  | PS_CURRENT_THREAD_ID %prec FUNCTION_CALL_NON_KEYWORD
  7790  | PS_THREAD_ID %prec FUNCTION_CALL_NON_KEYWORD
  7791  | PLUGINS
  7792  | POINT
  7793  | POLYGON
  7794  | POSITION %prec FUNCTION_CALL_NON_KEYWORD
  7795  | PROCEDURE
  7796  | PROCESSLIST
  7797  | QUERIES
  7798  | QUERY
  7799  | RANDOM
  7800  | RATIO
  7801  | REAL
  7802  | REBUILD
  7803  | REDUNDANT
  7804  | REFERENCE
  7805  | REFERENCES
  7806  | REGEXP_INSTR %prec FUNCTION_CALL_NON_KEYWORD
  7807  | REGEXP_LIKE %prec FUNCTION_CALL_NON_KEYWORD
  7808  | REGEXP_REPLACE %prec FUNCTION_CALL_NON_KEYWORD
  7809  | REGEXP_SUBSTR %prec FUNCTION_CALL_NON_KEYWORD
  7810  | RELAY
  7811  | RELEASE_ALL_LOCKS %prec FUNCTION_CALL_NON_KEYWORD
  7812  | RELEASE_LOCK %prec FUNCTION_CALL_NON_KEYWORD
  7813  | REMOVE
  7814  | REORGANIZE
  7815  | REPAIR
  7816  | REPEATABLE
  7817  | RESTRICT
  7818  | REQUIRE_ROW_FORMAT
  7819  | RESOURCE
  7820  | RESPECT
  7821  | RESTART
  7822  | RETAIN
  7823  | RETRY
  7824  | RETURNING
  7825  | REUSE
  7826  | ROLE
  7827  | ROLLBACK
  7828  | ROW_FORMAT
  7829  | RTRIM %prec FUNCTION_CALL_NON_KEYWORD
  7830  | S3
  7831  | SECONDARY
  7832  | SECONDARY_ENGINE
  7833  | SECONDARY_ENGINE_ATTRIBUTE
  7834  | SECONDARY_LOAD
  7835  | SECONDARY_UNLOAD
  7836  | SECURITY
  7837  | SEQUENCE
  7838  | SESSION
  7839  | SERIALIZABLE
  7840  | SHARE
  7841  | SHARED
  7842  | SIGNED
  7843  | SIMPLE
  7844  | SKIP
  7845  | SLOW
  7846  | SMALLINT
  7847  | SNAPSHOT
  7848  | SQL
  7849  | SRID
  7850  | START
  7851  | STARTING
  7852  | STATS_AUTO_RECALC
  7853  | STATS_PERSISTENT
  7854  | STATS_SAMPLE_PAGES
  7855  | STATUS
  7856  | STORAGE
  7857  | STD %prec FUNCTION_CALL_NON_KEYWORD
  7858  | STDDEV %prec FUNCTION_CALL_NON_KEYWORD
  7859  | STDDEV_POP %prec FUNCTION_CALL_NON_KEYWORD
  7860  | STDDEV_SAMP %prec FUNCTION_CALL_NON_KEYWORD
  7861  | STREAM
  7862  | SUBPARTITION
  7863  | SUBPARTITIONS
  7864  | SUM %prec FUNCTION_CALL_NON_KEYWORD
  7865  | TABLES
  7866  | TABLESPACE
  7867  | TEMPORARY
  7868  | TEMPTABLE
  7869  | TERMINATED
  7870  | TEXT
  7871  | THAN
  7872  | THREAD_PRIORITY
  7873  | THROTTLE
  7874  | TIES
  7875  | TIME %prec STRING_TYPE_PREFIX_NON_KEYWORD
  7876  | TIMESTAMP %prec STRING_TYPE_PREFIX_NON_KEYWORD
  7877  | TINYBLOB
  7878  | TINYINT
  7879  | TINYTEXT
  7880  | TRADITIONAL
  7881  | TRANSACTION
  7882  | TREE
  7883  | TRIGGER
  7884  | TRIGGERS
  7885  | TRIM %prec FUNCTION_CALL_NON_KEYWORD
  7886  | TRUNCATE
  7887  | UNBOUNDED
  7888  | UNCOMMITTED
  7889  | UNDEFINED
  7890  | UNICODE
  7891  | UNSIGNED
  7892  | UNTHROTTLE
  7893  | UNUSED
  7894  | UpdateXML %prec FUNCTION_CALL_NON_KEYWORD
  7895  | UPGRADE
  7896  | USER
  7897  | USER_RESOURCES
  7898  | VALIDATION
  7899  | VAR_POP %prec FUNCTION_CALL_NON_KEYWORD
  7900  | VAR_SAMP %prec FUNCTION_CALL_NON_KEYWORD
  7901  | VARBINARY
  7902  | VARCHAR
  7903  | VARIABLES
  7904  | VARIANCE %prec FUNCTION_CALL_NON_KEYWORD
  7905  | VCPU
  7906  | VEXPLAIN
  7907  | VGTID_EXECUTED
  7908  | VIEW
  7909  | VINDEX
  7910  | VINDEXES
  7911  | VISIBLE
  7912  | VITESS
  7913  | VITESS_KEYSPACES
  7914  | VITESS_METADATA
  7915  | VITESS_MIGRATION
  7916  | VITESS_MIGRATIONS
  7917  | VITESS_REPLICATION_STATUS
  7918  | VITESS_SHARDS
  7919  | VITESS_TABLETS
  7920  | VITESS_TARGET
  7921  | VITESS_THROTTLED_APPS
  7922  | VITESS_THROTTLER
  7923  | VSCHEMA
  7924  | VTEXPLAIN
  7925  | WAIT_FOR_EXECUTED_GTID_SET %prec FUNCTION_CALL_NON_KEYWORD
  7926  | WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS %prec FUNCTION_CALL_NON_KEYWORD
  7927  | WARNINGS
  7928  | WITHOUT
  7929  | WORK
  7930  | YEAR
  7931  | ZEROFILL
  7932  | DAY
  7933  | DAY_HOUR
  7934  | DAY_MICROSECOND
  7935  | DAY_MINUTE
  7936  | DAY_SECOND
  7937  | HOUR
  7938  | HOUR_MICROSECOND
  7939  | HOUR_MINUTE
  7940  | HOUR_SECOND
  7941  | MICROSECOND
  7942  | MINUTE
  7943  | MINUTE_MICROSECOND
  7944  | MINUTE_SECOND
  7945  | MONTH
  7946  | QUARTER
  7947  | SECOND
  7948  | SECOND_MICROSECOND
  7949  | YEAR_MONTH
  7950  | WEIGHT_STRING %prec FUNCTION_CALL_NON_KEYWORD
  7951  
  7952  
  7953  
  7954  openb:
  7955    '('
  7956    {
  7957      if incNesting(yylex) {
  7958        yylex.Error("max nesting level reached")
  7959        return 1
  7960      }
  7961    }
  7962  
  7963  closeb:
  7964    ')'
  7965    {
  7966      decNesting(yylex)
  7967    }
  7968  
  7969  skip_to_end:
  7970  {
  7971    skipToEnd(yylex)
  7972  }
  7973  
  7974  ddl_skip_to_end:
  7975    {
  7976      skipToEnd(yylex)
  7977    }
  7978  | openb
  7979    {
  7980      skipToEnd(yylex)
  7981    }
  7982  | reserved_sql_id
  7983    {
  7984      skipToEnd(yylex)
  7985    }