MySQL 9.2.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_list.h"
41#include "my_sqlcommand.h"
42#include "my_sys.h"
43#include "my_thread_local.h"
44#include "my_time.h"
45#include "mysqld_error.h"
46#include "sql/check_stack.h"
47#include "sql/enum_query_type.h"
48#include "sql/handler.h"
49#include "sql/key_spec.h"
50#include "sql/mem_root_array.h"
51#include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
52#include "sql/parse_location.h"
53#include "sql/parse_tree_helpers.h" // PT_item_list
55#include "sql/parser_yystype.h"
56#include "sql/partition_info.h"
59#include "sql/set_var.h"
60#include "sql/sp_head.h"
61#include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
62#include "sql/sql_alter.h"
63#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
64#include "sql/sql_cmd_srs.h"
65#include "sql/sql_exchange.h"
66#include "sql/sql_lex.h" // LEX
67#include "sql/sql_list.h"
68#include "sql/sql_load.h" // Sql_cmd_load_table
70#include "sql/sql_restart_server.h" // Sql_cmd_restart_server
71#include "sql/sql_tablespace.h" // Tablespace_options
72#include "sql/sql_truncate.h" // Sql_cmd_truncate_table
73#include "sql/table.h" // Common_table_expr
74#include "sql/tablesample.h"
75#include "sql/window_lex.h"
76#include "string_with_len.h"
77#include "thr_lock.h"
78
79class Item;
80class Item_cache;
84class PT_hint_list;
87class PT_partition;
88class PT_subquery;
89class PT_type;
90class PT_window_list;
91class Sql_cmd;
92class String;
93class THD;
94class Window;
95class sp_head;
96class sp_name;
97struct CHARSET_INFO;
98
99/**
100 @defgroup ptn Parse tree nodes
101 @ingroup Parser
102*/
103/**
104 @defgroup ptn_stmt Nodes representing SQL statements
105 @ingroup ptn
106*/
107/**
108 @defgroup ptn_create_table CREATE TABLE statement
109 @ingroup ptn_stmt
110*/
111/**
112 @defgroup ptn_alter_table ALTER TABLE statement
113 @ingroup ptn_stmt
114*/
115/**
116 @defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
117 @ingroup ptn_create_table
118*/
119/**
120 @defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
121 @ingroup ptn_create_table ptn_alter_table
122*/
123/**
124 @defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
125 @ingroup ptn_partitioning
126*/
127/**
128 @defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
129 TABLE
130 @anchor ptn_create_or_alter_table_options
131 @ingroup ptn_create_table ptn_alter_table
132*/
133/**
134 @defgroup ptn_col_types Column types in CREATE/ALTER TABLE
135 @ingroup ptn_create_table ptn_alter_table
136*/
137/**
138 @defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
139 @ingroup ptn_create_table ptn_alter_table
140*/
141/**
142 @defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
143 TABLE
144 @ingroup ptn_col_attrs ptn_alter_table
145*/
146
147/**
148 Calls contextualize() on every node in the array.
149*/
150template <class Node_type, class Parse_context_type>
152 Parse_context_type *pc) {
153 for (Node_type *i : nodes)
154 if (i->contextualize(pc)) return true;
155 return false;
156}
157
158/**
159 Base class for all top-level nodes of SQL statements
160
161 @ingroup ptn_stmt
162*/
165 void operator=(const Parse_tree_root &) = delete;
166
167 protected:
168 Parse_tree_root() = default;
169 explicit Parse_tree_root(const POS &pos) : m_pos(pos) {}
170 virtual ~Parse_tree_root() = default;
171
172 public:
173 /// Textual location of a token just parsed.
175
176 virtual Sql_cmd *make_cmd(THD *thd) = 0;
177
178 // Return Json parse tree generated by SHOW PARSE_TREE.
179 virtual std::string get_printable_parse_tree(THD *thd [[maybe_unused]]) {
180 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
181 "Parse tree display of this statement");
182 return "";
183 }
184};
185
187 public:
190
191 ~PT_table_ddl_stmt_base() override = 0; // force abstract class
192
193 protected:
195};
196
198
199/**
200 Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
201
202 For internal use in the contextualization code.
203*/
205 Table_ddl_parse_context(THD *thd_arg, Query_block *select_arg,
210};
211
212/**
213 Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
214*/
216
217class PT_order_expr : public Parse_tree_node, public ORDER {
219
220 public:
221 PT_order_expr(const POS &pos, Item *item_arg, enum_order dir) : super(pos) {
222 item_initial = item_arg;
224 }
225
226 bool do_contextualize(Parse_context *pc) override;
227
228 protected:
229 void add_json_info(Json_object *obj) override {
230 obj->add_alias("desc",
231 create_dom_ptr<Json_boolean>(direction == ORDER_DESC));
232 }
233};
234
237
238 public:
240
241 public:
242 explicit PT_order_list(const POS &pos) : super(pos) {}
243
244 bool do_contextualize(Parse_context *pc) override {
245 if (super::do_contextualize(pc)) return true;
246 for (ORDER *o = value.first; o != nullptr; o = o->next) {
247 if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
248 }
249 return false;
250 }
251
253 order->used_alias = nullptr;
254 order->used = 0;
255 value.link_in_list(order, &order->next);
256 }
257};
258
261
262 public:
263 explicit PT_gorder_list(const POS &pos) : super(pos) {}
264
265 bool do_contextualize(Parse_context *pc) override {
266 return super::do_contextualize(pc);
267 }
268};
269
270/**
271 Represents an element of the WITH list:
272 WITH [...], [...] SELECT ...,
273 ^ or ^
274 i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
275*/
278
279 public:
280 explicit PT_common_table_expr(const POS &pos, const LEX_STRING &name,
281 const LEX_STRING &subq_text,
282 uint subq_text_offset, PT_subquery *sn,
285
286 /// The name after AS
287 const LEX_STRING &name() const { return m_name; }
288 /**
289 @param thd Thread handler
290 @param[out] node PT_subquery
291 @returns a PT_subquery to attach to a table reference for this CTE
292 */
293 bool make_subquery_node(THD *thd, PT_subquery **node);
294 /**
295 @param tl Table reference to match
296 @param in_self If this is a recursive reference
297 @param[out] found Is set to true/false if matches or not
298 @returns true if error
299 */
300 bool match_table_ref(Table_ref *tl, bool in_self, bool *found);
301 /**
302 @returns true if 'other' is the same instance as 'this'
303 */
304 bool is(const Common_table_expr *other) const {
305 return other == &m_postparse;
306 }
307 void print(const THD *thd, String *str, enum_query_type query_type);
308 bool do_contextualize(Parse_context *pc) override;
309
310 protected:
311 void add_json_info(Json_object *obj) override;
312
313 private:
315 /// Raw text of query expression (including parentheses)
317 /**
318 Offset in bytes of m_subq_text in original statement which had the WITH
319 clause.
320 */
322 /// Parsed version of subq_text
324 /// List of explicitly specified column names; if empty, no list.
326 /**
327 A Table_ref representing a CTE needs access to the WITH list
328 element it derives from. However, in order to:
329 - limit the members which Table_ref can access
330 - avoid including this header file everywhere Table_ref needs to
331 access these members, these members are relocated into a separate inferior
332 object whose declaration is in table.h, like that of Table_ref. It's
333 the "postparse" part. Table_ref accesses this inferior object only.
334 */
336
338};
339
340/**
341 Represents the WITH list.
342 WITH [...], [...] SELECT ...,
343 ^^^^^^^^^^^^
344*/
347
348 public:
349 /// @param pos Position of this clause in the SQL statement.
350 /// @param mem_root where interior objects are allocated
351 explicit PT_with_list(const POS &pos, MEM_ROOT *mem_root)
352 : super(pos), m_elements(mem_root) {}
355 return m_elements;
356 }
357
358 private:
360};
361
362/**
363 Represents the WITH clause:
364 WITH [...], [...] SELECT ...,
365 ^^^^^^^^^^^^^^^^^
366*/
369
370 public:
371 PT_with_clause(const POS &pos, const PT_with_list *l, bool r)
372 : super(pos),
373 m_list(l),
374 m_recursive(r),
376
377 bool do_contextualize(Parse_context *pc) override;
378
379 /**
380 Looks up a table reference into the list of CTEs.
381 @param tl Table reference to look up
382 @param[out] found Is set to true/false if found or not
383 @returns true if error
384 */
385 bool lookup(Table_ref *tl, PT_common_table_expr **found);
386 /**
387 Call this to record in the WITH clause that we are contextualizing the
388 CTE definition inserted in table reference 'tl'.
389 @returns information which the caller must provide to
390 leave_parsing_definition().
391 */
393 auto old = m_most_inner_in_parsing;
395 return old;
396 }
399 }
400 void print(const THD *thd, String *str, enum_query_type query_type);
401
402 protected:
403 void add_json_info(Json_object *obj) override {
404 obj->add_alias("recursive", create_dom_ptr<Json_boolean>(m_recursive));
405 }
406
407 private:
408 /// All CTEs of this clause
409 const PT_with_list *const m_list;
410 /// True if the user has specified the RECURSIVE keyword.
411 const bool m_recursive;
412 /**
413 The innermost CTE reference which we're parsing at the
414 moment. Used to detect forward references, loops and recursiveness.
415 */
417
419};
420
423
424 public:
425 explicit PT_select_item_list(const POS &pos) : super(pos) {}
426
427 bool do_contextualize(Parse_context *pc) override;
428};
429
432
434
435 protected:
436 void add_json_info(Json_object *obj) override {
437 obj->add_alias("is_offset_first",
438 create_dom_ptr<Json_boolean>(limit_options.is_offset_first));
439 }
440
441 public:
442 PT_limit_clause(const POS &pos, const Limit_options &limit_options_arg)
443 : super(pos), limit_options(limit_options_arg) {}
444
445 bool do_contextualize(Parse_context *pc) override;
447};
448
449class PT_cross_join;
450class PT_joined_table;
451
453 public:
454 explicit PT_table_reference(const POS &pos) : Parse_tree_node(pos) {}
455
457
458 /**
459 Lets us build a parse tree top-down, which is necessary due to the
460 context-dependent nature of the join syntax. This function adds
461 the @<table_ref@> cross join as the left-most leaf in this join tree
462 rooted at this node.
463
464 @todo: comment on non-join PT_table_reference objects
465
466 @param cj This @<table ref@> will be added if it represents a cross join.
467
468 @return The new top-level join.
469 */
471};
472
475
478 const char *const opt_table_alias;
481
482 public:
483 PT_table_factor_table_ident(const POS &pos, Table_ident *table_ident_arg,
484 List<String> *opt_use_partition_arg,
485 const LEX_CSTRING &opt_table_alias_arg,
486 List<Index_hint> *opt_key_definition_arg,
487 PT_tablesample *opt_tablesample_arg)
488 : super(pos),
489 table_ident(table_ident_arg),
490 opt_use_partition(opt_use_partition_arg),
491 opt_table_alias(opt_table_alias_arg.str),
492 opt_key_definition(opt_key_definition_arg),
493 opt_tablesample(opt_tablesample_arg) {}
494
495 protected:
496 bool do_contextualize(Parse_context *pc) override;
497 void add_json_info(Json_object *obj) override;
498};
499
501 protected:
502 explicit PT_json_table_column(const POS &pos) : Parse_tree_node(pos) {}
503
504 public:
506};
507
510
511 public:
514 const LEX_STRING &table_alias)
515 : super(pos),
516 m_expr(expr),
517 m_path(path),
518 m_nested_columns(nested_cols),
519 m_table_alias(table_alias) {}
520
521 bool do_contextualize(Parse_context *pc) override;
522
523 private:
528};
529
532
534
535 public:
538 : super(pos), table_list(table_list) {}
539
540 bool do_contextualize(Parse_context *pc) override;
541};
542
545
546 public:
547 PT_derived_table(const POS &pos, bool lateral, PT_subquery *subquery,
548 const LEX_CSTRING &table_alias,
550
551 bool do_contextualize(Parse_context *pc) override;
552
553 protected:
554 void add_json_info(Json_object *obj) override;
555
556 private:
559 const char *const m_table_alias;
560 /// List of explicitly specified column names; if empty, no list.
562};
563
566
567 public:
569 : super(pos), m_joined_table(joined_table) {}
570
571 bool do_contextualize(Parse_context *pc) override;
572
573 private:
575};
576
579
580 protected:
585
588
589 public:
590 PT_joined_table(const POS &pos, PT_table_reference *tab1_node_arg,
591 const POS &join_pos_arg, PT_joined_table_type type,
592 PT_table_reference *tab2_node_arg)
593 : super(pos),
594 m_left_pt_table(tab1_node_arg),
595 m_join_pos(join_pos_arg),
596 m_type(type),
597 m_right_pt_table(tab2_node_arg) {
598 using std::has_single_bit;
599 static_assert(has_single_bit(unsigned{JTT_INNER}), "not a single bit");
600 static_assert(has_single_bit(unsigned{JTT_STRAIGHT}), "not a single bit");
601 static_assert(has_single_bit(unsigned{JTT_NATURAL}), "not a single bit");
602 static_assert(has_single_bit(unsigned{JTT_LEFT}), "not a single bit");
603 static_assert(has_single_bit(unsigned{JTT_RIGHT}), "not a single bit");
604
605 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
608 }
609
610 /**
611 Adds the cross join to this join operation. The cross join is nested as
612 the table reference on the left-hand side.
613 */
616 return this;
617 }
618
619 /// Adds the table reference as the right-hand side of this join.
621 assert(m_right_pt_table == nullptr);
623 }
624
625 bool do_contextualize(Parse_context *pc) override;
626
627 /// This class is being inherited, it should thus be abstract.
628 ~PT_joined_table() override = 0;
629
630 protected:
632 void add_json_info(Json_object *obj) override;
633};
634
635inline PT_joined_table::~PT_joined_table() = default;
636
639
640 public:
641 PT_cross_join(const POS &pos, PT_table_reference *tab1_node_arg,
642 const POS &join_pos_arg, PT_joined_table_type Type_arg,
643 PT_table_reference *tab2_node_arg)
644 : PT_joined_table(pos, tab1_node_arg, join_pos_arg, Type_arg,
645 tab2_node_arg) {}
646
647 bool do_contextualize(Parse_context *pc) override;
648};
649
653
654 public:
655 PT_joined_table_on(const POS &pos, PT_table_reference *tab1_node_arg,
656 const POS &join_pos_arg, PT_joined_table_type type,
657 PT_table_reference *tab2_node_arg, Item *on_arg)
658 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
659 on(on_arg) {}
660
661 bool do_contextualize(Parse_context *pc) override;
662};
663
667
668 public:
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 List<String> *using_fields_arg)
673 : super(pos, tab1_node_arg, join_pos_arg, type, tab2_node_arg),
674 using_fields(using_fields_arg) {}
675
676 /// A PT_joined_table_using without a list of columns denotes a natural join.
677 PT_joined_table_using(const POS &pos, PT_table_reference *tab1_node_arg,
678 const POS &join_pos_arg, PT_joined_table_type type,
679 PT_table_reference *tab2_node_arg)
680 : PT_joined_table_using(pos, tab1_node_arg, join_pos_arg, type,
681 tab2_node_arg, nullptr) {}
682
683 bool do_contextualize(Parse_context *pc) override;
684
685 protected:
686 void add_json_info(Json_object *obj) override;
687};
688
689/*
690 PT_tablesample - parse tree node
691
692 Information contained in TABLESAMPLE clause is here.
693*/
696
697 public:
700
701 PT_tablesample(const POS &pos, tablesample_type tablesample_type_arg,
702 Item *sample_percentage)
703 : super(pos),
704 m_sampling_type(tablesample_type_arg),
705 m_sample_percentage(sample_percentage) {}
706};
707
708class PT_group : public Parse_tree_node {
710
713
714 protected:
715 void add_json_info(Json_object *obj) override {
716 if (olap == ROLLUP_TYPE)
717 obj->add_alias("olap_options", create_dom_ptr<Json_string>("ROLLUP"));
718 // Only rollup type supported.
719 }
720
721 public:
722 PT_group(const POS &pos, PT_order_list *group_list_arg, olap_type olap_arg)
723 : super(pos), group_list(group_list_arg), olap(olap_arg) {}
724
725 bool do_contextualize(Parse_context *pc) override;
726};
727
728class PT_order : public Parse_tree_node {
730
731 public:
733 explicit PT_order(const POS &pos, PT_order_list *order_list_arg)
734 : super(pos), order_list(order_list_arg) {}
735
736 bool do_contextualize(Parse_context *pc) override;
737};
738
740 public:
741 PT_locking_clause(const POS &pos, Lock_strength strength,
743 : Parse_tree_node(pos),
744 m_lock_strength(strength),
746
747 bool do_contextualize(Parse_context *pc) final;
748
749 virtual bool set_lock_for_tables(Parse_context *pc) = 0;
750
752
753 protected:
755 thr_lock_type lock_type = TL_IGNORE;
756 switch (m_lock_strength) {
758 lock_type = TL_WRITE;
759 break;
761 lock_type = TL_READ_WITH_SHARED_LOCKS;
762 break;
763 }
764
765 return {lock_type, static_cast<thr_locked_row_action>(action())};
766 }
767
768 private:
771};
772
774 public:
776 const POS &pos, Lock_strength strength,
778 : PT_locking_clause(pos, strength, action) {}
779
780 bool set_lock_for_tables(Parse_context *pc) override;
781};
782
784 public:
786
790 : PT_locking_clause(pos, strength, action), m_tables(tables) {}
791
792 bool set_lock_for_tables(Parse_context *pc) override;
793
794 private:
795 bool raise_error(THD *thd, const Table_ident *name, int error);
796
797 bool raise_error(int error);
798
800};
801
803 public:
805 : Parse_tree_node(pos) {
807 }
808
809 bool push_back(PT_locking_clause *locking_clause) {
810 return m_locking_clauses.push_back(locking_clause);
811 }
812
813 bool do_contextualize(Parse_context *pc) override {
814 for (auto locking_clause : m_locking_clauses)
815 if (locking_clause->contextualize(pc)) return true;
816 return false;
817 }
818
819 private:
821};
822
824 public:
825 explicit PT_query_expression_body(const POS &pos) : Parse_tree_node(pos) {}
827 virtual Setop_type type() const { return NONE; }
828 virtual bool is_set_operation() const = 0;
829 /**
830 True if this query expression can absorb an extraneous order by/limit
831 clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
832 trailing clause may not refer to the tables in the `<query primary>`, with
833 one glaring exception:
834
835 (...( SELECT ... )...) ORDER BY ...
836
837 If the nested query expression doesn't contain `ORDER BY`, the statement
838 is interpreted as if the `ORDER BY` was absorbed by the innermost query
839 expression, i.e.:
840
841 (...( SELECT ... ORDER BY ... )...)
842
843 There is no rewriting of the parse tree nor AST happening here, the
844 transformation is done by the contextualizer (see
845 PT_query_expression::contextualize_order_and_limit), which interprets the
846 parse tree, and builds the AST according to this interpretation. This
847 interpretation is governed by the following rule: An `ORDER BY` can be
848 absorbed if none the nested query expressions contains an `ORDER BY` *or*
849 `LIMIT`. The rule is complex, so here are some examples for illustration:
850
851 In these cases the `ORDER BY` *is* absorbed:
852
853 ( SELECT * FROM t1 ) ORDER BY t1.a;
854 (( SELECT * FROM t1 )) ORDER BY t1.a;
855
856 In these cases the ORDER BY is *not* absorbed:
857
858 ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
859 (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
860 ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
861 (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
862
863 The same happens with `LIMIT`, obviously, but the optimizer is freeer to
864 choose when to apply the limit, and there are name no resolution issues
865 involved.
866
867 @param order True if the outer query block has the ORDER BY clause.
868 @param limit True if the outer query block has the LIMIT clause.
869 */
870 virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
871 virtual bool has_into_clause() const = 0;
872 virtual bool has_trailing_into_clause() const = 0;
873
874 virtual bool is_table_value_constructor() const = 0;
876};
877
880
881 public:
882 PT_set_scoped_system_variable(const POS &pos, const POS &var_pos,
883 const LEX_CSTRING &opt_prefix,
884 const LEX_CSTRING &name, Item *opt_expr)
885 : super(pos),
886 m_varpos(var_pos),
887 m_opt_prefix{opt_prefix},
888 m_name{name},
889 m_opt_expr{opt_expr} {}
890
891 bool do_contextualize(Parse_context *pc) override;
892
893 private:
898};
899
901 protected:
903 : Parse_tree_node(pos) {}
904};
905
908
909 public:
910 PT_set_variable(const POS &pos, const POS &varpos,
911 const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
912 const POS &expr_pos, Item *opt_expr)
913 : super{pos},
914 m_varpos{varpos},
915 m_opt_prefix{opt_prefix},
916 m_name{name},
917 m_expr_pos{expr_pos},
918 m_opt_expr{opt_expr} {}
919
920 bool do_contextualize(Parse_context *pc) override;
921
922 private:
928};
929
933
936
937 public:
939 const LEX_STRING &name_arg,
940 Item *expr_arg)
941 : super(pos), name(name_arg), expr(expr_arg) {}
942
943 bool do_contextualize(Parse_context *pc) override;
944};
945
948
949 public:
951 const POS &name_pos, const LEX_CSTRING &opt_prefix,
952 const LEX_CSTRING &name, Item *opt_expr)
953 : super(pos),
954 m_scope{scope},
955 m_name_pos{name_pos},
956 m_opt_prefix{opt_prefix},
957 m_name{name},
958 m_opt_expr{opt_expr} {}
959
960 bool do_contextualize(Parse_context *pc) override;
961
962 private:
968};
969
973
975
976 public:
978 const CHARSET_INFO *opt_charset_arg)
979 : super(pos), opt_charset(opt_charset_arg) {}
980
981 bool do_contextualize(Parse_context *pc) override;
982};
983
987
989
990 public:
992 const POS &error_pos)
993 : super(pos), m_error_pos(error_pos) {}
994
995 bool do_contextualize(Parse_context *pc) override;
996};
997
1000
1003
1004 public:
1005 PT_set_names(const POS &pos, const CHARSET_INFO *opt_charset_arg,
1006 const CHARSET_INFO *opt_collation_arg)
1007 : super(pos),
1008 opt_charset(opt_charset_arg),
1009 opt_collation(opt_collation_arg) {}
1010
1011 bool do_contextualize(Parse_context *pc) override;
1012};
1013
1015 protected:
1016 explicit PT_start_option_value_list(const POS &pos) : Parse_tree_node(pos) {}
1017};
1018
1022
1023 const char *password;
1024 const char *current_password;
1028
1029 public:
1031 const char *password_arg,
1032 const char *current_password_arg,
1033 bool retain_current,
1034 bool random_password,
1035 const POS &expr_pos_arg)
1036 : super(pos),
1037 password(password_arg),
1038 current_password(current_password_arg),
1039 retain_current_password(retain_current),
1040 random_password_generator(random_password),
1041 expr_pos(expr_pos_arg) {}
1042
1043 bool do_contextualize(Parse_context *pc) override;
1044};
1045
1049
1051 const char *password;
1052 const char *current_password;
1056
1057 public:
1059 const POS &pos, LEX_USER *user_arg, const char *password_arg,
1060 const char *current_password_arg, bool retain_current, bool random_pass,
1061 const POS &expr_pos_arg)
1062 : super(pos),
1063 user(user_arg),
1064 password(password_arg),
1065 current_password(current_password_arg),
1066 retain_current_password(retain_current),
1067 random_password_generator(random_pass),
1068 expr_pos(expr_pos_arg) {}
1069
1070 bool do_contextualize(Parse_context *pc) override;
1071};
1072
1075
1078
1079 public:
1082 : super(pos), type(type_arg), value(value_arg) {}
1083
1084 bool do_contextualize(Parse_context *pc) override;
1085};
1086
1089
1093
1094 public:
1095 PT_option_value_list_head(const POS &pos, const POS &delimiter_pos_arg,
1096 Parse_tree_node *value_arg,
1097 const POS &value_pos_arg)
1098 : super(pos),
1099 delimiter_pos(delimiter_pos_arg),
1100 value(value_arg),
1101 value_pos(value_pos_arg) {}
1102
1103 bool do_contextualize(Parse_context *pc) override;
1104};
1105
1108
1110
1111 public:
1113 const POS &delimiter_pos_arg, Parse_tree_node *tail,
1114 const POS &tail_pos)
1115 : super(pos, delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
1116
1117 bool do_contextualize(Parse_context *pc) override {
1118 uchar dummy;
1119 if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
1120 return head->contextualize(pc) || super::do_contextualize(pc);
1121 }
1122};
1123
1126
1130
1131 public:
1134 const POS &head_pos_arg,
1135 PT_option_value_list_head *tail_arg)
1136 : super(pos), head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1137
1138 bool do_contextualize(Parse_context *pc) override;
1139};
1140
1143
1144 const char *name;
1146
1147 public:
1148 PT_transaction_characteristic(const POS &pos, const char *name_arg,
1149 int32 value_arg)
1150 : super(pos), name(name_arg), value(value_arg) {}
1151
1152 bool do_contextualize(Parse_context *pc) override;
1153};
1154
1157
1158 public:
1159 explicit PT_transaction_access_mode(const POS &pos, bool is_read_only)
1160 : super(pos, "transaction_read_only", (int32)is_read_only) {}
1161};
1162
1165
1166 public:
1167 explicit PT_isolation_level(const POS &pos, enum_tx_isolation level)
1168 : super(pos, "transaction_isolation", (int32)level) {}
1169};
1170
1173
1176
1177 public:
1180 PT_transaction_characteristic *opt_tail_arg)
1181 : super(pos), head(head_arg), opt_tail(opt_tail_arg) {}
1182
1183 bool do_contextualize(Parse_context *pc) override {
1184 return (super::do_contextualize(pc) || head->contextualize(pc) ||
1185 (opt_tail != nullptr && opt_tail->contextualize(pc)));
1186 }
1187};
1188
1192
1195
1196 public:
1198 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1199 const POS &end_pos_arg)
1200 : super(pos),
1201 characteristics(characteristics_arg),
1202 end_pos(end_pos_arg) {}
1203
1204 bool do_contextualize(Parse_context *pc) override;
1205};
1206
1208 : public Parse_tree_node {
1209 protected:
1211 : Parse_tree_node(pos) {}
1212};
1213
1217
1221
1222 public:
1224 const POS &pos, PT_set_scoped_system_variable *head_arg,
1225 const POS &head_pos_arg, PT_option_value_list_head *opt_tail_arg)
1226 : super(pos),
1227 head(head_arg),
1228 head_pos(head_pos_arg),
1229 opt_tail(opt_tail_arg) {}
1230
1231 bool do_contextualize(Parse_context *pc) override;
1232};
1233
1237
1240
1241 public:
1243 const POS &pos, PT_transaction_characteristics *characteristics_arg,
1244 const POS &characteristics_pos_arg)
1245 : super(pos),
1246 characteristics(characteristics_arg),
1247 characteristics_pos(characteristics_pos_arg) {}
1248
1249 bool do_contextualize(Parse_context *pc) override;
1250};
1251
1254
1257
1258 public:
1260 const POS &pos, enum_var_type type_arg,
1262 : super(pos), type(type_arg), list(list_arg) {}
1263
1264 bool do_contextualize(Parse_context *pc) override;
1265};
1266
1267class PT_set : public Parse_tree_node {
1269
1272
1273 public:
1274 PT_set(const POS &pos, const POS &set_pos_arg,
1276 : super(pos), set_pos(set_pos_arg), list(list_arg) {}
1277
1278 bool do_contextualize(Parse_context *pc) override;
1279};
1280
1283
1284 protected:
1285 explicit PT_into_destination(const POS &pos) : super(pos) {}
1286
1287 public:
1288 bool do_contextualize(Parse_context *pc) override;
1289};
1290
1293
1294 public:
1295 PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1297 const Field_separators *field_term_arg,
1298 const Line_separators *line_term_arg,
1299 enum_destination dumpfile_flag)
1300 : PT_into_destination(pos),
1301 m_exchange(file_name_arg.str, dumpfile_flag),
1302 dumpfile_dest(dumpfile_flag) {
1304 m_exchange.field.merge_field_separators(field_term_arg);
1305 m_exchange.line.merge_line_separators(line_term_arg);
1306 }
1307
1309 enum_destination dumpfile_flag)
1310 : PT_into_destination(pos),
1311 m_exchange(dumpfile_flag),
1312 dumpfile_dest(dumpfile_flag) {
1313 m_exchange.outfile_json = attr;
1314 }
1315
1318 const Field_separators *field_term_arg,
1319 const Line_separators *line_term_arg,
1320 enum_destination dumpfile_flag)
1321 : PT_into_destination(pos),
1322 m_exchange(dumpfile_flag),
1323 dumpfile_dest(dumpfile_flag) {
1325 m_exchange.field.merge_field_separators(field_term_arg);
1326 m_exchange.line.merge_line_separators(line_term_arg);
1328 }
1329
1330 bool do_contextualize(Parse_context *pc) override;
1331
1332 private:
1335};
1336
1339
1340 public:
1341 PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1342 : PT_into_destination(pos),
1343 m_exchange(file_name_arg.str, DUMPFILE_DEST) {}
1344
1345 bool do_contextualize(Parse_context *pc) override;
1346
1347 private:
1349};
1350
1352 public:
1354
1355 explicit PT_select_var(const POS &pos, const LEX_STRING &name_arg)
1356 : Parse_tree_node(pos), name(name_arg) {}
1357
1358 virtual bool is_local() const { return false; }
1359 virtual uint get_offset() const {
1360 assert(0);
1361 return 0;
1362 }
1363};
1364
1367
1368 uint offset = 0;
1369
1370#ifndef NDEBUG
1371 /*
1372 Routine to which this Item_splocal belongs. Used for checking if correct
1373 runtime context is used for variable handling.
1374 */
1375 sp_head *sp = nullptr;
1376#endif
1377
1378 public:
1379 PT_select_sp_var(const POS &pos, const LEX_STRING &name_arg)
1380 : super(pos, name_arg) {}
1381
1382 bool is_local() const override { return true; }
1383 uint get_offset() const override { return offset; }
1384
1385 bool do_contextualize(Parse_context *pc) override;
1386};
1387
1390
1391 public:
1392 explicit PT_select_var_list(const POS &pos) : PT_into_destination(pos) {}
1393
1395
1396 bool do_contextualize(Parse_context *pc) override;
1397
1398 bool push_back(PT_select_var *var) { return value.push_back(var); }
1399};
1400
1401/**
1402 Parse tree node for a single of a window extent's borders,
1403 cf. <window frame extent> in SQL 2003.
1404*/
1406 friend class Window;
1407 Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1408 public:
1410 const bool m_date_time;
1411 interval_type m_int_type = INTERVAL_LAST; // clang-tidy needs initialization.
1412
1413 ///< For unbounded border
1417 }
1418
1419 ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1421 : Parse_tree_node(pos),
1422 m_value(value),
1424 m_date_time(false) {}
1425
1426 ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1428 interval_type int_type)
1429 : Parse_tree_node(pos),
1430 m_value(value),
1432 m_date_time(true),
1433 m_int_type(int_type) {}
1434
1435 ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1436 Item *border() const { return m_value; }
1437 /// Need such low-level access so that fix_fields updates the right pointer
1438 Item **border_ptr() { return &m_value; }
1439
1440 /**
1441 @returns Addition operator for computation of frames, nullptr if error.
1442 @param order_expr Expression to add to/subtract from
1443 @param prec true if PRECEDING
1444 @param asc true if ASC
1445 @param window only used for error generation
1446 */
1447 Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1448 const Window *window);
1449
1450 bool do_contextualize(Parse_context *pc) override;
1451};
1452
1453/**
1454 Parse tree node for one or both of a window extent's borders, cf.
1455 <window frame extent> in SQL 2003.
1456*/
1459 friend class PT_frame;
1460
1461 public:
1462 /**
1463 Constructor.
1464
1465 Frames of the form "frame_start no_frame_end" are translated during
1466 parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1467 'end' are non-nullptr.
1468 */
1470 : Parse_tree_node(pos) {
1471 m_borders[0] = start;
1472 m_borders[1] = end;
1473 }
1474};
1475
1476/**
1477 Parse tree node for a window frame's exclusions, cf. the
1478 <window frame exclusion> clause in SQL 2003.
1479*/
1482
1483 public:
1485 : Parse_tree_node(pos), m_exclusion(e) {}
1486 // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1487};
1488
1489/**
1490 Parse tree node for a window's frame, cf. the <window frame clause>
1491 in SQL 2003.
1492*/
1494 public:
1496
1499
1501
1502 /// If true, this is an artificial frame, not specified by the user
1504
1505 PT_frame(const POS &pos, enum_window_frame_unit unit, PT_borders *from_to,
1506 PT_exclusion *exclusion)
1507 : Parse_tree_node(pos),
1508 m_query_expression(unit),
1509 m_from(from_to->m_borders[0]),
1510 m_to(from_to->m_borders[1]),
1511 m_exclusion(exclusion) {}
1512
1513 bool do_contextualize(Parse_context *pc) override;
1514};
1515
1517 protected:
1518 explicit PT_query_primary(const POS &pos) : PT_query_expression_body(pos) {}
1519};
1520
1523
1535
1536 public:
1538 const POS &pos, PT_hint_list *opt_hints_arg,
1539 const Query_options &options_arg, PT_item_list *item_list_arg,
1540 PT_into_destination *opt_into1_arg,
1541 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1542 Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1543 Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
1544 Item *opt_qualify_clause_arg, bool implicit_from_clause)
1545 : super(pos),
1546 opt_hints(opt_hints_arg),
1547 options(options_arg),
1548 item_list(item_list_arg),
1549 opt_into1(opt_into1_arg),
1550 m_is_from_clause_implicit{implicit_from_clause},
1551 from_clause(from_clause_arg),
1552 opt_where_clause(opt_where_clause_arg),
1553 opt_group_clause(opt_group_clause_arg),
1554 opt_having_clause(opt_having_clause_arg),
1555 opt_window_clause(opt_window_clause_arg),
1556 opt_qualify_clause(opt_qualify_clause_arg) {
1557 assert(implicit_from_clause ? from_clause.empty() : true);
1558 }
1559
1561 const POS &pos, const Query_options &options_arg,
1562 PT_item_list *item_list_arg,
1563 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1564 Item *opt_where_clause_arg)
1565 : super(pos),
1567 options(options_arg),
1568 item_list(item_list_arg),
1571 from_clause(from_clause_arg),
1572 opt_where_clause(opt_where_clause_arg),
1577
1578 PT_query_specification(const POS &pos, const Query_options &options_arg,
1579 PT_item_list *item_list_arg)
1580 : super(pos),
1582 options(options_arg),
1583 item_list(item_list_arg),
1586 from_clause{},
1592
1593 bool do_contextualize(Parse_context *pc) override;
1594
1595 bool has_into_clause() const override { return opt_into1 != nullptr; }
1596 bool has_trailing_into_clause() const override {
1598 opt_where_clause == nullptr && opt_group_clause == nullptr &&
1599 opt_having_clause == nullptr && opt_window_clause == nullptr &&
1600 opt_qualify_clause == nullptr);
1601 }
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 false; }
1608 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1609
1610 protected:
1611 void add_json_info(Json_object *obj) override;
1612
1613 private:
1615};
1616
1619
1621
1622 public:
1623 explicit PT_table_value_constructor(const POS &pos,
1624 PT_insert_values_list *row_value_list_arg)
1625 : super(pos), row_value_list(row_value_list_arg) {}
1626
1627 bool do_contextualize(Parse_context *pc) override;
1628
1629 bool has_into_clause() const override { return false; }
1630 bool has_trailing_into_clause() const override { return false; }
1631
1632 bool is_set_operation() const override { return false; }
1633
1634 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1635
1636 bool is_table_value_constructor() const override { return true; }
1637
1639 return row_value_list;
1640 }
1641};
1642
1645
1646 public:
1648 const POS &pos, const Query_options &options_arg,
1649 PT_item_list *item_list_arg,
1650 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1651 : super(pos, options_arg, item_list_arg, from_clause_arg, nullptr) {}
1652};
1653
1655 public:
1656 PT_query_expression(const POS &pos, PT_with_clause *with_clause,
1657 PT_query_expression_body *body, PT_order *order,
1658 PT_limit_clause *limit)
1660 m_body(body),
1661 m_order(order),
1662 m_limit(limit),
1663 m_with_clause(with_clause) {}
1664
1666 PT_order *order, PT_limit_clause *limit)
1667 : PT_query_expression(pos, nullptr, body, order, limit) {}
1668
1670 : PT_query_expression(pos, body, nullptr, nullptr) {}
1671
1672 bool do_contextualize(Parse_context *pc) override;
1673
1674 bool is_set_operation() const override { return m_body->is_set_operation(); }
1675
1676 bool has_into_clause() const override { return m_body->has_into_clause(); }
1677 bool has_trailing_into_clause() const override {
1678 return (m_body->has_trailing_into_clause() && m_order == nullptr &&
1679 m_limit == nullptr);
1680 }
1681
1682 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1683 if (m_body->is_set_operation()) {
1684 return false;
1685 }
1686 if (m_order == nullptr && m_limit == nullptr) {
1687 /*
1688 It is safe to push ORDER and/or LIMIT down in:
1689
1690 (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1691 (SELECT ...<no order or limit clauses>) ORDER BY ...;
1692 (SELECT ...<no order or limit clauses>) LIMIT ...;
1693 */
1694 return true;
1695 }
1696 if (m_limit != nullptr && !order && limit) {
1697 /*
1698 In MySQL, it is ok(*) to push LIMIT down in:
1699
1700 (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1701
1702 *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1703 `LIMIT b` if a < b. Moreover, the result of:
1704
1705 (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1706
1707 can diverge from:
1708
1709 (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1710
1711 since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1712 while the example (2) does overwrite.
1713
1714 TODO: add a warning, deprecate and replace this behavior with the
1715 standard one.
1716 */
1717 return true;
1718 }
1719 if (m_order != nullptr && m_limit == nullptr && !order && limit) {
1720 /*
1721 Allow pushdown of LIMIT into body with ORDER BY, e.g
1722
1723 (SELECT ... ORDER BY order1) LIMIT a;
1724 */
1725 return true;
1726 }
1727 return false;
1728 }
1729
1730 bool is_table_value_constructor() const override {
1732 }
1733
1735 return m_body->get_row_value_list();
1736 }
1737
1738 private:
1739 /**
1740 Contextualizes the order and limit clauses, re-interpreting them according
1741 to the rules. If the `<query expression body>` can absorb the clauses,
1742 they are simply contextualized into the current Query_block. If not, we
1743 have to create the "fake" Query_block unless there is one already
1744 (Query_expression::new_set_operation_query() is known to do this.)
1745
1746 @see PT_query_expression::can_absorb_order_and_limit()
1747 */
1749
1754};
1755
1756/*
1757 After the removal of the `... <locking_clause> <into_clause>` syntax
1758 PT_locking will disappear.
1759*/
1762
1763 public:
1765 PT_locking_clause_list *locking_clauses)
1766 : super(pos),
1768 m_locking_clauses{locking_clauses} {}
1769
1770 bool do_contextualize(Parse_context *pc) override {
1771 return (super::do_contextualize(pc) ||
1774 }
1775
1776 bool is_set_operation() const override {
1778 }
1779
1780 bool has_into_clause() const override {
1782 }
1783 bool has_trailing_into_clause() const override { return false; }
1784
1785 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1786 return m_query_expression->can_absorb_order_and_limit(order, limit);
1787 }
1788
1789 bool is_table_value_constructor() const override {
1791 }
1792
1795 }
1796
1797 private:
1800};
1801
1804
1807
1808 public:
1810
1811 PT_subquery(const POS &pos, PT_query_expression_body *query_expression)
1812 : super(pos),
1813 qe(query_expression),
1815 m_is_derived_table(false) {}
1816
1817 bool do_contextualize(Parse_context *pc) override;
1818
1820};
1821
1824
1825 public:
1828 bool is_rhs_in_parentheses = false)
1829 : super(pos),
1831 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {
1832 m_list.push_back(lhs);
1833 m_list.push_back(rhs);
1834 }
1835
1837 QueryLevel &ql);
1838 bool is_set_operation() const override { return true; }
1839
1840 bool has_into_clause() const override {
1841 return std::any_of(m_list.cbegin(), m_list.cend(),
1842 [](const PT_query_expression_body &body) {
1843 return body.has_into_clause();
1844 });
1845 }
1846 bool has_trailing_into_clause() const override {
1847 return !m_is_rhs_in_parentheses &&
1848 m_list[m_list.elements - 1]->has_trailing_into_clause();
1849 }
1850
1851 bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1852
1853 bool is_table_value_constructor() const override { return false; }
1854 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1855 bool is_distinct() const { return m_is_distinct; }
1856
1859
1860 protected:
1862 Surrounding_context context);
1867 void add_json_info(Json_object *obj) override {
1868 obj->add_alias("distinct", create_dom_ptr<Json_boolean>(m_is_distinct));
1869 obj->add_alias("rhs_in_parentheses",
1870 create_dom_ptr<Json_boolean>(m_is_rhs_in_parentheses));
1871 }
1872};
1873
1876
1877 public:
1879 bool do_contextualize(Parse_context *pc) override;
1880 enum Setop_type type() const override { return UNION; }
1881};
1882
1885
1886 public:
1888 bool do_contextualize(Parse_context *pc) override;
1889 enum Setop_type type() const override { return EXCEPT; }
1890};
1891
1894
1895 public:
1897 bool do_contextualize(Parse_context *pc) override;
1898 enum Setop_type type() const override { return INTERSECT; }
1899};
1900
1903
1904 public:
1905 /**
1906 @param pos Position of this clause in the SQL statement.
1907 @param qe The query expression.
1908 @param sql_command The type of SQL command.
1909 */
1910 PT_select_stmt(const POS &pos, enum_sql_command sql_command,
1912 : super(pos),
1913 m_sql_command(sql_command),
1914 m_qe(qe),
1915 m_into(nullptr),
1917
1918 /**
1919 Creates a SELECT command. Only SELECT commands can have into.
1920
1921 @param pos Position of this clause in the SQL
1922 statement.
1923 @param qe The query expression.
1924 @param into The own INTO destination.
1925 @param has_trailing_locking_clauses True if there are locking clauses (like
1926 `FOR UPDATE`) at the end of the
1927 statement.
1928 */
1930 PT_into_destination *into = nullptr,
1931 bool has_trailing_locking_clauses = false)
1932 : super(pos),
1934 m_qe{qe},
1935 m_into{into},
1936 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1937
1938 Sql_cmd *make_cmd(THD *thd) override;
1939 std::string get_printable_parse_tree(THD *thd) override;
1940
1941 private:
1946};
1947
1948/**
1949 Top-level node for the DELETE statement
1950
1951 @ingroup ptn_stmt
1952*/
1953class PT_delete final : public Parse_tree_root {
1955
1956 private:
1961 const char *const opt_table_alias;
1969
1970 public:
1971 // single-table DELETE node constructor:
1972 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1973 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1974 Table_ident *table_ident_arg,
1975 const LEX_CSTRING &opt_table_alias_arg,
1976 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1977 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1978 : super(pos),
1979 m_with_clause(with_clause_arg),
1980 opt_hints(opt_hints_arg),
1981 opt_delete_options(opt_delete_options_arg),
1982 table_ident(table_ident_arg),
1983 opt_table_alias(opt_table_alias_arg.str),
1984 opt_use_partition(opt_use_partition_arg),
1985 opt_where_clause(opt_where_clause_arg),
1986 opt_order_clause(opt_order_clause_arg),
1987 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1989 join_table_list.init_empty_const();
1990 }
1991
1992 // multi-table DELETE node constructor:
1993 PT_delete(const POS &pos, PT_with_clause *with_clause_arg,
1994 PT_hint_list *opt_hints_arg, int opt_delete_options_arg,
1995 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1996 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1997 Item *opt_where_clause_arg)
1998 : super(pos),
1999 m_with_clause(with_clause_arg),
2000 opt_hints(opt_hints_arg),
2001 opt_delete_options(opt_delete_options_arg),
2004 table_list(table_list_arg),
2006 join_table_list(join_table_list_arg),
2007 opt_where_clause(opt_where_clause_arg),
2010
2011 Sql_cmd *make_cmd(THD *thd) override;
2012
2013 private:
2014 bool is_multitable() const {
2015 assert((table_ident != nullptr) ^ (table_list.size() > 0));
2016 return table_ident == nullptr;
2017 }
2018
2020};
2021
2022/**
2023 Top-level node for the UPDATE statement
2024
2025 @ingroup ptn_stmt
2026*/
2029
2040
2041 public:
2042 PT_update(const POS &pos, PT_with_clause *with_clause_arg,
2043 PT_hint_list *opt_hints_arg, thr_lock_type opt_low_priority_arg,
2044 bool opt_ignore_arg,
2045 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
2046 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
2047 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
2048 Item *opt_limit_clause_arg)
2049 : super(pos),
2050 m_with_clause(with_clause_arg),
2051 opt_hints(opt_hints_arg),
2052 opt_low_priority(opt_low_priority_arg),
2053 opt_ignore(opt_ignore_arg),
2054 join_table_list(join_table_list_arg),
2055 column_list(column_list_arg),
2056 value_list(value_list_arg),
2057 opt_where_clause(opt_where_clause_arg),
2058 opt_order_clause(opt_order_clause_arg),
2059 opt_limit_clause(opt_limit_clause_arg) {}
2060
2061 Sql_cmd *make_cmd(THD *thd) override;
2062};
2063
2066
2068
2069 public:
2071 : super(pos), many_values(mem_root) {}
2072
2073 bool do_contextualize(Parse_context *pc) override;
2074
2076 many_values.push_back(x);
2077 return false;
2078 }
2079
2081 assert(is_contextualized());
2082 return many_values;
2083 }
2084};
2085
2086/**
2087 Top-level node for the INSERT statement
2088
2089 @ingroup ptn_stmt
2090*/
2091class PT_insert final : public Parse_tree_root {
2093
2094 const bool is_replace;
2097 const bool ignore;
2103 const char *const opt_values_table_alias;
2107
2108 public:
2109 PT_insert(const POS &pos, bool is_replace_arg, PT_hint_list *opt_hints_arg,
2110 thr_lock_type lock_option_arg, bool ignore_arg,
2111 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
2112 PT_item_list *column_list_arg,
2113 PT_insert_values_list *row_value_list_arg,
2114 PT_query_expression_body *insert_query_expression_arg,
2115 const LEX_CSTRING &opt_values_table_alias_arg,
2116 Create_col_name_list *opt_values_column_list_arg,
2117 PT_item_list *opt_on_duplicate_column_list_arg,
2118 PT_item_list *opt_on_duplicate_value_list_arg)
2119 : super(pos),
2120 is_replace(is_replace_arg),
2121 opt_hints(opt_hints_arg),
2122 lock_option(lock_option_arg),
2123 ignore(ignore_arg),
2124 table_ident(table_ident_arg),
2125 opt_use_partition(opt_use_partition_arg),
2126 column_list(column_list_arg),
2127 row_value_list(row_value_list_arg),
2128 insert_query_expression(insert_query_expression_arg),
2129 opt_values_table_alias(opt_values_table_alias_arg.str),
2130 opt_values_column_list(opt_values_column_list_arg),
2131 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
2132 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
2133 // REPLACE statement can't have IGNORE flag:
2134 assert(!is_replace || !ignore);
2135 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
2136 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
2137 // INSERT/REPLACE ... SELECT can't have VALUES clause:
2138 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
2139 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
2140 assert((opt_on_duplicate_column_list == nullptr &&
2141 opt_on_duplicate_value_list == nullptr) ||
2144 }
2145
2146 Sql_cmd *make_cmd(THD *thd) override;
2147
2148 private:
2149 bool has_query_block() const { return insert_query_expression != nullptr; }
2150};
2151
2152class PT_call final : public Parse_tree_root {
2155
2156 public:
2157 PT_call(const POS &pos, sp_name *proc_name_arg,
2158 PT_item_list *opt_expr_list_arg)
2159 : Parse_tree_root(pos),
2160 proc_name(proc_name_arg),
2161 opt_expr_list(opt_expr_list_arg) {}
2162
2163 Sql_cmd *make_cmd(THD *thd) override;
2164};
2165
2166/**
2167 Top-level node for the SHUTDOWN statement
2168
2169 @ingroup ptn_stmt
2170*/
2171class PT_shutdown final : public Parse_tree_root {
2173
2174 public:
2175 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
2176};
2177
2178/**
2179 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
2180
2181 @ingroup ptn_stmt
2182*/
2183class PT_create_srs final : public Parse_tree_root {
2184 /// The SQL command object.
2186 /// Whether OR REPLACE is specified.
2188 /// Whether IF NOT EXISTS is specified.
2190 /// SRID of the SRS to create.
2191 ///
2192 /// The range is larger than that of gis::srid_t, so it must be
2193 /// verified to be less than the uint32 maximum value.
2194 unsigned long long m_srid;
2195 /// All attributes except SRID.
2197
2198 /// Check if a UTF-8 string contains control characters.
2199 ///
2200 /// @note This function only checks single byte control characters (U+0000 to
2201 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
2202 /// that are not detected by this function.
2203 ///
2204 /// @param str The string.
2205 /// @param length Length of the string.
2206 ///
2207 /// @retval false The string contains no control characters.
2208 /// @retval true The string contains at least one control character.
2209 bool contains_control_char(char *str, size_t length) {
2210 for (size_t pos = 0; pos < length; pos++) {
2211 if (std::iscntrl(str[pos])) return true;
2212 }
2213 return false;
2214 }
2215
2216 public:
2217 PT_create_srs(const POS &pos, unsigned long long srid,
2218 const Sql_cmd_srs_attributes &attributes, bool or_replace,
2219 bool if_not_exists)
2220 : Parse_tree_root(pos),
2221 m_or_replace(or_replace),
2222 m_if_not_exists(if_not_exists),
2223 m_srid(srid),
2224 m_attributes(attributes) {}
2225
2226 Sql_cmd *make_cmd(THD *thd) override;
2227};
2228
2229/**
2230 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
2231
2232 @ingroup ptn_stmt
2233*/
2234class PT_drop_srs final : public Parse_tree_root {
2235 /// The SQL command object.
2237 /// SRID of the SRS to drop.
2238 ///
2239 /// The range is larger than that of gis::srid_t, so it must be
2240 /// verified to be less than the uint32 maximum value.
2241 unsigned long long m_srid;
2242
2243 public:
2244 PT_drop_srs(const POS &pos, unsigned long long srid, bool if_exists)
2245 : Parse_tree_root(pos), sql_cmd(srid, if_exists), m_srid(srid) {}
2246
2247 Sql_cmd *make_cmd(THD *thd) override;
2248};
2249
2250/**
2251 Top-level node for the ALTER INSTANCE statement
2252
2253 @ingroup ptn_stmt
2254*/
2257
2258 public:
2260 const POS &pos, enum alter_instance_action_enum alter_instance_action,
2261 const LEX_CSTRING &channel)
2262 : Parse_tree_root(pos), sql_cmd(alter_instance_action, channel) {}
2263
2264 Sql_cmd *make_cmd(THD *thd) override;
2265};
2266
2267/**
2268 A template-free base class for index options that we can predeclare in
2269 sql_lex.h
2270*/
2272 protected:
2273 explicit PT_base_index_option(const POS &pos) : Table_ddl_node(pos) {}
2274};
2275
2276/**
2277 A key part specification.
2278
2279 This can either be a "normal" key part (a key part that points to a column),
2280 or this can be a functional key part (a key part that points to an
2281 expression).
2282*/
2285
2286 public:
2287 /**
2288 Constructor for a functional key part.
2289
2290 @param pos Position of this clause in the SQL statement.
2291 @param expression The expression to index.
2292 @param order The direction of the index.
2293 */
2294 PT_key_part_specification(const POS &pos, Item *expression, enum_order order);
2295
2296 /**
2297 Constructor for a "normal" key part. That is a key part that points to a
2298 column and not an expression.
2299
2300 @param pos Position of this clause in the SQL statement.
2301 @param column_name The column name that this key part points to.
2302 @param order The direction of the index.
2303 @param prefix_length How many bytes or characters this key part should
2304 index, or zero if it should index the entire column.
2305 */
2306 PT_key_part_specification(const POS &pos, const LEX_CSTRING &column_name,
2307 enum_order order, int prefix_length);
2308
2309 /**
2310 Contextualize this key part specification. This will also call itemize on
2311 the indexed expression if this is a functional key part.
2312
2313 @param pc The parse context
2314
2315 @retval true on error
2316 @retval false on success
2317 */
2318 bool do_contextualize(Parse_context *pc) override;
2319
2320 /**
2321 Get the indexed expression. The caller must ensure that has_expression()
2322 returns true before calling this.
2323
2324 @returns The indexed expression
2325 */
2327 assert(has_expression());
2328 return m_expression;
2329 }
2330
2331 /**
2332 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2333 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2334 direction.
2335 */
2336 enum_order get_order() const { return m_order; }
2337
2338 /**
2339 @retval true if the user explicitly specified a direction (asc/desc).
2340 @retval false if the user didn't explicitly specify a direction.
2341 */
2342 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2343
2344 /**
2345 @retval true if the key part contains an expression (and thus is a
2346 functional key part).
2347 @retval false if the key part doesn't contain an expression.
2348 */
2349 bool has_expression() const { return m_expression != nullptr; }
2350
2351 /**
2352 Get the column that this key part points to. This is only valid if this
2353 key part isn't a functional index. The caller must thus check the return
2354 value of has_expression() before calling this function.
2355
2356 @returns The column that this key part points to.
2357 */
2359 assert(!has_expression());
2360 return m_column_name;
2361 }
2362
2363 /**
2364 @returns The number of bytes that this key part should index. If the column
2365 this key part points to is a non-binary column, this is the number
2366 of characters. Returns zero if the entire column should be indexed.
2367 */
2368 int get_prefix_length() const { return m_prefix_length; }
2369
2370 private:
2371 /**
2372 The indexed expression in case this is a functional key part. Only valid if
2373 has_expression() returns true.
2374 */
2376
2377 /// The direction of the index.
2379
2380 /// The name of the column that this key part indexes.
2382
2383 /**
2384 If this is greater than zero, it represents how many bytes of the column
2385 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2386 is the number of characters.
2387 */
2389};
2390
2391/**
2392 A template for options that set a single `<alter option>` value in
2393 thd->lex->key_create_info.
2394
2395 @tparam Option_type The data type of the option.
2396 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2397*/
2398template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2400 public:
2401 /// @param pos Position of this clause in the SQL statement.
2402 /// @param option_value The value of the option.
2403 PT_index_option(const POS &pos, Option_type option_value)
2404 : PT_base_index_option(pos), m_option_value(option_value) {}
2405
2408 return false;
2409 }
2410
2411 private:
2412 Option_type m_option_value;
2413};
2414
2415/**
2416 A template for options that set a single property in a KEY_CREATE_INFO, and
2417 also records if the option was explicitly set.
2418*/
2419template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2420 bool KEY_CREATE_INFO::*Property_is_explicit>
2422 public:
2423 PT_traceable_index_option(const POS &pos, Option_type option_value)
2424 : PT_base_index_option(pos), m_option_value(option_value) {}
2425
2428 pc->key_create_info->*Property_is_explicit = true;
2429 return false;
2430 }
2431
2432 private:
2433 Option_type m_option_value;
2434};
2435
2443
2444/**
2445 The data structure (B-tree, Hash, etc) used for an index is called
2446 'index_type' in the manual. Internally, this is stored in
2447 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2448 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2449 it's ignored. The terminology is somewhat confusing, but we stick to the
2450 manual in the parser.
2451*/
2455
2457 public:
2459 const LEX_STRING &name_arg, PT_base_index_option *type,
2460 Table_ident *table_ident,
2466 m_keytype(type_par),
2467 m_name(name_arg),
2468 m_type(type),
2469 m_table_ident(table_ident),
2470 m_columns(cols),
2472 m_algo(algo),
2473 m_lock(lock) {}
2474
2475 Sql_cmd *make_cmd(THD *thd) override;
2476
2477 private:
2486};
2487
2488/**
2489 Base class for column/constraint definitions in CREATE %TABLE
2490
2491 @ingroup ptn_create_table_stuff
2492*/
2494 protected:
2495 explicit PT_table_element(const POS &pos) : Table_ddl_node(pos) {}
2496};
2497
2499 protected:
2500 explicit PT_table_constraint_def(const POS &pos) : PT_table_element(pos) {}
2501};
2502
2505
2506 public:
2508 const LEX_STRING &name_arg,
2512 : super(pos),
2513 m_keytype(type_par),
2514 m_name(name_arg),
2515 m_type(type),
2516 m_columns(cols),
2517 m_options(options) {}
2518
2519 bool do_contextualize(Table_ddl_parse_context *pc) override;
2520
2521 private:
2527};
2528
2531
2532 public:
2533 PT_foreign_key_definition(const POS &pos, const LEX_STRING &constraint_name,
2534 const LEX_STRING &key_name,
2536 Table_ident *referenced_table,
2537 List<Key_part_spec> *ref_list,
2538 fk_match_opt fk_match_option,
2539 fk_option fk_update_opt, fk_option fk_delete_opt)
2540 : super(pos),
2541 m_constraint_name(constraint_name),
2542 m_key_name(key_name),
2543 m_columns(columns),
2544 m_referenced_table(referenced_table),
2545 m_ref_list(ref_list),
2546 m_fk_match_option(fk_match_option),
2547 m_fk_update_opt(fk_update_opt),
2548 m_fk_delete_opt(fk_delete_opt) {}
2549
2550 bool do_contextualize(Table_ddl_parse_context *pc) override;
2551
2552 void set_column_name(const LEX_STRING &column_name) {
2553 m_column_name = column_name;
2554 }
2555
2556 private:
2565
2566 // Column name. Set when FK is specified at the column level.
2568};
2569
2570/**
2571 Common base class for CREATE TABLE and ALTER TABLE option nodes
2572
2573 @ingroup ptn_create_or_alter_table_options
2574*/
2576 protected:
2577 explicit PT_ddl_table_option(const POS &pos) : Table_ddl_node(pos) {}
2578
2579 public:
2580 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2581
2582 virtual bool is_rename_table() const { return false; }
2583};
2584
2586
2587/**
2588 Base class for CREATE TABLE option nodes
2589
2590 @ingroup ptn_create_or_alter_table_options
2591*/
2594
2595 protected:
2596 explicit PT_create_table_option(const POS &pos) : super(pos) {}
2597
2598 public:
2599 ~PT_create_table_option() override = 0; // Force abstract class declaration
2600
2602 if (super::do_contextualize(pc)) return true;
2604 return false;
2605 }
2606};
2607
2609
2610/**
2611 A template for options that set a single property in HA_CREATE_INFO, and
2612 also records if the option was explicitly set.
2613*/
2614template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2615 uint64_t Property_flag>
2618
2619 const Option_type value;
2620
2621 public:
2622 explicit PT_traceable_create_table_option(const POS &pos, Option_type value)
2623 : super(pos), value(value) {}
2624
2626 if (super::do_contextualize(pc)) return true;
2627 pc->create_info->*Property = value;
2628 pc->create_info->used_fields |= Property_flag;
2629 return false;
2630 }
2631};
2632
2633#define TYPE_AND_REF(x) decltype(x), &x
2634
2635/**
2636 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2637
2638 @ingroup ptn_create_or_alter_table_options
2639*/
2643
2644/**
2645 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2646
2647 @ingroup ptn_create_or_alter_table_options
2648*/
2652
2653/**
2654 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2655
2656 @ingroup ptn_create_or_alter_table_options
2657*/
2661
2662/**
2663 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2664
2665 @ingroup ptn_create_or_alter_table_options
2666*/
2670
2671/**
2672 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2673
2674 @ingroup ptn_create_or_alter_table_options
2675*/
2679
2680/**
2681 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2682
2683 @ingroup ptn_create_or_alter_table_options
2684*/
2688
2689/**
2690 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2691
2692 @ingroup ptn_create_or_alter_table_options
2693*/
2697
2698/**
2699 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2700
2701 @ingroup ptn_create_or_alter_table_options
2702*/
2706
2710
2715
2719
2723
2727
2731
2735
2740
2745
2747
2748/**
2749 A template for options that set HA_CREATE_INFO::table_options and
2750 also records if the option was explicitly set.
2751*/
2752template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2753 table_options_t No>
2756
2758
2759 public:
2761 : super(pos), value(value) {}
2762
2764 if (super::do_contextualize(pc)) return true;
2765 pc->create_info->table_options &= ~(Yes | No);
2766 switch (value) {
2767 case Ternary_option::ON:
2768 pc->create_info->table_options |= Yes;
2769 break;
2771 pc->create_info->table_options |= No;
2772 break;
2774 break;
2775 default:
2776 assert(false);
2777 }
2778 pc->create_info->used_fields |= Property_flag;
2779 return false;
2780 }
2781};
2782
2783/**
2784 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2785
2786 @ingroup ptn_create_or_alter_table_options
2787
2788 PACK_KEYS | Constructor parameter
2789 ----------|----------------------
2790 1 | Ternary_option::ON
2791 0 | Ternary_option::OFF
2792 DEFAULT | Ternary_option::DEFAULT
2793*/
2795 0, // DEFAULT
2796 HA_OPTION_PACK_KEYS, // ON
2799
2800/**
2801 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2802
2803 @ingroup ptn_create_or_alter_table_options
2804
2805 STATS_PERSISTENT | Constructor parameter
2806 -----------------|----------------------
2807 1 | Ternary_option::ON
2808 0 | Ternary_option::OFF
2809 DEFAULT | Ternary_option::DEFAULT
2810*/
2812 0, // DEFAULT
2816
2817/**
2818 A template for options that set HA_CREATE_INFO::table_options and
2819 also records if the option was explicitly set.
2820*/
2821template <ulong Property_flag, table_options_t Yes, table_options_t No>
2824
2825 const bool value;
2826
2827 public:
2828 explicit PT_bool_create_table_option(const POS &pos, bool value)
2829 : super(pos), value(value) {}
2830
2832 if (super::do_contextualize(pc)) return true;
2833 pc->create_info->table_options &= ~(Yes | No);
2834 pc->create_info->table_options |= value ? Yes : No;
2835 pc->create_info->used_fields |= Property_flag;
2836 return false;
2837 }
2838};
2839
2840/**
2841 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2842
2843 @ingroup ptn_create_or_alter_table_options
2844
2845 TABLE_CHECKSUM | Constructor parameter
2846 ---------------|----------------------
2847 0 | false
2848 not 0 | true
2849*/
2851 HA_OPTION_CHECKSUM, // ON
2853 >
2855
2856/**
2857 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2858
2859 @ingroup ptn_create_or_alter_table_options
2860
2861 TABLE_CHECKSUM | Constructor parameter
2862 ---------------|----------------------
2863 0 | false
2864 not 0 | true
2865*/
2870
2871/**
2872 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2873
2874 @ingroup ptn_create_or_alter_table_options
2875*/
2878
2880
2881 public:
2882 /**
2883 @param pos Position of this clause in the SQL statement.
2884 @param engine Storage engine name.
2885 */
2887 const LEX_CSTRING &engine)
2888 : super(pos), engine(engine) {}
2889
2890 bool do_contextualize(Table_ddl_parse_context *pc) override;
2891};
2892
2893/**
2894 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2895 table option.
2896
2897 @ingroup ptn_create_or_alter_table_options
2898*/
2901
2902 public:
2904 : super(pos) {}
2906 const POS &pos, const LEX_CSTRING &secondary_engine)
2908
2909 bool do_contextualize(Table_ddl_parse_context *pc) override;
2910
2911 private:
2913};
2914
2915/**
2916 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2917
2918 @ingroup ptn_create_or_alter_table_options
2919*/
2922
2924
2925 public:
2926 /**
2927 @param pos Position of this clause in the SQL statement.
2928 @param value
2929 STATS_AUTO_RECALC | value
2930 ------------------|----------------------
2931 1 | Ternary_option::ON
2932 0 | Ternary_option::OFF
2933 DEFAULT | Ternary_option::DEFAULT
2934 */
2936 : super(pos), value(value) {}
2937
2938 bool do_contextualize(Table_ddl_parse_context *pc) override;
2939};
2940
2941/**
2942 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2943
2944 @ingroup ptn_create_or_alter_table_options
2945*/
2949
2951
2952 public:
2953 /**
2954 Constructor for implicit number of pages
2955
2956 @param pos Position of this clause in the SQL statement.
2957 @param value Number of pages, 1@<=N@<=65535.
2958 */
2960 : super(pos), value(value) {
2961 assert(value != 0 && value <= 0xFFFF);
2962 }
2963 /**
2964 Constructor for the DEFAULT number of pages
2965 */
2967 : super(pos), value(0) {} // DEFAULT
2968
2969 bool do_contextualize(Table_ddl_parse_context *pc) override;
2970};
2971
2974
2976
2977 public:
2978 explicit PT_create_union_option(const POS &pos,
2980 : super(pos), tables(tables) {}
2981
2982 bool do_contextualize(Table_ddl_parse_context *pc) override;
2983};
2984
2987
2989
2990 public:
2992 : super(pos), value(value) {}
2993
2995 if (super::do_contextualize(pc)) return true;
2997 return false;
2998 }
2999};
3000
3003
3005
3006 public:
3008 const CHARSET_INFO *value)
3009 : super(pos), value(value) {
3010 assert(value != nullptr);
3011 }
3012
3013 bool do_contextualize(Table_ddl_parse_context *pc) override;
3014};
3015
3018
3020
3021 public:
3023 const CHARSET_INFO *value)
3024 : super(pos), value(value) {
3025 assert(value != nullptr);
3026 }
3027
3028 bool do_contextualize(Table_ddl_parse_context *pc) override;
3029};
3030
3034
3035 public:
3036 explicit PT_check_constraint(const POS &pos, LEX_STRING &name, Item *expr,
3037 bool is_enforced)
3038 : super(pos) {
3039 cc_spec.name = name;
3040 cc_spec.check_expr = expr;
3041 cc_spec.is_enforced = is_enforced;
3042 }
3043
3044 bool do_contextualize(Table_ddl_parse_context *pc) override;
3045};
3046
3049
3053
3054 const char *opt_place;
3055
3056 public:
3060 const char *opt_place = nullptr)
3061 : super(pos),
3066
3067 bool do_contextualize(Table_ddl_parse_context *pc) override;
3068};
3069
3070/**
3071 Top-level node for the CREATE %TABLE statement
3072
3073 @ingroup ptn_create_table
3074*/
3085
3087
3088 public:
3089 /**
3090 @param pos Position of this clause in the SQL
3091 statement.
3092 @param mem_root MEM_ROOT to use for allocation
3093 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
3094 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
3095 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
3096 @param opt_table_element_list NULL or a list of table column and
3097 constraint definitions.
3098 @param opt_create_table_options NULL or a list of
3099 @ref ptn_create_or_alter_table_options
3100 "table options".
3101 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
3102 @param on_duplicate DUPLICATE, IGNORE or fail with an error
3103 on data duplication errors (relevant
3104 for @SQL{CREATE TABLE ... SELECT}
3105 statements).
3106 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
3107 */
3109 const POS &pos, MEM_ROOT *mem_root, bool is_temporary,
3125 /**
3126 @param pos Position of this clause in the SQL statement.
3127 @param mem_root MEM_ROOT to use for allocation
3128 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
3129 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
3130 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
3131 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
3132 */
3146
3147 Sql_cmd *make_cmd(THD *thd) override;
3148};
3149
3150class PT_create_role final : public Parse_tree_root {
3152
3153 public:
3154 PT_create_role(const POS &pos, bool if_not_exists,
3155 const List<LEX_USER> *roles)
3156 : Parse_tree_root(pos), sql_cmd(if_not_exists, roles) {}
3157
3158 Sql_cmd *make_cmd(THD *thd) override;
3159};
3160
3161class PT_drop_role final : public Parse_tree_root {
3163
3164 public:
3165 explicit PT_drop_role(const POS &pos, bool ignore_errors,
3166 const List<LEX_USER> *roles)
3167 : Parse_tree_root(pos), sql_cmd(ignore_errors, roles) {}
3168
3169 Sql_cmd *make_cmd(THD *thd) override;
3170};
3171
3174
3175 public:
3176 explicit PT_set_role(const POS &pos, role_enum role_type,
3177 const List<LEX_USER> *opt_except_roles = nullptr)
3178 : Parse_tree_root(pos), sql_cmd(role_type, opt_except_roles) {
3179 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
3180 }
3181 explicit PT_set_role(const POS &pos, const List<LEX_USER> *roles)
3182 : Parse_tree_root(pos), sql_cmd(roles) {}
3183
3184 Sql_cmd *make_cmd(THD *thd) override;
3185};
3186
3187/**
3188 This class is used for representing both static and dynamic privileges on
3189 global as well as table and column level.
3190*/
3193
3196
3199 : type(type), columns(columns) {}
3200};
3201
3203 const uint grant;
3204
3206 : Privilege(STATIC, columns_arg), grant(grant) {}
3207};
3208
3211
3213 const Mem_root_array<LEX_CSTRING> *columns_arg)
3214 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
3215};
3216
3218 private:
3220
3221 public:
3222 explicit PT_role_or_privilege(const POS &pos, const POS &errpos)
3223 : Parse_tree_node(pos), m_errpos(errpos) {}
3224 virtual LEX_USER *get_user(THD *thd);
3225 virtual Privilege *get_privilege(THD *thd);
3226};
3227
3231
3232 public:
3233 PT_role_at_host(const POS &pos, const POS &errpos, const LEX_STRING &role,
3234 const LEX_STRING &host)
3235 : PT_role_or_privilege(pos, errpos), role(role), host(host) {}
3236
3237 LEX_USER *get_user(THD *thd) override;
3238};
3239
3242
3243 public:
3244 PT_role_or_dynamic_privilege(const POS &pos, const POS &errpos,
3245 const LEX_STRING &ident)
3246 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3247
3248 LEX_USER *get_user(THD *thd) override;
3249 Privilege *get_privilege(THD *thd) override;
3250};
3251
3253 const uint grant;
3255
3256 public:
3257 PT_static_privilege(const POS &pos, const POS &errpos, uint grant,
3258 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
3259 : PT_role_or_privilege(pos, errpos), grant(grant), columns(columns) {}
3260
3261 Privilege *get_privilege(THD *thd) override;
3262};
3263
3266
3267 public:
3268 PT_dynamic_privilege(const POS &pos, const POS &errpos,
3269 const LEX_STRING &ident)
3270 : PT_role_or_privilege(pos, errpos), ident(ident) {}
3271
3272 Privilege *get_privilege(THD *thd) override;
3273};
3274
3275class PT_grant_roles final : public Parse_tree_root {
3279
3280 public:
3284 : Parse_tree_root(pos),
3285 roles(roles),
3286 users(users),
3288
3289 Sql_cmd *make_cmd(THD *thd) override;
3290};
3291
3292class PT_revoke_roles final : public Parse_tree_root {
3295
3296 public:
3298 const List<LEX_USER> *users)
3299 : Parse_tree_root(pos), roles(roles), users(users) {}
3300
3301 Sql_cmd *make_cmd(THD *thd) override;
3302};
3303
3306
3307 public:
3308 PT_alter_user_default_role(const POS &pos, bool if_exists,
3309 const List<LEX_USER> *users,
3310 const List<LEX_USER> *roles,
3311 const role_enum role_type)
3312 : Parse_tree_root(pos), sql_cmd(if_exists, users, roles, role_type) {}
3313
3314 Sql_cmd *make_cmd(THD *thd) override;
3315};
3316
3317/// Base class for Parse tree nodes of SHOW statements
3318
3320 protected:
3321 PT_show_base(const POS &pos, enum_sql_command sql_command)
3322 : Parse_tree_root(pos), m_sql_command(sql_command) {}
3323
3324 /// SQL command
3326};
3327
3328/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3329
3331 protected:
3333 const LEX_STRING &wild, Item *where)
3334 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3335 assert(m_wild.str == nullptr || m_where == nullptr);
3336 }
3337 /// Wild or where clause used in the statement.
3340};
3341
3342/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3343
3345 protected:
3347 char *opt_db, const LEX_STRING &wild, Item *where)
3348 : PT_show_base(pos, sql_command),
3350 m_wild(wild),
3351 m_where(where) {
3352 assert(m_wild.str == nullptr || m_where == nullptr);
3353 }
3354 /// Optional schema name in FROM/IN clause.
3356 /// Wild or where clause used in the statement.
3359};
3360
3361/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3362
3364 protected:
3365 PT_show_table_base(const POS &pos, enum_sql_command sql_command,
3366 Table_ident *table_ident, const LEX_STRING &wild,
3367 Item *where)
3368 : PT_show_filter_base(pos, sql_command, wild, where),
3369 m_table_ident(table_ident) {}
3370
3371 bool make_table_base_cmd(THD *thd, bool *temporary);
3372
3373 /// Table used in the statement.
3375};
3376
3377/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3378
3380 protected:
3382 const sp_name *routine_name)
3383 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3384
3385 Sql_cmd *make_cmd(THD *thd) override;
3386
3387 private:
3389};
3390
3391/// Parse tree node for SHOW BINLOG EVENTS statement
3392
3394 public:
3395 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3396 PT_limit_clause *opt_limit_clause = nullptr)
3398 m_opt_log_file_name(opt_log_file_name),
3399 m_opt_limit_clause(opt_limit_clause) {}
3400
3401 Sql_cmd *make_cmd(THD *thd) override;
3402
3403 private:
3406
3408};
3409
3410/// Parse tree node for SHOW BINLOGS statement
3411
3412class PT_show_binlogs final : public PT_show_base {
3413 public:
3415
3416 Sql_cmd *make_cmd(THD *thd) override;
3417
3418 private:
3420};
3421
3422/// Parse tree node for SHOW CHARACTER SET statement
3423
3425 public:
3426 PT_show_charsets(const POS &pos, const LEX_STRING &wild, Item *where)
3428
3429 Sql_cmd *make_cmd(THD *thd) override;
3430
3431 private:
3433};
3434
3435/// Parse tree node for SHOW COLLATIONS statement
3436
3438 public:
3439 PT_show_collations(const POS &pos, const LEX_STRING &wild, Item *where)
3441
3442 Sql_cmd *make_cmd(THD *thd) override;
3443
3444 private:
3446};
3447
3448/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3449/// statements.
3450
3452 public:
3453 explicit PT_show_count_base(const POS &pos)
3454 : PT_show_base{pos, SQLCOM_SELECT} {}
3455
3456 protected:
3457 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3458};
3459
3460/// Parse tree node for SHOW COUNT(*) ERRORS
3461
3463 public:
3464 explicit PT_show_count_errors(const POS &pos) : PT_show_count_base(pos) {}
3465
3466 Sql_cmd *make_cmd(THD *thd) override {
3467 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3468 }
3469};
3470
3471/// Parse tree node for SHOW COUNT(*) WARNINGS
3472
3474 public:
3475 explicit PT_show_count_warnings(const POS &pos) : PT_show_count_base(pos) {}
3476
3477 Sql_cmd *make_cmd(THD *thd) override {
3478 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3479 }
3480};
3481
3482/// Parse tree node for SHOW CREATE DATABASE statement
3483
3485 public:
3486 PT_show_create_database(const POS &pos, bool if_not_exists,
3487 const LEX_STRING &name)
3489 m_if_not_exists(if_not_exists),
3490 m_name(name) {}
3491
3492 Sql_cmd *make_cmd(THD *thd) override;
3493
3494 private:
3497
3499};
3500
3501/// Parse tree node for SHOW CREATE EVENT statement
3502
3504 public:
3505 PT_show_create_event(const POS &pos, sp_name *event_name)
3506 : PT_show_base(pos, SQLCOM_SHOW_CREATE_EVENT), m_spname(event_name) {}
3507
3508 Sql_cmd *make_cmd(THD *thd) override;
3509
3510 private:
3512
3514};
3515
3516/// Parse tree node for SHOW CREATE FUNCTION statement
3517
3519 public:
3520 PT_show_create_function(const POS &pos, sp_name *function_name)
3521 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3522
3523 Sql_cmd *make_cmd(THD *thd) override;
3524
3525 private:
3527
3529};
3530
3531/// Parse tree node for SHOW CREATE LIBRARY statement
3532
3534 public:
3535 PT_show_create_library(const POS &pos, sp_name *library_name)
3536 : PT_show_base(pos, SQLCOM_SHOW_CREATE_LIBRARY), m_spname(library_name) {}
3537
3538 Sql_cmd *make_cmd(THD *thd) override;
3539
3540 private:
3542
3544};
3545
3546/// Parse tree node for SHOW CREATE PROCEDURE statement
3547
3549 public:
3550 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3551 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3552
3553 Sql_cmd *make_cmd(THD *thd) override;
3554
3555 private:
3557
3559};
3560
3561/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3562
3564 public:
3565 PT_show_create_table(const POS &pos, Table_ident *table_ident)
3566 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3567
3568 Sql_cmd *make_cmd(THD *thd) override;
3569
3570 private:
3572};
3573
3574/// Parse tree node for SHOW CREATE TRIGGER statement
3575
3577 public:
3578 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3579 : PT_show_base(pos, SQLCOM_SHOW_CREATE_TRIGGER), m_spname(trigger_name) {}
3580
3581 Sql_cmd *make_cmd(THD *thd) override;
3582
3583 private:
3585
3587};
3588
3589/// Parse tree node for SHOW CREATE USER statement
3590
3591class PT_show_create_user final : public PT_show_base {
3592 public:
3595
3596 Sql_cmd *make_cmd(THD *thd) override;
3597
3598 private:
3600
3602};
3603
3604/// Parse tree node for SHOW CREATE VIEW statement
3605
3606class PT_show_create_view final : public PT_show_base {
3607 public:
3608 PT_show_create_view(const POS &pos, Table_ident *table_ident)
3609 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3610
3611 Sql_cmd *make_cmd(THD *thd) override;
3612
3613 private:
3615};
3616
3617/// Parse tree node for SHOW DATABASES statement
3618
3620 public:
3621 PT_show_databases(const POS &pos, const LEX_STRING &wild, Item *where)
3623
3624 Sql_cmd *make_cmd(THD *thd) override;
3625
3626 private:
3628};
3629
3630/// Parse tree node for SHOW ENGINE statements
3631
3633 protected:
3634 PT_show_engine_base(const POS &pos, enum enum_sql_command sql_command,
3635 const LEX_STRING opt_engine = {})
3636 : PT_show_base(pos, sql_command),
3637 m_engine(opt_engine),
3638 m_all(opt_engine.str == nullptr) {}
3639
3641 bool m_all;
3642};
3643
3644/// Parse tree node for SHOW ENGINE LOGS statement
3645
3647 public:
3648 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3649 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_LOGS, opt_engine) {}
3650
3651 Sql_cmd *make_cmd(THD *thd) override;
3652
3653 private:
3655};
3656
3657/// Parse tree node for SHOW ENGINE MUTEX statement
3658
3660 public:
3661 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3662 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_MUTEX, opt_engine) {}
3663
3664 Sql_cmd *make_cmd(THD *thd) override;
3665
3666 private:
3668};
3669
3670/// Parse tree node for SHOW ENGINE STATUS statement
3671
3673 public:
3674 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3675 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_STATUS, opt_engine) {}
3676
3677 Sql_cmd *make_cmd(THD *thd) override;
3678
3679 private:
3681};
3682
3683/// Parse tree node for SHOW ENGINES statement
3684
3685class PT_show_engines final : public PT_show_base {
3686 public:
3689
3690 Sql_cmd *make_cmd(THD *thd) override;
3691
3692 private:
3694};
3695
3696/// Parse tree node for SHOW ERRORS statement
3697
3698class PT_show_errors final : public PT_show_base {
3699 public:
3700 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3702 m_opt_limit_clause(opt_limit_clause) {}
3703
3704 Sql_cmd *make_cmd(THD *thd) override;
3705
3706 private:
3708
3710};
3711
3712/// Parse tree node for SHOW EVENTS statement
3713
3715 public:
3716 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3717 Item *where)
3719
3720 Sql_cmd *make_cmd(THD *thd) override;
3721
3722 private:
3724};
3725
3726/// Parse tree node for SHOW COLUMNS statement.
3727
3730
3731 public:
3732 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3733 Table_ident *table, LEX_STRING opt_wild = {},
3734 Item *opt_where = nullptr)
3735 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3736 m_show_cmd_type(show_cmd_type) {}
3737
3738 Sql_cmd *make_cmd(THD *thd) override;
3739
3740 private:
3743};
3744
3745/// Parse tree node for SHOW FUNCTION CODE statement.
3746
3748 public:
3749 PT_show_function_code(const POS &pos, const sp_name *function_name)
3750 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3751};
3752
3753/// Parse tree node for SHOW GRANTS statement.
3754
3755class PT_show_grants final : public PT_show_base {
3756 public:
3757 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3758 const List<LEX_USER> *opt_using_users)
3760 sql_cmd(opt_for_user, opt_using_users) {
3761 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3762 }
3763
3764 Sql_cmd *make_cmd(THD *thd) override;
3765
3766 private:
3768};
3769
3770/// Parse tree node for SHOW INDEX statement.
3771
3772class PT_show_keys final : public PT_show_table_base {
3773 public:
3774 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3775 Item *where)
3777 m_extended_show(extended_show) {}
3778
3779 Sql_cmd *make_cmd(THD *thd) override;
3780
3781 private:
3783
3784 // Flag to indicate EXTENDED keyword usage in the statement.
3787};
3788
3789/// Parse tree node for SHOW BINARY LOG STATUS statement
3790
3792 public:
3795
3796 Sql_cmd *make_cmd(THD *thd) override;
3797
3798 private:
3800};
3801
3802/// Parse tree node for SHOW OPEN TABLES statement
3803
3805 public:
3806 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3807 Item *where)
3809 }
3810
3811 Sql_cmd *make_cmd(THD *thd) override;
3812
3813 private:
3815};
3816
3817/// Parse tree node for SHOW PLUGINS statement
3818
3819class PT_show_plugins final : public PT_show_base {
3820 public:
3822
3823 Sql_cmd *make_cmd(THD *thd) override;
3824
3825 private:
3827};
3828
3829/// Parse tree node for SHOW PRIVILEGES statement
3830
3831class PT_show_privileges final : public PT_show_base {
3832 public:
3835
3836 Sql_cmd *make_cmd(THD *thd) override;
3837
3838 private:
3840};
3841
3842/// Parse tree node for SHOW PARSE_TREE statement
3843
3844class PT_show_parse_tree final : public PT_show_base {
3845 public:
3846 PT_show_parse_tree(const POS &pos, Parse_tree_root *parse_tree_stmt)
3848 m_parse_tree_stmt(parse_tree_stmt) {}
3849
3850 Sql_cmd *make_cmd(THD *thd) override;
3851
3852 private:
3855};
3856
3857/// Parse tree node for SHOW FUNCTION CODE statement.
3858
3860 public:
3861 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3862 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3863};
3864
3865/// Parse tree node for SHOW PROCESSLIST statement
3866
3867class PT_show_processlist final : public PT_show_base {
3868 public:
3871
3872 Sql_cmd *make_cmd(THD *thd) override;
3873
3874 private:
3876};
3877
3878/// Parse tree node for SHOW PROFILE statement
3879
3880class PT_show_profile final : public PT_show_base {
3881 public:
3882 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3883 my_thread_id opt_query_id = 0,
3884 PT_limit_clause *opt_limit_clause = nullptr)
3886 m_opt_profile_options(opt_profile_options),
3887 m_opt_query_id(opt_query_id),
3888 m_opt_limit_clause(opt_limit_clause) {}
3889
3890 Sql_cmd *make_cmd(THD *thd) override;
3891
3892 private:
3896
3898};
3899
3900/// Parse tree node for SHOW PROFILES statement
3901
3902class PT_show_profiles final : public PT_show_base {
3903 public:
3905
3906 Sql_cmd *make_cmd(THD *thd) override;
3907
3908 private:
3910};
3911
3912/// Parse tree node for SHOW RELAYLOG EVENTS statement
3913
3915 public:
3917 const LEX_STRING opt_log_file_name = {},
3918 PT_limit_clause *opt_limit_clause = nullptr,
3919 LEX_CSTRING opt_channel_name = {})
3921 m_opt_log_file_name(opt_log_file_name),
3922 m_opt_limit_clause(opt_limit_clause),
3923 m_opt_channel_name(opt_channel_name) {}
3924
3925 Sql_cmd *make_cmd(THD *thd) override;
3926
3927 private:
3931
3933};
3934
3935/// Parse tree node for SHOW REPLICAS statement
3936
3937class PT_show_replicas final : public PT_show_base {
3938 public:
3940
3941 Sql_cmd *make_cmd(THD *thd) override;
3942
3943 private:
3945};
3946
3947/// Parse tree node for SHOW REPLICA STATUS statement
3948
3950 public:
3951 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3953 m_opt_channel_name(opt_channel_name) {}
3954
3955 Sql_cmd *make_cmd(THD *thd) override;
3956
3957 private:
3959
3961};
3962
3963/// Parse tree node for SHOW STATUS statement
3964
3966 public:
3967 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3968 Item *where)
3970 m_var_type(var_type) {
3972 }
3973
3974 Sql_cmd *make_cmd(THD *thd) override;
3975
3976 private:
3978
3980};
3981
3982/// Parse tree node for SHOW STATUS FUNCTION statement
3983
3985 public:
3986 PT_show_status_func(const POS &pos, const LEX_STRING &wild, Item *where)
3988
3989 Sql_cmd *make_cmd(THD *thd) override;
3990
3991 private:
3993};
3994
3995/// Parse tree node for SHOW STATUS PROCEDURE statement
3996
3998 public:
3999 PT_show_status_proc(const POS &pos, const LEX_STRING &wild, Item *where)
4001
4002 Sql_cmd *make_cmd(THD *thd) override;
4003
4004 private:
4006};
4007
4008/// Parse tree node for SHOW TABLE STATUS statement
4009
4011 public:
4012 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
4013 Item *where)
4015 where) {}
4016
4017 Sql_cmd *make_cmd(THD *thd) override;
4018
4019 private:
4021};
4022
4023/// Parse tree node for SHOW TABLES statement
4024
4026 public:
4027 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
4028 const LEX_STRING &wild, Item *where)
4030 m_show_cmd_type(show_cmd_type) {}
4031
4032 Sql_cmd *make_cmd(THD *thd) override;
4033
4034 private:
4036
4038};
4039
4040/// Parse tree node for SHOW TRIGGERS statement
4041
4043 public:
4044 PT_show_triggers(const POS &pos, bool full, char *opt_db,
4045 const LEX_STRING &wild, Item *where)
4047 m_full(full) {}
4048
4049 Sql_cmd *make_cmd(THD *thd) override;
4050
4051 private:
4053
4055};
4056
4057/// Parse tree node for SHOW VARIABLES statement
4058
4060 public:
4062 const LEX_STRING &wild, Item *where)
4064 m_var_type(var_type) {
4066 }
4067
4068 Sql_cmd *make_cmd(THD *thd) override;
4069
4070 private:
4072
4074};
4075
4076/// Parse tree node for SHOW WARNINGS statement
4077
4078class PT_show_warnings final : public PT_show_base {
4079 public:
4080 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
4082 m_opt_limit_clause(opt_limit_clause) {}
4083
4084 Sql_cmd *make_cmd(THD *thd) override;
4085
4086 private:
4088
4090};
4091
4094
4095 protected:
4096 explicit PT_alter_table_action(const POS &pos,
4098 : super(pos), flag(flag) {}
4099
4100 public:
4101 bool do_contextualize(Table_ddl_parse_context *pc) override;
4102
4103 protected:
4104 /**
4105 A routine used by the parser to decide whether we are specifying a full
4106 partitioning or if only partitions to add or to reorganize.
4107
4108 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
4109 @retval false Something else.
4110 */
4114 }
4115
4116 public:
4118};
4119
4122
4123 public:
4124 PT_alter_table_add_column(const POS &pos, const LEX_STRING &field_ident,
4125 PT_field_def_base *field_def,
4126 PT_table_constraint_def *opt_column_constraint,
4127 const char *opt_place)
4128 : super(pos, Alter_info::ALTER_ADD_COLUMN),
4129 m_column_def(POS(), field_ident, field_def, opt_column_constraint,
4130 opt_place) {}
4131
4134 }
4135
4136 private:
4137 PT_column_def m_column_def; // TODO: Position is not set.
4138};
4139
4142
4143 public:
4145 const POS &pos, const Mem_root_array<PT_table_element *> *columns)
4146 : super(pos, Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
4147
4149 if (super::do_contextualize(pc)) return true;
4150
4151 for (auto *column : *m_columns)
4152 if (column->contextualize(pc)) return true;
4153
4154 return false;
4155 }
4156
4157 private:
4159};
4160
4163
4164 public:
4166 PT_table_constraint_def *constraint)
4167 : super(pos, Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
4168
4171 }
4172
4173 private:
4175};
4176
4179
4180 public:
4181 PT_alter_table_change_column(const POS &pos, const LEX_STRING &old_name,
4182 const LEX_STRING &new_name,
4183 PT_field_def_base *field_def,
4184 const char *opt_place)
4185 : super(pos, Alter_info::ALTER_CHANGE_COLUMN),
4186 m_old_name(old_name),
4187 m_new_name(new_name),
4188 m_field_def(field_def),
4189 m_opt_place(opt_place) {}
4190
4192 PT_field_def_base *field_def,
4193 const char *opt_place)
4194 : PT_alter_table_change_column(pos, name, name, field_def, opt_place) {}
4195
4196 bool do_contextualize(Table_ddl_parse_context *pc) override;
4197
4198 private:
4202 const char<