MySQL 8.0.31
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 order->is_position = false;
232 value.link_in_list(order, &order->next);
233 }
234};
235
238
239 public:
240 bool contextualize(Parse_context *pc) override {
241 return super::contextualize(pc);
242 }
243};
244
245/**
246 Represents an element of the WITH list:
247 WITH [...], [...] SELECT ...,
248 ^ or ^
249 i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
250*/
253
254 public:
255 explicit PT_common_table_expr(const LEX_STRING &name,
256 const LEX_STRING &subq_text,
257 uint subq_text_offset, PT_subquery *sn,
260
261 /// The name after AS
262 const LEX_STRING &name() const { return m_name; }
263 /**
264 @param thd Thread handler
265 @param[out] node PT_subquery
266 @returns a PT_subquery to attach to a table reference for this CTE
267 */
268 bool make_subquery_node(THD *thd, PT_subquery **node);
269 /**
270 @param tl Table reference to match
271 @param in_self If this is a recursive reference
272 @param[out] found Is set to true/false if matches or not
273 @returns true if error
274 */
275 bool match_table_ref(TABLE_LIST *tl, bool in_self, bool *found);
276 /**
277 @returns true if 'other' is the same instance as 'this'
278 */
279 bool is(const Common_table_expr *other) const {
280 return other == &m_postparse;
281 }
282 void print(const THD *thd, String *str, enum_query_type query_type);
283
284 private:
286 /// Raw text of query expression (including parentheses)
288 /**
289 Offset in bytes of m_subq_text in original statement which had the WITH
290 clause.
291 */
293 /// Parsed version of subq_text
295 /// List of explicitly specified column names; if empty, no list.
297 /**
298 A TABLE_LIST representing a CTE needs access to the WITH list
299 element it derives from. However, in order to:
300 - limit the members which TABLE_LIST can access
301 - avoid including this header file everywhere TABLE_LIST needs to access
302 these members,
303 these members are relocated into a separate inferior object whose
304 declaration is in table.h, like that of TABLE_LIST. It's the "postparse"
305 part. TABLE_LIST accesses this inferior object only.
306 */
308
310};
311
312/**
313 Represents the WITH list.
314 WITH [...], [...] SELECT ...,
315 ^^^^^^^^^^^^
316*/
319
320 public:
321 /// @param mem_root where interior objects are allocated
325 return m_elements;
326 }
327
328 private:
330};
331
332/**
333 Represents the WITH clause:
334 WITH [...], [...] SELECT ...,
335 ^^^^^^^^^^^^^^^^^
336*/
339
340 public:
343
344 bool contextualize(Parse_context *pc) override;
345
346 /**
347 Looks up a table reference into the list of CTEs.
348 @param tl Table reference to look up
349 @param[out] found Is set to true/false if found or not
350 @returns true if error
351 */
352 bool lookup(TABLE_LIST *tl, PT_common_table_expr **found);
353 /**
354 Call this to record in the WITH clause that we are contextualizing the
355 CTE definition inserted in table reference 'tl'.
356 @returns information which the caller must provide to
357 leave_parsing_definition().
358 */
360 auto old = m_most_inner_in_parsing;
362 return old;
363 }
366 }
367 void print(const THD *thd, String *str, enum_query_type query_type);
368
369 private:
370 /// All CTEs of this clause
371 const PT_with_list *const m_list;
372 /// True if the user has specified the RECURSIVE keyword.
373 const bool m_recursive;
374 /**
375 The innermost CTE reference which we're parsing at the
376 moment. Used to detect forward references, loops and recursiveness.
377 */
379
381};
382
385
386 public:
387 bool contextualize(Parse_context *pc) override;
388};
389
392
394
395 public:
396 PT_limit_clause(const Limit_options &limit_options_arg)
397 : limit_options(limit_options_arg) {}
398
399 bool contextualize(Parse_context *pc) override;
401};
402
403class PT_cross_join;
404class PT_joined_table;
405
407 public:
409
410 /**
411 Lets us build a parse tree top-down, which is necessary due to the
412 context-dependent nature of the join syntax. This function adds
413 the @<table_ref@> cross join as the left-most leaf in this join tree
414 rooted at this node.
415
416 @todo: comment on non-join PT_table_reference objects
417
418 @param cj This @<table ref@> will be added if it represents a cross join.
419
420 @return The new top-level join.
421 */
423};
424
427
430 const char *const opt_table_alias;
432
433 public:
435 List<String> *opt_use_partition_arg,
436 const LEX_CSTRING &opt_table_alias_arg,
437 List<Index_hint> *opt_key_definition_arg)
438 : table_ident(table_ident_arg),
439 opt_use_partition(opt_use_partition_arg),
440 opt_table_alias(opt_table_alias_arg.str),
441 opt_key_definition(opt_key_definition_arg) {}
442
443 bool contextualize(Parse_context *pc) override;
444};
445
447 public:
449};
450
453
454 public:
457 const LEX_STRING &table_alias)
458 : m_expr(expr),
459 m_path(path),
460 m_nested_columns(nested_cols),
461 m_table_alias(table_alias) {}
462
463 bool contextualize(Parse_context *pc) override;
464
465 private:
470};
471
474
476
477 public:
481
482 bool contextualize(Parse_context *pc) override;
483};
484
487
488 public:
489 PT_derived_table(bool lateral, PT_subquery *subquery,
490 const LEX_CSTRING &table_alias,
492
493 bool contextualize(Parse_context *pc) override;
494
495 private:
498 const char *const m_table_alias;
499 /// List of explicitly specified column names; if empty, no list.
501};
502
505
506 public:
508 : m_joined_table(joined_table) {}
509
510 bool contextualize(Parse_context *pc) override;
511
512 private:
514};
515
518
519 protected:
524
527
528 public:
529 PT_joined_table(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
531 : tab1_node(tab1_node_arg),
532 join_pos(join_pos_arg),
533 m_type(type),
534 tab2_node(tab2_node_arg),
535 tr1(nullptr),
536 tr2(nullptr) {
537 static_assert(is_single_bit(JTT_INNER), "not a single bit");
538 static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
539 static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
540 static_assert(is_single_bit(JTT_LEFT), "not a single bit");
541 static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
542
543 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
546 }
547
548 /**
549 Adds the cross join to this join operation. The cross join is nested as
550 the table reference on the left-hand side.
551 */
554 return this;
555 }
556
557 /// Adds the table reference as the right-hand side of this join.
559 assert(tab2_node == nullptr);
560 tab2_node = table;
561 }
562
563 bool contextualize(Parse_context *pc) override;
564
565 /// This class is being inherited, it should thus be abstract.
566 ~PT_joined_table() override = 0;
567
568 protected:
570};
571
572inline PT_joined_table::~PT_joined_table() = default;
573
576
577 public:
578 PT_cross_join(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
579 PT_joined_table_type Type_arg,
580 PT_table_reference *tab2_node_arg)
581 : PT_joined_table(tab1_node_arg, join_pos_arg, Type_arg, tab2_node_arg) {}
582
583 bool contextualize(Parse_context *pc) override;
584};
585
589
590 public:
591 PT_joined_table_on(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
593 PT_table_reference *tab2_node_arg, Item *on_arg)
594 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg), on(on_arg) {}
595
596 bool contextualize(Parse_context *pc) override;
597};
598
602
603 public:
605 const POS &join_pos_arg, PT_joined_table_type type,
606 PT_table_reference *tab2_node_arg,
607 List<String> *using_fields_arg)
608 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg),
609 using_fields(using_fields_arg) {}
610
611 /// A PT_joined_table_using without a list of columns denotes a natural join.
613 const POS &join_pos_arg, PT_joined_table_type type,
614 PT_table_reference *tab2_node_arg)
615 : PT_joined_table_using(tab1_node_arg, join_pos_arg, type, tab2_node_arg,
616 nullptr) {}
617
618 bool contextualize(Parse_context *pc) override;
619};
620
621class PT_group : public Parse_tree_node {
623
626
627 public:
628 PT_group(PT_order_list *group_list_arg, olap_type olap_arg)
629 : group_list(group_list_arg), olap(olap_arg) {}
630
631 bool contextualize(Parse_context *pc) override;
632};
633
634class PT_order : public Parse_tree_node {
636
637 public:
639 explicit PT_order(PT_order_list *order_list_arg)
640 : order_list(order_list_arg) {}
641
642 bool contextualize(Parse_context *pc) override;
643};
644
646 public:
649
650 bool contextualize(Parse_context *pc) final;
651
652 virtual bool set_lock_for_tables(Parse_context *pc) = 0;
653
655
656 protected:
658 thr_lock_type lock_type = TL_IGNORE;
659 switch (m_lock_strength) {
661 lock_type = TL_WRITE;
662 break;
664 lock_type = TL_READ_WITH_SHARED_LOCKS;
665 break;
666 }
667
668 return {lock_type, static_cast<thr_locked_row_action>(action())};
669 }
670
671 private:
674};
675
677 public:
679 Lock_strength strength,
681 : PT_locking_clause(strength, action) {}
682
683 bool set_lock_for_tables(Parse_context *pc) override;
684};
685
687 public:
689
693 : PT_locking_clause(strength, action), m_tables(tables) {}
694
695 bool set_lock_for_tables(Parse_context *pc) override;
696
697 private:
698 /// @todo Move this function to Table_ident?
699 void print_table_ident(const THD *thd, const Table_ident *ident, String *s);
700
701 bool raise_error(THD *thd, const Table_ident *name, int error);
702
703 bool raise_error(int error);
704
706};
707
709 public:
712 }
713
714 bool push_back(PT_locking_clause *locking_clause) {
715 return m_locking_clauses.push_back(locking_clause);
716 }
717
718 bool contextualize(Parse_context *pc) override {
719 for (auto locking_clause : m_locking_clauses)
720 if (locking_clause->contextualize(pc)) return true;
721 return false;
722 }
723
724 private:
726};
727
729 public:
730 virtual bool is_set_operation() const = 0;
731
732 /**
733 True if this query expression can absorb an extraneous order by/limit
734 clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
735 trailing clause may not refer to the tables in the `<query primary>`, with
736 one glaring exception:
737
738 (...( SELECT ... )...) ORDER BY ...
739
740 If the nested query expression doesn't contain `ORDER BY`, the statement
741 is interpreted as if the `ORDER BY` was absorbed by the innermost query
742 expression, i.e.:
743
744 (...( SELECT ... ORDER BY ... )...)
745
746 There is no rewriting of the parse tree nor AST happening here, the
747 transformation is done by the contextualizer (see
748 PT_query_expression::contextualize_order_and_limit), which interprets the
749 parse tree, and builds the AST according to this interpretation. This
750 interpretation is governed by the following rule: An `ORDER BY` can be
751 absorbed if none the nested query expressions contains an `ORDER BY` *or*
752 `LIMIT`. The rule is complex, so here are some examples for illustration:
753
754 In these cases the `ORDER BY` *is* absorbed:
755
756 ( SELECT * FROM t1 ) ORDER BY t1.a;
757 (( SELECT * FROM t1 )) ORDER BY t1.a;
758
759 In these cases the ORDER BY is *not* absorbed:
760
761 ( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
762 (( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
763 ( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
764 (( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
765
766 The same happens with `LIMIT`, obviously, but the optimizer is freeer to
767 choose when to apply the limit, and there are name no resolution issues
768 involved.
769
770 @param order True if the outer query block has the ORDER BY clause.
771 @param limit True if the outer query block has the LIMIT clause.
772 */
773 virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
774 virtual bool has_into_clause() const = 0;
775 virtual bool has_trailing_into_clause() const = 0;
776
777 virtual bool is_table_value_constructor() const = 0;
779};
780
783
784 public:
786 const LEX_CSTRING &name, Item *opt_expr)
787 : m_pos{pos},
788 m_opt_prefix{opt_prefix},
789 m_name{name},
790 m_opt_expr{opt_expr} {}
791
792 bool contextualize(Parse_context *pc) override;
793
794 private:
795 const POS m_pos;
799};
800
802
805
806 public:
807 PT_set_variable(const POS &pos, const LEX_CSTRING &opt_prefix,
808 const LEX_CSTRING &name, const POS &expr_pos, Item *opt_expr)
809 : m_pos{pos},
810 m_opt_prefix{opt_prefix},
811 m_name{name},
812 m_expr_pos{expr_pos},
813 m_opt_expr{opt_expr} {}
814
815 bool contextualize(Parse_context *pc) override;
816
817 private:
818 const POS m_pos;
823};
824
828
831
832 public:
834 Item *expr_arg)
835 : name(name_arg), expr(expr_arg) {}
836
837 bool contextualize(Parse_context *pc) override;
838};
839
842
843 public:
845 const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
846 Item *opt_expr)
847 : m_scope{scope},
848 m_name_pos{name_pos},
849 m_opt_prefix{opt_prefix},
850 m_name{name},
851 m_opt_expr{opt_expr} {}
852
853 bool contextualize(Parse_context *pc) override;
854
855 private:
861};
862
866
868
869 public:
871 : opt_charset(opt_charset_arg) {}
872
873 bool contextualize(Parse_context *pc) override;
874};
875
879
881
882 public:
884
885 bool contextualize(Parse_context *pc) override;
886};
887
890
893
894 public:
895 PT_set_names(const CHARSET_INFO *opt_charset_arg,
896 const CHARSET_INFO *opt_collation_arg)
897 : opt_charset(opt_charset_arg), opt_collation(opt_collation_arg) {}
898
899 bool contextualize(Parse_context *pc) override;
900};
901
903
907
908 const char *password;
909 const char *current_password;
913
914 public:
916 const char *current_password_arg,
917 bool retain_current,
918 bool random_password,
919 const POS &expr_pos_arg)
920 : password(password_arg),
921 current_password(current_password_arg),
922 retain_current_password(retain_current),
923 random_password_generator(random_password),
924 expr_pos(expr_pos_arg) {}
925
926 bool contextualize(Parse_context *pc) override;
927};
928
932
934 const char *password;
935 const char *current_password;
939
940 public:
942 const char *password_arg,
943 const char *current_password_arg,
944 bool retain_current,
945 bool random_pass,
946 const POS &expr_pos_arg)
947 : user(user_arg),
948 password(password_arg),
949 current_password(current_password_arg),
950 retain_current_password(retain_current),
951 random_password_generator(random_pass),
952 expr_pos(expr_pos_arg) {}
953
954 bool contextualize(Parse_context *pc) override;
955};
956
959
962
963 public:
966 : type(type_arg), value(value_arg) {}
967
968 bool contextualize(Parse_context *pc) override;
969};
970
973
977
978 public:
979 PT_option_value_list_head(const POS &delimiter_pos_arg,
980 Parse_tree_node *value_arg,
981 const POS &value_pos_arg)
982 : delimiter_pos(delimiter_pos_arg),
983 value(value_arg),
984 value_pos(value_pos_arg) {}
985
986 bool contextualize(Parse_context *pc) override;
987};
988
991
993
994 public:
996 const POS &delimiter_pos_arg, Parse_tree_node *tail,
997 const POS &tail_pos)
998 : super(delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
999
1000 bool contextualize(Parse_context *pc) override {
1001 uchar dummy;
1002 if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
1003 return head->contextualize(pc) || super::contextualize(pc);
1004 }
1005};
1006
1009
1013
1014 public:
1016 const POS &head_pos_arg,
1017 PT_option_value_list_head *tail_arg)
1018 : head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
1019
1020 bool contextualize(Parse_context *pc) override;
1021};
1022
1025
1026 const char *name;
1028
1029 public:
1030 PT_transaction_characteristic(const char *name_arg, int32 value_arg)
1031 : name(name_arg), value(value_arg) {}
1032
1033 bool contextualize(Parse_context *pc) override;
1034};
1035
1038
1039 public:
1040 explicit PT_transaction_access_mode(bool is_read_only)
1041 : super("transaction_read_only", (int32)is_read_only) {}
1042};
1043
1046
1047 public:
1049 : super("transaction_isolation", (int32)level) {}
1050};
1051
1054
1057
1058 public:
1060 PT_transaction_characteristic *opt_tail_arg)
1061 : head(head_arg), opt_tail(opt_tail_arg) {}
1062
1063 bool contextualize(Parse_context *pc) override {
1064 return (super::contextualize(pc) || head->contextualize(pc) ||
1065 (opt_tail != nullptr && opt_tail->contextualize(pc)));
1066 }
1067};
1068
1072
1075
1076 public:
1078 PT_transaction_characteristics *characteristics_arg,
1079 const POS &end_pos_arg)
1080 : characteristics(characteristics_arg), end_pos(end_pos_arg) {}
1081
1082 bool contextualize(Parse_context *pc) override;
1083};
1084
1086 : public Parse_tree_node {};
1087
1091
1095
1096 public:
1098 PT_set_scoped_system_variable *head_arg, const POS &head_pos_arg,
1099 PT_option_value_list_head *opt_tail_arg)
1100 : head(head_arg), head_pos(head_pos_arg), opt_tail(opt_tail_arg) {}
1101
1102 bool contextualize(Parse_context *pc) override;
1103};
1104
1108
1111
1112 public:
1114 PT_transaction_characteristics *characteristics_arg,
1115 const POS &characteristics_pos_arg)
1116 : characteristics(characteristics_arg),
1117 characteristics_pos(characteristics_pos_arg) {}
1118
1119 bool contextualize(Parse_context *pc) override;
1120};
1121
1124
1127
1128 public:
1130 enum_var_type type_arg,
1132 : type(type_arg), list(list_arg) {}
1133
1134 bool contextualize(Parse_context *pc) override;
1135};
1136
1137class PT_set : public Parse_tree_node {
1139
1142
1143 public:
1144 PT_set(const POS &set_pos_arg, PT_start_option_value_list *list_arg)
1145 : set_pos(set_pos_arg), list(list_arg) {}
1146
1147 bool contextualize(Parse_context *pc) override;
1148};
1149
1153
1154 protected:
1156
1157 public:
1158 bool contextualize(Parse_context *pc) override;
1159};
1160
1163
1164 public:
1165 PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
1166 const CHARSET_INFO *charset_arg,
1167 const Field_separators &field_term_arg,
1168 const Line_separators &line_term_arg)
1169 : PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
1170 m_exchange.cs = charset_arg;
1171 m_exchange.field.merge_field_separators(field_term_arg);
1172 m_exchange.line.merge_line_separators(line_term_arg);
1173 }
1174
1175 bool contextualize(Parse_context *pc) override;
1176
1177 private:
1179};
1180
1183
1184 public:
1185 PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
1186 : PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
1187
1188 bool contextualize(Parse_context *pc) override;
1189
1190 private:
1192};
1193
1195 public:
1197
1198 explicit PT_select_var(const LEX_STRING &name_arg) : name(name_arg) {}
1199
1200 virtual bool is_local() const { return false; }
1201 virtual uint get_offset() const {
1202 assert(0);
1203 return 0;
1204 }
1205};
1206
1209
1211
1212#ifndef NDEBUG
1213 /*
1214 Routine to which this Item_splocal belongs. Used for checking if correct
1215 runtime context is used for variable handling.
1216 */
1218#endif
1219
1220 public:
1221 PT_select_sp_var(const LEX_STRING &name_arg) : super(name_arg) {}
1222
1223 bool is_local() const override { return true; }
1224 uint get_offset() const override { return offset; }
1225
1226 bool contextualize(Parse_context *pc) override;
1227};
1228
1231
1232 public:
1234
1236
1237 bool contextualize(Parse_context *pc) override;
1238
1239 bool push_back(PT_select_var *var) { return value.push_back(var); }
1240};
1241
1242/**
1243 Parse tree node for a single of a window extent's borders,
1244 cf. <window frame extent> in SQL 2003.
1245*/
1247 friend class Window;
1248 Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
1249 public:
1251 const bool m_date_time;
1253
1254 ///< For unbounded border
1256 : m_border_type(type), m_date_time(false) {
1258 }
1259
1260 ///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
1262 : m_value(value), m_border_type(type), m_date_time(false) {}
1263
1264 ///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
1266 : m_value(value),
1268 m_date_time(true),
1269 m_int_type(int_type) {}
1270
1271 ///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
1272 Item *border() const { return m_value; }
1273 /// Need such low-level access so that fix_fields updates the right pointer
1274 Item **border_ptr() { return &m_value; }
1275
1276 /**
1277 @returns Addition operator for computation of frames, nullptr if error.
1278 @param order_expr Expression to add to/subtract from
1279 @param prec true if PRECEDING
1280 @param asc true if ASC
1281 @param window only used for error generation
1282 */
1283 Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
1284 const Window *window);
1285};
1286
1287/**
1288 Parse tree node for one or both of a window extent's borders, cf.
1289 <window frame extent> in SQL 2003.
1290*/
1293 friend class PT_frame;
1294
1295 public:
1296 /**
1297 Constructor.
1298
1299 Frames of the form "frame_start no_frame_end" are translated during
1300 parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
1301 'end' are non-nullptr.
1302 */
1304 m_borders[0] = start;
1305 m_borders[1] = end;
1306 }
1307};
1308
1309/**
1310 Parse tree node for a window frame's exclusions, cf. the
1311 <window frame exclusion> clause in SQL 2003.
1312*/
1315
1316 public:
1318 // enum_window_frame_exclusion exclusion() { return m_exclusion; }
1319};
1320
1321/**
1322 Parse tree node for a window's frame, cf. the <window frame clause>
1323 in SQL 2003.
1324*/
1326 public:
1328
1331
1333
1334 /// If true, this is an artificial frame, not specified by the user
1336
1338 PT_exclusion *exclusion)
1339 : m_query_expression(unit),
1340 m_from(from_to->m_borders[0]),
1341 m_to(from_to->m_borders[1]),
1342 m_exclusion(exclusion) {}
1343};
1344
1346
1349
1360
1361 public:
1363 PT_hint_list *opt_hints_arg, const Query_options &options_arg,
1364 PT_item_list *item_list_arg, PT_into_destination *opt_into1_arg,
1365 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1366 Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
1367 Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
1368 bool implicit_from_clause)
1369 : opt_hints(opt_hints_arg),
1370 options(options_arg),
1371 item_list(item_list_arg),
1372 opt_into1(opt_into1_arg),
1373 m_is_from_clause_implicit{implicit_from_clause},
1374 from_clause(from_clause_arg),
1375 opt_where_clause(opt_where_clause_arg),
1376 opt_group_clause(opt_group_clause_arg),
1377 opt_having_clause(opt_having_clause_arg),
1378 opt_window_clause(opt_window_clause_arg) {
1379 assert(implicit_from_clause ? from_clause.empty() : true);
1380 }
1381
1383 const Query_options &options_arg, PT_item_list *item_list_arg,
1384 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
1385 Item *opt_where_clause_arg)
1386 : opt_hints(nullptr),
1387 options(options_arg),
1388 item_list(item_list_arg),
1391 from_clause(from_clause_arg),
1392 opt_where_clause(opt_where_clause_arg),
1396
1398 PT_item_list *item_list_arg)
1399 : opt_hints(nullptr),
1400 options(options_arg),
1401 item_list(item_list_arg),
1404 from_clause{},
1409
1410 bool contextualize(Parse_context *pc) override;
1411
1412 bool has_into_clause() const override { return opt_into1 != nullptr; }
1413 bool has_trailing_into_clause() const override {
1415 opt_where_clause == nullptr && opt_group_clause == nullptr &&
1416 opt_having_clause == nullptr && opt_window_clause == nullptr);
1417 }
1418
1419 bool is_set_operation() const override { return false; }
1420
1421 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1422
1423 bool is_table_value_constructor() const override { return false; }
1424 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1425
1426 private:
1428};
1429
1432
1434
1435 public:
1437 : row_value_list(row_value_list_arg) {}
1438
1439 bool contextualize(Parse_context *pc) override;
1440
1441 bool has_into_clause() const override { return false; }
1442 bool has_trailing_into_clause() const override { return false; }
1443
1444 bool is_set_operation() const override { return false; }
1445
1446 bool can_absorb_order_and_limit(bool, bool) const override { return true; }
1447
1448 bool is_table_value_constructor() const override { return true; }
1449
1451 return row_value_list;
1452 }
1453};
1454
1457
1458 public:
1460 const Query_options &options_arg, PT_item_list *item_list_arg,
1461 const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
1462 : super(options_arg, item_list_arg, from_clause_arg, nullptr) {}
1463};
1464
1466 public:
1468 PT_query_expression_body *body, PT_order *order,
1469 PT_limit_clause *limit)
1470 : m_body(body),
1471 m_order(order),
1472 m_limit(limit),
1473 m_with_clause(with_clause) {}
1474
1476 PT_limit_clause *limit)
1477 : PT_query_expression(nullptr, body, order, limit) {}
1478
1481
1482 bool contextualize(Parse_context *pc) override;
1483
1484 bool is_set_operation() const override { return m_body->is_set_operation(); }
1485
1486 bool has_into_clause() const override { return m_body->has_into_clause(); }
1487 bool has_trailing_into_clause() const override {
1488 return (m_body->has_trailing_into_clause() && m_order == nullptr &&
1489 m_limit == nullptr);
1490 }
1491
1492 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1493 if (m_body->is_set_operation()) {
1494 return false;
1495 }
1496 if (m_order == nullptr && m_limit == nullptr) {
1497 /*
1498 It is safe to push ORDER and/or LIMIT down in:
1499
1500 (SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
1501 (SELECT ...<no order or limit clauses>) ORDER BY ...;
1502 (SELECT ...<no order or limit clauses>) LIMIT ...;
1503 */
1504 return true;
1505 }
1506 if (m_limit != nullptr && !order && limit) {
1507 /*
1508 In MySQL, it is ok(*) to push LIMIT down in:
1509
1510 (SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
1511
1512 *) MySQL doesn't follow the standard when overwriting `LIMIT a` with
1513 `LIMIT b` if a < b. Moreover, the result of:
1514
1515 (SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
1516
1517 can diverge from:
1518
1519 (SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
1520
1521 since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
1522 while the example (2) does overwrite.
1523
1524 TODO: add a warning, deprecate and replace this behavior with the
1525 standard one.
1526 */
1527 return true;
1528 }
1529 if (m_order != nullptr && m_limit == nullptr && !order && limit) {
1530 /*
1531 Allow pushdown of LIMIT into body with ORDER BY, e.g
1532
1533 (SELECT ... ORDER BY order1) LIMIT a;
1534 */
1535 return true;
1536 }
1537 return false;
1538 }
1539
1540 bool is_table_value_constructor() const override {
1542 }
1543
1545 return m_body->get_row_value_list();
1546 }
1547
1548 private:
1549 /**
1550 Contextualizes the order and limit clauses, re-interpreting them according
1551 to the rules. If the `<query expression body>` can absorb the clauses,
1552 they are simply contextualized into the current Query_block. If not, we
1553 have to create the "fake" Query_block unless there is one already
1554 (Query_expression::new_set_operation_query() is known to do this.)
1555
1556 @see PT_query_expression::can_absorb_order_and_limit()
1557 */
1559
1564};
1565
1566/*
1567 After the removal of the `... <locking_clause> <into_clause>` syntax
1568 PT_locking will disappear.
1569*/
1572
1573 public:
1575 PT_locking_clause_list *locking_clauses)
1576 : m_query_expression{qe}, m_locking_clauses{locking_clauses} {}
1577
1578 bool contextualize(Parse_context *pc) override {
1581 }
1582
1583 bool is_set_operation() const override {
1585 }
1586
1587 bool has_into_clause() const override {
1589 }
1590 bool has_trailing_into_clause() const override { return false; }
1591
1592 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1593 return m_query_expression->can_absorb_order_and_limit(order, limit);
1594 }
1595
1596 bool is_table_value_constructor() const override {
1598 }
1599
1602 }
1603
1604 private:
1607};
1608
1611
1615
1616 public:
1618
1620 : qe(query_expression),
1621 pos(p),
1623 m_is_derived_table(false) {}
1624
1625 bool contextualize(Parse_context *pc) override;
1626
1628};
1629
1632
1633 public:
1636 bool is_rhs_in_parentheses = false)
1637 : m_lhs(lhs),
1638 m_is_distinct(is_distinct),
1639 m_rhs(rhs),
1640 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {}
1641
1643 QueryLevel &ql);
1644 bool is_set_operation() const override { return true; }
1645
1646 bool has_into_clause() const override {
1648 }
1649 bool has_trailing_into_clause() const override {
1651 }
1652
1653 bool can_absorb_order_and_limit(bool, bool) const override { return false; }
1654
1655 bool is_table_value_constructor() const override { return false; }
1656 PT_insert_values_list *get_row_value_list() const override { return nullptr; }
1657
1658 protected:
1660 Surrounding_context context);
1666};
1667
1670
1671 public:
1673 bool contextualize(Parse_context *pc) override;
1674};
1675
1678
1679 public:
1681 bool contextualize(Parse_context *pc) override;
1682};
1683
1686
1687 public:
1689 bool contextualize(Parse_context *pc) override;
1690};
1691
1694
1695 public:
1696 /**
1697 @param qe The query expression.
1698 @param sql_command The type of SQL command.
1699 */
1701 : m_sql_command(sql_command),
1702 m_qe(qe),
1703 m_into(nullptr),
1705
1706 /**
1707 Creates a SELECT command. Only SELECT commands can have into.
1708
1709 @param qe The query expression.
1710 @param into The own INTO destination.
1711 @param has_trailing_locking_clauses True if there are locking clauses (like
1712 `FOR UPDATE`) at the end of the
1713 statement.
1714 */
1716 PT_into_destination *into = nullptr,
1717 bool has_trailing_locking_clauses = false)
1719 m_qe{qe},
1720 m_into{into},
1721 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1722
1723 Sql_cmd *make_cmd(THD *thd) override;
1724
1725 private:
1730};
1731
1732/**
1733 Top-level node for the DELETE statement
1734
1735 @ingroup ptn_stmt
1736*/
1737class PT_delete final : public Parse_tree_root {
1738 private:
1743 const char *const opt_table_alias;
1751
1752 public:
1753 // single-table DELETE node constructor:
1754 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1755 int opt_delete_options_arg, Table_ident *table_ident_arg,
1756 const LEX_CSTRING &opt_table_alias_arg,
1757 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1758 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1759 : m_with_clause(with_clause_arg),
1760 opt_hints(opt_hints_arg),
1761 opt_delete_options(opt_delete_options_arg),
1762 table_ident(table_ident_arg),
1763 opt_table_alias(opt_table_alias_arg.str),
1764 opt_use_partition(opt_use_partition_arg),
1765 opt_where_clause(opt_where_clause_arg),
1766 opt_order_clause(opt_order_clause_arg),
1767 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1769 join_table_list.init_empty_const();
1770 }
1771
1772 // multi-table DELETE node constructor:
1773 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1774 int opt_delete_options_arg,
1775 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1776 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1777 Item *opt_where_clause_arg)
1778 : m_with_clause(with_clause_arg),
1779 opt_hints(opt_hints_arg),
1780 opt_delete_options(opt_delete_options_arg),
1783 table_list(table_list_arg),
1785 join_table_list(join_table_list_arg),
1786 opt_where_clause(opt_where_clause_arg),
1789
1790 Sql_cmd *make_cmd(THD *thd) override;
1791
1792 private:
1793 bool is_multitable() const {
1794 assert((table_ident != nullptr) ^ (table_list.size() > 0));
1795 return table_ident == nullptr;
1796 }
1797
1798 bool add_table(Parse_context *pc, Table_ident *table);
1799};
1800
1801/**
1802 Top-level node for the UPDATE statement
1803
1804 @ingroup ptn_stmt
1805*/
1817
1818 public:
1819 PT_update(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1820 thr_lock_type opt_low_priority_arg, bool opt_ignore_arg,
1821 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1822 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
1823 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
1824 Item *opt_limit_clause_arg)
1825 : m_with_clause(with_clause_arg),
1826 opt_hints(opt_hints_arg),
1827 opt_low_priority(opt_low_priority_arg),
1828 opt_ignore(opt_ignore_arg),
1829 join_table_list(join_table_list_arg),
1830 column_list(column_list_arg),
1831 value_list(value_list_arg),
1832 opt_where_clause(opt_where_clause_arg),
1833 opt_order_clause(opt_order_clause_arg),
1834 opt_limit_clause(opt_limit_clause_arg) {}
1835
1836 Sql_cmd *make_cmd(THD *thd) override;
1837};
1838
1841
1843
1844 public:
1846
1847 bool contextualize(Parse_context *pc) override;
1848
1850 many_values.push_back(x);
1851 return false;
1852 }
1853
1855 assert(is_contextualized());
1856 return many_values;
1857 }
1858};
1859
1860/**
1861 Top-level node for the INSERT statement
1862
1863 @ingroup ptn_stmt
1864*/
1865class PT_insert final : public Parse_tree_root {
1866 const bool is_replace;
1869 const bool ignore;
1875 const char *const opt_values_table_alias;
1879
1880 public:
1881 PT_insert(bool is_replace_arg, PT_hint_list *opt_hints_arg,
1882 thr_lock_type lock_option_arg, bool ignore_arg,
1883 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
1884 PT_item_list *column_list_arg,
1885 PT_insert_values_list *row_value_list_arg,
1886 PT_query_expression_body *insert_query_expression_arg,
1887 const LEX_CSTRING &opt_values_table_alias_arg,
1888 Create_col_name_list *opt_values_column_list_arg,
1889 PT_item_list *opt_on_duplicate_column_list_arg,
1890 PT_item_list *opt_on_duplicate_value_list_arg)
1891 : is_replace(is_replace_arg),
1892 opt_hints(opt_hints_arg),
1893 lock_option(lock_option_arg),
1894 ignore(ignore_arg),
1895 table_ident(table_ident_arg),
1896 opt_use_partition(opt_use_partition_arg),
1897 column_list(column_list_arg),
1898 row_value_list(row_value_list_arg),
1899 insert_query_expression(insert_query_expression_arg),
1900 opt_values_table_alias(opt_values_table_alias_arg.str),
1901 opt_values_column_list(opt_values_column_list_arg),
1902 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
1903 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
1904 // REPLACE statement can't have IGNORE flag:
1905 assert(!is_replace || !ignore);
1906 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
1907 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
1908 // INSERT/REPLACE ... SELECT can't have VALUES clause:
1909 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
1910 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
1911 assert((opt_on_duplicate_column_list == nullptr &&
1912 opt_on_duplicate_value_list == nullptr) ||
1915 }
1916
1917 Sql_cmd *make_cmd(THD *thd) override;
1918
1919 private:
1920 bool has_query_block() const { return insert_query_expression != nullptr; }
1921};
1922
1923class PT_call final : public Parse_tree_root {
1926
1927 public:
1928 PT_call(sp_name *proc_name_arg, PT_item_list *opt_expr_list_arg)
1929 : proc_name(proc_name_arg), opt_expr_list(opt_expr_list_arg) {}
1930
1931 Sql_cmd *make_cmd(THD *thd) override;
1932};
1933
1934/**
1935 Top-level node for the SHUTDOWN statement
1936
1937 @ingroup ptn_stmt
1938*/
1939class PT_shutdown final : public Parse_tree_root {
1941
1942 public:
1943 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
1944};
1945
1946/**
1947 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
1948
1949 @ingroup ptn_stmt
1950*/
1951class PT_create_srs final : public Parse_tree_root {
1952 /// The SQL command object.
1954 /// Whether OR REPLACE is specified.
1956 /// Whether IF NOT EXISTS is specified.
1958 /// SRID of the SRS to create.
1959 ///
1960 /// The range is larger than that of gis::srid_t, so it must be
1961 /// verified to be less than the uint32 maximum value.
1962 unsigned long long m_srid;
1963 /// All attributes except SRID.
1965
1966 /// Check if a UTF-8 string contains control characters.
1967 ///
1968 /// @note This function only checks single byte control characters (U+0000 to
1969 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
1970 /// that are not detected by this function.
1971 ///
1972 /// @param str The string.
1973 /// @param length Length of the string.
1974 ///
1975 /// @retval false The string contains no control characters.
1976 /// @retval true The string contains at least one control character.
1977 bool contains_control_char(char *str, size_t length) {
1978 for (size_t pos = 0; pos < length; pos++) {
1979 if (std::iscntrl(str[pos])) return true;
1980 }
1981 return false;
1982 }
1983
1984 public:
1985 PT_create_srs(unsigned long long srid,
1986 const Sql_cmd_srs_attributes &attributes, bool or_replace,
1987 bool if_not_exists)
1988 : m_or_replace(or_replace),
1989 m_if_not_exists(if_not_exists),
1990 m_srid(srid),
1991 m_attributes(attributes) {}
1992
1993 Sql_cmd *make_cmd(THD *thd) override;
1994};
1995
1996/**
1997 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
1998
1999 @ingroup ptn_stmt
2000*/
2001class PT_drop_srs final : public Parse_tree_root {
2002 /// The SQL command object.
2004 /// SRID of the SRS to drop.
2005 ///
2006 /// The range is larger than that of gis::srid_t, so it must be
2007 /// verified to be less than the uint32 maximum value.
2008 unsigned long long m_srid;
2009
2010 public:
2011 PT_drop_srs(unsigned long long srid, bool if_exists)
2012 : sql_cmd(srid, if_exists), m_srid(srid) {}
2013
2014 Sql_cmd *make_cmd(THD *thd) override;
2015};
2016
2017/**
2018 Top-level node for the ALTER INSTANCE statement
2019
2020 @ingroup ptn_stmt
2021*/
2024
2025 public:
2027 enum alter_instance_action_enum alter_instance_action,
2028 const LEX_CSTRING &channel)
2029 : sql_cmd(alter_instance_action, channel) {}
2030
2031 Sql_cmd *make_cmd(THD *thd) override;
2032};
2033
2034/**
2035 A template-free base class for index options that we can predeclare in
2036 sql_lex.h
2037*/
2039
2040/**
2041 A key part specification.
2042
2043 This can either be a "normal" key part (a key part that points to a column),
2044 or this can be a functional key part (a key part that points to an
2045 expression).
2046*/
2049
2050 public:
2051 /**
2052 Constructor for a functional key part.
2053
2054 @param expression The expression to index.
2055 @param order The direction of the index.
2056 */
2057 PT_key_part_specification(Item *expression, enum_order order);
2058
2059 /**
2060 Constructor for a "normal" key part. That is a key part that points to a
2061 column and not an expression.
2062
2063 @param column_name The column name that this key part points to.
2064 @param order The direction of the index.
2065 @param prefix_length How many bytes or characters this key part should
2066 index, or zero if it should index the entire column.
2067 */
2068 PT_key_part_specification(const LEX_CSTRING &column_name, enum_order order,
2069 int prefix_length);
2070
2071 /**
2072 Contextualize this key part specification. This will also call itemize on
2073 the indexed expression if this is a functional key part.
2074
2075 @param pc The parse context
2076
2077 @retval true on error
2078 @retval false on success
2079 */
2080 bool contextualize(Parse_context *pc) override;
2081
2082 /**
2083 Get the indexed expression. The caller must ensure that has_expression()
2084 returns true before calling this.
2085
2086 @returns The indexed expression
2087 */
2089 assert(has_expression());
2090 return m_expression;
2091 }
2092
2093 /**
2094 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2095 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2096 direction.
2097 */
2098 enum_order get_order() const { return m_order; }
2099
2100 /**
2101 @retval true if the user explicitly specified a direction (asc/desc).
2102 @retval false if the user didn't explicitly specify a direction.
2103 */
2104 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2105
2106 /**
2107 @retval true if the key part contains an expression (and thus is a
2108 functional key part).
2109 @retval false if the key part doesn't contain an expression.
2110 */
2111 bool has_expression() const { return m_expression != nullptr; }
2112
2113 /**
2114 Get the column that this key part points to. This is only valid if this
2115 key part isn't a functional index. The caller must thus check the return
2116 value of has_expression() before calling this function.
2117
2118 @returns The column that this key part points to.
2119 */
2121 assert(!has_expression());
2122 return m_column_name;
2123 }
2124
2125 /**
2126 @returns The number of bytes that this key part should index. If the column
2127 this key part points to is a non-binary column, this is the number
2128 of characters. Returns zero if the entire column should be indexed.
2129 */
2130 int get_prefix_length() const { return m_prefix_length; }
2131
2132 private:
2133 /**
2134 The indexed expression in case this is a functional key part. Only valid if
2135 has_expression() returns true.
2136 */
2138
2139 /// The direction of the index.
2141
2142 /// The name of the column that this key part indexes.
2144
2145 /**
2146 If this is greater than zero, it represents how many bytes of the column
2147 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2148 is the number of characters.
2149 */
2151};
2152
2153/**
2154 A template for options that set a single `<alter option>` value in
2155 thd->lex->key_create_info.
2156
2157 @tparam Option_type The data type of the option.
2158 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2159*/
2160template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2162 public:
2163 /// @param option_value The value of the option.
2164 PT_index_option(Option_type option_value) : m_option_value(option_value) {}
2165
2168 return false;
2169 }
2170
2171 private:
2172 Option_type m_option_value;
2173};
2174
2175/**
2176 A template for options that set a single property in a KEY_CREATE_INFO, and
2177 also records if the option was explicitly set.
2178*/
2179template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2180 bool KEY_CREATE_INFO::*Property_is_explicit>
2182 public:
2183 PT_traceable_index_option(Option_type option_value)
2184 : m_option_value(option_value) {}
2185
2188 pc->key_create_info->*Property_is_explicit = true;
2189 return false;
2190 }
2191
2192 private:
2193 Option_type m_option_value;
2194};
2195
2203
2204/**
2205 The data structure (B-tree, Hash, etc) used for an index is called
2206 'index_type' in the manual. Internally, this is stored in
2207 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2208 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2209 it's ignored. The terminology is somewhat confusing, but we stick to the
2210 manual in the parser.
2211*/
2215
2217 public:
2219 const LEX_STRING &name_arg, PT_base_index_option *type,
2220 Table_ident *table_ident,
2226 m_keytype(type_par),
2227 m_name(name_arg),
2228 m_type(type),
2229 m_table_ident(table_ident),
2230 m_columns(cols),
2232 m_algo(algo),
2233 m_lock(lock) {}
2234
2235 Sql_cmd *make_cmd(THD *thd) override;
2236
2237 private:
2246};
2247
2248/**
2249 Base class for column/constraint definitions in CREATE %TABLE
2250
2251 @ingroup ptn_create_table_stuff
2252*/
2254
2256
2259
2260 public:
2265 : m_keytype(type_par),
2266 m_name(name_arg),
2267 m_type(type),
2268 m_columns(cols),
2269 m_options(options) {}
2270
2271 bool contextualize(Table_ddl_parse_context *pc) override;
2272
2273 private:
2279};
2280
2283
2284 public:
2286 const LEX_STRING &key_name,
2288 Table_ident *referenced_table,
2289 List<Key_part_spec> *ref_list,
2290 fk_match_opt fk_match_option,
2291 fk_option fk_update_opt, fk_option fk_delete_opt)
2292 : m_constraint_name(constraint_name),
2293 m_key_name(key_name),
2294 m_columns(columns),
2295 m_referenced_table(referenced_table),
2296 m_ref_list(ref_list),
2297 m_fk_match_option(fk_match_option),
2298 m_fk_update_opt(fk_update_opt),
2299 m_fk_delete_opt(fk_delete_opt) {}
2300
2301 bool contextualize(Table_ddl_parse_context *pc) override;
2302
2303 private:
2312};
2313
2314/**
2315 Common base class for CREATE TABLE and ALTER TABLE option nodes
2316
2317 @ingroup ptn_create_or_alter_table_options
2318*/
2320 public:
2321 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2322
2323 virtual bool is_rename_table() const { return false; }
2324};
2325
2327
2328/**
2329 Base class for CREATE TABLE option nodes
2330
2331 @ingroup ptn_create_or_alter_table_options
2332*/
2335
2336 public:
2337 ~PT_create_table_option() override = 0; // Force abstract class declaration
2338
2340 if (super::contextualize(pc)) return true;
2342 return false;
2343 }
2344};
2345
2347
2348/**
2349 A template for options that set a single property in HA_CREATE_INFO, and
2350 also records if the option was explicitly set.
2351*/
2352template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2353 uint64_t Property_flag>
2356
2357 const Option_type value;
2358
2359 public:
2361
2363 if (super::contextualize(pc)) return true;
2364 pc->create_info->*Property = value;
2365 pc->create_info->used_fields |= Property_flag;
2366 return false;
2367 }
2368};
2369
2370#define TYPE_AND_REF(x) decltype(x), &x
2371
2372/**
2373 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2374
2375 @ingroup ptn_create_or_alter_table_options
2376*/
2380
2381/**
2382 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2383
2384 @ingroup ptn_create_or_alter_table_options
2385*/
2389
2390/**
2391 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2392
2393 @ingroup ptn_create_or_alter_table_options
2394*/
2398
2399/**
2400 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2401
2402 @ingroup ptn_create_or_alter_table_options
2403*/
2407
2408/**
2409 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2410
2411 @ingroup ptn_create_or_alter_table_options
2412*/
2416
2417/**
2418 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2419
2420 @ingroup ptn_create_or_alter_table_options
2421*/
2425
2426/**
2427 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2428
2429 @ingroup ptn_create_or_alter_table_options
2430*/
2434
2435/**
2436 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2437
2438 @ingroup ptn_create_or_alter_table_options
2439*/
2443
2447
2452
2456
2460
2464
2468
2472
2477
2482
2484
2485/**
2486 A template for options that set HA_CREATE_INFO::table_options and
2487 also records if the option was explicitly set.
2488*/
2489template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2490 table_options_t No>
2493
2495
2496 public:
2498 : value(value) {}
2499
2501 if (super::contextualize(pc)) return true;
2502 pc->create_info->table_options &= ~(Yes | No);
2503 switch (value) {
2504 case Ternary_option::ON:
2505 pc->create_info->table_options |= Yes;
2506 break;
2508 pc->create_info->table_options |= No;
2509 break;
2511 break;
2512 default:
2513 assert(false);
2514 }
2515 pc->create_info->used_fields |= Property_flag;
2516 return false;
2517 }
2518};
2519
2520/**
2521 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2522
2523 @ingroup ptn_create_or_alter_table_options
2524
2525 PACK_KEYS | Constructor parameter
2526 ----------|----------------------
2527 1 | Ternary_option::ON
2528 0 | Ternary_option::OFF
2529 DEFAULT | Ternary_option::DEFAULT
2530*/
2532 0, // DEFAULT
2533 HA_OPTION_PACK_KEYS, // ON
2536
2537/**
2538 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2539
2540 @ingroup ptn_create_or_alter_table_options
2541
2542 STATS_PERSISTENT | Constructor parameter
2543 -----------------|----------------------
2544 1 | Ternary_option::ON
2545 0 | Ternary_option::OFF
2546 DEFAULT | Ternary_option::DEFAULT
2547*/
2549 0, // DEFAULT
2553
2554/**
2555 A template for options that set HA_CREATE_INFO::table_options and
2556 also records if the option was explicitly set.
2557*/
2558template <ulong Property_flag, table_options_t Yes, table_options_t No>
2561
2562 const bool value;
2563
2564 public:
2566
2568 if (super::contextualize(pc)) return true;
2569 pc->create_info->table_options &= ~(Yes | No);
2570 pc->create_info->table_options |= value ? Yes : No;
2571 pc->create_info->used_fields |= Property_flag;
2572 return false;
2573 }
2574};
2575
2576/**
2577 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2578
2579 @ingroup ptn_create_or_alter_table_options
2580
2581 TABLE_CHECKSUM | Constructor parameter
2582 ---------------|----------------------
2583 0 | false
2584 not 0 | true
2585*/
2587 HA_OPTION_CHECKSUM, // ON
2589 >
2591
2592/**
2593 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2594
2595 @ingroup ptn_create_or_alter_table_options
2596
2597 TABLE_CHECKSUM | Constructor parameter
2598 ---------------|----------------------
2599 0 | false
2600 not 0 | true
2601*/
2606
2607/**
2608 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2609
2610 @ingroup ptn_create_or_alter_table_options
2611*/
2614
2616
2617 public:
2618 /**
2619 @param engine Storage engine name.
2620 */
2622 : engine(engine) {}
2623
2624 bool contextualize(Table_ddl_parse_context *pc) override;
2625};
2626
2627/**
2628 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2629 table option.
2630
2631 @ingroup ptn_create_or_alter_table_options
2632*/
2635
2636 public:
2641
2642 bool contextualize(Table_ddl_parse_context *pc) override;
2643
2644 private:
2646};
2647
2648/**
2649 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2650
2651 @ingroup ptn_create_or_alter_table_options
2652*/
2655
2657
2658 public:
2659 /**
2660 @param value
2661 STATS_AUTO_RECALC | value
2662 ------------------|----------------------
2663 1 | Ternary_option::ON
2664 0 | Ternary_option::OFF
2665 DEFAULT | Ternary_option::DEFAULT
2666 */
2668
2669 bool contextualize(Table_ddl_parse_context *pc) override;
2670};
2671
2672/**
2673 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2674
2675 @ingroup ptn_create_or_alter_table_options
2676*/
2680
2682
2683 public:
2684 /**
2685 Constructor for implicit number of pages
2686
2687 @param value Number of pages, 1@<=N@<=65535.
2688 */
2690 assert(value != 0 && value <= 0xFFFF);
2691 }
2692 /**
2693 Constructor for the DEFAULT number of pages
2694 */
2696
2697 bool contextualize(Table_ddl_parse_context *pc) override;
2698};
2699
2702
2704
2705 public:
2707 : tables(tables) {}
2708
2709 bool contextualize(Table_ddl_parse_context *pc) override;
2710};
2711
2714
2716
2717 public:
2719
2721 if (super::contextualize(pc)) return true;
2723 return false;
2724 }
2725};
2726
2729
2731
2732 public:
2734 : value(value) {
2735 assert(value != nullptr);
2736 }
2737
2738 bool contextualize(Table_ddl_parse_context *pc) override;
2739};
2740
2743
2745
2746 public:
2748 : value(value) {
2749 assert(value != nullptr);
2750 }
2751
2752 bool contextualize(Table_ddl_parse_context *pc) override;
2753};
2754
2758
2759 public:
2760 explicit PT_check_constraint(LEX_STRING &name, Item *expr, bool is_enforced) {
2761 cc_spec.name = name;
2762 cc_spec.check_expr = expr;
2763 cc_spec.is_enforced = is_enforced;
2764 }
2766
2767 bool contextualize(Table_ddl_parse_context *pc) override;
2768};
2769
2772
2775 // Currently we ignore that constraint in the executor.
2777
2778 const char *opt_place;
2779
2780 public:
2783 const char *opt_place = nullptr)
2788
2789 bool contextualize(Table_ddl_parse_context *pc) override;
2790};
2791
2792/**
2793 Top-level node for the CREATE %TABLE statement
2794
2795 @ingroup ptn_create_table
2796*/
2807
2809
2810 public:
2811 /**
2812 @param mem_root MEM_ROOT to use for allocation
2813 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
2814 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
2815 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
2816 @param opt_table_element_list NULL or a list of table column and
2817 constraint definitions.
2818 @param opt_create_table_options NULL or a list of
2819 @ref ptn_create_or_alter_table_options
2820 "table options".
2821 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
2822 @param on_duplicate DUPLICATE, IGNORE or fail with an error
2823 on data duplication errors (relevant
2824 for @SQL{CREATE TABLE ... SELECT}
2825 statements).
2826 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
2827 */
2845 /**
2846 @param mem_root MEM_ROOT to use for allocation
2847 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
2848 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
2849 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
2850 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
2851 */
2865
2866 Sql_cmd *make_cmd(THD *thd) override;
2867};
2868
2869class PT_create_role final : public Parse_tree_root {
2871
2872 public:
2873 PT_create_role(bool if_not_exists, const List<LEX_USER> *roles)
2874 : sql_cmd(if_not_exists, roles) {}
2875
2876 Sql_cmd *make_cmd(THD *thd) override;
2877};
2878
2879class PT_drop_role final : public Parse_tree_root {
2881
2882 public:
2883 explicit PT_drop_role(bool ignore_errors, const List<LEX_USER> *roles)
2884 : sql_cmd(ignore_errors, roles) {}
2885
2886 Sql_cmd *make_cmd(THD *thd) override;
2887};
2888
2891
2892 public:
2893 explicit PT_set_role(role_enum role_type,
2894 const List<LEX_USER> *opt_except_roles = nullptr)
2895 : sql_cmd(role_type, opt_except_roles) {
2896 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
2897 }
2898 explicit PT_set_role(const List<LEX_USER> *roles) : sql_cmd(roles) {}
2899
2900 Sql_cmd *make_cmd(THD *thd) override;
2901};
2902
2903/**
2904 This class is used for representing both static and dynamic privileges on
2905 global as well as table and column level.
2906*/
2909
2912
2915 : type(type), columns(columns) {}
2916};
2917
2920
2922 : Privilege(STATIC, columns_arg), grant(grant) {}
2923};
2924
2927
2929 const Mem_root_array<LEX_CSTRING> *columns_arg)
2930 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
2931};
2932
2934 private:
2936
2937 public:
2938 explicit PT_role_or_privilege(const POS &pos) : pos(pos) {}
2939 virtual LEX_USER *get_user(THD *thd);
2940 virtual Privilege *get_privilege(THD *thd);
2941};
2942
2946
2947 public:
2949 const LEX_STRING &host)
2951
2952 LEX_USER *get_user(THD *thd) override;
2953};
2954
2957
2958 public:
2961
2962 LEX_USER *get_user(THD *thd) override;
2963 Privilege *get_privilege(THD *thd) override;
2964};
2965
2969
2970 public:
2972 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
2974
2975 Privilege *get_privilege(THD *thd) override;
2976};
2977
2980
2981 public:
2984
2985 Privilege *get_privilege(THD *thd) override;
2986};
2987
2988class PT_grant_roles final : public Parse_tree_root {
2992
2993 public:
2997
2998 Sql_cmd *make_cmd(THD *thd) override;
2999};
3000
3001class PT_revoke_roles final : public Parse_tree_root {
3004
3005 public:
3007 const List<LEX_USER> *users)
3008 : roles(roles), users(users) {}
3009
3010 Sql_cmd *make_cmd(THD *thd) override;
3011};
3012
3015
3016 public:
3017 PT_alter_user_default_role(bool if_exists, const List<LEX_USER> *users,
3018 const List<LEX_USER> *roles,
3019 const role_enum role_type)
3020 : sql_cmd(if_exists, users, roles, role_type) {}
3021
3022 Sql_cmd *make_cmd(THD *thd) override;
3023};
3024
3025/// Base class for Parse tree nodes of SHOW statements
3026
3028 protected:
3030 : m_pos(pos), m_sql_command(sql_command) {}
3031
3032 /// Textual location of a token just parsed.
3034 /// SQL command
3036};
3037
3038/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3039
3041 protected:
3043 const LEX_STRING &wild, Item *where)
3044 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3045 assert(m_wild.str == nullptr || m_where == nullptr);
3046 }
3047 /// Wild or where clause used in the statement.
3050};
3051
3052/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3053
3055 protected:
3057 char *opt_db, const LEX_STRING &wild, Item *where)
3058 : PT_show_base(pos, sql_command),
3060 m_wild(wild),
3061 m_where(where) {
3062 assert(m_wild.str == nullptr || m_where == nullptr);
3063 }
3064 /// Optional schema name in FROM/IN clause.
3066 /// Wild or where clause used in the statement.
3069};
3070
3071/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3072
3074 protected:
3076 Table_ident *table_ident, const LEX_STRING &wild,
3077 Item *where)
3078 : PT_show_filter_base(pos, sql_command, wild, where),
3079 m_table_ident(table_ident) {}
3080
3081 bool make_table_base_cmd(THD *thd, bool *temporary);
3082
3083 /// Table used in the statement.
3085};
3086
3087/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3088
3090 protected:
3092 const sp_name *routine_name)
3093 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3094
3095 Sql_cmd *make_cmd(THD *thd) override;
3096
3097 private:
3099};
3100
3101/// Parse tree node for SHOW BINLOG EVENTS statement
3102
3104 public:
3105 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3106 PT_limit_clause *opt_limit_clause = nullptr)
3108 m_opt_log_file_name(opt_log_file_name),
3109 m_opt_limit_clause(opt_limit_clause) {}
3110
3111 Sql_cmd *make_cmd(THD *thd) override;
3112
3113 private:
3116
3118};
3119
3120/// Parse tree node for SHOW BINLOGS statement
3121
3122class PT_show_binlogs final : public PT_show_base {
3123 public:
3125
3126 Sql_cmd *make_cmd(THD *thd) override;
3127
3128 private:
3130};
3131
3132/// Parse tree node for SHOW CHARACTER SET statement
3133
3135 public:
3138
3139 Sql_cmd *make_cmd(THD *thd) override;
3140
3141 private:
3143};
3144
3145/// Parse tree node for SHOW COLLATIONS statement
3146
3148 public:
3151
3152 Sql_cmd *make_cmd(THD *thd) override;
3153
3154 private:
3156};
3157
3158/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3159/// statements.
3160
3162 public:
3163 explicit PT_show_count_base(const POS &pos)
3165
3166 protected:
3167 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3168};
3169
3170/// Parse tree node for SHOW COUNT(*) ERRORS
3171
3173 public:
3175
3176 Sql_cmd *make_cmd(THD *thd) override {
3177 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3178 }
3179};
3180
3181/// Parse tree node for SHOW COUNT(*) WARNINGS
3182
3184 public:
3186
3187 Sql_cmd *make_cmd(THD *thd) override {
3188 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3189 }
3190};
3191
3192/// Parse tree node for SHOW CREATE DATABASE statement
3193
3195 public:
3196 PT_show_create_database(const POS &pos, bool if_not_exists,
3197 const LEX_STRING &name)
3199 m_if_not_exists(if_not_exists),
3200 m_name(name) {}
3201
3202 Sql_cmd *make_cmd(THD *thd) override;
3203
3204 private:
3207
3209};
3210
3211/// Parse tree node for SHOW CREATE EVENT statement
3212
3214 public:
3217
3218 Sql_cmd *make_cmd(THD *thd) override;
3219
3220 private:
3222
3224};
3225
3226/// Parse tree node for SHOW CREATE FUNCTION statement
3227
3229 public:
3230 PT_show_create_function(const POS &pos, sp_name *function_name)
3231 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3232
3233 Sql_cmd *make_cmd(THD *thd) override;
3234
3235 private:
3237
3239};
3240
3241/// Parse tree node for SHOW CREATE PROCEDURE statement
3242
3244 public:
3245 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3246 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3247
3248 Sql_cmd *make_cmd(THD *thd) override;
3249
3250 private:
3252
3254};
3255
3256/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3257
3259 public:
3261 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3262
3263 Sql_cmd *make_cmd(THD *thd) override;
3264
3265 private:
3267};
3268
3269/// Parse tree node for SHOW CREATE TRIGGER statement
3270
3272 public:
3273 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3275
3276 Sql_cmd *make_cmd(THD *thd) override;
3277
3278 private:
3280
3282};
3283
3284/// Parse tree node for SHOW CREATE USER statement
3285
3286class PT_show_create_user final : public PT_show_base {
3287 public:
3290
3291 Sql_cmd *make_cmd(THD *thd) override;
3292
3293 private:
3295
3297};
3298
3299/// Parse tree node for SHOW CREATE VIEW statement
3300
3301class PT_show_create_view final : public PT_show_base {
3302 public:
3304 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3305
3306 Sql_cmd *make_cmd(THD *thd) override;
3307
3308 private:
3310};
3311
3312/// Parse tree node for SHOW DATABASES statement
3313
3315 public:
3318
3319 Sql_cmd *make_cmd(THD *thd) override;
3320
3321 private:
3323};
3324
3325/// Parse tree node for SHOW ENGINE statements
3326
3328 protected:
3330 const LEX_STRING opt_engine = {})
3331 : PT_show_base(pos, sql_command),
3332 m_engine(opt_engine),
3333 m_all(opt_engine.str == nullptr) {}
3334
3336 bool m_all;
3337};
3338
3339/// Parse tree node for SHOW ENGINE LOGS statement
3340
3342 public:
3343 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3345
3346 Sql_cmd *make_cmd(THD *thd) override;
3347
3348 private:
3350};
3351
3352/// Parse tree node for SHOW ENGINE MUTEX statement
3353
3355 public:
3356 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3358
3359 Sql_cmd *make_cmd(THD *thd) override;
3360
3361 private:
3363};
3364
3365/// Parse tree node for SHOW ENGINE STATUS statement
3366
3368 public:
3369 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3371
3372 Sql_cmd *make_cmd(THD *thd) override;
3373
3374 private:
3376};
3377
3378/// Parse tree node for SHOW ENGINES statement
3379
3380class PT_show_engines final : public PT_show_base {
3381 public:
3384
3385 Sql_cmd *make_cmd(THD *thd) override;
3386
3387 private:
3389};
3390
3391/// Parse tree node for SHOW ERRORS statement
3392
3393class PT_show_errors final : public PT_show_base {
3394 public:
3395 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3397 m_opt_limit_clause(opt_limit_clause) {}
3398
3399 Sql_cmd *make_cmd(THD *thd) override;
3400
3401 private:
3403
3405};
3406
3407/// Parse tree node for SHOW EVENTS statement
3408
3410 public:
3411 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3412 Item *where)
3414
3415 Sql_cmd *make_cmd(THD *thd) override;
3416
3417 private:
3419};
3420
3421/// Parse tree node for SHOW COLUMNS statement.
3422
3425
3426 public:
3427 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3428 Table_ident *table, LEX_STRING opt_wild = {},
3429 Item *opt_where = nullptr)
3430 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3431 m_show_cmd_type(show_cmd_type) {}
3432
3433 Sql_cmd *make_cmd(THD *thd) override;
3434
3435 private:
3438};
3439
3440/// Parse tree node for SHOW FUNCTION CODE statement.
3441
3443 public:
3444 PT_show_function_code(const POS &pos, const sp_name *function_name)
3445 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3446};
3447
3448/// Parse tree node for SHOW GRANTS statement.
3449
3450class PT_show_grants final : public PT_show_base {
3451 public:
3452 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3453 const List<LEX_USER> *opt_using_users)
3455 sql_cmd(opt_for_user, opt_using_users) {
3456 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3457 }
3458
3459 Sql_cmd *make_cmd(THD *thd) override;
3460
3461 private:
3463};
3464
3465/// Parse tree node for SHOW INDEX statement.
3466
3467class PT_show_keys final : public PT_show_table_base {
3468 public:
3469 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3470 Item *where)
3472 m_extended_show(extended_show) {}
3473
3474 Sql_cmd *make_cmd(THD *thd) override;
3475
3476 private:
3478
3479 // Flag to indicate EXTENDED keyword usage in the statement.
3482};
3483
3484/// Parse tree node for SHOW MASTER STATUS statement
3485
3487 public:
3490
3491 Sql_cmd *make_cmd(THD *thd) override;
3492
3493 private:
3495};
3496
3497/// Parse tree node for SHOW OPEN TABLES statement
3498
3500 public:
3501 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3502 Item *where)
3504 }
3505
3506 Sql_cmd *make_cmd(THD *thd) override;
3507
3508 private:
3510};
3511
3512/// Parse tree node for SHOW PLUGINS statement
3513
3514class PT_show_plugins final : public PT_show_base {
3515 public:
3517
3518 Sql_cmd *make_cmd(THD *thd) override;
3519
3520 private:
3522};
3523
3524/// Parse tree node for SHOW PRIVILEGES statement
3525
3526class PT_show_privileges final : public PT_show_base {
3527 public:
3530
3531 Sql_cmd *make_cmd(THD *thd) override;
3532
3533 private:
3535};
3536
3537/// Parse tree node for SHOW FUNCTION CODE statement.
3538
3540 public:
3541 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3542 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3543};
3544
3545/// Parse tree node for SHOW PROCESSLIST statement
3546
3547class PT_show_processlist final : public PT_show_base {
3548 public:
3551
3552 Sql_cmd *make_cmd(THD *thd) override;
3553
3554 private:
3556};
3557
3558/// Parse tree node for SHOW PROFILE statement
3559
3560class PT_show_profile final : public PT_show_base {
3561 public:
3562 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3563 my_thread_id opt_query_id = 0,
3564 PT_limit_clause *opt_limit_clause = nullptr)
3566 m_opt_profile_options(opt_profile_options),
3567 m_opt_query_id(opt_query_id),
3568 m_opt_limit_clause(opt_limit_clause) {}
3569
3570 Sql_cmd *make_cmd(THD *thd) override;
3571
3572 private:
3576
3578};
3579
3580/// Parse tree node for SHOW PROFILES statement
3581
3582class PT_show_profiles final : public PT_show_base {
3583 public:
3585
3586 Sql_cmd *make_cmd(THD *thd) override;
3587
3588 private:
3590};
3591
3592/// Parse tree node for SHOW RELAYLOG EVENTS statement
3593
3595 public:
3597 const LEX_STRING opt_log_file_name = {},
3598 PT_limit_clause *opt_limit_clause = nullptr,
3599 LEX_CSTRING opt_channel_name = {})
3601 m_opt_log_file_name(opt_log_file_name),
3602 m_opt_limit_clause(opt_limit_clause),
3603 m_opt_channel_name(opt_channel_name) {}
3604
3605 Sql_cmd *make_cmd(THD *thd) override;
3606
3607 private:
3611
3613};
3614
3615/// Parse tree node for SHOW REPLICAS statement
3616
3617class PT_show_replicas final : public PT_show_base {
3618 public:
3621
3622 Sql_cmd *make_cmd(THD *thd) override;
3623
3624 private:
3626};
3627
3628/// Parse tree node for SHOW REPLICA STATUS statement
3629
3631 public:
3632 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3634 m_opt_channel_name(opt_channel_name) {}
3635
3636 Sql_cmd *make_cmd(THD *thd) override;
3637
3638 private:
3640
3642};
3643
3644/// Parse tree node for SHOW STATUS statement
3645
3647 public:
3648 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3649 Item *where)
3651 m_var_type(var_type) {
3653 }
3654
3655 Sql_cmd *make_cmd(THD *thd) override;
3656
3657 private:
3659
3661};
3662
3663/// Parse tree node for SHOW STATUS FUNCTION statement
3664
3666 public:
3669
3670 Sql_cmd *make_cmd(THD *thd) override;
3671
3672 private:
3674};
3675
3676/// Parse tree node for SHOW STATUS PROCEDURE statement
3677
3679 public:
3682
3683 Sql_cmd *make_cmd(THD *thd) override;
3684
3685 private:
3687};
3688
3689/// Parse tree node for SHOW TABLE STATUS statement
3690
3692 public:
3693 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
3694 Item *where)
3696 where) {}
3697
3698 Sql_cmd *make_cmd(THD *thd) override;
3699
3700 private:
3702};
3703
3704/// Parse tree node for SHOW TABLES statement
3705
3707 public:
3708 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
3709 const LEX_STRING &wild, Item *where)
3711 m_show_cmd_type(show_cmd_type) {}
3712
3713 Sql_cmd *make_cmd(THD *thd) override;
3714
3715 private:
3717
3719};
3720
3721/// Parse tree node for SHOW TRIGGERS statement
3722
3724 public:
3725 PT_show_triggers(const POS &pos, bool full, char *opt_db,
3726 const LEX_STRING &wild, Item *where)
3728 m_full(full) {}
3729
3730 Sql_cmd *make_cmd(THD *thd) override;
3731
3732 private:
3734
3736};
3737
3738/// Parse tree node for SHOW VARIABLES statement
3739
3741 public:
3743 const LEX_STRING &wild, Item *where)
3745 m_var_type(var_type) {
3747 }
3748
3749 Sql_cmd *make_cmd(THD *thd) override;
3750
3751 private:
3753
3755};
3756
3757/// Parse tree node for SHOW WARNINGS statement
3758
3759class PT_show_warnings final : public PT_show_base {
3760 public:
3761 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3763 m_opt_limit_clause(opt_limit_clause) {}
3764
3765 Sql_cmd *make_cmd(THD *thd) override;
3766
3767 private:
3769
3771};
3772
3775
3776 protected:
3778 : flag(flag) {}
3779
3780 public:
3781 bool contextualize(Table_ddl_parse_context *pc) override;
3782
3783 protected:
3784 /**
3785 A routine used by the parser to decide whether we are specifying a full
3786 partitioning or if only partitions to add or to reorganize.
3787
3788 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
3789 @retval false Something else.
3790 */
3794 }
3795
3796 public:
3798};
3799
3802
3803 public:
3805 PT_field_def_base *field_def,
3806 PT_table_constraint_def *opt_column_constraint,
3807 const char *opt_place)
3808 : super(Alter_info::ALTER_ADD_COLUMN),
3809 m_column_def(field_ident, field_def, opt_column_constraint, opt_place) {
3810 }
3811
3814 }
3815
3816 private:
3818};
3819
3822
3823 public:
3826 : super(Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
3827
3829 if (super::contextualize(pc)) return true;
3830
3831 for (auto *column : *m_columns)
3832 if (column->contextualize(pc)) return true;
3833
3834 return false;
3835 }
3836
3837 private:
3839};
3840
3843
3844 public:
3846 : super(Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
3847
3850 }
3851
3852 private:
3854};
3855
3858
3859 public:
3861 const LEX_STRING &new_name,
3862 PT_field_def_base *field_def,
3863 const char *opt_place)
3864 : super(Alter_info::ALTER_CHANGE_COLUMN),
3865 m_old_name(old_name),
3866 m_new_name(new_name),
3867 m_field_def(field_def),
3868 m_opt_place(opt_place) {}
3869
3871 PT_field_def_base *field_def,
3872 const char *opt_place)
3873 : PT_alter_table_change_column(name, name, field_def, opt_place) {}
3874
3875 bool contextualize(Table_ddl_parse_context *pc) override;
3876
3877 private:
3881 const char *m_opt_place;
3882};
3883
3886
3887 protected:
3889 Alter_info::Alter_info_flag alter_info_flag,
3890 const char *name)
3891 : super(alter_info_flag), m_alter_drop(drop_type, name) {}
3892
3893 public:
3895 return (super::contextualize(pc) ||
3896 pc->alter_info->drop_list.push_back(&m_alter_drop));
3897 }
3898
3899 private:
3901};
3902
3904 public:
3905 explicit PT_alter_table_drop_column(const char *name)
3906 : PT_alter_table_drop(Alter_drop::COLUMN, Alter_info::ALTER_DROP_COLUMN,
3907 name) {}
3908};
3909
3911 public:
3914 Alter_info::DROP_FOREIGN_KEY, name) {}
3915};
3916
3918 public:
3919 explicit PT_alter_table_drop_key(const char *name)
3920 : PT_alter_table_drop(Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
3921 name) {}
3922};
3923
3925 public:
3927 : PT_alter_table_drop(Alter_drop::CHECK_CONSTRAINT,
3928 Alter_info::DROP_CHECK_CONSTRAINT, name) {}
3929};
3930
3932 public:
3934 : PT_alter_table_drop(Alter_drop::ANY_CONSTRAINT,
3935 Alter_info::DROP_ANY_CONSTRAINT, name) {}
3936};
3937
3940
3941 protected:
3944 Alter_info::Alter_info_flag alter_info_flag, const char *name,
3945 bool is_enforced)
3946 : super(alter_info_flag),
3947 m_constraint_enforcement(alter_type, name, is_enforced) {}
3948
3949 public:
3950 explicit PT_alter_table_enforce_constraint(const char *name, bool is_enforced)
3951 : super(is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
3952 : Alter_info::SUSPEND_ANY_CONSTRAINT),
3954 Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
3955 is_enforced) {}
3956
3958 return (super::contextualize(pc) ||
3961 }
3962
3963 private:
3965};
3966
3969 public:
3971 bool is_enforced)
3973 Alter_constraint_enforcement::Type::CHECK_CONSTRAINT,
3974 is_enforced ? Alter_info::ENFORCE_CHECK_CONSTRAINT
3975 : Alter_info::SUSPEND_CHECK_CONSTRAINT,
3976 name, is_enforced) {}
3977};
3978
3981
3982 public:
3983 explicit PT_alter_table_enable_keys(bool enable)
3984 : super(Alter_info::ALTER_KEYS_ONOFF), m_enable(enable) {}
3985
3987 pc->alter_info->keys_onoff =
3989 return super::contextualize(pc);
3990 }
3991
3992 private:
3994};
3995
3998
3999 public:
4000 PT_alter_table_set_default(const char *col_name, Item *opt_default_expr)
4001 : super(Alter_info::ALTER_CHANGE_COLUMN_DEFAULT),
4002 m_name(col_name),
4003 m_expr(opt_default_expr) {}
4004
4005 bool contextualize(Table_ddl_parse_context *pc) override;
4006
4007 private:
4008 const char *m_name;
4010};
4011
4014
4015 public:
4016 PT_alter_table_column_visibility(const char *col_name, bool is_visible)
4017 : super(Alter_info::ALTER_COLUMN_VISIBILITY),
4018 m_alter_column(col_name, is_visible) {}
4019
4021 return (super::contextualize(pc) ||
4022 pc->alter_info->alter_list.push_back(&m_alter_column));
4023 }
4024
4025 private:
4027};
4028
4031
4032 public:
4033 PT_alter_table_index_visible(const char *name, bool visible)
4034 : super(Alter_info::ALTER_INDEX_VISIBILITY),
4035 m_alter_index_visibility(name, visible) {}
4036
4038 return (super::contextualize(pc) ||
4041 }
4042
4043 private:
4045};
4046
4049
4050 public:
4051 explicit PT_alter_table_rename(const Table_ident *ident)
4052 : super(Alter_info::ALTER_RENAME), m_ident(ident) {}
4053
4054 bool contextualize(Table_ddl_parse_context *pc) override;
4055
4056 bool is_rename_table() const override { return true; }
4057
4058 private:
4059 const Table_ident *const m_ident;
4060};
4061
4064
4065 public:
4066 PT_alter_table_rename_key(const char *from, const char *to)
4067 : super(Alter_info::ALTER_RENAME_INDEX), m_rename_key(from, to) {}
4068
4070 return super::contextualize(pc) ||
4072 }
4073
4074 private:
4076};
4077
4080
4081 public:
4082 PT_alter_table_rename_column(const char *from, const char *to)
4083 : super(Alter_info::ALTER_CHANGE_COLUMN), m_rename_column(from, to) {}
4084
4086 return super::contextualize(pc) ||
4087 pc->alter_info->alter_list.push_back(&m_rename_column);
4088 }
4089
4090 private:
4092};
4093
4096
4097 public:
4099 const CHARSET_INFO *opt_collation)
4100 : super(Alter_info::ALTER_OPTIONS),
4102 m_collation(opt_collation) {}
4103
4104 bool contextualize(Table_ddl_parse_context *pc) override;
4105
4106 private:
4109};
4110
4113
4114 public:
4115 PT_alter_table_force() : super(Alter_info::ALTER_RECREATE) {}
4116};
4117
4120
4121 public:
4123 : super(Alter_info::ALTER_ORDER), m_order(order) {}
4124
4125 bool contextualize(Table_ddl_parse_context *pc) override;
4126
4127 private:
4129};
4130
4133
4134 public:
4136 : super(Alter_info::ALTER_PARTITION), m_partition(partition) {}
4137
4138 bool contextualize(Table_ddl_parse_context *pc) override;
4139
4140 private:
4142};
4143
4146
4147 public:
4149 : super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
4150};
4151
4154
4155 friend class PT_alter_table_standalone_stmt; // to access make_cmd()
4156
4157 protected:
4159 : super(alter_info_flag) {}
4160
4161 private:
4163};
4164
4165/**
4166 Node for the @SQL{ALTER TABLE ADD PARTITION} statement
4167
4168 @ingroup ptn_alter_table
4169*/
4172
4173 public:
4174 explicit PT_alter_table_add_partition(bool no_write_to_binlog)
4175 : super(Alter_info::ALTER_ADD_PARTITION),
4176 m_no_write_to_binlog(no_write_to_binlog) {}
4177
4178 bool contextualize(Table_ddl_parse_context *pc) override;
4179
4181 return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
4182 }
4183
4184 protected: