MySQL  8.0.19
Source Code Documentation
parse_tree_nodes.h
Go to the documentation of this file.
1 /* Copyright (c) 2013, 2019, 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 PARSE_TREE_NODES_INCLUDED
24 #define PARSE_TREE_NODES_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <cctype> // std::isspace
29 #include <memory>
30 
31 #include "lex_string.h"
32 #include "my_alloc.h"
33 #include "my_base.h"
34 #include "my_bit.h" // is_single_bit
35 #include "my_dbug.h"
36 #include "my_inttypes.h"
37 #include "my_sqlcommand.h"
38 #include "my_sys.h"
39 #include "my_thread_local.h"
40 #include "my_time.h"
41 #include "mysqld_error.h"
42 #include "sql/enum_query_type.h"
43 #include "sql/handler.h"
44 #include "sql/key_spec.h"
45 #include "sql/mem_root_array.h"
46 #include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
47 #include "sql/parse_tree_helpers.h" // PT_item_list
49 #include "sql/parser_yystype.h"
50 #include "sql/partition_info.h"
53 #include "sql/set_var.h"
54 #include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
55 #include "sql/sql_alter.h"
56 #include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
57 #include "sql/sql_cmd_srs.h"
58 #include "sql/sql_exchange.h"
59 #include "sql/sql_lex.h" // LEX
60 #include "sql/sql_list.h"
61 #include "sql/sql_load.h" // Sql_cmd_load_table
63 #include "sql/sql_restart_server.h" // Sql_cmd_restart_server
64 #include "sql/sql_show.h"
65 #include "sql/sql_tablespace.h" // Tablespace_options
66 #include "sql/sql_truncate.h" // Sql_cmd_truncate_table
67 #include "sql/table.h" // Common_table_expr
68 #include "sql/window.h" // Window
69 #include "sql/window_lex.h"
70 #include "thr_lock.h"
71 
72 class Item;
73 class Item_cache;
74 class Item_string;
75 class Json_table_column;
76 class PT_field_def_base;
77 class PT_hint_list;
78 class PT_part_definition;
79 class PT_partition;
80 class PT_subquery;
81 class PT_type;
82 class sp_head;
83 class sp_name;
84 class Sql_cmd;
85 class String;
86 class THD;
87 enum class enum_jt_column;
88 enum class enum_jtc_on : uint16;
89 struct CHARSET_INFO;
90 
91 /**
92  @defgroup ptn Parse tree nodes
93  @ingroup Parser
94 */
95 /**
96  @defgroup ptn_stmt Nodes representing SQL statements
97  @ingroup ptn
98 */
99 /**
100  @defgroup ptn_create_table CREATE TABLE statement
101  @ingroup ptn_stmt
102 */
103 /**
104  @defgroup ptn_alter_table ALTER TABLE statement
105  @ingroup ptn_stmt
106 */
107 /**
108  @defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
109  @ingroup ptn_create_table
110 */
111 /**
112  @defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
113  @ingroup ptn_create_table ptn_alter_table
114 */
115 /**
116  @defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
117  @ingroup ptn_partitioning
118 */
119 /**
120  @defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
121  TABLE
122  @anchor ptn_create_or_alter_table_options
123  @ingroup ptn_create_table ptn_alter_table
124 */
125 /**
126  @defgroup ptn_col_types Column types in CREATE/ALTER TABLE
127  @ingroup ptn_create_table ptn_alter_table
128 */
129 /**
130  @defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
131  @ingroup ptn_create_table ptn_alter_table
132 */
133 /**
134  @defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
135  TABLE
136  @ingroup ptn_col_attrs ptn_alter_table
137 */
138 
139 /**
140  Calls contextualize() on every node in the array.
141 */
142 template <class Node_type, class Parse_context_type>
143 bool contextualize_nodes(Mem_root_array_YY<Node_type *> nodes,
144  Parse_context_type *pc) {
145  for (Node_type *i : nodes)
146  if (i->contextualize(pc)) return true;
147  return false;
148 }
149 
150 /**
151  Base class for all top-level nodes of SQL statements
152 
153  @ingroup ptn_stmt
154 */
156  Parse_tree_root(const Parse_tree_root &) = delete;
157  void operator=(const Parse_tree_root &) = delete;
158 
159  protected:
160  virtual ~Parse_tree_root() {}
162 
163  public:
164  virtual Sql_cmd *make_cmd(THD *thd) = 0;
165 };
166 
168  public:
170  : m_alter_info(mem_root) {}
171 
172  virtual ~PT_table_ddl_stmt_base() = 0; // force abstract class
173 
174  protected:
176 };
177 
179 
180 /**
181  Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
182 
183  For internal use in the contextualization code.
184 */
186  Table_ddl_parse_context(THD *thd_arg, SELECT_LEX *select_arg,
191 };
192 
193 /**
194  Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
195 */
197 
198 class PT_order_expr : public Parse_tree_node, public ORDER {
200 
201  public:
202  PT_order_expr(Item *item_arg, enum_order dir) {
203  item_ptr = item_arg;
204  direction = (dir == ORDER_DESC) ? ORDER_DESC : ORDER_ASC;
205  }
206 
207  bool contextualize(Parse_context *pc) override;
208 };
209 
212 
213  public:
215 
216  public:
217  bool contextualize(Parse_context *pc) override {
218  if (super::contextualize(pc)) return true;
219  for (ORDER *o = value.first; o != NULL; o = o->next) {
220  if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
221  }
222  return false;
223  }
224 
225  void push_back(PT_order_expr *order) {
226  order->item = &order->item_ptr;
227  order->used_alias = false;
228  order->used = 0;
229  order->is_position = false;
230  value.link_in_list(order, &order->next);
231  }
232 };
233 
236 
237  public:
238  bool contextualize(Parse_context *pc) override {
239  return super::contextualize(pc);
240  }
241 };
242 
243 /**
244  Represents an element of the WITH list:
245  WITH [...], [...] SELECT ...,
246  ^ or ^
247  i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
248 */
251 
252  public:
253  explicit PT_common_table_expr(const LEX_STRING &name,
254  const LEX_STRING &subq_text,
255  uint subq_text_offset, PT_subquery *sn,
257  MEM_ROOT *mem_root);
258 
259  /// The name after AS
260  const LEX_STRING &name() const { return m_name; }
261  /**
262  @param thd Thread handler
263  @param[out] node PT_subquery
264  @returns a PT_subquery to attach to a table reference for this CTE
265  */
266  bool make_subquery_node(THD *thd, PT_subquery **node);
267  /**
268  @param tl Table reference to match
269  @param in_self If this is a recursive reference
270  @param[out] found Is set to true/false if matches or not
271  @returns true if error
272  */
273  bool match_table_ref(TABLE_LIST *tl, bool in_self, bool *found);
274  /**
275  @returns true if 'other' is the same instance as 'this'
276  */
277  bool is(const Common_table_expr *other) const {
278  return other == &m_postparse;
279  }
280  void print(const THD *thd, String *str, enum_query_type query_type);
281 
282  private:
284  /// Raw text of query expression (including parentheses)
286  /**
287  Offset in bytes of m_subq_text in original statement which had the WITH
288  clause.
289  */
291  /// Parsed version of subq_text
293  /// List of explicitely specified column names; if empty, no list.
295  /**
296  A TABLE_LIST representing a CTE needs access to the WITH list
297  element it derives from. However, in order to:
298  - limit the members which TABLE_LIST can access
299  - avoid including this header file everywhere TABLE_LIST needs to access
300  these members,
301  these members are relocated into a separate inferior object whose
302  declaration is in table.h, like that of TABLE_LIST. It's the "postparse"
303  part. TABLE_LIST accesses this inferior object only.
304  */
306 
308 };
309 
310 /**
311  Represents the WITH list.
312  WITH [...], [...] SELECT ...,
313  ^^^^^^^^^^^^
314 */
317 
318  public:
319  /// @param mem_root where interior objects are allocated
323  return m_elements;
324  }
325 
326  private:
328 };
329 
330 /**
331  Represents the WITH clause:
332  WITH [...], [...] SELECT ...,
333  ^^^^^^^^^^^^^^^^^
334 */
337 
338  public:
339  PT_with_clause(const PT_with_list *l, bool r)
340  : m_list(l), m_recursive(r), m_most_inner_in_parsing(nullptr) {}
341 
342  bool contextualize(Parse_context *pc) override;
343 
344  /**
345  Looks up a table reference into the list of CTEs.
346  @param tl Table reference to look up
347  @param[out] found Is set to true/false if found or not
348  @returns true if error
349  */
350  bool lookup(TABLE_LIST *tl, PT_common_table_expr **found);
351  /**
352  Call this to record in the WITH clause that we are contextualizing the
353  CTE definition inserted in table reference 'tl'.
354  @returns information which the caller must provide to
355  leave_parsing_definition().
356  */
358  auto old = m_most_inner_in_parsing;
360  return old;
361  }
364  }
365  void print(const THD *thd, String *str, enum_query_type query_type);
366 
367  private:
368  /// All CTEs of this clause
369  const PT_with_list *const m_list;
370  /// True if the user has specified the RECURSIVE keyword.
371  const bool m_recursive;
372  /**
373  The innermost CTE reference which we're parsing at the
374  moment. Used to detect forward references, loops and recursiveness.
375  */
377 
379 };
380 
383 
384  public:
385  bool contextualize(Parse_context *pc) override;
386 };
387 
390 
392 
393  public:
394  PT_limit_clause(const Limit_options &limit_options_arg)
395  : limit_options(limit_options_arg) {}
396 
397  bool contextualize(Parse_context *pc) override;
398 };
399 
400 class PT_cross_join;
401 class PT_joined_table;
402 
404  public:
406 
407  /**
408  Lets us build a parse tree top-down, which is necessary due to the
409  context-dependent nature of the join syntax. This function adds
410  the `<table_ref>` cross join as the left-most leaf in this join tree
411  rooted at this node.
412 
413  @todo: comment on non-join PT_table_reference objects
414 
415  @param cj This `<table ref>` will be added if it represents a cross join.
416 
417  @return The new top-level join.
418  */
420 };
421 
424 
427  const char *const opt_table_alias;
429 
430  public:
432  List<String> *opt_use_partition_arg,
433  const LEX_CSTRING &opt_table_alias_arg,
434  List<Index_hint> *opt_key_definition_arg)
435  : table_ident(table_ident_arg),
436  opt_use_partition(opt_use_partition_arg),
437  opt_table_alias(opt_table_alias_arg.str),
438  opt_key_definition(opt_key_definition_arg) {}
439 
440  bool contextualize(Parse_context *pc) override;
441 };
442 
444  public:
445  virtual Json_table_column *get_column() = 0;
446 };
447 
450 
451  public:
454  const LEX_STRING &table_alias)
455  : m_expr(expr),
456  m_path(path),
457  m_nested_columns(nested_cols),
458  m_table_alias(table_alias) {}
459 
460  bool contextualize(Parse_context *pc) override;
461 
462  private:
467 };
468 
471 
473 
474  public:
477  : table_list(table_list) {}
478 
479  bool contextualize(Parse_context *pc) override;
480 };
481 
484 
485  public:
486  PT_derived_table(bool lateral, PT_subquery *subquery,
487  const LEX_CSTRING &table_alias,
489 
490  bool contextualize(Parse_context *pc) override;
491 
492  private:
493  bool m_lateral;
495  const char *const m_table_alias;
496  /// List of explicitely specified column names; if empty, no list.
498 };
499 
502 
503  public:
505  : m_joined_table(joined_table) {}
506 
507  bool contextualize(Parse_context *pc) override;
508 
509  private:
511 };
512 
515 
516  protected:
521 
524 
525  public:
526  PT_joined_table(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
528  : tab1_node(tab1_node_arg),
529  join_pos(join_pos_arg),
530  m_type(type),
531  tab2_node(tab2_node_arg),
532  tr1(NULL),
533  tr2(NULL) {
534  static_assert(is_single_bit(JTT_INNER), "not a single bit");
535  static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
536  static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
537  static_assert(is_single_bit(JTT_LEFT), "not a single bit");
538  static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
539 
542  type == JTT_NATURAL_RIGHT || type == JTT_LEFT ||
543  type == JTT_RIGHT);
544  }
545 
546  /**
547  Adds the cross join to this join operation. The cross join is nested as
548  the table reference on the left-hand side.
549  */
552  return this;
553  }
554 
555  /// Adds the table reference as the right-hand side of this join.
558  tab2_node = table;
559  }
560 
561  bool contextualize(Parse_context *pc) override;
562 
563  /// This class is being inherited, it should thus be abstract.
564  ~PT_joined_table() override = 0;
565 
566  protected:
568  if (tr1 != NULL) return false; // already done
569 
571  return true;
572 
573  tr1 = tab1_node->value;
574  tr2 = tab2_node->value;
575 
576  if (tr1 == NULL || tr2 == NULL) {
577  error(pc, join_pos);
578  return true;
579  }
580  return false;
581  }
582 };
583 
585 
588 
589  public:
590  PT_cross_join(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
591  PT_joined_table_type Type_arg,
592  PT_table_reference *tab2_node_arg)
593  : PT_joined_table(tab1_node_arg, join_pos_arg, Type_arg, tab2_node_arg) {}
594 
595  bool contextualize(Parse_context *pc) override;
596 };
597 
601 
602  public:
603  PT_joined_table_on(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
605  PT_table_reference *tab2_node_arg, Item *on_arg)
606  : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg), on(on_arg) {}
607 
608  bool contextualize(Parse_context *pc) override;
609 };
610 
614 
615  public:
617  const POS &join_pos_arg, PT_joined_table_type type,
618  PT_table_reference *tab2_node_arg,
619  List<String> *using_fields_arg)
620  : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg),
621  using_fields(using_fields_arg) {}
622 
623  /// A PT_joined_table_using without a list of columns denotes a natural join.
625  const POS &join_pos_arg, PT_joined_table_type type,
626  PT_table_reference *tab2_node_arg)
627  : PT_joined_table_using(tab1_node_arg, join_pos_arg, type, tab2_node_arg,
628  NULL) {}
629 
630  bool contextualize(Parse_context *pc) override;
631 };
632 
633 class PT_group : public Parse_tree_node {
635 
638 
639  public:
640  PT_group(PT_order_list *group_list_arg, olap_type olap_arg)
641  : group_list(group_list_arg), olap(olap_arg) {}
642 
643  bool contextualize(Parse_context *pc) override;
644 };
645 
646 class PT_order : public Parse_tree_node {
648 
650 
651  public:
652  explicit PT_order(PT_order_list *order_list_arg)
653  : order_list(order_list_arg) {}
654 
655  bool contextualize(Parse_context *pc) override;
656 };
657 
659  public:
662 
663  bool contextualize(Parse_context *pc) override final;
664 
665  virtual bool set_lock_for_tables(Parse_context *pc) = 0;
666 
668 
669  protected:
671  thr_lock_type lock_type = TL_IGNORE;
672  switch (m_lock_strength) {
674  lock_type = TL_WRITE;
675  break;
677  lock_type = TL_READ_WITH_SHARED_LOCKS;
678  break;
679  }
680 
681  return {lock_type, static_cast<thr_locked_row_action>(action())};
682  }
683 
684  private:
687 };
688 
690  public:
692  Lock_strength strength,
694  : PT_locking_clause(strength, action) {}
695 
696  bool set_lock_for_tables(Parse_context *pc) override;
697 };
698 
700  public:
702 
706  : PT_locking_clause(strength, action), m_tables(tables) {}
707 
708  bool set_lock_for_tables(Parse_context *pc) override;
709 
710  private:
711  /// @todo Move this function to Table_ident?
712  void print_table_ident(const THD *thd, const Table_ident *ident, String *s);
713 
714  bool raise_error(THD *thd, const Table_ident *name, int error);
715 
716  bool raise_error(int error);
717 
719 };
720 
722  public:
725  }
726 
727  bool push_back(PT_locking_clause *locking_clause) {
728  return m_locking_clauses.push_back(locking_clause);
729  }
730 
731  bool contextualize(Parse_context *pc) override {
732  for (auto locking_clause : m_locking_clauses)
733  if (locking_clause->contextualize(pc)) return true;
734  return false;
735  }
736 
737  private:
739 };
740 
742  public:
743  virtual bool is_union() const = 0;
744 
745  /**
746  True if this query expression can absorb an extraneous order by/limit
747  clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
748  trailing clause may not refer to the tables in the `<query primary>`, with
749  one glaring exception:
750 
751  (...( SELECT ... )...) ORDER BY ...
752 
753  If the nested query expression doesn't contain `ORDER BY`, the statement
754  is interpreted as if the `ORDER BY` was absorbed by the innermost query
755  expression, i.e.:
756 
757  (...( SELECT ... ORDER BY ... )...)
758 
759  There is no rewriting of the parse tree nor AST happening here, the
760  transformation is done by the contextualizer (see
761  PT_query_expression::contextualize_order_and_limit), which interprets the
762  parse tree, and builds the AST according to this interpretation. This
763  interpretation is governed by the following rule: An `ORDER BY` can be
764  absorbed if none the nested query expressions contains an `ORDER BY` *or*
765  `LIMIT`. The rule is complex, so here are some examples for illustration:
766 
767  In these cases the `ORDER BY` *is* absorbed:
768 
769  ( SELECT * FROM t1 ) ORDER BY t1.a;
770  (( SELECT * FROM t1 )) ORDER BY t1.a;
771 
772  In these cases the ORDER BY is *not* absorbed:
773 
774  ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
775  (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
776  ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
777  (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
778 
779  The same happens with `LIMIT`, obviously, but the optimizer is freeer to
780  choose when to apply the limit, and there are name no resolution issues
781  involved.
782 
783  @param order True if the outer query block has the ORDER BY clause.
784  @param limit True if the outer query block has the LIMIT clause.
785  */
786  virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
787  virtual bool has_into_clause() const = 0;
788 
789  virtual bool is_table_value_constructor() const = 0;
790  virtual PT_insert_values_list *get_row_value_list() const = 0;
791 };
792 
794  public:
796 };
797 
800 
802 
803  public:
804  PT_internal_variable_name_1d(LEX_CSTRING ident_arg) : ident(ident_arg) {}
805 
806  bool contextualize(Parse_context *pc) override;
807 };
808 
809 /**
810  Parse tree node class for 2-dimentional variable names (example: \@global.x)
811 */
814 
815  public:
816  const POS pos;
817 
818  private:
821 
822  public:
824  LEX_CSTRING ident2_arg)
825  : pos(pos), ident1(ident1_arg), ident2(ident2_arg) {}
826 
827  bool contextualize(Parse_context *pc) override;
828 };
829 
832 
834 
835  public:
837  : ident(ident_arg) {}
838 
839  bool contextualize(Parse_context *pc) override;
840 };
841 
844 
848 
849  public:
851  PT_internal_variable_name *name_arg,
852  Item *opt_expr_arg)
853  : pos(pos), name(name_arg), opt_expr(opt_expr_arg) {}
854 
855  bool contextualize(Parse_context *pc) override;
856 };
857 
859 
863 
867 
868  public:
870  Item *opt_expr_arg,
871  const POS &expr_pos_arg)
872  : name(name_arg), opt_expr(opt_expr_arg), expr_pos(expr_pos_arg) {}
873 
874  bool contextualize(Parse_context *pc) override;
875 };
876 
880 
883 
884  public:
886  Item *expr_arg)
887  : name(name_arg), expr(expr_arg) {}
888 
889  bool contextualize(Parse_context *pc) override;
890 };
891 
895 
899 
900  public:
902  PT_internal_variable_name *name_arg,
903  Item *opt_expr_arg)
904  : type(type_arg), name(name_arg), opt_expr(opt_expr_arg) {}
905 
906  bool contextualize(Parse_context *pc) override;
907 };
908 
912 
914 
915  public:
917  : opt_charset(opt_charset_arg) {}
918 
919  bool contextualize(Parse_context *pc) override;
920 };
921 
925 
927 
928  public:
930 
931  bool contextualize(Parse_context *pc) override;
932 };
933 
936 
939 
940  public:
941  PT_set_names(const CHARSET_INFO *opt_charset_arg,
942  const CHARSET_INFO *opt_collation_arg)
943  : opt_charset(opt_charset_arg), opt_collation(opt_collation_arg) {}
944 
945  bool contextualize(Parse_context *pc) override;
946 };
947 
949 
951  : public PT_start_option_value_list {
953 
954  const char *password;
955  const char *current_password;
959 
960  public:
961  PT_option_value_no_option_type_password(const char *password_arg,
962  const char *current_password_arg,
963  bool retain_current,
964  bool random_password,
965  const POS &expr_pos_arg)
966  : password(password_arg),
967  current_password(current_password_arg),
968  retain_current_password(retain_current),
969  random_password_generator(random_password),
970  expr_pos(expr_pos_arg) {}
971 
972  bool contextualize(Parse_context *pc) override;
973 };
974 
976  : public PT_start_option_value_list {
978 
980  const char *password;
981  const char *current_password;
985 
986  public:
988  const char *password_arg,
989  const char *current_password_arg,
990  bool retain_current,
991  bool random_pass,
992  const POS &expr_pos_arg)
993  : user(user_arg),
994  password(password_arg),
995  current_password(current_password_arg),
996  retain_current_password(retain_current),
997  random_password_generator(random_pass),
998  expr_pos(expr_pos_arg) {}
999 
1000  bool contextualize(Parse_context *pc) override;
1001 };
1002 
1005 
1008 
1009  public:
1012  : type(type_arg), value(value_arg) {}
1013 
1014  bool contextualize(Parse_context *pc) override;
1015 };
1016 
1019 
1023 
1024  public:
1025  PT_option_value_list_head(const POS &delimiter_pos_arg,
1026  Parse_tree_node *value_arg,
1027  const POS &value_pos_arg)
1028  : delimiter_pos(delimiter_pos_arg),
1029  value(value_arg),
1030  value_pos(value_pos_arg) {}
1031 
1032  bool contextualize(Parse_context *pc) override;
1033 };
1034 
1037 
1039 
1040  public:
1042  const POS &delimiter_pos_arg, Parse_tree_node *tail,
1043  const POS &tail_pos)
1044  : super(delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
1045 
1046  bool contextualize(Parse_context *pc) override {
1047  return head->contextualize(pc) || super::contextualize(pc);
1048  }
1049 };
1050 
1053 
1057 
1058  public:
1060  const POS &head_pos_arg,
1061  PT_option_value_list_head *tail_arg)
1062  : head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1063 
1064  bool contextualize(Parse_context *pc) override;
1065 };
1066 
1069 
1070  const char *name;
1072 
1073  public:
1074  PT_transaction_characteristic(const char *name_arg, int32 value_arg)
1075  : name(name_arg), value(value_arg) {}
1076 
1077  bool contextualize(Parse_context *pc) override;
1078 };
1079 
1082 
1083  public:
1084  explicit PT_transaction_access_mode(bool is_read_only)
1085  : super("transaction_read_only", (int32)is_read_only) {}
1086 };
1087 
1090 
1091  public:
1093  : super("transaction_isolation", (int32)level) {}
1094 };
1095 
1098 
1101 
1102  public:
1104  PT_transaction_characteristic *opt_tail_arg)
1105  : head(head_arg), opt_tail(opt_tail_arg) {}
1106 
1107  bool contextualize(Parse_context *pc) override {
1108  return (super::contextualize(pc) || head->contextualize(pc) ||
1109  (opt_tail != NULL && opt_tail->contextualize(pc)));
1110  }
1111 };
1112 
1114  : public PT_start_option_value_list {
1116 
1119 
1120  public:
1122  PT_transaction_characteristics *characteristics_arg,
1123  const POS &end_pos_arg)
1124  : characteristics(characteristics_arg), end_pos(end_pos_arg) {}
1125 
1126  bool contextualize(Parse_context *pc) override;
1127 };
1128 
1130  : public Parse_tree_node {};
1131 
1135 
1139 
1140  public:
1142  PT_option_value_following_option_type *head_arg, const POS &head_pos_arg,
1143  PT_option_value_list_head *opt_tail_arg)
1144  : head(head_arg), head_pos(head_pos_arg), opt_tail(opt_tail_arg) {}
1145 
1146  bool contextualize(Parse_context *pc) override;
1147 };
1148 
1152 
1155 
1156  public:
1158  PT_transaction_characteristics *characteristics_arg,
1159  const POS &characteristics_pos_arg)
1160  : characteristics(characteristics_arg),
1161  characteristics_pos(characteristics_pos_arg) {}
1162 
1163  bool contextualize(Parse_context *pc) override;
1164 };
1165 
1168 
1171 
1172  public:
1174  enum_var_type type_arg,
1176  : type(type_arg), list(list_arg) {}
1177 
1178  bool contextualize(Parse_context *pc) override;
1179 };
1180 
1181 class PT_set : public Parse_tree_node {
1183 
1186 
1187  public:
1188  PT_set(const POS &set_pos_arg, PT_start_option_value_list *list_arg)
1189  : set_pos(set_pos_arg), list(list_arg) {}
1190 
1191  bool contextualize(Parse_context *pc) override;
1192 };
1193 
1197 
1198  protected:
1200 
1201  public:
1202  bool contextualize(Parse_context *pc) override;
1203 };
1204 
1207 
1208  public:
1209  PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1210  const CHARSET_INFO *charset_arg,
1211  const Field_separators &field_term_arg,
1212  const Line_separators &line_term_arg)
1213  : PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
1214  m_exchange.cs = charset_arg;
1215  m_exchange.field.merge_field_separators(field_term_arg);
1216  m_exchange.line.merge_line_separators(line_term_arg);
1217  }
1218 
1219  bool contextualize(Parse_context *pc) override;
1220 
1221  private:
1223 };
1224 
1227 
1228  public:
1229  PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1230  : PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
1231 
1232  bool contextualize(Parse_context *pc) override;
1233 
1234  private:
1236 };
1237 
1239  public:
1241 
1242  explicit PT_select_var(const LEX_STRING &name_arg) : name(name_arg) {}
1243 
1244  virtual bool is_local() const { return false; }
1245  virtual uint get_offset() const {
1246  DBUG_ASSERT(0);
1247  return 0;
1248  }
1249 };
1250 
1253 
1255 
1256 #ifndef DBUG_OFF
1257  /*
1258  Routine to which this Item_splocal belongs. Used for checking if correct
1259  runtime context is used for variable handling.
1260  */
1262 #endif
1263 
1264  public:
1265  PT_select_sp_var(const LEX_STRING &name_arg) : super(name_arg) {}
1266 
1267  bool is_local() const override { return true; }
1268  uint get_offset() const override { return offset; }
1269 
1270  bool contextualize(Parse_context *pc) override;
1271 };
1272 
1275 
1276  public:
1278 
1280 
1281  bool contextualize(Parse_context *pc) override;
1282 
1283  bool push_back(PT_select_var *var) { return value.push_back(var); }
1284 };
1285 
1286 /**
1287  Parse tree node for a single of a window extent's borders,
1288  cf. <window frame extent> in SQL 2003.
1289 */
1290 class PT_border : public Parse_tree_node {
1291  friend class Window;
1292  Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1293  public:
1295  const bool m_date_time;
1297 
1298  ///< For unbounded border
1302  }
1303 
1304  ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1307 
1308  ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1310  : m_value(value),
1312  m_date_time(true),
1313  m_int_type(int_type) {}
1314 
1315  ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1316  Item *border() const { return m_value; }
1317  /// Need such low-level access so that fix_fields updates the right pointer
1318  Item **border_ptr() { return &m_value; }
1319 
1320  /**
1321  @returns Addition operator for computation of frames, nullptr if error.
1322  @param order_expr Expression to add/substract to
1323  @param prec true if PRECEDING
1324  @param asc true if ASC
1325  @param window only used for error generation
1326  */
1327  Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1328  const Window *window);
1329 };
1330 
1331 /**
1332  Parse tree node for one or both of a window extent's borders, cf.
1333  <window frame extent> in SQL 2003.
1334 */
1335 class PT_borders : public Parse_tree_node {
1337  friend class PT_frame;
1338 
1339  public:
1340  /**
1341  Constructor.
1342 
1343  Frames of the form "frame_start no_frame_end" are translated during
1344  parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1345  'end' are non-nullptr.
1346  */
1348  m_borders[0] = start;
1349  m_borders[1] = end;
1350  }
1351 };
1352 
1353 /**
1354  Parse tree node for a window frame's exclusions, cf. the
1355  <window frame exclusion> clause in SQL 2003.
1356 */
1359 
1360  public:
1362  // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1363 };
1364 
1365 /**
1366  Parse tree node for a window's frame, cf. the <window frame clause>
1367  in SQL 2003.
1368 */
1369 class PT_frame : public Parse_tree_node {
1370  public:
1372 
1375 
1377 
1378  /// If true, this is an artificial frame, not specified by the user
1379  bool m_originally_absent = false;
1380 
1382  PT_exclusion *exclusion)
1383  : m_unit(unit),
1384  m_from(from_to->m_borders[0]),
1385  m_to(from_to->m_borders[1]),
1386  m_exclusion(exclusion) {}
1387 };
1388 
1389 /**
1390  Parse tree node for a window; just a shallow wrapper for
1391  class Window, q.v.
1392 */
1393 class PT_window : public Parse_tree_node, public Window {
1395 
1396  public:
1397  PT_window(PT_order_list *partition_by, PT_order_list *order_by,
1398  PT_frame *frame)
1399  : Window(partition_by, order_by, frame) {}
1400 
1401  PT_window(PT_order_list *partition_by, PT_order_list *order_by,
1402  PT_frame *frame, Item_string *inherit)
1403  : Window(partition_by, order_by, frame, inherit) {}
1404 
1406 
1407  bool contextualize(Parse_context *pc) override;
1408 };
1409 
1410 /**
1411  Parse tree node for a list of window definitions corresponding
1412  to a <window clause> in SQL 2003.
1413 */
1417 
1418  public:
1420 
1421  bool contextualize(Parse_context *pc) override;
1422 
1423  bool push_back(PT_window *w) { return m_windows.push_back(w); }
1424 };
1425 
1427 
1430 
1440 
1441  public:
1443  PT_hint_list *opt_hints_arg, const Query_options &options_arg,
1444  PT_item_list *item_list_arg, PT_into_destination *opt_into1_arg,
1445  const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1446  Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1447  Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg)
1448  : opt_hints(opt_hints_arg),
1449  options(options_arg),
1450  item_list(item_list_arg),
1451  opt_into1(opt_into1_arg),
1452  from_clause(from_clause_arg),
1453  opt_where_clause(opt_where_clause_arg),
1454  opt_group_clause(opt_group_clause_arg),
1455  opt_having_clause(opt_having_clause_arg),
1456  opt_window_clause(opt_window_clause_arg) {}
1457 
1459  const Query_options &options_arg, PT_item_list *item_list_arg,
1460  const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1461  Item *opt_where_clause_arg)
1462  : opt_hints(NULL),
1463  options(options_arg),
1464  item_list(item_list_arg),
1465  opt_into1(NULL),
1466  from_clause(from_clause_arg),
1467  opt_where_clause(opt_where_clause_arg),
1471 
1472  explicit PT_query_specification(const Query_options &options_arg,
1473  PT_item_list *item_list_arg)
1474  : opt_hints(NULL),
1475  options(options_arg),
1476  item_list(item_list_arg),
1477  opt_into1(NULL),
1483  }
1484 
1485  bool contextualize(Parse_context *pc) override;
1486 
1487  bool has_into_clause() const override { return opt_into1 != nullptr; }
1488 
1489  bool is_union() const override { return false; }
1490 
1491  bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1492 
1493  bool is_table_value_constructor() const override { return false; }
1494  PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1495 };
1496 
1499 
1501 
1502  public:
1504  : row_value_list(row_value_list_arg) {}
1505 
1506  bool contextualize(Parse_context *pc) override;
1507 
1508  bool has_into_clause() const override { return false; }
1509 
1510  bool is_union() const override { return false; }
1511 
1512  bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1513 
1514  bool is_table_value_constructor() const override { return true; }
1515 
1517  return row_value_list;
1518  }
1519 };
1520 
1523 
1524  public:
1526  const Query_options &options_arg, PT_item_list *item_list_arg,
1527  const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1528  : super(options_arg, item_list_arg, from_clause_arg, nullptr) {}
1529 };
1530 
1532  public:
1534  PT_query_expression_body *body, PT_order *order,
1535  PT_limit_clause *limit)
1536  : m_body(body),
1537  m_order(order),
1538  m_limit(limit),
1539  m_with_clause(with_clause) {}
1540 
1542  PT_limit_clause *limit)
1543  : PT_query_expression(nullptr, body, order, limit) {}
1544 
1546  : PT_query_expression(body, nullptr, nullptr) {}
1547 
1548  bool contextualize(Parse_context *pc) override;
1549 
1550  bool is_union() const override { return m_body->is_union(); }
1551 
1552  bool has_into_clause() const override { return m_body->has_into_clause(); }
1553 
1554  bool can_absorb_order_and_limit(bool order, bool limit) const override {
1555  if (m_body->is_union()) {
1556  return false;
1557  }
1558  if (m_order == nullptr && m_limit == nullptr) {
1559  /*
1560  It is safe to push ORDER and/or LIMIT down in:
1561 
1562  (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1563  (SELECT ...<no order or limit clauses>) ORDER BY ...;
1564  (SELECT ...<no order or limit clauses>) LIMIT ...;
1565  */
1566  return true;
1567  }
1568  if (m_limit != nullptr && !order && limit) {
1569  /*
1570  In MySQL, it is ok(*) to push LIMIT down in:
1571 
1572  (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1573 
1574  *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1575  `LIMIT b` if a < b. Moreover, the result of:
1576 
1577  (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1578 
1579  can diverge from:
1580 
1581  (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1582 
1583  since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1584  while the example (2) does overwrite.
1585 
1586  TODO: add a warning, deprecate and replace this behavior with the
1587  standard one.
1588  */
1589  return true;
1590  }
1591  return false;
1592  }
1593 
1594  bool is_table_value_constructor() const override {
1596  }
1597 
1599  return m_body->get_row_value_list();
1600  }
1601 
1602  private:
1603  /**
1604  Contextualizes the order and limit clauses, re-interpreting them according
1605  to the rules. If the `<query expression body>` can absorb the clauses,
1606  they are simply contextualized into the current SELECT_LEX. If not, we
1607  have to create the "fake" SELECT_LEX unless there is one already
1608  (SELECT_LEX_UNIT::new_union_query() is known to do this.)
1609 
1610  @see PT_query_expression::can_absorb_order_and_limit()
1611  */
1613 
1618 };
1619 
1620 /*
1621  After the removal of the `... <locking_clause> <into_clause>` syntax
1622  PT_locking will disappear.
1623 */
1626 
1627  public:
1629  PT_locking_clause_list *locking_clauses)
1630  : m_query_expression{qe}, m_locking_clauses{locking_clauses} {}
1631 
1632  bool contextualize(Parse_context *pc) override {
1635  }
1636 
1637  bool is_union() const override { return m_query_expression->is_union(); }
1638 
1639  bool has_into_clause() const override {
1641  }
1642 
1643  bool can_absorb_order_and_limit(bool order, bool limit) const override {
1644  return m_query_expression->can_absorb_order_and_limit(order, limit);
1645  }
1646 
1647  bool is_table_value_constructor() const override {
1649  }
1650 
1653  }
1654 
1655  private:
1658 };
1659 
1662 
1666 
1667  public:
1669 
1670  PT_subquery(POS p, PT_query_primary *query_expression)
1671  : qe(query_expression),
1672  pos(p),
1673  select_lex(NULL),
1675 
1676  bool contextualize(Parse_context *pc) override;
1677 
1678  SELECT_LEX *value() { return select_lex; }
1679 };
1680 
1682  public:
1683  PT_union(PT_query_expression_body *lhs, const POS &lhs_pos, bool is_distinct,
1684  PT_query_primary *rhs)
1685  : m_lhs(lhs),
1686  m_lhs_pos(lhs_pos),
1687  m_is_distinct(is_distinct),
1688  m_rhs(rhs) {}
1689 
1690  bool contextualize(Parse_context *pc) override;
1691 
1692  bool is_union() const override { return true; }
1693 
1694  bool has_into_clause() const override {
1695  return m_lhs->has_into_clause() || m_rhs->has_into_clause();
1696  }
1697 
1698  bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1699 
1700  bool is_table_value_constructor() const override { return false; }
1701  PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1702 
1703  private:
1709 };
1710 
1713 
1714  public:
1715  /**
1716  @param qe The query expression.
1717  @param sql_command The type of SQL command.
1718  */
1720  : m_sql_command(sql_command), m_qe(qe), m_into(NULL) {}
1721 
1722  /**
1723  Creates a SELECT command. Only SELECT commands can have into.
1724 
1725  @param qe The query expression.
1726  @param into The trailing INTO destination.
1727  */
1729  PT_into_destination *into = nullptr)
1730  : m_sql_command(SQLCOM_SELECT), m_qe(qe), m_into(into) {}
1731 
1732  Sql_cmd *make_cmd(THD *thd) override;
1733 
1734  private:
1738 };
1739 
1740 /**
1741  Top-level node for the DELETE statement
1742 
1743  @ingroup ptn_stmt
1744 */
1746  private:
1751  const char *const opt_table_alias;
1759 
1760  public:
1761  // single-table DELETE node constructor:
1762  PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1763  int opt_delete_options_arg, Table_ident *table_ident_arg,
1764  const LEX_CSTRING &opt_table_alias_arg,
1765  List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1766  PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1767  : m_with_clause(with_clause_arg),
1768  opt_hints(opt_hints_arg),
1769  opt_delete_options(opt_delete_options_arg),
1770  table_ident(table_ident_arg),
1771  opt_table_alias(opt_table_alias_arg.str),
1772  opt_use_partition(opt_use_partition_arg),
1773  opt_where_clause(opt_where_clause_arg),
1774  opt_order_clause(opt_order_clause_arg),
1775  opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1778  }
1779 
1780  // multi-table DELETE node constructor:
1781  PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1782  int opt_delete_options_arg,
1783  const Mem_root_array_YY<Table_ident *> &table_list_arg,
1784  const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1785  Item *opt_where_clause_arg)
1786  : m_with_clause(with_clause_arg),
1787  opt_hints(opt_hints_arg),
1788  opt_delete_options(opt_delete_options_arg),
1789  table_ident(NULL),
1790  opt_table_alias(nullptr),
1791  table_list(table_list_arg),
1793  join_table_list(join_table_list_arg),
1794  opt_where_clause(opt_where_clause_arg),
1797 
1798  Sql_cmd *make_cmd(THD *thd) override;
1799 
1800  private:
1801  bool is_multitable() const {
1802  DBUG_ASSERT((table_ident != NULL) ^ (table_list.size() > 0));
1803  return table_ident == NULL;
1804  }
1805 
1806  bool add_table(Parse_context *pc, Table_ident *table);
1807 };
1808 
1809 /**
1810  Top-level node for the UPDATE statement
1811 
1812  @ingroup ptn_stmt
1813 */
1814 class PT_update : public Parse_tree_root {
1825 
1826  public:
1827  PT_update(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1828  thr_lock_type opt_low_priority_arg, bool opt_ignore_arg,
1829  const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1830  PT_item_list *column_list_arg, PT_item_list *value_list_arg,
1831  Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
1832  Item *opt_limit_clause_arg)
1833  : m_with_clause(with_clause_arg),
1834  opt_hints(opt_hints_arg),
1835  opt_low_priority(opt_low_priority_arg),
1836  opt_ignore(opt_ignore_arg),
1837  join_table_list(join_table_list_arg),
1838  column_list(column_list_arg),
1839  value_list(value_list_arg),
1840  opt_where_clause(opt_where_clause_arg),
1841  opt_order_clause(opt_order_clause_arg),
1842  opt_limit_clause(opt_limit_clause_arg) {}
1843 
1844  Sql_cmd *make_cmd(THD *thd) override;
1845 };
1846 
1849 
1851 
1852  public:
1853  bool contextualize(Parse_context *pc) override;
1854 
1855  bool push_back(List<Item> *x) { return many_values.push_back(x); }
1856 
1859  return many_values;
1860  }
1861 };
1862 
1863 /**
1864  Top-level node for the INSERT statement
1865 
1866  @ingroup ptn_stmt
1867 */
1869  const bool is_replace;
1872  const bool ignore;
1878  const char *const opt_values_table_alias;
1882 
1883  public:
1884  PT_insert(bool is_replace_arg, PT_hint_list *opt_hints_arg,
1885  thr_lock_type lock_option_arg, bool ignore_arg,
1886  Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
1887  PT_item_list *column_list_arg,
1888  PT_insert_values_list *row_value_list_arg,
1889  PT_query_primary *insert_query_expression_arg,
1890  const LEX_CSTRING &opt_values_table_alias_arg,
1891  Create_col_name_list *opt_values_column_list_arg,
1892  PT_item_list *opt_on_duplicate_column_list_arg,
1893  PT_item_list *opt_on_duplicate_value_list_arg)
1894  : is_replace(is_replace_arg),
1895  opt_hints(opt_hints_arg),
1896  lock_option(lock_option_arg),
1897  ignore(ignore_arg),
1898  table_ident(table_ident_arg),
1899  opt_use_partition(opt_use_partition_arg),
1900  column_list(column_list_arg),
1901  row_value_list(row_value_list_arg),
1902  insert_query_expression(insert_query_expression_arg),
1903  opt_values_table_alias(opt_values_table_alias_arg.str),
1904  opt_values_column_list(opt_values_column_list_arg),
1905  opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
1906  opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
1907  // REPLACE statement can't have IGNORE flag:
1909  // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
1911  // INSERT/REPLACE ... SELECT can't have VALUES clause:
1913  // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
1918  }
1919 
1920  Sql_cmd *make_cmd(THD *thd) override;
1921 
1922  private:
1923  bool has_select() const { return insert_query_expression != NULL; }
1924 };
1925 
1929 
1930  public:
1931  PT_call(sp_name *proc_name_arg, PT_item_list *opt_expr_list_arg)
1932  : proc_name(proc_name_arg), opt_expr_list(opt_expr_list_arg) {}
1933 
1934  Sql_cmd *make_cmd(THD *thd) override;
1935 };
1936 
1937 /**
1938  Top-level node for the SHUTDOWN statement
1939 
1940  @ingroup ptn_stmt
1941 */
1944 
1945  public:
1946  Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
1947 };
1948 
1949 /**
1950  Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
1951 
1952  @ingroup ptn_stmt
1953 */
1955  /// The SQL command object.
1957  /// Whether OR REPLACE is specified.
1959  /// Whether IF NOT EXISTS is specified.
1961  /// SRID of the SRS to create.
1962  ///
1963  /// The range is larger than that of gis::srid_t, so it must be
1964  /// verified to be less than the uint32 maximum value.
1965  unsigned long long m_srid;
1966  /// All attributes except SRID.
1968 
1969  /// Check if a UTF-8 string contains control characters.
1970  ///
1971  /// @note This function only checks single byte control characters (U+0000 to
1972  /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
1973  /// that are not detected by this function.
1974  ///
1975  /// @param str The string.
1976  /// @param length Length of the string.
1977  ///
1978  /// @retval false The string contains no control characters.
1979  /// @retval true The string contains at least one control character.
1980  bool contains_control_char(char *str, size_t length) {
1981  for (size_t pos = 0; pos < length; pos++) {
1982  if (std::iscntrl(str[pos])) return true;
1983  }
1984  return false;
1985  }
1986 
1987  public:
1988  PT_create_srs(unsigned long long srid,
1989  const Sql_cmd_srs_attributes &attributes, bool or_replace,
1990  bool if_not_exists)
1991  : m_or_replace(or_replace),
1992  m_if_not_exists(if_not_exists),
1993  m_srid(srid),
1994  m_attributes(attributes) {}
1995 
1996  Sql_cmd *make_cmd(THD *thd) override;
1997 };
1998 
1999 /**
2000  Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
2001 
2002  @ingroup ptn_stmt
2003 */
2005  /// The SQL command object.
2007  /// SRID of the SRS to drop.
2008  ///
2009  /// The range is larger than that of gis::srid_t, so it must be
2010  /// verified to be less than the uint32 maximum value.
2011  unsigned long long m_srid;
2012 
2013  public:
2014  PT_drop_srs(unsigned long long srid, bool if_exists)
2015  : sql_cmd(srid, if_exists), m_srid(srid) {}
2016 
2017  Sql_cmd *make_cmd(THD *thd) override;
2018 };
2019 
2020 /**
2021  Top-level node for the ALTER INSTANCE statement
2022 
2023  @ingroup ptn_stmt
2024 */
2027 
2028  public:
2030  enum alter_instance_action_enum alter_instance_action)
2031  : sql_cmd(alter_instance_action) {}
2032 
2033  Sql_cmd *make_cmd(THD *thd) override;
2034 };
2035 
2036 /**
2037  A template-free base class for index options that we can predeclare in
2038  sql_lex.h
2039 */
2041 
2042 /**
2043  A key part specification.
2044 
2045  This can either be a "normal" key part (a key part that points to a column),
2046  or this can be a functional key part (a key part that points to an
2047  expression).
2048 */
2051 
2052  public:
2053  /**
2054  Constructor for a functional key part.
2055 
2056  @param expression The expression to index.
2057  @param order The direction of the index.
2058  */
2059  PT_key_part_specification(Item *expression, enum_order order);
2060 
2061  /**
2062  Constructor for a "normal" key part. That is a key part that points to a
2063  column and not an expression.
2064 
2065  @param column_name The column name that this key part points to.
2066  @param order The direction of the index.
2067  @param prefix_length How many bytes or characters this key part should
2068  index, or zero if it should index the entire column.
2069  */
2070  PT_key_part_specification(const LEX_CSTRING &column_name, enum_order order,
2071  int prefix_length);
2072 
2073  /**
2074  Contextualize this key part specification. This will also call itemize on
2075  the indexed expression if this is a functional key part.
2076 
2077  @param pc The parse context
2078 
2079  @retval true on error
2080  @retval false on success
2081  */
2082  bool contextualize(Parse_context *pc) override;
2083 
2084  /**
2085  Get the indexed expression. The caller must ensure that has_expression()
2086  returns true before calling this.
2087 
2088  @returns The indexed expression
2089  */
2092  return m_expression;
2093  }
2094 
2095  /**
2096  @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2097  ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2098  direction.
2099  */
2100  enum_order get_order() const { return m_order; }
2101 
2102  /**
2103  @retval true if the user explicitly specified a direction (asc/desc).
2104  @retval false if the user didn't explicitly specify a direction.
2105  */
2106  bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2107 
2108  /**
2109  @retval true if the key part contains an expression (and thus is a
2110  functional key part).
2111  @retval false if the key part doesn't contain an expression.
2112  */
2113  bool has_expression() const { return m_expression != nullptr; }
2114 
2115  /**
2116  Get the column that this key part points to. This is only valid if this
2117  key part isn't a functional index. The caller must thus check the return
2118  value of has_expression() before calling this function.
2119 
2120  @returns The column that this key part points to.
2121  */
2124  return m_column_name;
2125  }
2126 
2127  /**
2128  @returns The number of bytes that this key part should index. If the column
2129  this key part points to is a non-binary column, this is the number
2130  of characters. Returns zero if the entire column should be indexed.
2131  */
2132  int get_prefix_length() const { return m_prefix_length; }
2133 
2134  private:
2135  /**
2136  The indexed expression in case this is a functional key part. Only valid if
2137  has_expression() returns true.
2138  */
2140 
2141  /// The direction of the index.
2143 
2144  /// The name of the column that this key part indexes.
2146 
2147  /**
2148  If this is greater than zero, it represents how many bytes of the column
2149  that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2150  is the number of characters.
2151  */
2153 };
2154 
2155 /**
2156  A template for options that set a single `<alter option>` value in
2157  thd->lex->key_create_info.
2158 
2159  @tparam Option_type The data type of the option.
2160  @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2161 */
2162 template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2164  public:
2165  /// @param option_value The value of the option.
2167 
2170  return false;
2171  }
2172 
2173  private:
2174  Option_type m_option_value;
2175 };
2176 
2177 /**
2178  A template for options that set a single property in a KEY_CREATE_INFO, and
2179  also records if the option was explicitly set.
2180 */
2181 template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2182  bool KEY_CREATE_INFO::*Property_is_explicit>
2184  public:
2187 
2190  pc->key_create_info->*Property_is_explicit = true;
2191  return false;
2192  }
2193 
2194  private:
2195  Option_type m_option_value;
2196 };
2197 
2205 
2206 /**
2207  The data structure (B-tree, Hash, etc) used for an index is called
2208  'index_type' in the manual. Internally, this is stored in
2209  KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2210  stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2211  it's ignored. The terminology is somewhat confusing, but we stick to the
2212  manual in the parser.
2213 */
2217 
2219  public:
2221  const LEX_STRING &name_arg, PT_base_index_option *type,
2222  Table_ident *table_ident,
2228  m_keytype(type_par),
2229  m_name(name_arg),
2230  m_type(type),
2231  m_table_ident(table_ident),
2232  m_columns(cols),
2233  m_options(options),
2234  m_algo(algo),
2235  m_lock(lock) {}
2236 
2237  Sql_cmd *make_cmd(THD *thd) override;
2238 
2239  private:
2248 };
2249 
2250 /**
2251  Base class for column/constraint definitions in CREATE %TABLE
2252 
2253  @ingroup ptn_create_table_stuff
2254 */
2256 
2258 
2261 
2262  public:
2263  PT_inline_index_definition(keytype type_par, const LEX_STRING &name_arg,
2267  : m_keytype(type_par),
2268  m_name(name_arg),
2269  m_type(type),
2270  m_columns(cols),
2271  m_options(options) {}
2272 
2273  bool contextualize(Table_ddl_parse_context *pc) override;
2274 
2275  private:
2281 };
2282 
2285 
2286  public:
2287  PT_foreign_key_definition(const LEX_STRING &constraint_name,
2288  const LEX_STRING &key_name,
2290  Table_ident *referenced_table,
2291  List<Key_part_spec> *ref_list,
2292  fk_match_opt fk_match_option,
2293  fk_option fk_update_opt, fk_option fk_delete_opt)
2294  : m_constraint_name(constraint_name),
2295  m_key_name(key_name),
2296  m_columns(columns),
2297  m_referenced_table(referenced_table),
2298  m_ref_list(ref_list),
2299  m_fk_match_option(fk_match_option),
2300  m_fk_update_opt(fk_update_opt),
2301  m_fk_delete_opt(fk_delete_opt) {}
2302 
2303  bool contextualize(Table_ddl_parse_context *pc) override;
2304 
2305  private:
2314 };
2315 
2316 /**
2317  Common base class for CREATE TABLE and ALTER TABLE option nodes
2318 
2319  @ingroup ptn_create_or_alter_table_options
2320 */
2322  public:
2323  ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2324 
2325  virtual bool is_rename_table() const { return false; }
2326 };
2327 
2329 
2330 /**
2331  Base class for CREATE TABLE option nodes
2332 
2333  @ingroup ptn_create_or_alter_table_options
2334 */
2337 
2338  public:
2339  ~PT_create_table_option() override = 0; // Force abstract class declaration
2340 
2342  if (super::contextualize(pc)) return true;
2344  return false;
2345  }
2346 };
2347 
2349 
2350 /**
2351  A template for options that set a single property in HA_CREATE_INFO, and
2352  also records if the option was explicitly set.
2353 */
2354 template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2355  ulong Property_flag>
2358 
2359  const Option_type value;
2360 
2361  public:
2363 
2365  if (super::contextualize(pc)) return true;
2366  pc->create_info->*Property = value;
2367  pc->create_info->used_fields |= Property_flag;
2368  return false;
2369  }
2370 };
2371 
2372 #define TYPE_AND_REF(x) decltype(x), &x
2373 
2374 /**
2375  Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2376 
2377  @ingroup ptn_create_or_alter_table_options
2378 */
2382 
2383 /**
2384  Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2385 
2386  @ingroup ptn_create_or_alter_table_options
2387 */
2391 
2392 /**
2393  Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2394 
2395  @ingroup ptn_create_or_alter_table_options
2396 */
2400 
2401 /**
2402  Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2403 
2404  @ingroup ptn_create_or_alter_table_options
2405 */
2409 
2410 /**
2411  Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2412 
2413  @ingroup ptn_create_or_alter_table_options
2414 */
2418 
2419 /**
2420  Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2421 
2422  @ingroup ptn_create_or_alter_table_options
2423 */
2427 
2428 /**
2429  Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2430 
2431  @ingroup ptn_create_or_alter_table_options
2432 */
2436 
2437 /**
2438  Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2439 
2440  @ingroup ptn_create_or_alter_table_options
2441 */
2445 
2449 
2454 
2458 
2462 
2466 
2470 
2474 
2476 
2477 /**
2478  A template for options that set HA_CREATE_INFO::table_options and
2479  also records if the option was explicitly set.
2480 */
2481 template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2482  table_options_t No>
2485 
2487 
2488  public:
2490  : value(value) {}
2491 
2493  if (super::contextualize(pc)) return true;
2494  pc->create_info->table_options &= ~(Yes | No);
2495  switch (value) {
2496  case Ternary_option::ON:
2497  pc->create_info->table_options |= Yes;
2498  break;
2499  case Ternary_option::OFF:
2500  pc->create_info->table_options |= No;
2501  break;
2503  break;
2504  default:
2505  DBUG_ASSERT(false);
2506  }
2507  pc->create_info->used_fields |= Property_flag;
2508  return false;
2509  }
2510 };
2511 
2512 /**
2513  Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2514 
2515  @ingroup ptn_create_or_alter_table_options
2516 
2517  PACK_KEYS | Constructor parameter
2518  ----------|----------------------
2519  1 | Ternary_option::ON
2520  0 | Ternary_option::OFF
2521  DEFAULT | Ternary_option::DEFAULT
2522 */
2524  0, // DEFAULT
2525  HA_OPTION_PACK_KEYS, // ON
2526  HA_OPTION_NO_PACK_KEYS> // OFF
2528 
2529 /**
2530  Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2531 
2532  @ingroup ptn_create_or_alter_table_options
2533 
2534  STATS_PERSISTENT | Constructor parameter
2535  -----------------|----------------------
2536  1 | Ternary_option::ON
2537  0 | Ternary_option::OFF
2538  DEFAULT | Ternary_option::DEFAULT
2539 */
2541  0, // DEFAULT
2545 
2546 /**
2547  A template for options that set HA_CREATE_INFO::table_options and
2548  also records if the option was explicitly set.
2549 */
2550 template <ulong Property_flag, table_options_t Yes, table_options_t No>
2553 
2554  const bool value;
2555 
2556  public:
2558 
2560  if (super::contextualize(pc)) return true;
2561  pc->create_info->table_options &= ~(Yes | No);
2562  pc->create_info->table_options |= value ? Yes : No;
2563  pc->create_info->used_fields |= Property_flag;
2564  return false;
2565  }
2566 };
2567 
2568 /**
2569  Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2570 
2571  @ingroup ptn_create_or_alter_table_options
2572 
2573  TABLE_CHECKSUM | Constructor parameter
2574  ---------------|----------------------
2575  0 | false
2576  not 0 | true
2577 */
2579  HA_OPTION_CHECKSUM, // ON
2580  HA_OPTION_NO_CHECKSUM // OFF
2581  >
2583 
2584 /**
2585  Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2586 
2587  @ingroup ptn_create_or_alter_table_options
2588 
2589  TABLE_CHECKSUM | Constructor parameter
2590  ---------------|----------------------
2591  0 | false
2592  not 0 | true
2593 */
2598 
2599 /**
2600  Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2601 
2602  @ingroup ptn_create_or_alter_table_options
2603 */
2606 
2608 
2609  public:
2610  /**
2611  @param engine Storage engine name.
2612  */
2614  : engine(engine) {}
2615 
2616  bool contextualize(Table_ddl_parse_context *pc) override;
2617 };
2618 
2619 /**
2620  Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2621  table option.
2622 
2623  @ingroup ptn_create_or_alter_table_options
2624 */
2627 
2628  public:
2633 
2634  bool contextualize(Table_ddl_parse_context *pc) override;
2635 
2636  private:
2637  const LEX_CSTRING m_secondary_engine{nullptr, 0};
2638 };
2639 
2640 /**
2641  Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2642 
2643  @ingroup ptn_create_or_alter_table_options
2644 */
2647 
2649 
2650  public:
2651  /**
2652  @param value
2653  STATS_AUTO_RECALC | value
2654  ------------------|----------------------
2655  1 | Ternary_option::ON
2656  0 | Ternary_option::OFF
2657  DEFAULT | Ternary_option::DEFAULT
2658  */
2660 
2661  bool contextualize(Table_ddl_parse_context *pc) override;
2662 };
2663 
2664 /**
2665  Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2666 
2667  @ingroup ptn_create_or_alter_table_options
2668 */
2672 
2674 
2675  public:
2676  /**
2677  Constructor for implicit number of pages
2678 
2679  @param value Nunber of pages, 1@<=N@<=65535.
2680  */
2682  DBUG_ASSERT(value != 0 && value <= 0xFFFF);
2683  }
2684  /**
2685  Constructor for the DEFAULT number of pages
2686  */
2688 
2689  bool contextualize(Table_ddl_parse_context *pc) override;
2690 };
2691 
2694 
2696 
2697  public:
2699  : tables(tables) {}
2700 
2701  bool contextualize(Table_ddl_parse_context *pc) override;
2702 };
2703 
2706 
2708 
2709  public:
2711 
2713  if (super::contextualize(pc)) return true;
2715  return false;
2716  }
2717 };
2718 
2721 
2723 
2724  public:
2726  : value(value) {
2727  DBUG_ASSERT(value != nullptr);
2728  }
2729 
2730  bool contextualize(Table_ddl_parse_context *pc) override;
2731 };
2732 
2735 
2737 
2738  public:
2740  : value(value) {
2741  DBUG_ASSERT(value != nullptr);
2742  }
2743 
2744  bool contextualize(Table_ddl_parse_context *pc) override;
2745 };
2746 
2750 
2751  public:
2752  explicit PT_check_constraint(LEX_STRING &name, Item *expr, bool is_enforced) {
2753  cc_spec.name = name;
2754  cc_spec.check_expr = expr;
2755  cc_spec.is_enforced = is_enforced;
2756  }
2758 
2759  bool contextualize(Table_ddl_parse_context *pc) override;
2760 };
2761 
2764 
2767  // Currently we ignore that constraint in the executor.
2769 
2770  const char *opt_place;
2771 
2772  public:
2775  const char *opt_place = NULL)
2779  opt_place(opt_place) {}
2780 
2781  bool contextualize(Table_ddl_parse_context *pc) override;
2782 };
2783 
2784 /**
2785  Top-level node for the CREATE %TABLE statement
2786 
2787  @ingroup ptn_create_table
2788 */
2799 
2801 
2802  public:
2803  /**
2804  @param mem_root MEM_ROOT to use for allocation
2805  @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
2806  @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
2807  @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
2808  @param opt_table_element_list NULL or a list of table column and
2809  constraint definitions.
2810  @param opt_create_table_options NULL or a list of
2811  @ref ptn_create_or_alter_table_options
2812  "table options".
2813  @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
2814  @param on_duplicate DUPLICATE, IGNORE or fail with an error
2815  on data duplication errors (relevant
2816  for @SQL{CREATE TABLE ... SELECT}
2817  statements).
2818  @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
2819  */
2836  opt_like_clause(NULL) {}
2837  /**
2838  @param mem_root MEM_ROOT to use for allocation
2839  @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
2840  @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
2841  @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
2842  @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
2843  */
2857 
2858  Sql_cmd *make_cmd(THD *thd) override;
2859 };
2860 
2863 
2864  public:
2865  PT_create_role(bool if_not_exists, const List<LEX_USER> *roles)
2866  : sql_cmd(if_not_exists, roles) {}
2867 
2868  Sql_cmd *make_cmd(THD *thd) override;
2869 };
2870 
2873 
2874  public:
2875  explicit PT_drop_role(bool ignore_errors, const List<LEX_USER> *roles)
2876  : sql_cmd(ignore_errors, roles) {}
2877 
2878  Sql_cmd *make_cmd(THD *thd) override;
2879 };
2880 
2883 
2884  public:
2885  explicit PT_set_role(role_enum role_type,
2886  const List<LEX_USER> *opt_except_roles = NULL)
2887  : sql_cmd(role_type, opt_except_roles) {
2888  DBUG_ASSERT(role_type == role_enum::ROLE_ALL || opt_except_roles == NULL);
2889  }
2890  explicit PT_set_role(const List<LEX_USER> *roles) : sql_cmd(roles) {}
2891 
2892  Sql_cmd *make_cmd(THD *thd) override;
2893 };
2894 
2895 /**
2896  This class is used for representing both static and dynamic privileges on
2897  global as well as table and column level.
2898 */
2899 struct Privilege {
2901 
2904 
2907  : type(type), columns(columns) {}
2908 };
2909 
2910 struct Static_privilege : public Privilege {
2911  const uint grant;
2912 
2914  : Privilege(STATIC, columns_arg), grant(grant) {}
2915 };
2916 
2917 struct Dynamic_privilege : public Privilege {
2919 
2921  const Mem_root_array<LEX_CSTRING> *columns_arg)
2922  : Privilege(DYNAMIC, columns_arg), ident(ident) {}
2923 };
2924 
2926  private:
2928 
2929  public:
2930  explicit PT_role_or_privilege(const POS &pos) : pos(pos) {}
2931  virtual LEX_USER *get_user(THD *thd);
2932  virtual Privilege *get_privilege(THD *thd);
2933 };
2934 
2938 
2939  public:
2941  const LEX_STRING &host)
2943 
2944  LEX_USER *get_user(THD *thd) override;
2945 };
2946 
2949 
2950  public:
2953 
2954  LEX_USER *get_user(THD *thd) override;
2955  Privilege *get_privilege(THD *thd) override;
2956 };
2957 
2959  const uint grant;
2961 
2962  public:
2966 
2967  Privilege *get_privilege(THD *thd) override;
2968 };
2969 
2972 
2973  public:
2976 
2977  Privilege *get_privilege(THD *thd) override;
2978 };
2979 
2983  const bool with_admin_option;
2984 
2985  public:
2987  const List<LEX_USER> *users, bool with_admin_option)
2989 
2990  Sql_cmd *make_cmd(THD *thd) override;
2991 };
2992 
2996 
2997  public:
2999  const List<LEX_USER> *users)
3000  : roles(roles), users(users) {}
3001 
3002  Sql_cmd *make_cmd(THD *thd) override;
3003 };
3004 
3007 
3008  public:
3009  PT_alter_user_default_role(bool if_exists, const List<LEX_USER> *users,
3010  const List<LEX_USER> *roles,
3011  const role_enum role_type)
3012  : sql_cmd(if_exists, users, roles, role_type) {}
3013 
3014  Sql_cmd *make_cmd(THD *thd) override;
3015 };
3016 
3019 
3020  public:
3021  PT_show_grants(const LEX_USER *opt_for_user,
3022  const List<LEX_USER> *opt_using_users)
3023  : sql_cmd(opt_for_user, opt_using_users) {
3024  DBUG_ASSERT(opt_using_users == NULL || opt_for_user != NULL);
3025  }
3026 
3027  Sql_cmd *make_cmd(THD *thd) override;
3028 };
3029 
3030 /**
3031  Base class for Parse tree nodes of SHOW FIELDS/SHOW INDEX statements.
3032 */
3034  protected:
3036 
3038  const LEX_STRING &wild, Item *where_condition)
3039  : m_sql_cmd(static_cast<enum_sql_command>(type)),
3040  m_pos(pos),
3041  m_type(type),
3042  m_table_ident(table_ident),
3043  m_wild(wild),
3044  m_where_condition(where_condition) {
3045  DBUG_ASSERT(wild.str == nullptr || where_condition == nullptr);
3046  }
3047 
3048  public:
3049  Sql_cmd *make_cmd(THD *thd) override;
3050 
3051  private:
3052  // Sql_cmd for SHOW COLUMNS/SHOW INDEX statements.
3054 
3055  // Textual location of a token just parsed.
3057 
3058  // SHOW_FIELDS or SHOW_KEYS
3060 
3061  // Table used in the statement.
3063 
3064  // Wild or where clause used in the statement.
3067 };
3068 
3069 /**
3070  Parse tree node for SHOW FIELDS statement.
3071 */
3074 
3075  public:
3076  PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3077  Table_ident *table, const LEX_STRING &wild)
3078  : PT_show_fields_and_keys(pos, SHOW_FIELDS, table, wild, nullptr),
3079  m_show_cmd_type(show_cmd_type) {}
3080 
3081  PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3082  Table_ident *table_ident, Item *where_condition = nullptr);
3083 
3084  Sql_cmd *make_cmd(THD *thd) override;
3085 
3086  private:
3088 };
3089 
3090 /**
3091  Parse tree node for SHOW INDEX statement.
3092 */
3094  public:
3095  PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3096  Item *where_condition);
3097 
3098  Sql_cmd *make_cmd(THD *thd) override;
3099 
3100  private:
3102 
3103  // Flag to indicate EXTENDED keyword usage in the statement.
3105 };
3106 
3109 
3110  protected:
3112  : flag(flag) {}
3113 
3114  public:
3115  bool contextualize(Table_ddl_parse_context *pc) override;
3116 
3117  protected:
3118  /**
3119  A routine used by the parser to decide whether we are specifying a full
3120  partitioning or if only partitions to add or to reorganize.
3121 
3122  @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
3123  @retval false Something else.
3124  */
3128  }
3129 
3130  public:
3132 };
3133 
3136 
3137  public:
3139  PT_field_def_base *field_def,
3140  PT_table_constraint_def *opt_column_constraint,
3141  const char *opt_place)
3142  : super(Alter_info::ALTER_ADD_COLUMN),
3143  m_column_def(field_ident, field_def, opt_column_constraint, opt_place) {
3144  }
3145 
3148  }
3149 
3150  private:
3152 };
3153 
3156 
3157  public:
3159  const Mem_root_array<PT_table_element *> *columns)
3160  : super(Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
3161 
3163  if (super::contextualize(pc)) return true;
3164 
3165  for (auto *column : *m_columns)
3166  if (column->contextualize(pc)) return true;
3167 
3168  return false;
3169  }
3170 
3171  private:
3173 };
3174 
3177 
3178  public:
3180  : super(Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
3181 
3183  return super::contextualize(pc) || m_constraint->contextualize(pc);
3184  }
3185 
3186  private:
3188 };
3189 
3192 
3193  public:
3195  const LEX_STRING &new_name,
3196  PT_field_def_base *field_def,
3197  const char *opt_place)
3198  : super(Alter_info::ALTER_CHANGE_COLUMN),
3199  m_old_name(old_name),
3200  m_new_name(new_name),
3201  m_field_def(field_def),
3202  m_opt_place(opt_place) {}
3203 
3205  PT_field_def_base *field_def,
3206  const char *opt_place)
3207  : PT_alter_table_change_column(name, name, field_def, opt_place) {}
3208 
3209  bool contextualize(Table_ddl_parse_context *pc) override;
3210 
3211  private:
3215  const char *m_opt_place;
3216 };
3217 
3220 
3221  protected:
3223  Alter_info::Alter_info_flag alter_info_flag,
3224  const char *name)
3225  : super(alter_info_flag), m_alter_drop(drop_type, name) {}
3226 
3227  public:
3229  return (super::contextualize(pc) ||
3231  }
3232 
3233  private:
3235 };
3236 
3238  public:
3239  explicit PT_alter_table_drop_column(const char *name)
3240  : PT_alter_table_drop(Alter_drop::COLUMN, Alter_info::ALTER_DROP_COLUMN,
3241  name) {}
3242 };
3243 
3245  public:
3248  Alter_info::DROP_FOREIGN_KEY, name) {}
3249 };
3250 
3252  public:
3253  explicit PT_alter_table_drop_key(const char *name)
3254  : PT_alter_table_drop(Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
3255  name) {}
3256 };
3257 
3259  public:
3261  : PT_alter_table_drop(Alter_drop::CHECK_CONSTRAINT,
3262  Alter_info::DROP_CHECK_CONSTRAINT, name) {}
3263 };
3264 
3266  public:
3267  explicit PT_alter_table_drop_constraint(const char *name)
3268  : PT_alter_table_drop(Alter_drop::ANY_CONSTRAINT,
3269  Alter_info::DROP_ANY_CONSTRAINT, name) {}
3270 };
3271 
3274 
3275  protected:
3278  Alter_info::Alter_info_flag alter_info_flag, const char *name,
3279  bool is_enforced)
3280  : super(alter_info_flag),
3281  m_constraint_enforcement(alter_type, name, is_enforced) {}
3282 
3283  public:
3284  explicit PT_alter_table_enforce_constraint(const char *name, bool is_enforced)
3285  : super(is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
3286  : Alter_info::SUSPEND_ANY_CONSTRAINT),
3288  Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
3289  is_enforced) {}
3290 
3292  return (super::contextualize(pc) ||
3295  }
3296 
3297  private:
3299 };
3300 
3303  public:
3305  bool is_enforced)
3307  Alter_constraint_enforcement::Type::CHECK_CONSTRAINT,
3308  is_enforced ? Alter_info::ENFORCE_CHECK_CONSTRAINT
3309  : Alter_info::SUSPEND_CHECK_CONSTRAINT,
3310  name, is_enforced) {}
3311 };
3312 
3315 
3316  public:
3317  explicit PT_alter_table_enable_keys(bool enable)
3318  : super(Alter_info::ALTER_KEYS_ONOFF), m_enable(enable) {}
3319 
3321  pc->alter_info->keys_onoff =
3323  return super::contextualize(pc);
3324  }
3325 
3326  private:
3327  bool m_enable;
3328 };
3329 
3332 
3333  public:
3334  PT_alter_table_set_default(const char *col_name, Item *opt_default_expr)
3335  : super(Alter_info::ALTER_CHANGE_COLUMN_DEFAULT),
3336  m_name(col_name),
3337  m_expr(opt_default_expr) {}
3338 
3339  bool contextualize(Table_ddl_parse_context *pc) override;
3340 
3341  private:
3342  const char *m_name;
3344 };
3345 
3348 
3349  public:
3350  PT_alter_table_index_visible(const char *name, bool visible)
3351  : super(Alter_info::ALTER_INDEX_VISIBILITY),
3352  m_alter_index_visibility(name, visible) {}
3353 
3355  return (super::contextualize(pc) ||
3358  }
3359 
3360  private:
3362 };
3363 
3366 
3367  public:
3368  explicit PT_alter_table_rename(const Table_ident *ident)
3369  : super(Alter_info::ALTER_RENAME), m_ident(ident) {}
3370 
3371  bool contextualize(Table_ddl_parse_context *pc) override;
3372 
3373  bool is_rename_table() const override { return true; }
3374 
3375  private:
3376  const Table_ident *const m_ident;
3377 };
3378 
3381 
3382  public:
3383  PT_alter_table_rename_key(const char *from, const char *to)
3384  : super(Alter_info::ALTER_RENAME_INDEX), m_rename_key(from, to) {}
3385 
3387  return super::contextualize(pc) ||
3389  }
3390 
3391  private:
3393 };
3394 
3397 
3398  public:
3399  PT_alter_table_rename_column(const char *from, const char *to)
3400  : super(Alter_info::ALTER_CHANGE_COLUMN), m_rename_column(from, to) {}
3401 
3403  return super::contextualize(pc) ||
3405  }
3406 
3407  private:
3409 };
3410 
3413 
3414  public:
3416  const CHARSET_INFO *opt_collation)
3417  : super(Alter_info::ALTER_OPTIONS),
3418  m_charset(charset),
3419  m_collation(opt_collation) {}
3420 
3421  bool contextualize(Table_ddl_parse_context *pc) override;
3422 
3423  private:
3424  const CHARSET_INFO *const m_charset;
3426 };
3427 
3430 
3431  public:
3432  PT_alter_table_force() : super(Alter_info::ALTER_RECREATE) {}
3433 };
3434 
3437 
3438  public:
3440  : super(Alter_info::ALTER_ORDER), m_order(order) {}
3441 
3442  bool contextualize(Table_ddl_parse_context *pc) override;
3443 
3444  private:
3446 };
3447 
3450 
3451  public:
3453  : super(Alter_info::ALTER_PARTITION), m_partition(partition) {}
3454 
3455  bool contextualize(Table_ddl_parse_context *pc) override;
3456 
3457  private:
3459 };
3460 
3463 
3464  public:
3466  : super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
3467 };
3468 
3471 
3472  friend class PT_alter_table_standalone_stmt; // to access make_cmd()
3473 
3474  protected:
3476  : super(alter_info_flag) {}
3477 
3478  private:
3479  virtual Sql_cmd *make_cmd(Table_ddl_parse_context *pc) = 0;
3480 };
3481 
3482 /**
3483  Node for the @SQL{ALTER TABLE ADD PARTITION} statement
3484 
3485  @ingroup ptn_alter_table
3486 */
3489 
3490  public:
3491  explicit PT_alter_table_add_partition(bool no_write_to_binlog)
3492  : super(Alter_info::ALTER_ADD_PARTITION),
3493  m_no_write_to_binlog(no_write_to_binlog) {}
3494 
3495  bool contextualize(Table_ddl_parse_context *pc) override;
3496 
3498  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3499  }
3500 
3501  protected:
3503 
3504  private:
3506 };
3507 
3508 /**
3509  Node for the @SQL{ALTER TABLE ADD PARTITION (@<partition list@>)} statement
3510 
3511  @ingroup ptn_alter_table
3512 */
3514  : public PT_alter_table_add_partition {
3516 
3517  public:
3519  bool no_write_to_binlog,
3520  const Mem_root_array<PT_part_definition *> *def_list)
3521  : super(no_write_to_binlog), m_def_list(def_list) {}
3522 
3523  bool contextualize(Table_ddl_parse_context *pc) override;
3524 
3525  private:
3527 };
3528 
3529 /**
3530  Node for the @SQL{ALTER TABLE ADD PARTITION PARTITIONS (@<n>@)} statement
3531 
3532  @ingroup ptn_alter_table
3533 */
3535  : public PT_alter_table_add_partition {
3537 
3538  public:
3539  PT_alter_table_add_partition_num(bool no_write_to_binlog, uint num_parts)
3540  : super(no_write_to_binlog) {
3541  m_part_info.num_parts = num_parts;
3542  }
3543 };
3544 
3548 
3549  public:
3550  explicit PT_alter_table_drop_partition(const List<String> &partitions)
3551  : super(Alter_info::ALTER_DROP_PARTITION), m_partitions(partitions) {}
3552 
3553  bool contextualize(Table_ddl_parse_context *pc) override;
3554 
3556  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3557  }
3558 
3559  private:
3561 };
3562 
3566 
3567  public:
3569  Alter_info::Alter_info_flag alter_info_flag,
3570  const List<String> *opt_partition_list)
3571  : super(alter_info_flag), m_opt_partition_list(opt_partition_list) {}
3572 
3574  DBUG_ASSERT(pc->alter_info->partition_names.is_empty());
3575  if (m_opt_partition_list == NULL)
3577  else
3579  return super::contextualize(pc);
3580  }
3581 
3582  private:
3584 };
3585 
3589 
3590  public:
3591  PT_alter_table_rebuild_partition(bool no_write_to_binlog,
3592  const List<String> *opt_partition_list)
3593  : super(Alter_info::ALTER_REBUILD_PARTITION, opt_partition_list),
3594  m_no_write_to_binlog(no_write_to_binlog) {}
3595 
3596  bool contextualize(Table_ddl_parse_context *pc) override;
3597 
3599  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3600  }
3601 
3602  private:
3604 };
3605 
3609 
3610  public:
3611  PT_alter_table_optimize_partition(bool no_write_to_binlog,
3612  const List<String> *opt_partition_list)
3613  : super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
3614  m_no_write_to_binlog(no_write_to_binlog) {}
3615 
3616  bool contextualize(Table_ddl_parse_context *pc) override;
3617 
3619  return new (pc->mem_root)
3621  }
3622 
3623  private:
3625 };
3626 
3630 
3631  public:
3632  PT_alter_table_analyze_partition(bool no_write_to_binlog,
3633  const List<String> *opt_partition_list)
3634  : super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
3635  m_no_write_to_binlog(no_write_to_binlog) {}
3636 
3637  bool contextualize(Table_ddl_parse_context *pc) override;
3639  return new (pc->mem_root)
3641  }
3642 
3643  private:
3645 };
3646 
3650 
3651  public:
3654  : super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
3655  m_flags(flags),
3657 
3658  bool contextualize(Table_ddl_parse_context *pc) override;
3659 
3661  return new (pc->mem_root)
3663  }
3664 
3665  private:
3668 };
3669 
3673 
3674  public:
3675  PT_alter_table_repair_partition(bool no_write_to_binlog,
3676  const List<String> *opt_partition_list,
3678  : super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
3679  m_no_write_to_binlog(no_write_to_binlog),
3680  m_flags(flags),
3682 
3683  bool contextualize(Table_ddl_parse_context *pc) override;
3684 
3686  return new (pc->mem_root)
3688  }
3689 
3690  private:
3694 };
3695 
3699 
3700  public:
3701  PT_alter_table_coalesce_partition(bool no_write_to_binlog, uint num_parts)
3702  : super(Alter_info::ALTER_COALESCE_PARTITION),
3703  m_no_write_to_binlog(no_write_to_binlog),
3704  m_num_parts(num_parts) {}
3705 
3706  bool contextualize(Table_ddl_parse_context *pc) override;
3707 
3709  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3710  }
3711 
3712  private:
3715 };
3716 
3720 
3721  public:
3723  const List<String> *opt_partition_list)
3724  : super(static_cast<Alter_info::Alter_info_flag>(
3725  Alter_info::ALTER_ADMIN_PARTITION |
3726  Alter_info::ALTER_TRUNCATE_PARTITION),
3727  opt_partition_list) {}
3728 
3729  bool contextualize(Table_ddl_parse_context *pc) override;
3730 
3732  return new (pc->mem_root)
3734  }
3735 };
3736 
3740 
3741  public:
3742  explicit PT_alter_table_reorganize_partition(bool no_write_to_binlog)
3743  : super(Alter_info::ALTER_TABLE_REORG),
3744  m_no_write_to_binlog(no_write_to_binlog) {}
3745 
3746  bool contextualize(Table_ddl_parse_context *pc) override;
3747 
3749  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3750  }
3751 
3752  private:
3755 };
3756 
3760 
3761  public:
3763  bool no_write_to_binlog, const List<String> &partition_names,
3765  : super(Alter_info::ALTER_REORGANIZE_PARTITION),
3766  m_no_write_to_binlog(no_write_to_binlog),
3767  m_partition_names(partition_names),
3768  m_into(into) {}
3769 
3770  bool contextualize(Table_ddl_parse_context *pc) override;
3771 
3773  return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
3774  }
3775 
3776  private:
3781 };
3782 
3786 
3787  public:
3791  : super(Alter_info::ALTER_EXCHANGE_PARTITION),
3792  m_partition_name(partition_name),
3794  m_validation(validation) {}
3795 
3796  bool contextualize(Table_ddl_parse_context *pc) override;
3797 
3799  return new (pc->mem_root)
3801  }
3802 
3803  private:
3807 };
3808 
3812 
3813  public:
3815  : super(Alter_info::ALTER_SECONDARY_LOAD) {}
3816 
3818  return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
3819  }
3820 };
3821 
3825 
3826  public:
3828  : super(Alter_info::ALTER_SECONDARY_UNLOAD) {}
3829 
3831  return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
3832  }
3833 };
3834 
3838 
3839  public:
3841  const List<String> *opt_partition_list)
3842  : super(Alter_info::ALTER_DISCARD_TABLESPACE, opt_partition_list) {}
3843 
3846  }
3847 };
3848 
3852 
3853  public:
3855  const List<String> *opt_partition_list)
3856  : super(Alter_info::ALTER_IMPORT_TABLESPACE, opt_partition_list) {}
3857 
3860  }
3861 };
3862 
3866 
3867  public:
3869  : super(Alter_info::ALTER_DISCARD_TABLESPACE) {}
3870 
3873  }
3874 };
3875 
3879 
3880  public:
3882  : super(Alter_info::ALTER_IMPORT_TABLESPACE) {}
3883 
3886  }
3887 };
3888 
3890  public:
3899  m_opt_actions(opt_actions),
3900  m_algo(algo),
3901  m_lock(lock),
3902  m_validation(validation) {}
3903 
3904  Sql_cmd *make_cmd(THD *thd) override;
3905 
3906  private:
3912 
3914 };
3915 
3917  public:
3926  m_action(action),
3927  m_algo(algo),
3928  m_lock(lock),
3929  m_validation(validation) {}
3930 
3931  Sql_cmd *make_cmd(THD *thd) override;
3932 
3933  private:
3939 
3941 };
3942 
3944  public:
3945  PT_repair_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
3946  Mem_root_array<Table_ident *> *table_list,
3947  decltype(HA_CHECK_OPT::flags) flags,
3950  m_no_write_to_binlog(no_write_to_binlog),
3951  m_table_list(table_list),
3952  m_flags(flags),
3954 
3955  Sql_cmd *make_cmd(THD *thd) override;
3956 
3957  private:
3962 };
3963 
3965  public:
3966  PT_analyze_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
3967  Mem_root_array<Table_ident *> *table_list,
3969  int num_buckets, List<String> *columns)
3971  m_no_write_to_binlog(no_write_to_binlog),
3972  m_table_list(table_list),
3973  m_command(command),
3974  m_num_buckets(num_buckets),
3975  m_columns(columns) {}
3976 
3977  Sql_cmd *make_cmd(THD *thd) override;
3978 
3979  private:
3983  const int m_num_buckets;
3985 };
3986 
3988  public:
3990  Mem_root_array<Table_ident *> *table_list,
3991  decltype(HA_CHECK_OPT::flags) flags,
3994  m_table_list(table_list),
3995  m_flags(flags),
3997 
3998  Sql_cmd *make_cmd(THD *thd) override;
3999 
4000  private:
4004 };
4005 
4007  public:
4008  PT_optimize_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
4009  Mem_root_array<Table_ident *> *table_list)
4011  m_no_write_to_binlog(no_write_to_binlog),
4012  m_table_list(table_list) {}
4013 
4014  Sql_cmd *make_cmd(THD *thd) override;
4015 
4018 };
4019 
4021  public:
4022  PT_drop_index_stmt(MEM_ROOT *mem_root, const char *index_name,
4023  Table_ident *table,
4027  m_index_name(index_name),
4028  m_table(table),
4029  m_algo(algo),
4030  m_lock(lock),
4032 
4033  Sql_cmd *make_cmd(THD *thd) override;
4034 
4035  private:
4036  const char *m_index_name;
4040 
4042 };
4043 
4045  public:
4046  explicit PT_truncate_table_stmt(Table_ident *table) : m_table(table) {}
4047 
4048  Sql_cmd *make_cmd(THD *thd) override;
4049 
4050  private:
4052 
4054 };
4055 
4058 
4059  public:
4061  : m_table(table), m_index_hints(index_hints) {}
4062 
4063  bool contextualize(Table_ddl_parse_context *pc) override;
4064 
4065  private:
4068 };
4069 
4072 
4073  public:
4074  explicit PT_adm_partition(List<String> *opt_partitions)
4075  : m_opt_partitions(opt_partitions) {}
4076 
4077  bool contextualize(Table_ddl_parse_context *pc) override;
4078 
4079  private:
4081 };
4082 
4084  public:
4086  Mem_root_array<PT_assign_to_keycache *> *tbl_index_lists,
4087  const LEX_CSTRING &key_cache_name)
4089  m_tbl_index_lists(tbl_index_lists),
4090  m_key_cache_name(key_cache_name) {}
4091 
4092  Sql_cmd *make_cmd(THD *thd) override;
4093 
4094  private:
4097 };
4098 
4100  public:
4102  PT_adm_partition *partitions,
4103  List<Index_hint> *opt_key_usage_list,
4104  const LEX_CSTRING &key_cache_name)
4106  m_table(table),
4107  m_partitions(partitions),
4108  m_opt_key_usage_list(opt_key_usage_list),
4109  m_key_cache_name(key_cache_name) {}
4110 
4111  Sql_cmd *make_cmd(THD *thd) override;
4112 
4113  private:
4118 };
4119 
4122 
4123  public:
4124  PT_preload_keys(Table_ident *table, List<Index_hint> *opt_cache_key_list,
4125  bool ignore_leaves)
4126  : m_table(table),
4127  m_opt_cache_key_list(opt_cache_key_list),
4128  m_ignore_leaves(ignore_leaves) {}
4129 
4130  bool contextualize(Table_ddl_parse_context *pc) override;
4131 
4132  private:
4136 };
4137 
4139  public:
4141  PT_adm_partition *partitions,
4142  List<Index_hint> *opt_cache_key_list,
4143  bool ignore_leaves)
4145  m_table(table),
4146  m_partitions(partitions),
4147  m_opt_cache_key_list(opt_cache_key_list),
4148  m_ignore_leaves(ignore_leaves) {}
4149 
4150  Sql_cmd *make_cmd(THD *thd) override;
4151 
4152  private:
4157 };
4158 
4160  public:
4162  Mem_root_array<PT_preload_keys *> *preload_list)
4163  : PT_table_ddl_stmt_base(mem_root), m_preload_list(preload_list) {}
4164 
4165  Sql_cmd *make_cmd(THD *thd) override;
4166 
4167  private:
4169 };
4170 
4171 /**
4172  Base class for Parse tree nodes of SHOW TABLES statements.
4173 */
4175  public:
4176  PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
4177  const LEX_STRING &wild, Item *where_condition)
4178  : m_pos(pos),
4180  m_opt_db(opt_db),
4181  m_wild(wild),
4182  m_where_condition(where_condition),
4183  m_show_cmd_type(show_cmd_type) {
4184  DBUG_ASSERT(m_wild.str == nullptr || m_where_condition == nullptr);
4185  }
4186 
4187  public:
4188  Sql_cmd *make_cmd(THD *thd) override;
4189 
4190  private:
4191  /// Textual location of a token just parsed.
4193 
4194  /// Sql_cmd for SHOW TABLES statements.
4196 
4197  /// Optional schema name in FROM/IN clause.
4198  char *m_opt_db;
4199 
4200  /// Wild or where clause used in the statement.
4203 
4205 };
4206 
4209 
4210  public:
4213  bool contextualize(Parse_context *pc) override;
4214  Json_table_column *get_column() override { return m_column.get(); }
4215 
4216  private:
4218  const char *m_name;
4219 };
4220 
4223 
4224  public:
4227  PT_type *type, const CHARSET_INFO *collation);
4229 
4230  bool contextualize(Parse_context *pc) override;
4231 
4232  Json_table_column *get_column() override { return m_column.get(); }
4233 
4234  private:
4236  const char *m_name;
4239 };
4240 
4242  : public PT_json_table_column {
4244 
4245  public:
4248  : m_path(path), m_nested_columns(nested_cols) {}
4249 
4250  bool contextualize(Parse_context *pc) override;
4251 
4252  Json_table_column *get_column() override { return m_column; }
4253 
4254  private:
4258 };
4259 
4261  THD *const thd;
4263 
4265 };
4266 
4269 
4270 template <typename Option_type, Option_type Tablespace_options::*Option>
4272  : public PT_alter_tablespace_option_base /* purecov: inspected */
4273 {
4275 
4276  public:
4277  explicit PT_alter_tablespace_option(Option_type value) : m_value(value) {}
4278 
4280  pc->*Option = m_value;
4281  return super::contextualize(pc);
4282  }
4283 
4284  private:
4285  const Option_type m_value;
4286 };
4287 
4288 typedef PT_alter_tablespace_option<decltype(
4292 
4296 
4300 
4304 
4305 typedef PT_alter_tablespace_option<decltype(
4309 
4310 typedef PT_alter_tablespace_option<decltype(
4314 
4319 
4323 
4325  : public PT_alter_tablespace_option_base /* purecov: inspected */
4326 {
4329 
4330  public:
4332  : m_nodegroup_id(nodegroup_id) {}
4333 
4334  bool contextualize(Alter_tablespace_parse_context *pc) override;
4335 
4336  private:
4338 };
4339 
4341  : public PT_alter_tablespace_option_base /* purecov: inspected */
4342 {
4345 
4346  public:
4348  : m_comment(comment) {}
4349 
4351  if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
4352 
4353  if (pc->ts_comment.str) {
4354  my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "COMMENT");
4355  return true;
4356  }
4357  pc->ts_comment = m_comment;
4358  return false;
4359  }
4360 
4361  private:
4363 };
4364 
4366  : public PT_alter_tablespace_option_base /* purecov: inspected */
4367 {
4370 
4371  public:
4373  : m_engine_name(engine_name) {}
4374 
4376  if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
4377 
4378  if (pc->engine_name.str) {
4379  my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "STORAGE ENGINE");
4380  return true;
4381  }
4382  pc->engine_name = m_engine_name;
4383  return false;
4384  }
4385 
4386  private:
4388 };
4389 
4391  : public PT_alter_tablespace_option_base /* purecov: inspected */
4392 {
4395 
4396  public:
4398  option_type file_block_size)
4399  : m_file_block_size(file_block_size) {}
4400 
4402  if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
4403 
4404  if (pc->file_block_size != 0) {
4405  my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "FILE_BLOCK_SIZE");
4406  return true;
4407  }
4409  return false;
4410  }
4411 
4412  private:
4414 };
4415 
4416 /**
4417  Parse tree node for CREATE RESOURCE GROUP statement.
4418 */
4419 
4422  const bool has_priority;
4423 
4424  public:
4426  const LEX_CSTRING &name, const resourcegroups::Type type,
4427  const Mem_root_array<resourcegroups::Range> *cpu_list,
4428  const Value_or_default<int> &opt_priority, bool enabled)
4429  : sql_cmd(name, type, cpu_list,
4430  opt_priority.is_default ? 0 : opt_priority.value, enabled),
4431  has_priority(!opt_priority.is_default) {}
4432 
4433  Sql_cmd *make_cmd(THD *thd) override;
4434 };
4435 
4436 /**
4437  Parse tree node for ALTER RESOURCE GROUP statement.
4438 */
4439 
4442 
4443  public: