MySQL 8.0.32
Source Code Documentation
parse_tree_nodes.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef PARSE_TREE_NODES_INCLUDED
24#define PARSE_TREE_NODES_INCLUDED
25
26#include <assert.h>
27#include <sys/types.h> // TODO: replace with cstdint
28
29#include <cctype> // std::isspace
30#include <cstddef>
31#include <memory>
32
33#include "lex_string.h"
34#include "my_alloc.h"
35#include "my_base.h"
36#include "my_bit.h" // is_single_bit
37
38#include "my_inttypes.h" // TODO: replace with cstdint
39#include "my_sqlcommand.h"
40#include "my_sys.h"
41#include "my_thread_local.h"
42#include "my_time.h"
43#include "mysqld_error.h"
44#include "sql/check_stack.h"
45#include "sql/enum_query_type.h"
46#include "sql/handler.h"
47#include "sql/key_spec.h"
48#include "sql/mem_root_array.h"
49#include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
50#include "sql/parse_location.h"
51#include "sql/parse_tree_helpers.h" // PT_item_list
53#include "sql/parser_yystype.h"
54#include "sql/partition_info.h"
57#include "sql/set_var.h"
58#include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
59#include "sql/sql_alter.h"
60#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
61#include "sql/sql_cmd_srs.h"
62#include "sql/sql_exchange.h"
63#include "sql/sql_lex.h" // LEX
64#include "sql/sql_list.h"
65#include "sql/sql_load.h" // Sql_cmd_load_table
67#include "sql/sql_restart_server.h" // Sql_cmd_restart_server
68#include "sql/sql_tablespace.h" // Tablespace_options
69#include "sql/sql_truncate.h" // Sql_cmd_truncate_table
70#include "sql/table.h" // Common_table_expr
71#include "sql/window_lex.h"
72#include "thr_lock.h"
73
74class Item;
75class Item_cache;
79class PT_hint_list;
82class PT_partition;
83class PT_subquery;
84class PT_type;
85class PT_window_list;
86class Sql_cmd;
87class String;
88class THD;
89class Window;
90class sp_head;
91class sp_name;
92struct CHARSET_INFO;
93
94/**
95 @defgroup ptn Parse tree nodes
96 @ingroup Parser
97*/
98/**
99 @defgroup ptn_stmt Nodes representing SQL statements
100 @ingroup ptn
101*/
102/**
103 @defgroup ptn_create_table CREATE TABLE statement
104 @ingroup ptn_stmt
105*/
106/**
107 @defgroup ptn_alter_table ALTER TABLE statement
108 @ingroup ptn_stmt
109*/
110/**
111 @defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
112 @ingroup ptn_create_table
113*/
114/**
115 @defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
116 @ingroup ptn_create_table ptn_alter_table
117*/
118/**
119 @defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
120 @ingroup ptn_partitioning
121*/
122/**
123 @defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
124 TABLE
125 @anchor ptn_create_or_alter_table_options
126 @ingroup ptn_create_table ptn_alter_table
127*/
128/**
129 @defgroup ptn_col_types Column types in CREATE/ALTER TABLE
130 @ingroup ptn_create_table ptn_alter_table
131*/
132/**
133 @defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
134 @ingroup ptn_create_table ptn_alter_table
135*/
136/**
137 @defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
138 TABLE
139 @ingroup ptn_col_attrs ptn_alter_table
140*/
141
142/**
143 Calls contextualize() on every node in the array.
144*/
145template <class Node_type, class Parse_context_type>
147 Parse_context_type *pc) {
148 for (Node_type *i : nodes)
149 if (i->contextualize(pc)) return true;
150 return false;
151}
152
153/**
154 Base class for all top-level nodes of SQL statements
155
156 @ingroup ptn_stmt
157*/
160 void operator=(const Parse_tree_root &) = delete;
161
162 protected:
163 virtual ~Parse_tree_root() = default;
164 Parse_tree_root() = default;
165
166 public:
167 virtual Sql_cmd *make_cmd(THD *thd) = 0;
168};
169
171 public:
174
175 ~PT_table_ddl_stmt_base() override = 0; // force abstract class
176
177 protected:
179};
180
182
183/**
184 Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
185
186 For internal use in the contextualization code.
187*/
189 Table_ddl_parse_context(THD *thd_arg, Query_block *select_arg,
194};
195
196/**
197 Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
198*/
200
201class PT_order_expr : public Parse_tree_node, public ORDER {
203
204 public:
206 item_initial = item_arg;
208 }
209
210 bool contextualize(Parse_context *pc) override;
211};
212
215
216 public:
218
219 public:
220 bool contextualize(Parse_context *pc) override {
221 if (super::contextualize(pc)) return true;
222 for (ORDER *o = value.first; o != nullptr; o = o->next) {
223 if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
224 }
225 return false;
226 }
227
229 order->used_alias = false;
230 order->used = 0;
231 value.link_in_list(order, &order->next);
232 }
233};
234
237
238 public:
239 bool contextualize(Parse_context *pc) override {
240 return super::contextualize(pc);
241 }
242};
243
244/**
245 Represents an element of the WITH list:
246 WITH [...], [...] SELECT ...,
247 ^ or ^
248 i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
249*/
252
253 public:
254 explicit PT_common_table_expr(const LEX_STRING &name,
255 const LEX_STRING &subq_text,
256 uint subq_text_offset, PT_subquery *sn,
259
260 /// The name after AS
261 const LEX_STRING &name() const { return m_name; }
262 /**
263 @param thd Thread handler
264 @param[out] node PT_subquery
265 @returns a PT_subquery to attach to a table reference for this CTE
266 */
267 bool make_subquery_node(THD *thd, PT_subquery **node);
268 /**
269 @param tl Table reference to match
270 @param in_self If this is a recursive reference
271 @param[out] found Is set to true/false if matches or not
272 @returns true if error
273 */
274 bool match_table_ref(Table_ref *tl, bool in_self, bool *found);
275 /**
276 @returns true if 'other' is the same instance as 'this'
277 */
278 bool is(const Common_table_expr *other) const {
279 return other == &m_postparse;
280 }
281 void print(const THD *thd, String *str, enum_query_type query_type);
282
283 private:
285 /// Raw text of query expression (including parentheses)
287 /**
288 Offset in bytes of m_subq_text in original statement which had the WITH
289 clause.
290 */
292 /// Parsed version of subq_text
294 /// List of explicitly specified column names; if empty, no list.
296 /**
297 A Table_ref representing a CTE needs access to the WITH list
298 element it derives from. However, in order to:
299 - limit the members which Table_ref can access
300 - avoid including this header file everywhere Table_ref needs to
301 access these members, these members are relocated into a separate inferior
302 object whose declaration is in table.h, like that of Table_ref. It's
303 the "postparse" part. Table_ref accesses this inferior object only.
304 */
306
308};
309
310/**
311 Represents the WITH list.
312 WITH [...], [...] SELECT ...,
313 ^^^^^^^^^^^^
314*/
317
318 public:
319 /// @param mem_root where interior objects are allocated
323 return m_elements;
324 }
325
326 private:
328};
329
330/**
331 Represents the WITH clause:
332 WITH [...], [...] SELECT ...,
333 ^^^^^^^^^^^^^^^^^
334*/
337
338 public:
341
342 bool contextualize(Parse_context *pc) override;
343
344 /**
345 Looks up a table reference into the list of CTEs.
346 @param tl Table reference to look up
347 @param[out] found Is set to true/false if found or not
348 @returns true if error
349 */
350 bool lookup(Table_ref *tl, PT_common_table_expr **found);
351 /**
352 Call this to record in the WITH clause that we are contextualizing the
353 CTE definition inserted in table reference 'tl'.
354 @returns information which the caller must provide to
355 leave_parsing_definition().
356 */
358 auto old = m_most_inner_in_parsing;
360 return old;
361 }
364 }
365 void print(const THD *thd, String *str, enum_query_type query_type);
366
367 private:
368 /// All CTEs of this clause
369 const PT_with_list *const m_list;
370 /// True if the user has specified the RECURSIVE keyword.
371 const bool m_recursive;
372 /**
373 The innermost CTE reference which we're parsing at the
374 moment. Used to detect forward references, loops and recursiveness.
375 */
377
379};
380
383
384 public:
385 bool contextualize(Parse_context *pc) override;
386};
387
390
392
393 public:
394 PT_limit_clause(const Limit_options &limit_options_arg)
395 : limit_options(limit_options_arg) {}
396
397 bool contextualize(Parse_context *pc) override;
399};
400
401class PT_cross_join;
402class PT_joined_table;
403
405 public:
407
408 /**
409 Lets us build a parse tree top-down, which is necessary due to the
410 context-dependent nature of the join syntax. This function adds
411 the @<table_ref@> cross join as the left-most leaf in this join tree
412 rooted at this node.
413
414 @todo: comment on non-join PT_table_reference objects
415
416 @param cj This @<table ref@> will be added if it represents a cross join.
417
418 @return The new top-level join.
419 */
421};
422
425
428 const char *const opt_table_alias;
430
431 public:
433 List<String> *opt_use_partition_arg,
434 const LEX_CSTRING &opt_table_alias_arg,
435 List<Index_hint> *opt_key_definition_arg)
436 : table_ident(table_ident_arg),
437 opt_use_partition(opt_use_partition_arg),
438 opt_table_alias(opt_table_alias_arg.str),
439 opt_key_definition(opt_key_definition_arg) {}
440
441 bool contextualize(Parse_context *pc) override;
442};
443
445 public:
447};
448
451
452 public:
455 const LEX_STRING &table_alias)
456 : m_expr(expr),
457 m_path(path),
458 m_nested_columns(nested_cols),
459 m_table_alias(table_alias) {}
460
461 bool contextualize(Parse_context *pc) override;
462
463 private:
468};
469
472
474
475 public:
479
480 bool contextualize(Parse_context *pc) override;
481};
482
485
486 public:
487 PT_derived_table(bool lateral, PT_subquery *subquery,
488 const LEX_CSTRING &table_alias,
490
491 bool contextualize(Parse_context *pc) override;
492
493 private:
496 const char *const m_table_alias;
497 /// List of explicitly specified column names; if empty, no list.
499};
500
503
504 public:
506 : m_joined_table(joined_table) {}
507
508 bool contextualize(Parse_context *pc) override;
509
510 private:
512};
513
516
517 protected:
522
525
526 public:
527 PT_joined_table(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
529 : m_left_pt_table(tab1_node_arg),
530 m_join_pos(join_pos_arg),
531 m_type(type),
532 m_right_pt_table(tab2_node_arg) {
533 static_assert(is_single_bit(JTT_INNER), "not a single bit");
534 static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
535 static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
536 static_assert(is_single_bit(JTT_LEFT), "not a single bit");
537 static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
538
539 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
542 }
543
544 /**
545 Adds the cross join to this join operation. The cross join is nested as
546 the table reference on the left-hand side.
547 */
550 return this;
551 }
552
553 /// Adds the table reference as the right-hand side of this join.
555 assert(m_right_pt_table == nullptr);
556 m_right_pt_table = table;
557 }
558
559 bool contextualize(Parse_context *pc) override;
560
561 /// This class is being inherited, it should thus be abstract.
562 ~PT_joined_table() override = 0;
563
564 protected:
566};
567
568inline PT_joined_table::~PT_joined_table() = default;
569
572
573 public:
574 PT_cross_join(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
575 PT_joined_table_type Type_arg,
576 PT_table_reference *tab2_node_arg)
577 : PT_joined_table(tab1_node_arg, join_pos_arg, Type_arg, tab2_node_arg) {}
578
579 bool contextualize(Parse_context *pc) override;
580};
581
585
586 public:
587 PT_joined_table_on(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
589 PT_table_reference *tab2_node_arg, Item *on_arg)
590 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg), on(on_arg) {}
591
592 bool contextualize(Parse_context *pc) override;
593};
594
598
599 public:
601 const POS &join_pos_arg, PT_joined_table_type type,
602 PT_table_reference *tab2_node_arg,
603 List<String> *using_fields_arg)
604 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg),
605 using_fields(using_fields_arg) {}
606
607 /// A PT_joined_table_using without a list of columns denotes a natural join.
609 const POS &join_pos_arg, PT_joined_table_type type,
610 PT_table_reference *tab2_node_arg)
611 : PT_joined_table_using(tab1_node_arg, join_pos_arg, type, tab2_node_arg,
612 nullptr) {}
613
614 bool contextualize(Parse_context *pc) override;
615};
616
617class PT_group : public Parse_tree_node {
619
622
623 public:
624 PT_group(PT_order_list *group_list_arg, olap_type olap_arg)
625 : group_list(group_list_arg), olap(olap_arg) {}
626
627 bool contextualize(Parse_context *pc) override;
628};
629
630class PT_order : public Parse_tree_node {
632
633 public:
635 explicit PT_order(PT_order_list *order_list_arg)
636 : order_list(order_list_arg) {}
637
638 bool contextualize(Parse_context *pc) override;
639};
640
642 public:
645
646 bool contextualize(Parse_context *pc) final;
647
648 virtual bool set_lock_for_tables(Parse_context *pc) = 0;
649
651
652 protected:
654 thr_lock_type lock_type = TL_IGNORE;
655 switch (m_lock_strength) {
657 lock_type = TL_WRITE;
658 break;
660 lock_type = TL_READ_WITH_SHARED_LOCKS;
661 break;
662 }
663
664 return {lock_type, static_cast<thr_locked_row_action>(action())};
665 }
666
667 private:
670};
671
673 public:
675 Lock_strength strength,
677 : PT_locking_clause(strength, action) {}
678
679 bool set_lock_for_tables(Parse_context *pc) override;
680};
681
683 public:
685
689 : PT_locking_clause(strength, action), m_tables(tables) {}
690
691 bool set_lock_for_tables(Parse_context *pc) override;
692
693 private:
694 /// @todo Move this function to Table_ident?
695 void print_table_ident(const THD *thd, const Table_ident *ident, String *s);
696
697 bool raise_error(THD *thd, const Table_ident *name, int error);
698
699 bool raise_error(int error);
700
702};
703
705 public:
708 }
709
710 bool push_back(PT_locking_clause *locking_clause) {
711 return m_locking_clauses.push_back(locking_clause);
712 }
713
714 bool contextualize(Parse_context *pc) override {
715 for (auto locking_clause : m_locking_clauses)
716 if (locking_clause->contextualize(pc)) return true;
717 return false;
718 }
719
720 private:
722};
723
725 public:
726 virtual bool is_set_operation() const = 0;
727
728 /**
729 True if this query expression can absorb an extraneous order by/limit
730 clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
731 trailing clause may not refer to the tables in the `<query primary>`, with
732 one glaring exception:
733
734 (...( SELECT ... )...) ORDER BY ...
735
736 If the nested query expression doesn't contain `ORDER BY`, the statement
737 is interpreted as if the `ORDER BY` was absorbed by the innermost query
738 expression, i.e.:
739
740 (...( SELECT ... ORDER BY ... )...)
741
742 There is no rewriting of the parse tree nor AST happening here, the
743 transformation is done by the contextualizer (see
744 PT_query_expression::contextualize_order_and_limit), which interprets the
745 parse tree, and builds the AST according to this interpretation. This
746 interpretation is governed by the following rule: An `ORDER BY` can be
747 absorbed if none the nested query expressions contains an `ORDER BY` *or*
748 `LIMIT`. The rule is complex, so here are some examples for illustration:
749
750 In these cases the `ORDER BY` *is* absorbed:
751
752 ( SELECT * FROM t1 ) ORDER BY t1.a;
753 (( SELECT * FROM t1 )) ORDER BY t1.a;
754
755 In these cases the ORDER BY is *not* absorbed:
756
757 ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
758 (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
759 ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
760 (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
761
762 The same happens with `LIMIT`, obviously, but the optimizer is freeer to
763 choose when to apply the limit, and there are name no resolution issues
764 involved.
765
766 @param order True if the outer query block has the ORDER BY clause.
767 @param limit True if the outer query block has the LIMIT clause.
768 */
769 virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
770 virtual bool has_into_clause() const = 0;
771 virtual bool has_trailing_into_clause() const = 0;
772
773 virtual bool is_table_value_constructor() const = 0;
775};
776
779
780 public:
781 PT_set_scoped_system_variable(const POS &pos, const LEX_CSTRING &opt_prefix,
782 const LEX_CSTRING &name, Item *opt_expr)
783 : m_pos{pos},
784 m_opt_prefix{opt_prefix},
785 m_name{name},
786 m_opt_expr{opt_expr} {}
787
788 bool contextualize(Parse_context *pc) override;
789
790 private:
791 const POS m_pos;
795};
796
798
801
802 public:
803 PT_set_variable(const POS &pos, const LEX_CSTRING &opt_prefix,
804 const LEX_CSTRING &name, const POS &expr_pos, Item *opt_expr)
805 : m_pos{pos},
806 m_opt_prefix{opt_prefix},
807 m_name{name},
808 m_expr_pos{expr_pos},
809 m_opt_expr{opt_expr} {}
810
811 bool contextualize(Parse_context *pc) override;
812
813 private:
814 const POS m_pos;
819};
820
824
827
828 public:
830 Item *expr_arg)
831 : name(name_arg), expr(expr_arg) {}
832
833 bool contextualize(Parse_context *pc) override;
834};
835
838
839 public:
841 const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
842 Item *opt_expr)
843 : m_scope{scope},
844 m_name_pos{name_pos},
845 m_opt_prefix{opt_prefix},
846 m_name{name},
847 m_opt_expr{opt_expr} {}
848
849 bool contextualize(Parse_context *pc) override;
850
851 private:
857};
858
862
864
865 public:
867 : opt_charset(opt_charset_arg) {}
868
869 bool contextualize(Parse_context *pc) override;
870};
871
875
877
878 public:
880
881 bool contextualize(Parse_context *pc) override;
882};
883
886
889
890 public:
891 PT_set_names(const CHARSET_INFO *opt_charset_arg,
892 const CHARSET_INFO *opt_collation_arg)
893 : opt_charset(opt_charset_arg), opt_collation(opt_collation_arg) {}
894
895 bool contextualize(Parse_context *pc) override;
896};
897
899
903
904 const char *password;
905 const char *current_password;
909
910 public:
912 const char *current_password_arg,
913 bool retain_current,
914 bool random_password,
915 const POS &expr_pos_arg)
916 : password(password_arg),
917 current_password(current_password_arg),
918 retain_current_password(retain_current),
919 random_password_generator(random_password),
920 expr_pos(expr_pos_arg) {}
921
922 bool contextualize(Parse_context *pc) override;
923};
924
928
930 const char *password;
931 const char *current_password;
935
936 public:
938 const char *password_arg,
939 const char *current_password_arg,
940 bool retain_current,
941 bool random_pass,
942 const POS &expr_pos_arg)
943 : user(user_arg),
944 password(password_arg),
945 current_password(current_password_arg),
946 retain_current_password(retain_current),
947 random_password_generator(random_pass),
948 expr_pos(expr_pos_arg) {}
949
950 bool contextualize(Parse_context *pc) override;
951};
952
955
958
959 public:
962 : type(type_arg), value(value_arg) {}
963
964 bool contextualize(Parse_context *pc) override;
965};
966
969
973
974 public:
975 PT_option_value_list_head(const POS &delimiter_pos_arg,
976 Parse_tree_node *value_arg,
977 const POS &value_pos_arg)
978 : delimiter_pos(delimiter_pos_arg),
979 value(value_arg),
980 value_pos(value_pos_arg) {}
981
982 bool contextualize(Parse_context *pc) override;
983};
984
987
989
990 public:
992 const POS &delimiter_pos_arg, Parse_tree_node *tail,
993 const POS &tail_pos)
994 : super(delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
995
996 bool contextualize(Parse_context *pc) override {
997 uchar dummy;
998 if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
999 return head->contextualize(pc) || super::contextualize(pc);
1000 }
1001};
1002
1005
1009
1010 public:
1012 const POS &head_pos_arg,
1013 PT_option_value_list_head *tail_arg)
1014 : head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1015
1016 bool contextualize(Parse_context *pc) override;
1017};
1018
1021
1022 const char *name;
1024
1025 public:
1026 PT_transaction_characteristic(const char *name_arg, int32 value_arg)
1027 : name(name_arg), value(value_arg) {}
1028
1029 bool contextualize(Parse_context *pc) override;
1030};
1031
1034
1035 public:
1036 explicit PT_transaction_access_mode(bool is_read_only)
1037 : super("transaction_read_only", (int32)is_read_only) {}
1038};
1039
1042
1043 public:
1045 : super("transaction_isolation", (int32)level) {}
1046};
1047
1050
1053
1054 public:
1056 PT_transaction_characteristic *opt_tail_arg)
1057 : head(head_arg), opt_tail(opt_tail_arg) {}
1058
1059 bool contextualize(Parse_context *pc) override {
1060 return (super::contextualize(pc) || head->contextualize(pc) ||
1061 (opt_tail != nullptr && opt_tail->contextualize(pc)));
1062 }
1063};
1064
1068
1071
1072 public:
1074 PT_transaction_characteristics *characteristics_arg,
1075 const POS &end_pos_arg)
1076 : characteristics(characteristics_arg), end_pos(end_pos_arg) {}
1077
1078 bool contextualize(Parse_context *pc) override;
1079};
1080
1082 : public Parse_tree_node {};
1083
1087
1091
1092 public:
1094 PT_set_scoped_system_variable *head_arg, const POS &head_pos_arg,
1095 PT_option_value_list_head *opt_tail_arg)
1096 : head(head_arg), head_pos(head_pos_arg), opt_tail(opt_tail_arg) {}
1097
1098 bool contextualize(Parse_context *pc) override;
1099};
1100
1104
1107
1108 public:
1110 PT_transaction_characteristics *characteristics_arg,
1111 const POS &characteristics_pos_arg)
1112 : characteristics(characteristics_arg),
1113 characteristics_pos(characteristics_pos_arg) {}
1114
1115 bool contextualize(Parse_context *pc) override;
1116};
1117
1120
1123
1124 public:
1126 enum_var_type type_arg,
1128 : type(type_arg), list(list_arg) {}
1129
1130 bool contextualize(Parse_context *pc) override;
1131};
1132
1133class PT_set : public Parse_tree_node {
1135
1138
1139 public:
1140 PT_set(const POS &set_pos_arg, PT_start_option_value_list *list_arg)
1141 : set_pos(set_pos_arg), list(list_arg) {}
1142
1143 bool contextualize(Parse_context *pc) override;
1144};
1145
1149
1150 protected:
1151 PT_into_destination(const POS &pos) : m_pos(pos) {}
1152
1153 public:
1154 bool contextualize(Parse_context *pc) override;
1155};
1156
1159
1160 public:
1161 PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1162 const CHARSET_INFO *charset_arg,
1163 const Field_separators &field_term_arg,
1164 const Line_separators &line_term_arg)
1165 : PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
1166 m_exchange.cs = charset_arg;
1167 m_exchange.field.merge_field_separators(field_term_arg);
1168 m_exchange.line.merge_line_separators(line_term_arg);
1169 }
1170
1171 bool contextualize(Parse_context *pc) override;
1172
1173 private:
1175};
1176
1179
1180 public:
1181 PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1182 : PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
1183
1184 bool contextualize(Parse_context *pc) override;
1185
1186 private:
1188};
1189
1191 public:
1193
1194 explicit PT_select_var(const LEX_STRING &name_arg) : name(name_arg) {}
1195
1196 virtual bool is_local() const { return false; }
1197 virtual uint get_offset() const {
1198 assert(0);
1199 return 0;
1200 }
1201};
1202
1205
1207
1208#ifndef NDEBUG
1209 /*
1210 Routine to which this Item_splocal belongs. Used for checking if correct
1211 runtime context is used for variable handling.
1212 */
1214#endif
1215
1216 public:
1217 PT_select_sp_var(const LEX_STRING &name_arg) : super(name_arg) {}
1218
1219 bool is_local() const override { return true; }
1220 uint get_offset() const override { return offset; }
1221
1222 bool contextualize(Parse_context *pc) override;
1223};
1224
1227
1228 public:
1229 explicit PT_select_var_list(const POS &pos) : PT_into_destination(pos) {}
1230
1232
1233 bool contextualize(Parse_context *pc) override;
1234
1235 bool push_back(PT_select_var *var) { return value.push_back(var); }
1236};
1237
1238/**
1239 Parse tree node for a single of a window extent's borders,
1240 cf. <window frame extent> in SQL 2003.
1241*/
1243 friend class Window;
1244 Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1245 public:
1247 const bool m_date_time;
1249
1250 ///< For unbounded border
1252 : m_border_type(type), m_date_time(false) {
1254 }
1255
1256 ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1258 : m_value(value), m_border_type(type), m_date_time(false) {}
1259
1260 ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1262 : m_value(value),
1264 m_date_time(true),
1265 m_int_type(int_type) {}
1266
1267 ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1268 Item *border() const { return m_value; }
1269 /// Need such low-level access so that fix_fields updates the right pointer
1270 Item **border_ptr() { return &m_value; }
1271
1272 /**
1273 @returns Addition operator for computation of frames, nullptr if error.
1274 @param order_expr Expression to add to/subtract from
1275 @param prec true if PRECEDING
1276 @param asc true if ASC
1277 @param window only used for error generation
1278 */
1279 Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1280 const Window *window);
1281};
1282
1283/**
1284 Parse tree node for one or both of a window extent's borders, cf.
1285 <window frame extent> in SQL 2003.
1286*/
1289 friend class PT_frame;
1290
1291 public:
1292 /**
1293 Constructor.
1294
1295 Frames of the form "frame_start no_frame_end" are translated during
1296 parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1297 'end' are non-nullptr.
1298 */
1300 m_borders[0] = start;
1301 m_borders[1] = end;
1302 }
1303};
1304
1305/**
1306 Parse tree node for a window frame's exclusions, cf. the
1307 <window frame exclusion> clause in SQL 2003.
1308*/
1311
1312 public:
1314 // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1315};
1316
1317/**
1318 Parse tree node for a window's frame, cf. the <window frame clause>
1319 in SQL 2003.
1320*/
1322 public:
1324
1327
1329
1330 /// If true, this is an artificial frame, not specified by the user
1332
1334 PT_exclusion *exclusion)
1335 : m_query_expression(unit),
1336 m_from(from_to->m_borders[0]),
1337 m_to(from_to->m_borders[1]),
1338 m_exclusion(exclusion) {}
1339};
1340
1342
1345
1356
1357 public:
1359 PT_hint_list *opt_hints_arg, const Query_options &options_arg,
1360 PT_item_list *item_list_arg, PT_into_destination *opt_into1_arg,
1361 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1362 Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1363 Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
1364 bool implicit_from_clause)
1365 : opt_hints(opt_hints_arg),
1366 options(options_arg),
1367 item_list(item_list_arg),
1368 opt_into1(opt_into1_arg),
1369 m_is_from_clause_implicit{implicit_from_clause},
1370 from_clause(from_clause_arg),
1371 opt_where_clause(opt_where_clause_arg),
1372 opt_group_clause(opt_group_clause_arg),
1373 opt_having_clause(opt_having_clause_arg),
1374 opt_window_clause(opt_window_clause_arg) {
1375 assert(implicit_from_clause ? from_clause.empty() : true);
1376 }
1377
1379 const Query_options &options_arg, PT_item_list *item_list_arg,
1380 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1381 Item *opt_where_clause_arg)
1382 : opt_hints(nullptr),
1383 options(options_arg),
1384 item_list(item_list_arg),
1387 from_clause(from_clause_arg),
1388 opt_where_clause(opt_where_clause_arg),
1392
1394 PT_item_list *item_list_arg)
1395 : opt_hints(nullptr),
1396 options(options_arg),
1397 item_list(item_list_arg),
1400 from_clause{},
1405
1406 bool contextualize(Parse_context *pc) override;
1407
1408 bool has_into_clause() const override { return opt_into1 != nullptr; }
1409 bool has_trailing_into_clause() const override {
1411 opt_where_clause == nullptr && opt_group_clause == nullptr &&
1412 opt_having_clause == nullptr && opt_window_clause == nullptr);
1413 }
1414
1415 bool is_set_operation() const override { return false; }
1416
1417 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1418
1419 bool is_table_value_constructor() const override { return false; }
1420 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1421
1422 private:
1424};
1425
1428
1430
1431 public:
1433 : row_value_list(row_value_list_arg) {}
1434
1435 bool contextualize(Parse_context *pc) override;
1436
1437 bool has_into_clause() const override { return false; }
1438 bool has_trailing_into_clause() const override { return false; }
1439
1440 bool is_set_operation() const override { return false; }
1441
1442 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1443
1444 bool is_table_value_constructor() const override { return true; }
1445
1447 return row_value_list;
1448 }
1449};
1450
1453
1454 public:
1456 const Query_options &options_arg, PT_item_list *item_list_arg,
1457 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1458 : super(options_arg, item_list_arg, from_clause_arg, nullptr) {}
1459};
1460
1462 public:
1464 PT_query_expression_body *body, PT_order *order,
1465 PT_limit_clause *limit)
1466 : m_body(body),
1467 m_order(order),
1468 m_limit(limit),
1469 m_with_clause(with_clause) {}
1470
1472 PT_limit_clause *limit)
1473 : PT_query_expression(nullptr, body, order, limit) {}
1474
1477
1478 bool contextualize(Parse_context *pc) override;
1479
1480 bool is_set_operation() const override { return m_body->is_set_operation(); }
1481
1482 bool has_into_clause() const override { return m_body->has_into_clause(); }
1483 bool has_trailing_into_clause() const override {
1484 return (m_body->has_trailing_into_clause() && m_order == nullptr &&
1485 m_limit == nullptr);
1486 }
1487
1488 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1489 if (m_body->is_set_operation()) {
1490 return false;
1491 }
1492 if (m_order == nullptr && m_limit == nullptr) {
1493 /*
1494 It is safe to push ORDER and/or LIMIT down in:
1495
1496 (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1497 (SELECT ...<no order or limit clauses>) ORDER BY ...;
1498 (SELECT ...<no order or limit clauses>) LIMIT ...;
1499 */
1500 return true;
1501 }
1502 if (m_limit != nullptr && !order && limit) {
1503 /*
1504 In MySQL, it is ok(*) to push LIMIT down in:
1505
1506 (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1507
1508 *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1509 `LIMIT b` if a < b. Moreover, the result of:
1510
1511 (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1512
1513 can diverge from:
1514
1515 (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1516
1517 since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1518 while the example (2) does overwrite.
1519
1520 TODO: add a warning, deprecate and replace this behavior with the
1521 standard one.
1522 */
1523 return true;
1524 }
1525 if (m_order != nullptr && m_limit == nullptr && !order && limit) {
1526 /*
1527 Allow pushdown of LIMIT into body with ORDER BY, e.g
1528
1529 (SELECT ... ORDER BY order1) LIMIT a;
1530 */
1531 return true;
1532 }
1533 return false;
1534 }
1535
1536 bool is_table_value_constructor() const override {
1538 }
1539
1541 return m_body->get_row_value_list();
1542 }
1543
1544 private:
1545 /**
1546 Contextualizes the order and limit clauses, re-interpreting them according
1547 to the rules. If the `<query expression body>` can absorb the clauses,
1548 they are simply contextualized into the current Query_block. If not, we
1549 have to create the "fake" Query_block unless there is one already
1550 (Query_expression::new_set_operation_query() is known to do this.)
1551
1552 @see PT_query_expression::can_absorb_order_and_limit()
1553 */
1555
1560};
1561
1562/*
1563 After the removal of the `... <locking_clause> <into_clause>` syntax
1564 PT_locking will disappear.
1565*/
1568
1569 public:
1571 PT_locking_clause_list *locking_clauses)
1572 : m_query_expression{qe}, m_locking_clauses{locking_clauses} {}
1573
1574 bool contextualize(Parse_context *pc) override {
1577 }
1578
1579 bool is_set_operation() const override {
1581 }
1582
1583 bool has_into_clause() const override {
1585 }
1586 bool has_trailing_into_clause() const override { return false; }
1587
1588 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1589 return m_query_expression->can_absorb_order_and_limit(order, limit);
1590 }
1591
1592 bool is_table_value_constructor() const override {
1594 }
1595
1598 }
1599
1600 private:
1603};
1604
1607
1611
1612 public:
1614
1616 : qe(query_expression),
1617 pos(p),
1619 m_is_derived_table(false) {}
1620
1621 bool contextualize(Parse_context *pc) override;
1622
1624};
1625
1628
1629 public:
1632 bool is_rhs_in_parentheses = false)
1633 : m_lhs(lhs),
1634 m_is_distinct(is_distinct),
1635 m_rhs(rhs),
1636 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {}
1637
1639 QueryLevel &ql);
1640 bool is_set_operation() const override { return true; }
1641
1642 bool has_into_clause() const override {
1644 }
1645 bool has_trailing_into_clause() const override {
1647 }
1648
1649 bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1650
1651 bool is_table_value_constructor() const override { return false; }
1652 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1653
1654 protected:
1656 Surrounding_context context);
1662};
1663
1666
1667 public:
1669 bool contextualize(Parse_context *pc) override;
1670};
1671
1674
1675 public:
1677 bool contextualize(Parse_context *pc) override;
1678};
1679
1682
1683 public:
1685 bool contextualize(Parse_context *pc) override;
1686};
1687
1690
1691 public:
1692 /**
1693 @param qe The query expression.
1694 @param sql_command The type of SQL command.
1695 */
1697 : m_sql_command(sql_command),
1698 m_qe(qe),
1699 m_into(nullptr),
1701
1702 /**
1703 Creates a SELECT command. Only SELECT commands can have into.
1704
1705 @param qe The query expression.
1706 @param into The own INTO destination.
1707 @param has_trailing_locking_clauses True if there are locking clauses (like
1708 `FOR UPDATE`) at the end of the
1709 statement.
1710 */
1712 PT_into_destination *into = nullptr,
1713 bool has_trailing_locking_clauses = false)
1715 m_qe{qe},
1716 m_into{into},
1717 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1718
1719 Sql_cmd *make_cmd(THD *thd) override;
1720
1721 private:
1726};
1727
1728/**
1729 Top-level node for the DELETE statement
1730
1731 @ingroup ptn_stmt
1732*/
1733class PT_delete final : public Parse_tree_root {
1734 private:
1739 const char *const opt_table_alias;
1747
1748 public:
1749 // single-table DELETE node constructor:
1750 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1751 int opt_delete_options_arg, Table_ident *table_ident_arg,
1752 const LEX_CSTRING &opt_table_alias_arg,
1753 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1754 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1755 : m_with_clause(with_clause_arg),
1756 opt_hints(opt_hints_arg),
1757 opt_delete_options(opt_delete_options_arg),
1758 table_ident(table_ident_arg),
1759 opt_table_alias(opt_table_alias_arg.str),
1760 opt_use_partition(opt_use_partition_arg),
1761 opt_where_clause(opt_where_clause_arg),
1762 opt_order_clause(opt_order_clause_arg),
1763 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1765 join_table_list.init_empty_const();
1766 }
1767
1768 // multi-table DELETE node constructor:
1769 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1770 int opt_delete_options_arg,
1771 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1772 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1773 Item *opt_where_clause_arg)
1774 : m_with_clause(with_clause_arg),
1775 opt_hints(opt_hints_arg),
1776 opt_delete_options(opt_delete_options_arg),
1779 table_list(table_list_arg),
1781 join_table_list(join_table_list_arg),
1782 opt_where_clause(opt_where_clause_arg),
1785
1786 Sql_cmd *make_cmd(THD *thd) override;
1787
1788 private:
1789 bool is_multitable() const {
1790 assert((table_ident != nullptr) ^ (table_list.size() > 0));
1791 return table_ident == nullptr;
1792 }
1793
1794 bool add_table(Parse_context *pc, Table_ident *table);
1795};
1796
1797/**
1798 Top-level node for the UPDATE statement
1799
1800 @ingroup ptn_stmt
1801*/
1813
1814 public:
1815 PT_update(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1816 thr_lock_type opt_low_priority_arg, bool opt_ignore_arg,
1817 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1818 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
1819 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
1820 Item *opt_limit_clause_arg)
1821 : m_with_clause(with_clause_arg),
1822 opt_hints(opt_hints_arg),
1823 opt_low_priority(opt_low_priority_arg),
1824 opt_ignore(opt_ignore_arg),
1825 join_table_list(join_table_list_arg),
1826 column_list(column_list_arg),
1827 value_list(value_list_arg),
1828 opt_where_clause(opt_where_clause_arg),
1829 opt_order_clause(opt_order_clause_arg),
1830 opt_limit_clause(opt_limit_clause_arg) {}
1831
1832 Sql_cmd *make_cmd(THD *thd) override;
1833};
1834
1837
1839
1840 public:
1842
1843 bool contextualize(Parse_context *pc) override;
1844
1846 many_values.push_back(x);
1847 return false;
1848 }
1849
1851 assert(is_contextualized());
1852 return many_values;
1853 }
1854};
1855
1856/**
1857 Top-level node for the INSERT statement
1858
1859 @ingroup ptn_stmt
1860*/
1861class PT_insert final : public Parse_tree_root {
1862 const bool is_replace;
1865 const bool ignore;
1871 const char *const opt_values_table_alias;
1875
1876 public:
1877 PT_insert(bool is_replace_arg, PT_hint_list *opt_hints_arg,
1878 thr_lock_type lock_option_arg, bool ignore_arg,
1879 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
1880 PT_item_list *column_list_arg,
1881 PT_insert_values_list *row_value_list_arg,
1882 PT_query_expression_body *insert_query_expression_arg,
1883 const LEX_CSTRING &opt_values_table_alias_arg,
1884 Create_col_name_list *opt_values_column_list_arg,
1885 PT_item_list *opt_on_duplicate_column_list_arg,
1886 PT_item_list *opt_on_duplicate_value_list_arg)
1887 : is_replace(is_replace_arg),
1888 opt_hints(opt_hints_arg),
1889 lock_option(lock_option_arg),
1890 ignore(ignore_arg),
1891 table_ident(table_ident_arg),
1892 opt_use_partition(opt_use_partition_arg),
1893 column_list(column_list_arg),
1894 row_value_list(row_value_list_arg),
1895 insert_query_expression(insert_query_expression_arg),
1896 opt_values_table_alias(opt_values_table_alias_arg.str),
1897 opt_values_column_list(opt_values_column_list_arg),
1898 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
1899 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
1900 // REPLACE statement can't have IGNORE flag:
1901 assert(!is_replace || !ignore);
1902 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
1903 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
1904 // INSERT/REPLACE ... SELECT can't have VALUES clause:
1905 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
1906 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
1907 assert((opt_on_duplicate_column_list == nullptr &&
1908 opt_on_duplicate_value_list == nullptr) ||
1911 }
1912
1913 Sql_cmd *make_cmd(THD *thd) override;
1914
1915 private:
1916 bool has_query_block() const { return insert_query_expression != nullptr; }
1917};
1918
1919class PT_call final : public Parse_tree_root {
1922
1923 public:
1924 PT_call(sp_name *proc_name_arg, PT_item_list *opt_expr_list_arg)
1925 : proc_name(proc_name_arg), opt_expr_list(opt_expr_list_arg) {}
1926
1927 Sql_cmd *make_cmd(THD *thd) override;
1928};
1929
1930/**
1931 Top-level node for the SHUTDOWN statement
1932
1933 @ingroup ptn_stmt
1934*/
1935class PT_shutdown final : public Parse_tree_root {
1937
1938 public:
1939 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
1940};
1941
1942/**
1943 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
1944
1945 @ingroup ptn_stmt
1946*/
1947class PT_create_srs final : public Parse_tree_root {
1948 /// The SQL command object.
1950 /// Whether OR REPLACE is specified.
1952 /// Whether IF NOT EXISTS is specified.
1954 /// SRID of the SRS to create.
1955 ///
1956 /// The range is larger than that of gis::srid_t, so it must be
1957 /// verified to be less than the uint32 maximum value.
1958 unsigned long long m_srid;
1959 /// All attributes except SRID.
1961
1962 /// Check if a UTF-8 string contains control characters.
1963 ///
1964 /// @note This function only checks single byte control characters (U+0000 to
1965 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
1966 /// that are not detected by this function.
1967 ///
1968 /// @param str The string.
1969 /// @param length Length of the string.
1970 ///
1971 /// @retval false The string contains no control characters.
1972 /// @retval true The string contains at least one control character.
1973 bool contains_control_char(char *str, size_t length) {
1974 for (size_t pos = 0; pos < length; pos++) {
1975 if (std::iscntrl(str[pos])) return true;
1976 }
1977 return false;
1978 }
1979
1980 public:
1981 PT_create_srs(unsigned long long srid,
1982 const Sql_cmd_srs_attributes &attributes, bool or_replace,
1983 bool if_not_exists)
1984 : m_or_replace(or_replace),
1985 m_if_not_exists(if_not_exists),
1986 m_srid(srid),
1987 m_attributes(attributes) {}
1988
1989 Sql_cmd *make_cmd(THD *thd) override;
1990};
1991
1992/**
1993 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
1994
1995 @ingroup ptn_stmt
1996*/
1997class PT_drop_srs final : public Parse_tree_root {
1998 /// The SQL command object.
2000 /// SRID of the SRS to drop.
2001 ///
2002 /// The range is larger than that of gis::srid_t, so it must be
2003 /// verified to be less than the uint32 maximum value.
2004 unsigned long long m_srid;
2005
2006 public:
2007 PT_drop_srs(unsigned long long srid, bool if_exists)
2008 : sql_cmd(srid, if_exists), m_srid(srid) {}
2009
2010 Sql_cmd *make_cmd(THD *thd) override;
2011};
2012
2013/**
2014 Top-level node for the ALTER INSTANCE statement
2015
2016 @ingroup ptn_stmt
2017*/
2020
2021 public:
2023 enum alter_instance_action_enum alter_instance_action,
2024 const LEX_CSTRING &channel)
2025 : sql_cmd(alter_instance_action, channel) {}
2026
2027 Sql_cmd *make_cmd(THD *thd) override;
2028};
2029
2030/**
2031 A template-free base class for index options that we can predeclare in
2032 sql_lex.h
2033*/
2035
2036/**
2037 A key part specification.
2038
2039 This can either be a "normal" key part (a key part that points to a column),
2040 or this can be a functional key part (a key part that points to an
2041 expression).
2042*/
2045
2046 public:
2047 /**
2048 Constructor for a functional key part.
2049
2050 @param expression The expression to index.
2051 @param order The direction of the index.
2052 */
2053 PT_key_part_specification(Item *expression, enum_order order);
2054
2055 /**
2056 Constructor for a "normal" key part. That is a key part that points to a
2057 column and not an expression.
2058
2059 @param column_name The column name that this key part points to.
2060 @param order The direction of the index.
2061 @param prefix_length How many bytes or characters this key part should
2062 index, or zero if it should index the entire column.
2063 */
2064 PT_key_part_specification(const LEX_CSTRING &column_name, enum_order order,
2065 int prefix_length);
2066
2067 /**
2068 Contextualize this key part specification. This will also call itemize on
2069 the indexed expression if this is a functional key part.
2070
2071 @param pc The parse context
2072
2073 @retval true on error
2074 @retval false on success
2075 */
2076 bool contextualize(Parse_context *pc) override;
2077
2078 /**
2079 Get the indexed expression. The caller must ensure that has_expression()
2080 returns true before calling this.
2081
2082 @returns The indexed expression
2083 */
2085 assert(has_expression());
2086 return m_expression;
2087 }
2088
2089 /**
2090 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2091 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2092 direction.
2093 */
2094 enum_order get_order() const { return m_order; }
2095
2096 /**
2097 @retval true if the user explicitly specified a direction (asc/desc).
2098 @retval false if the user didn't explicitly specify a direction.
2099 */
2100 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2101
2102 /**
2103 @retval true if the key part contains an expression (and thus is a
2104 functional key part).
2105 @retval false if the key part doesn't contain an expression.
2106 */
2107 bool has_expression() const { return m_expression != nullptr; }
2108
2109 /**
2110 Get the column that this key part points to. This is only valid if this
2111 key part isn't a functional index. The caller must thus check the return
2112 value of has_expression() before calling this function.
2113
2114 @returns The column that this key part points to.
2115 */
2117 assert(!has_expression());
2118 return m_column_name;
2119 }
2120
2121 /**
2122 @returns The number of bytes that this key part should index. If the column
2123 this key part points to is a non-binary column, this is the number
2124 of characters. Returns zero if the entire column should be indexed.
2125 */
2126 int get_prefix_length() const { return m_prefix_length; }
2127
2128 private:
2129 /**
2130 The indexed expression in case this is a functional key part. Only valid if
2131 has_expression() returns true.
2132 */
2134
2135 /// The direction of the index.
2137
2138 /// The name of the column that this key part indexes.
2140
2141 /**
2142 If this is greater than zero, it represents how many bytes of the column
2143 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2144 is the number of characters.
2145 */
2147};
2148
2149/**
2150 A template for options that set a single `<alter option>` value in
2151 thd->lex->key_create_info.
2152
2153 @tparam Option_type The data type of the option.
2154 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2155*/
2156template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2158 public:
2159 /// @param option_value The value of the option.
2160 PT_index_option(Option_type option_value) : m_option_value(option_value) {}
2161
2164 return false;
2165 }
2166
2167 private:
2168 Option_type m_option_value;
2169};
2170
2171/**
2172 A template for options that set a single property in a KEY_CREATE_INFO, and
2173 also records if the option was explicitly set.
2174*/
2175template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2176 bool KEY_CREATE_INFO::*Property_is_explicit>
2178 public:
2179 PT_traceable_index_option(Option_type option_value)
2180 : m_option_value(option_value) {}
2181
2184 pc->key_create_info->*Property_is_explicit = true;
2185 return false;
2186 }
2187
2188 private:
2189 Option_type m_option_value;
2190};
2191
2199
2200/**
2201 The data structure (B-tree, Hash, etc) used for an index is called
2202 'index_type' in the manual. Internally, this is stored in
2203 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2204 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2205 it's ignored. The terminology is somewhat confusing, but we stick to the
2206 manual in the parser.
2207*/
2211
2213 public:
2215 const LEX_STRING &name_arg, PT_base_index_option *type,
2216 Table_ident *table_ident,
2222 m_keytype(type_par),
2223 m_name(name_arg),
2224 m_type(type),
2225 m_table_ident(table_ident),
2226 m_columns(cols),
2228 m_algo(algo),
2229 m_lock(lock) {}
2230
2231 Sql_cmd *make_cmd(THD *thd) override;
2232
2233 private:
2242};
2243
2244/**
2245 Base class for column/constraint definitions in CREATE %TABLE
2246
2247 @ingroup ptn_create_table_stuff
2248*/
2250
2252
2255
2256 public:
2261 : m_keytype(type_par),
2262 m_name(name_arg),
2263 m_type(type),
2264 m_columns(cols),
2265 m_options(options) {}
2266
2267 bool contextualize(Table_ddl_parse_context *pc) override;
2268
2269 private:
2275};
2276
2279
2280 public:
2282 const LEX_STRING &key_name,
2284 Table_ident *referenced_table,
2285 List<Key_part_spec> *ref_list,
2286 fk_match_opt fk_match_option,
2287 fk_option fk_update_opt, fk_option fk_delete_opt)
2288 : m_constraint_name(constraint_name),
2289 m_key_name(key_name),
2290 m_columns(columns),
2291 m_referenced_table(referenced_table),
2292 m_ref_list(ref_list),
2293 m_fk_match_option(fk_match_option),
2294 m_fk_update_opt(fk_update_opt),
2295 m_fk_delete_opt(fk_delete_opt) {}
2296
2297 bool contextualize(Table_ddl_parse_context *pc) override;
2298
2299 private:
2308};
2309
2310/**
2311 Common base class for CREATE TABLE and ALTER TABLE option nodes
2312
2313 @ingroup ptn_create_or_alter_table_options
2314*/
2316 public:
2317 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2318
2319 virtual bool is_rename_table() const { return false; }
2320};
2321
2323
2324/**
2325 Base class for CREATE TABLE option nodes
2326
2327 @ingroup ptn_create_or_alter_table_options
2328*/
2331
2332 public:
2333 ~PT_create_table_option() override = 0; // Force abstract class declaration
2334
2336 if (super::contextualize(pc)) return true;
2338 return false;
2339 }
2340};
2341
2343
2344/**
2345 A template for options that set a single property in HA_CREATE_INFO, and
2346 also records if the option was explicitly set.
2347*/
2348template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2349 uint64_t Property_flag>
2352
2353 const Option_type value;
2354
2355 public:
2357
2359 if (super::contextualize(pc)) return true;
2360 pc->create_info->*Property = value;
2361 pc->create_info->used_fields |= Property_flag;
2362 return false;
2363 }
2364};
2365
2366#define TYPE_AND_REF(x) decltype(x), &x
2367
2368/**
2369 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2370
2371 @ingroup ptn_create_or_alter_table_options
2372*/
2376
2377/**
2378 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2379
2380 @ingroup ptn_create_or_alter_table_options
2381*/
2385
2386/**
2387 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2388
2389 @ingroup ptn_create_or_alter_table_options
2390*/
2394
2395/**
2396 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2397
2398 @ingroup ptn_create_or_alter_table_options
2399*/
2403
2404/**
2405 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2406
2407 @ingroup ptn_create_or_alter_table_options
2408*/
2412
2413/**
2414 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2415
2416 @ingroup ptn_create_or_alter_table_options
2417*/
2421
2422/**
2423 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2424
2425 @ingroup ptn_create_or_alter_table_options
2426*/
2430
2431/**
2432 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2433
2434 @ingroup ptn_create_or_alter_table_options
2435*/
2439
2443
2448
2452
2456
2460
2464
2468
2473
2478
2480
2481/**
2482 A template for options that set HA_CREATE_INFO::table_options and
2483 also records if the option was explicitly set.
2484*/
2485template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2486 table_options_t No>
2489
2491
2492 public:
2494 : value(value) {}
2495
2497 if (super::contextualize(pc)) return true;
2498 pc->create_info->table_options &= ~(Yes | No);
2499 switch (value) {
2500 case Ternary_option::ON:
2501 pc->create_info->table_options |= Yes;
2502 break;
2504 pc->create_info->table_options |= No;
2505 break;
2507 break;
2508 default:
2509 assert(false);
2510 }
2511 pc->create_info->used_fields |= Property_flag;
2512 return false;
2513 }
2514};
2515
2516/**
2517 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2518
2519 @ingroup ptn_create_or_alter_table_options
2520
2521 PACK_KEYS | Constructor parameter
2522 ----------|----------------------
2523 1 | Ternary_option::ON
2524 0 | Ternary_option::OFF
2525 DEFAULT | Ternary_option::DEFAULT
2526*/
2528 0, // DEFAULT
2529 HA_OPTION_PACK_KEYS, // ON
2532
2533/**
2534 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2535
2536 @ingroup ptn_create_or_alter_table_options
2537
2538 STATS_PERSISTENT | Constructor parameter
2539 -----------------|----------------------
2540 1 | Ternary_option::ON
2541 0 | Ternary_option::OFF
2542 DEFAULT | Ternary_option::DEFAULT
2543*/
2545 0, // DEFAULT
2549
2550/**
2551 A template for options that set HA_CREATE_INFO::table_options and
2552 also records if the option was explicitly set.
2553*/
2554template <ulong Property_flag, table_options_t Yes, table_options_t No>
2557
2558 const bool value;
2559
2560 public:
2562
2564 if (super::contextualize(pc)) return true;
2565 pc->create_info->table_options &= ~(Yes | No);
2566 pc->create_info->table_options |= value ? Yes : No;
2567 pc->create_info->used_fields |= Property_flag;
2568 return false;
2569 }
2570};
2571
2572/**
2573 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2574
2575 @ingroup ptn_create_or_alter_table_options
2576
2577 TABLE_CHECKSUM | Constructor parameter
2578 ---------------|----------------------
2579 0 | false
2580 not 0 | true
2581*/
2583 HA_OPTION_CHECKSUM, // ON
2585 >
2587
2588/**
2589 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2590
2591 @ingroup ptn_create_or_alter_table_options
2592
2593 TABLE_CHECKSUM | Constructor parameter
2594 ---------------|----------------------
2595 0 | false
2596 not 0 | true
2597*/
2602
2603/**
2604 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2605
2606 @ingroup ptn_create_or_alter_table_options
2607*/
2610
2612
2613 public:
2614 /**
2615 @param engine Storage engine name.
2616 */
2618 : engine(engine) {}
2619
2620 bool contextualize(Table_ddl_parse_context *pc) override;
2621};
2622
2623/**
2624 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2625 table option.
2626
2627 @ingroup ptn_create_or_alter_table_options
2628*/
2631
2632 public:
2637
2638 bool contextualize(Table_ddl_parse_context *pc) override;
2639
2640 private:
2642};
2643
2644/**
2645 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2646
2647 @ingroup ptn_create_or_alter_table_options
2648*/
2651
2653
2654 public:
2655 /**
2656 @param value
2657 STATS_AUTO_RECALC | value
2658 ------------------|----------------------
2659 1 | Ternary_option::ON
2660 0 | Ternary_option::OFF
2661 DEFAULT | Ternary_option::DEFAULT
2662 */
2664
2665 bool contextualize(Table_ddl_parse_context *pc) override;
2666};
2667
2668/**
2669 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2670
2671 @ingroup ptn_create_or_alter_table_options
2672*/
2676
2678
2679 public:
2680 /**
2681 Constructor for implicit number of pages
2682
2683 @param value Number of pages, 1@<=N@<=65535.
2684 */
2686 assert(value != 0 && value <= 0xFFFF);
2687 }
2688 /**
2689 Constructor for the DEFAULT number of pages
2690 */
2692
2693 bool contextualize(Table_ddl_parse_context *pc) override;
2694};
2695
2698
2700
2701 public:
2703 : tables(tables) {}
2704
2705 bool contextualize(Table_ddl_parse_context *pc) override;
2706};
2707
2710
2712
2713 public:
2715
2717 if (super::contextualize(pc)) return true;
2719 return false;
2720 }
2721};
2722
2725
2727
2728 public:
2730 : value(value) {
2731 assert(value != nullptr);
2732 }
2733
2734 bool contextualize(Table_ddl_parse_context *pc) override;
2735};
2736
2739
2741
2742 public:
2744 : value(value) {
2745 assert(value != nullptr);
2746 }
2747
2748 bool contextualize(Table_ddl_parse_context *pc) override;
2749};
2750
2754
2755 public:
2756 explicit PT_check_constraint(LEX_STRING &name, Item *expr, bool is_enforced) {
2757 cc_spec.name = name;
2758 cc_spec.check_expr = expr;
2759 cc_spec.is_enforced = is_enforced;
2760 }
2762
2763 bool contextualize(Table_ddl_parse_context *pc) override;
2764};
2765
2768
2771 // Currently we ignore that constraint in the executor.
2773
2774 const char *opt_place;
2775
2776 public:
2779 const char *opt_place = nullptr)
2784
2785 bool contextualize(Table_ddl_parse_context *pc) override;
2786};
2787
2788/**
2789 Top-level node for the CREATE %TABLE statement
2790
2791 @ingroup ptn_create_table
2792*/
2803
2805
2806 public:
2807 /**
2808 @param mem_root MEM_ROOT to use for allocation
2809 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
2810 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
2811 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
2812 @param opt_table_element_list NULL or a list of table column and
2813 constraint definitions.
2814 @param opt_create_table_options NULL or a list of
2815 @ref ptn_create_or_alter_table_options
2816 "table options".
2817 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
2818 @param on_duplicate DUPLICATE, IGNORE or fail with an error
2819 on data duplication errors (relevant
2820 for @SQL{CREATE TABLE ... SELECT}
2821 statements).
2822 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
2823 */
2841 /**
2842 @param mem_root MEM_ROOT to use for allocation
2843 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
2844 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
2845 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
2846 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
2847 */
2861
2862 Sql_cmd *make_cmd(THD *thd) override;
2863};
2864
2865class PT_create_role final : public Parse_tree_root {
2867
2868 public:
2869 PT_create_role(bool if_not_exists, const List<LEX_USER> *roles)
2870 : sql_cmd(if_not_exists, roles) {}
2871
2872 Sql_cmd *make_cmd(THD *thd) override;
2873};
2874
2875class PT_drop_role final : public Parse_tree_root {
2877
2878 public:
2879 explicit PT_drop_role(bool ignore_errors, const List<LEX_USER> *roles)
2880 : sql_cmd(ignore_errors, roles) {}
2881
2882 Sql_cmd *make_cmd(THD *thd) override;
2883};
2884
2887
2888 public:
2889 explicit PT_set_role(role_enum role_type,
2890 const List<LEX_USER> *opt_except_roles = nullptr)
2891 : sql_cmd(role_type, opt_except_roles) {
2892 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
2893 }
2894 explicit PT_set_role(const List<LEX_USER> *roles) : sql_cmd(roles) {}
2895
2896 Sql_cmd *make_cmd(THD *thd) override;
2897};
2898
2899/**
2900 This class is used for representing both static and dynamic privileges on
2901 global as well as table and column level.
2902*/
2905
2908
2911 : type(type), columns(columns) {}
2912};
2913
2916
2918 : Privilege(STATIC, columns_arg), grant(grant) {}
2919};
2920
2923
2925 const Mem_root_array<LEX_CSTRING> *columns_arg)
2926 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
2927};
2928
2930 private:
2932
2933 public:
2934 explicit PT_role_or_privilege(const POS &pos) : pos(pos) {}
2935 virtual LEX_USER *get_user(THD *thd);
2936 virtual Privilege *get_privilege(THD *thd);
2937};
2938
2942
2943 public:
2945 const LEX_STRING &host)
2947
2948 LEX_USER *get_user(THD *thd) override;
2949};
2950
2953
2954 public:
2957
2958 LEX_USER *get_user(THD *thd) override;
2959 Privilege *get_privilege(THD *thd) override;
2960};
2961
2965
2966 public:
2968 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
2970
2971 Privilege *get_privilege(THD *thd) override;
2972};
2973
2976
2977 public:
2980
2981 Privilege *get_privilege(THD *thd) override;
2982};
2983
2984class PT_grant_roles final : public Parse_tree_root {
2988
2989 public:
2993
2994 Sql_cmd *make_cmd(THD *thd) override;
2995};
2996
2997class PT_revoke_roles final : public Parse_tree_root {
3000
3001 public:
3003 const List<LEX_USER> *users)
3004 : roles(roles), users(users) {}
3005
3006 Sql_cmd *make_cmd(THD *thd) override;
3007};
3008
3011
3012 public:
3013 PT_alter_user_default_role(bool if_exists, const List<LEX_USER> *users,
3014 const List<LEX_USER> *roles,
3015 const role_enum role_type)
3016 : sql_cmd(if_exists, users, roles, role_type) {}
3017
3018 Sql_cmd *make_cmd(THD *thd) override;
3019};
3020
3021/// Base class for Parse tree nodes of SHOW statements
3022
3024 protected:
3025 PT_show_base(const POS &pos, enum_sql_command sql_command)
3026 : m_pos(pos), m_sql_command(sql_command) {}
3027
3028 /// Textual location of a token just parsed.
3030 /// SQL command
3032};
3033
3034/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3035
3037 protected:
3039 const LEX_STRING &wild, Item *where)
3040 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3041 assert(m_wild.str == nullptr || m_where == nullptr);
3042 }
3043 /// Wild or where clause used in the statement.
3046};
3047
3048/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3049
3051 protected:
3053 char *opt_db, const LEX_STRING &wild, Item *where)
3054 : PT_show_base(pos, sql_command),
3056 m_wild(wild),
3057 m_where(where) {
3058 assert(m_wild.str == nullptr || m_where == nullptr);
3059 }
3060 /// Optional schema name in FROM/IN clause.
3062 /// Wild or where clause used in the statement.
3065};
3066
3067/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3068
3070 protected:
3071 PT_show_table_base(const POS &pos, enum_sql_command sql_command,
3072 Table_ident *table_ident, const LEX_STRING &wild,
3073 Item *where)
3074 : PT_show_filter_base(pos, sql_command, wild, where),
3075 m_table_ident(table_ident) {}
3076
3077 bool make_table_base_cmd(THD *thd, bool *temporary);
3078
3079 /// Table used in the statement.
3081};
3082
3083/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3084
3086 protected:
3088 const sp_name *routine_name)
3089 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3090
3091 Sql_cmd *make_cmd(THD *thd) override;
3092
3093 private:
3095};
3096
3097/// Parse tree node for SHOW BINLOG EVENTS statement
3098
3100 public:
3101 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3102 PT_limit_clause *opt_limit_clause = nullptr)
3104 m_opt_log_file_name(opt_log_file_name),
3105 m_opt_limit_clause(opt_limit_clause) {}
3106
3107 Sql_cmd *make_cmd(THD *thd) override;
3108
3109 private:
3112
3114};
3115
3116/// Parse tree node for SHOW BINLOGS statement
3117
3118class PT_show_binlogs final : public PT_show_base {
3119 public:
3121
3122 Sql_cmd *make_cmd(THD *thd) override;
3123
3124 private:
3126};
3127
3128/// Parse tree node for SHOW CHARACTER SET statement
3129
3131 public:
3132 PT_show_charsets(const POS &pos, const LEX_STRING &wild, Item *where)
3134
3135 Sql_cmd *make_cmd(THD *thd) override;
3136
3137 private:
3139};
3140
3141/// Parse tree node for SHOW COLLATIONS statement
3142
3144 public:
3145 PT_show_collations(const POS &pos, const LEX_STRING &wild, Item *where)
3147
3148 Sql_cmd *make_cmd(THD *thd) override;
3149
3150 private:
3152};
3153
3154/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3155/// statements.
3156
3158 public:
3159 explicit PT_show_count_base(const POS &pos)
3160 : PT_show_base{pos, SQLCOM_SELECT} {}
3161
3162 protected:
3163 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3164};
3165
3166/// Parse tree node for SHOW COUNT(*) ERRORS
3167
3169 public:
3170 explicit PT_show_count_errors(const POS &pos) : PT_show_count_base(pos) {}
3171
3172 Sql_cmd *make_cmd(THD *thd) override {
3173 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3174 }
3175};
3176
3177/// Parse tree node for SHOW COUNT(*) WARNINGS
3178
3180 public:
3181 explicit PT_show_count_warnings(const POS &pos) : PT_show_count_base(pos) {}
3182
3183 Sql_cmd *make_cmd(THD *thd) override {
3184 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3185 }
3186};
3187
3188/// Parse tree node for SHOW CREATE DATABASE statement
3189
3191 public:
3192 PT_show_create_database(const POS &pos, bool if_not_exists,
3193 const LEX_STRING &name)
3195 m_if_not_exists(if_not_exists),
3196 m_name(name) {}
3197
3198 Sql_cmd *make_cmd(THD *thd) override;
3199
3200 private:
3203
3205};
3206
3207/// Parse tree node for SHOW CREATE EVENT statement
3208
3210 public:
3211 PT_show_create_event(const POS &pos, sp_name *event_name)
3212 : PT_show_base(pos, SQLCOM_SHOW_CREATE_EVENT), m_spname(event_name) {}
3213
3214 Sql_cmd *make_cmd(THD *thd) override;
3215
3216 private:
3218
3220};
3221
3222/// Parse tree node for SHOW CREATE FUNCTION statement
3223
3225 public:
3226 PT_show_create_function(const POS &pos, sp_name *function_name)
3227 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3228
3229 Sql_cmd *make_cmd(THD *thd) override;
3230
3231 private:
3233
3235};
3236
3237/// Parse tree node for SHOW CREATE PROCEDURE statement
3238
3240 public:
3241 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3242 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3243
3244 Sql_cmd *make_cmd(THD *thd) override;
3245
3246 private:
3248
3250};
3251
3252/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3253
3255 public:
3256 PT_show_create_table(const POS &pos, Table_ident *table_ident)
3257 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3258
3259 Sql_cmd *make_cmd(THD *thd) override;
3260
3261 private:
3263};
3264
3265/// Parse tree node for SHOW CREATE TRIGGER statement
3266
3268 public:
3269 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3270 : PT_show_base(pos, SQLCOM_SHOW_CREATE_TRIGGER), m_spname(trigger_name) {}
3271
3272 Sql_cmd *make_cmd(THD *thd) override;
3273
3274 private:
3276
3278};
3279
3280/// Parse tree node for SHOW CREATE USER statement
3281
3282class PT_show_create_user final : public PT_show_base {
3283 public:
3286
3287 Sql_cmd *make_cmd(THD *thd) override;
3288
3289 private:
3291
3293};
3294
3295/// Parse tree node for SHOW CREATE VIEW statement
3296
3297class PT_show_create_view final : public PT_show_base {
3298 public:
3299 PT_show_create_view(const POS &pos, Table_ident *table_ident)
3300 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3301
3302 Sql_cmd *make_cmd(THD *thd) override;
3303
3304 private:
3306};
3307
3308/// Parse tree node for SHOW DATABASES statement
3309
3311 public:
3312 PT_show_databases(const POS &pos, const LEX_STRING &wild, Item *where)
3314
3315 Sql_cmd *make_cmd(THD *thd) override;
3316
3317 private:
3319};
3320
3321/// Parse tree node for SHOW ENGINE statements
3322
3324 protected:
3325 PT_show_engine_base(const POS &pos, enum enum_sql_command sql_command,
3326 const LEX_STRING opt_engine = {})
3327 : PT_show_base(pos, sql_command),
3328 m_engine(opt_engine),
3329 m_all(opt_engine.str == nullptr) {}
3330
3332 bool m_all;
3333};
3334
3335/// Parse tree node for SHOW ENGINE LOGS statement
3336
3338 public:
3339 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3340 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_LOGS, opt_engine) {}
3341
3342 Sql_cmd *make_cmd(THD *thd) override;
3343
3344 private:
3346};
3347
3348/// Parse tree node for SHOW ENGINE MUTEX statement
3349
3351 public:
3352 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3353 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_MUTEX, opt_engine) {}
3354
3355 Sql_cmd *make_cmd(THD *thd) override;
3356
3357 private:
3359};
3360
3361/// Parse tree node for SHOW ENGINE STATUS statement
3362
3364 public:
3365 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3366 : PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_STATUS, opt_engine) {}
3367
3368 Sql_cmd *make_cmd(THD *thd) override;
3369
3370 private:
3372};
3373
3374/// Parse tree node for SHOW ENGINES statement
3375
3376class PT_show_engines final : public PT_show_base {
3377 public:
3380
3381 Sql_cmd *make_cmd(THD *thd) override;
3382
3383 private:
3385};
3386
3387/// Parse tree node for SHOW ERRORS statement
3388
3389class PT_show_errors final : public PT_show_base {
3390 public:
3391 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3393 m_opt_limit_clause(opt_limit_clause) {}
3394
3395 Sql_cmd *make_cmd(THD *thd) override;
3396
3397 private:
3399
3401};
3402
3403/// Parse tree node for SHOW EVENTS statement
3404
3406 public:
3407 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3408 Item *where)
3410
3411 Sql_cmd *make_cmd(THD *thd) override;
3412
3413 private:
3415};
3416
3417/// Parse tree node for SHOW COLUMNS statement.
3418
3421
3422 public:
3423 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3424 Table_ident *table, LEX_STRING opt_wild = {},
3425 Item *opt_where = nullptr)
3426 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3427 m_show_cmd_type(show_cmd_type) {}
3428
3429 Sql_cmd *make_cmd(THD *thd) override;
3430
3431 private:
3434};
3435
3436/// Parse tree node for SHOW FUNCTION CODE statement.
3437
3439 public:
3440 PT_show_function_code(const POS &pos, const sp_name *function_name)
3441 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3442};
3443
3444/// Parse tree node for SHOW GRANTS statement.
3445
3446class PT_show_grants final : public PT_show_base {
3447 public:
3448 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3449 const List<LEX_USER> *opt_using_users)
3451 sql_cmd(opt_for_user, opt_using_users) {
3452 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3453 }
3454
3455 Sql_cmd *make_cmd(THD *thd) override;
3456
3457 private:
3459};
3460
3461/// Parse tree node for SHOW INDEX statement.
3462
3463class PT_show_keys final : public PT_show_table_base {
3464 public:
3465 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3466 Item *where)
3468 m_extended_show(extended_show) {}
3469
3470 Sql_cmd *make_cmd(THD *thd) override;
3471
3472 private:
3474
3475 // Flag to indicate EXTENDED keyword usage in the statement.
3478};
3479
3480/// Parse tree node for SHOW MASTER STATUS statement
3481
3483 public:
3486
3487 Sql_cmd *make_cmd(THD *thd) override;
3488
3489 private:
3491};
3492
3493/// Parse tree node for SHOW OPEN TABLES statement
3494
3496 public:
3497 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3498 Item *where)
3500 }
3501
3502 Sql_cmd *make_cmd(THD *thd) override;
3503
3504 private:
3506};
3507
3508/// Parse tree node for SHOW PLUGINS statement
3509
3510class PT_show_plugins final : public PT_show_base {
3511 public:
3513
3514 Sql_cmd *make_cmd(THD *thd) override;
3515
3516 private:
3518};
3519
3520/// Parse tree node for SHOW PRIVILEGES statement
3521
3522class PT_show_privileges final : public PT_show_base {
3523 public:
3526
3527 Sql_cmd *make_cmd(THD *thd) override;
3528
3529 private:
3531};
3532
3533/// Parse tree node for SHOW FUNCTION CODE statement.
3534
3536 public:
3537 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3538 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3539};
3540
3541/// Parse tree node for SHOW PROCESSLIST statement
3542
3543class PT_show_processlist final : public PT_show_base {
3544 public:
3547
3548 Sql_cmd *make_cmd(THD *thd) override;
3549
3550 private:
3552};
3553
3554/// Parse tree node for SHOW PROFILE statement
3555
3556class PT_show_profile final : public PT_show_base {
3557 public:
3558 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3559 my_thread_id opt_query_id = 0,
3560 PT_limit_clause *opt_limit_clause = nullptr)
3562 m_opt_profile_options(opt_profile_options),
3563 m_opt_query_id(opt_query_id),
3564 m_opt_limit_clause(opt_limit_clause) {}
3565
3566 Sql_cmd *make_cmd(THD *thd) override;
3567
3568 private:
3572
3574};
3575
3576/// Parse tree node for SHOW PROFILES statement
3577
3578class PT_show_profiles final : public PT_show_base {
3579 public:
3581
3582 Sql_cmd *make_cmd(THD *thd) override;
3583
3584 private:
3586};
3587
3588/// Parse tree node for SHOW RELAYLOG EVENTS statement
3589
3591 public:
3593 const LEX_STRING opt_log_file_name = {},
3594 PT_limit_clause *opt_limit_clause = nullptr,
3595 LEX_CSTRING opt_channel_name = {})
3597 m_opt_log_file_name(opt_log_file_name),
3598 m_opt_limit_clause(opt_limit_clause),
3599 m_opt_channel_name(opt_channel_name) {}
3600
3601 Sql_cmd *make_cmd(THD *thd) override;
3602
3603 private:
3607
3609};
3610
3611/// Parse tree node for SHOW REPLICAS statement
3612
3613class PT_show_replicas final : public PT_show_base {
3614 public:
3617
3618 Sql_cmd *make_cmd(THD *thd) override;
3619
3620 private:
3622};
3623
3624/// Parse tree node for SHOW REPLICA STATUS statement
3625
3627 public:
3628 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3630 m_opt_channel_name(opt_channel_name) {}
3631
3632 Sql_cmd *make_cmd(THD *thd) override;
3633
3634 private:
3636
3638};
3639
3640/// Parse tree node for SHOW STATUS statement
3641
3643 public:
3644 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3645 Item *where)
3647 m_var_type(var_type) {
3649 }
3650
3651 Sql_cmd *make_cmd(THD *thd) override;
3652
3653 private:
3655
3657};
3658
3659/// Parse tree node for SHOW STATUS FUNCTION statement
3660
3662 public:
3663 PT_show_status_func(const POS &pos, const LEX_STRING &wild, Item *where)
3665
3666 Sql_cmd *make_cmd(THD *thd) override;
3667
3668 private:
3670};
3671
3672/// Parse tree node for SHOW STATUS PROCEDURE statement
3673
3675 public:
3676 PT_show_status_proc(const POS &pos, const LEX_STRING &wild, Item *where)
3678
3679 Sql_cmd *make_cmd(THD *thd) override;
3680
3681 private:
3683};
3684
3685/// Parse tree node for SHOW TABLE STATUS statement
3686
3688 public:
3689 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
3690 Item *where)
3692 where) {}
3693
3694 Sql_cmd *make_cmd(THD *thd) override;
3695
3696 private:
3698};
3699
3700/// Parse tree node for SHOW TABLES statement
3701
3703 public:
3704 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
3705 const LEX_STRING &wild, Item *where)
3707 m_show_cmd_type(show_cmd_type) {}
3708
3709 Sql_cmd *make_cmd(THD *thd) override;
3710
3711 private:
3713
3715};
3716
3717/// Parse tree node for SHOW TRIGGERS statement
3718
3720 public:
3721 PT_show_triggers(const POS &pos, bool full, char *opt_db,
3722 const LEX_STRING &wild, Item *where)
3724 m_full(full) {}
3725
3726 Sql_cmd *make_cmd(THD *thd) override;
3727
3728 private:
3730
3732};
3733
3734/// Parse tree node for SHOW VARIABLES statement
3735
3737 public:
3739 const LEX_STRING &wild, Item *where)
3741 m_var_type(var_type) {
3743 }
3744
3745 Sql_cmd *make_cmd(THD *thd) override;
3746
3747 private:
3749
3751};
3752
3753/// Parse tree node for SHOW WARNINGS statement
3754
3755class PT_show_warnings final : public PT_show_base {
3756 public:
3757 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3759 m_opt_limit_clause(opt_limit_clause) {}
3760
3761 Sql_cmd *make_cmd(THD *thd) override;
3762
3763 private:
3765
3767};
3768
3771
3772 protected:
3774 : flag(flag) {}
3775
3776 public:
3777 bool contextualize(Table_ddl_parse_context *pc) override;
3778
3779 protected:
3780 /**
3781 A routine used by the parser to decide whether we are specifying a full
3782 partitioning or if only partitions to add or to reorganize.
3783
3784 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
3785 @retval false Something else.
3786 */
3790 }
3791
3792 public:
3794};
3795
3798
3799 public:
3801 PT_field_def_base *field_def,
3802 PT_table_constraint_def *opt_column_constraint,
3803 const char *opt_place)
3804 : super(Alter_info::ALTER_ADD_COLUMN),
3805 m_column_def(field_ident, field_def, opt_column_constraint, opt_place) {
3806 }
3807
3810 }
3811
3812 private:
3814};
3815
3818
3819 public:
3822 : super(Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
3823
3825 if (super::contextualize(pc)) return true;
3826
3827 for (auto *column : *m_columns)
3828 if (column->contextualize(pc)) return true;
3829
3830 return false;
3831 }
3832
3833 private:
3835};
3836
3839
3840 public:
3842 : super(Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
3843
3846 }
3847
3848 private:
3850};
3851
3854
3855 public:
3857 const LEX_STRING &new_name,
3858 PT_field_def_base *field_def,
3859 const char *opt_place)
3860 : super(Alter_info::ALTER_CHANGE_COLUMN),
3861 m_old_name(old_name),
3862 m_new_name(new_name),
3863 m_field_def(field_def),
3864 m_opt_place(opt_place) {}
3865
3867 PT_field_def_base *field_def,
3868 const char *opt_place)
3869 : PT_alter_table_change_column(name, name, field_def, opt_place) {}
3870
3871 bool contextualize(Table_ddl_parse_context *pc) override;
3872
3873 private:
3877 const char *m_opt_place;
3878};
3879
3882
3883 protected:
3885 Alter_info::Alter_info_flag alter_info_flag,
3886 const char *name)
3887 : super(alter_info_flag), m_alter_drop(drop_type, name) {}
3888
3889 public:
3891 return (super::contextualize(pc) ||
3892 pc->alter_info->drop_list.push_back(&m_alter_drop));
3893 }
3894
3895 private:
3897};
3898
3900 public:
3901 explicit PT_alter_table_drop_column(const char *name)
3902 : PT_alter_table_drop(Alter_drop::COLUMN, Alter_info::ALTER_DROP_COLUMN,
3903 name) {}
3904};
3905
3907 public:
3910 Alter_info::DROP_FOREIGN_KEY, name) {}
3911};
3912
3914 public:
3915 explicit PT_alter_table_drop_key(const char *name)
3916 : PT_alter_table_drop(Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
3917 name) {}
3918};
3919
3921 public:
3923 : PT_alter_table_drop(Alter_drop::CHECK_CONSTRAINT,
3924 Alter_info::DROP_CHECK_CONSTRAINT, name) {}
3925};
3926
3928 public:
3930 : PT_alter_table_drop(Alter_drop::ANY_CONSTRAINT,
3931 Alter_info::DROP_ANY_CONSTRAINT, name) {}
3932};
3933
3936
3937 protected:
3940 Alter_info::Alter_info_flag alter_info_flag, const char *name,
3941 bool is_enforced)
3942 : super(alter_info_flag),
3943 m_constraint_enforcement(alter_type, name, is_enforced) {}
3944
3945 public:
3946 explicit PT_alter_table_enforce_constraint(const char *name, bool is_enforced)
3947 : super(is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
3948 : Alter_info::SUSPEND_ANY_CONSTRAINT),
3950 Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
3951 is_enforced) {}
3952
3954 return (super::contextualize(pc) ||
3957 }
3958
3959 private:
3961};
3962
3965 public:
3967 bool is_enforced)
3969 Alter_constraint_enforcement::Type::CHECK_CONSTRAINT,
3970 is_enforced ? Alter_info::ENFORCE_CHECK_CONSTRAINT
3971 : Alter_info::SUSPEND_CHECK_CONSTRAINT,
3972 name, is_enforced) {}
3973};
3974
3977
3978 public:
3979 explicit PT_alter_table_enable_keys(bool enable)
3980 : super(Alter_info::ALTER_KEYS_ONOFF), m_enable(enable) {}
3981
3983 pc->alter_info->keys_onoff =
3985 return super::contextualize(pc);
3986 }
3987
3988 private:
3990};
3991
3994
3995 public:
3996 PT_alter_table_set_default(const char *col_name, Item *opt_default_expr)
3997 : super(Alter_info::ALTER_CHANGE_COLUMN_DEFAULT),
3998 m_name(col_name),
3999 m_expr(opt_default_expr) {}
4000
4001 bool contextualize(Table_ddl_parse_context *pc) override;
4002
4003 private:
4004 const char *m_name;
4006};
4007
4010
4011 public:
4012 PT_alter_table_column_visibility(const char *col_name, bool is_visible)
4013 : super(Alter_info::ALTER_COLUMN_VISIBILITY),
4014 m_alter_column(col_name, is_visible) {}
4015
4017 return (super::contextualize(pc) ||
4018 pc->alter_info->alter_list.push_back(&m_alter_column));
4019 }
4020
4021 private:
4023};
4024
4027
4028 public:
4029 PT_alter_table_index_visible(const char *name, bool visible)
4030 : super(Alter_info::ALTER_INDEX_VISIBILITY),
4031 m_alter_index_visibility(name, visible) {}
4032
4034 return (super::contextualize(pc) ||
4037 }
4038
4039 private:
4041};
4042
4045
4046 public:
4047 explicit PT_alter_table_rename(const Table_ident *ident)
4048 : super(Alter_info::ALTER_RENAME), m_ident(ident) {}
4049
4050 bool contextualize(Table_ddl_parse_context *pc) override;
4051
4052 bool is_rename_table() const override { return true; }
4053
4054 private:
4055 const Table_ident *const m_ident;
4056};
4057
4060
4061 public:
4062 PT_alter_table_rename_key(const char *from, const char *to)
4063 : super(Alter_info::ALTER_RENAME_INDEX), m_rename_key(from, to) {}
4064
4066 return super::contextualize(pc) ||
4068 }
4069
4070 private:
4072};
4073
4076
4077 public:
4078 PT_alter_table_rename_column(const char *from, const char *to)
4079 : super(Alter_info::ALTER_CHANGE_COLUMN), m_rename_column(from, to) {}
4080
4082 return super::contextualize(pc) ||
4083 pc->alter_info->alter_list.push_back(&m_rename_column);
4084 }
4085
4086 private:
4088};
4089
4092
4093 public:
4095 const CHARSET_INFO *opt_collation)
4096 : super(Alter_info::ALTER_OPTIONS),
4098 m_collation(opt_collation) {}
4099
4100 bool contextualize(Table_ddl_parse_context *pc) override;
4101
4102 private:
4105};
4106
4109
4110 public:
4111 PT_alter_table_force() : super(Alter_info::ALTER_RECREATE) {}
4112};
4113
4116
4117 public:
4119 : super(Alter_info::ALTER_ORDER), m_order(order) {}
4120
4121 bool contextualize(Table_ddl_parse_context *pc) override;
4122
4123 private:
4125};
4126
4129
4130 public:
4132 : super(Alter_info::ALTER_PARTITION), m_partition(partition) {}
4133
4134 bool contextualize(Table_ddl_parse_context *pc) override;
4135
4136 private:
4138};
4139
4142
4143 public:
4145 : super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
4146};
4147
4150
4151 friend class PT_alter_table_standalone_stmt; // to access make_cmd()
4152
4153 protected:
4155 : super(alter_info_flag) {}
4156
4157 private:
4159};
4160
4161/**
4162 Node for the @SQL{ALTER TABLE ADD PARTITION} statement
4163
4164 @ingroup ptn_alter_table
4165*/
4168
4169 public:
4170 explicit PT_alter_table_add_partition(bool no_write_to_binlog)
4171 : super(Alter_info::ALTER_ADD_PARTITION),
4172 m_no_write_to_binlog(no_write_to_binlog) {}
4173
4174 bool contextualize(Table_ddl_parse_context *pc) override;
4175
4177 return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
4178 }
4179
4180 protected:
4182
4183 private:
4185};
4186
4187/**
4188 Node for the @SQL{ALTER TABLE ADD PARTITION (@<partition list@>)} statement
4189
4190 @ingroup ptn_alter_table
4191*/
4195
4196 public:
4198 bool no_write_to_binlog,
4200 : super(no_write_to_binlog), m_def_list(def_list) {}
4201
4202 bool contextualize(Table_ddl_parse_context *pc) override;
4203
4204 private:
4206};
4207
4208/**
4209 Node for the @SQL{ALTER TABLE ADD PARTITION PARTITIONS (@<n>@)} statement
4210
4211 @ingroup ptn_alter_table
4212*/
4216
4217 public:
4218 PT_alter_table_add_partition_num(bool no_write_to_binlog, uint num_parts)
4219 : super(no_write_to_binlog) {
4220 m_part_info.num_parts = num_parts;
4221 }
4222};
4223
4227
4228 public:
4230 : super(Alter_info::ALTER_DROP_PARTITION), m_partitions(partitions) {}
4231
4232 bool contextualize(Table_ddl_parse_context *pc) override;
4233