github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/dialect/mysql/mysql_sql.y (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with 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 package mysql 17 18 import ( 19 "fmt" 20 "strings" 21 "go/constant" 22 23 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 24 "github.com/matrixorigin/matrixone/pkg/sql/parsers/util" 25 "github.com/matrixorigin/matrixone/pkg/defines" 26 ) 27 %} 28 29 %struct { 30 id int 31 str string 32 item interface{} 33 } 34 35 %union { 36 statement tree.Statement 37 statements []tree.Statement 38 39 tableDef tree.TableDef 40 tableDefs tree.TableDefs 41 tableName *tree.TableName 42 tableNames tree.TableNames 43 columnTableDef *tree.ColumnTableDef 44 tableOption tree.TableOption 45 tableOptions []tree.TableOption 46 tableExprs tree.TableExprs 47 tableExpr tree.TableExpr 48 rowFormatType tree.RowFormatType 49 matchType tree.MatchType 50 attributeReference *tree.AttributeReference 51 loadParam *tree.ExternParam 52 tailParam *tree.TailParameter 53 54 functionName *tree.FunctionName 55 funcArg tree.FunctionArg 56 funcArgs tree.FunctionArgs 57 funcArgDecl *tree.FunctionArgDecl 58 funcReturn *tree.ReturnType 59 60 from *tree.From 61 where *tree.Where 62 groupBy tree.GroupBy 63 aliasedTableExpr *tree.AliasedTableExpr 64 direction tree.Direction 65 nullsPosition tree.NullsPosition 66 orderBy tree.OrderBy 67 order *tree.Order 68 limit *tree.Limit 69 unionTypeRecord *tree.UnionTypeRecord 70 parenTableExpr *tree.ParenTableExpr 71 identifierList tree.IdentifierList 72 joinCond tree.JoinCond 73 74 columnType *tree.T 75 unresolvedName *tree.UnresolvedName 76 lengthScaleOpt tree.LengthScaleOpt 77 tuple *tree.Tuple 78 funcType tree.FuncType 79 80 columnAttribute tree.ColumnAttribute 81 columnAttributes []tree.ColumnAttribute 82 attributeNull tree.AttributeNull 83 expr tree.Expr 84 exprs tree.Exprs 85 rowsExprs []tree.Exprs 86 comparisonOp tree.ComparisonOp 87 referenceOptionType tree.ReferenceOptionType 88 referenceOnRecord *tree.ReferenceOnRecord 89 90 select *tree.Select 91 selectStatement tree.SelectStatement 92 selectExprs tree.SelectExprs 93 selectExpr tree.SelectExpr 94 95 insert *tree.Insert 96 replace *tree.Replace 97 createOption tree.CreateOption 98 createOptions []tree.CreateOption 99 indexType tree.IndexType 100 indexCategory tree.IndexCategory 101 keyParts []*tree.KeyPart 102 keyPart *tree.KeyPart 103 indexOption *tree.IndexOption 104 comparisionExpr *tree.ComparisonExpr 105 106 userMiscOption tree.UserMiscOption 107 userMiscOptions []tree.UserMiscOption 108 updateExpr *tree.UpdateExpr 109 updateExprs tree.UpdateExprs 110 completionType tree.CompletionType 111 varAssignmentExpr *tree.VarAssignmentExpr 112 varAssignmentExprs []*tree.VarAssignmentExpr 113 setRole *tree.SetRole 114 setDefaultRole *tree.SetDefaultRole 115 privilege *tree.Privilege 116 privileges []*tree.Privilege 117 objectType tree.ObjectType 118 privilegeType tree.PrivilegeType 119 privilegeLevel *tree.PrivilegeLevel 120 unresolveNames []*tree.UnresolvedName 121 122 partitionOption *tree.PartitionOption 123 clusterByOption *tree.ClusterByOption 124 partitionBy *tree.PartitionBy 125 windowSpec *tree.WindowSpec 126 windowFrame *tree.WindowFrame 127 windowFrameBound tree.WindowFrameBound 128 windowFrameUnit tree.WindowFrameUnits 129 partition *tree.Partition 130 partitions []*tree.Partition 131 values tree.Values 132 numVal *tree.NumVal 133 subPartition *tree.SubPartition 134 subPartitions []*tree.SubPartition 135 136 subquery *tree.Subquery 137 funcExpr *tree.FuncExpr 138 139 roles []*tree.Role 140 role *tree.Role 141 usernameRecord *tree.UsernameRecord 142 authRecord *tree.AuthRecord 143 user *tree.User 144 users []*tree.User 145 tlsOptions []tree.TlsOption 146 tlsOption tree.TlsOption 147 resourceOption tree.ResourceOption 148 resourceOptions []tree.ResourceOption 149 unresolvedObjectName *tree.UnresolvedObjectName 150 lengthOpt int32 151 unsignedOpt bool 152 zeroFillOpt bool 153 ifNotExists bool 154 defaultOptional bool 155 fullOpt bool 156 boolVal bool 157 int64Val int64 158 strs []string 159 160 duplicateKey tree.DuplicateKey 161 fields *tree.Fields 162 fieldsList []*tree.Fields 163 lines *tree.Lines 164 varExpr *tree.VarExpr 165 varExprs []*tree.VarExpr 166 loadColumn tree.LoadColumn 167 loadColumns []tree.LoadColumn 168 assignments []*tree.Assignment 169 assignment *tree.Assignment 170 properties []tree.Property 171 property tree.Property 172 exportParm *tree.ExportParam 173 174 epxlainOptions []tree.OptionElem 175 epxlainOption tree.OptionElem 176 whenClause *tree.When 177 whenClauseList []*tree.When 178 withClause *tree.With 179 cte *tree.CTE 180 cteList []*tree.CTE 181 182 accountAuthOption tree.AccountAuthOption 183 alterAccountAuthOption tree.AlterAccountAuthOption 184 accountIdentified tree.AccountIdentified 185 accountStatus tree.AccountStatus 186 accountComment tree.AccountComment 187 accountCommentOrAttribute tree.AccountCommentOrAttribute 188 userIdentified *tree.AccountIdentified 189 accountRole *tree.Role 190 showType tree.ShowType 191 joinTableExpr *tree.JoinTableExpr 192 193 indexHintType tree.IndexHintType 194 indexHintScope tree.IndexHintScope 195 indexHint *tree.IndexHint 196 indexHintList []*tree.IndexHint 197 198 killOption tree.KillOption 199 statementOption tree.StatementOption 200 201 tableLock tree.TableLock 202 tableLocks []tree.TableLock 203 tableLockType tree.TableLockType 204 } 205 206 %token LEX_ERROR 207 %nonassoc EMPTY 208 %left <str> UNION EXCEPT INTERSECT MINUS 209 %token <str> SELECT STREAM INSERT UPDATE DELETE FROM WHERE GROUP HAVING ORDER BY LIMIT OFFSET FOR CONNECT MANAGE GRANTS OWNERSHIP REFERENCE 210 %nonassoc LOWER_THAN_SET 211 %nonassoc <str> SET 212 %token <str> ALL DISTINCT DISTINCTROW AS EXISTS ASC DESC INTO DUPLICATE DEFAULT LOCK KEYS NULLS FIRST LAST 213 %token <str> VALUES 214 %token <str> NEXT VALUE SHARE MODE 215 %token <str> SQL_NO_CACHE SQL_CACHE 216 %left <str> JOIN STRAIGHT_JOIN LEFT RIGHT INNER OUTER CROSS NATURAL USE FORCE 217 %nonassoc LOWER_THAN_ON 218 %nonassoc <str> ON USING 219 %left <str> SUBQUERY_AS_EXPR 220 %right <str> '(' 221 %left <str> ')' 222 %nonassoc LOWER_THAN_STRING 223 %nonassoc <str> ID AT_ID AT_AT_ID STRING VALUE_ARG LIST_ARG COMMENT COMMENT_KEYWORD 224 %token <item> INTEGRAL HEX BIT_LITERAL FLOAT 225 %token <str> HEXNUM 226 %token <str> NULL TRUE FALSE 227 %nonassoc LOWER_THAN_CHARSET 228 %nonassoc <str> CHARSET 229 %right <str> UNIQUE KEY 230 %left <str> OR PIPE_CONCAT 231 %left <str> XOR 232 %left <str> AND 233 %right <str> NOT '!' 234 %left <str> BETWEEN CASE WHEN THEN ELSE END 235 %nonassoc LOWER_THAN_EQ 236 %left <str> '=' '<' '>' LE GE NE NULL_SAFE_EQUAL IS LIKE REGEXP IN ASSIGNMENT ILIKE 237 %left <str> '|' 238 %left <str> '&' 239 %left <str> SHIFT_LEFT SHIFT_RIGHT 240 %left <str> '+' '-' 241 %left <str> '*' '/' DIV '%' MOD 242 %left <str> '^' 243 %right <str> '~' UNARY 244 %left <str> COLLATE 245 %right <str> BINARY UNDERSCORE_BINARY 246 %right <str> INTERVAL 247 %nonassoc <str> '.' ',' 248 249 // Transaction 250 %token <str> BEGIN START TRANSACTION COMMIT ROLLBACK WORK CONSISTENT SNAPSHOT 251 %token <str> CHAIN NO RELEASE PRIORITY QUICK 252 253 // Type 254 %token <str> BIT TINYINT SMALLINT MEDIUMINT INT INTEGER BIGINT INTNUM 255 %token <str> REAL DOUBLE FLOAT_TYPE DECIMAL NUMERIC DECIMAL_VALUE 256 %token <str> TIME TIMESTAMP DATETIME YEAR 257 %token <str> CHAR VARCHAR BOOL CHARACTER VARBINARY NCHAR 258 %token <str> TEXT TINYTEXT MEDIUMTEXT LONGTEXT 259 %token <str> BLOB TINYBLOB MEDIUMBLOB LONGBLOB JSON ENUM UUID 260 %token <str> GEOMETRY POINT LINESTRING POLYGON GEOMETRYCOLLECTION MULTIPOINT MULTILINESTRING MULTIPOLYGON 261 %token <str> INT1 INT2 INT3 INT4 INT8 S3OPTION 262 263 // Select option 264 %token <str> SQL_SMALL_RESULT SQL_BIG_RESULT SQL_BUFFER_RESULT 265 %token <str> LOW_PRIORITY HIGH_PRIORITY DELAYED 266 267 // Create Table 268 %token <str> CREATE ALTER DROP RENAME ANALYZE ADD RETURNS 269 %token <str> SCHEMA TABLE INDEX VIEW TO IGNORE IF PRIMARY COLUMN CONSTRAINT SPATIAL FULLTEXT FOREIGN KEY_BLOCK_SIZE 270 %token <str> SHOW DESCRIBE EXPLAIN DATE ESCAPE REPAIR OPTIMIZE TRUNCATE 271 %token <str> MAXVALUE PARTITION REORGANIZE LESS THAN PROCEDURE TRIGGER 272 %token <str> STATUS VARIABLES ROLE PROXY AVG_ROW_LENGTH STORAGE DISK MEMORY 273 %token <str> CHECKSUM COMPRESSION DATA DIRECTORY DELAY_KEY_WRITE ENCRYPTION ENGINE 274 %token <str> MAX_ROWS MIN_ROWS PACK_KEYS ROW_FORMAT STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES 275 %token <str> DYNAMIC COMPRESSED REDUNDANT COMPACT FIXED COLUMN_FORMAT AUTO_RANDOM 276 %token <str> RESTRICT CASCADE ACTION PARTIAL SIMPLE CHECK ENFORCED 277 %token <str> RANGE LIST ALGORITHM LINEAR PARTITIONS SUBPARTITION SUBPARTITIONS CLUSTER 278 %token <str> TYPE ANY SOME EXTERNAL LOCALFILE URL 279 %token <str> PREPARE DEALLOCATE RESET 280 %token <str> EXTENSION 281 282 // MO table option 283 %token <str> PROPERTIES 284 285 // Index 286 %token <str> PARSER VISIBLE INVISIBLE BTREE HASH RTREE BSI 287 %token <str> ZONEMAP LEADING BOTH TRAILING UNKNOWN 288 289 // Alter 290 %token <str> EXPIRE ACCOUNT ACCOUNTS UNLOCK DAY NEVER PUMP MYSQL_COMPATBILITY_MODE 291 292 // Time 293 %token <str> SECOND ASCII COALESCE COLLATION HOUR MICROSECOND MINUTE MONTH QUARTER REPEAT 294 %token <str> REVERSE ROW_COUNT WEEK 295 296 // Revoke 297 %token <str> REVOKE FUNCTION PRIVILEGES TABLESPACE EXECUTE SUPER GRANT OPTION REFERENCES REPLICATION 298 %token <str> SLAVE CLIENT USAGE RELOAD FILE TEMPORARY ROUTINE EVENT SHUTDOWN 299 300 // Type Modifiers 301 %token <str> NULLX AUTO_INCREMENT APPROXNUM SIGNED UNSIGNED ZEROFILL ENGINES LOW_CARDINALITY 302 303 // Account 304 %token <str> ADMIN_NAME RANDOM SUSPEND ATTRIBUTE HISTORY REUSE CURRENT OPTIONAL FAILED_LOGIN_ATTEMPTS PASSWORD_LOCK_TIME UNBOUNDED SECONDARY 305 306 // User 307 %token <str> USER IDENTIFIED CIPHER ISSUER X509 SUBJECT SAN REQUIRE SSL NONE PASSWORD 308 %token <str> MAX_QUERIES_PER_HOUR MAX_UPDATES_PER_HOUR MAX_CONNECTIONS_PER_HOUR MAX_USER_CONNECTIONS 309 310 // Explain 311 %token <str> FORMAT VERBOSE CONNECTION TRIGGERS PROFILES 312 313 // Load 314 %token <str> LOAD INFILE TERMINATED OPTIONALLY ENCLOSED ESCAPED STARTING LINES ROWS IMPORT 315 316 // MODump 317 %token <str> MODUMP 318 319 // Window function 320 %token <str> OVER PRECEDING FOLLOWING GROUPS 321 322 // Supported SHOW tokens 323 %token <str> DATABASES TABLES EXTENDED FULL PROCESSLIST FIELDS COLUMNS OPEN ERRORS WARNINGS INDEXES SCHEMAS NODE LOCKS 324 %token <str> TABLE_NUMBER COLUMN_NUMBER TABLE_VALUES 325 326 // SET tokens 327 %token <str> NAMES GLOBAL SESSION ISOLATION LEVEL READ WRITE ONLY REPEATABLE COMMITTED UNCOMMITTED SERIALIZABLE 328 %token <str> LOCAL EVENTS PLUGINS 329 330 // Functions 331 %token <str> CURRENT_TIMESTAMP DATABASE 332 %token <str> CURRENT_TIME LOCALTIME LOCALTIMESTAMP 333 %token <str> UTC_DATE UTC_TIME UTC_TIMESTAMP 334 %token <str> REPLACE CONVERT 335 %token <str> SEPARATOR TIMESTAMPDIFF 336 %token <str> CURRENT_DATE CURRENT_USER CURRENT_ROLE 337 338 // Time unit 339 %token <str> SECOND_MICROSECOND MINUTE_MICROSECOND MINUTE_SECOND HOUR_MICROSECOND 340 %token <str> HOUR_SECOND HOUR_MINUTE DAY_MICROSECOND DAY_SECOND DAY_MINUTE DAY_HOUR YEAR_MONTH 341 %token <str> SQL_TSI_HOUR SQL_TSI_DAY SQL_TSI_WEEK SQL_TSI_MONTH SQL_TSI_QUARTER SQL_TSI_YEAR 342 %token <str> SQL_TSI_SECOND SQL_TSI_MINUTE 343 344 // With 345 %token <str> RECURSIVE CONFIG DRAINER 346 347 // Match 348 %token <str> MATCH AGAINST BOOLEAN LANGUAGE WITH QUERY EXPANSION 349 350 // Built-in function 351 %token <str> ADDDATE BIT_AND BIT_OR BIT_XOR CAST COUNT APPROX_COUNT_DISTINCT 352 %token <str> APPROX_PERCENTILE CURDATE CURTIME DATE_ADD DATE_SUB EXTRACT 353 %token <str> GROUP_CONCAT MAX MID MIN NOW POSITION SESSION_USER STD STDDEV MEDIAN 354 %token <str> STDDEV_POP STDDEV_SAMP SUBDATE SUBSTR SUBSTRING SUM SYSDATE 355 %token <str> SYSTEM_USER TRANSLATE TRIM VARIANCE VAR_POP VAR_SAMP AVG 356 357 //JSON function 358 %token <str> ARROW 359 360 // Insert 361 %token <str> ROW OUTFILE HEADER MAX_FILE_SIZE FORCE_QUOTE PARALLEL 362 363 %token <str> UNUSED BINDINGS 364 365 // Do 366 %token <str> DO 367 368 // Declare 369 %token <str> DECLARE 370 371 %type <statement> stmt 372 %type <statements> stmt_list 373 %type <statement> create_stmt insert_stmt delete_stmt drop_stmt alter_stmt truncate_table_stmt 374 %type <statement> delete_without_using_stmt delete_with_using_stmt 375 %type <statement> drop_ddl_stmt drop_database_stmt drop_table_stmt drop_index_stmt drop_prepare_stmt drop_view_stmt drop_function_stmt 376 %type <statement> drop_account_stmt drop_role_stmt drop_user_stmt 377 %type <statement> create_account_stmt create_user_stmt create_role_stmt 378 %type <statement> create_ddl_stmt create_table_stmt create_database_stmt create_index_stmt create_view_stmt create_function_stmt create_extension_stmt 379 %type <statement> show_stmt show_create_stmt show_columns_stmt show_databases_stmt show_target_filter_stmt show_table_status_stmt show_grants_stmt show_collation_stmt show_accounts_stmt 380 %type <statement> show_tables_stmt show_process_stmt show_errors_stmt show_warnings_stmt show_target 381 %type <statement> show_function_status_stmt show_node_list_stmt show_locks_stmt 382 %type <statement> show_table_num_stmt show_column_num_stmt show_table_values_stmt 383 %type <statement> show_variables_stmt show_status_stmt show_index_stmt 384 %type <statement> alter_account_stmt alter_user_stmt alter_view_stmt update_stmt use_stmt update_no_with_stmt alter_database_config_stmt 385 %type <statement> transaction_stmt begin_stmt commit_stmt rollback_stmt 386 %type <statement> explain_stmt explainable_stmt 387 %type <statement> set_stmt set_variable_stmt set_password_stmt set_role_stmt set_default_role_stmt 388 %type <statement> lock_stmt lock_table_stmt unlock_table_stmt 389 %type <statement> revoke_stmt grant_stmt 390 %type <statement> load_data_stmt import_data_stmt 391 %type <statement> analyze_stmt 392 %type <statement> prepare_stmt prepareable_stmt deallocate_stmt execute_stmt reset_stmt 393 %type <statement> replace_stmt 394 %type <statement> do_stmt 395 %type <statement> declare_stmt 396 %type <statement> values_stmt 397 %type <statement> mo_dump_stmt 398 %type <statement> load_extension_stmt 399 %type <statement> kill_stmt 400 %type <rowsExprs> row_constructor_list 401 %type <exprs> row_constructor 402 %type <exportParm> export_data_param_opt 403 %type <loadParam> load_param_opt load_param_opt_2 404 %type <tailParam> tail_param_opt 405 406 %type <select> select_stmt select_no_parens 407 %type <selectStatement> simple_select select_with_parens simple_select_clause 408 %type <selectExprs> select_expression_list 409 %type <selectExpr> select_expression 410 %type <tableExprs> table_name_wild_list 411 %type <joinTableExpr> table_references join_table 412 %type <tableExpr> into_table_name table_function table_factor table_reference escaped_table_reference 413 %type <direction> asc_desc_opt 414 %type <nullsPosition> nulls_first_last_opt 415 %type <order> order 416 %type <orderBy> order_list order_by_clause order_by_opt 417 %type <limit> limit_opt limit_clause 418 %type <str> insert_column 419 %type <identifierList> column_list column_list_opt partition_clause_opt partition_id_list insert_column_list accounts_opt accounts_list 420 %type <joinCond> join_condition join_condition_opt on_expression_opt 421 422 %type <functionName> func_name 423 %type <funcArgs> func_args_list_opt func_args_list 424 %type <funcArg> func_arg 425 %type <funcArgDecl> func_arg_decl 426 %type <funcReturn> func_return 427 %type <str> func_lang extension_lang extension_name 428 429 %type <tableDefs> table_elem_list_opt table_elem_list 430 %type <tableDef> table_elem constaint_def constraint_elem 431 %type <tableName> table_name table_name_opt_wild 432 %type <tableNames> table_name_list 433 %type <columnTableDef> column_def 434 %type <columnType> mo_cast_type mysql_cast_type 435 %type <columnType> column_type char_type spatial_type time_type numeric_type decimal_type int_type 436 %type <str> integer_opt 437 %type <columnAttribute> column_attribute_elem keys 438 %type <columnAttributes> column_attribute_list column_attribute_list_opt 439 %type <tableOptions> table_option_list_opt table_option_list 440 %type <str> charset_name storage_opt collate_name column_format storage_media 441 %type <rowFormatType> row_format_options 442 %type <int64Val> field_length_opt max_file_size_opt 443 %type <matchType> match match_opt 444 %type <referenceOptionType> ref_opt on_delete on_update 445 %type <referenceOnRecord> on_delete_update_opt 446 %type <attributeReference> references_def 447 448 %type <tableOption> table_option 449 %type <from> from_clause from_opt 450 %type <where> where_expression_opt having_opt 451 %type <groupBy> group_by_opt 452 %type <aliasedTableExpr> aliased_table_name 453 %type <unionTypeRecord> union_op 454 %type <parenTableExpr> table_subquery 455 %type <str> inner_join straight_join outer_join natural_join 456 %type <funcType> func_type_opt 457 %type <funcExpr> function_call_generic 458 %type <funcExpr> function_call_keyword 459 %type <funcExpr> function_call_nonkeyword 460 %type <funcExpr> function_call_aggregate 461 462 %type <unresolvedName> column_name column_name_unresolved 463 %type <strs> enum_values force_quote_opt force_quote_list infile_or_s3_param infile_or_s3_params 464 %type <str> sql_id charset_keyword db_name db_name_opt 465 %type <str> not_keyword func_not_keyword 466 %type <str> reserved_keyword non_reserved_keyword 467 %type <str> equal_opt reserved_sql_id reserved_table_id 468 %type <str> as_name_opt as_opt_id table_id id_or_var name_string ident 469 %type <str> database_id table_alias explain_sym prepare_sym deallocate_sym stmt_name reset_sym 470 %type <unresolvedObjectName> unresolved_object_name table_column_name 471 %type <unresolvedObjectName> table_name_unresolved 472 %type <comparisionExpr> like_opt 473 %type <fullOpt> full_opt 474 %type <str> database_name_opt auth_string constraint_keyword_opt constraint_keyword 475 %type <userMiscOption> pwd_or_lck pwd_or_lck_opt 476 //%type <userMiscOptions> pwd_or_lck_list 477 478 %type <expr> literal 479 %type <expr> predicate 480 %type <expr> bit_expr interval_expr 481 %type <expr> simple_expr else_opt 482 %type <expr> expression like_escape_opt boolean_primary col_tuple expression_opt 483 %type <exprs> expression_list_opt 484 %type <exprs> expression_list row_value window_partition_by window_partition_by_opt 485 %type <expr> datetime_precision_opt datetime_precision 486 %type <tuple> tuple_expression 487 %type <comparisonOp> comparison_operator and_or_some 488 %type <createOption> create_option 489 %type <createOptions> create_option_list_opt create_option_list 490 %type <ifNotExists> not_exists_opt 491 %type <defaultOptional> default_opt 492 %type <str> database_or_schema 493 %type <indexType> using_opt 494 %type <indexCategory> index_prefix 495 %type <keyParts> index_column_list index_column_list_opt 496 %type <keyPart> index_column 497 %type <indexOption> index_option_list index_option 498 %type <roles> role_spec_list using_roles_opt 499 %type <role> role_spec 500 %type <str> role_name 501 %type <usernameRecord> user_name 502 %type <user> user_spec drop_user_spec user_spec_with_identified 503 %type <users> user_spec_list drop_user_spec_list user_spec_list_of_create_user 504 //%type <tlsOptions> require_clause_opt require_clause require_list 505 //%type <tlsOption> require_elem 506 //%type <resourceOptions> conn_option_list conn_options 507 //%type <resourceOption> conn_option 508 %type <updateExpr> update_value 509 %type <updateExprs> update_list on_duplicate_key_update_opt 510 %type <completionType> completion_type 511 %type <str> password_opt 512 %type <boolVal> grant_option_opt enforce enforce_opt 513 514 %type <varAssignmentExpr> var_assignment 515 %type <varAssignmentExprs> var_assignment_list 516 %type <str> var_name equal_or_assignment 517 %type <strs> var_name_list 518 %type <expr> set_expr 519 //%type <setRole> set_role_opt 520 %type <setDefaultRole> set_default_role_opt 521 %type <privilege> priv_elem 522 %type <privileges> priv_list 523 %type <objectType> object_type 524 %type <privilegeType> priv_type 525 %type <privilegeLevel> priv_level 526 %type <unresolveNames> column_name_list 527 %type <partitionOption> partition_by_opt 528 %type <clusterByOption> cluster_by_opt 529 %type <partitionBy> partition_method sub_partition_method sub_partition_opt 530 %type <windowSpec> window_spec_opt 531 %type <windowFrame> window_frame window_frame_opt 532 %type <windowFrameBound> window_frame_bound 533 %type <windowFrameUnit> window_frame_unit 534 %type <str> fields_or_columns 535 %type <int64Val> algorithm_opt partition_num_opt sub_partition_num_opt 536 %type <boolVal> linear_opt 537 %type <partition> partition 538 %type <partitions> partition_list_opt partition_list 539 %type <values> values_opt 540 %type <tableOptions> partition_option_list 541 %type <subPartition> sub_partition 542 %type <subPartitions> sub_partition_list sub_partition_list_opt 543 %type <subquery> subquery 544 545 %type <lengthOpt> length_opt length_option_opt length timestamp_option_opt 546 %type <lengthScaleOpt> float_length_opt decimal_length_opt 547 %type <unsignedOpt> unsigned_opt header_opt parallel_opt 548 %type <zeroFillOpt> zero_fill_opt 549 %type <boolVal> global_scope exists_opt distinct_opt temporary_opt 550 %type <item> pwd_expire clear_pwd_opt 551 %type <str> name_confict distinct_keyword separator_opt 552 %type <insert> insert_data 553 %type <replace> replace_data 554 %type <rowsExprs> values_list 555 %type <str> name_datetime_precision braces_opt name_braces 556 %type <str> std_dev_pop extended_opt 557 %type <expr> expr_or_default 558 %type <exprs> data_values data_opt row_value 559 560 %type <boolVal> local_opt 561 %type <duplicateKey> duplicate_opt 562 %type <fields> load_fields field_item export_fields 563 %type <fieldsList> field_item_list 564 %type <str> field_terminator starting_opt lines_terminated_opt starting lines_terminated 565 %type <lines> load_lines export_lines_opt 566 %type <int64Val> ignore_lines 567 %type <varExpr> user_variable variable system_variable 568 %type <varExprs> variable_list 569 %type <loadColumn> columns_or_variable 570 %type <loadColumns> columns_or_variable_list columns_or_variable_list_opt 571 %type <unresolvedName> normal_ident 572 %type <updateExpr> load_set_item 573 %type <updateExprs> load_set_list load_set_spec_opt 574 %type <strs> index_name_and_type_opt index_name_list 575 %type <str> index_name index_type key_or_index_opt key_or_index 576 // type <str> mo_keywords 577 %type <properties> properties_list 578 %type <property> property_elem 579 %type <assignments> set_value_list 580 %type <assignment> set_value 581 %type <str> row_opt substr_option 582 %type <str> time_unit time_stamp_unit 583 %type <whenClause> when_clause 584 %type <whenClauseList> when_clause_list 585 %type <withClause> with_clause 586 %type <cte> common_table_expr 587 %type <cteList> cte_list 588 589 %type <epxlainOptions> utility_option_list 590 %type <epxlainOption> utility_option_elem 591 %type <str> utility_option_name utility_option_arg 592 %type <str> explain_option_key select_option_opt 593 %type <str> explain_foramt_value trim_direction 594 %type <str> priority_opt priority quick_opt ignore_opt wild_opt 595 596 %type <str> account_name account_admin_name account_role_name 597 %type <accountAuthOption> account_auth_option 598 %type <alterAccountAuthOption> alter_account_auth_option 599 %type <accountIdentified> account_identified 600 %type <accountStatus> account_status_option 601 %type <accountComment> account_comment_opt 602 %type <accountCommentOrAttribute> user_comment_or_attribute_opt 603 %type <userIdentified> user_identified user_identified_opt 604 %type <accountRole> default_role_opt 605 606 %type <indexHintType> index_hint_type 607 %type <indexHintScope> index_hint_scope 608 %type <indexHint> index_hint 609 %type <indexHintList> index_hint_list index_hint_list_opt 610 611 %token <str> KILL 612 %type <killOption> kill_opt 613 %type <statementOption> statement_id_opt 614 %token <str> QUERY_RESULT 615 %start start_command 616 617 %type<tableLock> table_lock_elem 618 %type<tableLocks> table_lock_list 619 %type<tableLockType> table_lock_type 620 621 %% 622 623 start_command: 624 stmt_list 625 626 stmt_list: 627 stmt 628 { 629 if $1 != nil { 630 yylex.(*Lexer).AppendStmt($1) 631 } 632 } 633 | stmt_list ';' stmt 634 { 635 if $3 != nil { 636 yylex.(*Lexer).AppendStmt($3) 637 } 638 } 639 640 stmt: 641 create_stmt 642 | mo_dump_stmt 643 | insert_stmt 644 | replace_stmt 645 | delete_stmt 646 | drop_stmt 647 | truncate_table_stmt 648 | explain_stmt 649 | prepare_stmt 650 | deallocate_stmt 651 | reset_stmt 652 | execute_stmt 653 | show_stmt 654 | alter_stmt 655 | analyze_stmt 656 | update_stmt 657 | use_stmt 658 | transaction_stmt 659 | set_stmt 660 | lock_stmt 661 | revoke_stmt 662 | grant_stmt 663 | load_data_stmt 664 | import_data_stmt 665 | load_extension_stmt 666 | do_stmt 667 | declare_stmt 668 | values_stmt 669 | select_stmt 670 { 671 $$ = $1 672 } 673 | kill_stmt 674 | /* EMPTY */ 675 { 676 $$ = tree.Statement(nil) 677 } 678 679 kill_stmt: 680 KILL kill_opt INTEGRAL statement_id_opt 681 { 682 var connectionId uint64 683 switch v := $3.(type) { 684 case uint64: 685 connectionId = v 686 case int64: 687 connectionId = uint64(v) 688 default: 689 yylex.Error("parse integral fail") 690 return 1 691 } 692 693 $$ = &tree.Kill{ 694 Option: $2, 695 ConnectionId: connectionId, 696 StmtOption: $4, 697 } 698 } 699 700 kill_opt: 701 { 702 $$ = tree.KillOption{ 703 Exist: false, 704 } 705 } 706 | CONNECTION 707 { 708 $$ = tree.KillOption{ 709 Exist: true, 710 Typ: tree.KillTypeConnection, 711 } 712 } 713 | QUERY 714 { 715 $$ = tree.KillOption{ 716 Exist: true, 717 Typ: tree.KillTypeQuery, 718 } 719 } 720 721 statement_id_opt: 722 { 723 $$ = tree.StatementOption{ 724 Exist: false, 725 } 726 } 727 | STRING 728 { 729 $$ = tree.StatementOption{ 730 Exist: true, 731 StatementId: $1, 732 } 733 } 734 735 mo_dump_stmt: 736 MODUMP DATABASE database_id INTO STRING max_file_size_opt 737 { 738 $$ = &tree.MoDump{ 739 DumpDatabase: true, 740 Database: tree.Identifier($3), 741 OutFile: $5, 742 MaxFileSize: int64($6), 743 } 744 } 745 | MODUMP DATABASE database_id TABLES table_name_list INTO STRING max_file_size_opt 746 { 747 $$ = &tree.MoDump{ 748 DumpDatabase: true, 749 Database: tree.Identifier($3), 750 Tables: $5, 751 OutFile: $7, 752 MaxFileSize: int64($8), 753 } 754 } 755 | MODUMP QUERY_RESULT STRING INTO STRING export_fields export_lines_opt header_opt max_file_size_opt force_quote_opt 756 { 757 ep := &tree.ExportParam{ 758 Outfile: true, 759 QueryId: $3, 760 FilePath : $5, 761 Fields: $6, 762 Lines: $7, 763 Header: $8, 764 MaxFileSize:uint64($9)*1024, 765 ForceQuote: $10, 766 } 767 $$ = &tree.MoDump{ 768 DumpDatabase: false, 769 ExportParams: ep, 770 } 771 } 772 773 774 775 import_data_stmt: 776 IMPORT DATA local_opt load_param_opt duplicate_opt INTO TABLE table_name tail_param_opt 777 { 778 $$ = &tree.Import{ 779 Local: $3, 780 Param: $4, 781 DuplicateHandling: $5, 782 Table: $8, 783 } 784 $$.(*tree.Import).Param.Tail = $9 785 } 786 787 load_data_stmt: 788 LOAD DATA local_opt load_param_opt duplicate_opt INTO TABLE table_name accounts_opt tail_param_opt parallel_opt 789 { 790 $$ = &tree.Load{ 791 Local: $3, 792 Param: $4, 793 DuplicateHandling: $5, 794 Table: $8, 795 Accounts: $9, 796 } 797 $$.(*tree.Load).Param.Tail = $10 798 $$.(*tree.Load).Param.Parallel = $11 799 } 800 801 load_extension_stmt: 802 LOAD extension_name 803 { 804 $$ = &tree.LoadExtension{ 805 Name: tree.Identifier($2), 806 } 807 } 808 809 load_set_spec_opt: 810 { 811 $$ = nil 812 } 813 | SET load_set_list 814 { 815 $$ = $2 816 } 817 818 load_set_list: 819 load_set_item 820 { 821 $$ = tree.UpdateExprs{$1} 822 } 823 | load_set_list ',' load_set_item 824 { 825 $$ = append($1, $3) 826 } 827 828 load_set_item: 829 normal_ident '=' DEFAULT 830 { 831 $$ = &tree.UpdateExpr{ 832 Names: []*tree.UnresolvedName{$1}, 833 Expr: &tree.DefaultVal{}, 834 } 835 } 836 | normal_ident '=' expression 837 { 838 $$ = &tree.UpdateExpr{ 839 Names: []*tree.UnresolvedName{$1}, 840 Expr: $3, 841 } 842 } 843 844 parallel_opt: 845 { 846 $$ = false 847 } 848 | PARALLEL STRING 849 { 850 str := strings.ToLower($2) 851 if str == "true" { 852 $$ = true 853 } else if str == "false" { 854 $$ = false 855 } else { 856 yylex.Error("error parallel flag") 857 return 1 858 } 859 } 860 861 normal_ident: 862 ident 863 { 864 $$ = tree.SetUnresolvedName($1) 865 } 866 | ident '.' ident 867 { 868 $$ = tree.SetUnresolvedName($1, $3) 869 } 870 | ident '.' ident '.' ident 871 { 872 $$ = tree.SetUnresolvedName($1, $3, $5) 873 } 874 875 columns_or_variable_list_opt: 876 { 877 $$ = nil 878 } 879 | '(' ')' 880 { 881 $$ = nil 882 } 883 | '(' columns_or_variable_list ')' 884 { 885 $$ = $2 886 } 887 888 columns_or_variable_list: 889 columns_or_variable 890 { 891 switch $1.(type) { 892 case *tree.UnresolvedName: 893 $$ = []tree.LoadColumn{$1.(*tree.UnresolvedName)} 894 case *tree.VarExpr: 895 $$ = []tree.LoadColumn{$1.(*tree.VarExpr)} 896 } 897 } 898 | columns_or_variable_list ',' columns_or_variable 899 { 900 switch $3.(type) { 901 case *tree.UnresolvedName: 902 $$ = append($1, $3.(*tree.UnresolvedName)) 903 case *tree.VarExpr: 904 $$ = append($1, $3.(*tree.VarExpr)) 905 } 906 } 907 908 columns_or_variable: 909 column_name_unresolved 910 { 911 $$ = $1 912 } 913 | user_variable 914 { 915 $$ = $1 916 } 917 918 variable_list: 919 variable 920 { 921 $$ = []*tree.VarExpr{$1} 922 } 923 | variable_list ',' variable 924 { 925 $$ = append($1, $3) 926 } 927 928 variable: 929 system_variable 930 { 931 $$ = $1 932 } 933 | user_variable 934 { 935 $$ = $1 936 } 937 938 system_variable: 939 AT_AT_ID 940 { 941 vs := strings.Split($1, ".") 942 var isGlobal bool 943 if strings.ToLower(vs[0]) == "global" { 944 isGlobal = true 945 } 946 var r string 947 if len(vs) == 2 { 948 r = vs[1] 949 } else if len(vs) == 1 { 950 r = vs[0] 951 } else { 952 yylex.Error("variable syntax error") 953 return 1 954 } 955 $$ = &tree.VarExpr{ 956 Name: r, 957 System: true, 958 Global: isGlobal, 959 } 960 } 961 962 user_variable: 963 AT_ID 964 { 965 // vs := strings.Split($1, ".") 966 // var r string 967 // if len(vs) == 2 { 968 // r = vs[1] 969 // } else if len(vs) == 1 { 970 // r = vs[0] 971 // } else { 972 // yylex.Error("variable syntax error") 973 // return 1 974 // } 975 $$ = &tree.VarExpr{ 976 Name: $1, 977 System: false, 978 Global: false, 979 } 980 } 981 982 ignore_lines: 983 { 984 $$ = 0 985 } 986 | IGNORE INTEGRAL LINES 987 { 988 $$ = $2.(int64) 989 } 990 | IGNORE INTEGRAL ROWS 991 { 992 $$ = $2.(int64) 993 } 994 995 load_lines: 996 { 997 $$ = nil 998 } 999 | LINES starting lines_terminated_opt 1000 { 1001 $$ = &tree.Lines{ 1002 StartingBy: $2, 1003 TerminatedBy: $3, 1004 } 1005 } 1006 | LINES lines_terminated starting_opt 1007 { 1008 $$ = &tree.Lines{ 1009 StartingBy: $3, 1010 TerminatedBy: $2, 1011 } 1012 } 1013 1014 starting_opt: 1015 { 1016 $$ = "" 1017 } 1018 | starting 1019 1020 starting: 1021 STARTING BY STRING 1022 { 1023 $$ = $3 1024 } 1025 1026 lines_terminated_opt: 1027 { 1028 $$ = "\n" 1029 } 1030 | lines_terminated 1031 1032 lines_terminated: 1033 TERMINATED BY STRING 1034 { 1035 $$ = $3 1036 } 1037 1038 load_fields: 1039 { 1040 $$ = nil 1041 } 1042 | fields_or_columns field_item_list 1043 { 1044 res := &tree.Fields{ 1045 Terminated: "\t", 1046 EscapedBy: 0, 1047 } 1048 for _, f := range $2 { 1049 if f.Terminated != "" { 1050 res.Terminated = f.Terminated 1051 } 1052 if f.Optionally { 1053 res.Optionally = f.Optionally 1054 } 1055 if f.EnclosedBy != 0 { 1056 res.EnclosedBy = f.EnclosedBy 1057 } 1058 if f.EscapedBy != 0 { 1059 res.EscapedBy = f.EscapedBy 1060 } 1061 } 1062 $$ = res 1063 } 1064 1065 field_item_list: 1066 field_item 1067 { 1068 $$ = []*tree.Fields{$1} 1069 } 1070 | field_item_list field_item 1071 { 1072 $$ = append($1, $2) 1073 } 1074 1075 field_item: 1076 TERMINATED BY field_terminator 1077 { 1078 $$ = &tree.Fields{ 1079 Terminated: $3, 1080 } 1081 } 1082 | OPTIONALLY ENCLOSED BY field_terminator 1083 { 1084 str := $4 1085 if str != "\\" && len(str) > 1 { 1086 yylex.Error("error field terminator") 1087 return 1 1088 } 1089 var b byte 1090 if len(str) != 0 { 1091 b = byte(str[0]) 1092 } else { 1093 b = 0 1094 } 1095 $$ = &tree.Fields{ 1096 Optionally: true, 1097 EnclosedBy: b, 1098 } 1099 } 1100 | ENCLOSED BY field_terminator 1101 { 1102 str := $3 1103 if str != "\\" && len(str) > 1 { 1104 yylex.Error("error field terminator") 1105 return 1 1106 } 1107 var b byte 1108 if len(str) != 0 { 1109 b = byte(str[0]) 1110 } else { 1111 b = 0 1112 } 1113 $$ = &tree.Fields{ 1114 EnclosedBy: b, 1115 } 1116 } 1117 | ESCAPED BY field_terminator 1118 { 1119 str := $3 1120 if str != "\\" && len(str) > 1 { 1121 yylex.Error("error field terminator") 1122 return 1 1123 } 1124 var b byte 1125 if len(str) != 0 { 1126 b = byte(str[0]) 1127 } else { 1128 b = 0 1129 } 1130 $$ = &tree.Fields{ 1131 EscapedBy: b, 1132 } 1133 } 1134 1135 field_terminator: 1136 STRING 1137 // | HEXNUM 1138 // | BIT_LITERAL 1139 1140 duplicate_opt: 1141 { 1142 $$ = &tree.DuplicateKeyError{} 1143 } 1144 | IGNORE 1145 { 1146 $$ = &tree.DuplicateKeyIgnore{} 1147 } 1148 | REPLACE 1149 { 1150 $$ = &tree.DuplicateKeyReplace{} 1151 } 1152 1153 local_opt: 1154 { 1155 $$ = false 1156 } 1157 | LOCAL 1158 { 1159 $$ = true 1160 } 1161 1162 grant_stmt: 1163 GRANT priv_list ON object_type priv_level TO role_spec_list grant_option_opt 1164 { 1165 $$ = &tree.Grant{ 1166 Typ: tree.GrantTypePrivilege, 1167 GrantPrivilege: tree.GrantPrivilege{ 1168 Privileges: $2, 1169 ObjType: $4, 1170 Level: $5, 1171 Roles: $7, 1172 GrantOption: $8, 1173 }, 1174 } 1175 } 1176 | GRANT role_spec_list TO drop_user_spec_list grant_option_opt 1177 { 1178 $$ = &tree.Grant{ 1179 Typ: tree.GrantTypeRole, 1180 GrantRole:tree.GrantRole{ 1181 Roles: $2, 1182 Users: $4, 1183 GrantOption: $5, 1184 }, 1185 } 1186 } 1187 | GRANT PROXY ON user_spec TO user_spec_list grant_option_opt 1188 { 1189 $$ = &tree.Grant{ 1190 Typ: tree.GrantTypeProxy, 1191 GrantProxy:tree.GrantProxy{ 1192 ProxyUser: $4, 1193 Users: $6, 1194 GrantOption: $7, 1195 }, 1196 } 1197 1198 } 1199 1200 grant_option_opt: 1201 { 1202 $$ = false 1203 } 1204 | WITH GRANT OPTION 1205 { 1206 $$ = true 1207 } 1208 // | WITH MAX_QUERIES_PER_HOUR INTEGRAL 1209 // | WITH MAX_UPDATES_PER_HOUR INTEGRAL 1210 // | WITH MAX_CONNECTIONS_PER_HOUR INTEGRAL 1211 // | WITH MAX_USER_CONNECTIONS INTEGRAL 1212 1213 revoke_stmt: 1214 REVOKE exists_opt priv_list ON object_type priv_level FROM role_spec_list 1215 { 1216 $$ = &tree.Revoke{ 1217 Typ: tree.RevokeTypePrivilege, 1218 RevokePrivilege: tree.RevokePrivilege{ 1219 IfExists: $2, 1220 Privileges: $3, 1221 ObjType: $5, 1222 Level: $6, 1223 Roles: $8, 1224 }, 1225 } 1226 } 1227 | REVOKE exists_opt role_spec_list FROM user_spec_list 1228 { 1229 $$ = &tree.Revoke{ 1230 Typ: tree.RevokeTypeRole, 1231 RevokeRole: tree.RevokeRole{ 1232 IfExists: $2, 1233 Roles: $3, 1234 Users: $5, 1235 }, 1236 } 1237 } 1238 1239 priv_level: 1240 '*' 1241 { 1242 $$ = &tree.PrivilegeLevel{ 1243 Level: tree.PRIVILEGE_LEVEL_TYPE_STAR, 1244 } 1245 } 1246 | '*' '.' '*' 1247 { 1248 $$ = &tree.PrivilegeLevel{ 1249 Level: tree.PRIVILEGE_LEVEL_TYPE_STAR_STAR, 1250 } 1251 } 1252 | ID '.' '*' 1253 { 1254 $$ = &tree.PrivilegeLevel{ 1255 Level: tree.PRIVILEGE_LEVEL_TYPE_DATABASE_STAR, 1256 DbName: $1, 1257 } 1258 } 1259 | ID '.' ID 1260 { 1261 $$ = &tree.PrivilegeLevel{ 1262 Level: tree.PRIVILEGE_LEVEL_TYPE_DATABASE_TABLE, 1263 DbName: $1, 1264 TabName: $3, 1265 } 1266 } 1267 | ID 1268 { 1269 $$ = &tree.PrivilegeLevel{ 1270 Level: tree.PRIVILEGE_LEVEL_TYPE_TABLE, 1271 TabName: $1, 1272 } 1273 } 1274 1275 object_type: 1276 TABLE 1277 { 1278 $$ = tree.OBJECT_TYPE_TABLE 1279 } 1280 | DATABASE 1281 { 1282 $$ = tree.OBJECT_TYPE_DATABASE 1283 } 1284 | FUNCTION 1285 { 1286 $$ = tree.OBJECT_TYPE_FUNCTION 1287 } 1288 | PROCEDURE 1289 { 1290 $$ = tree.OBJECT_TYPE_PROCEDURE 1291 } 1292 | VIEW 1293 { 1294 $$ = tree.OBJECT_TYPE_VIEW 1295 } 1296 | ACCOUNT 1297 { 1298 $$ = tree.OBJECT_TYPE_ACCOUNT 1299 } 1300 1301 1302 priv_list: 1303 priv_elem 1304 { 1305 $$ = []*tree.Privilege{$1} 1306 } 1307 | priv_list ',' priv_elem 1308 { 1309 $$ = append($1, $3) 1310 } 1311 1312 priv_elem: 1313 priv_type 1314 { 1315 $$ = &tree.Privilege{ 1316 Type: $1, 1317 ColumnList: nil, 1318 } 1319 } 1320 | priv_type '(' column_name_list ')' 1321 { 1322 $$ = &tree.Privilege{ 1323 Type: $1, 1324 ColumnList: $3, 1325 } 1326 } 1327 1328 column_name_list: 1329 column_name 1330 { 1331 $$ = []*tree.UnresolvedName{$1} 1332 } 1333 | column_name_list ',' column_name 1334 { 1335 $$ = append($1, $3) 1336 } 1337 1338 priv_type: 1339 ALL 1340 { 1341 $$ = tree.PRIVILEGE_TYPE_STATIC_ALL 1342 } 1343 | CREATE ACCOUNT 1344 { 1345 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_ACCOUNT 1346 } 1347 | DROP ACCOUNT 1348 { 1349 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_ACCOUNT 1350 } 1351 | ALTER ACCOUNT 1352 { 1353 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_ACCOUNT 1354 } 1355 | ALL PRIVILEGES 1356 { 1357 $$ = tree.PRIVILEGE_TYPE_STATIC_ALL 1358 } 1359 | ALTER TABLE 1360 { 1361 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_TABLE 1362 } 1363 | ALTER VIEW 1364 { 1365 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_VIEW 1366 } 1367 | CREATE 1368 { 1369 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE 1370 } 1371 | CREATE USER 1372 { 1373 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_USER 1374 } 1375 | DROP USER 1376 { 1377 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_USER 1378 } 1379 | ALTER USER 1380 { 1381 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_USER 1382 } 1383 | CREATE TABLESPACE 1384 { 1385 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_TABLESPACE 1386 } 1387 | TRIGGER 1388 { 1389 $$ = tree.PRIVILEGE_TYPE_STATIC_TRIGGER 1390 } 1391 | DELETE 1392 { 1393 $$ = tree.PRIVILEGE_TYPE_STATIC_DELETE 1394 } 1395 | DROP TABLE 1396 { 1397 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_TABLE 1398 } 1399 | DROP VIEW 1400 { 1401 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_VIEW 1402 } 1403 | EXECUTE 1404 { 1405 $$ = tree.PRIVILEGE_TYPE_STATIC_EXECUTE 1406 } 1407 | INDEX 1408 { 1409 $$ = tree.PRIVILEGE_TYPE_STATIC_INDEX 1410 } 1411 | INSERT 1412 { 1413 $$ = tree.PRIVILEGE_TYPE_STATIC_INSERT 1414 } 1415 | SELECT 1416 { 1417 $$ = tree.PRIVILEGE_TYPE_STATIC_SELECT 1418 } 1419 | SUPER 1420 { 1421 $$ = tree.PRIVILEGE_TYPE_STATIC_SUPER 1422 } 1423 | CREATE DATABASE 1424 { 1425 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_DATABASE 1426 } 1427 | DROP DATABASE 1428 { 1429 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_DATABASE 1430 } 1431 | SHOW DATABASES 1432 { 1433 $$ = tree.PRIVILEGE_TYPE_STATIC_SHOW_DATABASES 1434 } 1435 | CONNECT 1436 { 1437 $$ = tree.PRIVILEGE_TYPE_STATIC_CONNECT 1438 } 1439 | MANAGE GRANTS 1440 { 1441 $$ = tree.PRIVILEGE_TYPE_STATIC_MANAGE_GRANTS 1442 } 1443 | OWNERSHIP 1444 { 1445 $$ = tree.PRIVILEGE_TYPE_STATIC_OWNERSHIP 1446 } 1447 | SHOW TABLES 1448 { 1449 $$ = tree.PRIVILEGE_TYPE_STATIC_SHOW_TABLES 1450 } 1451 | CREATE TABLE 1452 { 1453 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_TABLE 1454 } 1455 | UPDATE 1456 { 1457 $$ = tree.PRIVILEGE_TYPE_STATIC_UPDATE 1458 } 1459 | GRANT OPTION 1460 { 1461 $$ = tree.PRIVILEGE_TYPE_STATIC_GRANT_OPTION 1462 } 1463 | REFERENCES 1464 { 1465 $$ = tree.PRIVILEGE_TYPE_STATIC_REFERENCES 1466 } 1467 | REFERENCE 1468 { 1469 $$ = tree.PRIVILEGE_TYPE_STATIC_REFERENCE 1470 } 1471 | REPLICATION SLAVE 1472 { 1473 $$ = tree.PRIVILEGE_TYPE_STATIC_REPLICATION_SLAVE 1474 } 1475 | REPLICATION CLIENT 1476 { 1477 $$ = tree.PRIVILEGE_TYPE_STATIC_REPLICATION_CLIENT 1478 } 1479 | USAGE 1480 { 1481 $$ = tree.PRIVILEGE_TYPE_STATIC_USAGE 1482 } 1483 | RELOAD 1484 { 1485 $$ = tree.PRIVILEGE_TYPE_STATIC_RELOAD 1486 } 1487 | FILE 1488 { 1489 $$ = tree.PRIVILEGE_TYPE_STATIC_FILE 1490 } 1491 | CREATE TEMPORARY TABLES 1492 { 1493 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_TEMPORARY_TABLES 1494 } 1495 | LOCK TABLES 1496 { 1497 $$ = tree.PRIVILEGE_TYPE_STATIC_LOCK_TABLES 1498 } 1499 | CREATE VIEW 1500 { 1501 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_VIEW 1502 } 1503 | SHOW VIEW 1504 { 1505 $$ = tree.PRIVILEGE_TYPE_STATIC_SHOW_VIEW 1506 } 1507 | CREATE ROLE 1508 { 1509 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_ROLE 1510 } 1511 | DROP ROLE 1512 { 1513 $$ = tree.PRIVILEGE_TYPE_STATIC_DROP_ROLE 1514 } 1515 | ALTER ROLE 1516 { 1517 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_ROLE 1518 } 1519 | CREATE ROUTINE 1520 { 1521 $$ = tree.PRIVILEGE_TYPE_STATIC_CREATE_ROUTINE 1522 } 1523 | ALTER ROUTINE 1524 { 1525 $$ = tree.PRIVILEGE_TYPE_STATIC_ALTER_ROUTINE 1526 } 1527 | EVENT 1528 { 1529 $$ = tree.PRIVILEGE_TYPE_STATIC_EVENT 1530 } 1531 | SHUTDOWN 1532 { 1533 $$ = tree.PRIVILEGE_TYPE_STATIC_SHUTDOWN 1534 } 1535 | TRUNCATE 1536 { 1537 $$ = tree.PRIVILEGE_TYPE_STATIC_TRUNCATE 1538 } 1539 1540 set_stmt: 1541 set_variable_stmt 1542 | set_password_stmt 1543 | set_role_stmt 1544 | set_default_role_stmt 1545 1546 set_role_stmt: 1547 SET ROLE role_spec 1548 { 1549 $$ = &tree.SetRole{ 1550 SecondaryRole: false, 1551 Role: $3, 1552 } 1553 } 1554 | SET SECONDARY ROLE ALL 1555 { 1556 $$ = &tree.SetRole{ 1557 SecondaryRole: true, 1558 SecondaryRoleType: tree.SecondaryRoleTypeAll, 1559 } 1560 } 1561 | SET SECONDARY ROLE NONE 1562 { 1563 $$ = &tree.SetRole{ 1564 SecondaryRole: true, 1565 SecondaryRoleType: tree.SecondaryRoleTypeNone, 1566 } 1567 } 1568 1569 set_default_role_stmt: 1570 SET DEFAULT ROLE set_default_role_opt TO user_spec_list 1571 { 1572 dr := $4 1573 dr.Users = $6 1574 $$ = dr 1575 } 1576 1577 //set_role_opt: 1578 // ALL EXCEPT role_spec_list 1579 // { 1580 // $$ = &tree.SetRole{Type: tree.SET_ROLE_TYPE_ALL_EXCEPT, Roles: $3} 1581 // } 1582 //| DEFAULT 1583 // { 1584 // $$ = &tree.SetRole{Type: tree.SET_ROLE_TYPE_DEFAULT, Roles: nil} 1585 // } 1586 //| NONE 1587 // { 1588 // $$ = &tree.SetRole{Type: tree.SET_ROLE_TYPE_NONE, Roles: nil} 1589 // } 1590 //| ALL 1591 // { 1592 // $$ = &tree.SetRole{Type: tree.SET_ROLE_TYPE_ALL, Roles: nil} 1593 // } 1594 //| role_spec_list 1595 // { 1596 // $$ = &tree.SetRole{Type: tree.SET_ROLE_TYPE_NORMAL, Roles: $1} 1597 // } 1598 1599 set_default_role_opt: 1600 NONE 1601 { 1602 $$ = &tree.SetDefaultRole{Type: tree.SET_DEFAULT_ROLE_TYPE_NONE, Roles: nil} 1603 } 1604 | ALL 1605 { 1606 $$ = &tree.SetDefaultRole{Type: tree.SET_DEFAULT_ROLE_TYPE_ALL, Roles: nil} 1607 } 1608 | role_spec_list 1609 { 1610 $$ = &tree.SetDefaultRole{Type: tree.SET_DEFAULT_ROLE_TYPE_NORMAL, Roles: $1} 1611 } 1612 1613 set_variable_stmt: 1614 SET var_assignment_list 1615 { 1616 $$ = &tree.SetVar{Assignments: $2} 1617 } 1618 1619 set_password_stmt: 1620 SET PASSWORD '=' password_opt 1621 { 1622 $$ = &tree.SetPassword{Password: $4} 1623 } 1624 | SET PASSWORD FOR user_spec '=' password_opt 1625 { 1626 $$ = &tree.SetPassword{User: $4, Password: $6} 1627 } 1628 1629 password_opt: 1630 STRING 1631 | PASSWORD '(' auth_string ')' 1632 { 1633 $$ = $3 1634 } 1635 1636 var_assignment_list: 1637 var_assignment 1638 { 1639 $$ = []*tree.VarAssignmentExpr{$1} 1640 } 1641 | var_assignment_list ',' var_assignment 1642 { 1643 $$ = append($1, $3) 1644 } 1645 1646 var_assignment: 1647 var_name equal_or_assignment set_expr 1648 { 1649 $$ = &tree.VarAssignmentExpr{ 1650 System: true, 1651 Name: $1, 1652 Value: $3, 1653 } 1654 } 1655 | GLOBAL var_name equal_or_assignment set_expr 1656 { 1657 $$ = &tree.VarAssignmentExpr{ 1658 System: true, 1659 Global: true, 1660 Name: $2, 1661 Value: $4, 1662 } 1663 } 1664 | SESSION var_name equal_or_assignment set_expr 1665 { 1666 $$ = &tree.VarAssignmentExpr{ 1667 System: true, 1668 Name: $2, 1669 Value: $4, 1670 } 1671 } 1672 | LOCAL var_name equal_or_assignment set_expr 1673 { 1674 $$ = &tree.VarAssignmentExpr{ 1675 System: true, 1676 Name: $2, 1677 Value: $4, 1678 } 1679 } 1680 | AT_ID equal_or_assignment set_expr 1681 { 1682 vs := strings.Split($1, ".") 1683 var isGlobal bool 1684 if strings.ToLower(vs[0]) == "global" { 1685 isGlobal = true 1686 } 1687 var r string 1688 if len(vs) == 2 { 1689 r = vs[1] 1690 } else if len(vs) == 1{ 1691 r = vs[0] 1692 } else { 1693 yylex.Error("variable syntax error") 1694 return 1 1695 } 1696 $$ = &tree.VarAssignmentExpr{ 1697 System: false, 1698 Global: isGlobal, 1699 Name: r, 1700 Value: $3, 1701 } 1702 } 1703 | AT_AT_ID equal_or_assignment set_expr 1704 { 1705 vs := strings.Split($1, ".") 1706 var isGlobal bool 1707 if strings.ToLower(vs[0]) == "global" { 1708 isGlobal = true 1709 } 1710 var r string 1711 if len(vs) == 2 { 1712 r = vs[1] 1713 } else if len(vs) == 1{ 1714 r = vs[0] 1715 } else { 1716 yylex.Error("variable syntax error") 1717 return 1 1718 } 1719 $$ = &tree.VarAssignmentExpr{ 1720 System: true, 1721 Global: isGlobal, 1722 Name: r, 1723 Value: $3, 1724 } 1725 } 1726 | NAMES charset_name 1727 { 1728 $$ = &tree.VarAssignmentExpr{ 1729 Name: $1, 1730 Value: tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char), 1731 } 1732 } 1733 | NAMES charset_name COLLATE DEFAULT 1734 { 1735 $$ = &tree.VarAssignmentExpr{ 1736 Name: $1, 1737 Value: tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char), 1738 } 1739 } 1740 | NAMES charset_name COLLATE name_string 1741 { 1742 $$ = &tree.VarAssignmentExpr{ 1743 Name: $1, 1744 Value: tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char), 1745 Reserved: tree.NewNumValWithType(constant.MakeString($4), $4, false, tree.P_char), 1746 } 1747 } 1748 | NAMES DEFAULT 1749 { 1750 $$ = &tree.VarAssignmentExpr{ 1751 Name: $1, 1752 Value: &tree.DefaultVal{}, 1753 } 1754 } 1755 | charset_keyword charset_name 1756 { 1757 $$ = &tree.VarAssignmentExpr{ 1758 Name: $1, 1759 Value: tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char), 1760 } 1761 } 1762 | charset_keyword DEFAULT 1763 { 1764 $$ = &tree.VarAssignmentExpr{ 1765 Name: $1, 1766 Value: &tree.DefaultVal{}, 1767 } 1768 } 1769 1770 set_expr: 1771 ON 1772 { 1773 $$ = tree.NewNumValWithType(constant.MakeString($1), $1, false, tree.P_char) 1774 } 1775 | BINARY 1776 { 1777 $$ = tree.NewNumValWithType(constant.MakeString($1), $1, false, tree.P_char) 1778 } 1779 | expr_or_default 1780 { 1781 $$ = $1 1782 } 1783 1784 equal_or_assignment: 1785 '=' 1786 { 1787 $$ = string($1) 1788 } 1789 | ASSIGNMENT 1790 { 1791 $$ = $1 1792 } 1793 1794 var_name: 1795 ident 1796 | ident '.' ident 1797 { 1798 $$ = $1 + "." + $3 1799 } 1800 1801 var_name_list: 1802 var_name 1803 { 1804 $$ = []string{$1} 1805 } 1806 | var_name_list ',' var_name 1807 { 1808 $$ = append($1, $3) 1809 } 1810 1811 transaction_stmt: 1812 begin_stmt 1813 | commit_stmt 1814 | rollback_stmt 1815 1816 rollback_stmt: 1817 ROLLBACK completion_type 1818 { 1819 $$ = &tree.RollbackTransaction{Type: $2} 1820 } 1821 1822 commit_stmt: 1823 COMMIT completion_type 1824 { 1825 $$ = &tree.CommitTransaction{Type: $2} 1826 } 1827 1828 completion_type: 1829 { 1830 $$ = tree.COMPLETION_TYPE_NO_CHAIN 1831 } 1832 | WORK 1833 { 1834 $$ = tree.COMPLETION_TYPE_NO_CHAIN 1835 } 1836 | AND CHAIN NO RELEASE 1837 { 1838 $$ = tree.COMPLETION_TYPE_CHAIN 1839 } 1840 | AND CHAIN 1841 { 1842 $$ = tree.COMPLETION_TYPE_CHAIN 1843 } 1844 | AND NO CHAIN RELEASE 1845 { 1846 $$ = tree.COMPLETION_TYPE_RELEASE 1847 } 1848 | RELEASE 1849 { 1850 $$ = tree.COMPLETION_TYPE_RELEASE 1851 } 1852 | AND NO CHAIN NO RELEASE 1853 { 1854 $$ = tree.COMPLETION_TYPE_NO_CHAIN 1855 } 1856 | AND NO CHAIN 1857 { 1858 $$ = tree.COMPLETION_TYPE_NO_CHAIN 1859 } 1860 | NO RELEASE 1861 { 1862 $$ = tree.COMPLETION_TYPE_NO_CHAIN 1863 } 1864 1865 begin_stmt: 1866 BEGIN 1867 { 1868 $$ = &tree.BeginTransaction{} 1869 } 1870 | BEGIN WORK 1871 { 1872 $$ = &tree.BeginTransaction{} 1873 } 1874 | START TRANSACTION 1875 { 1876 $$ = &tree.BeginTransaction{} 1877 } 1878 | START TRANSACTION READ WRITE 1879 { 1880 m := tree.MakeTransactionModes(tree.READ_WRITE_MODE_READ_WRITE) 1881 $$ = &tree.BeginTransaction{Modes: m} 1882 } 1883 | START TRANSACTION READ ONLY 1884 { 1885 m := tree.MakeTransactionModes(tree.READ_WRITE_MODE_READ_ONLY) 1886 $$ = &tree.BeginTransaction{Modes: m} 1887 } 1888 | START TRANSACTION WITH CONSISTENT SNAPSHOT 1889 { 1890 $$ = &tree.BeginTransaction{} 1891 } 1892 1893 use_stmt: 1894 USE ident 1895 { 1896 $$ = &tree.Use{ 1897 SecondaryRole: false, 1898 Name: $2, 1899 } 1900 } 1901 | USE 1902 { 1903 $$ = &tree.Use{ 1904 SecondaryRole: false, 1905 } 1906 } 1907 | USE ROLE role_spec 1908 { 1909 $$ = &tree.Use{ 1910 SecondaryRole: false, 1911 Role: $3, 1912 } 1913 } 1914 | USE SECONDARY ROLE ALL 1915 { 1916 $$ = &tree.Use{ 1917 SecondaryRole: true, 1918 SecondaryRoleType: tree.SecondaryRoleTypeAll, 1919 } 1920 } 1921 | USE SECONDARY ROLE NONE 1922 { 1923 $$ = &tree.Use{ 1924 SecondaryRole: true, 1925 SecondaryRoleType: tree.SecondaryRoleTypeNone, 1926 } 1927 } 1928 1929 update_stmt: 1930 update_no_with_stmt 1931 | with_clause update_no_with_stmt 1932 { 1933 $2.(*tree.Update).With = $1 1934 $$ = $2 1935 } 1936 1937 update_no_with_stmt: 1938 UPDATE priority_opt ignore_opt table_reference SET update_list where_expression_opt order_by_opt limit_opt 1939 { 1940 // Single-table syntax 1941 $$ = &tree.Update{ 1942 Tables: tree.TableExprs{$4}, 1943 Exprs: $6, 1944 Where: $7, 1945 OrderBy: $8, 1946 Limit: $9, 1947 } 1948 } 1949 | UPDATE priority_opt ignore_opt table_references SET update_list where_expression_opt 1950 { 1951 // Multiple-table syntax 1952 $$ = &tree.Update{ 1953 Tables: tree.TableExprs{$4}, 1954 Exprs: $6, 1955 Where: $7, 1956 } 1957 } 1958 1959 update_list: 1960 update_value 1961 { 1962 $$ = tree.UpdateExprs{$1} 1963 } 1964 | update_list ',' update_value 1965 { 1966 $$ = append($1, $3) 1967 } 1968 1969 update_value: 1970 column_name '=' expr_or_default 1971 { 1972 $$ = &tree.UpdateExpr{Names: []*tree.UnresolvedName{$1}, Expr: $3} 1973 } 1974 1975 lock_stmt: 1976 lock_table_stmt 1977 | unlock_table_stmt 1978 1979 lock_table_stmt: 1980 LOCK TABLES table_lock_list 1981 { 1982 $$ = &tree.LockTableStmt{TableLocks:$3} 1983 } 1984 1985 table_lock_list: 1986 table_lock_elem 1987 { 1988 $$ = []tree.TableLock{$1} 1989 } 1990 | table_lock_list ',' table_lock_elem 1991 { 1992 $$ = append($1, $3); 1993 } 1994 1995 table_lock_elem: 1996 table_name table_lock_type 1997 { 1998 $$ = tree.TableLock{$1, $2} 1999 } 2000 2001 table_lock_type: 2002 READ 2003 { 2004 $$ = tree.TableLockRead 2005 } 2006 | READ LOCAL 2007 { 2008 $$ = tree.TableLockReadLocal 2009 } 2010 | WRITE 2011 { 2012 $$ = tree.TableLockWrite 2013 } 2014 | LOW_PRIORITY WRITE 2015 { 2016 $$ = tree.TableLockLowPriorityWrite 2017 } 2018 2019 unlock_table_stmt: 2020 UNLOCK TABLES 2021 { 2022 $$ = &tree.UnLockTableStmt{} 2023 } 2024 2025 prepareable_stmt: 2026 create_stmt 2027 | insert_stmt 2028 | delete_stmt 2029 | drop_stmt 2030 | show_stmt 2031 | update_stmt 2032 | select_stmt 2033 { 2034 $$ = $1 2035 } 2036 2037 prepare_stmt: 2038 prepare_sym stmt_name FROM prepareable_stmt 2039 { 2040 $$ = tree.NewPrepareStmt(tree.Identifier($2), $4) 2041 } 2042 | prepare_sym stmt_name FROM STRING 2043 { 2044 $$ = tree.NewPrepareString(tree.Identifier($2), $4) 2045 } 2046 2047 execute_stmt: 2048 execute_sym stmt_name 2049 { 2050 $$ = tree.NewExecute(tree.Identifier($2)) 2051 } 2052 | execute_sym stmt_name USING variable_list 2053 { 2054 $$ = tree.NewExecuteWithVariables(tree.Identifier($2), $4) 2055 } 2056 2057 deallocate_stmt: 2058 deallocate_sym PREPARE stmt_name 2059 { 2060 $$ = tree.NewDeallocate(tree.Identifier($3), false) 2061 } 2062 2063 reset_stmt: 2064 reset_sym PREPARE stmt_name 2065 { 2066 $$ = tree.NewReset(tree.Identifier($3)) 2067 } 2068 2069 explainable_stmt: 2070 delete_stmt 2071 | insert_stmt 2072 | replace_stmt 2073 | update_stmt 2074 | select_stmt 2075 { 2076 $$ = $1 2077 } 2078 2079 explain_stmt: 2080 explain_sym unresolved_object_name 2081 { 2082 $$ = &tree.ShowColumns{Table: $2} 2083 } 2084 | explain_sym unresolved_object_name column_name 2085 { 2086 $$ = &tree.ShowColumns{Table: $2, ColName: $3} 2087 } 2088 | explain_sym FOR CONNECTION INTEGRAL 2089 { 2090 $$ = tree.NewExplainFor("", uint64($4.(int64))) 2091 } 2092 | explain_sym FORMAT '=' STRING FOR CONNECTION INTEGRAL 2093 { 2094 $$ = tree.NewExplainFor($4, uint64($7.(int64))) 2095 } 2096 | explain_sym explainable_stmt 2097 { 2098 $$ = tree.NewExplainStmt($2, "text") 2099 } 2100 | explain_sym VERBOSE explainable_stmt 2101 { 2102 explainStmt := tree.NewExplainStmt($3, "text") 2103 optionElem := tree.MakeOptionElem("verbose", "NULL") 2104 options := tree.MakeOptions(optionElem) 2105 explainStmt.Options = options 2106 $$ = explainStmt 2107 } 2108 | explain_sym ANALYZE explainable_stmt 2109 { 2110 explainStmt := tree.NewExplainAnalyze($3, "text") 2111 optionElem := tree.MakeOptionElem("analyze", "NULL") 2112 options := tree.MakeOptions(optionElem) 2113 explainStmt.Options = options 2114 $$ = explainStmt 2115 } 2116 | explain_sym ANALYZE VERBOSE explainable_stmt 2117 { 2118 explainStmt := tree.NewExplainAnalyze($4, "text") 2119 optionElem1 := tree.MakeOptionElem("analyze", "NULL") 2120 optionElem2 := tree.MakeOptionElem("verbose", "NULL") 2121 options := tree.MakeOptions(optionElem1) 2122 options = append(options, optionElem2) 2123 explainStmt.Options = options 2124 $$ = explainStmt 2125 } 2126 | explain_sym '(' utility_option_list ')' explainable_stmt 2127 { 2128 if tree.IsContainAnalyze($3) { 2129 explainStmt := tree.NewExplainAnalyze($5, "text") 2130 explainStmt.Options = $3 2131 $$ = explainStmt 2132 } else { 2133 explainStmt := tree.NewExplainStmt($5, "text") 2134 explainStmt.Options = $3 2135 $$ = explainStmt 2136 } 2137 } 2138 2139 explain_option_key: 2140 ANALYZE 2141 | VERBOSE 2142 | FORMAT 2143 2144 explain_foramt_value: 2145 JSON 2146 | TEXT 2147 2148 2149 prepare_sym: 2150 PREPARE 2151 2152 deallocate_sym: 2153 DEALLOCATE 2154 2155 execute_sym: 2156 EXECUTE 2157 2158 reset_sym: 2159 RESET 2160 2161 explain_sym: 2162 EXPLAIN 2163 | DESCRIBE 2164 | DESC 2165 2166 utility_option_list: 2167 utility_option_elem 2168 { 2169 $$ = tree.MakeOptions($1) 2170 } 2171 | utility_option_list ',' utility_option_elem 2172 { 2173 $$ = append($1, $3); 2174 } 2175 2176 utility_option_elem: 2177 utility_option_name utility_option_arg 2178 { 2179 $$ = tree.MakeOptionElem($1, $2) 2180 } 2181 2182 utility_option_name: 2183 explain_option_key 2184 { 2185 $$ = $1 2186 } 2187 2188 utility_option_arg: 2189 TRUE { $$ = "true" } 2190 | FALSE { $$ = "false" } 2191 | explain_foramt_value { $$ = $1 } 2192 2193 2194 analyze_stmt: 2195 ANALYZE TABLE table_name '(' column_list ')' 2196 { 2197 $$ = tree.NewAnalyzeStmt($3, $5) 2198 } 2199 2200 alter_stmt: 2201 alter_user_stmt 2202 | alter_account_stmt 2203 | alter_database_config_stmt 2204 | alter_view_stmt 2205 // | alter_ddl_stmt 2206 2207 alter_view_stmt: 2208 ALTER VIEW exists_opt table_name column_list_opt AS select_stmt 2209 { 2210 $$ = &tree.AlterView{ 2211 Name: $4, 2212 ColNames: $5, 2213 AsSource: $7, 2214 IfExists: $3, 2215 } 2216 } 2217 2218 alter_account_stmt: 2219 ALTER ACCOUNT exists_opt account_name alter_account_auth_option account_status_option account_comment_opt 2220 { 2221 $$ = &tree.AlterAccount{ 2222 IfExists:$3, 2223 Name:$4, 2224 AuthOption:$5, 2225 StatusOption:$6, 2226 Comment:$7, 2227 } 2228 } 2229 2230 alter_database_config_stmt: 2231 ALTER DATABASE db_name SET MYSQL_COMPATBILITY_MODE '=' STRING 2232 { 2233 $$ = &tree.AlterDataBaseConfig{ 2234 DbName:$3, 2235 UpdateConfig: $7, 2236 IsAccountLevel: false, 2237 } 2238 } 2239 | ALTER ACCOUNT CONFIG account_name SET MYSQL_COMPATBILITY_MODE '=' STRING 2240 { 2241 $$ = &tree.AlterDataBaseConfig{ 2242 AccountName:$4, 2243 UpdateConfig: $8, 2244 IsAccountLevel: true, 2245 } 2246 } 2247 2248 alter_account_auth_option: 2249 { 2250 $$ = tree.AlterAccountAuthOption{ 2251 Exist: false, 2252 } 2253 } 2254 | ADMIN_NAME equal_opt account_admin_name account_identified 2255 { 2256 $$ = tree.AlterAccountAuthOption{ 2257 Exist: true, 2258 Equal:$2, 2259 AdminName:$3, 2260 IdentifiedType:$4, 2261 } 2262 } 2263 2264 alter_user_stmt: 2265 ALTER USER exists_opt user_spec_list_of_create_user default_role_opt pwd_or_lck_opt user_comment_or_attribute_opt 2266 { 2267 $$ = &tree.AlterUser{ 2268 IfExists: $3, 2269 Users: $4, 2270 Role: $5, 2271 MiscOpt: $6, 2272 CommentOrAttribute: $7, 2273 } 2274 } 2275 2276 default_role_opt: 2277 { 2278 $$ = nil 2279 } 2280 | DEFAULT ROLE account_role_name 2281 { 2282 $$ = &tree.Role{UserName:$3} 2283 } 2284 2285 exists_opt: 2286 { 2287 $$ = false 2288 } 2289 | IF EXISTS 2290 { 2291 $$ = true 2292 } 2293 2294 pwd_or_lck_opt: 2295 { 2296 $$ = nil 2297 } 2298 | pwd_or_lck 2299 { 2300 $$ = $1 2301 } 2302 2303 //pwd_or_lck_list: 2304 // pwd_or_lck 2305 // { 2306 // $$ = []tree.UserMiscOption{$1} 2307 // } 2308 //| pwd_or_lck_list pwd_or_lck 2309 // { 2310 // $$ = append($1, $2) 2311 // } 2312 2313 pwd_or_lck: 2314 UNLOCK 2315 { 2316 $$ = &tree.UserMiscOptionAccountUnlock{} 2317 } 2318 | LOCK 2319 { 2320 $$ = &tree.UserMiscOptionAccountLock{} 2321 } 2322 | pwd_expire 2323 { 2324 $$ = &tree.UserMiscOptionPasswordExpireNone{} 2325 } 2326 | pwd_expire INTERVAL INTEGRAL DAY 2327 { 2328 $$ = &tree.UserMiscOptionPasswordExpireInterval{Value: $3.(int64)} 2329 } 2330 | pwd_expire NEVER 2331 { 2332 $$ = &tree.UserMiscOptionPasswordExpireNever{} 2333 } 2334 | pwd_expire DEFAULT 2335 { 2336 $$ = &tree.UserMiscOptionPasswordExpireDefault{} 2337 } 2338 | PASSWORD HISTORY DEFAULT 2339 { 2340 $$ = &tree.UserMiscOptionPasswordHistoryDefault{} 2341 } 2342 | PASSWORD HISTORY INTEGRAL 2343 { 2344 $$ = &tree.UserMiscOptionPasswordHistoryCount{Value: $3.(int64)} 2345 } 2346 | PASSWORD REUSE INTERVAL DEFAULT 2347 { 2348 $$ = &tree.UserMiscOptionPasswordReuseIntervalDefault{} 2349 } 2350 | PASSWORD REUSE INTERVAL INTEGRAL DAY 2351 { 2352 $$ = &tree.UserMiscOptionPasswordReuseIntervalCount{Value: $4.(int64)} 2353 } 2354 | PASSWORD REQUIRE CURRENT 2355 { 2356 $$ = &tree.UserMiscOptionPasswordRequireCurrentNone{} 2357 } 2358 | PASSWORD REQUIRE CURRENT DEFAULT 2359 { 2360 $$ = &tree.UserMiscOptionPasswordRequireCurrentDefault{} 2361 } 2362 | PASSWORD REQUIRE CURRENT OPTIONAL 2363 { 2364 $$ = &tree.UserMiscOptionPasswordRequireCurrentOptional{} 2365 } 2366 | FAILED_LOGIN_ATTEMPTS INTEGRAL 2367 { 2368 $$ = &tree.UserMiscOptionFailedLoginAttempts{Value: $2.(int64)} 2369 } 2370 | PASSWORD_LOCK_TIME INTEGRAL 2371 { 2372 $$ = &tree.UserMiscOptionPasswordLockTimeCount{Value: $2.(int64)} 2373 } 2374 | PASSWORD_LOCK_TIME UNBOUNDED 2375 { 2376 $$ = &tree.UserMiscOptionPasswordLockTimeUnbounded{} 2377 } 2378 2379 pwd_expire: 2380 PASSWORD EXPIRE clear_pwd_opt 2381 { 2382 $$ = nil 2383 } 2384 2385 clear_pwd_opt: 2386 { 2387 $$ = nil 2388 } 2389 2390 auth_string: 2391 STRING 2392 2393 show_stmt: 2394 show_create_stmt 2395 | show_columns_stmt 2396 | show_databases_stmt 2397 | show_tables_stmt 2398 | show_process_stmt 2399 | show_errors_stmt 2400 | show_warnings_stmt 2401 | show_variables_stmt 2402 | show_status_stmt 2403 | show_index_stmt 2404 | show_target_filter_stmt 2405 | show_table_status_stmt 2406 | show_grants_stmt 2407 | show_collation_stmt 2408 | show_function_status_stmt 2409 | show_node_list_stmt 2410 | show_locks_stmt 2411 | show_table_num_stmt 2412 | show_column_num_stmt 2413 | show_table_values_stmt 2414 | show_accounts_stmt 2415 2416 show_collation_stmt: 2417 SHOW COLLATION like_opt where_expression_opt 2418 { 2419 $$ = &tree.ShowCollation{} 2420 } 2421 show_grants_stmt: 2422 SHOW GRANTS 2423 { 2424 $$ = &tree.ShowGrants{ShowGrantType: tree.GrantForUser} 2425 } 2426 | SHOW GRANTS FOR user_name using_roles_opt 2427 { 2428 $$ = &tree.ShowGrants{Username: $4.Username, Hostname: $4.Hostname, Roles: $5, ShowGrantType: tree.GrantForUser} 2429 } 2430 | SHOW GRANTS FOR ROLE role_name 2431 { 2432 s := &tree.ShowGrants{} 2433 roles := []*tree.Role{tree.NewRole($5)} 2434 s.Roles = roles 2435 s.ShowGrantType = tree.GrantForRole 2436 $$ = s 2437 } 2438 2439 using_roles_opt: 2440 { 2441 $$ = nil 2442 } 2443 | USING role_spec_list 2444 { 2445 $$ = $2 2446 } 2447 2448 show_table_status_stmt: 2449 SHOW TABLE STATUS from_or_in_opt db_name_opt like_opt where_expression_opt 2450 { 2451 $$ = &tree.ShowTableStatus{DbName: $5, Like: $6, Where: $7} 2452 } 2453 2454 from_or_in_opt: 2455 {} 2456 | from_or_in 2457 2458 db_name_opt: 2459 {} 2460 | db_name 2461 2462 show_function_status_stmt: 2463 SHOW FUNCTION STATUS like_opt where_expression_opt 2464 { 2465 $$ = &tree.ShowFunctionStatus{ 2466 Like: $4, 2467 Where: $5, 2468 } 2469 } 2470 2471 show_node_list_stmt: 2472 SHOW NODE LIST 2473 { 2474 $$ = &tree.ShowNodeList{} 2475 } 2476 2477 show_locks_stmt: 2478 SHOW LOCKS 2479 { 2480 $$ = &tree.ShowLocks{} 2481 } 2482 2483 show_table_num_stmt: 2484 SHOW TABLE_NUMBER from_or_in_opt db_name_opt 2485 { 2486 $$ = &tree.ShowTableNumber{DbName: $4} 2487 } 2488 2489 show_column_num_stmt: 2490 SHOW COLUMN_NUMBER table_column_name database_name_opt 2491 { 2492 $$ = &tree.ShowColumnNumber{Table: $3, DbName: $4} 2493 } 2494 2495 show_table_values_stmt: 2496 SHOW TABLE_VALUES table_column_name database_name_opt 2497 { 2498 $$ = &tree.ShowTableValues{Table: $3, DbName: $4} 2499 } 2500 2501 show_target_filter_stmt: 2502 SHOW show_target like_opt where_expression_opt 2503 { 2504 s := $2.(*tree.ShowTarget) 2505 s.Like = $3 2506 s.Where = $4 2507 $$ = s 2508 } 2509 2510 show_target: 2511 CONFIG 2512 { 2513 $$ = &tree.ShowTarget{Type: tree.ShowConfig} 2514 } 2515 | charset_keyword 2516 { 2517 $$ = &tree.ShowTarget{Type: tree.ShowCharset} 2518 } 2519 | ENGINES 2520 { 2521 $$ = &tree.ShowTarget{Type: tree.ShowEngines} 2522 } 2523 | TRIGGERS from_or_in_opt db_name_opt 2524 { 2525 $$ = &tree.ShowTarget{DbName: $3, Type: tree.ShowTriggers} 2526 } 2527 | PROCEDURE STATUS 2528 { 2529 $$ = &tree.ShowTarget{Type: tree.ShowProcedureStatus} 2530 } 2531 | EVENTS from_or_in_opt db_name_opt 2532 { 2533 $$ = &tree.ShowTarget{DbName: $3, Type: tree.ShowEvents} 2534 } 2535 | PLUGINS 2536 { 2537 $$ = &tree.ShowTarget{Type: tree.ShowPlugins} 2538 } 2539 | PRIVILEGES 2540 { 2541 $$ = &tree.ShowTarget{Type: tree.ShowPrivileges} 2542 } 2543 | PROFILES 2544 { 2545 $$ = &tree.ShowTarget{Type: tree.ShowProfiles} 2546 } 2547 2548 show_index_stmt: 2549 SHOW extended_opt index_kwd from_or_in table_name where_expression_opt 2550 { 2551 $$ = &tree.ShowIndex{ 2552 TableName: *$5, 2553 Where: $6, 2554 } 2555 } 2556 | SHOW extended_opt index_kwd from_or_in ident from_or_in ident where_expression_opt 2557 { 2558 prefix := tree.ObjectNamePrefix{SchemaName: tree.Identifier($7), ExplicitSchema: true} 2559 tbl := tree.NewTableName(tree.Identifier($5), prefix) 2560 $$ = &tree.ShowIndex{ 2561 TableName: *tbl, 2562 Where: $8, 2563 } 2564 } 2565 2566 extended_opt: 2567 {} 2568 | EXTENDED 2569 {} 2570 2571 index_kwd: 2572 INDEX 2573 | INDEXES 2574 | KEYS 2575 2576 show_variables_stmt: 2577 SHOW global_scope VARIABLES like_opt where_expression_opt 2578 { 2579 $$ = &tree.ShowVariables{ 2580 Global: $2, 2581 Like: $4, 2582 Where: $5, 2583 } 2584 } 2585 2586 show_status_stmt: 2587 SHOW global_scope STATUS like_opt where_expression_opt 2588 { 2589 $$ = &tree.ShowStatus{ 2590 Global: $2, 2591 Like: $4, 2592 Where: $5, 2593 } 2594 } 2595 2596 global_scope: 2597 { 2598 $$ = false 2599 } 2600 | GLOBAL 2601 { 2602 $$ = true 2603 } 2604 | SESSION 2605 { 2606 $$ = false 2607 } 2608 2609 show_warnings_stmt: 2610 SHOW WARNINGS limit_opt 2611 { 2612 $$ = &tree.ShowWarnings{} 2613 } 2614 2615 show_errors_stmt: 2616 SHOW ERRORS limit_opt 2617 { 2618 $$ = &tree.ShowErrors{} 2619 } 2620 2621 show_process_stmt: 2622 SHOW full_opt PROCESSLIST 2623 { 2624 $$ = &tree.ShowProcessList{Full: $2} 2625 } 2626 2627 show_tables_stmt: 2628 SHOW full_opt TABLES database_name_opt like_opt where_expression_opt 2629 { 2630 $$ = &tree.ShowTables{ 2631 Open: false, 2632 Full: $2, 2633 DBName: $4, 2634 Like: $5, 2635 Where: $6, 2636 } 2637 } 2638 | SHOW OPEN full_opt TABLES database_name_opt like_opt where_expression_opt 2639 { 2640 $$ = &tree.ShowTables{ 2641 Open: true, 2642 Full: $3, 2643 DBName: $5, 2644 Like: $6, 2645 Where: $7, 2646 } 2647 } 2648 2649 show_databases_stmt: 2650 SHOW DATABASES like_opt where_expression_opt 2651 { 2652 $$ = &tree.ShowDatabases{Like: $3, Where: $4} 2653 } 2654 | SHOW SCHEMAS like_opt where_expression_opt 2655 { 2656 $$ = &tree.ShowDatabases{Like: $3, Where: $4} 2657 } 2658 2659 show_columns_stmt: 2660 SHOW full_opt fields_or_columns table_column_name database_name_opt like_opt where_expression_opt 2661 { 2662 $$ = &tree.ShowColumns{ 2663 Ext: false, 2664 Full: $2, 2665 Table: $4, 2666 // colName: $3, 2667 DBName: $5, 2668 Like: $6, 2669 Where: $7, 2670 } 2671 } 2672 | SHOW EXTENDED full_opt fields_or_columns table_column_name database_name_opt like_opt where_expression_opt 2673 { 2674 $$ = &tree.ShowColumns{ 2675 Ext: true, 2676 Full: $3, 2677 Table: $5, 2678 // colName: $3, 2679 DBName: $6, 2680 Like: $7, 2681 Where: $8, 2682 } 2683 } 2684 2685 show_accounts_stmt: 2686 SHOW ACCOUNTS like_opt 2687 { 2688 $$ = &tree.ShowAccounts{Like: $3} 2689 } 2690 2691 like_opt: 2692 { 2693 $$ = nil 2694 } 2695 | LIKE simple_expr 2696 { 2697 $$ = tree.NewComparisonExpr(tree.LIKE, nil, $2) 2698 } 2699 | ILIKE simple_expr 2700 { 2701 $$ = tree.NewComparisonExpr(tree.ILIKE, nil, $2) 2702 } 2703 2704 database_name_opt: 2705 { 2706 $$ = "" 2707 } 2708 | from_or_in database_id 2709 { 2710 $$ = $2 2711 } 2712 2713 table_column_name: 2714 from_or_in unresolved_object_name 2715 { 2716 $$ = $2 2717 } 2718 2719 from_or_in: 2720 FROM 2721 | IN 2722 2723 fields_or_columns: 2724 FIELDS 2725 | COLUMNS 2726 2727 full_opt: 2728 { 2729 $$ = false 2730 } 2731 | FULL 2732 { 2733 $$ = true 2734 } 2735 2736 show_create_stmt: 2737 SHOW CREATE TABLE table_name_unresolved 2738 { 2739 $$ = &tree.ShowCreateTable{Name: $4} 2740 } 2741 | 2742 SHOW CREATE VIEW table_name_unresolved 2743 { 2744 $$ = &tree.ShowCreateView{Name: $4} 2745 } 2746 | SHOW CREATE DATABASE not_exists_opt db_name 2747 { 2748 $$ = &tree.ShowCreateDatabase{IfNotExists: $4, Name: $5} 2749 } 2750 2751 table_name_unresolved: 2752 ident 2753 { 2754 $$ = tree.SetUnresolvedObjectName(1, [3]string{$1}) 2755 } 2756 | ident '.' ident 2757 { 2758 $$ = tree.SetUnresolvedObjectName(2, [3]string{$3, $1}) 2759 } 2760 2761 db_name: 2762 ident 2763 2764 unresolved_object_name: 2765 ident 2766 { 2767 $$ = tree.SetUnresolvedObjectName(1, [3]string{$1}) 2768 } 2769 | ident '.' ident 2770 { 2771 $$ = tree.SetUnresolvedObjectName(2, [3]string{$3, $1}) 2772 } 2773 | ident '.' ident '.' ident 2774 { 2775 $$ = tree.SetUnresolvedObjectName(3, [3]string{$5, $3, $1}) 2776 } 2777 2778 truncate_table_stmt: 2779 TRUNCATE table_name 2780 { 2781 $$ = tree.NewTruncateTable($2) 2782 } 2783 | TRUNCATE TABLE table_name 2784 { 2785 $$ = tree.NewTruncateTable($3) 2786 } 2787 2788 drop_stmt: 2789 drop_ddl_stmt 2790 2791 drop_ddl_stmt: 2792 drop_database_stmt 2793 | drop_prepare_stmt 2794 | drop_table_stmt 2795 | drop_view_stmt 2796 | drop_index_stmt 2797 | drop_role_stmt 2798 | drop_user_stmt 2799 | drop_account_stmt 2800 | drop_function_stmt 2801 2802 drop_account_stmt: 2803 DROP ACCOUNT exists_opt account_name 2804 { 2805 $$ = &tree.DropAccount{ 2806 IfExists: $3, 2807 Name: $4, 2808 } 2809 } 2810 2811 drop_user_stmt: 2812 DROP USER exists_opt drop_user_spec_list 2813 { 2814 $$ = &tree.DropUser{ 2815 IfExists: $3, 2816 Users: $4, 2817 } 2818 } 2819 2820 drop_user_spec_list: 2821 drop_user_spec 2822 { 2823 $$ = []*tree.User{$1} 2824 } 2825 | drop_user_spec_list ',' drop_user_spec 2826 { 2827 $$ = append($1, $3) 2828 } 2829 2830 drop_user_spec: 2831 user_name 2832 { 2833 $$ = &tree.User{ 2834 Username: $1.Username, 2835 Hostname: $1.Hostname, 2836 } 2837 } 2838 2839 drop_role_stmt: 2840 DROP ROLE exists_opt role_spec_list 2841 { 2842 $$ = &tree.DropRole{ 2843 IfExists: $3, 2844 Roles: $4, 2845 } 2846 } 2847 2848 drop_index_stmt: 2849 DROP INDEX exists_opt ident ON table_name 2850 { 2851 $$ = &tree.DropIndex{ 2852 Name: tree.Identifier($4), 2853 TableName: *$6, 2854 IfExists: $3, 2855 } 2856 } 2857 2858 drop_table_stmt: 2859 DROP TABLE exists_opt table_name_list 2860 { 2861 $$ = &tree.DropTable{IfExists: $3, Names: $4} 2862 } 2863 2864 drop_view_stmt: 2865 DROP VIEW exists_opt table_name_list 2866 { 2867 $$ = &tree.DropView{IfExists: $3, Names: $4} 2868 } 2869 2870 drop_database_stmt: 2871 DROP DATABASE exists_opt database_id 2872 { 2873 $$ = &tree.DropDatabase{Name: tree.Identifier($4), IfExists: $3} 2874 } 2875 2876 drop_prepare_stmt: 2877 DROP PREPARE stmt_name 2878 { 2879 $$ = tree.NewDeallocate(tree.Identifier($3), true) 2880 } 2881 2882 drop_function_stmt: 2883 DROP FUNCTION func_name '(' func_args_list_opt ')' 2884 { 2885 $$ = &tree.DropFunction{ 2886 Name: $3, 2887 Args: $5, 2888 } 2889 } 2890 2891 delete_stmt: 2892 delete_without_using_stmt 2893 | delete_with_using_stmt 2894 | with_clause delete_with_using_stmt 2895 { 2896 $2.(*tree.Delete).With = $1 2897 $$ = $2 2898 } 2899 | with_clause delete_without_using_stmt 2900 { 2901 $2.(*tree.Delete).With = $1 2902 $$ = $2 2903 } 2904 2905 delete_without_using_stmt: 2906 DELETE priority_opt quick_opt ignore_opt FROM table_name partition_clause_opt as_opt_id where_expression_opt order_by_opt limit_opt 2907 { 2908 // Single-Table Syntax 2909 t := &tree.AliasedTableExpr { 2910 Expr: $6, 2911 As: tree.AliasClause{ 2912 Alias: tree.Identifier($8), 2913 }, 2914 } 2915 $$ = &tree.Delete{ 2916 Tables: tree.TableExprs{t}, 2917 Where: $9, 2918 OrderBy: $10, 2919 Limit: $11, 2920 } 2921 } 2922 | DELETE priority_opt quick_opt ignore_opt table_name_wild_list FROM table_references where_expression_opt 2923 { 2924 // Multiple-Table Syntax 2925 $$ = &tree.Delete{ 2926 Tables: $5, 2927 Where: $8, 2928 TableRefs: tree.TableExprs{$7}, 2929 } 2930 } 2931 2932 2933 2934 delete_with_using_stmt: 2935 DELETE priority_opt quick_opt ignore_opt FROM table_name_wild_list USING table_references where_expression_opt 2936 { 2937 // Multiple-Table Syntax 2938 $$ = &tree.Delete{ 2939 Tables: $6, 2940 Where: $9, 2941 TableRefs: tree.TableExprs{$8}, 2942 } 2943 } 2944 2945 table_name_wild_list: 2946 table_name_opt_wild 2947 { 2948 $$ = tree.TableExprs{$1} 2949 } 2950 | table_name_wild_list ',' table_name_opt_wild 2951 { 2952 $$ = append($1, $3) 2953 } 2954 2955 table_name_opt_wild: 2956 ident wild_opt 2957 { 2958 prefix := tree.ObjectNamePrefix{ExplicitSchema: false} 2959 $$ = tree.NewTableName(tree.Identifier($1), prefix) 2960 } 2961 | ident '.' ident wild_opt 2962 { 2963 prefix := tree.ObjectNamePrefix{SchemaName: tree.Identifier($1), ExplicitSchema: true} 2964 $$ = tree.NewTableName(tree.Identifier($3), prefix) 2965 } 2966 2967 wild_opt: 2968 %prec EMPTY 2969 {} 2970 | '.' '*' 2971 {} 2972 2973 priority_opt: 2974 {} 2975 | priority 2976 2977 priority: 2978 LOW_PRIORITY 2979 | HIGH_PRIORITY 2980 | DELAYED 2981 2982 quick_opt: 2983 {} 2984 | QUICK 2985 2986 ignore_opt: 2987 {} 2988 | IGNORE 2989 2990 replace_stmt: 2991 REPLACE into_table_name partition_clause_opt replace_data 2992 { 2993 rep := $4 2994 rep.Table = $2 2995 rep.PartitionNames = $3 2996 $$ = rep 2997 } 2998 2999 replace_data: 3000 VALUES values_list 3001 { 3002 vc := tree.NewValuesClause($2) 3003 $$ = &tree.Replace{ 3004 Rows: tree.NewSelect(vc, nil, nil), 3005 } 3006 } 3007 | select_stmt 3008 { 3009 $$ = &tree.Replace{ 3010 Rows: $1, 3011 } 3012 } 3013 | '(' insert_column_list ')' VALUES values_list 3014 { 3015 vc := tree.NewValuesClause($5) 3016 $$ = &tree.Replace{ 3017 Columns: $2, 3018 Rows: tree.NewSelect(vc, nil, nil), 3019 } 3020 } 3021 | '(' ')' VALUES values_list 3022 { 3023 vc := tree.NewValuesClause($4) 3024 $$ = &tree.Replace{ 3025 Rows: tree.NewSelect(vc, nil, nil), 3026 } 3027 } 3028 | '(' insert_column_list ')' select_stmt 3029 { 3030 $$ = &tree.Replace{ 3031 Columns: $2, 3032 Rows: $4, 3033 } 3034 } 3035 | SET set_value_list 3036 { 3037 if $2 == nil { 3038 yylex.Error("the set list of replace can not be empty") 3039 return 1 3040 } 3041 var identList tree.IdentifierList 3042 var valueList tree.Exprs 3043 for _, a := range $2 { 3044 identList = append(identList, a.Column) 3045 valueList = append(valueList, a.Expr) 3046 } 3047 vc := tree.NewValuesClause([]tree.Exprs{valueList}) 3048 $$ = &tree.Replace{ 3049 Columns: identList, 3050 Rows: tree.NewSelect(vc, nil, nil), 3051 } 3052 } 3053 3054 insert_stmt: 3055 INSERT into_table_name partition_clause_opt insert_data on_duplicate_key_update_opt 3056 { 3057 ins := $4 3058 ins.Table = $2 3059 ins.PartitionNames = $3 3060 ins.OnDuplicateUpdate = $5 3061 $$ = ins 3062 } 3063 3064 accounts_opt: 3065 { 3066 $$ = nil 3067 } 3068 | ACCOUNTS '(' accounts_list ')' 3069 { 3070 $$ = $3 3071 } 3072 3073 accounts_list: 3074 account_name 3075 { 3076 $$ = tree.IdentifierList{tree.Identifier($1)} 3077 } 3078 | accounts_list ',' account_name 3079 { 3080 $$ = append($1, tree.Identifier($3)) 3081 } 3082 3083 insert_data: 3084 accounts_opt VALUES values_list 3085 { 3086 vc := tree.NewValuesClause($3) 3087 $$ = &tree.Insert{ 3088 Accounts: $1, 3089 Rows: tree.NewSelect(vc, nil, nil), 3090 } 3091 } 3092 | select_stmt 3093 { 3094 $$ = &tree.Insert{ 3095 Rows: $1, 3096 } 3097 } 3098 | ACCOUNTS '(' accounts_list ')' select_stmt 3099 { 3100 $$ = &tree.Insert{ 3101 Accounts: $3, 3102 Rows: $5, 3103 } 3104 } 3105 | '(' insert_column_list ')' accounts_opt VALUES values_list 3106 { 3107 vc := tree.NewValuesClause($6) 3108 $$ = &tree.Insert{ 3109 Columns: $2, 3110 Accounts: $4, 3111 Rows: tree.NewSelect(vc, nil, nil), 3112 } 3113 } 3114 | '(' ')' accounts_opt VALUES values_list 3115 { 3116 vc := tree.NewValuesClause($5) 3117 $$ = &tree.Insert{ 3118 Accounts: $3, 3119 Rows: tree.NewSelect(vc, nil, nil), 3120 } 3121 } 3122 | '(' insert_column_list ')' accounts_opt select_stmt 3123 { 3124 $$ = &tree.Insert{ 3125 Columns: $2, 3126 Accounts: $4, 3127 Rows: $5, 3128 } 3129 } 3130 | accounts_opt SET set_value_list 3131 { 3132 if $3 == nil { 3133 yylex.Error("the set list of insert can not be empty") 3134 return 1 3135 } 3136 var identList tree.IdentifierList 3137 var valueList tree.Exprs 3138 for _, a := range $3 { 3139 identList = append(identList, a.Column) 3140 valueList = append(valueList, a.Expr) 3141 } 3142 vc := tree.NewValuesClause([]tree.Exprs{valueList}) 3143 $$ = &tree.Insert{ 3144 Columns: identList, 3145 Accounts: $1, 3146 Rows: tree.NewSelect(vc, nil, nil), 3147 } 3148 } 3149 3150 on_duplicate_key_update_opt: 3151 { 3152 $$ = []*tree.UpdateExpr{} 3153 } 3154 | ON DUPLICATE KEY UPDATE update_list 3155 { 3156 $$ = $5 3157 } 3158 3159 set_value_list: 3160 { 3161 $$ = nil 3162 } 3163 | set_value 3164 { 3165 $$ = []*tree.Assignment{$1} 3166 } 3167 | set_value_list ',' set_value 3168 { 3169 $$ = append($1, $3) 3170 } 3171 3172 set_value: 3173 insert_column '=' expr_or_default 3174 { 3175 $$ = &tree.Assignment{ 3176 Column: tree.Identifier($1), 3177 Expr: $3, 3178 } 3179 } 3180 3181 insert_column_list: 3182 insert_column 3183 { 3184 $$ = tree.IdentifierList{tree.Identifier($1)} 3185 } 3186 | insert_column_list ',' insert_column 3187 { 3188 $$ = append($1, tree.Identifier($3)) 3189 } 3190 3191 insert_column: 3192 ident 3193 { 3194 $$ = $1 3195 } 3196 | ident '.' ident 3197 { 3198 $$ = $3 3199 } 3200 3201 values_list: 3202 row_value 3203 { 3204 $$ = []tree.Exprs{$1} 3205 } 3206 | values_list ',' row_value 3207 { 3208 $$ = append($1, $3) 3209 } 3210 3211 row_value: 3212 row_opt '(' data_opt ')' 3213 { 3214 $$ = $3 3215 } 3216 3217 row_opt: 3218 {} 3219 | ROW 3220 3221 data_opt: 3222 { 3223 $$ = nil 3224 } 3225 | data_values 3226 3227 data_values: 3228 expr_or_default 3229 { 3230 $$ = tree.Exprs{$1} 3231 } 3232 | data_values ',' expr_or_default 3233 { 3234 $$ = append($1, $3) 3235 } 3236 3237 expr_or_default: 3238 expression 3239 | DEFAULT 3240 { 3241 $$ = &tree.DefaultVal{} 3242 } 3243 3244 partition_clause_opt: 3245 { 3246 $$ = nil 3247 } 3248 | PARTITION '(' partition_id_list ')' 3249 { 3250 $$ = $3 3251 } 3252 3253 partition_id_list: 3254 ident 3255 { 3256 $$ = tree.IdentifierList{tree.Identifier($1)} 3257 } 3258 | partition_id_list ',' ident 3259 { 3260 $$ = append($1 , tree.Identifier($3)) 3261 } 3262 3263 into_table_name: 3264 INTO table_name 3265 { 3266 $$ = $2 3267 } 3268 | table_name 3269 { 3270 $$ = $1 3271 } 3272 3273 export_data_param_opt: 3274 { 3275 $$ = nil 3276 } 3277 | INTO OUTFILE STRING export_fields export_lines_opt header_opt max_file_size_opt force_quote_opt 3278 { 3279 $$ = &tree.ExportParam{ 3280 Outfile: true, 3281 FilePath : $3, 3282 Fields: $4, 3283 Lines: $5, 3284 Header: $6, 3285 MaxFileSize:uint64($7)*1024, 3286 ForceQuote: $8, 3287 } 3288 } 3289 3290 export_fields: 3291 { 3292 $$ = &tree.Fields{ 3293 Terminated: ",", 3294 EnclosedBy: '"', 3295 } 3296 } 3297 | FIELDS TERMINATED BY STRING 3298 { 3299 $$ = &tree.Fields{ 3300 Terminated: $4, 3301 EnclosedBy: '"', 3302 } 3303 } 3304 | FIELDS TERMINATED BY STRING ENCLOSED BY field_terminator 3305 { 3306 str := $7 3307 if str != "\\" && len(str) > 1 { 3308 yylex.Error("export1 error field terminator") 3309 return 1 3310 } 3311 var b byte 3312 if len(str) != 0 { 3313 b = byte(str[0]) 3314 } else { 3315 b = 0 3316 } 3317 $$ = &tree.Fields{ 3318 Terminated: $4, 3319 EnclosedBy: b, 3320 } 3321 } 3322 | FIELDS ENCLOSED BY field_terminator 3323 { 3324 str := $4 3325 if str != "\\" && len(str) > 1 { 3326 yylex.Error("export2 error field terminator") 3327 return 1 3328 } 3329 var b byte 3330 if len(str) != 0 { 3331 b = byte(str[0]) 3332 } else { 3333 b = 0 3334 } 3335 $$ = &tree.Fields{ 3336 Terminated: ",", 3337 EnclosedBy: b, 3338 } 3339 } 3340 3341 export_lines_opt: 3342 { 3343 $$ = &tree.Lines{ 3344 TerminatedBy: "\n", 3345 } 3346 } 3347 | LINES lines_terminated_opt 3348 { 3349 $$ = &tree.Lines{ 3350 TerminatedBy: $2, 3351 } 3352 } 3353 3354 header_opt: 3355 { 3356 $$ = true 3357 } 3358 | HEADER STRING 3359 { 3360 str := strings.ToLower($2) 3361 if str == "true" { 3362 $$ = true 3363 } else if str == "false" { 3364 $$ = false 3365 } else { 3366 yylex.Error("error header flag") 3367 return 1 3368 } 3369 } 3370 3371 max_file_size_opt: 3372 { 3373 $$ = 0 3374 } 3375 | MAX_FILE_SIZE INTEGRAL 3376 { 3377 $$ = $2.(int64) 3378 } 3379 3380 force_quote_opt: 3381 { 3382 $$ = []string{} 3383 } 3384 | FORCE_QUOTE '(' force_quote_list ')' 3385 { 3386 $$ = $3 3387 } 3388 3389 3390 force_quote_list: 3391 ident 3392 { 3393 $$ = make([]string, 0, 4) 3394 $$ = append($$, $1) 3395 } 3396 | force_quote_list ',' ident 3397 { 3398 $$ = append($1, $3) 3399 } 3400 3401 select_stmt: 3402 select_no_parens 3403 | select_with_parens 3404 { 3405 $$ = &tree.Select{Select: $1} 3406 } 3407 3408 select_no_parens: 3409 simple_select order_by_opt limit_opt export_data_param_opt // select_lock_opt 3410 { 3411 $$ = &tree.Select{Select: $1, OrderBy: $2, Limit: $3, Ep: $4} 3412 } 3413 | select_with_parens order_by_clause export_data_param_opt 3414 { 3415 $$ = &tree.Select{Select: $1, OrderBy: $2, Ep: $3} 3416 } 3417 | select_with_parens order_by_opt limit_clause export_data_param_opt 3418 { 3419 $$ = &tree.Select{Select: $1, OrderBy: $2, Limit: $3, Ep: $4} 3420 } 3421 | with_clause simple_select order_by_opt limit_opt export_data_param_opt // select_lock_opt 3422 { 3423 $$ = &tree.Select{Select: $2, OrderBy: $3, Limit: $4, Ep: $5, With: $1} 3424 } 3425 | with_clause select_with_parens order_by_clause export_data_param_opt 3426 { 3427 $$ = &tree.Select{Select: $2, OrderBy: $3, Ep: $4, With: $1} 3428 } 3429 | with_clause select_with_parens order_by_opt limit_clause export_data_param_opt 3430 { 3431 $$ = &tree.Select{Select: $2, OrderBy: $3, Limit: $4, Ep: $5, With: $1} 3432 } 3433 3434 with_clause: 3435 WITH cte_list 3436 { 3437 $$ = &tree.With{ 3438 IsRecursive: false, 3439 CTEs: $2, 3440 } 3441 } 3442 | WITH RECURSIVE cte_list 3443 { 3444 $$ = &tree.With{ 3445 IsRecursive: true, 3446 CTEs: $3, 3447 } 3448 } 3449 3450 cte_list: 3451 common_table_expr 3452 { 3453 $$ = []*tree.CTE{$1} 3454 } 3455 | cte_list ',' common_table_expr 3456 { 3457 $$ = append($1, $3) 3458 } 3459 3460 common_table_expr: 3461 ident column_list_opt AS '(' stmt ')' 3462 { 3463 $$ = &tree.CTE{ 3464 Name: &tree.AliasClause{Alias: tree.Identifier($1), Cols: $2}, 3465 Stmt: $5, 3466 } 3467 } 3468 3469 column_list_opt: 3470 { 3471 $$ = nil 3472 } 3473 | '(' column_list ')' 3474 { 3475 $$ = $2 3476 } 3477 3478 limit_opt: 3479 { 3480 $$ = nil 3481 } 3482 | limit_clause 3483 { 3484 $$ = $1 3485 } 3486 3487 limit_clause: 3488 LIMIT expression 3489 { 3490 $$ = &tree.Limit{Count: $2} 3491 } 3492 | LIMIT expression ',' expression 3493 { 3494 $$ = &tree.Limit{Offset: $2, Count: $4} 3495 } 3496 | LIMIT expression OFFSET expression 3497 { 3498 $$ = &tree.Limit{Offset: $4, Count: $2} 3499 } 3500 3501 order_by_opt: 3502 { 3503 $$ = nil 3504 } 3505 | order_by_clause 3506 { 3507 $$ = $1 3508 } 3509 3510 order_by_clause: 3511 ORDER BY order_list 3512 { 3513 $$ = $3 3514 } 3515 3516 order_list: 3517 order 3518 { 3519 $$ = tree.OrderBy{$1} 3520 } 3521 | order_list ',' order 3522 { 3523 $$ = append($1, $3) 3524 } 3525 3526 order: 3527 expression asc_desc_opt nulls_first_last_opt 3528 { 3529 $$ = &tree.Order{Expr: $1, Direction: $2, NullsPosition: $3} 3530 } 3531 3532 asc_desc_opt: 3533 { 3534 $$ = tree.DefaultDirection 3535 } 3536 | ASC 3537 { 3538 $$ = tree.Ascending 3539 } 3540 | DESC 3541 { 3542 $$ = tree.Descending 3543 } 3544 3545 nulls_first_last_opt: 3546 { 3547 $$ = tree.DefaultNullsPosition 3548 } 3549 | NULLS FIRST 3550 { 3551 $$ = tree.NullsFirst 3552 } 3553 | NULLS LAST 3554 { 3555 $$ = tree.NullsLast 3556 } 3557 3558 select_with_parens: 3559 '(' select_no_parens ')' 3560 { 3561 $$ = &tree.ParenSelect{Select: $2} 3562 } 3563 | '(' select_with_parens ')' 3564 { 3565 $$ = &tree.ParenSelect{Select: &tree.Select{Select: $2}} 3566 } 3567 | '(' values_stmt ')' 3568 { 3569 valuesStmt := $2.(*tree.ValuesStatement); 3570 $$ = &tree.ParenSelect{Select: &tree.Select { 3571 Select: &tree.ValuesClause { 3572 Rows: valuesStmt.Rows, 3573 RowWord: true, 3574 }, 3575 OrderBy: valuesStmt.OrderBy, 3576 Limit: valuesStmt.Limit, 3577 }} 3578 } 3579 3580 simple_select: 3581 simple_select_clause 3582 { 3583 $$ = $1 3584 } 3585 | simple_select union_op simple_select_clause 3586 { 3587 $$ = &tree.UnionClause{ 3588 Type: $2.Type, 3589 Left: $1, 3590 Right: $3, 3591 All: $2.All, 3592 Distinct: $2.Distinct, 3593 } 3594 } 3595 | select_with_parens union_op simple_select_clause 3596 { 3597 $$ = &tree.UnionClause{ 3598 Type: $2.Type, 3599 Left: $1, 3600 Right: $3, 3601 All: $2.All, 3602 Distinct: $2.Distinct, 3603 } 3604 } 3605 | simple_select union_op select_with_parens 3606 { 3607 $$ = &tree.UnionClause{ 3608 Type: $2.Type, 3609 Left: $1, 3610 Right: $3, 3611 All: $2.All, 3612 Distinct: $2.Distinct, 3613 } 3614 } 3615 | select_with_parens union_op select_with_parens 3616 { 3617 $$ = &tree.UnionClause{ 3618 Type: $2.Type, 3619 Left: $1, 3620 Right: $3, 3621 All: $2.All, 3622 Distinct: $2.Distinct, 3623 } 3624 } 3625 3626 union_op: 3627 UNION 3628 { 3629 $$ = &tree.UnionTypeRecord{ 3630 Type: tree.UNION, 3631 All: false, 3632 Distinct: false, 3633 } 3634 } 3635 | UNION ALL 3636 { 3637 $$ = &tree.UnionTypeRecord{ 3638 Type: tree.UNION, 3639 All: true, 3640 Distinct: false, 3641 } 3642 } 3643 | UNION DISTINCT 3644 { 3645 $$ = &tree.UnionTypeRecord{ 3646 Type: tree.UNION, 3647 All: false, 3648 Distinct: true, 3649 } 3650 } 3651 | 3652 EXCEPT 3653 { 3654 $$ = &tree.UnionTypeRecord{ 3655 Type: tree.EXCEPT, 3656 All: false, 3657 Distinct: false, 3658 } 3659 } 3660 | EXCEPT ALL 3661 { 3662 $$ = &tree.UnionTypeRecord{ 3663 Type: tree.EXCEPT, 3664 All: true, 3665 Distinct: false, 3666 } 3667 } 3668 | EXCEPT DISTINCT 3669 { 3670 $$ = &tree.UnionTypeRecord{ 3671 Type: tree.EXCEPT, 3672 All: false, 3673 Distinct: true, 3674 } 3675 } 3676 | INTERSECT 3677 { 3678 $$ = &tree.UnionTypeRecord{ 3679 Type: tree.INTERSECT, 3680 All: false, 3681 Distinct: false, 3682 } 3683 } 3684 | INTERSECT ALL 3685 { 3686 $$ = &tree.UnionTypeRecord{ 3687 Type: tree.INTERSECT, 3688 All: true, 3689 Distinct: false, 3690 } 3691 } 3692 | INTERSECT DISTINCT 3693 { 3694 $$ = &tree.UnionTypeRecord{ 3695 Type: tree.INTERSECT, 3696 All: false, 3697 Distinct: true, 3698 } 3699 } 3700 | MINUS 3701 { 3702 $$ = &tree.UnionTypeRecord{ 3703 Type: tree.UT_MINUS, 3704 All: false, 3705 Distinct: false, 3706 } 3707 } 3708 | MINUS ALL 3709 { 3710 $$ = &tree.UnionTypeRecord{ 3711 Type: tree.UT_MINUS, 3712 All: true, 3713 Distinct: false, 3714 } 3715 } 3716 | MINUS DISTINCT 3717 { 3718 $$ = &tree.UnionTypeRecord{ 3719 Type: tree.UT_MINUS, 3720 All: false, 3721 Distinct: true, 3722 } 3723 } 3724 3725 simple_select_clause: 3726 SELECT distinct_opt select_expression_list from_opt where_expression_opt group_by_opt having_opt 3727 { 3728 $$ = &tree.SelectClause{ 3729 Distinct: $2, 3730 Exprs: $3, 3731 From: $4, 3732 Where: $5, 3733 GroupBy: $6, 3734 Having: $7, 3735 } 3736 } 3737 | SELECT select_option_opt select_expression_list from_opt where_expression_opt group_by_opt having_opt 3738 { 3739 $$ = &tree.SelectClause{ 3740 Distinct: false, 3741 Exprs: $3, 3742 From: $4, 3743 Where: $5, 3744 GroupBy: $6, 3745 Having: $7, 3746 Option: $2, 3747 } 3748 } 3749 3750 select_option_opt: 3751 SQL_SMALL_RESULT 3752 | SQL_BIG_RESULT 3753 | SQL_BUFFER_RESULT 3754 3755 distinct_opt: 3756 { 3757 $$ = false 3758 } 3759 | ALL 3760 { 3761 $$ = false 3762 } 3763 | distinct_keyword 3764 { 3765 $$ = true 3766 } 3767 3768 distinct_keyword: 3769 DISTINCT 3770 | DISTINCTROW 3771 3772 having_opt: 3773 { 3774 $$ = nil 3775 } 3776 | HAVING expression 3777 { 3778 $$ = &tree.Where{Type: tree.AstHaving, Expr: $2} 3779 } 3780 3781 group_by_opt: 3782 { 3783 $$ = nil 3784 } 3785 | GROUP BY expression_list 3786 { 3787 $$ = tree.GroupBy($3) 3788 } 3789 3790 where_expression_opt: 3791 { 3792 $$ = nil 3793 } 3794 | WHERE expression 3795 { 3796 $$ = &tree.Where{Type: tree.AstWhere, Expr: $2} 3797 } 3798 3799 select_expression_list: 3800 select_expression 3801 { 3802 $$ = tree.SelectExprs{$1} 3803 } 3804 | select_expression_list ',' select_expression 3805 { 3806 $$ = append($1, $3) 3807 } 3808 3809 select_expression: 3810 '*' %prec '*' 3811 { 3812 $$ = tree.SelectExpr{Expr: tree.StarExpr()} 3813 } 3814 | expression as_name_opt 3815 { 3816 $$ = tree.SelectExpr{Expr: $1, As: tree.UnrestrictedIdentifier($2)} 3817 } 3818 | ident '.' '*' %prec '*' 3819 { 3820 $$ = tree.SelectExpr{Expr: tree.SetUnresolvedNameWithStar($1)} 3821 } 3822 | ident '.' ident '.' '*' %prec '*' 3823 { 3824 $$ = tree.SelectExpr{Expr: tree.SetUnresolvedNameWithStar($3, $1)} 3825 } 3826 3827 from_opt: 3828 { 3829 prefix := tree.ObjectNamePrefix{ExplicitSchema: false} 3830 tn := tree.NewTableName(tree.Identifier(""), prefix) 3831 $$ = &tree.From{ 3832 Tables: tree.TableExprs{&tree.AliasedTableExpr{Expr: tn}}, 3833 } 3834 } 3835 | from_clause 3836 { 3837 $$ = $1 3838 } 3839 3840 from_clause: 3841 FROM table_references 3842 { 3843 $$ = &tree.From{ 3844 Tables: tree.TableExprs{$2}, 3845 } 3846 } 3847 3848 table_references: 3849 escaped_table_reference 3850 { 3851 if t, ok := $1.(*tree.JoinTableExpr); ok { 3852 $$ = t 3853 } else { 3854 $$ = &tree.JoinTableExpr{Left: $1, Right: nil, JoinType: tree.JOIN_TYPE_CROSS} 3855 } 3856 } 3857 | table_references ',' escaped_table_reference 3858 { 3859 $$ = &tree.JoinTableExpr{Left: $1, Right: $3, JoinType: tree.JOIN_TYPE_CROSS} 3860 } 3861 3862 escaped_table_reference: 3863 table_reference %prec LOWER_THAN_SET 3864 3865 table_reference: 3866 table_factor 3867 | join_table 3868 { 3869 $$ = $1 3870 } 3871 3872 join_table: 3873 table_reference inner_join table_factor join_condition_opt 3874 { 3875 $$ = &tree.JoinTableExpr{ 3876 Left: $1, 3877 JoinType: $2, 3878 Right: $3, 3879 Cond: $4, 3880 } 3881 } 3882 | table_reference straight_join table_factor on_expression_opt 3883 { 3884 $$ = &tree.JoinTableExpr{ 3885 Left: $1, 3886 JoinType: $2, 3887 Right: $3, 3888 Cond: $4, 3889 } 3890 } 3891 | table_reference outer_join table_factor join_condition 3892 { 3893 $$ = &tree.JoinTableExpr{ 3894 Left: $1, 3895 JoinType: $2, 3896 Right: $3, 3897 Cond: $4, 3898 } 3899 } 3900 | table_reference natural_join table_factor 3901 { 3902 $$ = &tree.JoinTableExpr{ 3903 Left: $1, 3904 JoinType: $2, 3905 Right: $3, 3906 } 3907 } 3908 3909 natural_join: 3910 NATURAL JOIN 3911 { 3912 $$ = tree.JOIN_TYPE_NATURAL 3913 } 3914 | NATURAL outer_join 3915 { 3916 if $2 == tree.JOIN_TYPE_LEFT { 3917 $$ = tree.JOIN_TYPE_NATURAL_LEFT 3918 } else { 3919 $$ = tree.JOIN_TYPE_NATURAL_RIGHT 3920 } 3921 } 3922 3923 outer_join: 3924 LEFT JOIN 3925 { 3926 $$ = tree.JOIN_TYPE_LEFT 3927 } 3928 | LEFT OUTER JOIN 3929 { 3930 $$ = tree.JOIN_TYPE_LEFT 3931 } 3932 | RIGHT JOIN 3933 { 3934 $$ = tree.JOIN_TYPE_RIGHT 3935 } 3936 | RIGHT OUTER JOIN 3937 { 3938 $$ = tree.JOIN_TYPE_RIGHT 3939 } 3940 3941 values_stmt: 3942 VALUES row_constructor_list order_by_opt limit_opt 3943 { 3944 $$ = &tree.ValuesStatement{ 3945 Rows: $2, 3946 OrderBy: $3, 3947 Limit: $4, 3948 } 3949 } 3950 3951 row_constructor_list: 3952 row_constructor 3953 { 3954 $$ = []tree.Exprs{$1} 3955 } 3956 | row_constructor_list ',' row_constructor 3957 { 3958 $$ = append($1, $3) 3959 } 3960 3961 row_constructor: 3962 ROW '(' data_values ')' 3963 { 3964 $$ = $3 3965 } 3966 3967 on_expression_opt: 3968 %prec JOIN 3969 { 3970 $$ = nil 3971 } 3972 | ON expression 3973 { 3974 $$ = &tree.OnJoinCond{Expr: $2} 3975 } 3976 3977 straight_join: 3978 STRAIGHT_JOIN 3979 { 3980 $$ = tree.JOIN_TYPE_STRAIGHT 3981 } 3982 3983 inner_join: 3984 JOIN 3985 { 3986 $$ = tree.JOIN_TYPE_INNER 3987 } 3988 | INNER JOIN 3989 { 3990 $$ = tree.JOIN_TYPE_INNER 3991 } 3992 | CROSS JOIN 3993 { 3994 $$ = tree.JOIN_TYPE_CROSS 3995 } 3996 3997 join_condition_opt: 3998 %prec JOIN 3999 { 4000 $$ = nil 4001 } 4002 | join_condition 4003 { 4004 $$ = $1 4005 } 4006 4007 join_condition: 4008 ON expression 4009 { 4010 $$ = &tree.OnJoinCond{Expr: $2} 4011 } 4012 | USING '(' column_list ')' 4013 { 4014 $$ = &tree.UsingJoinCond{Cols: $3} 4015 } 4016 4017 column_list: 4018 ident 4019 { 4020 $$ = tree.IdentifierList{tree.Identifier($1)} 4021 } 4022 | column_list ',' ident 4023 { 4024 $$ = append($1, tree.Identifier($3)) 4025 } 4026 4027 table_factor: 4028 aliased_table_name 4029 { 4030 $$ = $1 4031 } 4032 | table_subquery as_opt_id column_list_opt 4033 { 4034 $$ = &tree.AliasedTableExpr{ 4035 Expr: $1, 4036 As: tree.AliasClause{ 4037 Alias: tree.Identifier($2), 4038 Cols: $3, 4039 }, 4040 } 4041 } 4042 | table_function as_opt_id 4043 { 4044 if $2 != "" { 4045 $$ = &tree.AliasedTableExpr{ 4046 Expr: $1, 4047 As: tree.AliasClause{ 4048 Alias: tree.Identifier($2), 4049 }, 4050 } 4051 } else { 4052 $$ = $1 4053 } 4054 } 4055 | '(' table_references ')' 4056 { 4057 $$ = $2 4058 } 4059 4060 table_subquery: 4061 select_with_parens %prec SUBQUERY_AS_EXPR 4062 { 4063 $$ = &tree.ParenTableExpr{Expr: $1.(*tree.ParenSelect).Select} 4064 } 4065 4066 table_function: 4067 ident '(' expression_list_opt ')' 4068 { 4069 name := tree.SetUnresolvedName(strings.ToLower($1)) 4070 $$ = &tree.TableFunction{ 4071 Func: &tree.FuncExpr{ 4072 Func: tree.FuncName2ResolvableFunctionReference(name), 4073 Exprs: $3, 4074 Type: tree.FUNC_TYPE_TABLE, 4075 }, 4076 } 4077 } 4078 4079 aliased_table_name: 4080 table_name as_opt_id index_hint_list_opt 4081 { 4082 $$ = &tree.AliasedTableExpr{ 4083 Expr: $1, 4084 As: tree.AliasClause{ 4085 Alias: tree.Identifier($2), 4086 }, 4087 IndexHints: $3, 4088 } 4089 } 4090 4091 index_hint_list_opt: 4092 { 4093 $$ = nil 4094 } 4095 | index_hint_list 4096 4097 index_hint_list: 4098 index_hint 4099 { 4100 $$ = []*tree.IndexHint{$1} 4101 } 4102 | index_hint_list index_hint 4103 { 4104 $$ = append($1, $2) 4105 } 4106 4107 index_hint: 4108 index_hint_type index_hint_scope '(' index_name_list ')' 4109 { 4110 $$ = &tree.IndexHint{ 4111 IndexNames: $4, 4112 HintType: $1, 4113 HintScope: $2, 4114 } 4115 } 4116 4117 index_hint_type: 4118 USE key_or_index 4119 { 4120 $$ = tree.HintUse 4121 } 4122 | IGNORE key_or_index 4123 { 4124 $$ = tree.HintIgnore 4125 } 4126 | FORCE key_or_index 4127 { 4128 $$ = tree.HintForce 4129 } 4130 4131 index_hint_scope: 4132 { 4133 $$ = tree.HintForScan 4134 } 4135 | FOR JOIN 4136 { 4137 $$ = tree.HintForJoin 4138 } 4139 | FOR ORDER BY 4140 { 4141 $$ = tree.HintForOrderBy 4142 } 4143 | FOR GROUP BY 4144 { 4145 $$ = tree.HintForGroupBy 4146 } 4147 4148 index_name_list: 4149 { 4150 $$ = nil 4151 } 4152 | ident 4153 { 4154 $$ = []string{$1} 4155 } 4156 | index_name_list ',' ident 4157 { 4158 $$ = append($1, $3) 4159 } 4160 | PRIMARY 4161 { 4162 $$ = []string{$1} 4163 } 4164 | index_name_list ',' PRIMARY 4165 { 4166 $$ = append($1, $3) 4167 } 4168 4169 as_opt_id: 4170 { 4171 $$ = "" 4172 } 4173 | table_alias 4174 { 4175 $$ = $1 4176 } 4177 | AS table_alias 4178 { 4179 $$ = $2 4180 } 4181 4182 table_alias: 4183 table_id 4184 | STRING 4185 4186 as_name_opt: 4187 { 4188 $$ = "" 4189 } 4190 | ident 4191 { 4192 $$ = $1 4193 } 4194 | AS ident 4195 { 4196 $$ = $2 4197 } 4198 | STRING 4199 { 4200 $$ = $1 4201 } 4202 | AS STRING 4203 { 4204 $$ = $2 4205 } 4206 4207 stmt_name: 4208 ident 4209 4210 database_id: 4211 id_or_var 4212 | non_reserved_keyword 4213 4214 table_id: 4215 id_or_var 4216 | non_reserved_keyword 4217 4218 id_or_var: 4219 ID 4220 | AT_ID 4221 | AT_AT_ID 4222 4223 create_stmt: 4224 create_ddl_stmt 4225 | create_role_stmt 4226 | create_user_stmt 4227 | create_account_stmt 4228 4229 create_ddl_stmt: 4230 create_table_stmt 4231 | create_database_stmt 4232 | create_index_stmt 4233 | create_view_stmt 4234 | create_function_stmt 4235 | create_extension_stmt 4236 4237 create_extension_stmt: 4238 CREATE EXTENSION extension_lang AS extension_name FILE STRING 4239 { 4240 $$ = &tree.CreateExtension{ 4241 Language: $3, 4242 Name: tree.Identifier($5), 4243 Filename: tree.Identifier($7), 4244 } 4245 } 4246 4247 extension_lang: 4248 ident 4249 { 4250 $$ = $1 4251 } 4252 4253 extension_name: 4254 ident 4255 { 4256 $$ = $1 4257 } 4258 4259 4260 create_function_stmt: 4261 CREATE FUNCTION func_name '(' func_args_list_opt ')' RETURNS func_return LANGUAGE func_lang AS STRING 4262 { 4263 $$ = &tree.CreateFunction{ 4264 Name: $3, 4265 Args: $5, 4266 ReturnType: $8, 4267 Language: $10, 4268 Body: $12, 4269 } 4270 } 4271 4272 func_name: 4273 ident 4274 { 4275 prefix := tree.ObjectNamePrefix{ExplicitSchema: false} 4276 $$ = tree.NewFuncName(tree.Identifier($1), prefix) 4277 } 4278 | ident '.' ident 4279 { 4280 prefix := tree.ObjectNamePrefix{SchemaName: tree.Identifier($1), ExplicitSchema: true} 4281 $$ = tree.NewFuncName(tree.Identifier($3), prefix) 4282 } 4283 4284 func_args_list_opt: 4285 { 4286 $$ = tree.FunctionArgs(nil) 4287 } 4288 | func_args_list 4289 4290 func_args_list: 4291 func_arg 4292 { 4293 $$ = tree.FunctionArgs{$1} 4294 } 4295 | func_args_list ',' func_arg 4296 { 4297 $$ = append($1, $3) 4298 } 4299 4300 func_arg: 4301 func_arg_decl 4302 { 4303 $$ = tree.FunctionArg($1) 4304 } 4305 4306 func_arg_decl: 4307 column_type 4308 { 4309 $$ = tree.NewFunctionArgDecl(nil, $1, nil) 4310 } 4311 | column_name column_type 4312 { 4313 $$ = tree.NewFunctionArgDecl($1, $2, nil) 4314 } 4315 | column_name column_type DEFAULT literal 4316 { 4317 $$ = tree.NewFunctionArgDecl($1, $2, $4) 4318 } 4319 4320 func_lang: 4321 ident 4322 { 4323 $$ = $1 4324 } 4325 4326 func_return: 4327 column_type 4328 { 4329 $$ = tree.NewReturnType($1) 4330 } 4331 4332 create_view_stmt: 4333 CREATE VIEW not_exists_opt table_name column_list_opt AS select_stmt 4334 { 4335 $$ = &tree.CreateView{ 4336 Name: $4, 4337 ColNames: $5, 4338 AsSource: $7, 4339 IfNotExists: $3, 4340 } 4341 } 4342 4343 create_account_stmt: 4344 CREATE ACCOUNT not_exists_opt account_name account_auth_option account_status_option account_comment_opt 4345 { 4346 $$ = &tree.CreateAccount{ 4347 IfNotExists:$3, 4348 Name:$4, 4349 AuthOption:$5, 4350 StatusOption:$6, 4351 Comment:$7, 4352 } 4353 } 4354 4355 account_name: 4356 ident 4357 { 4358 $$ = $1 4359 } 4360 4361 account_auth_option: 4362 ADMIN_NAME equal_opt account_admin_name account_identified 4363 { 4364 $$ = tree.AccountAuthOption{ 4365 Equal:$2, 4366 AdminName:$3, 4367 IdentifiedType:$4, 4368 } 4369 } 4370 4371 account_admin_name: 4372 STRING 4373 { 4374 $$ = $1 4375 } 4376 | ident 4377 { 4378 $$ = $1 4379 } 4380 4381 account_identified: 4382 IDENTIFIED BY STRING 4383 { 4384 $$ = tree.AccountIdentified{ 4385 Typ: tree.AccountIdentifiedByPassword, 4386 Str: $3, 4387 } 4388 } 4389 | IDENTIFIED BY RANDOM PASSWORD 4390 { 4391 $$ = tree.AccountIdentified{ 4392 Typ: tree.AccountIdentifiedByRandomPassword, 4393 } 4394 } 4395 | IDENTIFIED WITH STRING 4396 { 4397 $$ = tree.AccountIdentified{ 4398 Typ: tree.AccountIdentifiedWithSSL, 4399 Str: $3, 4400 } 4401 } 4402 4403 account_status_option: 4404 { 4405 $$ = tree.AccountStatus{ 4406 Exist: false, 4407 } 4408 } 4409 | OPEN 4410 { 4411 $$ = tree.AccountStatus{ 4412 Exist: true, 4413 Option: tree.AccountStatusOpen, 4414 } 4415 } 4416 | SUSPEND 4417 { 4418 $$ = tree.AccountStatus{ 4419 Exist: true, 4420 Option: tree.AccountStatusSuspend, 4421 } 4422 } 4423 4424 account_comment_opt: 4425 { 4426 $$ = tree.AccountComment{ 4427 Exist: false, 4428 } 4429 } 4430 | COMMENT_KEYWORD STRING 4431 { 4432 $$ = tree.AccountComment{ 4433 Exist: true, 4434 Comment: $2, 4435 } 4436 } 4437 4438 create_user_stmt: 4439 CREATE USER not_exists_opt user_spec_list_of_create_user default_role_opt pwd_or_lck_opt user_comment_or_attribute_opt 4440 { 4441 $$ = &tree.CreateUser{ 4442 IfNotExists: $3, 4443 Users: $4, 4444 Role: $5, 4445 MiscOpt: $6, 4446 CommentOrAttribute: $7, 4447 } 4448 } 4449 4450 account_role_name: 4451 ID 4452 { 4453 $$ = $1 4454 } 4455 4456 user_comment_or_attribute_opt: 4457 { 4458 $$ = tree.AccountCommentOrAttribute{ 4459 Exist: false, 4460 } 4461 } 4462 | COMMENT_KEYWORD STRING 4463 { 4464 $$ = tree.AccountCommentOrAttribute{ 4465 Exist: true, 4466 IsComment: true, 4467 Str: $2, 4468 } 4469 } 4470 | ATTRIBUTE STRING 4471 { 4472 $$ = tree.AccountCommentOrAttribute{ 4473 Exist: true, 4474 IsComment: false, 4475 Str: $2, 4476 } 4477 } 4478 4479 //conn_options: 4480 // { 4481 // $$ = nil 4482 // } 4483 //| WITH conn_option_list 4484 // { 4485 // $$ = $2 4486 // } 4487 // 4488 //conn_option_list: 4489 // conn_option 4490 // { 4491 // $$ = []tree.ResourceOption{$1} 4492 // } 4493 //| conn_option_list conn_option 4494 // { 4495 // $$ = append($1, $2) 4496 // } 4497 // 4498 //conn_option: 4499 // MAX_QUERIES_PER_HOUR INTEGRAL 4500 // { 4501 // $$ = &tree.ResourceOptionMaxQueriesPerHour{Count: $2.(int64)} 4502 // } 4503 //| MAX_UPDATES_PER_HOUR INTEGRAL 4504 // { 4505 // $$ = &tree.ResourceOptionMaxUpdatesPerHour{Count: $2.(int64)} 4506 // } 4507 //| MAX_CONNECTIONS_PER_HOUR INTEGRAL 4508 // { 4509 // $$ = &tree.ResourceOptionMaxConnectionPerHour{Count: $2.(int64)} 4510 // } 4511 //| MAX_USER_CONNECTIONS INTEGRAL 4512 // { 4513 // $$ = &tree.ResourceOptionMaxUserConnections{Count: $2.(int64)} 4514 // } 4515 4516 4517 //require_clause_opt: 4518 // { 4519 // $$ = nil 4520 // } 4521 //| require_clause 4522 // 4523 //require_clause: 4524 // REQUIRE NONE 4525 // { 4526 // t := &tree.TlsOptionNone{} 4527 // $$ = []tree.TlsOption{t} 4528 // } 4529 //| REQUIRE SSL 4530 // { 4531 // t := &tree.TlsOptionSSL{} 4532 // $$ = []tree.TlsOption{t} 4533 // } 4534 //| REQUIRE X509 4535 // { 4536 // t := &tree.TlsOptionX509{} 4537 // $$ = []tree.TlsOption{t} 4538 // } 4539 //| REQUIRE require_list 4540 // { 4541 // $$ = $2 4542 // } 4543 // 4544 //require_list: 4545 // require_elem 4546 // { 4547 // $$ = []tree.TlsOption{$1} 4548 // } 4549 //| require_list AND require_elem 4550 // { 4551 // $$ = append($1, $3) 4552 // } 4553 //| require_list require_elem 4554 // { 4555 // $$ = append($1, $2) 4556 // } 4557 // 4558 //require_elem: 4559 // ISSUER STRING 4560 // { 4561 // $$ = &tree.TlsOptionIssuer{Issuer: $2} 4562 // } 4563 //| SUBJECT STRING 4564 // { 4565 // $$ = &tree.TlsOptionSubject{Subject: $2} 4566 // } 4567 //| CIPHER STRING 4568 // { 4569 // $$ = &tree.TlsOptionCipher{Cipher: $2} 4570 // } 4571 //| SAN STRING 4572 // { 4573 // $$ = &tree.TlsOptionSan{San: $2} 4574 // } 4575 user_spec_list_of_create_user: 4576 user_spec_with_identified 4577 { 4578 $$ = []*tree.User{$1} 4579 } 4580 | user_spec_list_of_create_user ',' user_spec_with_identified 4581 { 4582 $$ = append($1, $3) 4583 } 4584 4585 user_spec_with_identified: 4586 user_name user_identified 4587 { 4588 $$ = &tree.User{ 4589 Username: $1.Username, 4590 Hostname: $1.Hostname, 4591 AuthOption: $2, 4592 } 4593 } 4594 4595 user_spec_list: 4596 user_spec 4597 { 4598 $$ = []*tree.User{$1} 4599 } 4600 | user_spec_list ',' user_spec 4601 { 4602 $$ = append($1, $3) 4603 } 4604 4605 user_spec: 4606 user_name user_identified_opt 4607 { 4608 $$ = &tree.User{ 4609 Username: $1.Username, 4610 Hostname: $1.Hostname, 4611 AuthOption: $2, 4612 } 4613 } 4614 4615 user_name: 4616 name_string 4617 { 4618 $$ = &tree.UsernameRecord{Username: $1, Hostname: "%"} 4619 } 4620 | name_string '@' name_string 4621 { 4622 $$ = &tree.UsernameRecord{Username: $1, Hostname: $3} 4623 } 4624 | name_string AT_ID 4625 { 4626 $$ = &tree.UsernameRecord{Username: $1, Hostname: $2} 4627 } 4628 4629 user_identified_opt: 4630 { 4631 $$ = nil 4632 } 4633 | user_identified 4634 { 4635 $$ = $1 4636 } 4637 4638 user_identified: 4639 IDENTIFIED BY STRING 4640 { 4641 $$ = &tree.AccountIdentified{ 4642 Typ: tree.AccountIdentifiedByPassword, 4643 Str: $3, 4644 } 4645 } 4646 | IDENTIFIED BY RANDOM PASSWORD 4647 { 4648 $$ = &tree.AccountIdentified{ 4649 Typ: tree.AccountIdentifiedByRandomPassword, 4650 } 4651 } 4652 | IDENTIFIED WITH STRING 4653 { 4654 $$ = &tree.AccountIdentified{ 4655 Typ: tree.AccountIdentifiedWithSSL, 4656 Str: $3, 4657 } 4658 } 4659 4660 name_string: 4661 ident 4662 | STRING 4663 4664 create_role_stmt: 4665 CREATE ROLE not_exists_opt role_spec_list 4666 { 4667 $$ = &tree.CreateRole{ 4668 IfNotExists: $3, 4669 Roles: $4, 4670 } 4671 } 4672 4673 role_spec_list: 4674 role_spec 4675 { 4676 $$ = []*tree.Role{$1} 4677 } 4678 | role_spec_list ',' role_spec 4679 { 4680 $$ = append($1, $3) 4681 } 4682 4683 role_spec: 4684 role_name 4685 { 4686 $$ = &tree.Role{UserName: $1} 4687 } 4688 //| name_string '@' name_string 4689 // { 4690 // $$ = &tree.Role{UserName: $1, HostName: $3} 4691 // } 4692 //| name_string AT_ID 4693 // { 4694 // $$ = &tree.Role{UserName: $1, HostName: $2} 4695 // } 4696 4697 role_name: 4698 ID 4699 | STRING 4700 4701 index_prefix: 4702 { 4703 $$ = tree.INDEX_CATEGORY_NONE 4704 } 4705 | FULLTEXT 4706 { 4707 $$ = tree.INDEX_CATEGORY_FULLTEXT 4708 } 4709 | SPATIAL 4710 { 4711 $$ = tree.INDEX_CATEGORY_SPATIAL 4712 } 4713 | UNIQUE 4714 { 4715 $$ = tree.INDEX_CATEGORY_UNIQUE 4716 } 4717 4718 create_index_stmt: 4719 CREATE index_prefix INDEX id_or_var using_opt ON table_name '(' index_column_list ')' index_option_list 4720 { 4721 var io *tree.IndexOption = nil 4722 if $11 == nil && $5 != tree.INDEX_TYPE_INVALID { 4723 io = &tree.IndexOption{IType: $5} 4724 } else if $11 != nil{ 4725 io = $11 4726 io.IType = $5 4727 } 4728 $$ = &tree.CreateIndex{ 4729 Name: tree.Identifier($4), 4730 Table: *$7, 4731 IndexCat: $2, 4732 KeyParts: $9, 4733 IndexOption: io, 4734 MiscOption: nil, 4735 } 4736 } 4737 4738 index_option_list: 4739 { 4740 $$ = nil 4741 } 4742 | index_option_list index_option 4743 { 4744 // Merge the options 4745 if $1 == nil { 4746 $$ = $2 4747 } else { 4748 opt1 := $1 4749 opt2 := $2 4750 if len(opt2.Comment) > 0 { 4751 opt1.Comment = opt2.Comment 4752 } else if opt2.KeyBlockSize > 0 { 4753 opt1.KeyBlockSize = opt2.KeyBlockSize 4754 } else if len(opt2.ParserName) > 0 { 4755 opt1.ParserName = opt2.ParserName 4756 } else if opt2.Visible != tree.VISIBLE_TYPE_INVALID { 4757 opt1.Visible = opt2.Visible 4758 } 4759 $$ = opt1 4760 } 4761 } 4762 4763 index_option: 4764 KEY_BLOCK_SIZE equal_opt INTEGRAL 4765 { 4766 $$ = &tree.IndexOption{KeyBlockSize: uint64($3.(int64))} 4767 } 4768 | COMMENT_KEYWORD STRING 4769 { 4770 $$ = &tree.IndexOption{Comment: $2} 4771 } 4772 | WITH PARSER id_or_var 4773 { 4774 $$ = &tree.IndexOption{ParserName: $3} 4775 } 4776 | VISIBLE 4777 { 4778 $$ = &tree.IndexOption{Visible: tree.VISIBLE_TYPE_VISIBLE} 4779 } 4780 | INVISIBLE 4781 { 4782 $$ = &tree.IndexOption{Visible: tree.VISIBLE_TYPE_INVISIBLE} 4783 } 4784 4785 index_column_list: 4786 index_column 4787 { 4788 $$ = []*tree.KeyPart{$1} 4789 } 4790 | index_column_list ',' index_column 4791 { 4792 $$ = append($1, $3) 4793 } 4794 4795 index_column: 4796 column_name length_opt asc_desc_opt 4797 { 4798 // Order is parsed but just ignored as MySQL did. 4799 $$ = &tree.KeyPart{ColName: $1, Length: int($2), Direction: $3} 4800 } 4801 | '(' expression ')' asc_desc_opt 4802 { 4803 $$ = &tree.KeyPart{Expr: $2, Direction: $4} 4804 } 4805 4806 using_opt: 4807 { 4808 $$ = tree.INDEX_TYPE_INVALID 4809 } 4810 | USING BTREE 4811 { 4812 $$ = tree.INDEX_TYPE_BTREE 4813 } 4814 | USING HASH 4815 { 4816 $$ = tree.INDEX_TYPE_HASH 4817 } 4818 | USING RTREE 4819 { 4820 $$ = tree.INDEX_TYPE_RTREE 4821 } 4822 | USING BSI 4823 { 4824 $$ = tree.INDEX_TYPE_BSI 4825 } 4826 4827 create_database_stmt: 4828 CREATE database_or_schema not_exists_opt ident create_option_list_opt 4829 { 4830 $$ = &tree.CreateDatabase{ 4831 IfNotExists: $3, 4832 Name: tree.Identifier($4), 4833 CreateOptions: $5, 4834 } 4835 } 4836 // CREATE comment_opt database_or_schema comment_opt not_exists_opt ident 4837 4838 database_or_schema: 4839 DATABASE 4840 | SCHEMA 4841 4842 not_exists_opt: 4843 { 4844 $$ = false 4845 } 4846 | IF NOT EXISTS 4847 { 4848 $$ = true 4849 } 4850 4851 create_option_list_opt: 4852 { 4853 $$ = nil 4854 } 4855 | create_option_list 4856 { 4857 $$ = $1 4858 } 4859 4860 create_option_list: 4861 create_option 4862 { 4863 $$ = []tree.CreateOption{$1} 4864 } 4865 | create_option_list create_option 4866 { 4867 $$ = append($1, $2) 4868 } 4869 4870 create_option: 4871 default_opt charset_keyword equal_opt charset_name 4872 { 4873 $$ = &tree.CreateOptionCharset{IsDefault: $1, Charset: $4} 4874 } 4875 | default_opt COLLATE equal_opt collate_name 4876 { 4877 $$ = &tree.CreateOptionCollate{IsDefault: $1, Collate: $4} 4878 } 4879 | default_opt ENCRYPTION equal_opt STRING 4880 { 4881 $$ = &tree.CreateOptionEncryption{Encrypt: $4} 4882 } 4883 4884 default_opt: 4885 { 4886 $$ = false 4887 } 4888 | DEFAULT 4889 { 4890 $$ = true 4891 } 4892 4893 create_table_stmt: 4894 CREATE temporary_opt TABLE not_exists_opt table_name '(' table_elem_list_opt ')' table_option_list_opt partition_by_opt cluster_by_opt 4895 { 4896 $$ = &tree.CreateTable { 4897 Temporary: $2, 4898 IfNotExists: $4, 4899 Table: *$5, 4900 Defs: $7, 4901 Options: $9, 4902 PartitionOption: $10, 4903 ClusterByOption: $11, 4904 } 4905 } 4906 | CREATE EXTERNAL TABLE not_exists_opt table_name '(' table_elem_list_opt ')' load_param_opt_2 4907 { 4908 $$ = &tree.CreateTable { 4909 IfNotExists: $4, 4910 Table: *$5, 4911 Defs: $7, 4912 Param: $9, 4913 } 4914 } 4915 | CREATE CLUSTER TABLE not_exists_opt table_name '(' table_elem_list_opt ')' table_option_list_opt partition_by_opt cluster_by_opt 4916 { 4917 $$ = &tree.CreateTable { 4918 IsClusterTable: true, 4919 IfNotExists: $4, 4920 Table: *$5, 4921 Defs: $7, 4922 Options: $9, 4923 PartitionOption: $10, 4924 ClusterByOption: $11, 4925 } 4926 } 4927 load_param_opt_2: 4928 load_param_opt tail_param_opt 4929 { 4930 $$ = $1 4931 $$.Tail = $2 4932 } 4933 4934 load_param_opt: 4935 INFILE STRING 4936 { 4937 $$ = &tree.ExternParam{ 4938 ExParamConst: tree.ExParamConst{ 4939 Filepath: $2, 4940 CompressType: tree.AUTO, 4941 Format: tree.CSV, 4942 }, 4943 } 4944 } 4945 | INFILE '{' infile_or_s3_params '}' 4946 { 4947 $$ = &tree.ExternParam{ 4948 ExParamConst: tree.ExParamConst{ 4949 Option: $3, 4950 }, 4951 } 4952 } 4953 | URL S3OPTION '{' infile_or_s3_params '}' 4954 { 4955 $$ = &tree.ExternParam{ 4956 ExParamConst: tree.ExParamConst{ 4957 ScanType: tree.S3, 4958 Option: $4, 4959 }, 4960 } 4961 } 4962 4963 infile_or_s3_params: 4964 infile_or_s3_param 4965 { 4966 $$ = $1 4967 } 4968 | infile_or_s3_params ',' infile_or_s3_param 4969 { 4970 $$ = append($1, $3...) 4971 } 4972 4973 infile_or_s3_param: 4974 { 4975 $$ = []string{} 4976 } 4977 | STRING '=' STRING 4978 { 4979 $$ = append($$, $1) 4980 $$ = append($$, $3) 4981 } 4982 4983 tail_param_opt: 4984 load_fields load_lines ignore_lines columns_or_variable_list_opt load_set_spec_opt 4985 { 4986 $$ = &tree.TailParameter{ 4987 Fields: $1, 4988 Lines: $2, 4989 IgnoredLines: uint64($3), 4990 ColumnList: $4, 4991 Assignments: $5, 4992 } 4993 } 4994 4995 temporary_opt: 4996 { 4997 $$ = false 4998 } 4999 | TEMPORARY 5000 { 5001 $$ = true 5002 } 5003 5004 partition_by_opt: 5005 { 5006 $$ = nil 5007 } 5008 | PARTITION BY partition_method partition_num_opt sub_partition_opt partition_list_opt 5009 { 5010 $3.Num = uint64($4) 5011 $$ = &tree.PartitionOption{ 5012 PartBy: *$3, 5013 SubPartBy: $5, 5014 Partitions: $6, 5015 } 5016 } 5017 5018 cluster_by_opt: 5019 { 5020 $$ = nil 5021 } 5022 | CLUSTER BY column_name 5023 { 5024 $$ = &tree.ClusterByOption{ 5025 ColumnList : []*tree.UnresolvedName{$3}, 5026 } 5027 5028 } 5029 | CLUSTER BY '(' column_name_list ')' 5030 { 5031 $$ = &tree.ClusterByOption{ 5032 ColumnList : $4, 5033 } 5034 } 5035 5036 sub_partition_opt: 5037 { 5038 $$ = nil 5039 } 5040 | SUBPARTITION BY sub_partition_method sub_partition_num_opt 5041 { 5042 $$ = &tree.PartitionBy{ 5043 IsSubPartition: true, 5044 PType: $3, 5045 Num: uint64($4), 5046 } 5047 } 5048 5049 partition_list_opt: 5050 { 5051 $$ = nil 5052 } 5053 | '(' partition_list ')' 5054 { 5055 $$ = $2 5056 } 5057 5058 partition_list: 5059 partition 5060 { 5061 $$ = []*tree.Partition{$1} 5062 } 5063 | partition_list ',' partition 5064 { 5065 $$ = append($1, $3) 5066 } 5067 5068 partition: 5069 PARTITION ID values_opt sub_partition_list_opt 5070 { 5071 $$ = &tree.Partition{ 5072 Name: tree.Identifier($2), 5073 Values: $3, 5074 Options: nil, 5075 Subs: $4, 5076 } 5077 } 5078 | PARTITION ID values_opt partition_option_list sub_partition_list_opt 5079 { 5080 $$ = &tree.Partition{ 5081 Name: tree.Identifier($2), 5082 Values: $3, 5083 Options: $4, 5084 Subs: $5, 5085 } 5086 } 5087 5088 sub_partition_list_opt: 5089 { 5090 $$ = nil 5091 } 5092 | '(' sub_partition_list ')' 5093 { 5094 $$ = $2 5095 } 5096 5097 sub_partition_list: 5098 sub_partition 5099 { 5100 $$ = []*tree.SubPartition{$1} 5101 } 5102 | sub_partition_list ',' sub_partition 5103 { 5104 $$ = append($1, $3) 5105 } 5106 5107 sub_partition: 5108 SUBPARTITION ID 5109 { 5110 $$ = &tree.SubPartition{ 5111 Name: tree.Identifier($2), 5112 Options: nil, 5113 } 5114 } 5115 | SUBPARTITION ID partition_option_list 5116 { 5117 $$ = &tree.SubPartition{ 5118 Name: tree.Identifier($2), 5119 Options: $3, 5120 } 5121 } 5122 5123 partition_option_list: 5124 table_option 5125 { 5126 $$ = []tree.TableOption{$1} 5127 } 5128 | partition_option_list table_option 5129 { 5130 $$ = append($1, $2) 5131 } 5132 5133 values_opt: 5134 { 5135 $$ = nil 5136 } 5137 | VALUES LESS THAN MAXVALUE 5138 { 5139 expr := tree.NewMaxValue() 5140 $$ = &tree.ValuesLessThan{ValueList: tree.Exprs{expr}} 5141 } 5142 | VALUES LESS THAN '(' expression_list ')' 5143 { 5144 $$ = &tree.ValuesLessThan{ValueList: $5} 5145 } 5146 | VALUES IN '(' expression_list ')' 5147 { 5148 $$ = &tree.ValuesIn{ValueList: $4} 5149 } 5150 5151 sub_partition_num_opt: 5152 { 5153 $$ = 0 5154 } 5155 | SUBPARTITIONS INTEGRAL 5156 { 5157 res := $2.(int64) 5158 if res == 0 { 5159 yylex.Error("partitions can not be 0") 5160 return 1 5161 } 5162 $$ = res 5163 } 5164 5165 partition_num_opt: 5166 { 5167 $$ = 0 5168 } 5169 | PARTITIONS INTEGRAL 5170 { 5171 res := $2.(int64) 5172 if res == 0 { 5173 yylex.Error("partitions can not be 0") 5174 return 1 5175 } 5176 $$ = res 5177 } 5178 5179 partition_method: 5180 RANGE '(' bit_expr ')' 5181 { 5182 $$ = &tree.PartitionBy{ 5183 PType: &tree.RangeType{ 5184 Expr: $3, 5185 }, 5186 } 5187 } 5188 | RANGE fields_or_columns '(' column_name_list ')' 5189 { 5190 $$ = &tree.PartitionBy{ 5191 PType: &tree.RangeType{ 5192 ColumnList: $4, 5193 }, 5194 } 5195 } 5196 | LIST '(' bit_expr ')' 5197 { 5198 $$ = &tree.PartitionBy{ 5199 PType: &tree.ListType{ 5200 Expr: $3, 5201 }, 5202 } 5203 } 5204 | LIST fields_or_columns '(' column_name_list ')' 5205 { 5206 $$ = &tree.PartitionBy{ 5207 PType: &tree.ListType{ 5208 ColumnList: $4, 5209 }, 5210 } 5211 } 5212 | sub_partition_method 5213 5214 sub_partition_method: 5215 linear_opt KEY algorithm_opt '(' ')' 5216 { 5217 $$ = &tree.PartitionBy{ 5218 PType: &tree.KeyType{ 5219 Linear: $1, 5220 Algorithm: $3, 5221 }, 5222 } 5223 } 5224 | linear_opt KEY algorithm_opt '(' column_name_list ')' 5225 { 5226 $$ = &tree.PartitionBy{ 5227 PType: &tree.KeyType{ 5228 Linear: $1, 5229 ColumnList: $5, 5230 Algorithm: $3, 5231 }, 5232 } 5233 } 5234 | linear_opt HASH '(' bit_expr ')' 5235 { 5236 $$ = &tree.PartitionBy{ 5237 PType: &tree.HashType{ 5238 Linear: $1, 5239 Expr: $4, 5240 }, 5241 } 5242 } 5243 5244 algorithm_opt: 5245 { 5246 $$ = 2 5247 } 5248 | ALGORITHM '=' INTEGRAL 5249 { 5250 $$ = $3.(int64) 5251 } 5252 5253 linear_opt: 5254 { 5255 $$ = false 5256 } 5257 | LINEAR 5258 { 5259 $$ = true 5260 } 5261 5262 table_option_list_opt: 5263 { 5264 $$ = nil 5265 } 5266 | table_option_list 5267 { 5268 $$ = $1 5269 } 5270 5271 table_option_list: 5272 table_option 5273 { 5274 $$ = []tree.TableOption{$1} 5275 } 5276 | table_option_list ',' table_option 5277 { 5278 $$ = append($1, $3) 5279 } 5280 | table_option_list table_option 5281 { 5282 $$ = append($1, $2) 5283 } 5284 5285 table_option: 5286 AUTO_INCREMENT equal_opt INTEGRAL 5287 { 5288 $$ = tree.NewTableOptionAutoIncrement(uint64($3.(int64))) 5289 } 5290 | AVG_ROW_LENGTH equal_opt INTEGRAL 5291 { 5292 $$ = tree.NewTableOptionAvgRowLength(uint64($3.(int64))) 5293 } 5294 | default_opt charset_keyword equal_opt charset_name 5295 { 5296 $$ = tree.NewTableOptionCharset($4) 5297 } 5298 | default_opt COLLATE equal_opt charset_name 5299 { 5300 $$ = tree.NewTableOptionCollate($4) 5301 } 5302 | CHECKSUM equal_opt INTEGRAL 5303 { 5304 $$ = tree.NewTableOptionChecksum(uint64($3.(int64))) 5305 } 5306 | COMMENT_KEYWORD equal_opt STRING 5307 { 5308 str := util.DealCommentString($3) 5309 $$ = tree.NewTableOptionComment(str) 5310 } 5311 | COMPRESSION equal_opt STRING 5312 { 5313 $$ = tree.NewTableOptionCompression($3) 5314 } 5315 | CONNECTION equal_opt STRING 5316 { 5317 $$ = tree.NewTableOptionConnection($3) 5318 } 5319 | DATA DIRECTORY equal_opt STRING 5320 { 5321 $$ = tree.NewTableOptionDataDirectory($4) 5322 } 5323 | INDEX DIRECTORY equal_opt STRING 5324 { 5325 $$ = tree.NewTableOptionIndexDirectory($4) 5326 } 5327 | DELAY_KEY_WRITE equal_opt INTEGRAL 5328 { 5329 $$ = tree.NewTableOptionDelayKeyWrite(uint64($3.(int64))) 5330 } 5331 | ENCRYPTION equal_opt STRING 5332 { 5333 $$ = tree.NewTableOptionEncryption($3) 5334 } 5335 | ENGINE equal_opt table_alias 5336 { 5337 $$ = tree.NewTableOptionEngine($3) 5338 } 5339 | KEY_BLOCK_SIZE equal_opt INTEGRAL 5340 { 5341 $$ = tree.NewTableOptionKeyBlockSize(uint64($3.(int64))) 5342 } 5343 | MAX_ROWS equal_opt INTEGRAL 5344 { 5345 $$ = tree.NewTableOptionMaxRows(uint64($3.(int64))) 5346 } 5347 | MIN_ROWS equal_opt INTEGRAL 5348 { 5349 $$ = tree.NewTableOptionMinRows(uint64($3.(int64))) 5350 } 5351 | PACK_KEYS equal_opt INTEGRAL 5352 { 5353 $$ = &tree.TableOptionPackKeys{Value: $3.(int64)} 5354 } 5355 | PACK_KEYS equal_opt DEFAULT 5356 { 5357 $$ = &tree.TableOptionPackKeys{Default: true} 5358 } 5359 | PASSWORD equal_opt STRING 5360 { 5361 $$ = tree.NewTableOptionPassword($3) 5362 } 5363 | ROW_FORMAT equal_opt row_format_options 5364 { 5365 $$ = tree.NewTableOptionRowFormat($3) 5366 } 5367 | STATS_AUTO_RECALC equal_opt INTEGRAL 5368 { 5369 $$ = &tree.TableOptionStatsAutoRecalc{Value: uint64($3.(int64))} 5370 } 5371 | STATS_AUTO_RECALC equal_opt DEFAULT 5372 { 5373 $$ = &tree.TableOptionStatsAutoRecalc{Default: true} 5374 } 5375 | STATS_PERSISTENT equal_opt INTEGRAL 5376 { 5377 $$ = &tree.TableOptionStatsPersistent{Value: uint64($3.(int64))} 5378 } 5379 | STATS_PERSISTENT equal_opt DEFAULT 5380 { 5381 $$ = &tree.TableOptionStatsPersistent{Default: true} 5382 } 5383 | STATS_SAMPLE_PAGES equal_opt INTEGRAL 5384 { 5385 $$ = &tree.TableOptionStatsSamplePages{Value: uint64($3.(int64))} 5386 } 5387 | STATS_SAMPLE_PAGES equal_opt DEFAULT 5388 { 5389 $$ = &tree.TableOptionStatsSamplePages{Default: true} 5390 } 5391 | TABLESPACE equal_opt ident storage_opt 5392 { 5393 $$= tree.NewTableOptionTablespace($3, $4) 5394 } 5395 | UNION equal_opt '(' table_name_list ')' 5396 { 5397 $$= tree.NewTableOptionUnion($4) 5398 } 5399 | PROPERTIES '(' properties_list ')' 5400 { 5401 $$ = &tree.TableOptionProperties{Preperties: $3} 5402 } 5403 // | INSERT_METHOD equal_opt insert_method_options 5404 5405 properties_list: 5406 property_elem 5407 { 5408 $$ = []tree.Property{$1} 5409 } 5410 | properties_list ',' property_elem 5411 { 5412 $$ = append($1, $3) 5413 } 5414 5415 property_elem: 5416 STRING '=' STRING 5417 { 5418 $$ = tree.Property{Key: $1, Value: $3} 5419 } 5420 5421 storage_opt: 5422 { 5423 $$ = "" 5424 } 5425 | STORAGE DISK 5426 { 5427 $$ = " " + $1 + " " + $2 5428 } 5429 | STORAGE MEMORY 5430 { 5431 $$ = " " + $1 + " " + $2 5432 } 5433 5434 row_format_options: 5435 DEFAULT 5436 { 5437 $$ = tree.ROW_FORMAT_DEFAULT 5438 } 5439 | DYNAMIC 5440 { 5441 $$ = tree.ROW_FORMAT_DYNAMIC 5442 } 5443 | FIXED 5444 { 5445 $$ = tree.ROW_FORMAT_FIXED 5446 } 5447 | COMPRESSED 5448 { 5449 $$ = tree.ROW_FORMAT_COMPRESSED 5450 } 5451 | REDUNDANT 5452 { 5453 $$ = tree.ROW_FORMAT_REDUNDANT 5454 } 5455 | COMPACT 5456 { 5457 $$ = tree.ROW_FORMAT_COMPACT 5458 } 5459 5460 charset_name: 5461 name_string 5462 | BINARY 5463 5464 collate_name: 5465 name_string 5466 | BINARY 5467 5468 table_name_list: 5469 table_name 5470 { 5471 $$ = tree.TableNames{$1} 5472 } 5473 | table_name_list ',' table_name 5474 { 5475 $$ = append($1, $3) 5476 } 5477 5478 // Accepted patterns: 5479 // <table> 5480 // <schema>.<table> 5481 table_name: 5482 ident 5483 { 5484 prefix := tree.ObjectNamePrefix{ExplicitSchema: false} 5485 $$ = tree.NewTableName(tree.Identifier($1), prefix) 5486 } 5487 | ident '.' ident 5488 { 5489 prefix := tree.ObjectNamePrefix{SchemaName: tree.Identifier($1), ExplicitSchema: true} 5490 $$ = tree.NewTableName(tree.Identifier($3), prefix) 5491 } 5492 5493 table_elem_list_opt: 5494 { 5495 $$ = tree.TableDefs(nil) 5496 } 5497 | table_elem_list 5498 5499 table_elem_list: 5500 table_elem 5501 { 5502 $$ = tree.TableDefs{$1} 5503 } 5504 | table_elem_list ',' table_elem 5505 { 5506 $$ = append($1, $3) 5507 } 5508 5509 table_elem: 5510 column_def 5511 { 5512 $$ = tree.TableDef($1) 5513 } 5514 | constaint_def 5515 { 5516 $$ = $1 5517 } 5518 5519 constaint_def: 5520 constraint_keyword constraint_elem 5521 { 5522 if $1 != "" { 5523 switch v := $2.(type) { 5524 case *tree.PrimaryKeyIndex: 5525 v.Name = $1 5526 case *tree.ForeignKey: 5527 v.Name = $1 5528 } 5529 } 5530 $$ = $2 5531 } 5532 | constraint_elem 5533 { 5534 $$ = $1 5535 } 5536 5537 constraint_elem: 5538 PRIMARY KEY index_name_and_type_opt '(' index_column_list ')' index_option_list 5539 { 5540 $$ = &tree.PrimaryKeyIndex{ 5541 KeyParts: $5, 5542 Name: $3[0], 5543 Empty: $3[1] == "", 5544 IndexOption: $7, 5545 } 5546 } 5547 | FULLTEXT key_or_index_opt index_name '(' index_column_list ')' index_option_list 5548 { 5549 $$ = &tree.FullTextIndex{ 5550 KeyParts: $5, 5551 Name: $3, 5552 Empty: true, 5553 IndexOption: $7, 5554 } 5555 } 5556 | key_or_index not_exists_opt index_name_and_type_opt '(' index_column_list ')' index_option_list 5557 { 5558 keyTyp := tree.INDEX_TYPE_INVALID 5559 if $3[1] != "" { 5560 t := strings.ToLower($3[1]) 5561 switch t { 5562 case "zonemap": 5563 keyTyp = tree.INDEX_TYPE_ZONEMAP 5564 case "bsi": 5565 keyTyp = tree.INDEX_TYPE_BSI 5566 default: 5567 yylex.Error("Invail the type of index") 5568 return 1 5569 } 5570 } 5571 $$ = &tree.Index{ 5572 IfNotExists: $2, 5573 KeyParts: $5, 5574 Name: $3[0], 5575 KeyType: keyTyp, 5576 IndexOption: $7, 5577 } 5578 } 5579 | UNIQUE key_or_index_opt index_name_and_type_opt '(' index_column_list ')' index_option_list 5580 { 5581 $$ = &tree.UniqueIndex{ 5582 KeyParts: $5, 5583 Name: $3[0], 5584 Empty: $3[1] == "", 5585 IndexOption: $7, 5586 } 5587 } 5588 | FOREIGN KEY not_exists_opt index_name '(' index_column_list ')' references_def 5589 { 5590 $$ = &tree.ForeignKey{ 5591 IfNotExists: $3, 5592 KeyParts: $6, 5593 Name: $4, 5594 Refer: $8, 5595 Empty: true, 5596 } 5597 } 5598 | CHECK '(' expression ')' enforce_opt 5599 { 5600 $$ = &tree.CheckIndex{ 5601 Expr: $3, 5602 Enforced: $5, 5603 } 5604 } 5605 5606 enforce_opt: 5607 { 5608 $$ = false 5609 } 5610 | enforce 5611 5612 key_or_index_opt: 5613 { 5614 $$ = "" 5615 } 5616 | key_or_index 5617 { 5618 $$ = $1 5619 } 5620 5621 key_or_index: 5622 KEY 5623 | INDEX 5624 5625 index_name_and_type_opt: 5626 index_name 5627 { 5628 $$ = make([]string, 2) 5629 $$[0] = $1 5630 $$[1] = "" 5631 } 5632 | index_name USING index_type 5633 { 5634 $$ = make([]string, 2) 5635 $$[0] = $1 5636 $$[1] = $3 5637 } 5638 | ident TYPE index_type 5639 { 5640 $$ = make([]string, 2) 5641 $$[0] = $1 5642 $$[1] = $3 5643 } 5644 5645 index_type: 5646 BTREE 5647 | HASH 5648 | RTREE 5649 | ZONEMAP 5650 | BSI 5651 5652 index_name: 5653 { 5654 $$ = "" 5655 } 5656 | ident 5657 5658 column_def: 5659 column_name column_type column_attribute_list_opt 5660 { 5661 $$ = tree.NewColumnTableDef($1, $2, $3) 5662 } 5663 5664 column_name_unresolved: 5665 ident 5666 { 5667 $$ = tree.SetUnresolvedName($1) 5668 } 5669 | ident '.' ident 5670 { 5671 $$ = tree.SetUnresolvedName($1, $3) 5672 } 5673 | ident '.' ident '.' ident 5674 { 5675 $$ = tree.SetUnresolvedName($1, $3, $5) 5676 } 5677 5678 ident: 5679 ID 5680 | not_keyword 5681 | non_reserved_keyword 5682 5683 column_name: 5684 ident 5685 { 5686 $$ = tree.SetUnresolvedName($1) 5687 } 5688 | ident '.' reserved_sql_id 5689 { 5690 $$ = tree.SetUnresolvedName($1, $3) 5691 } 5692 | ident '.' reserved_table_id '.' reserved_sql_id 5693 { 5694 $$ = tree.SetUnresolvedName($1, $3, $5) 5695 } 5696 5697 column_attribute_list_opt: 5698 { 5699 $$ = nil 5700 } 5701 | column_attribute_list 5702 { 5703 $$ = $1 5704 } 5705 5706 column_attribute_list: 5707 column_attribute_elem 5708 { 5709 $$ = []tree.ColumnAttribute{$1} 5710 } 5711 | column_attribute_list column_attribute_elem 5712 { 5713 $$ = append($1, $2) 5714 } 5715 5716 column_attribute_elem: 5717 NULL 5718 { 5719 $$ = tree.NewAttributeNull(true) 5720 } 5721 | NOT NULL 5722 { 5723 $$ = tree.NewAttributeNull(false) 5724 } 5725 | DEFAULT bit_expr 5726 { 5727 $$ = tree.NewAttributeDefault($2) 5728 } 5729 | AUTO_INCREMENT 5730 { 5731 $$ = tree.NewAttributeAutoIncrement() 5732 } 5733 | keys 5734 { 5735 $$ = $1 5736 } 5737 | COMMENT_KEYWORD STRING 5738 { 5739 str := util.DealCommentString($2) 5740 $$ = tree.NewAttributeComment(tree.NewNumValWithType(constant.MakeString(str), str, false, tree.P_char)) 5741 } 5742 | COLLATE collate_name 5743 { 5744 $$ = tree.NewAttributeCollate($2) 5745 } 5746 | COLUMN_FORMAT column_format 5747 { 5748 $$ = tree.NewAttributeColumnFormat($2) 5749 } 5750 | STORAGE storage_media 5751 { 5752 $$ = tree.NewAttributeStorage($2) 5753 } 5754 | AUTO_RANDOM field_length_opt 5755 { 5756 $$ = tree.NewAttributeAutoRandom(int($2)) 5757 } 5758 | references_def 5759 { 5760 $$ = $1 5761 } 5762 | constraint_keyword_opt CHECK '(' expression ')' 5763 { 5764 $$ = tree.NewAttributeCheck($4, false, $1) 5765 } 5766 | constraint_keyword_opt CHECK '(' expression ')' enforce 5767 { 5768 $$ = tree.NewAttributeCheck($4, $6, $1) 5769 } 5770 | ON UPDATE name_datetime_precision datetime_precision_opt 5771 { 5772 name := tree.SetUnresolvedName(strings.ToLower($3)) 5773 var es tree.Exprs = nil 5774 if $4 != nil { 5775 es = append(es, $4) 5776 } 5777 expr := &tree.FuncExpr{ 5778 Func: tree.FuncName2ResolvableFunctionReference(name), 5779 Exprs: es, 5780 } 5781 $$ = tree.NewAttributeOnUpdate(expr) 5782 } 5783 | LOW_CARDINALITY 5784 { 5785 $$ = tree.NewAttributeLowCardinality() 5786 } 5787 5788 enforce: 5789 ENFORCED 5790 { 5791 $$ = true 5792 } 5793 | NOT ENFORCED 5794 { 5795 $$ = false 5796 } 5797 5798 constraint_keyword_opt: 5799 { 5800 $$ = "" 5801 } 5802 | constraint_keyword 5803 { 5804 $$ = $1 5805 } 5806 5807 constraint_keyword: 5808 CONSTRAINT 5809 { 5810 $$ = "" 5811 } 5812 | CONSTRAINT ident 5813 { 5814 $$ = $2 5815 } 5816 5817 references_def: 5818 REFERENCES table_name index_column_list_opt match_opt on_delete_update_opt 5819 { 5820 $$ = &tree.AttributeReference{ 5821 TableName: $2, 5822 KeyParts: $3, 5823 Match: $4, 5824 OnDelete: $5.OnDelete, 5825 OnUpdate: $5.OnUpdate, 5826 } 5827 } 5828 5829 on_delete_update_opt: 5830 %prec LOWER_THAN_ON 5831 { 5832 $$ = &tree.ReferenceOnRecord{ 5833 OnDelete: tree.REFERENCE_OPTION_INVALID, 5834 OnUpdate: tree.REFERENCE_OPTION_INVALID, 5835 } 5836 } 5837 | on_delete %prec LOWER_THAN_ON 5838 { 5839 $$ = &tree.ReferenceOnRecord{ 5840 OnDelete: $1, 5841 OnUpdate: tree.REFERENCE_OPTION_INVALID, 5842 } 5843 } 5844 | on_update %prec LOWER_THAN_ON 5845 { 5846 $$ = &tree.ReferenceOnRecord{ 5847 OnDelete: tree.REFERENCE_OPTION_INVALID, 5848 OnUpdate: $1, 5849 } 5850 } 5851 | on_delete on_update 5852 { 5853 $$ = &tree.ReferenceOnRecord{ 5854 OnDelete: $1, 5855 OnUpdate: $2, 5856 } 5857 } 5858 | on_update on_delete 5859 { 5860 $$ = &tree.ReferenceOnRecord{ 5861 OnDelete: $2, 5862 OnUpdate: $1, 5863 } 5864 } 5865 5866 on_delete: 5867 ON DELETE ref_opt 5868 { 5869 $$ = $3 5870 } 5871 5872 on_update: 5873 ON UPDATE ref_opt 5874 { 5875 $$ = $3 5876 } 5877 5878 ref_opt: 5879 RESTRICT 5880 { 5881 $$ = tree.REFERENCE_OPTION_RESTRICT 5882 } 5883 | CASCADE 5884 { 5885 $$ = tree.REFERENCE_OPTION_CASCADE 5886 } 5887 | SET NULL 5888 { 5889 $$ = tree.REFERENCE_OPTION_SET_NULL 5890 } 5891 | NO ACTION 5892 { 5893 $$ = tree.REFERENCE_OPTION_NO_ACTION 5894 } 5895 | SET DEFAULT 5896 { 5897 $$ = tree.REFERENCE_OPTION_SET_DEFAULT 5898 } 5899 5900 match_opt: 5901 { 5902 $$ = tree.MATCH_INVALID 5903 } 5904 | match 5905 5906 match: 5907 MATCH FULL 5908 { 5909 $$ = tree.MATCH_FULL 5910 } 5911 | MATCH PARTIAL 5912 { 5913 $$ = tree.MATCH_PARTIAL 5914 } 5915 | MATCH SIMPLE 5916 { 5917 $$ = tree.MATCH_SIMPLE 5918 } 5919 5920 index_column_list_opt: 5921 { 5922 $$ = nil 5923 } 5924 | '(' index_column_list ')' 5925 { 5926 $$ = $2 5927 } 5928 5929 field_length_opt: 5930 { 5931 $$ = -1 5932 } 5933 | '(' INTEGRAL ')' 5934 { 5935 $$ = $2.(int64) 5936 } 5937 5938 storage_media: 5939 DEFAULT 5940 | DISK 5941 | MEMORY 5942 5943 column_format: 5944 DEFAULT 5945 | FIXED 5946 | DYNAMIC 5947 5948 subquery: 5949 select_with_parens %prec SUBQUERY_AS_EXPR 5950 { 5951 $$ = &tree.Subquery{Select: $1, Exists: false} 5952 } 5953 5954 bit_expr: 5955 bit_expr '&' bit_expr %prec '&' 5956 { 5957 $$ = tree.NewBinaryExpr(tree.BIT_AND, $1, $3) 5958 } 5959 | bit_expr '|' bit_expr %prec '|' 5960 { 5961 $$ = tree.NewBinaryExpr(tree.BIT_OR, $1, $3) 5962 } 5963 | bit_expr '^' bit_expr %prec '^' 5964 { 5965 $$ = tree.NewBinaryExpr(tree.BIT_XOR, $1, $3) 5966 } 5967 | bit_expr '+' bit_expr %prec '+' 5968 { 5969 $$ = tree.NewBinaryExpr(tree.PLUS, $1, $3) 5970 } 5971 | bit_expr '-' bit_expr %prec '-' 5972 { 5973 $$ = tree.NewBinaryExpr(tree.MINUS, $1, $3) 5974 } 5975 | bit_expr '*' bit_expr %prec '*' 5976 { 5977 $$ = tree.NewBinaryExpr(tree.MULTI, $1, $3) 5978 } 5979 | bit_expr '/' bit_expr %prec '/' 5980 { 5981 $$ = tree.NewBinaryExpr(tree.DIV, $1, $3) 5982 } 5983 | bit_expr DIV bit_expr %prec DIV 5984 { 5985 $$ = tree.NewBinaryExpr(tree.INTEGER_DIV, $1, $3) 5986 } 5987 | bit_expr '%' bit_expr %prec '%' 5988 { 5989 $$ = tree.NewBinaryExpr(tree.MOD, $1, $3) 5990 } 5991 | bit_expr MOD bit_expr %prec MOD 5992 { 5993 $$ = tree.NewBinaryExpr(tree.MOD, $1, $3) 5994 } 5995 | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT 5996 { 5997 $$ = tree.NewBinaryExpr(tree.LEFT_SHIFT, $1, $3) 5998 } 5999 | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT 6000 { 6001 $$ = tree.NewBinaryExpr(tree.RIGHT_SHIFT, $1, $3) 6002 } 6003 | simple_expr 6004 { 6005 $$ = $1 6006 } 6007 6008 simple_expr: 6009 normal_ident 6010 { 6011 $$ = $1 6012 } 6013 | variable 6014 { 6015 $$ = $1 6016 } 6017 | literal 6018 { 6019 $$ = $1 6020 } 6021 | '(' expression ')' 6022 { 6023 $$ = tree.NewParenExpr($2) 6024 } 6025 | '(' expression_list ',' expression ')' 6026 { 6027 $$ = tree.NewTuple(append($2, $4)) 6028 } 6029 | '+' simple_expr %prec UNARY 6030 { 6031 $$ = tree.NewUnaryExpr(tree.UNARY_PLUS, $2) 6032 } 6033 | '-' simple_expr %prec UNARY 6034 { 6035 $$ = tree.NewUnaryExpr(tree.UNARY_MINUS, $2) 6036 } 6037 | '~' simple_expr 6038 { 6039 $$ = tree.NewUnaryExpr(tree.UNARY_TILDE, $2) 6040 } 6041 | '!' simple_expr %prec UNARY 6042 { 6043 $$ = tree.NewUnaryExpr(tree.UNARY_MARK, $2) 6044 } 6045 | interval_expr 6046 { 6047 $$ = $1 6048 } 6049 | subquery 6050 { 6051 $$ = $1 6052 } 6053 | EXISTS subquery 6054 { 6055 $2.Exists = true 6056 $$ = $2 6057 } 6058 | CASE expression_opt when_clause_list else_opt END 6059 { 6060 $$ = &tree.CaseExpr{ 6061 Expr: $2, 6062 Whens: $3, 6063 Else: $4, 6064 } 6065 } 6066 | CAST '(' expression AS mo_cast_type ')' 6067 { 6068 $$ = tree.NewCastExpr($3, $5) 6069 } 6070 | BINARY '(' expression ')' 6071 { 6072 locale := "" 6073 $$ = tree.NewCastExpr($3, &tree.T{ 6074 InternalType: tree.InternalType{ 6075 Family: tree.StringFamily, 6076 FamilyString: "BINARY", 6077 Locale: &locale, 6078 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 6079 }, 6080 }) 6081 } 6082 | CONVERT '(' expression ',' mysql_cast_type ')' 6083 { 6084 $$ = tree.NewCastExpr($3, $5) 6085 } 6086 | CONVERT '(' expression USING charset_name ')' 6087 { 6088 name := tree.SetUnresolvedName("convert") 6089 es := tree.NewNumValWithType(constant.MakeString($5), $5, false, tree.P_char) 6090 $$ = &tree.FuncExpr{ 6091 Func: tree.FuncName2ResolvableFunctionReference(name), 6092 Exprs: tree.Exprs{$3, es}, 6093 } 6094 } 6095 | function_call_generic 6096 { 6097 $$ = $1 6098 } 6099 | function_call_keyword 6100 { 6101 $$ = $1 6102 } 6103 | function_call_nonkeyword 6104 { 6105 $$ = $1 6106 } 6107 | function_call_aggregate 6108 { 6109 $$ = $1 6110 } 6111 6112 else_opt: 6113 { 6114 $$ = nil 6115 } 6116 | ELSE expression 6117 { 6118 $$ = $2 6119 } 6120 6121 expression_opt: 6122 { 6123 $$ = nil 6124 } 6125 | expression 6126 { 6127 $$ = $1 6128 } 6129 6130 when_clause_list: 6131 when_clause 6132 { 6133 $$ = []*tree.When{$1} 6134 } 6135 | when_clause_list when_clause 6136 { 6137 $$ = append($1, $2) 6138 } 6139 6140 when_clause: 6141 WHEN expression THEN expression 6142 { 6143 $$ = &tree.When{ 6144 Cond: $2, 6145 Val: $4, 6146 } 6147 } 6148 6149 mo_cast_type: 6150 column_type 6151 | SIGNED integer_opt 6152 { 6153 name := $1 6154 if $2 != "" { 6155 name = $2 6156 } 6157 locale := "" 6158 $$ = &tree.T{ 6159 InternalType: tree.InternalType{ 6160 Family: tree.IntFamily, 6161 FamilyString: name, 6162 Width: 64, 6163 Locale: &locale, 6164 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 6165 }, 6166 } 6167 } 6168 | UNSIGNED integer_opt 6169 { 6170 locale := "" 6171 $$ = &tree.T{ 6172 InternalType: tree.InternalType{ 6173 Family: tree.IntFamily, 6174 FamilyString: $2, 6175 Width: 64, 6176 Locale: &locale, 6177 Unsigned: true, 6178 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 6179 }, 6180 } 6181 } 6182 6183 mysql_cast_type: 6184 decimal_type 6185 | BINARY length_opt 6186 { 6187 locale := "" 6188 $$ = &tree.T{ 6189 InternalType: tree.InternalType{ 6190 Family: tree.StringFamily, 6191 FamilyString: $1, 6192 Locale: &locale, 6193 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 6194 DisplayWith: $2, 6195 }, 6196 } 6197 } 6198 | CHAR length_option_opt 6199 { 6200 locale := "" 6201 $$ = &tree.T{ 6202 InternalType: tree.InternalType{ 6203 Family: tree.StringFamily, 6204 FamilyString: $1, 6205 Locale: &locale, 6206 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 6207 DisplayWith: $2, 6208 }, 6209 } 6210 } 6211 | DATE 6212 { 6213 locale := "" 6214 $$ = &tree.T{ 6215 InternalType: tree.InternalType{ 6216 Family: tree.DateFamily, 6217 FamilyString: $1, 6218 Locale: &locale, 6219 Oid: uint32(defines.MYSQL_TYPE_DATE), 6220 }, 6221 } 6222 } 6223 | YEAR length_opt 6224 { 6225 locale := "" 6226 $$ = &tree.T{ 6227 InternalType: tree.InternalType{ 6228 Family: tree.IntFamily, 6229 FamilyString: $1, 6230 DisplayWith: $2, 6231 Width: 16, 6232 Locale: &locale, 6233 Oid: uint32(defines.MYSQL_TYPE_YEAR), 6234 }, 6235 } 6236 } 6237 | DATETIME timestamp_option_opt 6238 { 6239 locale := "" 6240 $$ = &tree.T{ 6241 InternalType: tree.InternalType{ 6242 Family: tree.TimestampFamily, 6243 Precision: $2, 6244 FamilyString: $1, 6245 DisplayWith: $2, 6246 TimePrecisionIsSet: false, 6247 Locale: &locale, 6248 Oid: uint32(defines.MYSQL_TYPE_DATETIME), 6249 }, 6250 } 6251 } 6252 | TIME length_opt 6253 { 6254 locale := "" 6255 $$ = &tree.T{ 6256 InternalType: tree.InternalType{ 6257 Family: tree.TimeFamily, 6258 FamilyString: $1, 6259 DisplayWith: $2, 6260 Precision: $2, 6261 TimePrecisionIsSet: false, 6262 Locale: &locale, 6263 Oid: uint32(defines.MYSQL_TYPE_TIME), 6264 }, 6265 } 6266 } 6267 | SIGNED integer_opt 6268 { 6269 name := $1 6270 if $2 != "" { 6271 name = $2 6272 } 6273 locale := "" 6274 $$ = &tree.T{ 6275 InternalType: tree.InternalType{ 6276 Family: tree.IntFamily, 6277 FamilyString: name, 6278 Width: 64, 6279 Locale: &locale, 6280 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 6281 }, 6282 } 6283 } 6284 | UNSIGNED integer_opt 6285 { 6286 locale := "" 6287 $$ = &tree.T{ 6288 InternalType: tree.InternalType{ 6289 Family: tree.IntFamily, 6290 FamilyString: $2, 6291 Width: 64, 6292 Locale: &locale, 6293 Unsigned: true, 6294 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 6295 }, 6296 } 6297 } 6298 6299 integer_opt: 6300 {} 6301 | INTEGER 6302 | INT 6303 6304 window_frame_bound: 6305 CURRENT ROW 6306 { 6307 $$ = &tree.WindowFrameBoundCurrentRow{} 6308 } 6309 | UNBOUNDED PRECEDING 6310 { 6311 $$ = &tree.WindowFrameBoundPreceding{} 6312 } 6313 | expression PRECEDING 6314 { 6315 $$ = &tree.WindowFrameBoundPreceding{ 6316 Expr: $1, 6317 } 6318 } 6319 | UNBOUNDED FOLLOWING 6320 { 6321 $$ = &tree.WindowFrameBoundFollowing{} 6322 } 6323 | expression FOLLOWING 6324 { 6325 $$ = &tree.WindowFrameBoundFollowing{ 6326 Expr: $1, 6327 } 6328 } 6329 6330 window_frame_unit: 6331 ROWS 6332 { 6333 $$ = tree.WIN_FRAME_UNIT_ROWS 6334 } 6335 | RANGE 6336 { 6337 $$ = tree.WIN_FRAME_UNIT_RANGE 6338 } 6339 | GROUPS 6340 { 6341 $$ = tree.WIN_FRAME_UNIT_GROUPS 6342 } 6343 6344 window_frame: 6345 window_frame_unit window_frame_bound 6346 { 6347 $$ = &tree.WindowFrame{ 6348 Unit: $1, 6349 StartBound: $2, 6350 } 6351 } 6352 | window_frame_unit BETWEEN window_frame_bound AND window_frame_bound 6353 { 6354 $$ = &tree.WindowFrame{ 6355 Unit: $1, 6356 StartBound: $3, 6357 EndBound: $5, 6358 } 6359 } 6360 6361 window_frame_opt: 6362 { 6363 $$ = nil 6364 } 6365 | window_frame 6366 { 6367 $$ = $1 6368 } 6369 6370 6371 window_partition_by: 6372 PARTITION BY expression_list 6373 { 6374 $$ = $3 6375 } 6376 6377 window_partition_by_opt: 6378 { 6379 $$ = nil 6380 } 6381 | window_partition_by 6382 { 6383 $$ = $1 6384 } 6385 6386 separator_opt: 6387 { 6388 $$ = "," 6389 } 6390 | SEPARATOR STRING 6391 { 6392 $$ = $2 6393 } 6394 6395 window_spec_opt: 6396 { 6397 $$ = nil 6398 } 6399 | OVER '(' window_partition_by_opt order_by_opt window_frame_opt ')' 6400 { 6401 $$ = &tree.WindowSpec{ 6402 PartitionBy: $3, 6403 OrderBy: $4, 6404 WindowFrame: $5, 6405 } 6406 } 6407 6408 function_call_aggregate: 6409 GROUP_CONCAT '(' func_type_opt expression_list order_by_opt separator_opt ')' window_spec_opt 6410 { 6411 name := tree.SetUnresolvedName(strings.ToLower($1)) 6412 $$ = &tree.FuncExpr{ 6413 Func: tree.FuncName2ResolvableFunctionReference(name), 6414 Exprs: append($4,tree.NewNumValWithType(constant.MakeString($6), $6, false, tree.P_char)), 6415 Type: $3, 6416 WindowSpec: $8, 6417 AggType: 2, 6418 } 6419 } 6420 | AVG '(' func_type_opt expression ')' window_spec_opt 6421 { 6422 name := tree.SetUnresolvedName(strings.ToLower($1)) 6423 $$ = &tree.FuncExpr{ 6424 Func: tree.FuncName2ResolvableFunctionReference(name), 6425 Exprs: tree.Exprs{$4}, 6426 Type: $3, 6427 WindowSpec: $6, 6428 } 6429 } 6430 | APPROX_COUNT_DISTINCT '(' expression_list ')' window_spec_opt 6431 { 6432 name := tree.SetUnresolvedName(strings.ToLower($1)) 6433 $$ = &tree.FuncExpr{ 6434 Func: tree.FuncName2ResolvableFunctionReference(name), 6435 Exprs: $3, 6436 WindowSpec: $5, 6437 } 6438 } 6439 | APPROX_PERCENTILE '(' expression_list ')' window_spec_opt 6440 { 6441 name := tree.SetUnresolvedName(strings.ToLower($1)) 6442 $$ = &tree.FuncExpr{ 6443 Func: tree.FuncName2ResolvableFunctionReference(name), 6444 Exprs: $3, 6445 WindowSpec: $5, 6446 } 6447 } 6448 | BIT_AND '(' func_type_opt expression ')' window_spec_opt 6449 { 6450 name := tree.SetUnresolvedName(strings.ToLower($1)) 6451 $$ = &tree.FuncExpr{ 6452 Func: tree.FuncName2ResolvableFunctionReference(name), 6453 Exprs: tree.Exprs{$4}, 6454 Type: $3, 6455 WindowSpec: $6, 6456 } 6457 } 6458 | BIT_OR '(' func_type_opt expression ')' window_spec_opt 6459 { 6460 name := tree.SetUnresolvedName(strings.ToLower($1)) 6461 $$ = &tree.FuncExpr{ 6462 Func: tree.FuncName2ResolvableFunctionReference(name), 6463 Exprs: tree.Exprs{$4}, 6464 Type: $3, 6465 WindowSpec: $6, 6466 } 6467 } 6468 | BIT_XOR '(' func_type_opt expression ')' window_spec_opt 6469 { 6470 name := tree.SetUnresolvedName(strings.ToLower($1)) 6471 $$ = &tree.FuncExpr{ 6472 Func: tree.FuncName2ResolvableFunctionReference(name), 6473 Exprs: tree.Exprs{$4}, 6474 Type: $3, 6475 WindowSpec: $6, 6476 } 6477 } 6478 | COUNT '(' func_type_opt expression_list ')' window_spec_opt 6479 { 6480 name := tree.SetUnresolvedName(strings.ToLower($1)) 6481 $$ = &tree.FuncExpr{ 6482 Func: tree.FuncName2ResolvableFunctionReference(name), 6483 Exprs: $4, 6484 Type: $3, 6485 WindowSpec: $6, 6486 } 6487 } 6488 | COUNT '(' '*' ')' window_spec_opt 6489 { 6490 name := tree.SetUnresolvedName(strings.ToLower($1)) 6491 es := tree.NewNumValWithType(constant.MakeString("*"), "*", false, tree.P_char) 6492 $$ = &tree.FuncExpr{ 6493 Func: tree.FuncName2ResolvableFunctionReference(name), 6494 Exprs: tree.Exprs{es}, 6495 WindowSpec: $5, 6496 } 6497 } 6498 | MAX '(' func_type_opt expression ')' window_spec_opt 6499 { 6500 name := tree.SetUnresolvedName(strings.ToLower($1)) 6501 $$ = &tree.FuncExpr{ 6502 Func: tree.FuncName2ResolvableFunctionReference(name), 6503 Exprs: tree.Exprs{$4}, 6504 Type: $3, 6505 WindowSpec: $6, 6506 } 6507 } 6508 | MIN '(' func_type_opt expression ')' window_spec_opt 6509 { 6510 name := tree.SetUnresolvedName(strings.ToLower($1)) 6511 $$ = &tree.FuncExpr{ 6512 Func: tree.FuncName2ResolvableFunctionReference(name), 6513 Exprs: tree.Exprs{$4}, 6514 Type: $3, 6515 WindowSpec: $6, 6516 } 6517 } 6518 | SUM '(' func_type_opt expression ')' window_spec_opt 6519 { 6520 name := tree.SetUnresolvedName(strings.ToLower($1)) 6521 $$ = &tree.FuncExpr{ 6522 Func: tree.FuncName2ResolvableFunctionReference(name), 6523 Exprs: tree.Exprs{$4}, 6524 Type: $3, 6525 WindowSpec: $6, 6526 } 6527 } 6528 | std_dev_pop '(' func_type_opt expression ')' window_spec_opt 6529 { 6530 name := tree.SetUnresolvedName(strings.ToLower($1)) 6531 $$ = &tree.FuncExpr{ 6532 Func: tree.FuncName2ResolvableFunctionReference(name), 6533 Exprs: tree.Exprs{$4}, 6534 Type: $3, 6535 WindowSpec: $6, 6536 } 6537 } 6538 | STDDEV_SAMP '(' func_type_opt expression ')' window_spec_opt 6539 { 6540 name := tree.SetUnresolvedName(strings.ToLower($1)) 6541 $$ = &tree.FuncExpr{ 6542 Func: tree.FuncName2ResolvableFunctionReference(name), 6543 Exprs: tree.Exprs{$4}, 6544 Type: $3, 6545 WindowSpec: $6, 6546 } 6547 } 6548 | VAR_POP '(' func_type_opt expression ')' window_spec_opt 6549 { 6550 name := tree.SetUnresolvedName(strings.ToLower($1)) 6551 $$ = &tree.FuncExpr{ 6552 Func: tree.FuncName2ResolvableFunctionReference(name), 6553 Exprs: tree.Exprs{$4}, 6554 Type: $3, 6555 WindowSpec: $6, 6556 } 6557 } 6558 | VAR_SAMP '(' func_type_opt expression ')' window_spec_opt 6559 { 6560 name := tree.SetUnresolvedName(strings.ToLower($1)) 6561 $$ = &tree.FuncExpr{ 6562 Func: tree.FuncName2ResolvableFunctionReference(name), 6563 Exprs: tree.Exprs{$4}, 6564 Type: $3, 6565 WindowSpec: $6, 6566 } 6567 } 6568 | MEDIAN '(' func_type_opt expression ')' window_spec_opt 6569 { 6570 name := tree.SetUnresolvedName(strings.ToLower($1)) 6571 $$ = &tree.FuncExpr{ 6572 Func: tree.FuncName2ResolvableFunctionReference(name), 6573 Exprs: tree.Exprs{$4}, 6574 Type: $3, 6575 WindowSpec: $6, 6576 } 6577 } 6578 6579 std_dev_pop: 6580 STD 6581 | STDDEV 6582 | STDDEV_POP 6583 6584 function_call_generic: 6585 ID '(' expression_list_opt ')' 6586 { 6587 name := tree.SetUnresolvedName(strings.ToLower($1)) 6588 $$ = &tree.FuncExpr{ 6589 Func: tree.FuncName2ResolvableFunctionReference(name), 6590 Exprs: $3, 6591 } 6592 } 6593 | substr_option '(' expression_list_opt ')' 6594 { 6595 name := tree.SetUnresolvedName(strings.ToLower($1)) 6596 $$ = &tree.FuncExpr{ 6597 Func: tree.FuncName2ResolvableFunctionReference(name), 6598 Exprs: $3, 6599 } 6600 } 6601 | substr_option '(' expression FROM expression ')' 6602 { 6603 name := tree.SetUnresolvedName(strings.ToLower($1)) 6604 $$ = &tree.FuncExpr{ 6605 Func: tree.FuncName2ResolvableFunctionReference(name), 6606 Exprs: tree.Exprs{$3, $5}, 6607 } 6608 } 6609 | substr_option '(' expression FROM expression FOR expression ')' 6610 { 6611 name := tree.SetUnresolvedName(strings.ToLower($1)) 6612 $$ = &tree.FuncExpr{ 6613 Func: tree.FuncName2ResolvableFunctionReference(name), 6614 Exprs: tree.Exprs{$3, $5, $7}, 6615 } 6616 } 6617 | EXTRACT '(' time_unit FROM expression ')' 6618 { 6619 name := tree.SetUnresolvedName(strings.ToLower($1)) 6620 timeUinit := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6621 $$ = &tree.FuncExpr{ 6622 Func: tree.FuncName2ResolvableFunctionReference(name), 6623 Exprs: tree.Exprs{timeUinit, $5}, 6624 } 6625 } 6626 | func_not_keyword '(' expression_list_opt ')' 6627 { 6628 name := tree.SetUnresolvedName(strings.ToLower($1)) 6629 $$ = &tree.FuncExpr{ 6630 Func: tree.FuncName2ResolvableFunctionReference(name), 6631 Exprs: $3, 6632 } 6633 } 6634 | VARIANCE '(' func_type_opt expression ')' 6635 { 6636 name := tree.SetUnresolvedName(strings.ToLower($1)) 6637 $$ = &tree.FuncExpr{ 6638 Func: tree.FuncName2ResolvableFunctionReference(name), 6639 Exprs: tree.Exprs{$4}, 6640 Type: $3, 6641 } 6642 } 6643 | TRIM '(' expression ')' 6644 { 6645 name := tree.SetUnresolvedName(strings.ToLower($1)) 6646 arg0 := tree.NewNumValWithType(constant.MakeInt64(0), "0", false, tree.P_int64) 6647 arg1 := tree.NewNumValWithType(constant.MakeString("both"), "both", false, tree.P_char) 6648 arg2 := tree.NewNumValWithType(constant.MakeString(" "), " ", false, tree.P_char) 6649 $$ = &tree.FuncExpr{ 6650 Func: tree.FuncName2ResolvableFunctionReference(name), 6651 Exprs: tree.Exprs{arg0, arg1, arg2, $3}, 6652 } 6653 } 6654 | TRIM '(' expression FROM expression ')' 6655 { 6656 name := tree.SetUnresolvedName(strings.ToLower($1)) 6657 arg0 := tree.NewNumValWithType(constant.MakeInt64(1), "1", false, tree.P_int64) 6658 arg1 := tree.NewNumValWithType(constant.MakeString("both"), "both", false, tree.P_char) 6659 $$ = &tree.FuncExpr{ 6660 Func: tree.FuncName2ResolvableFunctionReference(name), 6661 Exprs: tree.Exprs{arg0, arg1, $3, $5}, 6662 } 6663 } 6664 | TRIM '(' trim_direction FROM expression ')' 6665 { 6666 name := tree.SetUnresolvedName(strings.ToLower($1)) 6667 arg0 := tree.NewNumValWithType(constant.MakeInt64(2), "2", false, tree.P_int64) 6668 arg1 := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6669 arg2 := tree.NewNumValWithType(constant.MakeString(" "), " ", false, tree.P_char) 6670 $$ = &tree.FuncExpr{ 6671 Func: tree.FuncName2ResolvableFunctionReference(name), 6672 Exprs: tree.Exprs{arg0, arg1, arg2, $5}, 6673 } 6674 } 6675 | TRIM '(' trim_direction expression FROM expression ')' 6676 { 6677 name := tree.SetUnresolvedName(strings.ToLower($1)) 6678 arg0 := tree.NewNumValWithType(constant.MakeInt64(3), "3", false, tree.P_int64) 6679 arg1 := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6680 $$ = &tree.FuncExpr{ 6681 Func: tree.FuncName2ResolvableFunctionReference(name), 6682 Exprs: tree.Exprs{arg0, arg1, $4, $6}, 6683 } 6684 } 6685 | VALUES '(' insert_column ')' 6686 { 6687 column := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6688 name := tree.SetUnresolvedName(strings.ToLower($1)) 6689 $$ = &tree.FuncExpr{ 6690 Func: tree.FuncName2ResolvableFunctionReference(name), 6691 Exprs: tree.Exprs{column}, 6692 } 6693 } 6694 6695 6696 trim_direction: 6697 BOTH 6698 | LEADING 6699 | TRAILING 6700 6701 substr_option: 6702 SUBSTRING 6703 | SUBSTR 6704 | MID 6705 6706 time_unit: 6707 time_stamp_unit 6708 { 6709 $$ = $1 6710 } 6711 | SECOND_MICROSECOND 6712 | MINUTE_MICROSECOND 6713 | MINUTE_SECOND 6714 | HOUR_MICROSECOND 6715 | HOUR_SECOND 6716 | HOUR_MINUTE 6717 | DAY_MICROSECOND 6718 | DAY_SECOND 6719 | DAY_MINUTE 6720 | DAY_HOUR 6721 | YEAR_MONTH 6722 6723 time_stamp_unit: 6724 MICROSECOND 6725 | SECOND 6726 | MINUTE 6727 | HOUR 6728 | DAY 6729 | WEEK 6730 | MONTH 6731 | QUARTER 6732 | YEAR 6733 | SQL_TSI_SECOND 6734 | SQL_TSI_MINUTE 6735 | SQL_TSI_HOUR 6736 | SQL_TSI_DAY 6737 | SQL_TSI_WEEK 6738 | SQL_TSI_MONTH 6739 | SQL_TSI_QUARTER 6740 | SQL_TSI_YEAR 6741 6742 function_call_nonkeyword: 6743 CURTIME datetime_precision 6744 { 6745 name := tree.SetUnresolvedName(strings.ToLower($1)) 6746 var es tree.Exprs = nil 6747 if $2 != nil { 6748 es = append(es, $2) 6749 } 6750 $$ = &tree.FuncExpr{ 6751 Func: tree.FuncName2ResolvableFunctionReference(name), 6752 Exprs: es, 6753 } 6754 } 6755 | SYSDATE datetime_precision 6756 { 6757 name := tree.SetUnresolvedName(strings.ToLower($1)) 6758 var es tree.Exprs = nil 6759 if $2 != nil { 6760 es = append(es, $2) 6761 } 6762 $$ = &tree.FuncExpr{ 6763 Func: tree.FuncName2ResolvableFunctionReference(name), 6764 Exprs: es, 6765 } 6766 } 6767 | TIMESTAMPDIFF '(' time_stamp_unit ',' expression ',' expression ')' 6768 { 6769 name := tree.SetUnresolvedName(strings.ToLower($1)) 6770 arg1 := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6771 $$ = &tree.FuncExpr{ 6772 Func: tree.FuncName2ResolvableFunctionReference(name), 6773 Exprs: tree.Exprs{arg1, $5, $7}, 6774 } 6775 } 6776 function_call_keyword: 6777 name_confict '(' expression_list_opt ')' 6778 { 6779 name := tree.SetUnresolvedName(strings.ToLower($1)) 6780 $$ = &tree.FuncExpr{ 6781 Func: tree.FuncName2ResolvableFunctionReference(name), 6782 Exprs: $3, 6783 } 6784 } 6785 | name_braces braces_opt 6786 { 6787 name := tree.SetUnresolvedName(strings.ToLower($1)) 6788 $$ = &tree.FuncExpr{ 6789 Func: tree.FuncName2ResolvableFunctionReference(name), 6790 } 6791 } 6792 | SCHEMA '('')' 6793 { 6794 name := tree.SetUnresolvedName(strings.ToLower($1)) 6795 $$ = &tree.FuncExpr{ 6796 Func: tree.FuncName2ResolvableFunctionReference(name), 6797 } 6798 } 6799 | name_datetime_precision datetime_precision_opt 6800 { 6801 name := tree.SetUnresolvedName(strings.ToLower($1)) 6802 var es tree.Exprs = nil 6803 if $2 != nil { 6804 es = append(es, $2) 6805 } 6806 $$ = &tree.FuncExpr{ 6807 Func: tree.FuncName2ResolvableFunctionReference(name), 6808 Exprs: es, 6809 } 6810 } 6811 | CHAR '(' expression_list ')' 6812 { 6813 name := tree.SetUnresolvedName("char") 6814 $$ = &tree.FuncExpr{ 6815 Func: tree.FuncName2ResolvableFunctionReference(name), 6816 Exprs: $3, 6817 } 6818 } 6819 | CHAR '(' expression_list USING charset_name ')' 6820 { 6821 cn := tree.NewNumValWithType(constant.MakeString($5), $5, false, tree.P_char) 6822 es := $3 6823 es = append(es, cn) 6824 name := tree.SetUnresolvedName("char") 6825 $$ = &tree.FuncExpr{ 6826 Func: tree.FuncName2ResolvableFunctionReference(name), 6827 Exprs: es, 6828 } 6829 } 6830 | DATE STRING 6831 { 6832 val := tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char) 6833 name := tree.SetUnresolvedName("date") 6834 $$ = &tree.FuncExpr{ 6835 Func: tree.FuncName2ResolvableFunctionReference(name), 6836 Exprs: tree.Exprs{val}, 6837 } 6838 } 6839 | TIME STRING 6840 { 6841 val := tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char) 6842 name := tree.SetUnresolvedName("time") 6843 $$ = &tree.FuncExpr{ 6844 Func: tree.FuncName2ResolvableFunctionReference(name), 6845 Exprs: tree.Exprs{val}, 6846 } 6847 } 6848 | INSERT '(' expression_list_opt ')' 6849 { 6850 name := tree.SetUnresolvedName("insert") 6851 $$ = &tree.FuncExpr{ 6852 Func: tree.FuncName2ResolvableFunctionReference(name), 6853 Exprs: $3, 6854 } 6855 } 6856 | MOD '(' bit_expr ',' bit_expr ')' 6857 { 6858 es := tree.Exprs{$3} 6859 es = append(es, $5) 6860 name := tree.SetUnresolvedName("mod") 6861 $$ = &tree.FuncExpr{ 6862 Func: tree.FuncName2ResolvableFunctionReference(name), 6863 Exprs: es, 6864 } 6865 } 6866 | PASSWORD '(' expression_list_opt ')' 6867 { 6868 name := tree.SetUnresolvedName("password") 6869 $$ = &tree.FuncExpr{ 6870 Func: tree.FuncName2ResolvableFunctionReference(name), 6871 Exprs: $3, 6872 } 6873 } 6874 | TIMESTAMP STRING 6875 { 6876 val := tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_char) 6877 name := tree.SetUnresolvedName("timestamp") 6878 $$ = &tree.FuncExpr{ 6879 Func: tree.FuncName2ResolvableFunctionReference(name), 6880 Exprs: tree.Exprs{val}, 6881 } 6882 } 6883 6884 datetime_precision_opt: 6885 { 6886 $$ = nil 6887 } 6888 | datetime_precision 6889 { 6890 $$ = $1 6891 } 6892 6893 datetime_precision: 6894 '(' ')' 6895 { 6896 $$ = nil 6897 } 6898 | '(' INTEGRAL ')' 6899 { 6900 ival, errStr := util.GetInt64($2) 6901 if errStr != "" { 6902 yylex.Error(errStr) 6903 return 1 6904 } 6905 str := fmt.Sprintf("%v", $2) 6906 $$ = tree.NewNumValWithType(constant.MakeInt64(ival), str, false, tree.P_int64) 6907 } 6908 6909 name_datetime_precision: 6910 CURRENT_TIME 6911 | CURRENT_TIMESTAMP 6912 | LOCALTIME 6913 | LOCALTIMESTAMP 6914 | UTC_TIME 6915 | UTC_TIMESTAMP 6916 6917 braces_opt: 6918 {} 6919 | '(' ')' 6920 {} 6921 6922 name_braces: 6923 CURRENT_USER 6924 | CURRENT_DATE 6925 | CURRENT_ROLE 6926 | UTC_DATE 6927 6928 name_confict: 6929 ASCII 6930 | CHARSET 6931 | COALESCE 6932 | COLLATION 6933 | DATE 6934 | DATABASE 6935 | DAY 6936 | HOUR 6937 | IF 6938 | INTERVAL 6939 | FORMAT 6940 | LEFT 6941 | MICROSECOND 6942 | MINUTE 6943 | MONTH 6944 | QUARTER 6945 | REPEAT 6946 | REPLACE 6947 | REVERSE 6948 | RIGHT 6949 | ROW_COUNT 6950 | SECOND 6951 | TIME 6952 | TIMESTAMP 6953 | TRUNCATE 6954 | USER 6955 | WEEK 6956 | YEAR 6957 | UUID 6958 6959 interval_expr: 6960 INTERVAL expression time_unit 6961 { 6962 name := tree.SetUnresolvedName("interval") 6963 arg2 := tree.NewNumValWithType(constant.MakeString($3), $3, false, tree.P_char) 6964 $$ = &tree.FuncExpr{ 6965 Func: tree.FuncName2ResolvableFunctionReference(name), 6966 Exprs: tree.Exprs{$2, arg2}, 6967 } 6968 } 6969 6970 func_type_opt: 6971 { 6972 $$ = tree.FUNC_TYPE_DEFAULT 6973 } 6974 | DISTINCT 6975 { 6976 $$ = tree.FUNC_TYPE_DISTINCT 6977 } 6978 | ALL 6979 { 6980 $$ = tree.FUNC_TYPE_ALL 6981 } 6982 6983 tuple_expression: 6984 '(' expression_list ')' 6985 { 6986 $$ = tree.NewTuple($2) 6987 } 6988 6989 expression_list_opt: 6990 { 6991 $$ = nil 6992 } 6993 | expression_list 6994 { 6995 $$ = $1 6996 } 6997 6998 expression_list: 6999 expression 7000 { 7001 $$ = tree.Exprs{$1} 7002 } 7003 | expression_list ',' expression 7004 { 7005 $$ = append($1, $3) 7006 } 7007 7008 // See https://dev.mysql.com/doc/refman/8.0/en/expressions.html 7009 expression: 7010 expression AND expression %prec AND 7011 { 7012 $$ = tree.NewAndExpr($1, $3) 7013 } 7014 | expression OR expression %prec OR 7015 { 7016 $$ = tree.NewOrExpr($1, $3) 7017 } 7018 | expression PIPE_CONCAT expression %prec PIPE_CONCAT 7019 { 7020 name := tree.SetUnresolvedName(strings.ToLower("concat")) 7021 $$ = &tree.FuncExpr{ 7022 Func: tree.FuncName2ResolvableFunctionReference(name), 7023 Exprs: tree.Exprs{$1, $3}, 7024 } 7025 } 7026 | expression XOR expression %prec XOR 7027 { 7028 $$ = tree.NewXorExpr($1, $3) 7029 } 7030 | NOT expression %prec NOT 7031 { 7032 $$ = tree.NewNotExpr($2) 7033 } 7034 | MAXVALUE 7035 { 7036 $$ = tree.NewMaxValue() 7037 } 7038 | boolean_primary 7039 { 7040 $$ = $1 7041 } 7042 7043 boolean_primary: 7044 boolean_primary IS NULL %prec IS 7045 { 7046 $$ = tree.NewIsNullExpr($1) 7047 } 7048 | boolean_primary IS NOT NULL %prec IS 7049 { 7050 $$ = tree.NewIsNotNullExpr($1) 7051 } 7052 | boolean_primary IS UNKNOWN %prec IS 7053 { 7054 $$ = tree.NewIsUnknownExpr($1) 7055 } 7056 | boolean_primary IS NOT UNKNOWN %prec IS 7057 { 7058 $$ = tree.NewIsNotUnknownExpr($1) 7059 } 7060 | boolean_primary IS TRUE %prec IS 7061 { 7062 $$ = tree.NewIsTrueExpr($1) 7063 } 7064 | boolean_primary IS NOT TRUE %prec IS 7065 { 7066 $$ = tree.NewIsNotTrueExpr($1) 7067 } 7068 | boolean_primary IS FALSE %prec IS 7069 { 7070 $$ = tree.NewIsFalseExpr($1) 7071 } 7072 | boolean_primary IS NOT FALSE %prec IS 7073 { 7074 $$ = tree.NewIsNotFalseExpr($1) 7075 } 7076 | boolean_primary comparison_operator predicate %prec '=' 7077 { 7078 $$ = tree.NewComparisonExpr($2, $1, $3) 7079 } 7080 | boolean_primary comparison_operator and_or_some subquery %prec '=' 7081 { 7082 $$ = tree.NewSubqueryComparisonExpr($2, $3, $1, $4) 7083 $$ = tree.NewSubqueryComparisonExpr($2, $3, $1, $4) 7084 } 7085 | predicate 7086 7087 predicate: 7088 bit_expr IN col_tuple 7089 { 7090 $$ = tree.NewComparisonExpr(tree.IN, $1, $3) 7091 } 7092 | bit_expr NOT IN col_tuple 7093 { 7094 $$ = tree.NewComparisonExpr(tree.NOT_IN, $1, $4) 7095 } 7096 | bit_expr LIKE simple_expr like_escape_opt 7097 { 7098 $$ = tree.NewComparisonExprWithEscape(tree.LIKE, $1, $3, $4) 7099 } 7100 | bit_expr NOT LIKE simple_expr like_escape_opt 7101 { 7102 $$ = tree.NewComparisonExprWithEscape(tree.NOT_LIKE, $1, $4, $5) 7103 } 7104 | bit_expr ILIKE simple_expr like_escape_opt 7105 { 7106 $$ = tree.NewComparisonExprWithEscape(tree.ILIKE, $1, $3, $4) 7107 } 7108 | bit_expr NOT ILIKE simple_expr like_escape_opt 7109 { 7110 $$ = tree.NewComparisonExprWithEscape(tree.NOT_ILIKE, $1, $4, $5) 7111 } 7112 | bit_expr REGEXP bit_expr 7113 { 7114 $$ = tree.NewComparisonExpr(tree.REG_MATCH, $1, $3) 7115 } 7116 | bit_expr NOT REGEXP bit_expr 7117 { 7118 $$ = tree.NewComparisonExpr(tree.NOT_REG_MATCH, $1, $4) 7119 } 7120 | bit_expr BETWEEN bit_expr AND predicate 7121 { 7122 $$ = tree.NewRangeCond(false, $1, $3, $5) 7123 } 7124 | bit_expr NOT BETWEEN bit_expr AND predicate 7125 { 7126 $$ = tree.NewRangeCond(true, $1, $4, $6) 7127 } 7128 | bit_expr 7129 7130 like_escape_opt: 7131 { 7132 $$ = nil 7133 } 7134 | ESCAPE simple_expr 7135 { 7136 $$ = $2 7137 } 7138 7139 col_tuple: 7140 tuple_expression 7141 { 7142 $$ = $1 7143 } 7144 | subquery 7145 { 7146 $$ = $1 7147 } 7148 // | LIST_ARG 7149 7150 and_or_some: 7151 ALL 7152 { 7153 $$ = tree.ALL 7154 } 7155 | ANY 7156 { 7157 $$ = tree.ANY 7158 } 7159 | SOME 7160 { 7161 $$ = tree.SOME 7162 } 7163 7164 comparison_operator: 7165 '=' 7166 { 7167 $$ = tree.EQUAL 7168 } 7169 | '<' 7170 { 7171 $$ = tree.LESS_THAN 7172 } 7173 | '>' 7174 { 7175 $$ = tree.GREAT_THAN 7176 } 7177 | LE 7178 { 7179 $$ = tree.LESS_THAN_EQUAL 7180 } 7181 | GE 7182 { 7183 $$ = tree.GREAT_THAN_EQUAL 7184 } 7185 | NE 7186 { 7187 $$ = tree.NOT_EQUAL 7188 } 7189 | NULL_SAFE_EQUAL 7190 { 7191 $$ = tree.NULL_SAFE_EQUAL 7192 } 7193 7194 keys: 7195 PRIMARY KEY 7196 { 7197 $$ = tree.NewAttributePrimaryKey() 7198 } 7199 | UNIQUE KEY 7200 { 7201 $$ = tree.NewAttributeUniqueKey() 7202 } 7203 | UNIQUE 7204 { 7205 $$ = tree.NewAttributeUnique() 7206 } 7207 | KEY 7208 { 7209 $$ = tree.NewAttributeKey() 7210 } 7211 7212 literal: 7213 STRING 7214 { 7215 $$ = tree.NewNumValWithType(constant.MakeString($1), $1, false, tree.P_char) 7216 } 7217 | INTEGRAL 7218 { 7219 str := fmt.Sprintf("%v", $1) 7220 switch v := $1.(type) { 7221 case uint64: 7222 $$ = tree.NewNumValWithType(constant.MakeUint64(v), str, false, tree.P_uint64) 7223 case int64: 7224 $$ = tree.NewNumValWithType(constant.MakeInt64(v), str, false, tree.P_int64) 7225 default: 7226 yylex.Error("parse integral fail") 7227 return 1 7228 } 7229 } 7230 | FLOAT 7231 { 7232 fval := $1.(float64) 7233 $$ = tree.NewNumValWithType(constant.MakeFloat64(fval), yylex.(*Lexer).scanner.LastToken, false, tree.P_float64) 7234 } 7235 | TRUE 7236 { 7237 $$ = tree.NewNumValWithType(constant.MakeBool(true), "true", false, tree.P_bool) 7238 } 7239 | FALSE 7240 { 7241 $$ = tree.NewNumValWithType(constant.MakeBool(false), "false", false, tree.P_bool) 7242 } 7243 | NULL 7244 { 7245 $$ = tree.NewNumValWithType(constant.MakeUnknown(), "null", false, tree.P_null) 7246 } 7247 | HEXNUM 7248 { 7249 $$ = tree.NewNumValWithType(constant.MakeString($1), $1, false, tree.P_hexnum) 7250 } 7251 | DECIMAL_VALUE 7252 { 7253 $$ = tree.NewNumValWithType(constant.MakeString($1), $1, false, tree.P_decimal) 7254 } 7255 | BIT_LITERAL 7256 { 7257 switch v := $1.(type) { 7258 case uint64: 7259 $$ = tree.NewNumValWithType(constant.MakeUint64(v), yylex.(*Lexer).scanner.LastToken, false, tree.P_uint64) 7260 case int64: 7261 $$ = tree.NewNumValWithType(constant.MakeInt64(v), yylex.(*Lexer).scanner.LastToken, false, tree.P_int64) 7262 case string: 7263 $$ = tree.NewNumValWithType(constant.MakeString(v), v, false, tree.P_bit) 7264 default: 7265 yylex.Error("parse integral fail") 7266 return 1 7267 } 7268 } 7269 | VALUE_ARG 7270 { 7271 $$ = tree.NewParamExpr(yylex.(*Lexer).GetParamIndex()) 7272 } 7273 | UNDERSCORE_BINARY STRING 7274 { 7275 $$ = tree.NewNumValWithType(constant.MakeString($2), $2, false, tree.P_ScoreBinary) 7276 } 7277 7278 7279 column_type: 7280 numeric_type unsigned_opt zero_fill_opt 7281 { 7282 $$ = $1 7283 $$.InternalType.Unsigned = $2 7284 $$.InternalType.Zerofill = $3 7285 } 7286 | char_type 7287 | time_type 7288 | spatial_type 7289 7290 numeric_type: 7291 int_type length_opt 7292 { 7293 $$ = $1 7294 $$.InternalType.DisplayWith = $2 7295 } 7296 | decimal_type 7297 { 7298 $$ = $1 7299 } 7300 7301 int_type: 7302 BIT 7303 { 7304 locale := "" 7305 $$ = &tree.T{ 7306 InternalType: tree.InternalType{ 7307 Family: tree.BitFamily, 7308 FamilyString: $1, 7309 Locale: &locale, 7310 Oid: uint32(defines.MYSQL_TYPE_BIT), 7311 }, 7312 } 7313 } 7314 | BOOL 7315 { 7316 locale := "" 7317 $$ = &tree.T{ 7318 InternalType: tree.InternalType{ 7319 Family: tree.BoolFamily, 7320 FamilyString: $1, 7321 Locale: &locale, 7322 Oid:uint32(defines.MYSQL_TYPE_BOOL), 7323 }, 7324 } 7325 } 7326 | BOOLEAN 7327 { 7328 locale := "" 7329 $$ = &tree.T{ 7330 InternalType: tree.InternalType{ 7331 Family: tree.BoolFamily, 7332 FamilyString: $1, 7333 Locale: &locale, 7334 Oid:uint32(defines.MYSQL_TYPE_BOOL), 7335 }, 7336 } 7337 } 7338 | INT1 7339 { 7340 locale := "" 7341 $$ = &tree.T{ 7342 InternalType: tree.InternalType{ 7343 Family: tree.IntFamily, 7344 FamilyString: $1, 7345 Width: 8, 7346 Locale: &locale, 7347 Oid: uint32(defines.MYSQL_TYPE_TINY), 7348 }, 7349 } 7350 } 7351 | TINYINT 7352 { 7353 locale := "" 7354 $$ = &tree.T{ 7355 InternalType: tree.InternalType{ 7356 Family: tree.IntFamily, 7357 FamilyString: $1, 7358 Width: 8, 7359 Locale: &locale, 7360 Oid: uint32(defines.MYSQL_TYPE_TINY), 7361 }, 7362 } 7363 } 7364 | INT2 7365 { 7366 locale := "" 7367 $$ = &tree.T{ 7368 InternalType: tree.InternalType{ 7369 Family: tree.IntFamily, 7370 FamilyString: $1, 7371 Width: 16, 7372 Locale: &locale, 7373 Oid: uint32(defines.MYSQL_TYPE_SHORT), 7374 }, 7375 } 7376 } 7377 | SMALLINT 7378 { 7379 locale := "" 7380 $$ = &tree.T{ 7381 InternalType: tree.InternalType{ 7382 Family: tree.IntFamily, 7383 FamilyString: $1, 7384 Width: 16, 7385 Locale: &locale, 7386 Oid: uint32(defines.MYSQL_TYPE_SHORT), 7387 }, 7388 } 7389 } 7390 | INT3 7391 { 7392 locale := "" 7393 $$ = &tree.T{ 7394 InternalType: tree.InternalType{ 7395 Family: tree.IntFamily, 7396 FamilyString: $1, 7397 Width: 24, 7398 Locale: &locale, 7399 Oid: uint32(defines.MYSQL_TYPE_INT24), 7400 }, 7401 } 7402 } 7403 | MEDIUMINT 7404 { 7405 locale := "" 7406 $$ = &tree.T{ 7407 InternalType: tree.InternalType{ 7408 Family: tree.IntFamily, 7409 FamilyString: $1, 7410 Width: 24, 7411 Locale: &locale, 7412 Oid: uint32(defines.MYSQL_TYPE_INT24), 7413 }, 7414 } 7415 } 7416 | INT4 7417 { 7418 locale := "" 7419 $$ = &tree.T{ 7420 InternalType: tree.InternalType{ 7421 Family: tree.IntFamily, 7422 FamilyString: $1, 7423 Width: 32, 7424 Locale: &locale, 7425 Oid: uint32(defines.MYSQL_TYPE_LONG), 7426 }, 7427 } 7428 } 7429 | INT 7430 { 7431 locale := "" 7432 $$ = &tree.T{ 7433 InternalType: tree.InternalType{ 7434 Family: tree.IntFamily, 7435 FamilyString: $1, 7436 Width: 32, 7437 Locale: &locale, 7438 Oid: uint32(defines.MYSQL_TYPE_LONG), 7439 }, 7440 } 7441 } 7442 | INTEGER 7443 { 7444 locale := "" 7445 $$ = &tree.T{ 7446 InternalType: tree.InternalType{ 7447 Family: tree.IntFamily, 7448 FamilyString: $1, 7449 Width: 32, 7450 Locale: &locale, 7451 Oid: uint32(defines.MYSQL_TYPE_LONG), 7452 }, 7453 } 7454 } 7455 | INT8 7456 { 7457 locale := "" 7458 $$ = &tree.T{ 7459 InternalType: tree.InternalType{ 7460 Family: tree.IntFamily, 7461 FamilyString: $1, 7462 Width: 64, 7463 Locale: &locale, 7464 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 7465 }, 7466 } 7467 } 7468 | BIGINT 7469 { 7470 locale := "" 7471 $$ = &tree.T{ 7472 InternalType: tree.InternalType{ 7473 Family: tree.IntFamily, 7474 FamilyString: $1, 7475 Width: 64, 7476 Locale: &locale, 7477 Oid: uint32(defines.MYSQL_TYPE_LONGLONG), 7478 }, 7479 } 7480 } 7481 7482 decimal_type: 7483 DOUBLE float_length_opt 7484 { 7485 locale := "" 7486 if $2.DisplayWith > 255 { 7487 yylex.Error("Display width for double out of range (max = 255)") 7488 return 1 7489 } 7490 if $2.Precision != tree.NotDefineDec && $2.Precision > $2.DisplayWith { 7491 yylex.Error("For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'))") 7492 return 1 7493 } 7494 $$ = &tree.T{ 7495 InternalType: tree.InternalType{ 7496 Family: tree.FloatFamily, 7497 FamilyString: $1, 7498 Width: 64, 7499 Locale: &locale, 7500 Oid: uint32(defines.MYSQL_TYPE_DOUBLE), 7501 DisplayWith: $2.DisplayWith, 7502 Precision: $2.Precision, 7503 }, 7504 } 7505 } 7506 | FLOAT_TYPE float_length_opt 7507 { 7508 locale := "" 7509 if $2.Precision != tree.NotDefineDec && $2.Precision > $2.DisplayWith { 7510 yylex.Error("For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'))") 7511 return 1 7512 } 7513 if $2.DisplayWith >= 24 { 7514 $$ = &tree.T{ 7515 InternalType: tree.InternalType{ 7516 Family: tree.FloatFamily, 7517 FamilyString: $1, 7518 Width: 64, 7519 Locale: &locale, 7520 Oid: uint32(defines.MYSQL_TYPE_DOUBLE), 7521 DisplayWith: $2.DisplayWith, 7522 Precision: $2.Precision, 7523 }, 7524 } 7525 } else { 7526 $$ = &tree.T{ 7527 InternalType: tree.InternalType{ 7528 Family: tree.FloatFamily, 7529 FamilyString: $1, 7530 Width: 32, 7531 Locale: &locale, 7532 Oid: uint32(defines.MYSQL_TYPE_FLOAT), 7533 DisplayWith: $2.DisplayWith, 7534 Precision: $2.Precision, 7535 }, 7536 } 7537 } 7538 } 7539 7540 | DECIMAL decimal_length_opt 7541 { 7542 locale := "" 7543 if $2.Precision != tree.NotDefineDec && $2.Precision > $2.DisplayWith { 7544 yylex.Error("For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'))") 7545 return 1 7546 } 7547 if $2.DisplayWith > 38 || $2.DisplayWith < 0 { 7548 yylex.Error("For decimal(M), M must between 0 and 38.") 7549 return 1 7550 } else if $2.DisplayWith <= 16 { 7551 $$ = &tree.T{ 7552 InternalType: tree.InternalType{ 7553 Family: tree.FloatFamily, 7554 FamilyString: $1, 7555 Width: 64, 7556 Locale: &locale, 7557 Oid: uint32(defines.MYSQL_TYPE_DECIMAL), 7558 DisplayWith: $2.DisplayWith, 7559 Precision: $2.Precision, 7560 }, 7561 } 7562 } else { 7563 $$ = &tree.T{ 7564 InternalType: tree.InternalType{ 7565 Family: tree.FloatFamily, 7566 FamilyString: $1, 7567 Width: 128, 7568 Locale: &locale, 7569 Oid: uint32(defines.MYSQL_TYPE_DECIMAL), 7570 DisplayWith: $2.DisplayWith, 7571 Precision: $2.Precision, 7572 }, 7573 } 7574 } 7575 } 7576 // | DECIMAL decimal_length_opt 7577 // { 7578 // $$ = tree.TYPE_DOUBLE 7579 // $$.InternalType.DisplayWith = $2.DisplayWith 7580 // $$.InternalType.Precision = $2.Precision 7581 // } 7582 // | NUMERIC decimal_length_opt 7583 // { 7584 // $$ = tree.TYPE_DOUBLE 7585 // $$.InternalType.DisplayWith = $2.DisplayWith 7586 // $$.InternalType.Precision = $2.Precision 7587 // } 7588 | REAL float_length_opt 7589 { 7590 locale := "" 7591 $$ = &tree.T{ 7592 InternalType: tree.InternalType{ 7593 Family: tree.FloatFamily, 7594 FamilyString: $1, 7595 Width: 64, 7596 Locale: &locale, 7597 Oid: uint32(defines.MYSQL_TYPE_DOUBLE), 7598 DisplayWith: $2.DisplayWith, 7599 Precision: $2.Precision, 7600 }, 7601 } 7602 } 7603 7604 time_type: 7605 DATE 7606 { 7607 locale := "" 7608 $$ = &tree.T{ 7609 InternalType: tree.InternalType{ 7610 Family: tree.DateFamily, 7611 FamilyString: $1, 7612 Locale: &locale, 7613 Oid: uint32(defines.MYSQL_TYPE_DATE), 7614 }, 7615 } 7616 } 7617 | TIME timestamp_option_opt 7618 { 7619 locale := "" 7620 if $2 < 0 || $2 > 6 { 7621 yylex.Error("For Time(fsp), fsp must in [0, 6]") 7622 return 1 7623 } else { 7624 $$ = &tree.T{ 7625 InternalType: tree.InternalType{ 7626 Family: tree.TimeFamily, 7627 Precision: $2, 7628 FamilyString: $1, 7629 DisplayWith: 26, 7630 TimePrecisionIsSet: true, 7631 Locale: &locale, 7632 Oid: uint32(defines.MYSQL_TYPE_TIME), 7633 }, 7634 } 7635 } 7636 } 7637 | TIMESTAMP timestamp_option_opt 7638 { 7639 locale := "" 7640 if $2 < 0 || $2 > 6 { 7641 yylex.Error("For Timestamp(fsp), fsp must in [0, 6]") 7642 return 1 7643 } else { 7644 $$ = &tree.T{ 7645 InternalType: tree.InternalType{ 7646 Family: tree.TimestampFamily, 7647 Precision: $2, 7648 FamilyString: $1, 7649 DisplayWith: 26, 7650 TimePrecisionIsSet: true, 7651 Locale: &locale, 7652 Oid: uint32(defines.MYSQL_TYPE_TIMESTAMP), 7653 }, 7654 } 7655 } 7656 } 7657 | DATETIME timestamp_option_opt 7658 { 7659 locale := "" 7660 if $2 < 0 || $2 > 6 { 7661 yylex.Error("For Datetime(fsp), fsp must in [0, 6]") 7662 return 1 7663 } else { 7664 $$ = &tree.T{ 7665 InternalType: tree.InternalType{ 7666 Family: tree.TimestampFamily, 7667 Precision: $2, 7668 FamilyString: $1, 7669 DisplayWith: 26, 7670 TimePrecisionIsSet: true, 7671 Locale: &locale, 7672 Oid: uint32(defines.MYSQL_TYPE_DATETIME), 7673 }, 7674 } 7675 } 7676 } 7677 | YEAR length_opt 7678 { 7679 locale := "" 7680 $$ = &tree.T{ 7681 InternalType: tree.InternalType{ 7682 Family: tree.IntFamily, 7683 FamilyString: $1, 7684 DisplayWith: $2, 7685 Width: 16, 7686 Locale: &locale, 7687 Oid: uint32(defines.MYSQL_TYPE_YEAR), 7688 }, 7689 } 7690 } 7691 7692 char_type: 7693 CHAR length_option_opt 7694 { 7695 locale := "" 7696 $$ = &tree.T{ 7697 InternalType: tree.InternalType{ 7698 Family: tree.StringFamily, 7699 FamilyString: $1, 7700 Locale: &locale, 7701 Oid: uint32(defines.MYSQL_TYPE_STRING), 7702 DisplayWith: $2, 7703 }, 7704 } 7705 } 7706 | VARCHAR length_option_opt 7707 { 7708 locale := "" 7709 $$ = &tree.T{ 7710 InternalType: tree.InternalType{ 7711 Family: tree.StringFamily, 7712 Locale: &locale, 7713 FamilyString: $1, 7714 DisplayWith: $2, 7715 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 7716 }, 7717 } 7718 } 7719 | BINARY length_opt 7720 { 7721 locale := "" 7722 $$ = &tree.T{ 7723 InternalType: tree.InternalType{ 7724 Family: tree.StringFamily, 7725 FamilyString: $1, 7726 Locale: &locale, 7727 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 7728 DisplayWith: $2, 7729 }, 7730 } 7731 } 7732 | VARBINARY length_opt 7733 { 7734 locale := "" 7735 $$ = &tree.T{ 7736 InternalType: tree.InternalType{ 7737 Family: tree.StringFamily, 7738 Locale: &locale, 7739 FamilyString: $1, 7740 DisplayWith: $2, 7741 Oid: uint32(defines.MYSQL_TYPE_VARCHAR), 7742 }, 7743 } 7744 } 7745 | TEXT 7746 { 7747 locale := "" 7748 $$ = &tree.T{ 7749 InternalType: tree.InternalType{ 7750 Family: tree.BlobFamily, 7751 FamilyString: $1, 7752 Locale: &locale, 7753 Oid: uint32(defines.MYSQL_TYPE_TEXT), 7754 }, 7755 } 7756 } 7757 | TINYTEXT 7758 { 7759 locale := "" 7760 $$ = &tree.T{ 7761 InternalType: tree.InternalType{ 7762 Family: tree.BlobFamily, 7763 FamilyString: $1, 7764 Locale: &locale, 7765 Oid: uint32(defines.MYSQL_TYPE_TEXT), 7766 }, 7767 } 7768 } 7769 | MEDIUMTEXT 7770 { 7771 locale := "" 7772 $$ = &tree.T{ 7773 InternalType: tree.InternalType{ 7774 Family: tree.BlobFamily, 7775 FamilyString: $1, 7776 Locale: &locale, 7777 Oid: uint32(defines.MYSQL_TYPE_TEXT), 7778 }, 7779 } 7780 } 7781 | LONGTEXT 7782 { 7783 locale := "" 7784 $$ = &tree.T{ 7785 InternalType: tree.InternalType{ 7786 Family: tree.BlobFamily, 7787 FamilyString: $1, 7788 Locale: &locale, 7789 Oid: uint32(defines.MYSQL_TYPE_TEXT), 7790 }, 7791 } 7792 } 7793 | BLOB 7794 { 7795 locale := "" 7796 $$ = &tree.T{ 7797 InternalType: tree.InternalType{ 7798 Family: tree.BlobFamily, 7799 FamilyString: $1, 7800 Locale: &locale, 7801 Oid: uint32(defines.MYSQL_TYPE_BLOB), 7802 }, 7803 } 7804 } 7805 | TINYBLOB 7806 { 7807 locale := "" 7808 $$ = &tree.T{ 7809 InternalType: tree.InternalType{ 7810 Family: tree.BlobFamily, 7811 FamilyString: $1, 7812 Locale: &locale, 7813 Oid: uint32(defines.MYSQL_TYPE_TINY_BLOB), 7814 }, 7815 } 7816 } 7817 | MEDIUMBLOB 7818 { 7819 locale := "" 7820 $$ = &tree.T{ 7821 InternalType: tree.InternalType{ 7822 Family: tree.BlobFamily, 7823 FamilyString: $1, 7824 Locale: &locale, 7825 Oid: uint32(defines.MYSQL_TYPE_MEDIUM_BLOB), 7826 }, 7827 } 7828 } 7829 | LONGBLOB 7830 { 7831 locale := "" 7832 $$ = &tree.T{ 7833 InternalType: tree.InternalType{ 7834 Family: tree.BlobFamily, 7835 FamilyString: $1, 7836 Locale: &locale, 7837 Oid: uint32(defines.MYSQL_TYPE_LONG_BLOB), 7838 }, 7839 } 7840 } 7841 | JSON 7842 { 7843 locale := "" 7844 $$ = &tree.T{ 7845 InternalType: tree.InternalType{ 7846 Family: tree.JsonFamily, 7847 FamilyString: $1, 7848 Locale: &locale, 7849 Oid:uint32(defines.MYSQL_TYPE_JSON), 7850 }, 7851 } 7852 } 7853 | ENUM '(' enum_values ')' 7854 { 7855 locale := "" 7856 $$ = &tree.T{ 7857 InternalType: tree.InternalType{ 7858 Family: tree.EnumFamily, 7859 FamilyString: $1, 7860 Locale: &locale, 7861 Oid:uint32(defines.MYSQL_TYPE_ENUM), 7862 EnumValues: $3, 7863 }, 7864 } 7865 } 7866 | SET '(' enum_values ')' 7867 { 7868 locale := "" 7869 $$ = &tree.T{ 7870 InternalType: tree.InternalType{ 7871 Family: tree.SetFamily, 7872 FamilyString: $1, 7873 Locale: &locale, 7874 Oid:uint32(defines.MYSQL_TYPE_SET), 7875 EnumValues: $3, 7876 }, 7877 } 7878 } 7879 | UUID 7880 { 7881 locale := "" 7882 $$ = &tree.T{ 7883 InternalType: tree.InternalType{ 7884 Family: tree.UuidFamily, 7885 FamilyString: $1, 7886 Width: 128, 7887 Locale: &locale, 7888 Oid: uint32(defines.MYSQL_TYPE_UUID), 7889 }, 7890 } 7891 } 7892 7893 do_stmt: 7894 DO expression_list 7895 { 7896 $$ = &tree.Do { 7897 Exprs: $2, 7898 } 7899 } 7900 7901 declare_stmt: 7902 DECLARE var_name_list column_type 7903 { 7904 $$ = &tree.Declare { 7905 Variables: $2, 7906 ColumnType: $3, 7907 DefaultVal: tree.NewNumValWithType(constant.MakeUnknown(), "null", false, tree.P_null), 7908 } 7909 } 7910 | 7911 DECLARE var_name_list column_type DEFAULT expression 7912 { 7913 $$ = &tree.Declare { 7914 Variables: $2, 7915 ColumnType: $3, 7916 DefaultVal: $5, 7917 } 7918 } 7919 7920 spatial_type: 7921 GEOMETRY 7922 { 7923 locale := "" 7924 $$ = &tree.T{ 7925 InternalType: tree.InternalType{ 7926 Family: tree.GeometryFamily, 7927 FamilyString: $1, 7928 Locale: &locale, 7929 Oid:uint32(defines.MYSQL_TYPE_GEOMETRY), 7930 }, 7931 } 7932 } 7933 // | POINT 7934 // | LINESTRING 7935 // | POLYGON 7936 // | GEOMETRYCOLLECTION 7937 // | MULTIPOINT 7938 // | MULTILINESTRING 7939 // | MULTIPOLYGON 7940 7941 // TODO: 7942 // need to encode SQL string 7943 enum_values: 7944 STRING 7945 { 7946 $$ = make([]string, 0, 4) 7947 $$ = append($$, $1) 7948 } 7949 | enum_values ',' STRING 7950 { 7951 $$ = append($1, $3) 7952 } 7953 7954 length_opt: 7955 /* EMPTY */ 7956 { 7957 $$ = 0 7958 } 7959 | length 7960 7961 timestamp_option_opt: 7962 /* EMPTY */ 7963 { 7964 $$ = 0 7965 } 7966 | '(' INTEGRAL ')' 7967 { 7968 $$ = int32($2.(int64)) 7969 } 7970 7971 length_option_opt: 7972 { 7973 $$ = int32(-1) 7974 } 7975 | '(' INTEGRAL ')' 7976 { 7977 $$ = int32($2.(int64)) 7978 } 7979 7980 length: 7981 '(' INTEGRAL ')' 7982 { 7983 $$ = tree.GetDisplayWith(int32($2.(int64))) 7984 } 7985 7986 float_length_opt: 7987 /* EMPTY */ 7988 { 7989 $$ = tree.LengthScaleOpt{ 7990 DisplayWith: tree.NotDefineDisplayWidth, 7991 Precision: tree.NotDefineDec, 7992 } 7993 } 7994 | '(' INTEGRAL ')' 7995 { 7996 $$ = tree.LengthScaleOpt{ 7997 DisplayWith: tree.GetDisplayWith(int32($2.(int64))), 7998 Precision: tree.NotDefineDec, 7999 } 8000 } 8001 | '(' INTEGRAL ',' INTEGRAL ')' 8002 { 8003 $$ = tree.LengthScaleOpt{ 8004 DisplayWith: tree.GetDisplayWith(int32($2.(int64))), 8005 Precision: int32($4.(int64)), 8006 } 8007 } 8008 8009 decimal_length_opt: 8010 /* EMPTY */ 8011 { 8012 $$ = tree.LengthScaleOpt{ 8013 DisplayWith: 34, // this is the default precision for decimal 8014 Precision: 0, 8015 } 8016 } 8017 | '(' INTEGRAL ')' 8018 { 8019 $$ = tree.LengthScaleOpt{ 8020 DisplayWith: tree.GetDisplayWith(int32($2.(int64))), 8021 Precision: 0, 8022 } 8023 } 8024 | '(' INTEGRAL ',' INTEGRAL ')' 8025 { 8026 $$ = tree.LengthScaleOpt{ 8027 DisplayWith: tree.GetDisplayWith(int32($2.(int64))), 8028 Precision: int32($4.(int64)), 8029 } 8030 } 8031 8032 unsigned_opt: 8033 /* EMPTY */ 8034 { 8035 $$ = false 8036 } 8037 | UNSIGNED 8038 { 8039 $$ = true 8040 } 8041 | SIGNED 8042 { 8043 $$ = false 8044 } 8045 8046 zero_fill_opt: 8047 /* EMPTY */ 8048 {} 8049 | ZEROFILL 8050 { 8051 $$ = true 8052 } 8053 8054 charset_keyword: 8055 CHARSET 8056 | CHARACTER SET 8057 | CHAR SET 8058 8059 equal_opt: 8060 { 8061 $$ = "" 8062 } 8063 | '=' 8064 { 8065 $$ = string($1) 8066 } 8067 8068 sql_id: 8069 id_or_var 8070 | non_reserved_keyword 8071 8072 reserved_sql_id: 8073 sql_id 8074 | reserved_keyword 8075 8076 reserved_table_id: 8077 table_id 8078 | reserved_keyword 8079 8080 reserved_keyword: 8081 ADD 8082 | ALL 8083 | AND 8084 | AS 8085 | ASC 8086 | ASCII 8087 | AUTO_INCREMENT 8088 | BETWEEN 8089 | BINARY 8090 | BY 8091 | CASE 8092 | CHAR 8093 | COLLATE 8094 | COLLATION 8095 | CONVERT 8096 | COALESCE 8097 | CREATE 8098 | CROSS 8099 | CURRENT_DATE 8100 | CURRENT_ROLE 8101 | CURRENT_USER 8102 | CURRENT_TIME 8103 | CURRENT_TIMESTAMP 8104 | CIPHER 8105 | SAN 8106 | SSL 8107 | SUBJECT 8108 | DATABASE 8109 | DATABASES 8110 | DEFAULT 8111 | DELETE 8112 | DESC 8113 | DESCRIBE 8114 | DISTINCT 8115 | DISTINCTROW 8116 | DIV 8117 | DROP 8118 | ELSE 8119 | END 8120 | ESCAPE 8121 | EXISTS 8122 | EXPLAIN 8123 | FALSE 8124 | FIRST 8125 | FOR 8126 | FORCE 8127 | FROM 8128 | GROUP 8129 | HAVING 8130 | HOUR 8131 | IDENTIFIED 8132 | IF 8133 | IGNORE 8134 | IN 8135 | INFILE 8136 | INDEX 8137 | INNER 8138 | INSERT 8139 | INTERVAL 8140 | INTO 8141 | IS 8142 | ISSUER 8143 | JOIN 8144 | KEY 8145 | LAST 8146 | LEFT 8147 | LIKE 8148 | ILIKE 8149 | LIMIT 8150 | LOCALTIME 8151 | LOCALTIMESTAMP 8152 | LOCK 8153 | LOAD 8154 | IMPORT 8155 | MATCH 8156 | MAXVALUE 8157 | MOD 8158 | MICROSECOND 8159 | MINUTE 8160 | NATURAL 8161 | NOT 8162 | NONE 8163 | NULL 8164 | NULLS 8165 | ON 8166 | OR 8167 | ORDER 8168 | OUTER 8169 | REGEXP 8170 | RENAME 8171 | REPLACE 8172 | RIGHT 8173 | REQUIRE 8174 | REPEAT 8175 | ROW_COUNT 8176 | REFERENCES 8177 | RECURSIVE 8178 | REVERSE 8179 | SCHEMA 8180 | SCHEMAS 8181 | SELECT 8182 | SECOND 8183 | SEPARATOR 8184 | SET 8185 | SHOW 8186 | STRAIGHT_JOIN 8187 | TABLE 8188 | THEN 8189 | TO 8190 | TRUE 8191 | TRUNCATE 8192 | UNION 8193 | UNIQUE 8194 | UPDATE 8195 | USE 8196 | USING 8197 | UTC_DATE 8198 | UTC_TIME 8199 | UTC_TIMESTAMP 8200 | VALUES 8201 | WHEN 8202 | WHERE 8203 | WEEK 8204 | WITH 8205 | TERMINATED 8206 | OPTIONALLY 8207 | ENCLOSED 8208 | ESCAPED 8209 | STARTING 8210 | LINES 8211 | ROWS 8212 | INT1 8213 | INT2 8214 | INT3 8215 | INT4 8216 | INT8 8217 | CHECK 8218 | CONSTRAINT 8219 | PRIMARY 8220 | FULLTEXT 8221 | FOREIGN 8222 | ROW 8223 | OUTFILE 8224 | SQL_SMALL_RESULT 8225 | SQL_BIG_RESULT 8226 | LEADING 8227 | TRAILING 8228 | CHARACTER 8229 | LOW_PRIORITY 8230 | HIGH_PRIORITY 8231 | DELAYED 8232 | PARTITION 8233 | QUICK 8234 | EXCEPT 8235 | ADMIN_NAME 8236 | RANDOM 8237 | SUSPEND 8238 | REUSE 8239 | CURRENT 8240 | OPTIONAL 8241 | FAILED_LOGIN_ATTEMPTS 8242 | PASSWORD_LOCK_TIME 8243 | UNBOUNDED 8244 | SECONDARY 8245 | DECLARE 8246 | MODUMP 8247 | OVER 8248 | PRECEDING 8249 | FOLLOWING 8250 | GROUPS 8251 | LOCKS 8252 | TABLE_NUMBER 8253 | COLUMN_NUMBER 8254 | TABLE_VALUES 8255 | RETURNS 8256 | MYSQL_COMPATBILITY_MODE 8257 8258 non_reserved_keyword: 8259 ACCOUNT 8260 | ACCOUNTS 8261 | AGAINST 8262 | AVG_ROW_LENGTH 8263 | AUTO_RANDOM 8264 | ATTRIBUTE 8265 | ACTION 8266 | ALGORITHM 8267 | BEGIN 8268 | BIGINT 8269 | BIT 8270 | BLOB 8271 | BOOL 8272 | CHAIN 8273 | CHECKSUM 8274 | CLUSTER 8275 | COMPRESSION 8276 | COMMENT_KEYWORD 8277 | COMMIT 8278 | COMMITTED 8279 | CHARSET 8280 | COLUMNS 8281 | CONNECTION 8282 | CONSISTENT 8283 | COMPRESSED 8284 | COMPACT 8285 | COLUMN_FORMAT 8286 | CASCADE 8287 | DATA 8288 | DATETIME 8289 | DECIMAL 8290 | DYNAMIC 8291 | DISK 8292 | DO 8293 | DOUBLE 8294 | DIRECTORY 8295 | DUPLICATE 8296 | DELAY_KEY_WRITE 8297 | ENUM 8298 | ENCRYPTION 8299 | ENGINE 8300 | EXPANSION 8301 | EXTENDED 8302 | EXPIRE 8303 | ERRORS 8304 | ENFORCED 8305 | FORMAT 8306 | FLOAT_TYPE 8307 | FULL 8308 | FIXED 8309 | FIELDS 8310 | GEOMETRY 8311 | GEOMETRYCOLLECTION 8312 | GLOBAL 8313 | GRANT 8314 | INT 8315 | INTEGER 8316 | INDEXES 8317 | ISOLATION 8318 | JSON 8319 | KEY_BLOCK_SIZE 8320 | KEYS 8321 | LANGUAGE 8322 | LESS 8323 | LEVEL 8324 | LINESTRING 8325 | LONGBLOB 8326 | LONGTEXT 8327 | LOCAL 8328 | LINEAR 8329 | LIST 8330 | MEDIUMBLOB 8331 | MEDIUMINT 8332 | MEDIUMTEXT 8333 | MEMORY 8334 | MODE 8335 | MULTILINESTRING 8336 | MULTIPOINT 8337 | MULTIPOLYGON 8338 | MAX_QUERIES_PER_HOUR 8339 | MAX_UPDATES_PER_HOUR 8340 | MAX_CONNECTIONS_PER_HOUR 8341 | MAX_USER_CONNECTIONS 8342 | MAX_ROWS 8343 | MIN_ROWS 8344 | MONTH 8345 | NAMES 8346 | NCHAR 8347 | NUMERIC 8348 | NEVER 8349 | NO 8350 | OFFSET 8351 | ONLY 8352 | OPTIMIZE 8353 | OPEN 8354 | OPTION 8355 | PACK_KEYS 8356 | PARTIAL 8357 | PARTITIONS 8358 | POINT 8359 | POLYGON 8360 | PROCEDURE 8361 | PROXY 8362 | QUERY 8363 | PROFILES 8364 | ROLE 8365 | RANGE 8366 | READ 8367 | REAL 8368 | REORGANIZE 8369 | REDUNDANT 8370 | REPAIR 8371 | REPEATABLE 8372 | RELEASE 8373 | REVOKE 8374 | REPLICATION 8375 | ROW_FORMAT 8376 | ROLLBACK 8377 | RESTRICT 8378 | SESSION 8379 | SERIALIZABLE 8380 | SHARE 8381 | SIGNED 8382 | SMALLINT 8383 | SNAPSHOT 8384 | SPATIAL 8385 | START 8386 | STATUS 8387 | STORAGE 8388 | STREAM 8389 | STATS_AUTO_RECALC 8390 | STATS_PERSISTENT 8391 | STATS_SAMPLE_PAGES 8392 | SUBPARTITIONS 8393 | SUBPARTITION 8394 | SIMPLE 8395 | TEXT 8396 | THAN 8397 | TINYBLOB 8398 | TIME %prec LOWER_THAN_STRING 8399 | TINYINT 8400 | TINYTEXT 8401 | TRANSACTION 8402 | TRIGGER 8403 | UNCOMMITTED 8404 | UNSIGNED 8405 | UNUSED 8406 | UNLOCK 8407 | USER 8408 | VARBINARY 8409 | VARCHAR 8410 | VARIABLES 8411 | VIEW 8412 | WRITE 8413 | WARNINGS 8414 | WORK 8415 | X509 8416 | ZEROFILL 8417 | YEAR 8418 | TYPE 8419 | HEADER 8420 | MAX_FILE_SIZE 8421 | FORCE_QUOTE 8422 | QUARTER 8423 | UNKNOWN 8424 | ANY 8425 | SOME 8426 | TIMESTAMP %prec LOWER_THAN_STRING 8427 | DATE %prec LOWER_THAN_STRING 8428 | TABLES 8429 | EXTERNAL 8430 | URL 8431 | PASSWORD %prec LOWER_THAN_EQ 8432 | HASH 8433 | ENGINES 8434 | TRIGGERS 8435 | HISTORY 8436 | LOW_CARDINALITY 8437 | S3OPTION 8438 | EXTENSION 8439 | NODE 8440 | UUID 8441 | PARALLEL 8442 8443 func_not_keyword: 8444 DATE_ADD 8445 | DATE_SUB 8446 | NOW 8447 | ADDDATE 8448 | CURDATE 8449 | POSITION 8450 | SESSION_USER 8451 | SUBDATE 8452 | SYSTEM_USER 8453 | TRANSLATE 8454 8455 not_keyword: 8456 ADDDATE 8457 | BIT_AND 8458 | BIT_OR 8459 | BIT_XOR 8460 | CAST 8461 | COUNT 8462 | APPROX_COUNT_DISTINCT 8463 | APPROX_PERCENTILE 8464 | CURDATE 8465 | CURTIME 8466 | DATE_ADD 8467 | DATE_SUB 8468 | EXTRACT 8469 | GROUP_CONCAT 8470 | MAX 8471 | MID 8472 | MIN 8473 | NOW 8474 | POSITION 8475 | SESSION_USER 8476 | STD 8477 | STDDEV 8478 | STDDEV_POP 8479 | STDDEV_SAMP 8480 | SUBDATE 8481 | SUBSTR 8482 | SUBSTRING 8483 | SUM 8484 | SYSDATE 8485 | SYSTEM_USER 8486 | TRANSLATE 8487 | TRIM 8488 | VARIANCE 8489 | VAR_POP 8490 | VAR_SAMP 8491 | AVG 8492 | TIMESTAMPDIFF 8493 8494 //mo_keywords: 8495 // PROPERTIES 8496 // BSI 8497 // ZONEMAP 8498 8499 %%