MySQL 8.1.0
Source Code Documentation
parse_tree_nodes.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2023, Oracle and/or its affiliates.
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 <assert.h>
27#include <sys/types.h> // TODO: replace with cstdint
28
29#include <cctype> // std::isspace
30#include <cstddef>
31#include <memory>
32
33#include "lex_string.h"
34#include "my_alloc.h"
35#include "my_base.h"
36#include "my_bit.h" // is_single_bit
37
38#include "my_inttypes.h" // TODO: replace with cstdint
39#include "my_sqlcommand.h"
40#include "my_sys.h"
41#include "my_thread_local.h"
42#include "my_time.h"
43#include "mysqld_error.h"
44#include "sql/check_stack.h"
45#include "sql/enum_query_type.h"
46#include "sql/handler.h"
47#include "sql/key_spec.h"
48#include "sql/mem_root_array.h"
49#include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
50#include "sql/parse_location.h"
51#include "sql/parse_tree_helpers.h" // PT_item_list
53#include "sql/parser_yystype.h"
54#include "sql/partition_info.h"
57#include "sql/set_var.h"
58#include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
59#include "sql/sql_alter.h"
60#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
61#include "sql/sql_cmd_srs.h"
62#include "sql/sql_exchange.h"
63#include "sql/sql_lex.h" // LEX
64#include "sql/sql_list.h"
65#include "sql/sql_load.h" // Sql_cmd_load_table
67#include "sql/sql_restart_server.h" // Sql_cmd_restart_server
68#include "sql/sql_tablespace.h" // Tablespace_options
69#include "sql/sql_truncate.h" // Sql_cmd_truncate_table
70#include "sql/table.h" // Common_table_expr
71#include "sql/window_lex.h"
72#include "string_with_len.h"
73#include "thr_lock.h"
74
75class Item;
76class Item_cache;
80class PT_hint_list;
83class PT_partition;
84class PT_subquery;
85class PT_type;
86class PT_window_list;
87class Sql_cmd;
88class String;
89class THD;
90class Window;
91class sp_head;
92class sp_name;
93struct CHARSET_INFO;
94
95/**
96 @defgroup ptn Parse tree nodes
97 @ingroup Parser
98*/
99/**
100 @defgroup ptn_stmt Nodes representing SQL statements
101 @ingroup ptn
102*/
103/**
104 @defgroup ptn_create_table CREATE TABLE statement
105 @ingroup ptn_stmt
106*/
107/**
108 @defgroup ptn_alter_table ALTER TABLE statement
109 @ingroup ptn_stmt
110*/
111/**
112 @defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
113 @ingroup ptn_create_table
114*/
115/**
116 @defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
117 @ingroup ptn_create_table ptn_alter_table
118*/
119/**
120 @defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
121 @ingroup ptn_partitioning
122*/
123/**
124 @defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
125 TABLE
126 @anchor ptn_create_or_alter_table_options
127 @ingroup ptn_create_table ptn_alter_table
128*/
129/**
130 @defgroup ptn_col_types Column types in CREATE/ALTER TABLE
131 @ingroup ptn_create_table ptn_alter_table
132*/
133/**
134 @defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
135 @ingroup ptn_create_table ptn_alter_table
136*/
137/**
138 @defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
139 TABLE
140 @ingroup ptn_col_attrs ptn_alter_table
141*/
142
143/**
144 Calls contextualize() on every node in the array.
145*/
146template <class Node_type, class Parse_context_type>
148 Parse_context_type *pc) {
149 for (Node_type *i : nodes)
150 if (i->contextualize(pc)) return true;
151 return false;
152}
153
154/**
155 Base class for all top-level nodes of SQL statements
156
157 @ingroup ptn_stmt
158*/
161 void operator=(const Parse_tree_root &) = delete;
162
163 protected:
164 Parse_tree_root() = default;
165 explicit Parse_tree_root(const POS &pos) : m_pos(pos) {}
166 virtual ~Parse_tree_root() = default;
167
168 public:
169 /// Textual location of a token just parsed.
171
172 virtual Sql_cmd *make_cmd(THD *thd) = 0;
173
174 // Return Json parse tree generated by SHOW PARSE_TREE.
175 virtual std::string get_printable_parse_tree(THD *thd [[maybe_unused]]) {
176 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
177 "Parse tree display of this statement");
178 return "";
179 }
180};
181
183 public:
186
187 ~PT_table_ddl_stmt_base() override = 0; // force abstract class
188
189 protected:
191};
192
194
195/**
196 Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
197
198 For internal use in the contextualization code.
199*/
201 Table_ddl_parse_context(THD *thd_arg, Query_block *select_arg,
206};
207
208/**
209 Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
210*/
212
213class PT_order_expr : public Parse_tree_node, public ORDER {
215
216 public:
217 PT_order_expr(const POS &pos, Item *item_arg, enum_order dir) : super(pos) {
218 item_initial = item_arg;
220 }
221
222 bool do_contextualize(Parse_context *pc) override;
223
224 protected:
225 void add_json_info(Json_object *obj) override {
226 obj->add_alias("desc",
227 create_dom_ptr<Json_boolean>(direction == ORDER_DESC));
228 }
229};
230
233
234 public:
236
237 public:
238 explicit PT_order_list(const POS &pos) : super(pos) {}
239
240 bool do_contextualize(Parse_context *pc) override {
241 if (super::do_contextualize(pc)) return true;
242 for (ORDER *o = value.first; o != nullptr; o = o->next) {
243 if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
244 }
245 return false;
246 }
247
249 order->used_alias = nullptr;
250 order->used = 0;
251 value.link_in_list(order, &order->next);
252 }
253};
254
257
258 public:
259 explicit PT_gorder_list(const POS &pos) : super(pos) {}
260
261 bool do_contextualize(Parse_context *pc) override {
262 return super::do_contextualize(pc);
263 }
264};
265
266/**
267 Represents an element of the WITH list:
268 WITH [...], [...] SELECT ...,
269 ^ or ^
270 i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
271*/
274
275 public:
276 explicit PT_common_table_expr(const POS &pos, const LEX_STRING &name,
277 const LEX_STRING &subq_text,
278 uint subq_text_offset, PT_subquery *sn,
281
282 /// The name after AS
283 const LEX_STRING &name() const { return m_name; }
284 /**
285 @param thd Thread handler
286 @param[out] node PT_subquery
287 @returns a PT_subquery to attach to a table reference for this CTE
288 */
289 bool make_subquery_node(THD *thd, PT_subquery **node);
290 /**
291 @param tl Table reference to match
292 @param in_self If this is a recursive reference
293 @param[out] found Is set to true/false if matches or not
294 @returns true if error
295 */
296 bool match_table_ref(Table_ref *tl, bool in_self, bool *found);
297 /**
298 @returns true if 'other' is the same instance as 'this'
299 */
300 bool is(const Common_table_expr *other) const {
301 return other == &m_postparse;
302 }
303 void print(const THD *thd, String *str, enum_query_type query_type);
304 bool do_contextualize(Parse_context *pc) override;
305
306 protected:
307 void add_json_info(Json_object *obj) override;
308
309 private:
311 /// Raw text of query expression (including parentheses)
313 /**
314 Offset in bytes of m_subq_text in original statement which had the WITH
315 clause.
316 */
318 /// Parsed version of subq_text
320 /// List of explicitly specified column names; if empty, no list.
322 /**
323 A Table_ref representing a CTE needs access to the WITH list
324 element it derives from. However, in order to:
325 - limit the members which Table_ref can access
326 - avoid including this header file everywhere Table_ref needs to
327 access these members, these members are relocated into a separate inferior
328 object whose declaration is in table.h, like that of Table_ref. It's
329 the "postparse" part. Table_ref accesses this inferior object only.
330 */
332
334};
335
336/**
337 Represents the WITH list.
338 WITH [...], [...] SELECT ...,
339 ^^^^^^^^^^^^
340*/
343
344 public:
345 /// @param pos Position of this clause in the SQL statement.
346 /// @param mem_root where interior objects are allocated
347 explicit PT_with_list(const POS &pos, MEM_ROOT *mem_root)
348 : super(pos), m_elements(mem_root) {}
351 return m_elements;
352 }
353
354 private:
356};
357
358/**
359 Represents the WITH clause:
360 WITH [...], [...] SELECT ...,
361 ^^^^^^^^^^^^^^^^^
362*/
365
366 public:
367 PT_with_clause(const POS &pos, const PT_with_list *l, bool r)
368 : super(pos),
369 m_list(l),
370 m_recursive(r),
372
373 bool do_contextualize(Parse_context *pc) override;
374
375 /**
376 Looks up a table reference into the list of CTEs.
377 @param tl Table reference to look up
378 @param[out] found Is set to true/false if found or not
379 @returns true if error
380 */
381 bool lookup(Table_ref *tl, PT_common_table_expr **found);
382 /**
383 Call this to record in the WITH clause that we are contextualizing the
384 CTE definition inserted in table reference 'tl'.
385 @returns information which the caller must provide to
386 leave_parsing_definition().
387 */
389 auto old = m_most_inner_in_parsing;
391 return old;
392 }
395 }
396 void print(const THD *thd, String *str, enum_query_type query_type);
397
398 protected:
399 void add_json_info(Json_object *obj) override {
400 obj->add_alias("recursive", create_dom_ptr<Json_boolean>(m_recursive));
401 }
402
403 private:
404 /// All CTEs of this clause
405 const PT_with_list *const m_list;
406 /// True if the user has specified the RECURSIVE keyword.
407 const bool m_recursive;
408 /**
409 The innermost CTE reference which we're parsing at the
410 moment. Used to detect forward references, loops and recursiveness.
411 */
413
415};
416
419
420 public:
421 explicit PT_select_item_list(const POS &pos) : super(pos) {}
422
423 bool do_contextualize(Parse_context *pc) override;
424};
425
428
430
431 protected:
432 void add_json_info(Json_object *obj) override {
433 obj->add_alias("is_offset_first",
434 create_dom_ptr<Json_boolean>(limit_options.is_offset_first));
435 }
436
437 public:
438 PT_limit_clause(const POS &pos, const Limit_options &limit_options_arg)
439 : super(pos), limit_options(limit_options_arg) {}
440
441 bool do_contextualize(Parse_context *pc) override;
443};
444
445class PT_cross_join;
446class PT_joined_table;
447
449 public:
450 explicit PT_table_reference(const POS &pos) : Parse_tree_node(pos) {}
451
453
454 /**
455 Lets us build a parse tree top-down, which is necessary due to the
456 context-dependent nature of the join syntax. This function adds
457 the @<table_ref@> cross join as the left-most leaf in this join tree
458 rooted at this node.
459
460 @todo: comment on non-join PT_table_reference objects
461
462 @param cj This @<table ref@> will be added if it represents a cross join.
463
464 @return The new top-level join.
465 */
467};
468
471
474 const char *const opt_table_alias;
476
477 public:
478 PT_table_factor_table_ident(const POS &pos, Table_ident *table_ident_arg,
479 List<String> *opt_use_partition_arg,
480 const LEX_CSTRING &opt_table_alias_arg,
481 List<Index_hint> *opt_key_definition_arg)
482 : super(pos),
483 table_ident(table_ident_arg),
484 opt_use_partition(opt_use_partition_arg),
485 opt_table_alias(opt_table_alias_arg.str),
486 opt_key_definition(opt_key_definition_arg) {}
487
488 protected:
489 bool do_contextualize(Parse_context *pc) override;
490 void add_json_info(Json_object *obj) override;
491};
492
494 protected:
495 explicit PT_json_table_column(const POS &pos) : Parse_tree_node(pos) {}
496
497 public:
499};
500
503
504 public:
507 const LEX_STRING &table_alias)
508 : super(pos),
509 m_expr(expr),
510 m_path(path),
511 m_nested_columns(nested_cols),
512 m_table_alias(table_alias) {}
513
514 bool do_contextualize(Parse_context *pc) override;
515
516 private:
521};
522
525
527
528 public:
531 : super(pos), table_list(table_list) {}
532
533 bool do_contextualize(Parse_context *pc) override;
534};
535
538
539 public:
540 PT_derived_table(const POS &pos, bool lateral, PT_subquery *subquery,
541 const LEX_CSTRING &table_alias,
543
544 bool do_contextualize(Parse_context *pc) override;
545
546 protected:
547 void add_json_info(Json_object *obj) override;
548
549 private:
552 const char *const m_table_alias;
553 /// List of explicitly specified column names; if empty, no list.
555};
556
559
560 public:
562 : super(pos), m_joined_table(joined_table) {}
563
564 bool do_contextualize(Parse_context *pc) override;
565
566 private:
568};
569
572
573 protected:
578
581
582 public:
583 PT_joined_table(const POS &pos, PT_table_reference *tab1_node_arg,
584 const POS &join_pos_arg, PT_joined_table_type type,
585 PT_table_reference *tab2_node_arg)
586 : super(pos),
587 m_left_pt_table(tab1_node_arg),
588 m_join_pos(join_pos_arg),
589 m_type(type),
590 m_right_pt_table(tab2_node_arg) {
591 static_assert(is_single_bit(JTT_INNER), "not a single bit");
592 static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
593 static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
594 static_assert(is_single_bit(JTT_LEFT), "not a single bit");
595 static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
596
597 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
600 }
601
602 /**
603 Adds the cross join to this join operation. The cross join is nested as
604 the table reference on the left-hand side.
605 */
608 return this;
609 }
610
611 /// Adds the table reference as the right-hand side of this join.
613 assert(m_right_pt_table == nullptr);
615 }
616
617 bool do_contextualize(Parse_context *pc) override;
618
619 /// This class is being inherited, it should thus be abstract.
620 ~PT_joined_table() override = 0;
621
622 protected:
624 void add_json_info(Json_object *obj) override;
625};
626
627inline PT_joined_table::~PT_joined_table() = default;
628
631
632 public:
633 PT_cross_join(const POS &pos, PT_table_reference *tab1_node_arg,
634 const POS &join_pos_arg, PT_joined_table_type Type_arg,
635 PT_table_reference *tab2_node_arg)
636 : PT_joined_table(pos, tab1_node_arg, join_pos_arg, Type_arg,
637 tab2_node_arg) {}
638
639 bool do_contextualize(Parse_context *pc) override;
640};
641
645
646 public:
647 PT_joined_table_on(const POS &pos, PT_table_reference *tab1_node_arg,
648 const POS &join_pos_arg, PT_joined_table_type type,
649 PT_table_reference *tab2_node_arg, Item *on_arg)
650 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
651 on(on_arg) {}
652
653 bool do_contextualize(Parse_context *pc) override;
654};
655
659
660 public:
661 PT_joined_table_using(const POS &pos, PT_table_reference *tab1_node_arg,
662 const POS &join_pos_arg, PT_joined_table_type type,
663 PT_table_reference *tab2_node_arg,
664 List<String> *using_fields_arg)
665 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
666 using_fields(using_fields_arg) {}
667
668 /// A PT_joined_table_using without a list of columns denotes a natural join.
669 PT_joined_table_using(const POS &pos, PT_table_reference *tab1_node_arg,
670 const POS &join_pos_arg, PT_joined_table_type type,
671 PT_table_reference *tab2_node_arg)
672 : PT_joined_table_using(pos, tab1_node_arg, join_pos_arg, type,
673 tab2_node_arg, nullptr) {}
674
675 bool do_contextualize(Parse_context *pc) override;
676
677 protected:
678 void add_json_info(Json_object *obj) override;
679};
680
681class PT_group : public Parse_tree_node {
683
686
687 protected:
688 void add_json_info(Json_object *obj) override {
689 if (olap == ROLLUP_TYPE)
690 obj->add_alias("olap_options", create_dom_ptr<Json_string>("ROLLUP"));
691 // Only rollup type supported.
692 }
693
694 public:
695 PT_group(const POS &pos, PT_order_list *group_list_arg, olap_type olap_arg)
696 : super(pos), group_list(group_list_arg), olap(olap_arg) {}
697
698 bool do_contextualize(Parse_context *pc) override;
699};
700
701class PT_order : public Parse_tree_node {
703
704 public:
706 explicit PT_order(const POS &pos, PT_order_list *order_list_arg)
707 : super(pos), order_list(order_list_arg) {}
708
709 bool do_contextualize(Parse_context *pc) override;
710};
711
713 public:
714 PT_locking_clause(const POS &pos, Lock_strength strength,
716 : Parse_tree_node(pos),
717 m_lock_strength(strength),
719
720 bool do_contextualize(Parse_context *pc) final;
721
722 virtual bool set_lock_for_tables(Parse_context *pc) = 0;
723
725
726 protected:
728 thr_lock_type lock_type = TL_IGNORE;
729 switch (m_lock_strength) {
731 lock_type = TL_WRITE;
732 break;
734 lock_type = TL_READ_WITH_SHARED_LOCKS;
735 break;
736 }
737
738 return {lock_type, static_cast<thr_locked_row_action>(action())};
739 }
740
741 private:
744};
745
747 public:
749 const POS &pos, Lock_strength strength,
751 : PT_locking_clause(pos, strength, action) {}
752
753 bool set_lock_for_tables(Parse_context *pc) override;
754};
755
757 public:
759
763 : PT_locking_clause(pos, strength, action), m_tables(tables) {}
764
765 bool set_lock_for_tables(Parse_context *pc) override;
766
767 private:
768 bool raise_error(THD *thd, const Table_ident *name, int error);
769
770 bool raise_error(int error);
771
773};
774
776 public:
778 : Parse_tree_node(pos) {
780 }
781
782 bool push_back(PT_locking_clause *locking_clause) {
783 return m_locking_clauses.push_back(locking_clause);
784 }
785
786 bool do_contextualize(Parse_context *pc) override {
787 for (auto locking_clause : m_locking_clauses)
788 if (locking_clause->contextualize(pc)) return true;
789 return false;
790 }
791
792 private:
794};
795
797 public:
798 explicit PT_query_expression_body(const POS &pos) : Parse_tree_node(pos) {}
799
800 virtual bool is_set_operation() const = 0;
801
802 /**
803 True if this query expression can absorb an extraneous order by/limit
804 clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
805 trailing clause may not refer to the tables in the `<query primary>`, with
806 one glaring exception:
807
808 (...( SELECT ... )...) ORDER BY ...
809
810 If the nested query expression doesn't contain `ORDER BY`, the statement
811 is interpreted as if the `ORDER BY` was absorbed by the innermost query
812 expression, i.e.:
813
814 (...( SELECT ... ORDER BY ... )...)
815
816 There is no rewriting of the parse tree nor AST happening here, the
817 transformation is done by the contextualizer (see
818 PT_query_expression::contextualize_order_and_limit), which interprets the
819 parse tree, and builds the AST according to this interpretation. This
820 interpretation is governed by the following rule: An `ORDER BY` can be
821 absorbed if none the nested query expressions contains an `ORDER BY` *or*
822 `LIMIT`. The rule is complex, so here are some examples for illustration:
823
824 In these cases the `ORDER BY` *is* absorbed:
825
826 ( SELECT * FROM t1 ) ORDER BY t1.a;
827 (( SELECT * FROM t1 )) ORDER BY t1.a;
828
829 In these cases the ORDER BY is *not* absorbed:
830
831 ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
832 (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
833 ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
834 (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
835
836 The same happens with `LIMIT`, obviously, but the optimizer is freeer to
837 choose when to apply the limit, and there are name no resolution issues
838 involved.
839
840 @param order True if the outer query block has the ORDER BY clause.
841 @param limit True if the outer query block has the LIMIT clause.
842 */
843 virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
844 virtual bool has_into_clause() const = 0;
845 virtual bool has_trailing_into_clause() const = 0;
846
847 virtual bool is_table_value_constructor() const = 0;
849};
850
853
854 public:
855 PT_set_scoped_system_variable(const POS &pos, const POS &var_pos,
856 const LEX_CSTRING &opt_prefix,
857 const LEX_CSTRING &name, Item *opt_expr)
858 : super(pos),
859 m_varpos(var_pos),
860 m_opt_prefix{opt_prefix},
861 m_name{name},
862 m_opt_expr{opt_expr} {}
863
864 bool do_contextualize(Parse_context *pc) override;
865
866 private:
871};
872
874 protected:
876 : Parse_tree_node(pos) {}
877};
878
881
882 public:
883 PT_set_variable(const POS &pos, const POS &varpos,
884 const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
885 const POS &expr_pos, Item *opt_expr)
886 : super{pos},
887 m_varpos{varpos},
888 m_opt_prefix{opt_prefix},
889 m_name{name},
890 m_expr_pos{expr_pos},
891 m_opt_expr{opt_expr} {}
892
893 bool do_contextualize(Parse_context *pc) override;
894
895 private:
901};
902
906
909
910 public:
912 const LEX_STRING &name_arg,
913 Item *expr_arg)
914 : super(pos), name(name_arg), expr(expr_arg) {}
915
916 bool do_contextualize(Parse_context *pc) override;
917};
918
921
922 public:
924 const POS &name_pos, const LEX_CSTRING &opt_prefix,
925 const LEX_CSTRING &name, Item *opt_expr)
926 : super(pos),
927 m_scope{scope},
928 m_name_pos{name_pos},
929 m_opt_prefix{opt_prefix},
930 m_name{name},
931 m_opt_expr{opt_expr} {}
932
933 bool do_contextualize(Parse_context *pc) override;
934
935 private:
941};
942
946
948
949 public:
951 const CHARSET_INFO *opt_charset_arg)
952 : super(pos), opt_charset(opt_charset_arg) {}
953
954 bool do_contextualize(Parse_context *pc) override;
955};
956
960
962
963 public:
965 const POS &error_pos)
966 : super(pos), m_error_pos(error_pos) {}
967
968 bool do_contextualize(Parse_context *pc) override;
969};
970
973
976
977 public:
978 PT_set_names(const POS &pos, const CHARSET_INFO *opt_charset_arg,
979 const CHARSET_INFO *opt_collation_arg)
980 : super(pos),
981 opt_charset(opt_charset_arg),
982 opt_collation(opt_collation_arg) {}
983
984 bool do_contextualize(Parse_context *pc) override;
985};
986
988 protected:
989 explicit PT_start_option_value_list(const POS &pos) : Parse_tree_node(pos) {}
990};
991
995
996 const char *password;
997 const char *current_password;
1001
1002 public:
1004 const char *password_arg,
1005 const char *current_password_arg,
1006 bool retain_current,
1007 bool random_password,
1008 const POS &expr_pos_arg)
1009 : super(pos),
1010 password(password_arg),
1011 current_password(current_password_arg),
1012 retain_current_password(retain_current),
1013 random_password_generator(random_password),
1014 expr_pos(expr_pos_arg) {}
1015
1016 bool do_contextualize(Parse_context *pc) override;
1017};
1018
1022
1024 const char *password;
1025 const char *current_password;
1029
1030 public:
1032 const POS &pos, LEX_USER *user_arg, const char *password_arg,
1033 const char *current_password_arg, bool retain_current, bool random_pass,
1034 const POS &expr_pos_arg)
1035 : super(pos),
1036 user(user_arg),
1037 password(password_arg),
1038 current_password(current_password_arg),
1039 retain_current_password(retain_current),
1040 random_password_generator(random_pass),
1041 expr_pos(expr_pos_arg) {}
1042
1043 bool do_contextualize(Parse_context *pc) override;
1044};
1045
1048
1051
1052 public:
1055 : super(pos), type(type_arg), value(value_arg) {}
1056
1057 bool do_contextualize(Parse_context *pc) override;
1058};
1059
1062
1066
1067 public:
1068 PT_option_value_list_head(const POS &pos, const POS &delimiter_pos_arg,
1069 Parse_tree_node *value_arg,
1070 const POS &value_pos_arg)
1071 : super(pos),
1072 delimiter_pos(delimiter_pos_arg),
1073 value(value_arg),
1074 value_pos(value_pos_arg) {}
1075
1076 bool do_contextualize(Parse_context *pc) override;
1077};
1078
1081
1083
1084 public:
1086 const POS &delimiter_pos_arg, Parse_tree_node *tail,
1087 const POS &tail_pos)
1088 : super(pos, delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
1089
1090 bool do_contextualize(Parse_context *pc) override {
1091 uchar dummy;
1092 if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
1093 return head->contextualize(pc) || super::do_contextualize(pc);
1094 }
1095};
1096
1099
1103
1104 public:
1107 const POS &head_pos_arg,
1108 PT_option_value_list_head *tail_arg)
1109 : super(pos), head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1110
1111 bool do_contextualize(Parse_context *pc) override;
1112};
1113
1116
1117 const char *name;
1119
1120 public:
1121 PT_transaction_characteristic(const POS &pos, const char *name_arg,
1122 int32 value_arg)
1123 : super(pos), name(name_arg), value(value_arg) {}
1124
1125 bool do_contextualize(Parse_context *pc) override;
1126};
1127
1130
1131 public:
1132 explicit PT_transaction_access_mode(const POS &pos, bool is_read_only)
1133 : super(pos, "transaction_read_only", (int32)is_read_only) {}
1134};
1135
1138
1139 public:
1140 explicit PT_isolation_level(const POS &pos, enum_tx_isolation level)
1141 : super(pos, "transaction_isolation", (int32)level) {}
1142};
1143
1146
1149
1150 public:
1153 PT_transaction_characteristic *opt_tail_arg)
1154 : super(pos), head(head_arg), opt_tail(opt_tail_arg) {}
1155
1156 bool do_contextualize(Parse_context *pc) override {
1157 return (super::do_contextualize(pc) || head->contextualize(pc) ||
1158 (opt_tail != nullptr && opt_tail->contextualize(pc)));
1159 }
1160};
1161
1165
1168
1169 public:
1171 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1172 const POS &end_pos_arg)
1173 : super(pos),
1174 characteristics(characteristics_arg),
1175 end_pos(end_pos_arg) {}
1176
1177 bool do_contextualize(Parse_context *pc) override;
1178};
1179
1181 : public Parse_tree_node {
1182 protected:
1184 : Parse_tree_node(pos) {}
1185};
1186
1190
1194
1195 public:
1197 const POS &pos, PT_set_scoped_system_variable *head_arg,
1198 const POS &head_pos_arg, PT_option_value_list_head *opt_tail_arg)
1199 : super(pos),
1200 head(head_arg),
1201 head_pos(head_pos_arg),
1202 opt_tail(opt_tail_arg) {}
1203
1204 bool do_contextualize(Parse_context *pc) override;
1205};
1206
1210
1213
1214 public:
1216 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1217 const POS &characteristics_pos_arg)
1218 : super(pos),
1219 characteristics(characteristics_arg),
1220 characteristics_pos(characteristics_pos_arg) {}
1221
1222 bool do_contextualize(Parse_context *pc) override;
1223};
1224
1227
1230
1231 public:
1233 const POS &pos, enum_var_type type_arg,
1235 : super(pos), type(type_arg), list(list_arg) {}
1236
1237 bool do_contextualize(Parse_context *pc) override;
1238};
1239
1240class PT_set : public Parse_tree_node {
1242
1245
1246 public:
1247 PT_set(const POS &pos, const POS &set_pos_arg,
1249 : super(pos), set_pos(set_pos_arg), list(list_arg) {}
1250
1251 bool do_contextualize(Parse_context *pc) override;
1252};
1253
1256
1257 protected:
1258 explicit PT_into_destination(const POS &pos) : super(pos) {}
1259
1260 public:
1261 bool do_contextualize(Parse_context *pc) override;
1262};
1263
1266
1267 public:
1268 PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1269 const CHARSET_INFO *charset_arg,
1270 const Field_separators &field_term_arg,
1271 const Line_separators &line_term_arg)
1272 : PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
1273 m_exchange.cs = charset_arg;
1274 m_exchange.field.merge_field_separators(field_term_arg);
1275 m_exchange.line.merge_line_separators(line_term_arg);
1276 }
1277
1278 bool do_contextualize(Parse_context *pc) override;
1279
1280 private:
1282};
1283
1286
1287 public:
1288 PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1289 : PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
1290
1291 bool do_contextualize(Parse_context *pc) override;
1292
1293 private:
1295};
1296
1298 public:
1300
1301 explicit PT_select_var(const POS &pos, const LEX_STRING &name_arg)
1302 : Parse_tree_node(pos), name(name_arg) {}
1303
1304 virtual bool is_local() const { return false; }
1305 virtual uint get_offset() const {
1306 assert(0);
1307 return 0;
1308 }
1309};
1310
1313
1314 uint offset = 0;
1315
1316#ifndef NDEBUG
1317 /*
1318 Routine to which this Item_splocal belongs. Used for checking if correct
1319 runtime context is used for variable handling.
1320 */
1321 sp_head *sp = nullptr;
1322#endif
1323
1324 public:
1325 PT_select_sp_var(const POS &pos, const LEX_STRING &name_arg)
1326 : super(pos, name_arg) {}
1327
1328 bool is_local() const override { return true; }
1329 uint get_offset() const override { return offset; }
1330
1331 bool do_contextualize(Parse_context *pc) override;
1332};
1333
1336
1337 public:
1338 explicit PT_select_var_list(const POS &pos) : PT_into_destination(pos) {}
1339
1341
1342 bool do_contextualize(Parse_context *pc) override;
1343
1344 bool push_back(PT_select_var *var) { return value.push_back(var); }
1345};
1346
1347/**
1348 Parse tree node for a single of a window extent's borders,
1349 cf. <window frame extent> in SQL 2003.
1350*/
1352 friend class Window;
1353 Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1354 public:
1356 const bool m_date_time;
1357 interval_type m_int_type = INTERVAL_LAST; // clang-tidy needs initialization.
1358
1359 ///< For unbounded border
1363 }
1364
1365 ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1367 : Parse_tree_node(pos),
1368 m_value(value),
1370 m_date_time(false) {}
1371
1372 ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1374 interval_type int_type)
1375 : Parse_tree_node(pos),
1376 m_value(value),
1378 m_date_time(true),
1379 m_int_type(int_type) {}
1380
1381 ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1382 Item *border() const { return m_value; }
1383 /// Need such low-level access so that fix_fields updates the right pointer
1384 Item **border_ptr() { return &m_value; }
1385
1386 /**
1387 @returns Addition operator for computation of frames, nullptr if error.
1388 @param order_expr Expression to add to/subtract from
1389 @param prec true if PRECEDING
1390 @param asc true if ASC
1391 @param window only used for error generation
1392 */
1393 Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1394 const Window *window);
1395
1396 bool do_contextualize(Parse_context *pc) override;
1397};
1398
1399/**
1400 Parse tree node for one or both of a window extent's borders, cf.
1401 <window frame extent> in SQL 2003.
1402*/
1405 friend class PT_frame;
1406
1407 public:
1408 /**
1409 Constructor.
1410
1411 Frames of the form "frame_start no_frame_end" are translated during
1412 parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1413 'end' are non-nullptr.
1414 */
1416 : Parse_tree_node(pos) {
1417 m_borders[0] = start;
1418 m_borders[1] = end;
1419 }
1420};
1421
1422/**
1423 Parse tree node for a window frame's exclusions, cf. the
1424 <window frame exclusion> clause in SQL 2003.
1425*/
1428
1429 public:
1431 : Parse_tree_node(pos), m_exclusion(e) {}
1432 // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1433};
1434
1435/**
1436 Parse tree node for a window's frame, cf. the <window frame clause>
1437 in SQL 2003.
1438*/
1440 public:
1442
1445
1447
1448 /// If true, this is an artificial frame, not specified by the user
1450
1451 PT_frame(const POS &pos, enum_window_frame_unit unit, PT_borders *from_to,
1452 PT_exclusion *exclusion)
1453 : Parse_tree_node(pos),
1454 m_query_expression(unit),
1455 m_from(from_to->m_borders[0]),
1456 m_to(from_to->m_borders[1]),
1457 m_exclusion(exclusion) {}
1458
1459 bool do_contextualize(Parse_context *pc) override;
1460};
1461
1463 protected:
1464 explicit PT_query_primary(const POS &pos) : PT_query_expression_body(pos) {}
1465};
1466
1469
1480
1481 public:
1483 const POS &pos, PT_hint_list *opt_hints_arg,
1484 const Query_options &options_arg, PT_item_list *item_list_arg,
1485 PT_into_destination *opt_into1_arg,
1486 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1487 Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1488 Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
1489 bool implicit_from_clause)
1490 : super(pos),
1491 opt_hints(opt_hints_arg),
1492 options(options_arg),
1493 item_list(item_list_arg),
1494 opt_into1(opt_into1_arg),
1495 m_is_from_clause_implicit{implicit_from_clause},
1496 from_clause(from_clause_arg),
1497 opt_where_clause(opt_where_clause_arg),
1498 opt_group_clause(opt_group_clause_arg),
1499 opt_having_clause(opt_having_clause_arg),
1500 opt_window_clause(opt_window_clause_arg) {
1501 assert(implicit_from_clause ? from_clause.empty() : true);
1502 }
1503
1505 const POS &pos, const Query_options &options_arg,
1506 PT_item_list *item_list_arg,
1507 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1508 Item *opt_where_clause_arg)
1509 : super(pos),
1511 options(options_arg),
1512 item_list(item_list_arg),
1515 from_clause(from_clause_arg),
1516 opt_where_clause(opt_where_clause_arg),
1520
1521 PT_query_specification(const POS &pos, const Query_options &options_arg,
1522 PT_item_list *item_list_arg)
1523 : super(pos),
1525 options(options_arg),
1526 item_list(item_list_arg),
1529 from_clause{},
1534
1535 bool do_contextualize(Parse_context *pc) override;
1536
1537 bool has_into_clause() const override { return opt_into1 != nullptr; }
1538 bool has_trailing_into_clause() const override {
1540 opt_where_clause == nullptr && opt_group_clause == nullptr &&
1541 opt_having_clause == nullptr && opt_window_clause == nullptr);
1542 }
1543
1544 bool is_set_operation() const override { return false; }
1545
1546 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1547
1548 bool is_table_value_constructor() const override { return false; }
1549 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1550
1551 protected:
1552 void add_json_info(Json_object *obj) override;
1553
1554 private:
1556};
1557
1560
1562
1563 public:
1564 explicit PT_table_value_constructor(const POS &pos,
1565 PT_insert_values_list *row_value_list_arg)
1566 : super(pos), row_value_list(row_value_list_arg) {}
1567
1568 bool do_contextualize(Parse_context *pc) override;
1569
1570 bool has_into_clause() const override { return false; }
1571 bool has_trailing_into_clause() const override { return false; }
1572
1573 bool is_set_operation() const override { return false; }
1574
1575 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1576
1577 bool is_table_value_constructor() const override { return true; }
1578
1580 return row_value_list;
1581 }
1582};
1583
1586
1587 public:
1589 const POS &pos, const Query_options &options_arg,
1590 PT_item_list *item_list_arg,
1591 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1592 : super(pos, options_arg, item_list_arg, from_clause_arg, nullptr) {}
1593};
1594
1596 public:
1597 PT_query_expression(const POS &pos, PT_with_clause *with_clause,
1598 PT_query_expression_body *body, PT_order *order,
1599 PT_limit_clause *limit)
1601 m_body(body),
1602 m_order(order),
1603 m_limit(limit),
1604 m_with_clause(with_clause) {}
1605
1607 PT_order *order, PT_limit_clause *limit)
1608 : PT_query_expression(pos, nullptr, body, order, limit) {}
1609
1611 : PT_query_expression(pos, body, nullptr, nullptr) {}
1612
1613 bool do_contextualize(Parse_context *pc) override;
1614
1615 bool is_set_operation() const override { return m_body->is_set_operation(); }
1616
1617 bool has_into_clause() const override { return m_body->has_into_clause(); }
1618 bool has_trailing_into_clause() const override {
1619 return (m_body->has_trailing_into_clause() && m_order == nullptr &&
1620 m_limit == nullptr);
1621 }
1622
1623 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1624 if (m_body->is_set_operation()) {
1625 return false;
1626 }
1627 if (m_order == nullptr && m_limit == nullptr) {
1628 /*
1629 It is safe to push ORDER and/or LIMIT down in:
1630
1631 (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1632 (SELECT ...<no order or limit clauses>) ORDER BY ...;
1633 (SELECT ...<no order or limit clauses>) LIMIT ...;
1634 */
1635 return true;
1636 }
1637 if (m_limit != nullptr && !order && limit) {
1638 /*
1639 In MySQL, it is ok(*) to push LIMIT down in:
1640
1641 (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1642
1643 *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1644 `LIMIT b` if a < b. Moreover, the result of:
1645
1646 (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1647
1648 can diverge from:
1649
1650 (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1651
1652 since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1653 while the example (2) does overwrite.
1654
1655 TODO: add a warning, deprecate and replace this behavior with the
1656 standard one.
1657 */
1658 return true;
1659 }
1660 if (m_order != nullptr && m_limit == nullptr && !order && limit) {
1661 /*
1662 Allow pushdown of LIMIT into body with ORDER BY, e.g
1663
1664 (SELECT ... ORDER BY order1) LIMIT a;
1665 */
1666 return true;
1667 }
1668 return false;
1669 }
1670
1671 bool is_table_value_constructor() const override {
1673 }
1674
1676 return m_body->get_row_value_list();
1677 }
1678
1679 private:
1680 /**
1681 Contextualizes the order and limit clauses, re-interpreting them according
1682 to the rules. If the `<query expression body>` can absorb the clauses,
1683 they are simply contextualized into the current Query_block. If not, we
1684 have to create the "fake" Query_block unless there is one already
1685 (Query_expression::new_set_operation_query() is known to do this.)
1686
1687 @see PT_query_expression::can_absorb_order_and_limit()
1688 */
1690
1695};
1696
1697/*
1698 After the removal of the `... <locking_clause> <into_clause>` syntax
1699 PT_locking will disappear.
1700*/
1703
1704 public:
1706 PT_locking_clause_list *locking_clauses)
1707 : super(pos),
1709 m_locking_clauses{locking_clauses} {}
1710
1711 bool do_contextualize(Parse_context *pc) override {
1712 return (super::do_contextualize(pc) ||
1715 }
1716
1717 bool is_set_operation() const override {
1719 }
1720
1721 bool has_into_clause() const override {
1723 }
1724 bool has_trailing_into_clause() const override { return false; }
1725
1726 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1727 return m_query_expression->can_absorb_order_and_limit(order, limit);
1728 }
1729
1730 bool is_table_value_constructor() const override {
1732 }
1733
1736 }
1737
1738 private:
1741};
1742
1745
1748
1749 public:
1751
1752 PT_subquery(const POS &pos, PT_query_expression_body *query_expression)
1753 : super(pos),
1754 qe(query_expression),
1756 m_is_derived_table(false) {}
1757
1758 bool do_contextualize(Parse_context *pc) override;
1759
1761};
1762
1765
1766 public:
1768 bool is_distinct, PT_query_expression_body *rhs,
1769 bool is_rhs_in_parentheses = false)
1770 : super(pos),
1771 m_lhs(lhs),
1772 m_is_distinct(is_distinct),
1773 m_rhs(rhs),
1774 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {}
1775
1777 QueryLevel &ql);
1778 bool is_set_operation() const override { return true; }
1779
1780 bool has_into_clause() const override {
1782 }
1783 bool has_trailing_into_clause() const override {
1785 }
1786
1787 bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1788
1789 bool is_table_value_constructor() const override { return false; }
1790 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1791
1792 protected:
1794 Surrounding_context context);
1800
1801 void add_json_info(Json_object *obj) override {
1802 obj->add_alias("distinct", create_dom_ptr<Json_boolean>(m_is_distinct));
1803 obj->add_alias("rhs_in_parentheses",
1804 create_dom_ptr<Json_boolean>(m_is_rhs_in_parentheses));
1805 }
1806};
1807
1810
1811 public:
1813 bool do_contextualize(Parse_context *pc) override;
1814};
1815
1818
1819 public:
1821 bool do_contextualize(Parse_context *pc) override;
1822};
1823
1826
1827 public:
1829 bool do_contextualize(Parse_context *pc) override;
1830};
1831
1834
1835 public:
1836 /**
1837 @param pos Position of this clause in the SQL statement.
1838 @param qe The query expression.
1839 @param sql_command The type of SQL command.
1840 */
1841 PT_select_stmt(const POS &pos, enum_sql_command sql_command,
1843 : super(pos),
1844 m_sql_command(sql_command),
1845 m_qe(qe),
1846 m_into(nullptr),
1848
1849 /**
1850 Creates a SELECT command. Only SELECT commands can have into.
1851
1852 @param pos Position of this clause in the SQL
1853 statement.
1854 @param qe The query expression.
1855 @param into The own INTO destination.
1856 @param has_trailing_locking_clauses True if there are locking clauses (like
1857 `FOR UPDATE`) at the end of the
1858 statement.
1859 */
1861 PT_into_destination *into = nullptr,
1862 bool has_trailing_locking_clauses = false)
1863 : super(pos),
1865 m_qe{qe},
1866 m_into{into},
1867 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1868
1869 Sql_cmd *make_cmd(THD *thd) override;
1870 std::string get_printable_parse_tree(THD *thd) override;
1871
1872 private:
1877};
1878
1879/**
1880 Top-level node for the DELETE statement
1881
1882 @ingroup ptn_stmt
1883*/
1884class PT_delete final : public Parse_tree_root {
1886
1887 private:
1892 const char *const opt_table_alias;
1900
1901 public:
1902 // single-table DELETE node constructor:
1903 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1904 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1905 Table_ident *table_ident_arg,
1906 const LEX_CSTRING &opt_table_alias_arg,
1907 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1908 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1909 : super(pos),
1910 m_with_clause(with_clause_arg),
1911 opt_hints(opt_hints_arg),
1912 opt_delete_options(opt_delete_options_arg),
1913 table_ident(table_ident_arg),
1914 opt_table_alias(opt_table_alias_arg.str),
1915 opt_use_partition(opt_use_partition_arg),
1916 opt_where_clause(opt_where_clause_arg),
1917 opt_order_clause(opt_order_clause_arg),
1918 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1920 join_table_list.init_empty_const();
1921 }
1922
1923 // multi-table DELETE node constructor:
1924 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1925 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1926 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1927 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1928 Item *opt_where_clause_arg)
1929 : super(pos),
1930 m_with_clause(with_clause_arg),
1931 opt_hints(opt_hints_arg),
1932 opt_delete_options(opt_delete_options_arg),
1935 table_list(table_list_arg),
1937 join_table_list(join_table_list_arg),
1938 opt_where_clause(opt_where_clause_arg),
1941
1942 Sql_cmd *make_cmd(THD *thd) override;
1943
1944 private:
1945 bool is_multitable() const {
1946 assert((table_ident != nullptr) ^ (table_list.size() > 0));
1947 return table_ident == nullptr;
1948 }
1949
1951};
1952
1953/**
1954 Top-level node for the UPDATE statement
1955
1956 @ingroup ptn_stmt
1957*/
1960
1971
1972 public:
1973 PT_update(const POS &pos, PT_with_clause *with_clause_arg,
1974 PT_hint_list *opt_hints_arg, thr_lock_type opt_low_priority_arg,
1975 bool opt_ignore_arg,
1976 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1977 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
1978 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
1979 Item *opt_limit_clause_arg)
1980 : super(pos),
1981 m_with_clause(with_clause_arg),
1982 opt_hints(opt_hints_arg),
1983 opt_low_priority(opt_low_priority_arg),
1984 opt_ignore(opt_ignore_arg),
1985 join_table_list(join_table_list_arg),
1986 column_list(column_list_arg),
1987 value_list(value_list_arg),
1988 opt_where_clause(opt_where_clause_arg),
1989 opt_order_clause(opt_order_clause_arg),
1990 opt_limit_clause(opt_limit_clause_arg) {}
1991
1992 Sql_cmd *make_cmd(THD *thd) override;
1993};
1994
1997
1999
2000 public:
2002 : super(pos), many_values(mem_root) {}
2003
2004 bool do_contextualize(Parse_context *pc) override;
2005
2007 many_values.push_back(x);
2008 return false;
2009 }
2010
2012 assert(is_contextualized());
2013 return many_values;
2014 }
2015};
2016
2017/**
2018 Top-level node for the INSERT statement
2019
2020 @ingroup ptn_stmt
2021*/
2022class PT_insert final : public Parse_tree_root {
2024
2025 const bool is_replace;
2028 const bool ignore;
2034 const char *const opt_values_table_alias;
2038
2039 public:
2040 PT_insert(const POS &pos, bool is_replace_arg, PT_hint_list *opt_hints_arg,
2041 thr_lock_type lock_option_arg, bool ignore_arg,
2042 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
2043 PT_item_list *column_list_arg,
2044 PT_insert_values_list *row_value_list_arg,
2045 PT_query_expression_body *insert_query_expression_arg,
2046 const LEX_CSTRING &opt_values_table_alias_arg,
2047 Create_col_name_list *opt_values_column_list_arg,
2048 PT_item_list *opt_on_duplicate_column_list_arg,
2049 PT_item_list *opt_on_duplicate_value_list_arg)
2050 : super(pos),
2051 is_replace(is_replace_arg),
2052 opt_hints(opt_hints_arg),
2053 lock_option(lock_option_arg),
2054 ignore(ignore_arg),
2055 table_ident(table_ident_arg),
2056 opt_use_partition(opt_use_partition_arg),
2057 column_list(column_list_arg),
2058 row_value_list(row_value_list_arg),
2059 insert_query_expression(insert_query_expression_arg),
2060 opt_values_table_alias(opt_values_table_alias_arg.str),
2061 opt_values_column_list(opt_values_column_list_arg),
2062 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
2063 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
2064 // REPLACE statement can't have IGNORE flag:
2065 assert(!is_replace || !ignore);
2066 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
2067 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
2068 // INSERT/REPLACE ... SELECT can't have VALUES clause:
2069 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
2070 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
2071 assert((opt_on_duplicate_column_list == nullptr &&
2072 opt_on_duplicate_value_list == nullptr) ||
2075 }
2076
2077 Sql_cmd *make_cmd(THD *thd) override;
2078
2079 private:
2080 bool has_query_block() const { return insert_query_expression != nullptr; }
2081};
2082
2083class PT_call final : public Parse_tree_root {
2086
2087 public:
2088 PT_call(const POS &pos, sp_name *proc_name_arg,
2089 PT_item_list *opt_expr_list_arg)
2090 : Parse_tree_root(pos),
2091 proc_name(proc_name_arg),
2092 opt_expr_list(opt_expr_list_arg) {}
2093
2094 Sql_cmd *make_cmd(THD *thd) override;
2095};
2096
2097/**
2098 Top-level node for the SHUTDOWN statement
2099
2100 @ingroup ptn_stmt
2101*/
2102class PT_shutdown final : public Parse_tree_root {
2104
2105 public:
2106 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
2107};
2108
2109/**
2110 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
2111
2112 @ingroup ptn_stmt
2113*/
2114class PT_create_srs final : public Parse_tree_root {
2115 /// The SQL command object.
2117 /// Whether OR REPLACE is specified.
2119 /// Whether IF NOT EXISTS is specified.
2121 /// SRID of the SRS to create.
2122 ///
2123 /// The range is larger than that of gis::srid_t, so it must be
2124 /// verified to be less than the uint32 maximum value.
2125 unsigned long long m_srid;
2126 /// All attributes except SRID.
2128
2129 /// Check if a UTF-8 string contains control characters.
2130 ///
2131 /// @note This function only checks single byte control characters (U+0000 to
2132 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
2133 /// that are not detected by this function.
2134 ///
2135 /// @param str The string.
2136 /// @param length Length of the string.
2137 ///
2138 /// @retval false The string contains no control characters.
2139 /// @retval true The string contains at least one control character.
2140 bool contains_control_char(char *str, size_t length) {
2141 for (size_t pos = 0; pos < length; pos++) {
2142 if (std::iscntrl(str[pos])) return true;
2143 }
2144 return false;
2145 }
2146
2147 public:
2148 PT_create_srs(const POS &pos, unsigned long long srid,
2149 const Sql_cmd_srs_attributes &attributes, bool or_replace,
2150 bool if_not_exists)
2151 : Parse_tree_root(pos),
2152 m_or_replace(or_replace),
2153 m_if_not_exists(if_not_exists),
2154 m_srid(srid),
2155 m_attributes(attributes) {}
2156
2157 Sql_cmd *make_cmd(THD *thd) override;
2158};
2159
2160/**
2161 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
2162
2163 @ingroup ptn_stmt
2164*/
2165class PT_drop_srs final : public Parse_tree_root {
2166 /// The SQL command object.
2168 /// SRID of the SRS to drop.
2169 ///
2170 /// The range is larger than that of gis::srid_t, so it must be
2171 /// verified to be less than the uint32 maximum value.
2172 unsigned long long m_srid;
2173
2174 public:
2175 PT_drop_srs(const POS &pos, unsigned long long srid, bool if_exists)
2176 : Parse_tree_root(pos), sql_cmd(srid, if_exists), m_srid(srid) {}
2177
2178 Sql_cmd *make_cmd(THD *thd) override;
2179};
2180
2181/**
2182 Top-level node for the ALTER INSTANCE statement
2183
2184 @ingroup ptn_stmt
2185*/
2188
2189 public:
2191 const POS &pos, enum alter_instance_action_enum alter_instance_action,
2192 const LEX_CSTRING &channel)
2193 : Parse_tree_root(pos), sql_cmd(alter_instance_action, channel) {}
2194
2195 Sql_cmd *make_cmd(THD *thd) override;
2196};
2197
2198/**
2199 A template-free base class for index options that we can predeclare in
2200 sql_lex.h
2201*/
2203 protected:
2204 explicit PT_base_index_option(const POS &pos) : Table_ddl_node(pos) {}
2205};
2206
2207/**
2208 A key part specification.
2209
2210 This can either be a "normal" key part (a key part that points to a column),
2211 or this can be a functional key part (a key part that points to an
2212 expression).
2213*/
2216
2217 public:
2218 /**
2219 Constructor for a functional key part.
2220
2221 @param pos Position of this clause in the SQL statement.
2222 @param expression The expression to index.
2223 @param order The direction of the index.
2224 */
2225 PT_key_part_specification(const POS &pos, Item *expression, enum_order order);
2226
2227 /**
2228 Constructor for a "normal" key part. That is a key part that points to a
2229 column and not an expression.
2230
2231 @param pos Position of this clause in the SQL statement.
2232 @param column_name The column name that this key part points to.
2233 @param order The direction of the index.
2234 @param prefix_length How many bytes or characters this key part should
2235 index, or zero if it should index the entire column.
2236 */
2237 PT_key_part_specification(const POS &pos, const LEX_CSTRING &column_name,
2238 enum_order order, int prefix_length);
2239
2240 /**
2241 Contextualize this key part specification. This will also call itemize on
2242 the indexed expression if this is a functional key part.
2243
2244 @param pc The parse context
2245
2246 @retval true on error
2247 @retval false on success
2248 */
2249 bool do_contextualize(Parse_context *pc) override;
2250
2251 /**
2252 Get the indexed expression. The caller must ensure that has_expression()
2253 returns true before calling this.
2254
2255 @returns The indexed expression
2256 */
2258 assert(has_expression());
2259 return m_expression;
2260 }
2261
2262 /**
2263 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2264 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2265 direction.
2266 */
2267 enum_order get_order() const { return m_order; }
2268
2269 /**
2270 @retval true if the user explicitly specified a direction (asc/desc).
2271 @retval false if the user didn't explicitly specify a direction.
2272 */
2273 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2274
2275 /**
2276 @retval true if the key part contains an expression (and thus is a
2277 functional key part).
2278 @retval false if the key part doesn't contain an expression.
2279 */
2280 bool has_expression() const { return m_expression != nullptr; }
2281
2282 /**
2283 Get the column that this key part points to. This is only valid if this
2284 key part isn't a functional index. The caller must thus check the return
2285 value of has_expression() before calling this function.
2286
2287 @returns The column that this key part points to.
2288 */
2290 assert(!has_expression());
2291 return m_column_name;
2292 }
2293
2294 /**
2295 @returns The number of bytes that this key part should index. If the column
2296 this key part points to is a non-binary column, this is the number
2297 of characters. Returns zero if the entire column should be indexed.
2298 */
2299 int get_prefix_length() const { return m_prefix_length; }
2300
2301 private:
2302 /**
2303 The indexed expression in case this is a functional key part. Only valid if
2304 has_expression() returns true.
2305 */
2307
2308 /// The direction of the index.
2310
2311 /// The name of the column that this key part indexes.
2313
2314 /**
2315 If this is greater than zero, it represents how many bytes of the column
2316 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2317 is the number of characters.
2318 */
2320};
2321
2322/**
2323 A template for options that set a single `<alter option>` value in
2324 thd->lex->key_create_info.
2325
2326 @tparam Option_type The data type of the option.
2327 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2328*/
2329template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2331 public:
2332 /// @param pos Position of this clause in the SQL statement.
2333 /// @param option_value The value of the option.
2334 PT_index_option(const POS &pos, Option_type option_value)
2335 : PT_base_index_option(pos), m_option_value(option_value) {}
2336
2339 return false;
2340 }
2341
2342 private:
2343 Option_type m_option_value;
2344};
2345
2346/**
2347 A template for options that set a single property in a KEY_CREATE_INFO, and
2348 also records if the option was explicitly set.
2349*/
2350template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2351 bool KEY_CREATE_INFO::*Property_is_explicit>
2353 public:
2354 PT_traceable_index_option(const POS &pos, Option_type option_value)
2355 : PT_base_index_option(pos), m_option_value(option_value) {}
2356
2359 pc->key_create_info->*Property_is_explicit = true;
2360 return false;
2361 }
2362
2363 private:
2364 Option_type m_option_value;
2365};
2366
2374
2375/**
2376 The data structure (B-tree, Hash, etc) used for an index is called
2377 'index_type' in the manual. Internally, this is stored in
2378 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2379 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2380 it's ignored. The terminology is somewhat confusing, but we stick to the
2381 manual in the parser.
2382*/
2386
2388 public:
2390 const LEX_STRING &name_arg, PT_base_index_option *type,
2391 Table_ident *table_ident,
2397 m_keytype(type_par),
2398 m_name(name_arg),
2399 m_type(type),
2400 m_table_ident(table_ident),
2401 m_columns(cols),
2403 m_algo(algo),
2404 m_lock(lock) {}
2405
2406 Sql_cmd *make_cmd(THD *thd) override;
2407
2408 private:
2417};
2418
2419/**
2420 Base class for column/constraint definitions in CREATE %TABLE
2421
2422 @ingroup ptn_create_table_stuff
2423*/
2425 protected:
2426 explicit PT_table_element(const POS &pos) : Table_ddl_node(pos) {}
2427};
2428
2430 protected:
2431 explicit PT_table_constraint_def(const POS &pos) : PT_table_element(pos) {}
2432};
2433
2436
2437 public:
2439 const LEX_STRING &name_arg,
2443 : super(pos),
2444 m_keytype(type_par),
2445 m_name(name_arg),
2446 m_type(type),
2447 m_columns(cols),
2448 m_options(options) {}
2449
2450 bool do_contextualize(Table_ddl_parse_context *pc) override;
2451
2452 private:
2458};
2459
2462
2463 public:
2464 PT_foreign_key_definition(const POS &pos, const LEX_STRING &constraint_name,
2465 const LEX_STRING &key_name,
2467 Table_ident *referenced_table,
2468 List<Key_part_spec> *ref_list,
2469 fk_match_opt fk_match_option,
2470 fk_option fk_update_opt, fk_option fk_delete_opt)
2471 : super(pos),
2472 m_constraint_name(constraint_name),
2473 m_key_name(key_name),
2474 m_columns(columns),
2475 m_referenced_table(referenced_table),
2476 m_ref_list(ref_list),
2477 m_fk_match_option(fk_match_option),
2478 m_fk_update_opt(fk_update_opt),
2479 m_fk_delete_opt(fk_delete_opt) {}
2480
2481 bool do_contextualize(Table_ddl_parse_context *pc) override;
2482
2483 private:
2492};
2493
2494/**
2495 Common base class for CREATE TABLE and ALTER TABLE option nodes
2496
2497 @ingroup ptn_create_or_alter_table_options
2498*/
2500 protected:
2501 explicit PT_ddl_table_option(const POS &pos) : Table_ddl_node(pos) {}
2502
2503 public:
2504 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2505
2506 virtual bool is_rename_table() const { return false; }
2507};
2508
2510
2511/**
2512 Base class for CREATE TABLE option nodes
2513
2514 @ingroup ptn_create_or_alter_table_options
2515*/
2518
2519 protected:
2520 explicit PT_create_table_option(const POS &pos) : super(pos) {}
2521
2522 public:
2523 ~PT_create_table_option() override = 0; // Force abstract class declaration
2524
2526 if (super::do_contextualize(pc)) return true;
2528 return false;
2529 }
2530};
2531
2533
2534/**
2535 A template for options that set a single property in HA_CREATE_INFO, and
2536 also records if the option was explicitly set.
2537*/
2538template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2539 uint64_t Property_flag>
2542
2543 const Option_type value;
2544
2545 public:
2546 explicit PT_traceable_create_table_option(const POS &pos, Option_type value)
2547 : super(pos), value(value) {}
2548
2550 if (super::do_contextualize(pc)) return true;
2551 pc->create_info->*Property = value;
2552 pc->create_info->used_fields |= Property_flag;
2553 return false;
2554 }
2555};
2556
2557#define TYPE_AND_REF(x) decltype(x), &x
2558
2559/**
2560 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2561
2562 @ingroup ptn_create_or_alter_table_options
2563*/
2567
2568/**
2569 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2570
2571 @ingroup ptn_create_or_alter_table_options
2572*/
2576
2577/**
2578 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2579
2580 @ingroup ptn_create_or_alter_table_options
2581*/
2585
2586/**
2587 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2588
2589 @ingroup ptn_create_or_alter_table_options
2590*/
2594
2595/**
2596 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2597
2598 @ingroup ptn_create_or_alter_table_options
2599*/
2603
2604/**
2605 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2606
2607 @ingroup ptn_create_or_alter_table_options
2608*/
2612
2613/**
2614 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2615
2616 @ingroup ptn_create_or_alter_table_options
2617*/
2621
2622/**
2623 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2624
2625 @ingroup ptn_create_or_alter_table_options
2626*/
2630
2634
2639
2643
2647
2651
2655
2659
2664
2669
2671
2672/**
2673 A template for options that set HA_CREATE_INFO::table_options and
2674 also records if the option was explicitly set.
2675*/
2676template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2677 table_options_t No>
2680
2682
2683 public:
2685 : super(pos), value(value) {}
2686
2688 if (super::do_contextualize(pc)) return true;
2689 pc->create_info->table_options &= ~(Yes | No);
2690 switch (value) {
2691 case Ternary_option::ON:
2692 pc->create_info->table_options |= Yes;
2693 break;
2695 pc->create_info->table_options |= No;
2696 break;
2698 break;
2699 default:
2700 assert(false);
2701 }
2702 pc->create_info->used_fields |= Property_flag;
2703 return false;
2704 }
2705};
2706
2707/**
2708 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2709
2710 @ingroup ptn_create_or_alter_table_options
2711
2712 PACK_KEYS | Constructor parameter
2713 ----------|----------------------
2714 1 | Ternary_option::ON
2715 0 | Ternary_option::OFF
2716 DEFAULT | Ternary_option::DEFAULT
2717*/
2719 0, // DEFAULT
2720 HA_OPTION_PACK_KEYS, // ON
2723
2724/**
2725 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2726
2727 @ingroup ptn_create_or_alter_table_options
2728
2729 STATS_PERSISTENT | Constructor parameter
2730 -----------------|----------------------
2731 1 | Ternary_option::ON
2732 0 | Ternary_option::OFF
2733 DEFAULT | Ternary_option::DEFAULT
2734*/
2736 0, // DEFAULT
2740
2741/**
2742 A template for options that set HA_CREATE_INFO::table_options and
2743 also records if the option was explicitly set.
2744*/
2745template <ulong Property_flag, table_options_t Yes, table_options_t No>
2748
2749 const bool value;
2750
2751 public:
2752 explicit PT_bool_create_table_option(const POS &pos, bool value)
2753 : super(pos), value(value) {}
2754
2756 if (super::do_contextualize(pc)) return true;
2757 pc->create_info->table_options &= ~(Yes | No);
2758 pc->create_info->table_options |= value ? Yes : No;
2759 pc->create_info->used_fields |= Property_flag;
2760 return false;
2761 }
2762};
2763
2764/**
2765 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2766
2767 @ingroup ptn_create_or_alter_table_options
2768
2769 TABLE_CHECKSUM | Constructor parameter
2770 ---------------|----------------------
2771 0 | false
2772 not 0 | true
2773*/
2775 HA_OPTION_CHECKSUM, // ON
2777 >
2779
2780/**
2781 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2782
2783 @ingroup ptn_create_or_alter_table_options
2784
2785 TABLE_CHECKSUM | Constructor parameter
2786 ---------------|----------------------
2787 0 | false
2788 not 0 | true
2789*/
2794
2795/**
2796 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2797
2798 @ingroup ptn_create_or_alter_table_options
2799*/
2802
2804
2805 public:
2806 /**
2807 @param pos Position of this clause in the SQL statement.
2808 @param engine Storage engine name.
2809 */
2811 const LEX_CSTRING &engine)
2812 : super(pos), engine(engine) {}
2813
2814 bool do_contextualize(Table_ddl_parse_context *pc) override;
2815};
2816
2817/**
2818 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2819 table option.
2820
2821 @ingroup ptn_create_or_alter_table_options
2822*/
2825
2826 public:
2828 : super(pos) {}
2830 const POS &pos, const LEX_CSTRING &secondary_engine)
2832
2833 bool do_contextualize(Table_ddl_parse_context *pc) override;
2834
2835 private:
2837};
2838
2839/**
2840 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2841
2842 @ingroup ptn_create_or_alter_table_options
2843*/
2846
2848
2849 public:
2850 /**
2851 @param pos Position of this clause in the SQL statement.
2852 @param value
2853 STATS_AUTO_RECALC | value
2854 ------------------|----------------------
2855 1 | Ternary_option::ON
2856 0 | Ternary_option::OFF
2857 DEFAULT | Ternary_option::DEFAULT
2858 */
2860 : super(pos), value(value) {}
2861
2862 bool do_contextualize(Table_ddl_parse_context *pc) override;
2863};
2864
2865/**
2866 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2867
2868 @ingroup ptn_create_or_alter_table_options
2869*/
2873
2875
2876 public:
2877 /**
2878 Constructor for implicit number of pages
2879
2880 @param pos Position of this clause in the SQL statement.
2881 @param value Number of pages, 1@<=N@<=65535.
2882 */
2884 : super(pos), value(value) {
2885 assert(value != 0 && value <= 0xFFFF);
2886 }
2887 /**
2888 Constructor for the DEFAULT number of pages
2889 */
2891 : super(pos), value(0) {} // DEFAULT
2892
2893 bool do_contextualize(Table_ddl_parse_context *pc) override;
2894};
2895
2898
2900
2901 public:
2902 explicit PT_create_union_option(const POS &pos,
2904 : super(pos), tables(tables) {}
2905
2906 bool do_contextualize(Table_ddl_parse_context *pc) override;
2907};
2908
2911
2913
2914 public:
2916 : super(pos), value(value) {}
2917
2919 if (super::do_contextualize(pc)) return true;
2921 return false;
2922 }
2923};
2924
2927
2929
2930 public:
2932 const CHARSET_INFO *value)
2933 : super(pos), value(value) {
2934 assert(value != nullptr);
2935 }
2936
2937 bool do_contextualize(Table_ddl_parse_context *pc) override;
2938};
2939
2942
2944
2945 public:
2947 const CHARSET_INFO *value)
2948 : super(pos), value(value) {
2949 assert(value != nullptr);
2950 }
2951
2952 bool do_contextualize(Table_ddl_parse_context *pc) override;
2953};
2954
2958
2959 public:
2960 explicit PT_check_constraint(const POS &pos, LEX_STRING &name, Item *expr,
2961 bool is_enforced)
2962 : super(pos) {
2963 cc_spec.name = name;
2964 cc_spec.check_expr = expr;
2965 cc_spec.is_enforced = is_enforced;
2966 }
2968
2969 bool do_contextualize(Table_ddl_parse_context *pc) override;
2970};
2971
2974
2977 // Currently we ignore that constraint in the executor.
2979
2980 const char *opt_place;
2981
2982 public:
2986 const char *opt_place = nullptr)
2987 : super(pos),
2992
2993 bool do_contextualize(Table_ddl_parse_context *pc) override;
2994};
2995
2996/**
2997 Top-level node for the CREATE %TABLE statement
2998
2999 @ingroup ptn_create_table
3000*/
3011
3013
3014 public:
3015 /**
3016 @param pos Position of this clause in the SQL
3017 statement.
3018 @param mem_root MEM_ROOT to use for allocation
3019 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
3020 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
3021 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
3022 @param opt_table_element_list NULL or a list of table column and
3023 constraint definitions.
3024 @param opt_create_table_options NULL or a list of
3025 @ref ptn_create_or_alter_table_options
3026 "table options".
3027 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
3028 @param on_duplicate DUPLICATE, IGNORE or fail with an error
3029 on data duplication errors (relevant
3030 for @SQL{CREATE TABLE ... SELECT}
3031 statements).
3032 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
3033 */
3035 const POS &pos, MEM_ROOT *mem_root, bool is_temporary,
3051 /**
3052 @param pos Position of this clause in the SQL statement.
3053 @param mem_root MEM_ROOT to use for allocation
3054 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
3055 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
3056 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
3057 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
3058 */
3072
3073 Sql_cmd *make_cmd(THD *thd) override;
3074};
3075
3076class PT_create_role final : public Parse_tree_root {
3078
3079 public:
3080 PT_create_role(const POS &pos, bool if_not_exists,
3081 const List<LEX_USER> *roles)
3082 : Parse_tree_root(pos), sql_cmd(if_not_exists, roles) {}
3083
3084 Sql_cmd *make_cmd(THD *thd) override;
3085};
3086
3087class PT_drop_role final : public Parse_tree_root {
3089
3090 public:
3091 explicit PT_drop_role(const POS &pos, bool ignore_errors,
3092 const List<LEX_USER> *roles)
3093 : Parse_tree_root(pos), sql_cmd(ignore_errors, roles) {}
3094
3095 Sql_cmd *make_cmd(THD *thd) override;
3096};
3097
3100
3101 public:
3102 explicit PT_set_role(const POS &pos, role_enum role_type,
3103 const List<LEX_USER> *opt_except_roles = nullptr)
3104 : Parse_tree_root(pos), sql_cmd(role_type, opt_except_roles) {
3105 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
3106 }
3107 explicit PT_set_role(const POS &pos, const List<LEX_USER> *roles)
3108 : Parse_tree_root(pos), sql_cmd(roles) {}
3109
3110 Sql_cmd *make_cmd(THD *thd) override;
3111};
3112
3113/**
3114 This class is used for representing both static and dynamic privileges on
3115 global as well as table and column level.
3116*/
3119
3122
3125 : type(type), columns(columns) {}
3126};
3127
3129 const uint grant;
3130
3132 : Privilege(STATIC, columns_arg), grant(grant) {}
3133};
3134
3137
3139 const Mem_root_array<LEX_CSTRING> *columns_arg)
3140 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
3141};
3142
3144 private:
3146
3147 public:
3148 explicit PT_role_or_privilege(const POS &pos, const POS &errpos)
3149 : Parse_tree_node(pos), m_errpos(errpos) {}
3150 virtual LEX_USER *get_user(THD *thd);
3151 virtual Privilege *get_privilege(THD *thd);
3152};
3153
3157
3158 public:
3159 PT_role_at_host(const POS &pos, const POS &errpos, const LEX_STRING &role,
3160 const LEX_STRING &host)
3161 : PT_role_or_privilege(pos, errpos), role(role), host(host) {}
3162
3163 LEX_USER *get_user(THD *thd) override;
3164};
3165
3168
3169 public:
3170 PT_role_or_dynamic_privilege(const POS &pos, const POS &errpos,
3171 const LEX_STRING &ident)
3172 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3173
3174 LEX_USER *get_user(THD *thd) override;
3175 Privilege *get_privilege(THD *thd) override;
3176};
3177
3179 const uint grant;
3181
3182 public:
3183 PT_static_privilege(const POS &pos, const POS &errpos, uint grant,
3184 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
3185 : PT_role_or_privilege(pos, errpos), grant(grant), columns(columns) {}
3186
3187 Privilege *get_privilege(THD *thd) override;
3188};
3189
3192
3193 public:
3194 PT_dynamic_privilege(const POS &pos, const POS &errpos,
3195 const LEX_STRING &ident)
3196 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3197
3198 Privilege *get_privilege(THD *thd) override;
3199};
3200
3201class PT_grant_roles final : public Parse_tree_root {
3205
3206 public:
3210 : Parse_tree_root(pos),
3211 roles(roles),
3212 users(users),
3214
3215 Sql_cmd *make_cmd(THD *thd) override;
3216};
3217
3218class PT_revoke_roles final : public Parse_tree_root {
3221
3222 public:
3224 const List<LEX_USER> *users)
3225 : Parse_tree_root(pos), roles(roles), users(users) {}
3226
3227 Sql_cmd *make_cmd(THD *thd) override;
3228};
3229
3232
3233 public:
3234 PT_alter_user_default_role(const POS &pos, bool if_exists,
3235 const List<LEX_USER> *users,
3236 const List<LEX_USER> *roles,
3237 const role_enum role_type)
3238 : Parse_tree_root(pos), sql_cmd(if_exists, users, roles, role_type) {}
3239
3240 Sql_cmd *make_cmd(THD *thd) override;
3241};
3242
3243/// Base class for Parse tree nodes of SHOW statements
3244
3246 protected:
3247 PT_show_base(const POS &pos, enum_sql_command sql_command)
3248 : Parse_tree_root(pos), m_sql_command(sql_command) {}
3249
3250 /// SQL command
3252};
3253
3254/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3255
3257 protected:
3259 const LEX_STRING &wild, Item *where)
3260 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3261 assert(m_wild.str == nullptr || m_where == nullptr);
3262 }
3263 /// Wild or where clause used in the statement.
3266};
3267
3268/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3269
3271 protected:
3273 char *opt_db, const LEX_STRING &wild, Item *where)
3274 : PT_show_base(pos, sql_command),
3276 m_wild(wild),
3277 m_where(where) {
3278 assert(m_wild.str == nullptr || m_where == nullptr);
3279 }
3280 /// Optional schema name in FROM/IN clause.
3282 /// Wild or where clause used in the statement.
3285};
3286
3287/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3288
3290 protected:
3291 PT_show_table_base(const POS &pos, enum_sql_command sql_command,
3292 Table_ident *table_ident, const LEX_STRING &wild,
3293 Item *where)
3294 : PT_show_filter_base(pos, sql_command, wild, where),
3295 m_table_ident(table_ident) {}
3296
3297 bool make_table_base_cmd(THD *thd, bool *temporary);
3298
3299 /// Table used in the statement.
3301};
3302
3303/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3304
3306 protected:
3308 const sp_name *routine_name)
3309 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3310
3311 Sql_cmd *make_cmd(THD *thd) override;
3312
3313 private:
3315};
3316
3317/// Parse tree node for SHOW BINLOG EVENTS statement
3318
3320 public:
3321 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3322 PT_limit_clause *opt_limit_clause = nullptr)
3324 m_opt_log_file_name(opt_log_file_name),
3325 m_opt_limit_clause(opt_limit_clause) {}
3326
3327 Sql_cmd *make_cmd(THD *thd) override;
3328
3329 private:
3332
3334};
3335
3336/// Parse tree node for SHOW BINLOGS statement
3337
3338class PT_show_binlogs final : public PT_show_base {
3339 public:
3341
3342 Sql_cmd *make_cmd(THD *thd) override;
3343
3344 private:
3346};
3347
3348/// Parse tree node for SHOW CHARACTER SET statement
3349
3351 public:
3352 PT_show_charsets(const POS &pos, const LEX_STRING &wild, Item *where)
3354
3355 Sql_cmd *make_cmd(THD *thd) override;
3356
3357 private:
3359};
3360
3361/// Parse tree node for SHOW COLLATIONS statement
3362
3364 public:
3365 PT_show_collations(const POS &pos, const LEX_STRING &wild, Item *where)
3367
3368 Sql_cmd *make_cmd(THD *thd) override;
3369
3370 private:
3372};
3373
3374/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3375/// statements.
3376
3378 public:
3379 explicit PT_show_count_base(const POS &pos)
3380 : PT_show_base{pos, SQLCOM_SELECT} {}
3381
3382 protected:
3383 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3384};
3385
3386/// Parse tree node for SHOW COUNT(*) ERRORS
3387
3389 public:
3390 explicit PT_show_count_errors(const POS &pos) : PT_show_count_base(pos) {}
3391
3392 Sql_cmd *make_cmd(THD *thd) override {
3393 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3394 }
3395};
3396
3397/// Parse tree node for SHOW COUNT(*) WARNINGS
3398
3400 public:
3401 explicit PT_show_count_warnings(const POS &pos) : PT_show_count_base(pos) {}
3402
3403 Sql_cmd *make_cmd(THD *thd) override {
3404 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3405 }
3406};
3407
3408/// Parse tree node for SHOW CREATE DATABASE statement
3409
3411 public:
3412 PT_show_create_database(const POS &pos, bool if_not_exists,
3413 const LEX_STRING &name)
3415 m_if_not_exists(if_not_exists),
3416 m_name(name) {}
3417
3418 Sql_cmd *make_cmd(THD *thd) override;
3419
3420 private:
3423
3425};
3426
3427/// Parse tree node for SHOW CREATE EVENT statement
3428
3430 public:
3431 PT_show_create_event(const POS &pos, sp_name *event_name)
3432 : PT_show_base(pos, SQLCOM_SHOW_CREATE_EVENT), m_spname(event_name) {}
3433
3434 Sql_cmd *make_cmd(THD *thd) override;
3435
3436 private:
3438
3440};
3441
3442/// Parse tree node for SHOW CREATE FUNCTION statement
3443
3445 public:
3446 PT_show_create_function(const POS &pos, sp_name *function_name)
3447 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3448
3449 Sql_cmd *make_cmd(THD *thd) override;
3450
3451 private:
3453
3455};
3456
3457/// Parse tree node for SHOW CREATE PROCEDURE statement
3458
3460 public:
3461 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3462 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3463
3464 Sql_cmd *make_cmd(THD *thd) override;
3465
3466 private:
3468
3470};
3471
3472/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3473
3475 public:
3476 PT_show_create_table(const POS &pos, Table_ident *table_ident)
3477 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3478
3479 Sql_cmd *make_cmd(THD *thd) override;
3480
3481 private:
3483};
3484
3485/// Parse tree node for SHOW CREATE TRIGGER statement
3486
3488 public:
3489 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3490 : PT_show_base(pos, SQLCOM_SHOW_CREATE_TRIGGER), m_spname(trigger_name) {}
3491
3492 Sql_cmd *make_cmd(THD *thd) override;
3493
3494 private:
3496
3498};
3499
3500/// Parse tree node for SHOW CREATE USER statement
3501
3502class PT_show_create_user final : public PT_show_base {
3503 public:
3506
3507 Sql_cmd *make_cmd(THD *thd) override;
3508
3509 private:
3511
3513};
3514
3515/// Parse tree node for SHOW CREATE VIEW statement
3516
3517class PT_show_create_view final : public PT_show_base {
3518 public:
3519 PT_show_create_view(const POS &pos, Table_ident *table_ident)
3520 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3521
3522 Sql_cmd *make_cmd(THD *thd) override;
3523
3524 private:
3526};
3527
3528/// Parse tree node for SHOW DATABASES statement
3529
3531 public:
3532 PT_show_databases(const POS &pos, const LEX_STRING &wild, Item *where)
3534
3535 Sql_cmd *make_cmd(THD *thd) override;
3536
3537 private:
3539};
3540
3541/// Parse tree node for SHOW ENGINE statements
3542
3544 protected:
3545 PT_show_engine_base(const POS &pos, enum enum_sql_command sql_command,
3546 const LEX_STRING opt_engine = {})
3547 : PT_show_base(pos, sql_command),
3548 m_engine(opt_engine),
3549 m_all(opt_engine.str == nullptr) {}
3550
3552 bool m_all;
3553};
3554
3555/// Parse tree node for SHOW ENGINE LOGS statement
3556
3558 public:
3559 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3560 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_LOGS, opt_engine) {}
3561
3562 Sql_cmd *make_cmd(THD *thd) override;
3563
3564 private:
3566};
3567
3568/// Parse tree node for SHOW ENGINE MUTEX statement
3569
3571 public:
3572 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3573 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_MUTEX, opt_engine) {}
3574
3575 Sql_cmd *make_cmd(THD *thd) override;
3576
3577 private:
3579};
3580
3581/// Parse tree node for SHOW ENGINE STATUS statement
3582
3584 public:
3585 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3586 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_STATUS, opt_engine) {}
3587
3588 Sql_cmd *make_cmd(THD *thd) override;
3589
3590 private:
3592};
3593
3594/// Parse tree node for SHOW ENGINES statement
3595
3596class PT_show_engines final : public PT_show_base {
3597 public:
3600
3601 Sql_cmd *make_cmd(THD *thd) override;
3602
3603 private:
3605};
3606
3607/// Parse tree node for SHOW ERRORS statement
3608
3609class PT_show_errors final : public PT_show_base {
3610 public:
3611 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3613 m_opt_limit_clause(opt_limit_clause) {}
3614
3615 Sql_cmd *make_cmd(THD *thd) override;
3616
3617 private:
3619
3621};
3622
3623/// Parse tree node for SHOW EVENTS statement
3624
3626 public:
3627 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3628 Item *where)
3630
3631 Sql_cmd *make_cmd(THD *thd) override;
3632
3633 private:
3635};
3636
3637/// Parse tree node for SHOW COLUMNS statement.
3638
3641
3642 public:
3643 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3644 Table_ident *table, LEX_STRING opt_wild = {},
3645 Item *opt_where = nullptr)
3646 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3647 m_show_cmd_type(show_cmd_type) {}
3648
3649 Sql_cmd *make_cmd(THD *thd) override;
3650
3651 private:
3654};
3655
3656/// Parse tree node for SHOW FUNCTION CODE statement.
3657
3659 public:
3660 PT_show_function_code(const POS &pos, const sp_name *function_name)
3661 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3662};
3663
3664/// Parse tree node for SHOW GRANTS statement.
3665
3666class PT_show_grants final : public PT_show_base {
3667 public:
3668 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3669 const List<LEX_USER> *opt_using_users)
3671 sql_cmd(opt_for_user, opt_using_users) {
3672 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3673 }
3674
3675 Sql_cmd *make_cmd(THD *thd) override;
3676
3677 private:
3679};
3680
3681/// Parse tree node for SHOW INDEX statement.
3682
3683class PT_show_keys final : public PT_show_table_base {
3684 public:
3685 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3686 Item *where)
3688 m_extended_show(extended_show) {}
3689
3690 Sql_cmd *make_cmd(THD *thd) override;
3691
3692 private:
3694
3695 // Flag to indicate EXTENDED keyword usage in the statement.
3698};
3699
3700/// Parse tree node for SHOW MASTER STATUS statement
3701
3703 public:
3706
3707 Sql_cmd *make_cmd(THD *thd) override;
3708
3709 private:
3711};
3712
3713/// Parse tree node for SHOW OPEN TABLES statement
3714
3716 public:
3717 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3718 Item *where)
3720 }
3721
3722 Sql_cmd *make_cmd(THD *thd) override;
3723
3724 private:
3726};
3727
3728/// Parse tree node for SHOW PLUGINS statement
3729
3730class PT_show_plugins final : public PT_show_base {
3731 public:
3733
3734 Sql_cmd *make_cmd(THD *thd) override;
3735
3736 private:
3738};
3739
3740/// Parse tree node for SHOW PRIVILEGES statement
3741
3742class PT_show_privileges final : public PT_show_base {
3743 public:
3746
3747 Sql_cmd *make_cmd(THD *thd) override;
3748
3749 private:
3751};
3752
3753/// Parse tree node for SHOW PARSE_TREE statement
3754
3755class PT_show_parse_tree final : public PT_show_base {
3756 public:
3757 PT_show_parse_tree(const POS &pos, Parse_tree_root *parse_tree_stmt)
3759 m_parse_tree_stmt(parse_tree_stmt) {}
3760
3761 Sql_cmd *make_cmd(THD *thd) override;
3762
3763 private:
3766};
3767
3768/// Parse tree node for SHOW FUNCTION CODE statement.
3769
3771 public:
3772 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3773 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3774};
3775
3776/// Parse tree node for SHOW PROCESSLIST statement
3777
3778class PT_show_processlist final : public PT_show_base {
3779 public:
3782
3783 Sql_cmd *make_cmd(THD *thd) override;
3784
3785 private:
3787};
3788
3789/// Parse tree node for SHOW PROFILE statement
3790
3791class PT_show_profile final : public PT_show_base {
3792 public:
3793 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3794 my_thread_id opt_query_id = 0,
3795 PT_limit_clause *opt_limit_clause = nullptr)
3797 m_opt_profile_options(opt_profile_options),
3798 m_opt_query_id(opt_query_id),
3799 m_opt_limit_clause(opt_limit_clause) {}
3800
3801 Sql_cmd *make_cmd(THD *thd) override;
3802
3803 private:
3807
3809};
3810
3811/// Parse tree node for SHOW PROFILES statement
3812
3813class PT_show_profiles final : public PT_show_base {
3814 public:
3816
3817 Sql_cmd *make_cmd(THD *thd) override;
3818
3819 private:
3821};
3822
3823/// Parse tree node for SHOW RELAYLOG EVENTS statement
3824
3826 public:
3828 const LEX_STRING opt_log_file_name = {},
3829 PT_limit_clause *opt_limit_clause = nullptr,
3830 LEX_CSTRING opt_channel_name = {})
3832 m_opt_log_file_name(opt_log_file_name),
3833 m_opt_limit_clause(opt_limit_clause),
3834 m_opt_channel_name(opt_channel_name) {}
3835
3836 Sql_cmd *make_cmd(THD *thd) override;
3837
3838 private:
3842
3844};
3845
3846/// Parse tree node for SHOW REPLICAS statement
3847
3848class PT_show_replicas final : public PT_show_base {
3849 public:
3852
3853 Sql_cmd *make_cmd(THD *thd) override;
3854
3855 private:
3857};
3858
3859/// Parse tree node for SHOW REPLICA STATUS statement
3860
3862 public:
3863 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3865 m_opt_channel_name(opt_channel_name) {}
3866
3867 Sql_cmd *make_cmd(THD *thd) override;
3868
3869 private:
3871
3873};
3874
3875/// Parse tree node for SHOW STATUS statement
3876
3878 public:
3879 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3880 Item *where)
3882 m_var_type(var_type) {
3884 }
3885
3886 Sql_cmd *make_cmd(THD *thd) override;
3887
3888 private:
3890
3892};
3893
3894/// Parse tree node for SHOW STATUS FUNCTION statement
3895
3897 public:
3898 PT_show_status_func(const POS &pos, const LEX_STRING &wild, Item *where)
3900
3901 Sql_cmd *make_cmd(THD *thd) override;
3902
3903 private:
3905};
3906
3907/// Parse tree node for SHOW STATUS PROCEDURE statement
3908
3910 public:
3911 PT_show_status_proc(const POS &pos, const LEX_STRING &wild, Item *where)
3913
3914 Sql_cmd *make_cmd(THD *thd) override;
3915
3916 private:
3918};
3919
3920/// Parse tree node for SHOW TABLE STATUS statement
3921
3923 public:
3924 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
3925 Item *where)
3927 where) {}
3928
3929 Sql_cmd *make_cmd(THD *thd) override;
3930
3931 private:
3933};
3934
3935/// Parse tree node for SHOW TABLES statement
3936
3938 public:
3939 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
3940 const LEX_STRING &wild, Item *where)
3942 m_show_cmd_type(show_cmd_type) {}
3943
3944 Sql_cmd *make_cmd(THD *thd) override;
3945
3946 private:
3948
3950};
3951
3952/// Parse tree node for SHOW TRIGGERS statement
3953
3955 public:
3956 PT_show_triggers(const POS &pos, bool full, char *opt_db,
3957 const LEX_STRING &wild, Item *where)
3959 m_full(full) {}
3960
3961 Sql_cmd *make_cmd(THD *thd) override;
3962
3963 private:
3965
3967};
3968
3969/// Parse tree node for SHOW VARIABLES statement
3970
3972 public:
3974 const LEX_STRING &wild, Item *where)
3976 m_var_type(var_type) {
3978 }
3979
3980 Sql_cmd *make_cmd(THD *thd) override;
3981
3982 private:
3984
3986};
3987
3988/// Parse tree node for SHOW WARNINGS statement
3989
3990class PT_show_warnings final : public PT_show_base {
3991 public:
3992 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3994 m_opt_limit_clause(opt_limit_clause) {}
3995
3996 Sql_cmd *make_cmd(THD *thd) override;
3997
3998 private:
4000
4002};
4003
4006
4007 protected:
4008 explicit PT_alter_table_action(const POS &pos,
4010 : super(pos), flag(flag) {}
4011
4012 public:
4013 bool do_contextualize(Table_ddl_parse_context *pc) override;
4014
4015 protected:
4016 /**
4017 A routine used by the parser to decide whether we are specifying a full
4018 partitioning or if only partitions to add or to reorganize.
4019
4020 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
4021 @retval false Something else.
4022 */
4026 }
4027
4028 public:
4030};
4031
4034
4035 public:
4036 PT_alter_table_add_column(const POS &pos, const LEX_STRING &field_ident,
4037 PT_field_def_base *field_def,
4038 PT_table_constraint_def *opt_column_constraint,
4039 const char *opt_place)
4040 : super(pos, Alter_info::ALTER_ADD_COLUMN),
4041 m_column_def(POS(), field_ident, field_def, opt_column_constraint,
4042 opt_place) {}
4043
4046 }
4047
4048 private:
4049 PT_column_def m_column_def; // TODO: Position is not set.
4050};
4051
4054
4055 public:
4057 const POS &pos, const Mem_root_array<PT_table_element *> *columns)
4058 : super(pos, Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
4059
4061 if (super::do_contextualize(pc)) return true;
4062
4063 for (auto *column : *m_columns)
4064 if (column->contextualize(pc)) return true;
4065
4066 return false;
4067 }
4068
4069 private:
4071};
4072
4075
4076 public:
4078 PT_table_constraint_def *constraint)
4079 : super(pos, Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
4080
4083 }
4084
4085 private:
4087};
4088
4091
4092 public:
4093 PT_alter_table_change_column(const POS &pos, const LEX_STRING &old_name,
4094 const LEX_STRING &new_name,
4095 PT_field_def_base *field_def,
4096 const char *opt_place)
4097 : super(pos, Alter_info::ALTER_CHANGE_COLUMN),
4098 m_old_name(old_name),
4099 m_new_name(new_name),
4100 m_field_def(field_def),
4101 m_opt_place(opt_place) {}
4102
4104 PT_field_def_base *field_def,
4105 const char *opt_place)
4106 : PT_alter_table_change_column(pos, name, name, field_def, opt_place) {}
4107
4108 bool do_contextualize(Table_ddl_parse_context *pc) override;
4109
4110 private:
4114 const char *m_opt_place;
4115};
4116
4119
4120 protected:
4122 Alter_info::Alter_info_flag alter_info_flag,
4123 const char *name)
4124 : super(pos, alter_info_flag), m_alter_drop(drop_type, name) {}
4125
4126 public:
4128 return (super::do_contextualize(pc) ||
4129 pc->alter_info->drop_list.push_back(&m_alter_drop));
4130 }
4131
4132 private:
4134};
4135
4137 public:
4138 explicit PT_alter_table_drop_column(const POS &pos, const char *name)
4139 : PT_alter_table_drop(pos, Alter_drop::COLUMN,
4140 Alter_info::ALTER_DROP_COLUMN, name) {}
4141};
4142
4144 public:
4145 explicit PT_alter_table_drop_foreign_key(const POS &pos, const char *name)
4147 Alter_info::DROP_FOREIGN_KEY, name) {}
4148};
4149
4151 public:
4152 explicit PT_alter_table_drop_key(const POS &pos, const char *name)
4153 : PT_alter_table_drop(pos, Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
4154 name) {}
4155};
4156
4158 public:
4160 const char *name)
4161 : PT_alter_table_drop(pos, Alter_drop::CHECK_CONSTRAINT,
4162 Alter_info::DROP_CHECK_CONSTRAINT, name) {}
4163};
4164
4166 public:
4167 explicit PT_alter_table_drop_constraint(const POS &pos, const char *name)
4168 : PT_alter_table_drop(pos, Alter_drop::ANY_CONSTRAINT,
4169 Alter_info::DROP_ANY_CONSTRAINT, name) {}
4170};
4171
4174
4175 protected:
4177 const POS &pos, Alter_constraint_enforcement::Type alter_type,
4178 Alter_info::Alter_info_flag alter_info_flag, const char *name,
4179 bool is_enforced)
4180 : super(pos, alter_info_flag),
4181 m_constraint_enforcement(alter_type, name, is_enforced) {}
4182
4183 public:
4184 explicit PT_alter_table_enforce_constraint(const POS &pos, const char *name,
4185 bool is_enforced)
4186 : super(pos, is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
4187 : Alter_info::SUSPEND_ANY_CONSTRAINT),
4189 Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
4190 is_enforced) {}
4191
4193 return (super::do_contextualize(pc) ||
4196 }
4197
4198 private:
4200};
4201
4204 public:
4206 const char *name,