1 /* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef PARSER_YYSTYPE_INCLUDED 24 #define PARSER_YYSTYPE_INCLUDED 25 26 #include "my_base.h" 27 #include "my_time.h" // interval_type 28 #include "sql/comp_creator.h" 29 #include "sql/handler.h" 30 #include "sql/item_create.h" // Cast_target 31 #include "sql/key_spec.h" // keytype, fk_option 32 #include "sql/lexer_yystype.h" // Lexer_yystype 33 #include "sql/opt_hints.h" // opt_hints_enum 34 #include "sql/parse_tree_hints.h" 35 #include "sql/resourcegroups/platform/thread_attrs_api.h" // ...::cpu_id_t 36 #include "sql/resourcegroups/resource_group_basic_types.h" // resourcegroups::Range 37 #include "sql/sql_admin.h" // Sql_cmd_analyze_table::Histogram_command 38 #include "sql/sql_alter.h" // Alter_info::enum_with_validation 39 #include "sql/sql_exchange.h" // Line_separators, enum_filetype 40 #include "sql/sql_get_diagnostics.h" // Diagnostics_information::Which_area 41 #include "sql/sql_signal.h" // enum_condition_item_name 42 #include "sql/table.h" // index_hint_type 43 #include "sql/trigger_def.h" // enum_trigger_order_type 44 #include "sql/window_lex.h" // enum_window_frame_unit 45 #include "sql/xa.h" // xa_option_words 46 #include "sql_string.h" // String 47 #include "thr_lock.h" // thr_lock_type 48 49 class PT_ddl_table_option; 50 class PT_json_table_column; 51 class Parse_tree_root; 52 class Table_ident; 53 enum class Acl_type; 54 enum class enum_ha_read_modes; 55 enum class enum_jt_column; 56 enum class Json_on_response_type : uint16; 57 enum class enum_key_algorithm; 58 enum class partition_type; 59 struct Alter_tablespace_parse_context; 60 struct Sql_cmd_srs_attributes; 61 struct udf_func; 62 63 typedef Parse_tree_node_tmpl<Alter_tablespace_parse_context> 64 PT_alter_tablespace_option_base; 65 66 enum enum_yes_no_unknown { TVL_YES, TVL_NO, TVL_UNKNOWN }; 67 68 enum class enum_ha_read_modes; 69 70 /** 71 used by the parser to store internal variable name 72 */ 73 struct sys_var_with_base { 74 sys_var *var; 75 LEX_CSTRING base_name; 76 }; 77 78 enum enum_drop_mode { 79 DROP_DEFAULT, // mode is not specified 80 DROP_CASCADE, // CASCADE option 81 DROP_RESTRICT // RESTRICT option 82 }; 83 84 enum olap_type { UNSPECIFIED_OLAP_TYPE, ROLLUP_TYPE }; 85 86 struct Cast_type { 87 Cast_target target; 88 const CHARSET_INFO *charset; 89 const char *length; 90 const char *dec; 91 }; 92 93 struct Limit_options { 94 Item *limit; 95 Item *opt_offset; 96 /* 97 true for "LIMIT offset,limit" and false for "LIMIT limit OFFSET offset" 98 */ 99 bool is_offset_first; 100 }; 101 102 struct Query_options { 103 ulonglong query_spec_options; 104 105 bool merge(const Query_options &a, const Query_options &b); 106 bool save_to(Parse_context *); 107 }; 108 109 enum delete_option_enum { 110 DELETE_QUICK = 1 << 0, 111 DELETE_LOW_PRIORITY = 1 << 1, 112 DELETE_IGNORE = 1 << 2 113 }; 114 115 enum class Lock_strength { UPDATE, SHARE }; 116 117 /// We will static_cast this one to thr_lock_type. 118 enum class Locked_row_action { 119 DEFAULT = THR_DEFAULT, 120 WAIT = THR_WAIT, 121 NOWAIT = THR_NOWAIT, 122 SKIP = THR_SKIP 123 }; 124 125 /** 126 Internally there is no CROSS JOIN join type, as cross joins are just a 127 special case of inner joins with a join condition that is always true. The 128 only difference is the nesting, and that is handled by the parser. 129 */ 130 enum PT_joined_table_type { 131 JTT_INNER = 0x01, 132 JTT_STRAIGHT = 0x02, 133 JTT_NATURAL = 0x04, 134 JTT_LEFT = 0x08, 135 JTT_RIGHT = 0x10, 136 137 JTT_STRAIGHT_INNER = JTT_STRAIGHT | JTT_INNER, 138 JTT_NATURAL_INNER = JTT_NATURAL | JTT_INNER, 139 JTT_NATURAL_LEFT = JTT_NATURAL | JTT_LEFT, 140 JTT_NATURAL_RIGHT = JTT_NATURAL | JTT_RIGHT 141 }; 142 143 typedef Mem_root_array_YY<LEX_CSTRING> Create_col_name_list; 144 145 enum class Ternary_option { DEFAULT, ON, OFF }; 146 147 enum class On_duplicate { ERROR, IGNORE_DUP, REPLACE_DUP }; 148 149 enum class Virtual_or_stored { VIRTUAL, STORED }; 150 151 enum class Int_type : ulong { 152 INT = MYSQL_TYPE_LONG, 153 TINYINT = MYSQL_TYPE_TINY, 154 SMALLINT = MYSQL_TYPE_SHORT, 155 MEDIUMINT = MYSQL_TYPE_INT24, 156 BIGINT = MYSQL_TYPE_LONGLONG, 157 }; 158 159 enum class Numeric_type : ulong { 160 DECIMAL = MYSQL_TYPE_NEWDECIMAL, 161 FLOAT = MYSQL_TYPE_FLOAT, 162 DOUBLE = MYSQL_TYPE_DOUBLE, 163 }; 164 165 enum class Show_cmd_type { 166 STANDARD, 167 FULL_SHOW, 168 EXTENDED_SHOW, 169 EXTENDED_FULL_SHOW 170 }; 171 172 /** 173 std::optional-like wrapper for simple bitmaps (usually enums of binary flags) 174 175 This template wraps trivial bitmap implementations to add two features: 176 177 * std::optional-like behavior -- the "unset" flag, so we don't have 178 to inject a special "invalid" value into existent enum types, this 179 wrapper class does that for us. 180 181 * the merge() function to merge two bitmap values in a type-safe way. 182 183 @tparam Enum Usually a enum type which simulates a bit set. 184 @tparam Default_value A default Enum value for "unset" variables. 185 186 */ 187 template <typename Enum, Enum Default_value> 188 class Enum_parser { 189 public: 190 /// Constructor-like function 191 /// 192 /// The Enum_parser<> class is designed for use as a field of restricted 193 /// unions, so it can't have C++ constructors. init()194 void init() { m_is_set = false; } 195 196 /// False if the wrapped Enum value is not assigned. is_set()197 bool is_set() const { return m_is_set; } 198 199 /// Return the wrapped Enum value. 200 /// 201 /// @note The wrapped value must be assigned. get()202 Enum get() const { 203 DBUG_ASSERT(is_set()); 204 return m_enum; 205 } 206 207 /// Return the wrapped Enum value (if any) or the Default_value. get_or_default()208 Enum get_or_default() const { return is_set() ? get() : Default_value; } 209 210 /// Assign the wrapped Enum value. set(Enum value)211 void set(Enum value) { 212 m_is_set = true; 213 m_enum = value; 214 } 215 216 /// Merge the x bit set into the wrapped Enum value (if any), or replace it merge(const Enum_parser & x)217 void merge(const Enum_parser &x) { 218 if (x.is_set()) set(x.get()); 219 } 220 221 private: 222 bool m_is_set; ///< True if m_enum is assigned with some value 223 Enum m_enum; ///< The wrapped Enum value. 224 }; 225 226 template <typename T> 227 struct Value_or_default { 228 bool is_default; 229 T value; ///< undefined if is_default is true 230 }; 231 232 enum class Explain_format_type { 233 // DEFAULT will be changed during parsing to TRADITIONAL 234 // for regular EXPLAIN, or TREE for EXPLAIN ANALYZE. 235 DEFAULT, 236 TRADITIONAL, 237 JSON, 238 TREE, 239 TREE_WITH_EXECUTE 240 }; 241 242 // Compatibility with Bison 2.3: 243 #ifndef YYSTYPE_IS_DECLARED 244 #define YYSTYPE_IS_DECLARED 1 245 #endif // YYSTYPE_IS_DECLARED 246 247 union YYSTYPE { 248 Lexer_yystype lexer; // terminal values from the lexical scanner 249 /* 250 Hint parser section (sql_hints.yy) 251 */ 252 opt_hints_enum hint_type; 253 class PT_hint *hint; 254 class PT_hint_list *hint_list; 255 Hint_param_index_list hint_param_index_list; 256 Hint_param_table hint_param_table; 257 Hint_param_table_list hint_param_table_list; 258 259 /* 260 Main parser section (sql_yacc.yy) 261 */ 262 int num; 263 ulong ulong_num; 264 ulonglong ulonglong_number; 265 LEX_CSTRING lex_cstr; 266 LEX_STRING *lex_str_ptr; 267 Table_ident *table; 268 char *simple_string; 269 Item *item; 270 Item_num *item_num; 271 List<Item> *item_list; 272 List<String> *string_list; 273 String *string; 274 Mem_root_array<Table_ident *> *table_list; 275 udf_func *udf; 276 LEX_USER *lex_user; 277 List<LEX_USER> *user_list; 278 struct sys_var_with_base variable; 279 enum enum_var_type var_type; 280 keytype key_type; 281 enum ha_key_alg key_alg; 282 enum row_type row_type; 283 enum ha_rkey_function ha_rkey_mode; 284 enum_ha_read_modes ha_read_mode; 285 enum enum_tx_isolation tx_isolation; 286 const char *c_str; 287 struct { 288 const CHARSET_INFO *charset; 289 bool force_binary; 290 } charset_with_opt_binary; 291 struct { 292 const char *length; 293 const char *dec; 294 } precision; 295 struct Cast_type cast_type; 296 thr_lock_type lock_type; 297 interval_type interval, interval_time_st; 298 enum_mysql_timestamp_type date_time_type; 299 SELECT_LEX *select_lex; 300 chooser_compare_func_creator boolfunc2creator; 301 class sp_condition_value *spcondvalue; 302 struct { 303 int vars, conds, hndlrs, curs; 304 } spblock; 305 sp_name *spname; 306 LEX *lex; 307 sp_head *sphead; 308 enum index_hint_type index_hint; 309 enum enum_filetype filetype; 310 enum fk_option m_fk_option; 311 enum enum_yes_no_unknown m_yes_no_unk; 312 enum_condition_item_name da_condition_item_name; 313 Diagnostics_information::Which_area diag_area; 314 Diagnostics_information *diag_info; 315 Statement_information_item *stmt_info_item; 316 Statement_information_item::Name stmt_info_item_name; 317 List<Statement_information_item> *stmt_info_list; 318 Condition_information_item *cond_info_item; 319 Condition_information_item::Name cond_info_item_name; 320 List<Condition_information_item> *cond_info_list; 321 bool is_not_empty; 322 Set_signal_information *signal_item_list; 323 enum enum_trigger_order_type trigger_action_order_type; 324 struct { 325 enum enum_trigger_order_type ordering_clause; 326 LEX_CSTRING anchor_trigger_name; 327 } trg_characteristics; 328 class Index_hint *key_usage_element; 329 List<Index_hint> *key_usage_list; 330 class PT_subselect *subselect; 331 class PT_item_list *item_list2; 332 class PT_order_expr *order_expr; 333 class PT_order_list *order_list; 334 struct Limit_options limit_options; 335 Query_options select_options; 336 class PT_limit_clause *limit_clause; 337 Parse_tree_node *node; 338 enum olap_type olap_type; 339 class PT_group *group; 340 class PT_window_list *windows; 341 class PT_window *window; 342 class PT_frame *window_frame; 343 enum_window_frame_unit frame_units; 344 class PT_borders *frame_extent; 345 class PT_border *bound; 346 class PT_exclusion *frame_exclusion; 347 enum enum_null_treatment null_treatment; 348 enum enum_from_first_last from_first_last; 349 Item_string *item_string; 350 class PT_order *order; 351 class PT_table_reference *table_reference; 352 class PT_joined_table *join_table; 353 enum PT_joined_table_type join_type; 354 class PT_internal_variable_name *internal_variable_name; 355 class PT_option_value_following_option_type 356 *option_value_following_option_type; 357 class PT_option_value_no_option_type *option_value_no_option_type; 358 class PT_option_value_list_head *option_value_list; 359 class PT_start_option_value_list *start_option_value_list; 360 class PT_transaction_access_mode *transaction_access_mode; 361 class PT_isolation_level *isolation_level; 362 class PT_transaction_characteristics *transaction_characteristics; 363 class PT_start_option_value_list_following_option_type 364 *start_option_value_list_following_option_type; 365 class PT_set *set; 366 Line_separators line_separators; 367 Field_separators field_separators; 368 class PT_into_destination *into_destination; 369 class PT_select_var *select_var_ident; 370 class PT_select_var_list *select_var_list; 371 Mem_root_array_YY<PT_table_reference *> table_reference_list; 372 class Item_param *param_marker; 373 class PTI_text_literal *text_literal; 374 class PT_query_expression *query_expression; 375 class PT_derived_table *derived_table; 376 class PT_query_expression_body *query_expression_body; 377 class PT_query_primary *query_primary; 378 class PT_subquery *subquery; 379 class PT_key_part_specification *key_part; 380 381 XID *xid; 382 enum xa_option_words xa_option_type; 383 struct { 384 Item *column; 385 Item *value; 386 } column_value_pair; 387 struct { 388 class PT_item_list *column_list; 389 class PT_item_list *value_list; 390 } column_value_list_pair; 391 struct { 392 class PT_item_list *column_list; 393 class PT_insert_values_list *row_value_list; 394 } column_row_value_list_pair; 395 struct { 396 class PT_item_list *column_list; 397 class PT_query_primary *insert_query_expression; 398 } insert_query_expression; 399 struct { 400 class Item *offset; 401 class Item *default_value; 402 } lead_lag_info; 403 class PT_insert_values_list *values_list; 404 Parse_tree_root *top_level_node; 405 class Table_ident *table_ident; 406 Mem_root_array_YY<Table_ident *> table_ident_list; 407 delete_option_enum opt_delete_option; 408 class PT_alter_instance *alter_instance_cmd; 409 class PT_create_index_stmt *create_index_stmt; 410 class PT_table_constraint_def *table_constraint_def; 411 List<PT_key_part_specification> *index_column_list; 412 struct { 413 LEX_STRING name; 414 class PT_base_index_option *type; 415 } index_name_and_type; 416 PT_base_index_option *index_option; 417 Mem_root_array_YY<PT_base_index_option *> index_options; 418 Mem_root_array_YY<LEX_STRING> lex_str_list; 419 bool visibility; 420 class PT_with_clause *with_clause; 421 class PT_with_list *with_list; 422 class PT_common_table_expr *common_table_expr; 423 Create_col_name_list simple_ident_list; 424 class PT_partition_option *partition_option; 425 Mem_root_array<PT_partition_option *> *partition_option_list; 426 class PT_subpartition *sub_part_definition; 427 Mem_root_array<PT_subpartition *> *sub_part_list; 428 class PT_part_value_item *part_value_item; 429 Mem_root_array<PT_part_value_item *> *part_value_item_list; 430 class PT_part_value_item_list_paren *part_value_item_list_paren; 431 Mem_root_array<PT_part_value_item_list_paren *> *part_value_list; 432 class PT_part_values *part_values; 433 struct { 434 partition_type type; 435 PT_part_values *values; 436 } opt_part_values; 437 class PT_part_definition *part_definition; 438 Mem_root_array<PT_part_definition *> *part_def_list; 439 List<char> *name_list; // TODO: merge with string_list 440 enum_key_algorithm opt_key_algo; 441 class PT_sub_partition *opt_sub_part; 442 class PT_part_type_def *part_type_def; 443 class PT_partition *partition_clause; 444 class PT_add_partition *add_partition_rule; 445 struct { 446 decltype(HA_CHECK_OPT::flags) flags; 447 decltype(HA_CHECK_OPT::sql_flags) sql_flags; 448 } mi_type; 449 enum_drop_mode opt_restrict; 450 Ternary_option ternary_option; 451 class PT_create_table_option *create_table_option; 452 Mem_root_array<PT_create_table_option *> *create_table_options; 453 Mem_root_array<PT_ddl_table_option *> *space_separated_alter_table_opts; 454 On_duplicate on_duplicate; 455 class PT_column_attr_base *col_attr; 456 column_format_type column_format; 457 ha_storage_media storage_media; 458 Mem_root_array<PT_column_attr_base *> *col_attr_list; 459 Virtual_or_stored virtual_or_stored; 460 ulong field_option; // 0 or combinations of UNSIGNED_FLAG and ZEROFILL_FLAG 461 Int_type int_type; 462 class PT_type *type; 463 Numeric_type numeric_type; 464 struct { 465 const char *expr_start; 466 Item *expr; 467 } sp_default; 468 class PT_field_def_base *field_def; 469 struct { 470 fk_option fk_update_opt; 471 fk_option fk_delete_opt; 472 } fk_options; 473 fk_match_opt opt_match_clause; 474 List<Key_part_spec> *reference_list; 475 struct { 476 Table_ident *table_name; 477 List<Key_part_spec> *reference_list; 478 fk_match_opt fk_match_option; 479 fk_option fk_update_opt; 480 fk_option fk_delete_opt; 481 } fk_references; 482 class PT_column_def *column_def; 483 class PT_table_element *table_element; 484 Mem_root_array<PT_table_element *> *table_element_list; 485 struct { 486 Mem_root_array<PT_create_table_option *> *opt_create_table_options; 487 PT_partition *opt_partitioning; 488 On_duplicate on_duplicate; 489 PT_query_primary *opt_query_expression; 490 } create_table_tail; 491 Lock_strength lock_strength; 492 Locked_row_action locked_row_action; 493 class PT_locking_clause *locking_clause; 494 class PT_locking_clause_list *locking_clause_list; 495 Mem_root_array<PT_json_table_column *> *jtc_list; 496 // ON EMPTY/ON ERROR response for JSON_TABLE and JSON_VALUE. 497 struct Json_on_response { 498 Json_on_response_type type; 499 Item *default_string; 500 } json_on_response; 501 struct { 502 Json_on_response error; 503 Json_on_response empty; 504 } json_on_error_or_empty; 505 PT_json_table_column *jt_column; 506 enum_jt_column jt_column_type; 507 struct { 508 LEX_STRING wild; 509 Item *where; 510 } wild_or_where; 511 Show_cmd_type show_cmd_type; 512 struct { 513 Sql_cmd_analyze_table::Histogram_command command; 514 List<String> *columns; 515 int num_buckets; 516 } histogram; 517 Acl_type acl_type; 518 Mem_root_array<LEX_CSTRING> *lex_cstring_list; 519 class PT_role_or_privilege *role_or_privilege; 520 Mem_root_array<PT_role_or_privilege *> *role_or_privilege_list; 521 enum_order order_direction; 522 Alter_info::enum_with_validation with_validation; 523 class PT_alter_table_action *alter_table_action; 524 class PT_alter_table_standalone_action *alter_table_standalone_action; 525 Alter_info::enum_alter_table_algorithm alter_table_algorithm; 526 Alter_info::enum_alter_table_lock alter_table_lock; 527 struct Algo_and_lock { 528 Enum_parser<Alter_info::enum_alter_table_algorithm, 529 Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT> 530 algo; 531 Enum_parser<Alter_info::enum_alter_table_lock, 532 Alter_info::ALTER_TABLE_LOCK_DEFAULT> 533 lock; initYYSTYPE::Algo_and_lock534 void init() { 535 algo.init(); 536 lock.init(); 537 } 538 } opt_index_lock_and_algorithm; 539 struct Algo_and_lock_and_validation { 540 Enum_parser<Alter_info::enum_alter_table_algorithm, 541 Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT> 542 algo; 543 Enum_parser<Alter_info::enum_alter_table_lock, 544 Alter_info::ALTER_TABLE_LOCK_DEFAULT> 545 lock; 546 Enum_parser<Alter_info::enum_with_validation, 547 Alter_info::ALTER_VALIDATION_DEFAULT> 548 validation; initYYSTYPE::Algo_and_lock_and_validation549 void init() { 550 algo.init(); 551 lock.init(); 552 validation.init(); 553 } mergeYYSTYPE::Algo_and_lock_and_validation554 void merge(const Algo_and_lock_and_validation &x) { 555 algo.merge(x.algo); 556 lock.merge(x.lock); 557 validation.merge(x.validation); 558 } 559 } algo_and_lock_and_validation; 560 struct { 561 Algo_and_lock_and_validation flags; 562 Mem_root_array<PT_ddl_table_option *> *actions; 563 } alter_list; 564 struct { 565 Algo_and_lock_and_validation flags; 566 PT_alter_table_standalone_action *action; 567 } standalone_alter_table_action; 568 class PT_assign_to_keycache *assign_to_keycache; 569 Mem_root_array<PT_assign_to_keycache *> *keycache_list; 570 class PT_adm_partition *adm_partition; 571 class PT_preload_keys *preload_keys; 572 Mem_root_array<PT_preload_keys *> *preload_list; 573 PT_alter_tablespace_option_base *ts_option; 574 Mem_root_array<PT_alter_tablespace_option_base *> *ts_options; 575 struct { 576 resourcegroups::platform::cpu_id_t start; 577 resourcegroups::platform::cpu_id_t end; 578 } vcpu_range_type; 579 Mem_root_array<resourcegroups::Range> *resource_group_vcpu_list_type; 580 Value_or_default<int> resource_group_priority_type; 581 Value_or_default<bool> resource_group_state_type; 582 bool resource_group_flag_type; 583 resourcegroups::Type resource_group_type; 584 Mem_root_array<ulonglong> *thread_id_list_type; 585 Explain_format_type explain_format_type; 586 struct { 587 Item *set_var; 588 Item *set_expr; 589 String *set_expr_str; 590 } load_set_element; 591 struct { 592 PT_item_list *set_var_list; 593 PT_item_list *set_expr_list; 594 List<String> *set_expr_str_list; 595 } load_set_list; 596 ts_alter_tablespace_type alter_tablespace_type; 597 Sql_cmd_srs_attributes *sql_cmd_srs_attributes; 598 struct { 599 LEX_CSTRING table_alias; 600 Create_col_name_list *column_list; 601 } insert_update_values_reference; 602 }; 603 604 static_assert(sizeof(YYSTYPE) <= 32, "YYSTYPE is too big"); 605 606 #endif // PARSER_YYSTYPE_INCLUDED 607