MySQL 8.0.30
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;
400};
401
402class PT_cross_join;
403class PT_joined_table;
404
406 public:
408
409 /**
410 Lets us build a parse tree top-down, which is necessary due to the
411 context-dependent nature of the join syntax. This function adds
412 the @<table_ref@> cross join as the left-most leaf in this join tree
413 rooted at this node.
414
415 @todo: comment on non-join PT_table_reference objects
416
417 @param cj This @<table ref@> will be added if it represents a cross join.
418
419 @return The new top-level join.
420 */
422};
423
426
429 const char *const opt_table_alias;
431
432 public:
434 List<String> *opt_use_partition_arg,
435 const LEX_CSTRING &opt_table_alias_arg,
436 List<Index_hint> *opt_key_definition_arg)
437 : table_ident(table_ident_arg),
438 opt_use_partition(opt_use_partition_arg),
439 opt_table_alias(opt_table_alias_arg.str),
440 opt_key_definition(opt_key_definition_arg) {}
441
442 bool contextualize(Parse_context *pc) override;
443};
444
446 public:
448};
449
452
453 public:
456 const LEX_STRING &table_alias)
457 : m_expr(expr),
458 m_path(path),
459 m_nested_columns(nested_cols),
460 m_table_alias(table_alias) {}
461
462 bool contextualize(Parse_context *pc) override;
463
464 private:
469};
470
473
475
476 public:
480
481 bool contextualize(Parse_context *pc) override;
482};
483
486
487 public:
488 PT_derived_table(bool lateral, PT_subquery *subquery,
489 const LEX_CSTRING &table_alias,
491
492 bool contextualize(Parse_context *pc) override;
493
494 private:
497 const char *const m_table_alias;
498 /// List of explicitly specified column names; if empty, no list.
500};
501
504
505 public:
507 : m_joined_table(joined_table) {}
508
509 bool contextualize(Parse_context *pc) override;
510
511 private:
513};
514
517
518 protected:
523
526
527 public:
528 PT_joined_table(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
530 : tab1_node(tab1_node_arg),
531 join_pos(join_pos_arg),
532 m_type(type),
533 tab2_node(tab2_node_arg),
534 tr1(nullptr),
535 tr2(nullptr) {
536 static_assert(is_single_bit(JTT_INNER), "not a single bit");
537 static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
538 static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
539 static_assert(is_single_bit(JTT_LEFT), "not a single bit");
540 static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
541
542 assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
545 }
546
547 /**
548 Adds the cross join to this join operation. The cross join is nested as
549 the table reference on the left-hand side.
550 */
553 return this;
554 }
555
556 /// Adds the table reference as the right-hand side of this join.
558 assert(tab2_node == nullptr);
559 tab2_node = table;
560 }
561
562 bool contextualize(Parse_context *pc) override;
563
564 /// This class is being inherited, it should thus be abstract.
565 ~PT_joined_table() override = 0;
566
567 protected:
569};
570
571inline PT_joined_table::~PT_joined_table() = default;
572
575
576 public:
577 PT_cross_join(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
578 PT_joined_table_type Type_arg,
579 PT_table_reference *tab2_node_arg)
580 : PT_joined_table(tab1_node_arg, join_pos_arg, Type_arg, tab2_node_arg) {}
581
582 bool contextualize(Parse_context *pc) override;
583};
584
588
589 public:
590 PT_joined_table_on(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
592 PT_table_reference *tab2_node_arg, Item *on_arg)
593 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg), on(on_arg) {}
594
595 bool contextualize(Parse_context *pc) override;
596};
597
601
602 public:
604 const POS &join_pos_arg, PT_joined_table_type type,
605 PT_table_reference *tab2_node_arg,
606 List<String> *using_fields_arg)
607 : super(tab1_node_arg, join_pos_arg, type, tab2_node_arg),
608 using_fields(using_fields_arg) {}
609
610 /// A PT_joined_table_using without a list of columns denotes a natural join.
612 const POS &join_pos_arg, PT_joined_table_type type,
613 PT_table_reference *tab2_node_arg)
614 : PT_joined_table_using(tab1_node_arg, join_pos_arg, type, tab2_node_arg,
615 nullptr) {}
616
617 bool contextualize(Parse_context *pc) override;
618};
619
620class PT_group : public Parse_tree_node {
622
625
626 public:
627 PT_group(PT_order_list *group_list_arg, olap_type olap_arg)
628 : group_list(group_list_arg), olap(olap_arg) {}
629
630 bool contextualize(Parse_context *pc) override;
631};
632
633class PT_order : public Parse_tree_node {
635
637
638 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_union() 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_union() 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_union() 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_union() const override { return m_body->is_union(); }
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_union()) {
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_union_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*/
1570class PT_locking final : public PT_query_primary {
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_union() const override { return m_query_expression->is_union(); }
1584
1585 bool has_into_clause() const override {
1587 }
1588 bool has_trailing_into_clause() const override { return false; }
1589
1590 bool can_absorb_order_and_limit(bool order, bool limit) const override {
1591 return m_query_expression->can_absorb_order_and_limit(order, limit);
1592 }
1593
1594 bool is_table_value_constructor() const override {
1596 }
1597
1600 }
1601
1602 private:
1605};
1606
1609
1613
1614 public:
1616
1617 PT_subquery(POS p, PT_query_primary *query_expression)
1618 : qe(query_expression),
1619 pos(p),
1621 m_is_derived_table(false) {}
1622
1623 bool contextualize(Parse_context *pc) override;
1624
1626};
1627
1629 public:
1630 PT_union(PT_query_expression_body *lhs, const POS &lhs_pos, bool is_distinct,
1631 PT_query_primary *rhs, bool is_rhs_in_parentheses = false)
1632 : m_lhs(lhs),
1633 m_lhs_pos(lhs_pos),
1634 m_is_distinct(is_distinct),
1635 m_rhs(rhs),
1636 m_is_rhs_in_parentheses{is_rhs_in_parentheses} {}
1637
1638 bool contextualize(Parse_context *pc) override;
1639
1640 bool is_union() 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 private:
1661};
1662
1665
1666 public:
1667 /**
1668 @param qe The query expression.
1669 @param sql_command The type of SQL command.
1670 */
1672 : m_sql_command(sql_command),
1673 m_qe(qe),
1674 m_into(nullptr),
1676
1677 /**
1678 Creates a SELECT command. Only SELECT commands can have into.
1679
1680 @param qe The query expression.
1681 @param into The own INTO destination.
1682 @param has_trailing_locking_clauses True if there are locking clauses (like
1683 `FOR UPDATE`) at the end of the
1684 statement.
1685 */
1687 PT_into_destination *into = nullptr,
1688 bool has_trailing_locking_clauses = false)
1690 m_qe{qe},
1691 m_into{into},
1692 m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
1693
1695
1696 Sql_cmd *make_cmd(THD *thd) override;
1697
1698 private:
1703};
1704
1705/**
1706 Top-level node for the DELETE statement
1707
1708 @ingroup ptn_stmt
1709*/
1710class PT_delete final : public Parse_tree_root {
1711 private:
1716 const char *const opt_table_alias;
1724
1725 public:
1726 // single-table DELETE node constructor:
1727 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1728 int opt_delete_options_arg, Table_ident *table_ident_arg,
1729 const LEX_CSTRING &opt_table_alias_arg,
1730 List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
1731 PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
1732 : m_with_clause(with_clause_arg),
1733 opt_hints(opt_hints_arg),
1734 opt_delete_options(opt_delete_options_arg),
1735 table_ident(table_ident_arg),
1736 opt_table_alias(opt_table_alias_arg.str),
1737 opt_use_partition(opt_use_partition_arg),
1738 opt_where_clause(opt_where_clause_arg),
1739 opt_order_clause(opt_order_clause_arg),
1740 opt_delete_limit_clause(opt_delete_limit_clause_arg) {
1742 join_table_list.init_empty_const();
1743 }
1744
1745 // multi-table DELETE node constructor:
1746 PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1747 int opt_delete_options_arg,
1748 const Mem_root_array_YY<Table_ident *> &table_list_arg,
1749 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1750 Item *opt_where_clause_arg)
1751 : m_with_clause(with_clause_arg),
1752 opt_hints(opt_hints_arg),
1753 opt_delete_options(opt_delete_options_arg),
1756 table_list(table_list_arg),
1758 join_table_list(join_table_list_arg),
1759 opt_where_clause(opt_where_clause_arg),
1762
1763 Sql_cmd *make_cmd(THD *thd) override;
1764
1765 private:
1766 bool is_multitable() const {
1767 assert((table_ident != nullptr) ^ (table_list.size() > 0));
1768 return table_ident == nullptr;
1769 }
1770
1771 bool add_table(Parse_context *pc, Table_ident *table);
1772};
1773
1774/**
1775 Top-level node for the UPDATE statement
1776
1777 @ingroup ptn_stmt
1778*/
1790
1791 public:
1792 PT_update(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
1793 thr_lock_type opt_low_priority_arg, bool opt_ignore_arg,
1794 const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
1795 PT_item_list *column_list_arg, PT_item_list *value_list_arg,
1796 Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
1797 Item *opt_limit_clause_arg)
1798 : m_with_clause(with_clause_arg),
1799 opt_hints(opt_hints_arg),
1800 opt_low_priority(opt_low_priority_arg),
1801 opt_ignore(opt_ignore_arg),
1802 join_table_list(join_table_list_arg),
1803 column_list(column_list_arg),
1804 value_list(value_list_arg),
1805 opt_where_clause(opt_where_clause_arg),
1806 opt_order_clause(opt_order_clause_arg),
1807 opt_limit_clause(opt_limit_clause_arg) {}
1808
1809 Sql_cmd *make_cmd(THD *thd) override;
1810};
1811
1814
1816
1817 public:
1819
1820 bool contextualize(Parse_context *pc) override;
1821
1823 many_values.push_back(x);
1824 return false;
1825 }
1826
1828 assert(is_contextualized());
1829 return many_values;
1830 }
1831};
1832
1833/**
1834 Top-level node for the INSERT statement
1835
1836 @ingroup ptn_stmt
1837*/
1838class PT_insert final : public Parse_tree_root {
1839 const bool is_replace;
1842 const bool ignore;
1848 const char *const opt_values_table_alias;
1852
1853 public:
1854 PT_insert(bool is_replace_arg, PT_hint_list *opt_hints_arg,
1855 thr_lock_type lock_option_arg, bool ignore_arg,
1856 Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
1857 PT_item_list *column_list_arg,
1858 PT_insert_values_list *row_value_list_arg,
1859 PT_query_primary *insert_query_expression_arg,
1860 const LEX_CSTRING &opt_values_table_alias_arg,
1861 Create_col_name_list *opt_values_column_list_arg,
1862 PT_item_list *opt_on_duplicate_column_list_arg,
1863 PT_item_list *opt_on_duplicate_value_list_arg)
1864 : is_replace(is_replace_arg),
1865 opt_hints(opt_hints_arg),
1866 lock_option(lock_option_arg),
1867 ignore(ignore_arg),
1868 table_ident(table_ident_arg),
1869 opt_use_partition(opt_use_partition_arg),
1870 column_list(column_list_arg),
1871 row_value_list(row_value_list_arg),
1872 insert_query_expression(insert_query_expression_arg),
1873 opt_values_table_alias(opt_values_table_alias_arg.str),
1874 opt_values_column_list(opt_values_column_list_arg),
1875 opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
1876 opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
1877 // REPLACE statement can't have IGNORE flag:
1878 assert(!is_replace || !ignore);
1879 // REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
1880 assert(!is_replace || opt_on_duplicate_column_list == nullptr);
1881 // INSERT/REPLACE ... SELECT can't have VALUES clause:
1882 assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
1883 // ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
1884 assert((opt_on_duplicate_column_list == nullptr &&
1885 opt_on_duplicate_value_list == nullptr) ||
1888 }
1889
1890 Sql_cmd *make_cmd(THD *thd) override;
1891
1892 private:
1893 bool has_query_block() const { return insert_query_expression != nullptr; }
1894};
1895
1896class PT_call final : public Parse_tree_root {
1899
1900 public:
1901 PT_call(sp_name *proc_name_arg, PT_item_list *opt_expr_list_arg)
1902 : proc_name(proc_name_arg), opt_expr_list(opt_expr_list_arg) {}
1903
1904 Sql_cmd *make_cmd(THD *thd) override;
1905};
1906
1907/**
1908 Top-level node for the SHUTDOWN statement
1909
1910 @ingroup ptn_stmt
1911*/
1912class PT_shutdown final : public Parse_tree_root {
1914
1915 public:
1916 Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
1917};
1918
1919/**
1920 Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
1921
1922 @ingroup ptn_stmt
1923*/
1924class PT_create_srs final : public Parse_tree_root {
1925 /// The SQL command object.
1927 /// Whether OR REPLACE is specified.
1929 /// Whether IF NOT EXISTS is specified.
1931 /// SRID of the SRS to create.
1932 ///
1933 /// The range is larger than that of gis::srid_t, so it must be
1934 /// verified to be less than the uint32 maximum value.
1935 unsigned long long m_srid;
1936 /// All attributes except SRID.
1938
1939 /// Check if a UTF-8 string contains control characters.
1940 ///
1941 /// @note This function only checks single byte control characters (U+0000 to
1942 /// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
1943 /// that are not detected by this function.
1944 ///
1945 /// @param str The string.
1946 /// @param length Length of the string.
1947 ///
1948 /// @retval false The string contains no control characters.
1949 /// @retval true The string contains at least one control character.
1950 bool contains_control_char(char *str, size_t length) {
1951 for (size_t pos = 0; pos < length; pos++) {
1952 if (std::iscntrl(str[pos])) return true;
1953 }
1954 return false;
1955 }
1956
1957 public:
1958 PT_create_srs(unsigned long long srid,
1959 const Sql_cmd_srs_attributes &attributes, bool or_replace,
1960 bool if_not_exists)
1961 : m_or_replace(or_replace),
1962 m_if_not_exists(if_not_exists),
1963 m_srid(srid),
1964 m_attributes(attributes) {}
1965
1966 Sql_cmd *make_cmd(THD *thd) override;
1967};
1968
1969/**
1970 Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
1971
1972 @ingroup ptn_stmt
1973*/
1974class PT_drop_srs final : public Parse_tree_root {
1975 /// The SQL command object.
1977 /// SRID of the SRS to drop.
1978 ///
1979 /// The range is larger than that of gis::srid_t, so it must be
1980 /// verified to be less than the uint32 maximum value.
1981 unsigned long long m_srid;
1982
1983 public:
1984 PT_drop_srs(unsigned long long srid, bool if_exists)
1985 : sql_cmd(srid, if_exists), m_srid(srid) {}
1986
1987 Sql_cmd *make_cmd(THD *thd) override;
1988};
1989
1990/**
1991 Top-level node for the ALTER INSTANCE statement
1992
1993 @ingroup ptn_stmt
1994*/
1997
1998 public:
2000 enum alter_instance_action_enum alter_instance_action,
2001 const LEX_CSTRING &channel)
2002 : sql_cmd(alter_instance_action, channel) {}
2003
2004 Sql_cmd *make_cmd(THD *thd) override;
2005};
2006
2007/**
2008 A template-free base class for index options that we can predeclare in
2009 sql_lex.h
2010*/
2012
2013/**
2014 A key part specification.
2015
2016 This can either be a "normal" key part (a key part that points to a column),
2017 or this can be a functional key part (a key part that points to an
2018 expression).
2019*/
2022
2023 public:
2024 /**
2025 Constructor for a functional key part.
2026
2027 @param expression The expression to index.
2028 @param order The direction of the index.
2029 */
2030 PT_key_part_specification(Item *expression, enum_order order);
2031
2032 /**
2033 Constructor for a "normal" key part. That is a key part that points to a
2034 column and not an expression.
2035
2036 @param column_name The column name that this key part points to.
2037 @param order The direction of the index.
2038 @param prefix_length How many bytes or characters this key part should
2039 index, or zero if it should index the entire column.
2040 */
2041 PT_key_part_specification(const LEX_CSTRING &column_name, enum_order order,
2042 int prefix_length);
2043
2044 /**
2045 Contextualize this key part specification. This will also call itemize on
2046 the indexed expression if this is a functional key part.
2047
2048 @param pc The parse context
2049
2050 @retval true on error
2051 @retval false on success
2052 */
2053 bool contextualize(Parse_context *pc) override;
2054
2055 /**
2056 Get the indexed expression. The caller must ensure that has_expression()
2057 returns true before calling this.
2058
2059 @returns The indexed expression
2060 */
2062 assert(has_expression());
2063 return m_expression;
2064 }
2065
2066 /**
2067 @returns The direction of the index: ORDER_ASC, ORDER_DESC or
2068 ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
2069 direction.
2070 */
2071 enum_order get_order() const { return m_order; }
2072
2073 /**
2074 @retval true if the user explicitly specified a direction (asc/desc).
2075 @retval false if the user didn't explicitly specify a direction.
2076 */
2077 bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
2078
2079 /**
2080 @retval true if the key part contains an expression (and thus is a
2081 functional key part).
2082 @retval false if the key part doesn't contain an expression.
2083 */
2084 bool has_expression() const { return m_expression != nullptr; }
2085
2086 /**
2087 Get the column that this key part points to. This is only valid if this
2088 key part isn't a functional index. The caller must thus check the return
2089 value of has_expression() before calling this function.
2090
2091 @returns The column that this key part points to.
2092 */
2094 assert(!has_expression());
2095 return m_column_name;
2096 }
2097
2098 /**
2099 @returns The number of bytes that this key part should index. If the column
2100 this key part points to is a non-binary column, this is the number
2101 of characters. Returns zero if the entire column should be indexed.
2102 */
2103 int get_prefix_length() const { return m_prefix_length; }
2104
2105 private:
2106 /**
2107 The indexed expression in case this is a functional key part. Only valid if
2108 has_expression() returns true.
2109 */
2111
2112 /// The direction of the index.
2114
2115 /// The name of the column that this key part indexes.
2117
2118 /**
2119 If this is greater than zero, it represents how many bytes of the column
2120 that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
2121 is the number of characters.
2122 */
2124};
2125
2126/**
2127 A template for options that set a single `<alter option>` value in
2128 thd->lex->key_create_info.
2129
2130 @tparam Option_type The data type of the option.
2131 @tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
2132*/
2133template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
2135 public:
2136 /// @param option_value The value of the option.
2137 PT_index_option(Option_type option_value) : m_option_value(option_value) {}
2138
2141 return false;
2142 }
2143
2144 private:
2145 Option_type m_option_value;
2146};
2147
2148/**
2149 A template for options that set a single property in a KEY_CREATE_INFO, and
2150 also records if the option was explicitly set.
2151*/
2152template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
2153 bool KEY_CREATE_INFO::*Property_is_explicit>
2155 public:
2156 PT_traceable_index_option(Option_type option_value)
2157 : m_option_value(option_value) {}
2158
2161 pc->key_create_info->*Property_is_explicit = true;
2162 return false;
2163 }
2164
2165 private:
2166 Option_type m_option_value;
2167};
2168
2176
2177/**
2178 The data structure (B-tree, Hash, etc) used for an index is called
2179 'index_type' in the manual. Internally, this is stored in
2180 KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
2181 stored in partition_info::key_algorithm. In an `<create_index_stmt>`
2182 it's ignored. The terminology is somewhat confusing, but we stick to the
2183 manual in the parser.
2184*/
2188
2190 public:
2192 const LEX_STRING &name_arg, PT_base_index_option *type,
2193 Table_ident *table_ident,
2199 m_keytype(type_par),
2200 m_name(name_arg),
2201 m_type(type),
2202 m_table_ident(table_ident),
2203 m_columns(cols),
2205 m_algo(algo),
2206 m_lock(lock) {}
2207
2208 Sql_cmd *make_cmd(THD *thd) override;
2209
2210 private:
2219};
2220
2221/**
2222 Base class for column/constraint definitions in CREATE %TABLE
2223
2224 @ingroup ptn_create_table_stuff
2225*/
2227
2229
2232
2233 public:
2238 : m_keytype(type_par),
2239 m_name(name_arg),
2240 m_type(type),
2241 m_columns(cols),
2242 m_options(options) {}
2243
2244 bool contextualize(Table_ddl_parse_context *pc) override;
2245
2246 private:
2252};
2253
2256
2257 public:
2259 const LEX_STRING &key_name,
2261 Table_ident *referenced_table,
2262 List<Key_part_spec> *ref_list,
2263 fk_match_opt fk_match_option,
2264 fk_option fk_update_opt, fk_option fk_delete_opt)
2265 : m_constraint_name(constraint_name),
2266 m_key_name(key_name),
2267 m_columns(columns),
2268 m_referenced_table(referenced_table),
2269 m_ref_list(ref_list),
2270 m_fk_match_option(fk_match_option),
2271 m_fk_update_opt(fk_update_opt),
2272 m_fk_delete_opt(fk_delete_opt) {}
2273
2274 bool contextualize(Table_ddl_parse_context *pc) override;
2275
2276 private:
2285};
2286
2287/**
2288 Common base class for CREATE TABLE and ALTER TABLE option nodes
2289
2290 @ingroup ptn_create_or_alter_table_options
2291*/
2293 public:
2294 ~PT_ddl_table_option() override = 0; // Force abstract class declaration
2295
2296 virtual bool is_rename_table() const { return false; }
2297};
2298
2300
2301/**
2302 Base class for CREATE TABLE option nodes
2303
2304 @ingroup ptn_create_or_alter_table_options
2305*/
2308
2309 public:
2310 ~PT_create_table_option() override = 0; // Force abstract class declaration
2311
2313 if (super::contextualize(pc)) return true;
2315 return false;
2316 }
2317};
2318
2320
2321/**
2322 A template for options that set a single property in HA_CREATE_INFO, and
2323 also records if the option was explicitly set.
2324*/
2325template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
2326 uint64_t Property_flag>
2329
2330 const Option_type value;
2331
2332 public:
2334
2336 if (super::contextualize(pc)) return true;
2337 pc->create_info->*Property = value;
2338 pc->create_info->used_fields |= Property_flag;
2339 return false;
2340 }
2341};
2342
2343#define TYPE_AND_REF(x) decltype(x), &x
2344
2345/**
2346 Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
2347
2348 @ingroup ptn_create_or_alter_table_options
2349*/
2353
2354/**
2355 Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
2356
2357 @ingroup ptn_create_or_alter_table_options
2358*/
2362
2363/**
2364 Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
2365
2366 @ingroup ptn_create_or_alter_table_options
2367*/
2371
2372/**
2373 Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
2374
2375 @ingroup ptn_create_or_alter_table_options
2376*/
2380
2381/**
2382 Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
2383
2384 @ingroup ptn_create_or_alter_table_options
2385*/
2389
2390/**
2391 Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
2392
2393 @ingroup ptn_create_or_alter_table_options
2394*/
2398
2399/**
2400 Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
2401
2402 @ingroup ptn_create_or_alter_table_options
2403*/
2407
2408/**
2409 Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
2410
2411 @ingroup ptn_create_or_alter_table_options
2412*/
2416
2420
2425
2429
2433
2437
2441
2445
2450
2455
2457
2458/**
2459 A template for options that set HA_CREATE_INFO::table_options and
2460 also records if the option was explicitly set.
2461*/
2462template <ulong Property_flag, table_options_t Default, table_options_t Yes,
2463 table_options_t No>
2466
2468
2469 public:
2471 : value(value) {}
2472
2474 if (super::contextualize(pc)) return true;
2475 pc->create_info->table_options &= ~(Yes | No);
2476 switch (value) {
2477 case Ternary_option::ON:
2478 pc->create_info->table_options |= Yes;
2479 break;
2481 pc->create_info->table_options |= No;
2482 break;
2484 break;
2485 default:
2486 assert(false);
2487 }
2488 pc->create_info->used_fields |= Property_flag;
2489 return false;
2490 }
2491};
2492
2493/**
2494 Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
2495
2496 @ingroup ptn_create_or_alter_table_options
2497
2498 PACK_KEYS | Constructor parameter
2499 ----------|----------------------
2500 1 | Ternary_option::ON
2501 0 | Ternary_option::OFF
2502 DEFAULT | Ternary_option::DEFAULT
2503*/
2505 0, // DEFAULT
2506 HA_OPTION_PACK_KEYS, // ON
2509
2510/**
2511 Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
2512
2513 @ingroup ptn_create_or_alter_table_options
2514
2515 STATS_PERSISTENT | Constructor parameter
2516 -----------------|----------------------
2517 1 | Ternary_option::ON
2518 0 | Ternary_option::OFF
2519 DEFAULT | Ternary_option::DEFAULT
2520*/
2522 0, // DEFAULT
2526
2527/**
2528 A template for options that set HA_CREATE_INFO::table_options and
2529 also records if the option was explicitly set.
2530*/
2531template <ulong Property_flag, table_options_t Yes, table_options_t No>
2534
2535 const bool value;
2536
2537 public:
2539
2541 if (super::contextualize(pc)) return true;
2542 pc->create_info->table_options &= ~(Yes | No);
2543 pc->create_info->table_options |= value ? Yes : No;
2544 pc->create_info->used_fields |= Property_flag;
2545 return false;
2546 }
2547};
2548
2549/**
2550 Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
2551
2552 @ingroup ptn_create_or_alter_table_options
2553
2554 TABLE_CHECKSUM | Constructor parameter
2555 ---------------|----------------------
2556 0 | false
2557 not 0 | true
2558*/
2560 HA_OPTION_CHECKSUM, // ON
2562 >
2564
2565/**
2566 Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
2567
2568 @ingroup ptn_create_or_alter_table_options
2569
2570 TABLE_CHECKSUM | Constructor parameter
2571 ---------------|----------------------
2572 0 | false
2573 not 0 | true
2574*/
2579
2580/**
2581 Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
2582
2583 @ingroup ptn_create_or_alter_table_options
2584*/
2587
2589
2590 public:
2591 /**
2592 @param engine Storage engine name.
2593 */
2595 : engine(engine) {}
2596
2597 bool contextualize(Table_ddl_parse_context *pc) override;
2598};
2599
2600/**
2601 Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
2602 table option.
2603
2604 @ingroup ptn_create_or_alter_table_options
2605*/
2608
2609 public:
2614
2615 bool contextualize(Table_ddl_parse_context *pc) override;
2616
2617 private:
2619};
2620
2621/**
2622 Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
2623
2624 @ingroup ptn_create_or_alter_table_options
2625*/
2628
2630
2631 public:
2632 /**
2633 @param value
2634 STATS_AUTO_RECALC | value
2635 ------------------|----------------------
2636 1 | Ternary_option::ON
2637 0 | Ternary_option::OFF
2638 DEFAULT | Ternary_option::DEFAULT
2639 */
2641
2642 bool contextualize(Table_ddl_parse_context *pc) override;
2643};
2644
2645/**
2646 Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
2647
2648 @ingroup ptn_create_or_alter_table_options
2649*/
2653
2655
2656 public:
2657 /**
2658 Constructor for implicit number of pages
2659
2660 @param value Number of pages, 1@<=N@<=65535.
2661 */
2663 assert(value != 0 && value <= 0xFFFF);
2664 }
2665 /**
2666 Constructor for the DEFAULT number of pages
2667 */
2669
2670 bool contextualize(Table_ddl_parse_context *pc) override;
2671};
2672
2675
2677
2678 public:
2680 : tables(tables) {}
2681
2682 bool contextualize(Table_ddl_parse_context *pc) override;
2683};
2684
2687
2689
2690 public:
2692
2694 if (super::contextualize(pc)) return true;
2696 return false;
2697 }
2698};
2699
2702
2704
2705 public:
2707 : value(value) {
2708 assert(value != nullptr);
2709 }
2710
2711 bool contextualize(Table_ddl_parse_context *pc) override;
2712};
2713
2716
2718
2719 public:
2721 : value(value) {
2722 assert(value != nullptr);
2723 }
2724
2725 bool contextualize(Table_ddl_parse_context *pc) override;
2726};
2727
2731
2732 public:
2733 explicit PT_check_constraint(LEX_STRING &name, Item *expr, bool is_enforced) {
2734 cc_spec.name = name;
2735 cc_spec.check_expr = expr;
2736 cc_spec.is_enforced = is_enforced;
2737 }
2739
2740 bool contextualize(Table_ddl_parse_context *pc) override;
2741};
2742
2745
2748 // Currently we ignore that constraint in the executor.
2750
2751 const char *opt_place;
2752
2753 public:
2756 const char *opt_place = nullptr)
2761
2762 bool contextualize(Table_ddl_parse_context *pc) override;
2763};
2764
2765/**
2766 Top-level node for the CREATE %TABLE statement
2767
2768 @ingroup ptn_create_table
2769*/
2780
2782
2783 public:
2784 /**
2785 @param mem_root MEM_ROOT to use for allocation
2786 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
2787 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
2788 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
2789 @param opt_table_element_list NULL or a list of table column and
2790 constraint definitions.
2791 @param opt_create_table_options NULL or a list of
2792 @ref ptn_create_or_alter_table_options
2793 "table options".
2794 @param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
2795 @param on_duplicate DUPLICATE, IGNORE or fail with an error
2796 on data duplication errors (relevant
2797 for @SQL{CREATE TABLE ... SELECT}
2798 statements).
2799 @param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
2800 */
2818 /**
2819 @param mem_root MEM_ROOT to use for allocation
2820 @param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
2821 @param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
2822 @param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
2823 @param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
2824 */
2838
2839 Sql_cmd *make_cmd(THD *thd) override;
2840};
2841
2842class PT_create_role final : public Parse_tree_root {
2844
2845 public:
2846 PT_create_role(bool if_not_exists, const List<LEX_USER> *roles)
2847 : sql_cmd(if_not_exists, roles) {}
2848
2849 Sql_cmd *make_cmd(THD *thd) override;
2850};
2851
2852class PT_drop_role final : public Parse_tree_root {
2854
2855 public:
2856 explicit PT_drop_role(bool ignore_errors, const List<LEX_USER> *roles)
2857 : sql_cmd(ignore_errors, roles) {}
2858
2859 Sql_cmd *make_cmd(THD *thd) override;
2860};
2861
2864
2865 public:
2866 explicit PT_set_role(role_enum role_type,
2867 const List<LEX_USER> *opt_except_roles = nullptr)
2868 : sql_cmd(role_type, opt_except_roles) {
2869 assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
2870 }
2871 explicit PT_set_role(const List<LEX_USER> *roles) : sql_cmd(roles) {}
2872
2873 Sql_cmd *make_cmd(THD *thd) override;
2874};
2875
2876/**
2877 This class is used for representing both static and dynamic privileges on
2878 global as well as table and column level.
2879*/
2882
2885
2888 : type(type), columns(columns) {}
2889};
2890
2893
2895 : Privilege(STATIC, columns_arg), grant(grant) {}
2896};
2897
2900
2902 const Mem_root_array<LEX_CSTRING> *columns_arg)
2903 : Privilege(DYNAMIC, columns_arg), ident(ident) {}
2904};
2905
2907 private:
2909
2910 public:
2911 explicit PT_role_or_privilege(const POS &pos) : pos(pos) {}
2912 virtual LEX_USER *get_user(THD *thd);
2913 virtual Privilege *get_privilege(THD *thd);
2914};
2915
2919
2920 public:
2922 const LEX_STRING &host)
2924
2925 LEX_USER *get_user(THD *thd) override;
2926};
2927
2930
2931 public:
2934
2935 LEX_USER *get_user(THD *thd) override;
2936 Privilege *get_privilege(THD *thd) override;
2937};
2938
2942
2943 public:
2945 const Mem_root_array<LEX_CSTRING> *columns = nullptr)
2947
2948 Privilege *get_privilege(THD *thd) override;
2949};
2950
2953
2954 public:
2957
2958 Privilege *get_privilege(THD *thd) override;
2959};
2960
2961class PT_grant_roles final : public Parse_tree_root {
2965
2966 public:
2970
2971 Sql_cmd *make_cmd(THD *thd) override;
2972};
2973
2974class PT_revoke_roles final : public Parse_tree_root {
2977
2978 public:
2980 const List<LEX_USER> *users)
2981 : roles(roles), users(users) {}
2982
2983 Sql_cmd *make_cmd(THD *thd) override;
2984};
2985
2988
2989 public:
2990 PT_alter_user_default_role(bool if_exists, const List<LEX_USER> *users,
2991 const List<LEX_USER> *roles,
2992 const role_enum role_type)
2993 : sql_cmd(if_exists, users, roles, role_type) {}
2994
2995 Sql_cmd *make_cmd(THD *thd) override;
2996};
2997
2998/// Base class for Parse tree nodes of SHOW statements
2999
3001 protected:
3003 : m_pos(pos), m_sql_command(sql_command) {}
3004
3005 /// Textual location of a token just parsed.
3007 /// SQL command
3009};
3010
3011/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
3012
3014 protected:
3016 const LEX_STRING &wild, Item *where)
3017 : PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
3018 assert(m_wild.str == nullptr || m_where == nullptr);
3019 }
3020 /// Wild or where clause used in the statement.
3023};
3024
3025/// Base class for Parse tree nodes of SHOW statements with schema parameter.
3026
3028 protected:
3030 char *opt_db, const LEX_STRING &wild, Item *where)
3031 : PT_show_base(pos, sql_command),
3033 m_wild(wild),
3034 m_where(where) {
3035 assert(m_wild.str == nullptr || m_where == nullptr);
3036 }
3037 /// Optional schema name in FROM/IN clause.
3039 /// Wild or where clause used in the statement.
3042};
3043
3044/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
3045
3047 protected:
3049 Table_ident *table_ident, const LEX_STRING &wild,
3050 Item *where)
3051 : PT_show_filter_base(pos, sql_command, wild, where),
3052 m_table_ident(table_ident) {}
3053
3054 bool make_table_base_cmd(THD *thd, bool *temporary);
3055
3056 /// Table used in the statement.
3058};
3059
3060/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
3061
3063 protected:
3065 const sp_name *routine_name)
3066 : PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
3067
3068 Sql_cmd *make_cmd(THD *thd) override;
3069
3070 private:
3072};
3073
3074/// Parse tree node for SHOW BINLOG EVENTS statement
3075
3077 public:
3078 PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
3079 PT_limit_clause *opt_limit_clause = nullptr)
3081 m_opt_log_file_name(opt_log_file_name),
3082 m_opt_limit_clause(opt_limit_clause) {}
3083
3084 Sql_cmd *make_cmd(THD *thd) override;
3085
3086 private:
3089
3091};
3092
3093/// Parse tree node for SHOW BINLOGS statement
3094
3095class PT_show_binlogs final : public PT_show_base {
3096 public:
3098
3099 Sql_cmd *make_cmd(THD *thd) override;
3100
3101 private:
3103};
3104
3105/// Parse tree node for SHOW CHARACTER SET statement
3106
3108 public:
3111
3112 Sql_cmd *make_cmd(THD *thd) override;
3113
3114 private:
3116};
3117
3118/// Parse tree node for SHOW COLLATIONS statement
3119
3121 public:
3124
3125 Sql_cmd *make_cmd(THD *thd) override;
3126
3127 private:
3129};
3130
3131/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
3132/// statements.
3133
3135 public:
3136 explicit PT_show_count_base(const POS &pos)
3138
3139 protected:
3140 Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
3141};
3142
3143/// Parse tree node for SHOW COUNT(*) ERRORS
3144
3146 public:
3148
3149 Sql_cmd *make_cmd(THD *thd) override {
3150 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
3151 }
3152};
3153
3154/// Parse tree node for SHOW COUNT(*) WARNINGS
3155
3157 public:
3159
3160 Sql_cmd *make_cmd(THD *thd) override {
3161 return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
3162 }
3163};
3164
3165/// Parse tree node for SHOW CREATE DATABASE statement
3166
3168 public:
3169 PT_show_create_database(const POS &pos, bool if_not_exists,
3170 const LEX_STRING &name)
3172 m_if_not_exists(if_not_exists),
3173 m_name(name) {}
3174
3175 Sql_cmd *make_cmd(THD *thd) override;
3176
3177 private:
3180
3182};
3183
3184/// Parse tree node for SHOW CREATE EVENT statement
3185
3187 public:
3190
3191 Sql_cmd *make_cmd(THD *thd) override;
3192
3193 private:
3195
3197};
3198
3199/// Parse tree node for SHOW CREATE FUNCTION statement
3200
3202 public:
3203 PT_show_create_function(const POS &pos, sp_name *function_name)
3204 : PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
3205
3206 Sql_cmd *make_cmd(THD *thd) override;
3207
3208 private:
3210
3212};
3213
3214/// Parse tree node for SHOW CREATE PROCEDURE statement
3215
3217 public:
3218 PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
3219 : PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
3220
3221 Sql_cmd *make_cmd(THD *thd) override;
3222
3223 private:
3225
3227};
3228
3229/// Parse tree node for SHOW CREATE TABLE and VIEW statements
3230
3232 public:
3234 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
3235
3236 Sql_cmd *make_cmd(THD *thd) override;
3237
3238 private:
3240};
3241
3242/// Parse tree node for SHOW CREATE TRIGGER statement
3243
3245 public:
3246 PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
3248
3249 Sql_cmd *make_cmd(THD *thd) override;
3250
3251 private:
3253
3255};
3256
3257/// Parse tree node for SHOW CREATE USER statement
3258
3259class PT_show_create_user final : public PT_show_base {
3260 public:
3263
3264 Sql_cmd *make_cmd(THD *thd) override;
3265
3266 private:
3268
3270};
3271
3272/// Parse tree node for SHOW CREATE VIEW statement
3273
3274class PT_show_create_view final : public PT_show_base {
3275 public:
3277 : PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
3278
3279 Sql_cmd *make_cmd(THD *thd) override;
3280
3281 private:
3283};
3284
3285/// Parse tree node for SHOW DATABASES statement
3286
3288 public:
3291
3292 Sql_cmd *make_cmd(THD *thd) override;
3293
3294 private:
3296};
3297
3298/// Parse tree node for SHOW ENGINE statements
3299
3301 protected:
3303 const LEX_STRING opt_engine = {})
3304 : PT_show_base(pos, sql_command),
3305 m_engine(opt_engine),
3306 m_all(opt_engine.str == nullptr) {}
3307
3309 bool m_all;
3310};
3311
3312/// Parse tree node for SHOW ENGINE LOGS statement
3313
3315 public:
3316 PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
3318
3319 Sql_cmd *make_cmd(THD *thd) override;
3320
3321 private:
3323};
3324
3325/// Parse tree node for SHOW ENGINE MUTEX statement
3326
3328 public:
3329 PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
3331
3332 Sql_cmd *make_cmd(THD *thd) override;
3333
3334 private:
3336};
3337
3338/// Parse tree node for SHOW ENGINE STATUS statement
3339
3341 public:
3342 PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
3344
3345 Sql_cmd *make_cmd(THD *thd) override;
3346
3347 private:
3349};
3350
3351/// Parse tree node for SHOW ENGINES statement
3352
3353class PT_show_engines final : public PT_show_base {
3354 public:
3357
3358 Sql_cmd *make_cmd(THD *thd) override;
3359
3360 private:
3362};
3363
3364/// Parse tree node for SHOW ERRORS statement
3365
3366class PT_show_errors final : public PT_show_base {
3367 public:
3368 PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3370 m_opt_limit_clause(opt_limit_clause) {}
3371
3372 Sql_cmd *make_cmd(THD *thd) override;
3373
3374 private:
3376
3378};
3379
3380/// Parse tree node for SHOW EVENTS statement
3381
3383 public:
3384 PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
3385 Item *where)
3387
3388 Sql_cmd *make_cmd(THD *thd) override;
3389
3390 private:
3392};
3393
3394/// Parse tree node for SHOW COLUMNS statement.
3395
3398
3399 public:
3400 PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
3401 Table_ident *table, LEX_STRING opt_wild = {},
3402 Item *opt_where = nullptr)
3403 : PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
3404 m_show_cmd_type(show_cmd_type) {}
3405
3406 Sql_cmd *make_cmd(THD *thd) override;
3407
3408 private:
3411};
3412
3413/// Parse tree node for SHOW FUNCTION CODE statement.
3414
3416 public:
3417 PT_show_function_code(const POS &pos, const sp_name *function_name)
3418 : PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
3419};
3420
3421/// Parse tree node for SHOW GRANTS statement.
3422
3423class PT_show_grants final : public PT_show_base {
3424 public:
3425 PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
3426 const List<LEX_USER> *opt_using_users)
3428 sql_cmd(opt_for_user, opt_using_users) {
3429 assert(opt_using_users == nullptr || opt_for_user != nullptr);
3430 }
3431
3432 Sql_cmd *make_cmd(THD *thd) override;
3433
3434 private:
3436};
3437
3438/// Parse tree node for SHOW INDEX statement.
3439
3440class PT_show_keys final : public PT_show_table_base {
3441 public:
3442 PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
3443 Item *where)
3445 m_extended_show(extended_show) {}
3446
3447 Sql_cmd *make_cmd(THD *thd) override;
3448
3449 private:
3451
3452 // Flag to indicate EXTENDED keyword usage in the statement.
3455};
3456
3457/// Parse tree node for SHOW MASTER STATUS statement
3458
3460 public:
3463
3464 Sql_cmd *make_cmd(THD *thd) override;
3465
3466 private:
3468};
3469
3470/// Parse tree node for SHOW OPEN TABLES statement
3471
3473 public:
3474 PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
3475 Item *where)
3477 }
3478
3479 Sql_cmd *make_cmd(THD *thd) override;
3480
3481 private:
3483};
3484
3485/// Parse tree node for SHOW PLUGINS statement
3486
3487class PT_show_plugins final : public PT_show_base {
3488 public:
3490
3491 Sql_cmd *make_cmd(THD *thd) override;
3492
3493 private:
3495};
3496
3497/// Parse tree node for SHOW PRIVILEGES statement
3498
3499class PT_show_privileges final : public PT_show_base {
3500 public:
3503
3504 Sql_cmd *make_cmd(THD *thd) override;
3505
3506 private:
3508};
3509
3510/// Parse tree node for SHOW FUNCTION CODE statement.
3511
3513 public:
3514 PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
3515 : PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
3516};
3517
3518/// Parse tree node for SHOW PROCESSLIST statement
3519
3520class PT_show_processlist final : public PT_show_base {
3521 public:
3524
3525 Sql_cmd *make_cmd(THD *thd) override;
3526
3527 private:
3529};
3530
3531/// Parse tree node for SHOW PROFILE statement
3532
3533class PT_show_profile final : public PT_show_base {
3534 public:
3535 PT_show_profile(const POS &pos, uint opt_profile_options = 0,
3536 my_thread_id opt_query_id = 0,
3537 PT_limit_clause *opt_limit_clause = nullptr)
3539 m_opt_profile_options(opt_profile_options),
3540 m_opt_query_id(opt_query_id),
3541 m_opt_limit_clause(opt_limit_clause) {}
3542
3543 Sql_cmd *make_cmd(THD *thd) override;
3544
3545 private:
3549
3551};
3552
3553/// Parse tree node for SHOW PROFILES statement
3554
3555class PT_show_profiles final : public PT_show_base {
3556 public:
3558
3559 Sql_cmd *make_cmd(THD *thd) override;
3560
3561 private:
3563};
3564
3565/// Parse tree node for SHOW RELAYLOG EVENTS statement
3566
3568 public:
3570 const LEX_STRING opt_log_file_name = {},
3571 PT_limit_clause *opt_limit_clause = nullptr,
3572 LEX_CSTRING opt_channel_name = {})
3574 m_opt_log_file_name(opt_log_file_name),
3575 m_opt_limit_clause(opt_limit_clause),
3576 m_opt_channel_name(opt_channel_name) {}
3577
3578 Sql_cmd *make_cmd(THD *thd) override;
3579
3580 private:
3584
3586};
3587
3588/// Parse tree node for SHOW REPLICAS statement
3589
3590class PT_show_replicas final : public PT_show_base {
3591 public:
3594
3595 Sql_cmd *make_cmd(THD *thd) override;
3596
3597 private:
3599};
3600
3601/// Parse tree node for SHOW REPLICA STATUS statement
3602
3604 public:
3605 PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
3607 m_opt_channel_name(opt_channel_name) {}
3608
3609 Sql_cmd *make_cmd(THD *thd) override;
3610
3611 private:
3613
3615};
3616
3617/// Parse tree node for SHOW STATUS statement
3618
3620 public:
3621 PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
3622 Item *where)
3624 m_var_type(var_type) {
3626 }
3627
3628 Sql_cmd *make_cmd(THD *thd) override;
3629
3630 private:
3632
3634};
3635
3636/// Parse tree node for SHOW STATUS FUNCTION statement
3637
3639 public:
3642
3643 Sql_cmd *make_cmd(THD *thd) override;
3644
3645 private:
3647};
3648
3649/// Parse tree node for SHOW STATUS PROCEDURE statement
3650
3652 public:
3655
3656 Sql_cmd *make_cmd(THD *thd) override;
3657
3658 private:
3660};
3661
3662/// Parse tree node for SHOW TABLE STATUS statement
3663
3665 public:
3666 PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
3667 Item *where)
3669 where) {}
3670
3671 Sql_cmd *make_cmd(THD *thd) override;
3672
3673 private:
3675};
3676
3677/// Parse tree node for SHOW TABLES statement
3678
3680 public:
3681 PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
3682 const LEX_STRING &wild, Item *where)
3684 m_show_cmd_type(show_cmd_type) {}
3685
3686 Sql_cmd *make_cmd(THD *thd) override;
3687
3688 private:
3690
3692};
3693
3694/// Parse tree node for SHOW TRIGGERS statement
3695
3697 public:
3698 PT_show_triggers(const POS &pos, bool full, char *opt_db,
3699 const LEX_STRING &wild, Item *where)
3701 m_full(full) {}
3702
3703 Sql_cmd *make_cmd(THD *thd) override;
3704
3705 private:
3707
3709};
3710
3711/// Parse tree node for SHOW VARIABLES statement
3712
3714 public:
3716 const LEX_STRING &wild, Item *where)
3718 m_var_type(var_type) {
3720 }
3721
3722 Sql_cmd *make_cmd(THD *thd) override;
3723
3724 private:
3726
3728};
3729
3730/// Parse tree node for SHOW WARNINGS statement
3731
3732class PT_show_warnings final : public PT_show_base {
3733 public:
3734 PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
3736 m_opt_limit_clause(opt_limit_clause) {}
3737
3738 Sql_cmd *make_cmd(THD *thd) override;
3739
3740 private:
3742
3744};
3745
3748
3749 protected:
3751 : flag(flag) {}
3752
3753 public:
3754 bool contextualize(Table_ddl_parse_context *pc) override;
3755
3756 protected:
3757 /**
3758 A routine used by the parser to decide whether we are specifying a full
3759 partitioning or if only partitions to add or to reorganize.
3760
3761 @retval true ALTER TABLE ADD/REORGANIZE PARTITION.
3762 @retval false Something else.
3763 */
3767 }
3768
3769 public:
3771};
3772
3775
3776 public:
3778 PT_field_def_base *field_def,
3779 PT_table_constraint_def *opt_column_constraint,
3780 const char *opt_place)
3781 : super(Alter_info::ALTER_ADD_COLUMN),
3782 m_column_def(field_ident, field_def, opt_column_constraint, opt_place) {
3783 }
3784
3787 }
3788
3789 private:
3791};
3792
3795
3796 public:
3799 : super(Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
3800
3802 if (super::contextualize(pc)) return true;
3803
3804 for (auto *column : *m_columns)
3805 if (column->contextualize(pc)) return true;
3806
3807 return false;
3808 }
3809
3810 private:
3812};
3813
3816
3817 public:
3819 : super(Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
3820
3823 }
3824
3825 private:
3827};
3828
3831
3832 public:
3834 const LEX_STRING &new_name,
3835 PT_field_def_base *field_def,
3836 const char *opt_place)
3837 : super(Alter_info::ALTER_CHANGE_COLUMN),
3838 m_old_name(old_name),
3839 m_new_name(new_name),
3840 m_field_def(field_def),
3841 m_opt_place(opt_place) {}
3842
3844 PT_field_def_base *field_def,
3845 const char *opt_place)
3846 : PT_alter_table_change_column(name, name, field_def, opt_place) {}
3847
3848 bool contextualize(Table_ddl_parse_context *pc) override;
3849
3850 private:
3854 const char *m_opt_place;
3855};
3856
3859
3860 protected:
3862 Alter_info::Alter_info_flag alter_info_flag,
3863 const char *name)
3864 : super(alter_info_flag), m_alter_drop(drop_type, name) {}
3865
3866 public:
3868 return (super::contextualize(pc) ||
3869 pc->alter_info->drop_list.push_back(&m_alter_drop));
3870 }
3871
3872 private:
3874};
3875
3877 public:
3878 explicit PT_alter_table_drop_column(const char *name)
3879 : PT_alter_table_drop(Alter_drop::COLUMN, Alter_info::ALTER_DROP_COLUMN,
3880 name) {}
3881};
3882
3884 public:
3887 Alter_info::DROP_FOREIGN_KEY, name) {}
3888};
3889
3891 public:
3892 explicit PT_alter_table_drop_key(const char *name)
3893 : PT_alter_table_drop(Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
3894 name) {}
3895};
3896
3898 public:
3900 : PT_alter_table_drop(Alter_drop::CHECK_CONSTRAINT,
3901 Alter_info::DROP_CHECK_CONSTRAINT, name) {}
3902};
3903
3905 public:
3907 : PT_alter_table_drop(Alter_drop::ANY_CONSTRAINT,
3908 Alter_info::DROP_ANY_CONSTRAINT, name) {}
3909};
3910
3913
3914 protected:
3917 Alter_info::Alter_info_flag alter_info_flag, const char *name,
3918 bool is_enforced)
3919 : super(alter_info_flag),
3920 m_constraint_enforcement(alter_type, name, is_enforced) {}
3921
3922 public:
3923 explicit PT_alter_table_enforce_constraint(const char *name, bool is_enforced)
3924 : super(is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
3925 : Alter_info::SUSPEND_ANY_CONSTRAINT),
3927 Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
3928 is_enforced) {}
3929
3931 return (super::contextualize(pc) ||
3934 }
3935
3936 private:
3938};
3939
3942 public:
3944 bool is_enforced)
3946 Alter_constraint_enforcement::Type::CHECK_CONSTRAINT,
3947 is_enforced ? Alter_info::ENFORCE_CHECK_CONSTRAINT
3948 : Alter_info::SUSPEND_CHECK_CONSTRAINT,
3949 name, is_enforced) {}
3950};
3951
3954
3955 public:
3956 explicit PT_alter_table_enable_keys(bool enable)
3957 : super(Alter_info::ALTER_KEYS_ONOFF), m_enable(enable) {}
3958
3960 pc->alter_info->keys_onoff =
3962 return super::contextualize(pc);
3963 }
3964
3965 private:
3967};
3968
3971
3972 public:
3973 PT_alter_table_set_default(const char *col_name, Item *opt_default_expr)
3974 : super(Alter_info::ALTER_CHANGE_COLUMN_DEFAULT),
3975 m_name(col_name),
3976 m_expr(opt_default_expr) {}
3977
3978 bool contextualize(Table_ddl_parse_context *pc) override;
3979
3980 private:
3981 const char *m_name;
3983};
3984
3987
3988 public:
3989 PT_alter_table_column_visibility(const char *col_name, bool is_visible)
3990 : super(Alter_info::ALTER_COLUMN_VISIBILITY),
3991 m_alter_column(col_name, is_visible) {}
3992
3994 return (super::contextualize(pc) ||
3995 pc->alter_info->alter_list.push_back(&m_alter_column));
3996 }
3997
3998 private:
4000};
4001
4004
4005 public:
4006 PT_alter_table_index_visible(const char *name, bool visible)
4007 : super(Alter_info::ALTER_INDEX_VISIBILITY),
4008 m_alter_index_visibility(name, visible) {}
4009
4011 return (super::contextualize(pc) ||
4014 }
4015
4016 private:
4018};
4019
4022
4023 public:
4024 explicit PT_alter_table_rename(const Table_ident *ident)
4025 : super(Alter_info::ALTER_RENAME), m_ident(ident) {}
4026
4027 bool contextualize(Table_ddl_parse_context *pc) override;
4028
4029 bool is_rename_table() const override { return true; }
4030
4031 private:
4032 const Table_ident *const m_ident;
4033};
4034
4037
4038 public:
4039 PT_alter_table_rename_key(const char *from, const char *to)
4040 : super(Alter_info::ALTER_RENAME_INDEX), m_rename_key(from, to) {}
4041
4043 return super::contextualize(pc) ||
4045 }
4046
4047 private:
4049};
4050
4053
4054 public:
4055 PT_alter_table_rename_column(const char *from, const char *to)
4056 : super(Alter_info::ALTER_CHANGE_COLUMN), m_rename_column(from, to) {}
4057
4059 return super::contextualize(pc) ||
4060 pc->alter_info->alter_list.push_back(&m_rename_column);
4061 }
4062
4063 private:
4065};
4066
4069
4070 public:
4072 const CHARSET_INFO *opt_collation)
4073 : super(Alter_info::ALTER_OPTIONS),
4075 m_collation(opt_collation) {}
4076
4077 bool contextualize(Table_ddl_parse_context *pc) override;
4078
4079 private:
4082};
4083
4086
4087 public:
4088 PT_alter_table_force() : super(Alter_info::ALTER_RECREATE) {}
4089};
4090
4093
4094 public:
4096 : super(Alter_info::ALTER_ORDER), m_order(order) {}
4097
4098 bool contextualize(Table_ddl_parse_context *pc) override;
4099
4100 private:
4102};
4103
4106
4107 public:
4109 : super(Alter_info::ALTER_PARTITION), m_partition(partition) {}
4110
4111 bool contextualize(Table_ddl_parse_context *pc) override;
4112
4113 private:
4115};
4116
4119
4120 public:
4122 : super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
4123};
4124
4127
4128 friend class PT_alter_table_standalone_stmt; // to access make_cmd()
4129
4130 protected:
4132 : super(alter_info_flag) {}
4133
4134 private:
4136};
4137
4138/**
4139 Node for the @SQL{ALTER TABLE ADD PARTITION} statement
4140
4141 @ingroup ptn_alter_table
4142*/
4145
4146 public:
4147 explicit PT_alter_table_add_partition(bool no_write_to_binlog)
4148 : super(Alter_info::ALTER_ADD_PARTITION),
4149 m_no_write_to_binlog(no_write_to_binlog) {}
4150
4151 bool contextualize(Table_ddl_parse_context *pc) override;
4152
4154 return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
4155 }
4156
4157 protected:
4159
4160 private:
4162};
4163
4164/**
4165 Node for the @SQL{ALTER TABLE ADD PARTITION (@<partition list@>)} statement
4166
4167 @ingroup ptn_alter_table
4168*/
4172
4173 public:
4175 bool no_write_to_binlog,
4177 : super(no_write_to_binlog), m_def_list(def_list) {}
4178
4179 bool contextualize(Table_ddl_parse_context *pc) override;
4180
4181 private:
4183};
4184
4185/**
4186 Node for the @SQL{ALTER TABLE ADD PARTITION PARTITIONS (@<n>@)} statement
4187
4188 @ingroup ptn_alter_table
4189*/