MySQL 9.1.0
Source Code Documentation
parse_tree_nodes.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PARSE_TREE_NODES_INCLUDED
25#define PARSE_TREE_NODES_INCLUDED
26
27#include <assert.h>
28#include <sys/types.h> // TODO: replace with cstdint
29
30#include <bit>
31#include <cctype> // std::isspace
32#include <cstddef>
33#include <memory>
34
35#include "lex_string.h"
36#include "my_alloc.h"
37#include "my_base.h"
38
39#include "my_inttypes.h" // TODO: replace with cstdint
40#include "my_sqlcommand.h"
41#include "my_sys.h"
42#include "my_thread_local.h"
43#include "my_time.h"
44#include "mysqld_error.h"
45#include "sql/check_stack.h"
46#include "sql/enum_query_type.h"
47#include "sql/handler.h"
48#include "sql/key_spec.h"
49#include "sql/mem_root_array.h"
50#include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
51#include "sql/parse_location.h"
52#include "sql/parse_tree_helpers.h" // PT_item_list
54#include "sql/parser_yystype.h"
55#include "sql/partition_info.h"
58#include "sql/set_var.h"
59#include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
60#include "sql/sql_alter.h"
61#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
62#include "sql/sql_cmd_srs.h"
63#include "sql/sql_exchange.h"
64#include "sql/sql_lex.h" // LEX
65#include "sql/sql_list.h"
66#include "sql/sql_load.h" // Sql_cmd_load_table
68#include "sql/sql_restart_server.h" // Sql_cmd_restart_server
69#include "sql/sql_tablespace.h" // Tablespace_options
70#include "sql/sql_truncate.h" // Sql_cmd_truncate_table
71#include "sql/table.h" // Common_table_expr
72#include "sql/tablesample.h"
73#include "sql/window_lex.h"
74#include "string_with_len.h"
75#include "thr_lock.h"
76
77class Item;
78class Item_cache;
82class PT_hint_list;
85class PT_partition;
86class PT_subquery;
87class PT_type;
88class PT_window_list;
89class Sql_cmd;
90class String;
91class THD;
92class Window;
93class sp_head;
94class sp_name;
95struct CHARSET_INFO;
96
97/**
98 @defgroup ptn Parse tree nodes
99 @ingroup Parser
100*/
101/**
102 @defgroup ptn_stmt Nodes representing SQL statements
103 @ingroup ptn
104*/
105/**
106 @defgroup ptn_create_table CREATE TABLE statement
107 @ingroup ptn_stmt
108*/
109/**
110 @defgroup ptn_alter_table ALTER TABLE statement
111 @ingroup ptn_stmt
112*/
113/**
114 @defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
115 @ingroup ptn_create_table
116*/
117/**
118 @defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
119 @ingroup ptn_create_table ptn_alter_table
120*/
121/**
122 @defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
123 @ingroup ptn_partitioning
124*/
125/**
126 @defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
127 TABLE
128 @anchor ptn_create_or_alter_table_options
129 @ingroup ptn_create_table ptn_alter_table
130*/
131/**
132 @defgroup ptn_col_types Column types in CREATE/ALTER TABLE
133 @ingroup ptn_create_table ptn_alter_table
134*/
135/**
136 @defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
137 @ingroup ptn_create_table ptn_alter_table
138*/
139/**
140 @defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
141 TABLE
142 @ingroup ptn_col_attrs ptn_alter_table
143*/
144
145/**
146 Calls contextualize() on every node in the array.
147*/
148template <class Node_type, class Parse_context_type>
150 Parse_context_type *pc) {
151 for (Node_type *i : nodes)
152 if (i->contextualize(pc)) return true;
153 return false;
154}
155
156/**
157 Base class for all top-level nodes of SQL statements
158
159 @ingroup ptn_stmt
160*/
163 void operator=(const Parse_tree_root &) = delete;
164
165 protected:
166 Parse_tree_root() = default;
167 explicit Parse_tree_root(const POS &pos) : m_pos(pos) {}
168 virtual ~Parse_tree_root() = default;
169
170 public:
171 /// Textual location of a token just parsed.
173
174 virtual Sql_cmd *make_cmd(THD *thd) = 0;
175
176 // Return Json parse tree generated by SHOW PARSE_TREE.
177 virtual std::string get_printable_parse_tree(THD *thd [[maybe_unused]]) {
178 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
179 "Parse tree display of this statement");
180 return "";
181 }
182};
183
185 public:
188
189 ~PT_table_ddl_stmt_base() override = 0; // force abstract class
190
191 protected:
193};
194
196
197/**
198 Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
199
200 For internal use in the contextualization code.
201*/
203 Table_ddl_parse_context(THD *thd_arg, Query_block *select_arg,
208};
209
210/**
211 Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
212*/
214
215class PT_order_expr : public Parse_tree_node, public ORDER {
217
218 public:
219 PT_order_expr(const POS &pos, Item *item_arg, enum_order dir) : super(pos) {
220 item_initial = item_arg;
222 }
223
224 bool do_contextualize(Parse_context *pc) override;
225
226 protected:
227 void add_json_info(Json_object *obj) override {
228 obj->add_alias("desc",
229 create_dom_ptr<Json_boolean>(direction == ORDER_DESC));
230 }
231};
232
235
236 public:
238
239 public:
240 explicit PT_order_list(const POS &pos) : super(pos) {}
241
242 bool do_contextualize(Parse_context *pc) override {
243 if (super::do_contextualize(pc)) return true;
244 for (ORDER *o = value.first; o != nullptr; o = o->next) {
245 if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
246 }
247 return false;
248 }
249
251 order->used_alias = nullptr;
252 order->used = 0;
253 value.link_in_list(order, &order->next);
254 }
255};
256
259
260 public:
261 explicit PT_gorder_list(const POS &pos) : super(pos) {}
262
263 bool do_contextualize(Parse_context *pc) override {
264 return super::do_contextualize(pc);
265 }
266};
267
268/**
269 Represents an element of the WITH list:
270 WITH [...], [...] SELECT ...,
271 ^ or ^
272 i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
273*/
276
277 public:
278 explicit PT_common_table_expr(const POS &pos, const LEX_STRING &name,
279 const LEX_STRING &subq_text,
280 uint subq_text_offset, PT_subquery *sn,
283
284 /// The name after AS
285 const LEX_STRING &name() const { return m_name; }
286 /**
287 @param thd Thread handler
288 @param[out] node PT_subquery
289 @returns a PT_subquery to attach to a table reference for this CTE
290 */
291 bool make_subquery_node(THD *thd, PT_subquery **node);
292 /**
293 @param tl Table reference to match
294 @param in_self If this is a recursive reference
295 @param[out] found Is set to true/false if matches or not
296 @returns true if error
297 */
298 bool match_table_ref(Table_ref *tl, bool in_self, bool *found);
299 /**
300 @returns true if 'other' is the same instance as 'this'
301 */
302 bool is(const Common_table_expr *other) const {
303 return other == &m_postparse;
304 }
305 void print(const THD *thd, String *str, enum_query_type query_type);
306 bool do_contextualize(Parse_context *pc) override;
307
308 protected:
309 void add_json_info(Json_object *obj) override;
310
311 private:
313 /// Raw text of query expression (including parentheses)
315 /**
316 Offset in bytes of m_subq_text in original statement which had the WITH
317 clause.
318 */
320 /// Parsed version of subq_text
322 /// List of explicitly specified column names; if empty, no list.
324 /**
325 A Table_ref representing a CTE needs access to the WITH list
326 element it derives from. However, in order to:
327 - limit the members which Table_ref can access
328 - avoid including this header file everywhere Table_ref needs to
329 access these members, these members are relocated into a separate inferior
330 object whose declaration is in table.h, like that of Table_ref. It's
331 the "postparse" part. Table_ref accesses this inferior object only.
332 */
334
336};
337
338/**
339 Represents the WITH list.
340 WITH [...], [...] SELECT ...,
341 ^^^^^^^^^^^^
342*/
345
346 public:
347 /// @param pos Position of this clause in the SQL statement.
348 /// @param mem_root where interior objects are allocated
349 explicit PT_with_list(const POS &pos, MEM_ROOT *mem_root)
350 : super(pos), m_elements(mem_root) {}
353 return m_elements;
354 }
355
356 private:
358};
359
360/**
361 Represents the WITH clause:
362 WITH [...], [...] SELECT ...,
363 ^^^^^^^^^^^^^^^^^
364*/
367
368 public:
369 PT_with_clause(const POS &pos, const PT_with_list *l, bool r)
370 : super(pos),
371 m_list(l),
372 m_recursive(r),
374
375 bool do_contextualize(Parse_context *pc) override;
376
377 /**
378 Looks up a table reference into the list of CTEs.
379 @param tl Table reference to look up
380 @param[out] found Is set to true/false if found or not
381 @returns true if error
382 */
383 bool lookup(Table_ref *tl, PT_common_table_expr **found);
384 /**
385 Call this to record in the WITH clause that we are contextualizing the
386 CTE definition inserted in table reference 'tl'.
387 @returns information which the caller must provide to
388 leave_parsing_definition().
389 */
391 auto old = m_most_inner_in_parsing;
393 return old;
394 }
397 }
398 void print(const THD *thd, String *str, enum_query_type query_type);
399
400 protected:
401 void add_json_info(Json_object *obj) override {
402 obj->add_alias("recursive", create_dom_ptr<Json_boolean>(m_recursive));
403 }
404
405 private:
406 /// All CTEs of this clause
407 const PT_with_list *const m_list;
408 /// True if the user has specified the RECURSIVE keyword.
409 const bool m_recursive;
410 /**
411 The innermost CTE reference which we're parsing at the
412 moment. Used to detect forward references, loops and recursiveness.
413 */
415
417};
418
421
422 public:
423 explicit PT_select_item_list(const POS &pos) : super(pos) {}
424
425 bool do_contextualize(Parse_context *pc) override;
426};
427
430
432
433 protected:
434 void add_json_info(Json_object *obj) override {
435 obj->add_alias("is_offset_first",
436 create_dom_ptr<Json_boolean>(limit_options.is_offset_first));
437 }
438
439 public:
440 PT_limit_clause(const POS &pos, const Limit_options &limit_options_arg)
441 : super(pos), limit_options(limit_options_arg) {}
442
443 bool do_contextualize(Parse_context *pc) override;
445};
446
447class PT_cross_join;
448class PT_joined_table;
449
451 public:
452 explicit PT_table_reference(const POS &pos) : Parse_tree_node(pos) {}
453
455
456 /**
457 Lets us build a parse tree top-down, which is necessary due to the
458 context-dependent nature of the join syntax. This function adds
459 the @<table_ref@> cross join as the left-most leaf in this join tree
460 rooted at this node.
461
462 @todo: comment on non-join PT_table_reference objects
463
464 @param cj This @<table ref@> will be added if it represents a cross join.
465
466 @return The new top-level join.
467 */
469};
470
473
476 const char *const opt_table_alias;
479
480 public:
481 PT_table_factor_table_ident(const POS &pos, Table_ident *table_ident_arg,
482 List<String> *opt_use_partition_arg,
483 const LEX_CSTRING &opt_table_alias_arg,
484 List<Index_hint> *opt_key_definition_arg,
485 PT_tablesample *opt_tablesample_arg)
486 : super(pos),
487 table_ident(table_ident_arg),
488 opt_use_partition(opt_use_partition_arg),
489 opt_table_alias(opt_table_alias_arg.str),
490 opt_key_definition(opt_key_definition_arg),
491 opt_tablesample(opt_tablesample_arg) {}
492
493 protected:
494 bool do_contextualize(Parse_context *pc) override;
495 void add_json_info(Json_object *obj) override;
496};
497
499 protected:
500 explicit PT_json_table_column(const POS &pos) : Parse_tree_node(pos) {}
501
502 public:
504};
505
508
509 public:
512 const LEX_STRING &table_alias)
513 : super(pos),
514 m_expr(expr),
515 m_path(path),
516 m_nested_columns(nested_cols),
517 m_table_alias(table_alias) {}
518
519 bool do_contextualize(Parse_context *pc) override;
520
521 private:
526};
527
530
532
533 public:
536 : super(pos), table_list(table_list) {}
537
538 bool do_contextualize(Parse_context *pc) override;
539};
540
543
544 public:
545 PT_derived_table(const POS &pos, bool lateral, PT_subquery *subquery,
546 const LEX_CSTRING &table_alias,
548
549 bool do_contextualize(Parse_context *pc) override;
550
551 protected:
552 void add_json_info(Json_object *obj) override;
553
554 private:
557 const char *const m_table_alias;
558 /// List of explicitly specified column names; if empty, no list.
560};
561
564
565 public:
567 : super(pos), m_joined_table(joined_table) {}
568
569 bool do_contextualize(Parse_context *pc) override;
570
571 private:
573};
574
577
578 protected:
583
586
587 public:
588 PT_joined_table(const POS &pos, PT_table_reference *tab1_node_arg,
589 const POS &join_pos_arg, PT_joined_table_type type,
590 PT_table_reference *tab2_node_arg)
591 : super(pos),
592 m_left_pt_table(tab1_node_arg),
593 m_join_pos(join_pos_arg),
594 m_type(type),
595 m_right_pt_table(tab2_node_arg) {
596 using std::has_single_bit;
597 static_assert(has_single_bit(unsigned{JTT_INNER}), "not a single bit");
598 static_assert(has_single_bit(unsigned{JTT_STRAIGHT}), "not a single bit");
599 static_assert(has_single_bit(unsigned{JTT_NATURAL}), "not a single bit");
600 static_assert(has_single_bit(unsigned{JTT_LEFT}), "not a single bit");
601 static_assert(has_single_bit(unsigned{JTT_RIGHT}), "not a single bit");
602
603 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
606 }
607
608 /**
609 Adds the cross join to this join operation. The cross join is nested as
610 the table reference on the left-hand side.
611 */
614 return this;
615 }
616
617 /// Adds the table reference as the right-hand side of this join.
619 assert(m_right_pt_table == nullptr);
621 }
622
623 bool do_contextualize(Parse_context *pc) override;
624
625 /// This class is being inherited, it should thus be abstract.
626 ~PT_joined_table() override = 0;
627
628 protected:
630 void add_json_info(Json_object *obj) override;
631};
632
633inline PT_joined_table::~PT_joined_table() = default;
634
637
638 public:
639 PT_cross_join(const POS &pos, PT_table_reference *tab1_node_arg,
640 const POS &join_pos_arg, PT_joined_table_type Type_arg,
641 PT_table_reference *tab2_node_arg)
642 : PT_joined_table(pos, tab1_node_arg, join_pos_arg, Type_arg,
643 tab2_node_arg) {}
644
645 bool do_contextualize(Parse_context *pc) override;
646};
647
651
652 public:
653 PT_joined_table_on(const POS &pos, PT_table_reference *tab1_node_arg,
654 const POS &join_pos_arg, PT_joined_table_type type,
655 PT_table_reference *tab2_node_arg, Item *on_arg)
656 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
657 on(on_arg) {}
658
659 bool do_contextualize(Parse_context *pc) override;
660};
661
665
666 public:
667 PT_joined_table_using(const POS &pos, PT_table_reference *tab1_node_arg,
668 const POS &join_pos_arg, PT_joined_table_type type,
669 PT_table_reference *tab2_node_arg,
670 List<String> *using_fields_arg)
671 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
672 using_fields(using_fields_arg) {}
673
674 /// A PT_joined_table_using without a list of columns denotes a natural join.
675 PT_joined_table_using(const POS &pos, PT_table_reference *tab1_node_arg,
676 const POS &join_pos_arg, PT_joined_table_type type,
677 PT_table_reference *tab2_node_arg)
678 : PT_joined_table_using(pos, tab1_node_arg, join_pos_arg, type,
679 tab2_node_arg, nullptr) {}
680
681 bool do_contextualize(Parse_context *pc) override;
682
683 protected:
684 void add_json_info(Json_object *obj) override;
685};
686
687/*
688 PT_tablesample - parse tree node
689
690 Information contained in TABLESAMPLE clause is here.
691*/
694
695 public:
698
699 PT_tablesample(const POS &pos, tablesample_type tablesample_type_arg,
700 Item *sample_percentage)
701 : super(pos),
702 m_sampling_type(tablesample_type_arg),
703 m_sample_percentage(sample_percentage) {}
704};
705
706class PT_group : public Parse_tree_node {
708
711
712 protected:
713 void add_json_info(Json_object *obj) override {
714 if (olap == ROLLUP_TYPE)
715 obj->add_alias("olap_options", create_dom_ptr<Json_string>("ROLLUP"));
716 // Only rollup type supported.
717 }
718
719 public:
720 PT_group(const POS &pos, PT_order_list *group_list_arg, olap_type olap_arg)
721 : super(pos), group_list(group_list_arg), olap(olap_arg) {}
722
723 bool do_contextualize(Parse_context *pc) override;
724};
725
726class PT_order : public Parse_tree_node {
728
729 public:
731 explicit PT_order(const POS &pos, PT_order_list *order_list_arg)
732 : super(pos), order_list(order_list_arg) {}
733
734 bool do_contextualize(Parse_context *pc) override;
735};
736
738 public:
739 PT_locking_clause(const POS &pos, Lock_strength strength,
741 : Parse_tree_node(pos),
742 m_lock_strength(strength),
744
745 bool do_contextualize(Parse_context *pc) final;
746
747 virtual bool set_lock_for_tables(Parse_context *pc) = 0;
748
750
751 protected:
753 thr_lock_type lock_type = TL_IGNORE;
754 switch (m_lock_strength) {
756 lock_type = TL_WRITE;
757 break;
759 lock_type = TL_READ_WITH_SHARED_LOCKS;
760 break;
761 }
762
763 return {lock_type, static_cast<thr_locked_row_action>(action())};
764 }
765
766 private:
769};
770
772 public:
774 const POS &pos, Lock_strength strength,
776 : PT_locking_clause(pos, strength, action) {}
777
778 bool set_lock_for_tables(Parse_context *pc) override;
779};
780
782 public:
784
788 : PT_locking_clause(pos, strength, action), m_tables(tables) {}
789
790 bool set_lock_for_tables(Parse_context *pc) override;
791
792 private:
793 bool raise_error(THD *thd, const Table_ident *name, int error);
794
795 bool raise_error(int error);
796
798};
799
801 public:
803 : Parse_tree_node(pos) {
805 }
806
807 bool push_back(PT_locking_clause *locking_clause) {
808 return m_locking_clauses.push_back(locking_clause);
809 }
810
811 bool do_contextualize(Parse_context *pc) override {
812 for (auto locking_clause : m_locking_clauses)
813 if (locking_clause->contextualize(pc)) return true;
814 return false;
815 }
816
817 private:
819};
820
822 public:
823 explicit PT_query_expression_body(const POS &pos) : Parse_tree_node(pos) {}
824
825 virtual bool is_set_operation() const = 0;
826
827 /**
828 True if this query expression can absorb an extraneous order by/limit
829 clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
830 trailing clause may not refer to the tables in the `<query primary>`, with
831 one glaring exception:
832
833 (...( SELECT ... )...) ORDER BY ...
834
835 If the nested query expression doesn't contain `ORDER BY`, the statement
836 is interpreted as if the `ORDER BY` was absorbed by the innermost query
837 expression, i.e.:
838
839 (...( SELECT ... ORDER BY ... )...)
840
841 There is no rewriting of the parse tree nor AST happening here, the
842 transformation is done by the contextualizer (see
843 PT_query_expression::contextualize_order_and_limit), which interprets the
844 parse tree, and builds the AST according to this interpretation. This
845 interpretation is governed by the following rule: An `ORDER BY` can be
846 absorbed if none the nested query expressions contains an `ORDER BY` *or*
847 `LIMIT`. The rule is complex, so here are some examples for illustration:
848
849 In these cases the `ORDER BY` *is* absorbed:
850
851 ( SELECT * FROM t1 ) ORDER BY t1.a;
852 (( SELECT * FROM t1 )) ORDER BY t1.a;
853
854 In these cases the ORDER BY is *not* absorbed:
855
856 ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
857 (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
858 ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
859 (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
860
861 The same happens with `LIMIT`, obviously, but the optimizer is freeer to
862 choose when to apply the limit, and there are name no resolution issues
863 involved.
864
865 @param order True if the outer query block has the ORDER BY clause.
866 @param limit True if the outer query block has the LIMIT clause.
867 */
868 virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
869 virtual bool has_into_clause() const = 0;
870 virtual bool has_trailing_into_clause() const = 0;
871
872 virtual bool is_table_value_constructor() const = 0;
874};
875
878
879 public:
880 PT_set_scoped_system_variable(const POS &pos, const POS &var_pos,
881 const LEX_CSTRING &opt_prefix,
882 const LEX_CSTRING &name, Item *opt_expr)
883 : super(pos),
884 m_varpos(var_pos),
885 m_opt_prefix{opt_prefix},
886 m_name{name},
887 m_opt_expr{opt_expr} {}
888
889 bool do_contextualize(Parse_context *pc) override;
890
891 private:
896};
897
899 protected:
901 : Parse_tree_node(pos) {}
902};
903
906
907 public:
908 PT_set_variable(const POS &pos, const POS &varpos,
909 const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
910 const POS &expr_pos, Item *opt_expr)
911 : super{pos},
912 m_varpos{varpos},
913 m_opt_prefix{opt_prefix},
914 m_name{name},
915 m_expr_pos{expr_pos},
916 m_opt_expr{opt_expr} {}
917
918 bool do_contextualize(Parse_context *pc) override;
919
920 private:
926};
927
931
934
935 public:
937 const LEX_STRING &name_arg,
938 Item *expr_arg)
939 : super(pos), name(name_arg), expr(expr_arg) {}
940
941 bool do_contextualize(Parse_context *pc) override;
942};
943
946
947 public:
949 const POS &name_pos, const LEX_CSTRING &opt_prefix,
950 const LEX_CSTRING &name, Item *opt_expr)
951 : super(pos),
952 m_scope{scope},
953 m_name_pos{name_pos},
954 m_opt_prefix{opt_prefix},
955 m_name{name},
956 m_opt_expr{opt_expr} {}
957
958 bool do_contextualize(Parse_context *pc) override;
959
960 private:
966};
967
971
973
974 public:
976 const CHARSET_INFO *opt_charset_arg)
977 : super(pos), opt_charset(opt_charset_arg) {}
978
979 bool do_contextualize(Parse_context *pc) override;
980};
981
985
987
988 public:
990 const POS &error_pos)
991 : super(pos), m_error_pos(error_pos) {}
992
993 bool do_contextualize(Parse_context *pc) override;
994};
995
998
1001
1002 public:
1003 PT_set_names(const POS &pos, const CHARSET_INFO *opt_charset_arg,
1004 const CHARSET_INFO *opt_collation_arg)
1005 : super(pos),
1006 opt_charset(opt_charset_arg),
1007 opt_collation(opt_collation_arg) {}
1008
1009 bool do_contextualize(Parse_context *pc) override;
1010};
1011
1013 protected:
1014 explicit PT_start_option_value_list(const POS &pos) : Parse_tree_node(pos) {}
1015};
1016
1020
1021 const char *password;
1022 const char *current_password;
1026
1027 public:
1029 const char *password_arg,
1030 const char *current_password_arg,
1031 bool retain_current,
1032 bool random_password,
1033 const POS &expr_pos_arg)
1034 : super(pos),
1035 password(password_arg),
1036 current_password(current_password_arg),
1037 retain_current_password(retain_current),
1038 random_password_generator(random_password),
1039 expr_pos(expr_pos_arg) {}
1040
1041 bool do_contextualize(Parse_context *pc) override;
1042};
1043
1047
1049 const char *password;
1050 const char *current_password;
1054
1055 public:
1057 const POS &pos, LEX_USER *user_arg, const char *password_arg,
1058 const char *current_password_arg, bool retain_current, bool random_pass,
1059 const POS &expr_pos_arg)
1060 : super(pos),
1061 user(user_arg),
1062 password(password_arg),
1063 current_password(current_password_arg),
1064 retain_current_password(retain_current),
1065 random_password_generator(random_pass),
1066 expr_pos(expr_pos_arg) {}
1067
1068 bool do_contextualize(Parse_context *pc) override;
1069};
1070
1073
1076
1077 public:
1080 : super(pos), type(type_arg), value(value_arg) {}
1081
1082 bool do_contextualize(Parse_context *pc) override;
1083};
1084
1087
1091
1092 public:
1093 PT_option_value_list_head(const POS &pos, const POS &delimiter_pos_arg,
1094 Parse_tree_node *value_arg,
1095 const POS &value_pos_arg)
1096 : super(pos),
1097 delimiter_pos(delimiter_pos_arg),
1098 value(value_arg),
1099 value_pos(value_pos_arg) {}
1100
1101 bool do_contextualize(Parse_context *pc) override;
1102};
1103
1106
1108
1109 public:
1111 const POS &delimiter_pos_arg, Parse_tree_node *tail,
1112 const POS &tail_pos)
1113 : super(pos, delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
1114
1115 bool do_contextualize(Parse_context *pc) override {
1116 uchar dummy;
1117 if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
1118 return head->contextualize(pc) || super::do_contextualize(pc);
1119 }
1120};
1121
1124
1128
1129 public:
1132 const POS &head_pos_arg,
1133 PT_option_value_list_head *tail_arg)
1134 : super(pos), head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1135
1136 bool do_contextualize(Parse_context *pc) override;
1137};
1138
1141
1142 const char *name;
1144
1145 public:
1146 PT_transaction_characteristic(const POS &pos, const char *name_arg,
1147 int32 value_arg)
1148 : super(pos), name(name_arg), value(value_arg) {}
1149
1150 bool do_contextualize(Parse_context *pc) override;
1151};
1152
1155
1156 public:
1157 explicit PT_transaction_access_mode(const POS &pos, bool is_read_only)
1158 : super(pos, "transaction_read_only", (int32)is_read_only) {}
1159};
1160
1163
1164 public:
1165 explicit PT_isolation_level(const POS &pos, enum_tx_isolation level)
1166 : super(pos, "transaction_isolation", (int32)level) {}
1167};
1168
1171
1174
1175 public:
1178 PT_transaction_characteristic *opt_tail_arg)
1179 : super(pos), head(head_arg), opt_tail(opt_tail_arg) {}
1180
1181 bool do_contextualize(Parse_context *pc) override {
1182 return (super::do_contextualize(pc) || head->contextualize(pc) ||
1183 (opt_tail != nullptr && opt_tail->contextualize(pc)));
1184 }
1185};
1186
1190
1193
1194 public:
1196 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1197 const POS &end_pos_arg)
1198 : super(pos),
1199 characteristics(characteristics_arg),
1200 end_pos(end_pos_arg) {}
1201
1202 bool do_contextualize(Parse_context *pc) override;
1203};
1204
1206 : public Parse_tree_node {
1207 protected:
1209 : Parse_tree_node(pos) {}
1210};
1211
1215
1219
1220 public:
1222 const POS &pos, PT_set_scoped_system_variable *head_arg,
1223 const POS &head_pos_arg, PT_option_value_list_head *opt_tail_arg)
1224 : super(pos),
1225 head(head_arg),
1226 head_pos(head_pos_arg),
1227 opt_tail(opt_tail_arg) {}
1228
1229 bool do_contextualize(Parse_context *pc) override;
1230};
1231
1235
1238
1239 public:
1241 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1242 const POS &characteristics_pos_arg)
1243 : super(pos),
1244 characteristics(characteristics_arg),
1245 characteristics_pos(characteristics_pos_arg) {}
1246
1247 bool do_contextualize(Parse_context *pc) override;
1248};
1249
1252
1255
1256 public:
1258 const POS &pos, enum_var_type type_arg,
1260 : super(pos), type(type_arg), list(list_arg) {}
1261
1262 bool do_contextualize(Parse_context *pc) override;
1263};
1264
1265class PT_set : public Parse_tree_node {
1267
1270
1271 public:
1272 PT_set(const POS &pos, const POS &set_pos_arg,
1274 : super(pos), set_pos(set_pos_arg), list(list_arg) {}
1275
1276 bool do_contextualize(Parse_context *pc) override;
1277};
1278
1281
1282 protected:
1283 explicit PT_into_destination(const POS &pos) : super(pos) {}
1284
1285 public:
1286 bool do_contextualize(Parse_context *pc) override;
1287};
1288
1291
1292 public:
1293 PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1294 const CHARSET_INFO *charset_arg,
1295 const Field_separators &field_term_arg,
1296 const Line_separators &line_term_arg)
1297 : PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
1298 m_exchange.cs = charset_arg;
1299 m_exchange.field.merge_field_separators(field_term_arg);
1300 m_exchange.line.merge_line_separators(line_term_arg);
1301 }
1302
1303 bool do_contextualize(Parse_context *pc) override;
1304
1305 private:
1307};
1308
1311
1312 public:
1313 PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1314 : PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
1315
1316 bool do_contextualize(Parse_context *pc) override;
1317
1318 private:
1320};
1321
1323 public:
1325
1326 explicit PT_select_var(const POS &pos, const LEX_STRING &name_arg)
1327 : Parse_tree_node(pos), name(name_arg) {}
1328
1329 virtual bool is_local() const { return false; }
1330 virtual uint get_offset() const {
1331 assert(0);
1332 return 0;
1333 }
1334};
1335
1338
1339 uint offset = 0;
1340
1341#ifndef NDEBUG
1342 /*
1343 Routine to which this Item_splocal belongs. Used for checking if correct
1344 runtime context is used for variable handling.
1345 */
1346 sp_head *sp = nullptr;
1347#endif
1348
1349 public:
1350 PT_select_sp_var(const POS &pos, const LEX_STRING &name_arg)
1351 : super(pos, name_arg) {}
1352
1353 bool is_local() const override { return true; }
1354 uint get_offset() const override { return offset; }
1355
1356 bool do_contextualize(Parse_context *pc) override;
1357};
1358
1361
1362 public:
1363 explicit PT_select_var_list(const POS &pos) : PT_into_destination(pos) {}
1364
1366
1367 bool do_contextualize(Parse_context *pc) override;
1368
1369 bool push_back(PT_select_var *var) { return value.push_back(var); }
1370};
1371
1372/**
1373 Parse tree node for a single of a window extent's borders,
1374 cf. <window frame extent> in SQL 2003.
1375*/
1377 friend class Window;
1378 Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1379 public:
1381 const bool m_date_time;
1382 interval_type m_int_type = INTERVAL_LAST; // clang-tidy needs initialization.
1383
1384 ///< For unbounded border
1388 }
1389
1390 ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1392 : Parse_tree_node(pos),
1393 m_value(value),
1395 m_date_time(false) {}
1396
1397 ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1399 interval_type int_type)
1400 : Parse_tree_node(pos),
1401 m_value(value),
1403 m_date_time(true),
1404 m_int_type(int_type) {}
1405
1406 ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1407 Item *border() const { return m_value; }
1408 /// Need such low-level access so that fix_fields updates the right pointer
1409 Item **border_ptr() { return &m_value; }
1410
1411 /**
1412 @returns Addition operator for computation of frames, nullptr if error.
1413 @param order_expr Expression to add to/subtract from
1414 @param prec true if PRECEDING
1415 @param asc true if ASC
1416 @param window only used for error generation
1417 */
1418 Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1419 const Window *window);
1420
1421 bool do_contextualize(Parse_context *pc) override;
1422};
1423
1424/**
1425 Parse tree node for one or both of a window extent's borders, cf.
1426 <window frame extent> in SQL 2003.
1427*/
1430 friend class PT_frame;
1431
1432 public:
1433 /**
1434 Constructor.
1435
1436 Frames of the form "frame_start no_frame_end" are translated during
1437 parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1438 'end' are non-nullptr.
1439 */
1441 : Parse_tree_node(pos) {
1442 m_borders[0] = start;
1443 m_borders[1] = end;
1444 }
1445};
1446
1447/**
1448 Parse tree node for a window frame's exclusions, cf. the
1449 <window frame exclusion> clause in SQL 2003.
1450*/
1453
1454 public:
1456 : Parse_tree_node(pos), m_exclusion(e) {}
1457 // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1458};
1459
1460/**
1461 Parse tree node for a window's frame, cf. the <window frame clause>
1462 in SQL 2003.
1463*/
1465 public:
1467
1470
1472
1473 /// If true, this is an artificial frame, not specified by the user
1475
1476 PT_frame(const POS &pos, enum_window_frame_unit unit, PT_borders *from_to,
1477 PT_exclusion *exclusion)
1478 : Parse_tree_node(pos),
1479 m_query_expression(unit),
1480 m_from(from_to->m_borders[0]),
1481 m_to(from_to->m_borders[1]),
1482 m_exclusion(exclusion) {}
1483
1484 bool do_contextualize(Parse_context *pc) override;
1485};
1486
1488 protected:
1489 explicit PT_query_primary(const POS &pos) : PT_query_expression_body(pos) {}
1490};
1491
1494
1506
1507 public:
1509 const POS &pos, PT_hint_list *opt_hints_arg,
1510 const Query_options &options_arg, PT_item_list *item_list_arg,
1511 PT_into_destination *opt_into1_arg,
1512 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1513 Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1514 Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
1515 Item *opt_qualify_clause_arg, bool implicit_from_clause)
1516 : super(pos),
1517 opt_hints(opt_hints_arg),
1518 options(options_arg),
1519 item_list(item_list_arg),
1520 opt_into1(opt_into1_arg),
1521 m_is_from_clause_implicit{implicit_from_clause},
1522 from_clause(from_clause_arg),
1523 opt_where_clause(opt_where_clause_arg),
1524 opt_group_clause(opt_group_clause_arg),
1525 opt_having_clause(opt_having_clause_arg),
1526 opt_window_clause(opt_window_clause_arg),
1527 opt_qualify_clause(opt_qualify_clause_arg) {
1528 assert(implicit_from_clause ? from_clause.empty() : true);
1529 }
1530
1532 const POS &pos, const Query_options &options_arg,
1533 PT_item_list *item_list_arg,
1534 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1535 Item *opt_where_clause_arg)
1536 : super(pos),
1538 options(options_arg),
1539 item_list(item_list_arg),
1542 from_clause(from_clause_arg),
1543 opt_where_clause(opt_where_clause_arg),
1548
1549 PT_query_specification(const POS &pos, const Query_options &options_arg,
1550 PT_item_list *item_list_arg)
1551 : super(pos),
1553 options(options_arg),
1554 item_list(item_list_arg),
1557 from_clause{},
1563
1564 bool do_contextualize(Parse_context *pc) override;
1565
1566 bool has_into_clause() const override { return opt_into1 != nullptr; }
1567 bool has_trailing_into_clause() const override {
1569 opt_where_clause == nullptr && opt_group_clause == nullptr &&
1570 opt_having_clause == nullptr && opt_window_clause == nullptr &&
1571 opt_qualify_clause == nullptr);
1572 }
1573
1574 bool is_set_operation() const override { return false; }
1575
1576 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1577
1578 bool is_table_value_constructor() const override { return false; }
1579 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1580
1581 protected:
1582 void add_json_info(Json_object *obj) override;
1583
1584 private:
1586};
1587
1590
1592
1593 public:
1594 explicit PT_table_value_constructor(const POS &pos,
1595 PT_insert_values_list *row_value_list_arg)
1596 : super(pos), row_value_list(row_value_list_arg) {}
1597
1598 bool do_contextualize(Parse_context *pc) override;
1599
1600 bool has_into_clause() const override { return false; }
1601 bool has_trailing_into_clause() const override { return false; }
1602
1603 bool is_set_operation() const override { return false; }
1604
1605 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1606
1607 bool is_table_value_constructor() const override { return true; }
1608
1610 return row_value_list;
1611 }
1612};
1613
1616
1617 public:
1619 const POS &pos, const Query_options &options_arg,
1620 PT_item_list *item_list_arg,
1621 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1622 : super(pos, options_arg, item_list_arg, from_clause_arg, nullptr) {}
1623};
1624
1626 public:
1627 PT_query_expression(const POS &pos, PT_with_clause *with_clause,
1628 PT_query_expression_body *body, PT_order *order,
1629 PT_limit_clause *limit)
1631 m_body(body),
1632 m_order(order),
1633 m_limit(limit),
1634 m_with_clause(with_clause) {}
1635
1637 PT_order *order, PT_limit_clause *limit)
1638 : PT_query_expression(pos, nullptr, body, order, limit) {}
1639
1641 : PT_query_expression(pos, body, nullptr, nullptr) {}
1642
1643 bool do_contextualize(Parse_context *pc) override;
1644
1645 bool is_set_operation() const override { return m_body->is_set_operation(); }
1646
1647 bool has_into_clause() const override { return m_body->has_into_clause(); }
1648 bool has_trailing_into_clause() const override {
1649 return (m_body->has_trailing_into_clause() && m_order == nullptr &&
1650 m_limit == nullptr);
1651 }
1652
1653 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1654 if (m_body->is_set_operation()) {
1655 return false;
1656 }
1657 if (m_order == nullptr && m_limit == nullptr) {
1658 /*
1659 It is safe to push ORDER and/or LIMIT down in:
1660
1661 (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1662 (SELECT ...<no order or limit clauses>) ORDER BY ...;
1663 (SELECT ...<no order or limit clauses>) LIMIT ...;
1664 */
1665 return true;
1666 }
1667 if (m_limit != nullptr && !order && limit) {
1668 /*
1669 In MySQL, it is ok(*) to push LIMIT down in:
1670
1671 (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1672
1673 *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1674 `LIMIT b` if a < b. Moreover, the result of:
1675
1676 (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1677
1678 can diverge from:
1679
1680 (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1681
1682 since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1683 while the example (2) does overwrite.
1684
1685 TODO: add a warning, deprecate and replace this behavior with the
1686 standard one.
1687 */
1688 return true;
1689 }
1690 if (m_order != nullptr && m_limit == nullptr && !order && limit) {
1691 /*
1692 Allow pushdown of LIMIT into body with ORDER BY, e.g
1693
1694 (SELECT ... ORDER BY order1) LIMIT a;
1695 */
1696 return true;
1697 }
1698 return false;
1699 }
1700
1701 bool is_table_value_constructor() const override {
1703 }
1704
1706 return m_body->get_row_value_list();
1707 }
1708
1709 private:
1710 /**
1711 Contextualizes the order and limit clauses, re-interpreting them according
1712 to the rules. If the `<query expression body>` can absorb the clauses,
1713 they are simply contextualized into the current Query_block. If not, we
1714 have to create the "fake" Query_block unless there is one already
1715 (Query_expression::new_set_operation_query() is known to do this.)
1716
1717 @see PT_query_expression::can_absorb_order_and_limit()
1718 */
1720
1725};
1726
1727/*
1728 After the removal of the `... <locking_clause> <into_clause>` syntax
1729 PT_locking will disappear.
1730*/
1733
1734 public:
1736 PT_locking_clause_list *locking_clauses)
1737 : super(pos),
1739 m_locking_clauses{locking_clauses} {}
1740
1741 bool do_contextualize(Parse_context *pc) override {
1742 return (super::do_contextualize(pc) ||
1745 }
1746
1747 bool is_set_operation() const override {
1749 }
1750
1751 bool has_into_clause() const override {
1753 }
1754 bool has_trailing_into_clause() const override { return false; }
1755
1756 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1757 return m_query_expression->can_absorb_order_and_limit(order, limit);
1758 }
1759
1760 bool is_table_value_constructor() const override {
1762 }
1763
1766 }
1767
1768 private:
1771};
1772
1775
1778
1779 public:
1781
1782 PT_subquery(const POS &pos, PT_query_expression_body *query_expression)
1783 : super(pos),
1784 qe(query_expression),
1786 m_is_derived_table(false) {}
1787
1788 bool do_contextualize(Parse_context *pc) override;
1789
1791};
1792
1795
1796 public:
1798 bool is_distinct, PT_query_expression_body *rhs,
1799 bool is_rhs_in_parentheses = false)
1800 : super(pos),
1801 m_lhs(lhs),
1802 m_is_distinct(is_distinct),
1803 m_rhs(rhs),
1804 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {}
1805
1807 QueryLevel &ql);
1808 bool is_set_operation() const override { return true; }
1809
1810 bool has_into_clause() const override {
1812 }
1813 bool has_trailing_into_clause() const override {
1815 }
1816
1817 bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1818
1819 bool is_table_value_constructor() const override { return false; }
1820 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1821
1822 protected:
1824 Surrounding_context context);
1830
1831 void add_json_info(Json_object *obj) override {
1832 obj->add_alias("distinct", create_dom_ptr<Json_boolean>(m_is_distinct));
1833 obj->add_alias("rhs_in_parentheses",
1834 create_dom_ptr<Json_boolean>(m_is_rhs_in_parentheses));
1835 }
1836};
1837
1840
1841 public:
1843 bool do_contextualize(Parse_context *pc) override;
1844};
1845
1848
1849 public:
1851 bool do_contextualize(Parse_context *pc) override;
1852};
1853
1856
1857 public:
1859 bool do_contextualize(Parse_context *pc) override;
1860};
1861
1864
1865 public:
1866 /**
1867 @param pos Position of this clause in the SQL statement.
1868 @param qe The query expression.
1869 @param sql_command The type of SQL command.
1870 */
1871 PT_select_stmt(const POS &pos, enum_sql_command sql_command,
1873 : super(pos),
1874 m_sql_command(sql_command),
1875 m_qe(qe),
1876 m_into(nullptr),
1878
1879 /**
1880 Creates a SELECT command. Only SELECT commands can have into.
1881
1882 @param pos Position of this clause in the SQL
1883 statement.
1884 @param qe The query expression.
1885 @param into The own INTO destination.
1886 @param has_trailing_locking_clauses True if there are locking clauses (like
1887 `FOR UPDATE`) at the end of the
1888 statement.
1889 */
1891 PT_into_destination *into = nullptr,
1892 bool has_trailing_locking_clauses = false)
1893 : super(pos),
1895 m_qe{qe},
1896 m_into{into},
1897 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1898
1899 Sql_cmd *make_cmd(THD *thd) override;
1900 std::string get_printable_parse_tree(THD *thd) override;
1901
1902 private:
1907};
1908
1909/**
1910 Top-level node for the DELETE statement
1911
1912 @ingroup ptn_stmt
1913*/
1914class PT_delete final : public Parse_tree_root {
1916
1917 private:
1922 const char *const opt_table_alias;
1930
1931 public:
1932 // single-table DELETE node constructor:
1933 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1934 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1935 Table_ident *table_ident_arg,
1936 const LEX_CSTRING &opt_table_alias_arg,
1937 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1938 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1939 : super(pos),
1940 m_with_clause(with_clause_arg),
1941 opt_hints(opt_hints_arg),
1942 opt_delete_options(opt_delete_options_arg),
1943 table_ident(table_ident_arg),
1944 opt_table_alias(opt_table_alias_arg.str),
1945 opt_use_partition(opt_use_partition_arg),
1946 opt_where_clause(opt_where_clause_arg),
1947 opt_order_clause(opt_order_clause_arg),
1948 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1950 join_table_list.init_empty_const();
1951 }
1952
1953 // multi-table DELETE node constructor:
1954 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1955 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1956 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1957 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1958 Item *opt_where_clause_arg)
1959 : super(pos),
1960 m_with_clause(with_clause_arg),
1961 opt_hints(opt_hints_arg),
1962 opt_delete_options(opt_delete_options_arg),
1965 table_list(table_list_arg),
1967 join_table_list(join_table_list_arg),
1968 opt_where_clause(opt_where_clause_arg),
1971
1972 Sql_cmd *make_cmd(THD *thd) override;
1973
1974 private:
1975 bool is_multitable() const {
1976 assert((table_ident != nullptr) ^ (table_list.size() > 0));
1977 return table_ident == nullptr;
1978 }
1979
1981};
1982
1983/**
1984 Top-level node for the UPDATE statement
1985
1986 @ingroup ptn_stmt
1987*/
1990
2001
2002 public:
2003 PT_update(const POS &pos, PT_with_clause *with_clause_arg,
2004 PT_hint_list *opt_hints_arg, thr_lock_type opt_low_priority_arg,
2005 bool opt_ignore_arg,
2006 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
2007 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
2008 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
2009 Item *opt_limit_clause_arg)
2010 : super(pos),
2011 m_with_clause(with_clause_arg),
2012 opt_hints(opt_hints_arg),
2013 opt_low_priority(opt_low_priority_arg),
2014 opt_ignore(opt_ignore_arg),
2015 join_table_list(join_table_list_arg),
2016 column_list(column_list_arg),
2017 value_list(value_list_arg),
2018 opt_where_clause(opt_where_clause_arg),
2019 opt_order_clause(opt_order_clause_arg),
2020 opt_limit_clause(opt_limit_clause_arg) {}
2021
2022 Sql_cmd *make_cmd(THD *thd) override;
2023};
2024
2027
2029
2030 public:
2032 : super(pos), many_values(mem_root) {}
2033
2034 bool do_contextualize(Parse_context *pc) override;
2035
2037 many_values.push_back(x);
2038 return false;
2039 }
2040
2042 assert(is_contextualized());
2043 return many_values;
2044 }
2045};
2046
2047/**
2048 Top-level node for the INSERT statement
2049
2050 @ingroup ptn_stmt
2051*/
2052class PT_insert final : public Parse_tree_root {
2054
2055 const bool is_replace;
2058 const bool ignore;
2064 const char *const opt_values_table_alias;
2068
2069 public:
2070 PT_insert(const POS &pos, bool is_replace_arg, PT_hint_list *opt_hints_arg,
2071 thr_lock_type lock_option_arg, bool ignore_arg,
2072 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
2073 PT_item_list *column_list_arg,
2074 PT_insert_values_list *row_value_list_arg,
2075 PT_query_expression_body *insert_query_expression_arg,
2076 const LEX_CSTRING &opt_values_table_alias_arg,
2077 Create_col_name_list *opt_values_column_list_arg,
2078 PT_item_list *opt_on_duplicate_column_list_arg,
2079 PT_item_list *opt_on_duplicate_value_list_arg)
2080 : super(pos),
2081 is_replace(is_replace_arg),
2082 opt_hints(opt_hints_arg),
2083 lock_option(lock_option_arg),
2084 ignore(ignore_arg),
2085 table_ident(table_ident_arg),
2086 opt_use_partition(opt_use_partition_arg),
2087 column_list(column_list_arg),
2088 row_value_list(row_value_list_arg),
2089 insert_query_expression(insert_query_expression_arg),
2090 opt_values_table_alias(opt_values_table_alias_arg.str),
2091 opt_values_column_list(opt_values_column_list_arg),
2092 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
2093 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
2094 // REPLACE statement can't have IGNORE flag:
2095 assert(!is_replace || !ignore);
2096 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
2097 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
2098 // INSERT/REPLACE ... SELECT can't have VALUES clause:
2099 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
2100 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
2101 assert((opt_on_duplicate_column_list == nullptr &&
2102 opt_on_duplicate_value_list == nullptr) ||
2105 }
2106
2107 Sql_cmd *make_cmd(THD *thd) override;
2108
2109 private:
2110 bool has_query_block() const { return insert_query_expression != nullptr; }
2111};
2112
2113class PT_call final : public Parse_tree_root {
2116
2117 public:
2118 PT_call(const POS &pos, sp_name *proc_name_arg,
2119 PT_item_list *opt_expr_list_arg)
2120 : Parse_tree_root(pos),
2121 proc_name(proc_name_arg),
2122 opt_expr_list(opt_expr_list_arg) {}
2123
2124 Sql_cmd *make_cmd(THD *thd) override;
2125};
2126
2127/**
2128 Top-level node for the SHUTDOWN statement
2129
2130 @ingroup ptn_stmt
2131*/
2132class PT_shutdown final : public Parse_tree_root {
2134
2135 public:
2136 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
2137};
2138
2139/**
2140 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
2141
2142 @ingroup ptn_stmt
2143*/
2144class PT_create_srs final : public Parse_tree_root {
2145 /// The SQL command object.
2147 /// Whether OR REPLACE is specified.
2149 /// Whether IF NOT EXISTS is specified.
2151 /// SRID of the SRS to create.
2152 ///
2153 /// The range is larger than that of gis::srid_t, so it must be
2154 /// verified to be less than the uint32 maximum value.
2155 unsigned long long m_srid;
2156 /// All attributes except SRID.
2158
2159 /// Check if a UTF-8 string contains control characters.
2160 ///
2161 /// @note This function only checks single byte control characters (U+0000 to
2162 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
2163 /// that are not detected by this function.
2164 ///
2165 /// @param str The string.
2166 /// @param length Length of the string.
2167 ///
2168 /// @retval false The string contains no control characters.
2169 /// @retval true The string contains at least one control character.
2170 bool contains_control_char(char *str, size_t length) {
2171 for (size_t pos = 0; pos < length; pos++) {
2172 if (std::iscntrl(str[pos])) return true;
2173 }
2174 return false;
2175 }
2176
2177 public:
2178 PT_create_srs(const POS &pos, unsigned long long srid,
2179 const Sql_cmd_srs_attributes &attributes, bool or_replace,
2180 bool if_not_exists)
2181 : Parse_tree_root(pos),
2182 m_or_replace(or_replace),
2183 m_if_not_exists(if_not_exists),
2184 m_srid(srid),
2185 m_attributes(attributes) {}
2186
2187 Sql_cmd *make_cmd(THD *thd) override;
2188};
2189
2190/**
2191 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
2192
2193 @ingroup ptn_stmt
2194*/
2195class PT_drop_srs final : public Parse_tree_root {
2196 /// The SQL command object.
2198 /// SRID of the SRS to drop.
2199 ///
2200 /// The range is larger than that of gis::srid_t, so it must be
2201 /// verified to be less than the uint32 maximum value.
2202 unsigned long long m_srid;
2203
2204 public:
2205 PT_drop_srs(const POS &pos, unsigned long long srid, bool if_exists)
2206 : Parse_tree_root(pos), sql_cmd(srid, if_exists), m_srid(srid) {}
2207
2208 Sql_cmd *make_cmd(THD *thd) override;
2209};
2210
2211/**
2212 Top-level node for the ALTER INSTANCE statement
2213
2214 @ingroup ptn_stmt
2215*/
2218
2219 public:
2221 const POS &pos, enum alter_instance_action_enum alter_instance_action,
2222 const LEX_CSTRING &channel)
2223 : Parse_tree_root(pos), sql_cmd(alter_instance_action, channel) {}
2224
2225 Sql_cmd *make_cmd(THD *thd) override;
2226};
2227
2228/**
2229 A template-free base class for index options that we can predeclare in
2230 sql_lex.h
2231*/
2233 protected:
2234 explicit PT_base_index_option(const POS &pos) : Table_ddl_node(pos) {}
2235};
2236
2237/**
2238 A key part specification.
2239
2240 This can either be a "normal" key part (a key part that points to a column),
2241 or this can be a functional key part (a key part that points to an
2242 expression).
2243*/
2246
2247 public:
2248 /**
2249 Constructor for a functional key part.
2250
2251 @param pos Position of this clause in the SQL statement.
2252 @param expression The expression to index.
2253 @param order The direction of the index.
2254 */
2255 PT_key_part_specification(const POS &pos, Item *expression, enum_order order);
2256
2257 /**
2258 Constructor for a "normal" key part. That is a key part that points to a
2259 column and not an expression.
2260
2261 @param pos Position of this clause in the SQL statement.
2262 @param column_name The column name that this key part points to.
2263 @param order The direction of the index.
2264 @param prefix_length How many bytes or characters this key part should
2265 index, or zero if it should index the entire column.
2266 */
2267 PT_key_part_specification(const POS &pos, const LEX_CSTRING &column_name,
2268 enum_order order, int prefix_length);
2269
2270 /**
2271 Contextualize this key part specification. This will also call itemize on
2272 the indexed expression if this is a functional key part.
2273
2274 @param pc The parse context
2275
2276 @retval true on error
2277 @retval false on success
2278 */
2279 bool do_contextualize(Parse_context *pc) override;
2280
2281 /**
2282 Get the indexed expression. The caller must ensure that has_expression()
2283 returns true before calling this.
2284
2285 @returns The indexed expression
2286 */
2288 assert(has_expression());
2289 return m_expression;
2290 }
2291
2292 /**
2293 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2294 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2295 direction.
2296 */
2297 enum_order get_order() const { return m_order; }
2298
2299 /**
2300 @retval true if the user explicitly specified a direction (asc/desc).
2301 @retval false if the user didn't explicitly specify a direction.
2302 */
2303 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2304
2305 /**
2306 @retval true if the key part contains an expression (and thus is a
2307 functional key part).
2308 @retval false if the key part doesn't contain an expression.
2309 */
2310 bool has_expression() const { return m_expression != nullptr; }
2311
2312 /**
2313 Get the column that this key part points to. This is only valid if this
2314 key part isn't a functional index. The caller must thus check the return
2315 value of has_expression() before calling this function.
2316
2317 @returns The column that this key part points to.
2318 */
2320 assert(!has_expression());
2321 return m_column_name;
2322 }
2323
2324 /**
2325 @returns The number of bytes that this key part should index. If the column
2326 this key part points to is a non-binary column, this is the number
2327 of characters. Returns zero if the entire column should be indexed.
2328 */
2329 int get_prefix_length() const { return m_prefix_length; }
2330
2331 private:
2332 /**
2333 The indexed expression in case this is a functional key part. Only valid if
2334 has_expression() returns true.
2335 */
2337
2338 /// The direction of the index.
2340
2341 /// The name of the column that this key part indexes.
2343
2344 /**
2345 If this is greater than zero, it represents how many bytes of the column
2346 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2347 is the number of characters.
2348 */
2350};
2351
2352/**
2353 A template for options that set a single `<alter option>` value in
2354 thd->lex->key_create_info.
2355
2356 @tparam Option_type The data type of the option.
2357 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2358*/
2359template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2361 public:
2362 /// @param pos Position of this clause in the SQL statement.
2363 /// @param option_value The value of the option.
2364 PT_index_option(const POS &pos, Option_type option_value)
2365 : PT_base_index_option(pos), m_option_value(option_value) {}
2366
2369 return false;
2370 }
2371
2372 private:
2373 Option_type m_option_value;
2374};
2375
2376/**
2377 A template for options that set a single property in a KEY_CREATE_INFO, and
2378 also records if the option was explicitly set.
2379*/
2380template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2381 bool KEY_CREATE_INFO::*Property_is_explicit>
2383 public:
2384 PT_traceable_index_option(const POS &pos, Option_type option_value)
2385 : PT_base_index_option(pos), m_option_value(option_value) {}
2386
2389 pc->key_create_info->*Property_is_explicit = true;
2390 return false;
2391 }
2392
2393 private:
2394 Option_type m_option_value;
2395};
2396
2404
2405/**
2406 The data structure (B-tree, Hash, etc) used for an index is called
2407 'index_type' in the manual. Internally, this is stored in
2408 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2409 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2410 it's ignored. The terminology is somewhat confusing, but we stick to the
2411 manual in the parser.
2412*/
2416
2418 public:
2420 const LEX_STRING &name_arg, PT_base_index_option *type,
2421 Table_ident *table_ident,
2427 m_keytype(type_par),
2428 m_name(name_arg),
2429 m_type(type),
2430 m_table_ident(table_ident),
2431 m_columns(cols),
2433 m_algo(algo),
2434 m_lock(lock) {}
2435
2436 Sql_cmd *make_cmd(THD *thd) override;
2437
2438 private:
2447};
2448
2449/**
2450 Base class for column/constraint definitions in CREATE %TABLE
2451
2452 @ingroup ptn_create_table_stuff
2453*/
2455 protected:
2456 explicit PT_table_element(const POS &pos) : Table_ddl_node(pos) {}
2457};
2458
2460 protected:
2461 explicit PT_table_constraint_def(const POS &pos) : PT_table_element(pos) {}
2462};
2463
2466
2467 public:
2469 const LEX_STRING &name_arg,
2473 : super(pos),
2474 m_keytype(type_par),
2475 m_name(name_arg),
2476 m_type(type),
2477 m_columns(cols),
2478 m_options(options) {}
2479
2480 bool do_contextualize(Table_ddl_parse_context *pc) override;
2481
2482 private:
2488};
2489
2492
2493 public:
2494 PT_foreign_key_definition(const POS &pos, const LEX_STRING &constraint_name,
2495 const LEX_STRING &key_name,
2497 Table_ident *referenced_table,
2498 List<Key_part_spec> *ref_list,
2499 fk_match_opt fk_match_option,
2500 fk_option fk_update_opt, fk_option fk_delete_opt)
2501 : super(pos),
2502 m_constraint_name(constraint_name),
2503 m_key_name(key_name),
2504 m_columns(columns),
2505 m_referenced_table(referenced_table),
2506 m_ref_list(ref_list),
2507 m_fk_match_option(fk_match_option),
2508 m_fk_update_opt(fk_update_opt),
2509 m_fk_delete_opt(fk_delete_opt) {}
2510
2511 bool do_contextualize(Table_ddl_parse_context *pc) override;
2512
2513 void set_column_name(const LEX_STRING &column_name) {
2514 m_column_name = column_name;
2515 }
2516
2517 private:
2526
2527 // Column name. Set when FK is specified at the column level.
2529};
2530
2531/**
2532 Common base class for CREATE TABLE and ALTER TABLE option nodes
2533
2534 @ingroup ptn_create_or_alter_table_options
2535*/
2537 protected:
2538 explicit PT_ddl_table_option(const POS &pos) : Table_ddl_node(pos) {}
2539
2540 public:
2541 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2542
2543 virtual bool is_rename_table() const { return false; }
2544};
2545
2547
2548/**
2549 Base class for CREATE TABLE option nodes
2550
2551 @ingroup ptn_create_or_alter_table_options
2552*/
2555
2556 protected:
2557 explicit PT_create_table_option(const POS &pos) : super(pos) {}
2558
2559 public:
2560 ~PT_create_table_option() override = 0; // Force abstract class declaration
2561
2563 if (super::do_contextualize(pc)) return true;
2565 return false;
2566 }
2567};
2568
2570
2571/**
2572 A template for options that set a single property in HA_CREATE_INFO, and
2573 also records if the option was explicitly set.
2574*/
2575template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2576 uint64_t Property_flag>
2579
2580 const Option_type value;
2581
2582 public:
2583 explicit PT_traceable_create_table_option(const POS &pos, Option_type value)
2584 : super(pos), value(value) {}
2585
2587 if (super::do_contextualize(pc)) return true;
2588 pc->create_info->*Property = value;
2589 pc->create_info->used_fields |= Property_flag;
2590 return false;
2591 }
2592};
2593
2594#define TYPE_AND_REF(x) decltype(x), &x
2595
2596/**
2597 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2598
2599 @ingroup ptn_create_or_alter_table_options
2600*/
2604
2605/**
2606 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2607
2608 @ingroup ptn_create_or_alter_table_options
2609*/
2613
2614/**
2615 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2616
2617 @ingroup ptn_create_or_alter_table_options
2618*/
2622
2623/**
2624 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2625
2626 @ingroup ptn_create_or_alter_table_options
2627*/
2631
2632/**
2633 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2634
2635 @ingroup ptn_create_or_alter_table_options
2636*/
2640
2641/**
2642 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2643
2644 @ingroup ptn_create_or_alter_table_options
2645*/
2649
2650/**
2651 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2652
2653 @ingroup ptn_create_or_alter_table_options
2654*/
2658
2659/**
2660 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2661
2662 @ingroup ptn_create_or_alter_table_options
2663*/
2667
2671
2676
2680
2684
2688
2692
2696
2701
2706
2708
2709/**
2710 A template for options that set HA_CREATE_INFO::table_options and
2711 also records if the option was explicitly set.
2712*/
2713template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2714 table_options_t No>
2717
2719
2720 public:
2722 : super(pos), value(value) {}
2723
2725 if (super::do_contextualize(pc)) return true;
2726 pc->create_info->table_options &= ~(Yes | No);
2727 switch (value) {
2728 case Ternary_option::ON:
2729 pc->create_info->table_options |= Yes;
2730 break;
2732 pc->create_info->table_options |= No;
2733 break;
2735 break;
2736 default:
2737 assert(false);
2738 }
2739 pc->create_info->used_fields |= Property_flag;
2740 return false;
2741 }
2742};
2743
2744/**
2745 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2746
2747 @ingroup ptn_create_or_alter_table_options
2748
2749 PACK_KEYS | Constructor parameter
2750 ----------|----------------------
2751 1 | Ternary_option::ON
2752 0 | Ternary_option::OFF
2753 DEFAULT | Ternary_option::DEFAULT
2754*/
2756 0, // DEFAULT
2757 HA_OPTION_PACK_KEYS, // ON
2760
2761/**
2762 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2763
2764 @ingroup ptn_create_or_alter_table_options
2765
2766 STATS_PERSISTENT | Constructor parameter
2767 -----------------|----------------------
2768 1 | Ternary_option::ON
2769 0 | Ternary_option::OFF
2770 DEFAULT | Ternary_option::DEFAULT
2771*/
2773 0, // DEFAULT
2777
2778/**
2779 A template for options that set HA_CREATE_INFO::table_options and
2780 also records if the option was explicitly set.
2781*/
2782template <ulong Property_flag, table_options_t Yes, table_options_t No>
2785
2786 const bool value;
2787
2788 public:
2789 explicit PT_bool_create_table_option(const POS &pos, bool value)
2790 : super(pos), value(value) {}
2791
2793 if (super::do_contextualize(pc)) return true;
2794 pc->create_info->table_options &= ~(Yes | No);
2795 pc->create_info->table_options |= value ? Yes : No;
2796 pc->create_info->used_fields |= Property_flag;
2797 return false;
2798 }
2799};
2800
2801/**
2802 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2803
2804 @ingroup ptn_create_or_alter_table_options
2805
2806 TABLE_CHECKSUM | Constructor parameter
2807 ---------------|----------------------
2808 0 | false
2809 not 0 | true
2810*/
2812 HA_OPTION_CHECKSUM, // ON
2814 >
2816
2817/**
2818 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2819
2820 @ingroup ptn_create_or_alter_table_options
2821
2822 TABLE_CHECKSUM | Constructor parameter
2823 ---------------|----------------------
2824 0 | false
2825 not 0 | true
2826*/
2831
2832/**
2833 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2834
2835 @ingroup ptn_create_or_alter_table_options
2836*/
2839
2841
2842 public:
2843 /**
2844 @param pos Position of this clause in the SQL statement.
2845 @param engine Storage engine name.
2846 */
2848 const LEX_CSTRING &engine)
2849 : super(pos), engine(engine) {}
2850
2851 bool do_contextualize(Table_ddl_parse_context *pc) override;
2852};
2853
2854/**
2855 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2856 table option.
2857
2858 @ingroup ptn_create_or_alter_table_options
2859*/
2862
2863 public:
2865 : super(pos) {}
2867 const POS &pos, const LEX_CSTRING &secondary_engine)
2869
2870 bool do_contextualize(Table_ddl_parse_context *pc) override;
2871
2872 private:
2874};
2875
2876/**
2877 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2878
2879 @ingroup ptn_create_or_alter_table_options
2880*/
2883
2885
2886 public:
2887 /**
2888 @param pos Position of this clause in the SQL statement.
2889 @param value
2890 STATS_AUTO_RECALC | value
2891 ------------------|----------------------
2892 1 | Ternary_option::ON
2893 0 | Ternary_option::OFF
2894 DEFAULT | Ternary_option::DEFAULT
2895 */
2897 : super(pos), value(value) {}
2898
2899 bool do_contextualize(Table_ddl_parse_context *pc) override;
2900};
2901
2902/**
2903 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2904
2905 @ingroup ptn_create_or_alter_table_options
2906*/
2910
2912
2913 public:
2914 /**
2915 Constructor for implicit number of pages
2916
2917 @param pos Position of this clause in the SQL statement.
2918 @param value Number of pages, 1@<=N@<=65535.
2919 */
2921 : super(pos), value(value) {
2922 assert(value != 0 && value <= 0xFFFF);
2923 }
2924 /**
2925 Constructor for the DEFAULT number of pages
2926 */
2928 : super(pos), value(0) {} // DEFAULT
2929
2930 bool do_contextualize(Table_ddl_parse_context *pc) override;
2931};
2932
2935
2937
2938 public:
2939 explicit PT_create_union_option(const POS &pos,
2941 : super(pos), tables(tables) {}
2942
2943 bool do_contextualize(Table_ddl_parse_context *pc) override;
2944};
2945
2948
2950
2951 public:
2953 : super(pos), value(value) {}
2954
2956 if (super::do_contextualize(pc)) return true;
2958 return false;
2959 }
2960};
2961
2964
2966
2967 public:
2969 const CHARSET_INFO *value)
2970 : super(pos), value(value) {
2971 assert(value != nullptr);
2972 }
2973
2974 bool do_contextualize(Table_ddl_parse_context *pc) override;
2975};
2976
2979
2981
2982 public:
2984 const CHARSET_INFO *value)
2985 : super(pos), value(value) {
2986 assert(value != nullptr);
2987 }
2988
2989 bool do_contextualize(Table_ddl_parse_context *pc) override;
2990};
2991
2995
2996 public:
2997 explicit PT_check_constraint(const POS &pos, LEX_STRING &name, Item *expr,
2998 bool is_enforced)
2999 : super(pos) {
3000 cc_spec.name = name;
3001 cc_spec.check_expr = expr;
3002 cc_spec.is_enforced = is_enforced;
3003 }
3004
3005 bool do_contextualize(Table_ddl_parse_context *pc) override;
3006};
3007
3010
3014
3015 const char *opt_place;
3016
3017 public:
3021 const char *opt_place = nullptr)
3022 : super(pos),
3027
3028 bool do_contextualize(Table_ddl_parse_context *pc) override;
3029};
3030
3031/**
3032 Top-level node for the CREATE %TABLE statement
3033
3034 @ingroup ptn_create_table
3035*/
3046
3048
3049 public:
3050 /**
3051 @param pos Position of this clause in the SQL
3052 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_table_element_list NULL or a list of table column and
3058 constraint definitions.
3059 @param opt_create_table_options NULL or a list of
3060 @ref ptn_create_or_alter_table_options
3061 "table options".
3062 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
3063 @param on_duplicate DUPLICATE, IGNORE or fail with an error
3064 on data duplication errors (relevant
3065 for @SQL{CREATE TABLE ... SELECT}
3066 statements).
3067 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
3068 */
3070 const POS &pos, MEM_ROOT *mem_root, bool is_temporary,
3086 /**
3087 @param pos Position of this clause in the SQL statement.
3088 @param mem_root MEM_ROOT to use for allocation
3089 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
3090 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
3091 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
3092 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
3093 */
3107
3108 Sql_cmd *make_cmd(THD *thd) override;
3109};
3110
3111class PT_create_role final : public Parse_tree_root {
3113
3114 public:
3115 PT_create_role(const POS &pos, bool if_not_exists,
3116 const List<LEX_USER> *roles)
3117 : Parse_tree_root(pos), sql_cmd(if_not_exists, roles) {}
3118
3119 Sql_cmd *make_cmd(THD *thd) override;
3120};
3121
3122class PT_drop_role final : public Parse_tree_root {
3124
3125 public:
3126 explicit PT_drop_role(const POS &pos, bool ignore_errors,
3127 const List<LEX_USER> *roles)
3128 : Parse_tree_root(pos), sql_cmd(ignore_errors, roles) {}
3129
3130 Sql_cmd *make_cmd(THD *thd) override;
3131};
3132
3135
3136 public:
3137 explicit PT_set_role(const POS &pos, role_enum role_type,
3138 const List<LEX_USER> *opt_except_roles = nullptr)
3139 : Parse_tree_root(pos), sql_cmd(role_type, opt_except_roles) {
3140 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
3141 }
3142 explicit PT_set_role(const POS &pos, const List<LEX_USER> *roles)
3143 : Parse_tree_root(pos), sql_cmd(roles) {}
3144
3145 Sql_cmd *make_cmd(THD *thd) override;
3146};
3147
3148/**
3149 This class is used for representing both static and dynamic privileges on
3150 global as well as table and column level.
3151*/
3154
3157
3160 : type(type), columns(columns) {}
3161};
3162
3164 const uint grant;
3165
3167 : Privilege(STATIC, columns_arg), grant(grant) {}
3168};
3169
3172
3174 const Mem_root_array<LEX_CSTRING> *columns_arg)
3175 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
3176};
3177
3179 private:
3181
3182 public:
3183 explicit PT_role_or_privilege(const POS &pos, const POS &errpos)
3184 : Parse_tree_node(pos), m_errpos(errpos) {}
3185 virtual LEX_USER *get_user(THD *thd);
3186 virtual Privilege *get_privilege(THD *thd);
3187};
3188
3192
3193 public:
3194 PT_role_at_host(const POS &pos, const POS &errpos, const LEX_STRING &role,
3195 const LEX_STRING &host)
3196 : PT_role_or_privilege(pos, errpos), role(role), host(host) {}
3197
3198 LEX_USER *get_user(THD *thd) override;
3199};
3200
3203
3204 public:
3205 PT_role_or_dynamic_privilege(const POS &pos, const POS &errpos,
3206 const LEX_STRING &ident)
3207 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3208
3209 LEX_USER *get_user(THD *thd) override;
3210 Privilege *get_privilege(THD *thd) override;
3211};
3212
3214 const uint grant;
3216
3217 public:
3218 PT_static_privilege(const POS &pos, const POS &errpos, uint grant,
3219 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
3220 : PT_role_or_privilege(pos, errpos), grant(grant), columns(columns) {}
3221
3222 Privilege *get_privilege(THD *thd) override;
3223};
3224
3227
3228 public:
3229 PT_dynamic_privilege(const POS &pos, const POS &errpos,
3230 const LEX_STRING &ident)
3231 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3232
3233 Privilege *get_privilege(THD *thd) override;
3234};
3235
3236class PT_grant_roles final : public Parse_tree_root {
3240
3241 public:
3245 : Parse_tree_root(pos),
3246 roles(roles),
3247 users(users),
3249
3250 Sql_cmd *make_cmd(THD *thd) override;
3251};
3252
3253class PT_revoke_roles final : public Parse_tree_root {
3256
3257 public:
3259 const List<LEX_USER> *users)
3260 : Parse_tree_root(pos), roles(roles), users(users) {}
3261
3262 Sql_cmd *make_cmd(THD *thd) override;
3263};
3264
3267
3268 public:
3269 PT_alter_user_default_role(const POS &pos, bool if_exists,
3270 const List<LEX_USER> *users,
3271 const List<LEX_USER> *roles,
3272 const role_enum role_type)
3273 : Parse_tree_root(pos), sql_cmd(if_exists, users, roles, role_type) {}
3274
3275 Sql_cmd *make_cmd(THD *thd) override;
3276};
3277
3278/// Base class for Parse tree nodes of SHOW statements
3279
3281 protected:
3282 PT_show_base(const POS &pos, enum_sql_command sql_command)
3283 : Parse_tree_root(pos), m_sql_command(sql_command) {}
3284
3285 /// SQL command
3287};
3288
3289/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3290
3292 protected:
3294 const LEX_STRING &wild, Item *where)
3295 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3296 assert(m_wild.str == nullptr || m_where == nullptr);
3297 }
3298 /// Wild or where clause used in the statement.
3301};
3302
3303/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3304
3306 protected:
3308 char *opt_db, const LEX_STRING &wild, Item *where)
3309 : PT_show_base(pos, sql_command),
3311 m_wild(wild),
3312 m_where(where) {
3313 assert(m_wild.str == nullptr || m_where == nullptr);
3314 }
3315 /// Optional schema name in FROM/IN clause.
3317 /// Wild or where clause used in the statement.
3320};
3321
3322/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3323
3325 protected:
3326 PT_show_table_base(const POS &pos, enum_sql_command sql_command,
3327 Table_ident *table_ident, const LEX_STRING &wild,
3328 Item *where)
3329 : PT_show_filter_base(pos, sql_command, wild, where),
3330 m_table_ident(table_ident) {}
3331
3332 bool make_table_base_cmd(THD *thd, bool *temporary);
3333
3334 /// Table used in the statement.
3336};
3337
3338/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3339
3341 protected:
3343 const sp_name *routine_name)
3344 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3345
3346 Sql_cmd *make_cmd(THD *thd) override;
3347
3348 private:
3350};
3351
3352/// Parse tree node for SHOW BINLOG EVENTS statement
3353
3355 public:
3356 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3357 PT_limit_clause *opt_limit_clause = nullptr)
3359 m_opt_log_file_name(opt_log_file_name),
3360 m_opt_limit_clause(opt_limit_clause) {}
3361
3362 Sql_cmd *make_cmd(THD *thd) override;
3363
3364 private:
3367
3369};
3370
3371/// Parse tree node for SHOW BINLOGS statement
3372
3373class PT_show_binlogs final : public PT_show_base {
3374 public:
3376
3377 Sql_cmd *make_cmd(THD *thd) override;
3378
3379 private:
3381};
3382
3383/// Parse tree node for SHOW CHARACTER SET statement
3384
3386 public:
3387 PT_show_charsets(const POS &pos, const LEX_STRING &wild, Item *where)
3389
3390 Sql_cmd *make_cmd(THD *thd) override;
3391
3392 private:
3394};
3395
3396/// Parse tree node for SHOW COLLATIONS statement
3397
3399 public:
3400 PT_show_collations(const POS &pos, const LEX_STRING &wild, Item *where)
3402
3403 Sql_cmd *make_cmd(THD *thd) override;
3404
3405 private:
3407};
3408
3409/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3410/// statements.
3411
3413 public:
3414 explicit PT_show_count_base(const POS &pos)
3415 : PT_show_base{pos, SQLCOM_SELECT} {}
3416
3417 protected:
3418 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3419};
3420
3421/// Parse tree node for SHOW COUNT(*) ERRORS
3422
3424 public:
3425 explicit PT_show_count_errors(const POS &pos) : PT_show_count_base(pos) {}
3426
3427 Sql_cmd *make_cmd(THD *thd) override {
3428 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3429 }
3430};
3431
3432/// Parse tree node for SHOW COUNT(*) WARNINGS
3433
3435 public:
3436 explicit PT_show_count_warnings(const POS &pos) : PT_show_count_base(pos) {}
3437
3438 Sql_cmd *make_cmd(THD *thd) override {
3439 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3440 }
3441};
3442
3443/// Parse tree node for SHOW CREATE DATABASE statement
3444
3446 public:
3447 PT_show_create_database(const POS &pos, bool if_not_exists,
3448 const LEX_STRING &name)
3450 m_if_not_exists(if_not_exists),
3451 m_name(name) {}
3452
3453 Sql_cmd *make_cmd(THD *thd) override;
3454
3455 private:
3458
3460};
3461
3462/// Parse tree node for SHOW CREATE EVENT statement
3463
3465 public:
3466 PT_show_create_event(const POS &pos, sp_name *event_name)
3467 : PT_show_base(pos, SQLCOM_SHOW_CREATE_EVENT), m_spname(event_name) {}
3468
3469 Sql_cmd *make_cmd(THD *thd) override;
3470
3471 private:
3473
3475};
3476
3477/// Parse tree node for SHOW CREATE FUNCTION statement
3478
3480 public:
3481 PT_show_create_function(const POS &pos, sp_name *function_name)
3482 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3483
3484 Sql_cmd *make_cmd(THD *thd) override;
3485
3486 private:
3488
3490};
3491
3492/// Parse tree node for SHOW CREATE PROCEDURE statement
3493
3495 public:
3496 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3497 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3498
3499 Sql_cmd *make_cmd(THD *thd) override;
3500
3501 private:
3503
3505};
3506
3507/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3508
3510 public:
3511 PT_show_create_table(const POS &pos, Table_ident *table_ident)
3512 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3513
3514 Sql_cmd *make_cmd(THD *thd) override;
3515
3516 private:
3518};
3519
3520/// Parse tree node for SHOW CREATE TRIGGER statement
3521
3523 public:
3524 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3525 : PT_show_base(pos, SQLCOM_SHOW_CREATE_TRIGGER), m_spname(trigger_name) {}
3526
3527 Sql_cmd *make_cmd(THD *thd) override;
3528
3529 private:
3531
3533};
3534
3535/// Parse tree node for SHOW CREATE USER statement
3536
3537class PT_show_create_user final : public PT_show_base {
3538 public:
3541
3542 Sql_cmd *make_cmd(THD *thd) override;
3543
3544 private:
3546
3548};
3549
3550/// Parse tree node for SHOW CREATE VIEW statement
3551
3552class PT_show_create_view final : public PT_show_base {
3553 public:
3554 PT_show_create_view(const POS &pos, Table_ident *table_ident)
3555 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3556
3557 Sql_cmd *make_cmd(THD *thd) override;
3558
3559 private:
3561};
3562
3563/// Parse tree node for SHOW DATABASES statement
3564
3566 public:
3567 PT_show_databases(const POS &pos, const LEX_STRING &wild, Item *where)
3569
3570 Sql_cmd *make_cmd(THD *thd) override;
3571
3572 private:
3574};
3575
3576/// Parse tree node for SHOW ENGINE statements
3577
3579 protected:
3580 PT_show_engine_base(const POS &pos, enum enum_sql_command sql_command,
3581 const LEX_STRING opt_engine = {})
3582 : PT_show_base(pos, sql_command),
3583 m_engine(opt_engine),
3584 m_all(opt_engine.str == nullptr) {}
3585
3587 bool m_all;
3588};
3589
3590/// Parse tree node for SHOW ENGINE LOGS statement
3591
3593 public:
3594 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3595 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_LOGS, opt_engine) {}
3596
3597 Sql_cmd *make_cmd(THD *thd) override;
3598
3599 private:
3601};
3602
3603/// Parse tree node for SHOW ENGINE MUTEX statement
3604
3606 public:
3607 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3608 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_MUTEX, opt_engine) {}
3609
3610 Sql_cmd *make_cmd(THD *thd) override;
3611
3612 private:
3614};
3615
3616/// Parse tree node for SHOW ENGINE STATUS statement
3617
3619 public:
3620 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3621 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_STATUS, opt_engine) {}
3622
3623 Sql_cmd *make_cmd(THD *thd) override;
3624
3625 private:
3627};
3628
3629/// Parse tree node for SHOW ENGINES statement
3630
3631class PT_show_engines final : public PT_show_base {
3632 public:
3635
3636 Sql_cmd *make_cmd(THD *thd) override;
3637
3638 private:
3640};
3641
3642/// Parse tree node for SHOW ERRORS statement
3643
3644class PT_show_errors final : public PT_show_base {
3645 public:
3646 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3648 m_opt_limit_clause(opt_limit_clause) {}
3649
3650 Sql_cmd *make_cmd(THD *thd) override;
3651
3652 private:
3654
3656};
3657
3658/// Parse tree node for SHOW EVENTS statement
3659
3661 public:
3662 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3663 Item *where)
3665
3666 Sql_cmd *make_cmd(THD *thd) override;
3667
3668 private:
3670};
3671
3672/// Parse tree node for SHOW COLUMNS statement.
3673
3676
3677 public:
3678 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3679 Table_ident *table, LEX_STRING opt_wild = {},
3680 Item *opt_where = nullptr)
3681 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3682 m_show_cmd_type(show_cmd_type) {}
3683
3684 Sql_cmd *make_cmd(THD *thd) override;
3685
3686 private:
3689};
3690
3691/// Parse tree node for SHOW FUNCTION CODE statement.
3692
3694 public:
3695 PT_show_function_code(const POS &pos, const sp_name *function_name)
3696 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3697};
3698
3699/// Parse tree node for SHOW GRANTS statement.
3700
3701class PT_show_grants final : public PT_show_base {
3702 public:
3703 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3704 const List<LEX_USER> *opt_using_users)
3706 sql_cmd(opt_for_user, opt_using_users) {
3707 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3708 }
3709
3710 Sql_cmd *make_cmd(THD *thd) override;
3711
3712 private:
3714};
3715
3716/// Parse tree node for SHOW INDEX statement.
3717
3718class PT_show_keys final : public PT_show_table_base {
3719 public:
3720 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3721 Item *where)
3723 m_extended_show(extended_show) {}
3724
3725 Sql_cmd *make_cmd(THD *thd) override;
3726
3727 private:
3729
3730 // Flag to indicate EXTENDED keyword usage in the statement.
3733};
3734
3735/// Parse tree node for SHOW BINARY LOG STATUS statement
3736
3738 public:
3741
3742 Sql_cmd *make_cmd(THD *thd) override;
3743
3744 private:
3746};
3747
3748/// Parse tree node for SHOW OPEN TABLES statement
3749
3751 public:
3752 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3753 Item *where)
3755 }
3756
3757 Sql_cmd *make_cmd(THD *thd) override;
3758
3759 private:
3761};
3762
3763/// Parse tree node for SHOW PLUGINS statement
3764
3765class PT_show_plugins final : public PT_show_base {
3766 public:
3768
3769 Sql_cmd *make_cmd(THD *thd) override;
3770
3771 private:
3773};
3774
3775/// Parse tree node for SHOW PRIVILEGES statement
3776
3777class PT_show_privileges final : public PT_show_base {
3778 public:
3781
3782 Sql_cmd *make_cmd(THD *thd) override;
3783
3784 private:
3786};
3787
3788/// Parse tree node for SHOW PARSE_TREE statement
3789
3790class PT_show_parse_tree final : public PT_show_base {
3791 public:
3792 PT_show_parse_tree(const POS &pos, Parse_tree_root *parse_tree_stmt)
3794 m_parse_tree_stmt(parse_tree_stmt) {}
3795
3796 Sql_cmd *make_cmd(THD *thd) override;
3797
3798 private:
3801};
3802
3803/// Parse tree node for SHOW FUNCTION CODE statement.
3804
3806 public:
3807 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3808 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3809};
3810
3811/// Parse tree node for SHOW PROCESSLIST statement
3812
3813class PT_show_processlist final : public PT_show_base {
3814 public:
3817
3818 Sql_cmd *make_cmd(THD *thd) override;
3819
3820 private:
3822};
3823
3824/// Parse tree node for SHOW PROFILE statement
3825
3826class PT_show_profile final : public PT_show_base {
3827 public:
3828 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3829 my_thread_id opt_query_id = 0,
3830 PT_limit_clause *opt_limit_clause = nullptr)
3832 m_opt_profile_options(opt_profile_options),
3833 m_opt_query_id(opt_query_id),
3834 m_opt_limit_clause(opt_limit_clause) {}
3835
3836 Sql_cmd *make_cmd(THD *thd) override;
3837
3838 private:
3842
3844};
3845
3846/// Parse tree node for SHOW PROFILES statement
3847
3848class PT_show_profiles final : public PT_show_base {
3849 public:
3851
3852 Sql_cmd *make_cmd(THD *thd) override;
3853
3854 private:
3856};
3857
3858/// Parse tree node for SHOW RELAYLOG EVENTS statement
3859
3861 public:
3863 const LEX_STRING opt_log_file_name = {},
3864 PT_limit_clause *opt_limit_clause = nullptr,
3865 LEX_CSTRING opt_channel_name = {})
3867 m_opt_log_file_name(opt_log_file_name),
3868 m_opt_limit_clause(opt_limit_clause),
3869 m_opt_channel_name(opt_channel_name) {}
3870
3871 Sql_cmd *make_cmd(THD *thd) override;
3872
3873 private:
3877
3879};
3880
3881/// Parse tree node for SHOW REPLICAS statement
3882
3883class PT_show_replicas final : public PT_show_base {
3884 public:
3886
3887 Sql_cmd *make_cmd(THD *thd) override;
3888
3889 private:
3891};
3892
3893/// Parse tree node for SHOW REPLICA STATUS statement
3894
3896 public:
3897 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3899 m_opt_channel_name(opt_channel_name) {}
3900
3901 Sql_cmd *make_cmd(THD *thd) override;
3902
3903 private:
3905
3907};
3908
3909/// Parse tree node for SHOW STATUS statement
3910
3912 public:
3913 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3914 Item *where)
3916 m_var_type(var_type) {
3918 }
3919
3920 Sql_cmd *make_cmd(THD *thd) override;
3921
3922 private:
3924
3926};
3927
3928/// Parse tree node for SHOW STATUS FUNCTION statement
3929
3931 public:
3932 PT_show_status_func(const POS &pos, const LEX_STRING &wild, Item *where)
3934
3935 Sql_cmd *make_cmd(THD *thd) override;
3936
3937 private:
3939};
3940
3941/// Parse tree node for SHOW STATUS PROCEDURE statement
3942
3944 public:
3945 PT_show_status_proc(const POS &pos, const LEX_STRING &wild, Item *where)
3947
3948 Sql_cmd *make_cmd(THD *thd) override;
3949
3950 private:
3952};
3953
3954/// Parse tree node for SHOW TABLE STATUS statement
3955
3957 public:
3958 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
3959 Item *where)
3961 where) {}
3962
3963 Sql_cmd *make_cmd(THD *thd) override;
3964
3965 private:
3967};
3968
3969/// Parse tree node for SHOW TABLES statement
3970
3972 public:
3973 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
3974 const LEX_STRING &wild, Item *where)
3976 m_show_cmd_type(show_cmd_type) {}
3977
3978 Sql_cmd *make_cmd(THD *thd) override;
3979
3980 private:
3982
3984};
3985
3986/// Parse tree node for SHOW TRIGGERS statement
3987
3989 public:
3990 PT_show_triggers(const POS &pos, bool full, char *opt_db,
3991 const LEX_STRING &wild, Item *where)
3993 m_full(full) {}
3994
3995 Sql_cmd *make_cmd(THD *thd) override;
3996
3997 private:
3999
4001};
4002
4003/// Parse tree node for SHOW VARIABLES statement
4004
4006 public:
4008 const LEX_STRING &wild, Item *where)
4010 m_var_type(var_type) {
4012 }
4013
4014 Sql_cmd *make_cmd(THD *thd) override;
4015
4016 private:
4018
4020};
4021
4022/// Parse tree node for SHOW WARNINGS statement
4023
4024class PT_show_warnings final : public PT_show_base {
4025 public:
4026 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
4028 m_opt_limit_clause(opt_limit_clause) {}
4029
4030 Sql_cmd *make_cmd(THD *thd) override;
4031
4032 private:
4034
4036};
4037
4040
4041 protected:
4042 explicit PT_alter_table_action(const POS &pos,
4044 : super(pos), flag(flag) {}
4045
4046 public:
4047 bool do_contextualize(Table_ddl_parse_context *pc) override;
4048
4049 protected:
4050 /**
4051 A routine used by the parser to decide whether we are specifying a full
4052 partitioning or if only partitions to add or to reorganize.
4053
4054 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
4055 @retval false Something else.
4056 */
4060 }
4061
4062 public:
4064};
4065
4068
4069 public:
4070 PT_alter_table_add_column(const POS &pos, const LEX_STRING &field_ident,
4071 PT_field_def_base *field_def,
4072 PT_table_constraint_def *opt_column_constraint,
4073 const char *opt_place)
4074 : super(pos, Alter_info::ALTER_ADD_COLUMN),
4075 m_column_def(POS(), field_ident, field_def, opt_column_constraint,
4076 opt_place) {}
4077
4080 }
4081
4082 private:
4083 PT_column_def m_column_def; // TODO: Position is not set.
4084};
4085
4088
4089 public:
4091 const POS &pos, const Mem_root_array<PT_table_element *> *columns)
4092 : super(pos, Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
4093
4095 if (super::do_contextualize(pc)) return true;
4096
4097 for (auto *column : *m_columns)
4098 if (column->contextualize(pc)) return true;
4099
4100 return false;
4101 }
4102
4103 private:
4105};
4106
4109
4110 public:
4112 PT_table_constraint_def *constraint)
4113 : super(pos, Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
4114
4117 }
4118
4119 private:
4121};
4122
4125
4126 public:
4127 PT_alter_table_change_column(const POS &pos, const LEX_STRING &old_name,
4128 const LEX_STRING &new_name,
4129 PT_field_def_base *field_def,
4130 const char *opt_place)
4131 : super(pos, Alter_info::ALTER_CHANGE_COLUMN),
4132 m_old_name(old_name),
4133 m_new_name(new_name),
4134 m_field_def(field_def),
4135 m_opt_place(opt_place) {}
4136
4138 PT_field_def_base *field_def,
4139 const char *opt_place)
4140 : PT_alter_table_change_column(pos, name, name, field_def, opt_place) {}
4141
4142 bool do_contextualize(Table_ddl_parse_context *pc) override;
4143
4144 private:
4148 const char *m_opt_place;
4149};
4150
4153
4154 protected:
4156 Alter_info::Alter_info_flag alter_info_flag,
4157 const char *name)
4158 : super(pos, alter_info_flag), m_alter_drop(drop_type, name) {}
4159
4160 public:
4162 return (super::do_contextualize(pc) ||
4163 pc->alter_info->drop_list.push_back(&m_alter_drop));
4164 }
4165
4166 private:
4168};
4169
4171 public:
4172 explicit PT_alter_table_drop_column(const POS &pos, const char *name)
4173 : PT_alter_table_drop(pos, Alter_drop::COLUMN,
4174 Alter_info::ALTER_DROP_COLUMN, name) {}
4175};
4176
4178 public:
4179 explicit PT_alter_table_drop_foreign_key(const POS &pos, const char *name)
4181 Alter_info::DROP_FOREIGN_KEY, name) {}
4182};
4183
4185 public:
4186 explicit PT_alter_table_drop_key(const POS &pos, const char *name)
4187 : PT_alter_table_drop(pos, Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
4188 name) {}
4189};
4190
4192 public:
4194 const char *name)
4195 : PT_alter_table_drop(pos, Alter_drop::CHECK_CONSTRAINT,
4196 Alter_info::DROP_CHECK_CONSTRAINT, name) {}
4197};
4198
4200 public:
4201 explicit PT_alter_table_drop_constraint(const POS &pos, const char *name)
4202 : PT_alter_table_drop(pos, Alter_drop::ANY_CONSTRAINT,
4203 Alter_info::DROP_ANY_CONSTRAINT, name) {}
4204};
4205
4208
4209 protected:
4211 const POS &pos,