MySQL 9.3.0
Source Code Documentation
sql_lex.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @defgroup GROUP_PARSER Parser
26 @{
27*/
28
29#ifndef SQL_LEX_INCLUDED
30#define SQL_LEX_INCLUDED
31
32#include <string.h>
33#include <sys/types.h> // TODO: replace with cstdint
34
35#include <algorithm>
36#include <cstdint>
37#include <cstring>
38#include <functional>
39#include <map>
40#include <memory>
41#include <new>
42#include <string>
43#include <utility>
44
45#include "lex_string.h"
46#include "map_helpers.h"
47#include "mem_root_deque.h"
48#include "memory_debugging.h"
49#include "my_alloc.h" // Destroy_only
50#include "my_base.h"
51#include "my_compiler.h"
52#include "my_dbug.h"
53#include "my_inttypes.h" // TODO: replace with cstdint
54#include "my_sqlcommand.h"
55#include "my_sys.h"
56#include "my_table_map.h"
57#include "my_thread_local.h"
59#include "mysql/service_mysql_alloc.h" // my_free
61#include "mysql_com.h"
62#include "mysqld_error.h"
63#include "prealloced_array.h" // Prealloced_array
64#include "sql/dd/info_schema/table_stats.h" // dd::info_schema::Table_stati...
65#include "sql/dd/info_schema/tablespace_stats.h" // dd::info_schema::Tablesp...
66#include "sql/enum_query_type.h"
67#include "sql/handler.h"
68#include "sql/item.h" // Name_resolution_context
69#include "sql/item_subselect.h" // Subquery_strategy
73#include "sql/key_spec.h" // KEY_CREATE_INFO
74#include "sql/mdl.h"
75#include "sql/mem_root_array.h" // Mem_root_array
76#include "sql/parse_location.h"
77#include "sql/parse_tree_node_base.h" // enum_parsing_context
78#include "sql/parser_yystype.h"
79#include "sql/query_options.h" // OPTION_NO_CONST_TABLES
80#include "sql/query_term.h"
81#include "sql/set_var.h"
82#include "sql/sql_array.h"
83#include "sql/sql_connect.h" // USER_RESOURCES
84#include "sql/sql_const.h"
85#include "sql/sql_data_change.h" // enum_duplicates
86#include "sql/sql_error.h" // warn_on_deprecated_charset
87#include "sql/sql_list.h"
88#include "sql/sql_plugin_ref.h"
89#include "sql/sql_servers.h" // Server_options
90#include "sql/sql_udf.h" // Item_udftype
91#include "sql/table.h" // Table_ref
92#include "sql/thr_malloc.h"
93#include "sql/trigger_def.h" // enum_trigger_action_time_type
94#include "sql/visible_fields.h"
95#include "sql_string.h"
96#include "string_with_len.h"
97#include "strings/sql_chars.h"
98#include "thr_lock.h" // thr_lock_type
99#include "violite.h" // SSL_type
100
101class Alter_info;
102class Event_parse_data;
103class Field;
104class Item_cond;
106class Item_func_match;
110class Item_sum;
111class JOIN;
112class Opt_hints_global;
113class Opt_hints_qb;
114class PT_subquery;
115class PT_with_clause;
116class Parse_tree_root;
117class Protocol;
118class Query_result;
121class Query_block;
122class Query_expression;
124class Sql_cmd;
125class THD;
126class Value_generator;
127class Window;
128class partition_info;
129class sp_head;
130class sp_name;
131class sp_pcontext;
132struct LEX;
133struct NESTED_JOIN;
134struct PSI_digest_locker;
135struct sql_digest_state;
136union Lexer_yystype;
138
140constexpr const int MAX_SELECT_NESTING{sizeof(nesting_map) * 8 - 1};
141
142/*
143 There are 8 different type of table access so there is no more than
144 combinations 2^8 = 256:
145
146 . STMT_READS_TRANS_TABLE
147
148 . STMT_READS_NON_TRANS_TABLE
149
150 . STMT_READS_TEMP_TRANS_TABLE
151
152 . STMT_READS_TEMP_NON_TRANS_TABLE
153
154 . STMT_WRITES_TRANS_TABLE
155
156 . STMT_WRITES_NON_TRANS_TABLE
157
158 . STMT_WRITES_TEMP_TRANS_TABLE
159
160 . STMT_WRITES_TEMP_NON_TRANS_TABLE
161
162 The unsafe conditions for each combination is represented within a byte
163 and stores the status of the option --binlog-direct-non-trans-updates,
164 whether the trx-cache is empty or not, and whether the isolation level
165 is lower than ISO_REPEATABLE_READ:
166
167 . option (OFF/ON)
168 . trx-cache (empty/not empty)
169 . isolation (>= ISO_REPEATABLE_READ / < ISO_REPEATABLE_READ)
170
171 bits 0 : . OFF, . empty, . >= ISO_REPEATABLE_READ
172 bits 1 : . OFF, . empty, . < ISO_REPEATABLE_READ
173 bits 2 : . OFF, . not empty, . >= ISO_REPEATABLE_READ
174 bits 3 : . OFF, . not empty, . < ISO_REPEATABLE_READ
175 bits 4 : . ON, . empty, . >= ISO_REPEATABLE_READ
176 bits 5 : . ON, . empty, . < ISO_REPEATABLE_READ
177 bits 6 : . ON, . not empty, . >= ISO_REPEATABLE_READ
178 bits 7 : . ON, . not empty, . < ISO_REPEATABLE_READ
179*/
180extern uint binlog_unsafe_map[256];
181/*
182 Initializes the array with unsafe combinations and its respective
183 conditions.
184*/
186
187/*
188 If we encounter a diagnostics statement (GET DIAGNOSTICS, or e.g.
189 the old SHOW WARNINGS|ERRORS, or "diagnostics variables" such as
190 @@warning_count | @@error_count, we'll set some hints so this
191 information is not lost. DA_KEEP_UNSPECIFIED is used in LEX constructor to
192 avoid leaving variables uninitialized.
193 */
195 DA_KEEP_NOTHING = 0, /**< keep nothing */
196 DA_KEEP_DIAGNOSTICS, /**< keep the diagnostics area */
197 DA_KEEP_COUNTS, /**< keep \@warning_count / \@error_count */
198 DA_KEEP_PARSE_ERROR, /**< keep diagnostics area after parse error */
199 DA_KEEP_UNSPECIFIED /**< keep semantics is unspecified */
201
207
215
216/**
217 enum_sp_type defines type codes of stored programs.
218
219 @note these codes are used when dealing with the mysql.routines system table,
220 so they must not be changed.
221
222 @note the following macros were used previously for the same purpose. Now they
223 are used for ACL only.
224*/
225enum class enum_sp_type {
226 FUNCTION = 1,
227 PROCEDURE,
228 TRIGGER,
229 EVENT,
230 LIBRARY,
231 /*
232 Must always be the last one.
233 Denotes an error condition.
234 */
236};
237
239 if (val >= static_cast<longlong>(enum_sp_type::FUNCTION) &&
240 val < static_cast<longlong>(enum_sp_type::INVALID_SP_TYPE))
241 return static_cast<enum_sp_type>(val);
242 else
244}
245
247 return static_cast<longlong>(val);
248}
249
250inline uint to_uint(enum_sp_type val) { return static_cast<uint>(val); }
251
252/*
253 Values for the type enum. This reflects the order of the enum declaration
254 in the CREATE TABLE command. These values are used to enumerate object types
255 for the ACL statements.
256
257 These values were also used for enumerating stored program types. However, now
258 enum_sp_type should be used for that instead of them.
259*/
260#define TYPE_ENUM_FUNCTION 1
261#define TYPE_ENUM_PROCEDURE 2
262#define TYPE_ENUM_TRIGGER 3
263#define TYPE_ENUM_PROXY 4
264#define TYPE_ENUM_LIBRARY 5
265#define TYPE_ENUM_INVALID 6
266
267enum class Acl_type {
268 TABLE = 0,
273};
274
275Acl_type lex_type_to_acl_type(ulong lex_type);
276
278
280
282 {STRING_WITH_LEN("")},
283 {STRING_WITH_LEN("CONTAINS SQL")},
284 {STRING_WITH_LEN("NO SQL")},
285 {STRING_WITH_LEN("READS SQL DATA")},
286 {STRING_WITH_LEN("MODIFIES SQL DATA")}};
287
289 VIEW_CREATE_NEW, // check that there are not such VIEW/table
290 VIEW_ALTER, // check that VIEW with such name exists
291 VIEW_CREATE_OR_REPLACE // check only that there are not such table
292};
293
295 ALTER_USER_COMMENT_NOT_USED, // No user metadata ALTER in the AST
296 ALTER_USER_COMMENT, // A text comment is expected
297 ALTER_USER_ATTRIBUTE // A JSON object is expected
298};
299
300/* Options to add_table_to_list() */
301#define TL_OPTION_UPDATING 0x01
302#define TL_OPTION_IGNORE_LEAVES 0x02
303#define TL_OPTION_ALIAS 0x04
304
305/* Structure for db & table in sql_yacc */
306class Table_function;
307
309 public:
314
315 Table_ident(Protocol *protocol, const LEX_CSTRING &db_arg,
316 const LEX_CSTRING &table_arg, bool force);
317 Table_ident(const LEX_CSTRING &db_arg, const LEX_CSTRING &table_arg)
318 : db(db_arg), table(table_arg), sel(nullptr), table_function(nullptr) {}
319 Table_ident(const LEX_CSTRING &table_arg)
320 : table(table_arg), sel(nullptr), table_function(nullptr) {
321 db = NULL_CSTR;
322 }
323 /**
324 This constructor is used only for the case when we create a derived
325 table. A derived table has no name and doesn't belong to any database.
326 Later, if there was an alias specified for the table, it will be set
327 by add_table_to_list.
328 */
330 db = EMPTY_CSTR; /* a subject to casedn_str */
332 }
333 /*
334 This constructor is used only for the case when we create a table function.
335 It has no name and doesn't belong to any database as it exists only
336 during query execution. Later, if there was an alias specified for the
337 table, it will be set by add_table_to_list.
338 */
339 Table_ident(LEX_CSTRING &table_arg, Table_function *table_func_arg)
340 : table(table_arg), sel(nullptr), table_function(table_func_arg) {
341 /* We must have a table name here as this is used with add_table_to_list */
342 db = EMPTY_CSTR; /* a subject to casedn_str */
343 }
344 // True if we can tell from syntax that this is a table function.
345 bool is_table_function() const { return (table_function != nullptr); }
346 // True if we can tell from syntax that this is an unnamed derived table.
347 bool is_derived_table() const { return sel; }
348 void change_db(const char *db_name) {
349 db.str = db_name;
350 db.length = strlen(db_name);
351 }
352};
353
356
357/**
358 Structure to hold parameters for CHANGE REPLICATION SOURCE, START REPLICA, and
359 STOP REPLICA.
360
361 Remark: this should not be confused with Master_info (and perhaps
362 would better be renamed to st_lex_replication_info). Some fields,
363 e.g., delay, are saved in Relay_log_info, not in Master_info.
364*/
366 /*
367 The array of IGNORE_SERVER_IDS has a preallocation, and is not expected
368 to grow to any significant size, so no instrumentation.
369 */
371 initialize();
372 }
379 char *gtid;
380 char *view_id;
381 const char *channel; // identifier similar to database name
382 enum {
389
390 /*
391 Enum is used for making it possible to detect if the user
392 changed variable or if it should be left at old value
393 */
394 enum {
404 /*
405 Ciphersuites used for TLS 1.3 communication with the master server.
406 */
411 };
420 /**
421 Flag that is set to `true` whenever `PRIVILEGE_CHECKS_USER` is set to `NULL`
422 as a part of a `CHANGE REPLICATION SOURCE TO` statement.
423 */
425 /**
426 Username and hostname parts of the `PRIVILEGE_CHECKS_USER`, when it's set to
427 a user.
428 */
430 /**
431 Flag indicating if row format should be enforced for this channel event
432 stream.
433 */
435
436 /**
437 Identifies what is the slave policy on primary keys in tables.
438 If set to STREAM it just replicates the value of sql_require_primary_key.
439 If set to ON it fails when the source tries to replicate a table creation
440 or alter operation that does not have a primary key.
441 If set to OFF it does not enforce any policies on the channel for primary
442 keys.
443 */
444 enum {
451
452 enum {
458
460
461 /// Initializes everything to zero/NULL/empty.
462 void initialize();
463 /// Sets all fields to their "unspecified" value.
464 void set_unspecified();
465
466 private:
467 // Not copyable or assignable.
470};
471
473 bool all;
474};
475
481
482/*
483 String names used to print a statement with index hints.
484 Keep in sync with index_hint_type.
485*/
486extern const char *index_hint_type_name[];
488
489/*
490 Bits in index_clause_map : one for each possible FOR clause in
491 USE/FORCE/IGNORE INDEX index hint specification
492*/
493#define INDEX_HINT_MASK_JOIN (1)
494#define INDEX_HINT_MASK_GROUP (1 << 1)
495#define INDEX_HINT_MASK_ORDER (1 << 2)
496
497#define INDEX_HINT_MASK_ALL \
498 (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | INDEX_HINT_MASK_ORDER)
499
500/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
502 public:
503 /* The type of the hint : USE/FORCE/IGNORE */
505 /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
507 /*
508 The index name. Empty (str=NULL) name represents an empty list
509 USE INDEX () clause
510 */
512
513 Index_hint(const char *str, uint length) {
514 key_name.str = str;
516 }
517
518 void print(const THD *thd, String *str);
519};
520
521/*
522 Class Query_expression represents a query expression.
523 Class Query_block represents a query block.
524
525 In addition to what is explained below, the query block(s) of a query
526 expression is contained in a tree expressing the nesting of set operations,
527 cf. query_term.h
528
529 A query expression contains one or more query blocks (more than one means
530 that the query expression contains one or more set operations - UNION,
531 INTERSECT or EXCEPT - unless the query blocks are used to describe
532 subqueries). These classes are connected as follows: both classes have a
533 master, a slave, a next and a prev field. For class Query_block, master and
534 slave connect to objects of type Query_expression, whereas for class
535 Query_expression, they connect to Query_block. master is pointer to outer
536 node. slave is pointer to the first inner node.
537
538 neighbors are two Query_block or Query_expression objects on
539 the same level.
540
541 The structures are linked with the following pointers:
542 - list of neighbors (next/prev) (prev of first element point to slave
543 pointer of outer structure)
544 - For Query_block, this is a list of query blocks.
545 - For Query_expression, this is a list of subqueries.
546
547 - pointer to outer node (master), which is
548 If this is Query_expression
549 - pointer to outer query_block.
550 If this is Query_block
551 - pointer to outer Query_expression.
552
553 - pointer to inner objects (slave), which is either:
554 If this is an Query_expression:
555 - first query block that belong to this query expression.
556 If this is an Query_block
557 - first query expression that belong to this query block (subqueries).
558
559 - list of all Query_block objects (link_next/link_prev)
560 This is to be used for things like derived tables creation, where we
561 go through this list and create the derived tables.
562
563 In addition to the above mentioned link, the query's tree structure is
564 represented by the member m_query_term, see query_term.h
565 For example for following query:
566
567 select *
568 from table1
569 where table1.field IN (select * from table1_1_1 union
570 select * from table1_1_2)
571 union
572 select *
573 from table2
574 where table2.field=(select (select f1 from table2_1_1_1_1
575 where table2_1_1_1_1.f2=table2_1_1.f3)
576 from table2_1_1
577 where table2_1_1.f1=table2.f2)
578 union
579 select * from table3;
580
581 we will have following structure:
582
583 select1: (select * from table1 ...)
584 select2: (select * from table2 ...)
585 select3: (select * from table3)
586 select1.1.1: (select * from table1_1_1)
587 ...
588
589 main unit
590 select1 select2 select3
591 |^^ |^
592 s||| ||master
593 l||| |+---------------------------------+
594 a||| +---------------------------------+|
595 v|||master slave ||
596 e||+-------------------------+ ||
597 V| neighbor | V|
598 unit1.1<+==================>unit1.2 unit2.1
599 select1.1.1 select 1.1.2 select1.2.1 select2.1.1
600 |^
601 ||
602 V|
603 unit2.1.1.1
604 select2.1.1.1.1
605
606
607 relation in main unit will be following:
608 (bigger picture for:
609 main unit
610 select1 select2 select3
611 in the above picture)
612
613 main unit
614 |^^^
615 ||||
616 ||||
617 |||+------------------------------+
618 ||+--------------+ |
619 slave||master | |
620 V| neighbor | neighbor |
621 select1<========>select2<========>select3
622
623 list of all query_block will be following (as it will be constructed by
624 parser):
625
626 select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
627 |
628 +---------------------------------------------------------------------+
629 |
630 +->select1.1.1->select1.1.2
631
632*/
633
634/**
635 This class represents a query expression (one query block or
636 several query blocks combined with UNION).
637*/
639 /**
640 Intrusive double-linked list of all query expressions
641 immediately contained within the same query block.
642 */
645
646 /**
647 The query block wherein this query expression is contained,
648 NULL if the query block is the outer-most one.
649 */
651 /// The first query block in this query expression.
653
654 // The query set operation structure, see doc for Query_term.
656
657 public:
658 /// Getter for m_query_term, q.v.
659 Query_term *query_term() const { return m_query_term; }
660 /// Setter for m_query_term, q.v.
662 /// Convenience method to avoid down casting, i.e. interpret m_query_term
663 /// as a Query_term_set_op.
664 /// @retval a non-null node iff !is_simple
665 /// @retval nullptr if is_simple() holds.
667 return is_simple() ? nullptr : down_cast<Query_term_set_op *>(m_query_term);
668 }
669 /// Return the query block iff !is_simple() holds
671 if (is_simple())
672 return nullptr;
673 else
674 return m_query_term->query_block();
675 }
676 bool is_leaf_block(Query_block *qb);
678 for (auto qt : query_terms<>()) {
679 if (qt->query_block() == qb) return qt;
680 }
681 return nullptr;
682 }
683
684 /**
685 Return iterator object over query terms rooted in m_query_term,
686 using either post order visiting (default) or pre order,
687 optionally skipping leaf nodes (query blocks corresponding to SELECTs or
688 table constructors). By default, we visit all nodes.
689 Usage: for (auto qt : query_terms<..>() { ... }
690 E.g.
691 for (auto qt : query_terms<>()) { } Visit all nodes, post order
692 for (auto qt : query_terms<QTC_PRE_ORDER, false>()) { }
693 Skip leaves, pre order
694 @tparam order == QTC_POST_ORDER if post order traversal is desired;default
695 == QTC_PRE_ORDER pre-order traversal
696 @tparam visit_leaves == VL_VISIT_LEAVES: if we want the traversal to include
697 leaf nodes i.e. the SELECTs or table constructors
698 == VL_SKIP_LEAVES: leaves will be skipped
699 @returns iterator object
700 */
701 template <Visit_order order = QTC_POST_ORDER,
702 Visit_leaves visit_leaves = VL_VISIT_LEAVES>
705 }
706
707 /**
708 Return the Query_block of the last query term in a n-ary set
709 operation that is the right side of the last DISTINCT set operation in that
710 n_ary set operation:
711 E.e. for
712 A UNION B UNION ALL C,
713 B's block will be returned. If no DISTINCT is present or not a set
714 operation, return nullptr.
715
716 @returns query block of last distinct right operand
717 */
719 auto const setop = down_cast<Query_term_set_op *>(m_query_term);
720 if (setop->last_distinct() > 0)
721 return setop->child(setop->last_distinct())->query_block();
722 else
723 return nullptr;
724 }
725
727 if (is_simple()) return false;
728 return down_cast<Query_term_set_op *>(m_query_term)->last_distinct() > 0;
729 }
730
731 private:
732 /**
733 Marker for subqueries in WHERE, HAVING, ORDER BY, GROUP BY and
734 SELECT item lists.
735 Must be read/written when holding LOCK_query_plan.
736
737 See Item_subselect::explain_subquery_checker
738 */
740
741 bool prepared; ///< All query blocks in query expression are prepared
742 bool optimized; ///< All query blocks in query expression are optimized
743 bool executed; ///< Query expression has been executed
744 ///< Explain mode: query expression refers stored function
746
747 /// Object to which the result for this query expression is sent.
748 /// Not used if we materialize directly into a parent query expression's
749 /// result table (see optimize()).
751
752 /**
753 An iterator you can read from to get all records for this query.
754
755 May be nullptr even after create_access_paths(), or in the case of an
756 unfinished materialization (see optimize()).
757 */
760
761 /**
762 If there is an unfinished materialization (see optimize()),
763 contains one element for each operand (query block) in this query
764 expression.
765 */
767
768 private:
769 /**
770 Convert the executor structures to a set of access paths, storing the result
771 in m_root_access_path.
772 */
773 void create_access_paths(THD *thd);
774
775 public:
776 /**
777 result of this query can't be cached, bit field, can be :
778 UNCACHEABLE_DEPENDENT
779 UNCACHEABLE_RAND
780 UNCACHEABLE_SIDEEFFECT
781 */
783
784 explicit Query_expression(enum_parsing_context parsing_context);
785
786 /// @return true for a query expression without UNION/INTERSECT/EXCEPT or
787 /// multi-level ORDER, i.e. we have a "simple table".
788 bool is_simple() const { return m_query_term->term_type() == QT_QUERY_BLOCK; }
789
791
792 /// Values for Query_expression::cleaned
794 UC_DIRTY, ///< Unit isn't cleaned
795 UC_PART_CLEAN, ///< Unit were cleaned, except JOIN and JOIN_TABs were
796 ///< kept for possible EXPLAIN
797 UC_CLEAN ///< Unit completely cleaned, all underlying JOINs were
798 ///< freed
799 };
800 enum_clean_state cleaned; ///< cleanliness state
801
802 public:
803 /**
804 Return the query block holding the top level ORDER BY, LIMIT and OFFSET.
805
806 If the query is not a set operation (UNION, INTERSECT or EXCEPT, and the
807 query expression has no multi-level ORDER BY/LIMIT, this represents the
808 single query block of the query itself, cf. documentation for class
809 Query_term.
810
811 @return query block containing the global parameters
812 */
814 return query_term()->query_block();
815 }
816
817 /* LIMIT clause runtime counters */
819
820 /* For IN/EXISTS predicates, we may not push down LIMIT 1 safely if true*/
822
823 /// Points to subquery if this query expression is used in one, otherwise NULL
825 /**
826 The WITH clause which is the first part of this query expression. NULL if
827 none.
828 */
830 /**
831 If this query expression is underlying of a derived table, the derived
832 table. NULL if none.
833 */
835 /**
836 First query block (in this UNION) which references the CTE.
837 NULL if not the query expression of a recursive CTE.
838 */
840
841 /**
842 If 'this' is body of lateral derived table:
843 map of tables in the same FROM clause as this derived table, and to which
844 the derived table's body makes references.
845 In pre-resolution stages, this is OUTER_REF_TABLE_BIT, just to indicate
846 that this has LATERAL; after resolution, which has found references in the
847 body, this is the proper map (with no PSEUDO_TABLE_BITS anymore).
848 */
850
851 /**
852 This query expression represents a scalar subquery and we need a run-time
853 check that the cardinality doesn't exceed 1.
854 */
856
857 /// @return true if query expression can be merged into an outer query
858 bool is_mergeable() const;
859
860 /// @return true if query expression is recommended to be merged
861 bool merge_heuristic(const LEX *lex) const;
862
863 /// @return the query block this query expression belongs to as subquery
865
866 /// @return the first query block inside this query expression
868
869 /// @return the next query expression within same query block (next subquery)
871
872 /// @return the query result object in use for this query expression
874
875 RowIterator *root_iterator() const { return m_root_iterator.get(); }
877 return std::move(m_root_iterator);
878 }
880
881 // Asks each query block to switch to an access path with in2exists
882 // conditions removed (if they were ever added).
883 // See JOIN::change_to_access_path_without_in2exists().
885
887 m_root_access_path = nullptr;
888 m_root_iterator.reset();
889 }
890
891 /**
892 Ensures that there are iterators created for the access paths created
893 by optimize(), even if it is not a top-level Query_expression.
894 If there are already iterators, it is a no-op. optimize() must have
895 been called earlier.
896
897 The use case for this is if we have a query block that's not top-level,
898 but we figure out after the fact that we wanted to run it anyway.
899 The typical case would be that we notice that the query block can return
900 at most one row (a so-called const table), and want to run it during
901 optimization.
902 */
903 bool force_create_iterators(THD *thd);
904
905 /**
906 Creates iterators for the access paths created by optimize(). Usually called
907 on a top-level Query_expression, but can also be called on non-top level
908 expressions from force_create_iterators(). See force_create_iterators() for
909 details.
910 */
911 bool create_iterators(THD *thd);
912
913 /// See optimize().
914 bool unfinished_materialization() const { return !m_operands.empty(); }
915
916 /// See optimize().
919 return std::move(m_operands);
920 }
921
922 /// Set new query result object for this query expression
924
925 /**
926 Whether there is a chance that optimize() is capable of materializing
927 directly into a result table if given one. Note that even if this function
928 returns true, optimize() can choose later not to do so, since it depends
929 on information (in particular, whether the query blocks can run under
930 the iterator executor or not) that is not available before optimize time.
931
932 TODO(sgunders): Now that all query blocks can run under the iterator
933 executor, the above may no longer be true. This needs investigation.
934 */
936
937 bool prepare(THD *thd, Query_result *result,
938 mem_root_deque<Item *> *insert_field_list,
939 ulonglong added_options, ulonglong removed_options);
940
941 /**
942 If and only if materialize_destination is non-nullptr, it means that the
943 caller intends to materialize our result into the given table. If it is
944 advantageous (in particular, if this query expression is a UNION DISTINCT),
945 optimize() will not create an iterator by itself, but rather do an
946 unfinished materialize. This means that it will collect iterators for
947 all the query blocks and prepare them for materializing into the given
948 table, but not actually create a root iterator for this query expression;
949 the caller is responsible for calling release_query_blocks_to_materialize()
950 and creating the iterator itself.
951
952 Even if materialize_destination is non-nullptr, this function may choose
953 to make a regular iterator. The caller is responsible for checking
954 unfinished_materialization() if it has given a non-nullptr table.
955
956 @param thd Thread handle.
957
958 @param materialize_destination What table to try to materialize into,
959 or nullptr if the caller does not intend to materialize the result.
960
961 @param finalize_access_paths Relevant for the hypergraph optimizer only.
962 If false, the given access paths will _not_ be finalized, so you cannot
963 create iterators from it before finalize() is called (see
964 FinalizePlanForQueryBlock()), and create_iterators must also be false.
965 This is relevant only if you are potentially optimizing multiple times
966 (see change_to_access_path_without_in2exists()), since you are only
967 allowed to finalize a query block once. "Fake" query blocks (see
968 query_term.h) are always finalized.
969 */
970 bool optimize(THD *thd, TABLE *materialize_destination,
971 bool finalize_access_paths);
972
973 /**
974 For any non-finalized query block, finalize it so that we are allowed to
975 create iterators. Must be called after the final access path is chosen
976 (ie., after any calls to change_to_access_path_without_in2exists()).
977 */
978 bool finalize(THD *thd);
979
980#ifndef NDEBUG
981 void DebugPrintQueryPlan(THD *thd, const char *keyword) const;
982#endif
983 /**
984 Do everything that would be needed before running Init() on the root
985 iterator. In particular, clear out data from previous execution iterations,
986 if needed.
987 */
988 bool ClearForExecution();
989
990 bool ExecuteIteratorQuery(THD *thd);
991 bool execute(THD *thd);
992 bool explain(THD *explain_thd, const THD *query_thd);
993 bool explain_query_term(THD *explain_thd, const THD *query_thd,
994 Query_term *qt);
995 void cleanup(bool full);
996 /**
997 Destroy contained objects, in particular temporary tables which may
998 have their own mem_roots.
999 */
1000 void destroy();
1001
1002 void print(const THD *thd, String *str, enum_query_type query_type);
1003 bool accept(Select_lex_visitor *visitor);
1004
1005 /**
1006 Create a block to be used for ORDERING and LIMIT/OFFSET processing of a
1007 query term, which isn't itself a query specification or table value
1008 constructor. Such blocks are not included in the list starting in
1009 Query_Expression::first_query_block, and Query_block::next_query_block().
1010 They blocks are accessed via Query_term::query_block().
1011
1012 @param term the term on behalf of which we are making a post processing
1013 block
1014 @returns a query block
1015 */
1017
1019 assert(!is_prepared());
1020 prepared = true;
1021 }
1023 assert(is_prepared() && !is_optimized());
1024 optimized = true;
1025 }
1027 // assert(is_prepared() && is_optimized() && !is_executed());
1028 assert(is_prepared() && is_optimized());
1029 executed = true;
1030 }
1031 /// Reset this query expression for repeated evaluation within same execution
1033 assert(is_prepared() && is_optimized());
1034 executed = false;
1035 }
1036 /// Clear execution state, needed before new execution of prepared statement
1038 // Cannot be enforced when called from Prepared_statement::execute():
1039 // assert(is_prepared());
1040 optimized = false;
1041 executed = false;
1042 cleaned = UC_DIRTY;
1043 }
1044 /// Check state of preparation of the contained query expression.
1045 bool is_prepared() const { return prepared; }
1046 /// Check state of optimization of the contained query expression.
1047 bool is_optimized() const { return optimized; }
1048 /**
1049 Check state of execution of the contained query expression.
1050 Should not be used to check the state of a complete statement, use
1051 LEX::is_exec_completed() instead.
1052 */
1053 bool is_executed() const { return executed; }
1055 Query_result_interceptor *old_result);
1056 bool set_limit(THD *thd, Query_block *provider);
1057 bool has_any_limit() const;
1058
1059 inline bool is_union() const;
1060 inline bool is_set_operation() const;
1061
1062 /// Include a query expression below a query block.
1063 void include_down(LEX *lex, Query_block *outer);
1064
1065 /// Exclude this unit and immediately contained query_block objects
1066 void exclude_level();
1067
1068 /// Exclude subtree of current unit from tree of SELECTs
1069 void exclude_tree();
1070
1071 /// Renumber query blocks of a query expression according to supplied LEX
1072 void renumber_selects(LEX *lex);
1073
1075 bool save_cmd_properties(THD *thd);
1076
1077 friend class Query_block;
1078
1081 size_t num_visible_fields() const;
1082
1083 // If we are doing a query with global LIMIT, we need somewhere to store the
1084 // record count for FOUND_ROWS(). It can't be in any of the JOINs, since
1085 // they may have their own LimitOffsetIterators, which will write to
1086 // join->send_records whenever there is an OFFSET. Thus, we'll keep it here
1087 // instead.
1089
1092 void set_explain_marker_from(THD *thd, const Query_expression *u);
1093
1094#ifndef NDEBUG
1095 /**
1096 Asserts that none of {this unit and its children units} is fully cleaned
1097 up.
1098 */
1100#else
1101 void assert_not_fully_clean() {}
1102#endif
1103 void invalidate();
1104
1105 bool is_recursive() const { return first_recursive != nullptr; }
1106
1108
1110
1111 void fix_after_pullout(Query_block *parent_query_block,
1112 Query_block *removed_query_block);
1113
1114 /**
1115 If unit is a subquery, which forms an object of the upper level (an
1116 Item_subselect, a derived Table_ref), adds to this object a map
1117 of tables of the upper level which the unit references.
1118 */
1120
1121 /**
1122 If unit is a subquery, which forms an object of the upper level (an
1123 Item_subselect, a derived Table_ref), returns the place of this object
1124 in the upper level query block.
1125 */
1127
1128 bool walk(Item_processor processor, enum_walk walk, uchar *arg);
1129
1130 /**
1131 Replace all targeted items using transformer provided and info in
1132 arg.
1133 */
1134 bool replace_items(Item_transformer t, uchar *arg);
1135
1136 /*
1137 An exception: this is the only function that needs to adjust
1138 explain_marker.
1139 */
1140 friend bool parse_view_definition(THD *thd, Table_ref *view_ref);
1141};
1142
1145
1146/**
1147 Query_block type enum
1148*/
1150 EXPLAIN_NONE = 0,
1163 // Total:
1164 EXPLAIN_total ///< fake type, total number of all valid types
1165
1166 // Don't insert new types below this line!
1167};
1168
1169/**
1170 This class represents a query block, aka a query specification, which is
1171 a query consisting of a SELECT keyword, followed by a table list,
1172 optionally followed by a WHERE clause, a GROUP BY, etc.
1173*/
1174class Query_block : public Query_term {
1175 public:
1176 /**
1177 @note the group_by and order_by lists below will probably be added to the
1178 constructor when the parser is converted into a true bottom-up design.
1179
1180 //SQL_I_LIST<ORDER> *group_by, SQL_I_LIST<ORDER> order_by
1181 */
1183
1184 /// Query_term methods overridden
1185 void debugPrint(int level, std::ostringstream &buf) const override;
1186 /// Minion of debugPrint
1187 void qbPrint(int level, std::ostringstream &buf) const;
1189 Change_current_query_block *save_query_block,
1190 mem_root_deque<Item *> *insert_field_list,
1191 Query_result *common_result, ulonglong added_options,
1192 ulonglong removed_options,
1193 ulonglong create_option) override;
1195 // leaf block optimization done elsewhere
1196 return false;
1197 }
1198
1201 Mem_root_array<AppendPathParameters> *union_all_subpaths,
1202 bool calc_found_rows) override;
1203
1205 Query_term_type term_type() const override { return QT_QUERY_BLOCK; }
1206 const char *operator_string() const override { return "query_block"; }
1207 Query_block *query_block() const override {
1208 return const_cast<Query_block *>(this);
1209 }
1210 void label_children() override {}
1211 void destroy_tree() override { m_parent = nullptr; }
1212
1213 bool open_result_tables(THD *, int) override;
1214 /// end of overridden methods from Query_term
1215 bool absorb_limit_of(Query_block *block);
1216
1217 Item *where_cond() const { return m_where_cond; }
1219 void set_where_cond(Item *cond) { m_where_cond = cond; }
1220 Item *having_cond() const { return m_having_cond; }
1222 void set_having_cond(Item *cond) { m_having_cond = cond; }
1223 Item *qualify_cond() const { return m_qualify_cond; }
1225 void set_qualify_cond(Item *cond) { m_qualify_cond = cond; }
1228 bool change_query_result(THD *thd, Query_result_interceptor *new_result,
1229 Query_result_interceptor *old_result);
1230
1231 /// Set base options for a query block (and active options too)
1232 void set_base_options(ulonglong options_arg) {
1233 DBUG_EXECUTE_IF("no_const_tables", options_arg |= OPTION_NO_CONST_TABLES;);
1234
1235 // Make sure we do not overwrite options by accident
1236 assert(m_base_options == 0 && m_active_options == 0);
1237 m_base_options = options_arg;
1238 m_active_options = options_arg;
1239 }
1240
1241 /// Add base options to a query block, also update active options
1243 assert(first_execution);
1246 }
1247
1248 /**
1249 Remove base options from a query block.
1250 Active options are also updated, and we assume here that "extra" options
1251 cannot override removed base options.
1252 */
1254 assert(first_execution);
1257 }
1258
1259 /// Make active options from base options, supplied options and environment:
1260 void make_active_options(ulonglong added_options, ulonglong removed_options);
1261
1262 /// Adjust the active option set
1264
1265 /// @return the active query options
1267
1268 /**
1269 Set associated tables as read_only, ie. they cannot be inserted into,
1270 updated or deleted from during this statement.
1271 Commonly used for query blocks that are part of derived tables or
1272 views that are materialized.
1273 */
1275 // Set all referenced base tables as read only.
1276 for (Table_ref *tr = leaf_tables; tr != nullptr; tr = tr->next_leaf)
1277 tr->set_readonly();
1278 }
1279
1280 /// @returns a map of all tables references in the query block
1281 table_map all_tables_map() const { return (1ULL << leaf_table_count) - 1; }
1282
1283 bool remove_aggregates(THD *thd, Query_block *select);
1284
1288 Query_block *next_query_block() const { return next; }
1289
1291
1293
1294 void mark_as_dependent(Query_block *last, bool aggregate);
1295
1296 /// @returns true if query block references any tables
1297 bool has_tables() const { return m_table_list.elements != 0; }
1298
1299 /// @return true if query block is explicitly grouped (non-empty GROUP BY)
1300 bool is_explicitly_grouped() const { return group_list.elements != 0; }
1301
1302 /**
1303 @return true if this query block is implicitly grouped, ie it is not
1304 explicitly grouped but contains references to set functions.
1305 The query will return max. 1 row (@see also is_single_grouped()).
1306 */
1308 return m_agg_func_used && group_list.elements == 0;
1309 }
1310
1311 /**
1312 @return true if this query block has GROUP BY modifier.
1313 */
1315 return (olap != UNSPECIFIED_OLAP_TYPE);
1316 }
1317
1318 /**
1319 @return true if this query block is explicitly or implicitly grouped.
1320 @note a query with DISTINCT is not considered to be aggregated.
1321 @note in standard SQL, a query with HAVING is defined as grouped, however
1322 MySQL allows HAVING without any aggregation to be the same as WHERE.
1323 */
1324 bool is_grouped() const { return group_list.elements > 0 || m_agg_func_used; }
1325
1326 /// @return true if this query block contains DISTINCT at start of select list
1327 bool is_distinct() const { return active_options() & SELECT_DISTINCT; }
1328
1329 /**
1330 @return true if this query block contains an ORDER BY clause.
1331
1332 @note returns false if ORDER BY has been eliminated, e.g if the query
1333 can return max. 1 row.
1334 */
1335 bool is_ordered() const { return order_list.elements > 0; }
1336
1337 /**
1338 Based on the structure of the query at resolution time, it is possible to
1339 conclude that DISTINCT is useless and remove it.
1340 This is the case if:
1341 - all GROUP BY expressions are in SELECT list, so resulting group rows are
1342 distinct,
1343 - and ROLLUP is not specified, so it adds no row for NULLs.
1344
1345 @returns true if we can remove DISTINCT.
1346
1347 @todo could refine this to if ROLLUP were specified and all GROUP
1348 expressions were non-nullable, because ROLLUP then adds only NULL values.
1349 Currently, ROLLUP+DISTINCT is rejected because executor cannot handle
1350 it in all cases.
1351 */
1352 bool can_skip_distinct() const {
1353 return is_grouped() && hidden_group_field_count == 0 &&
1355 }
1356
1357 /// @return true if this query block has a LIMIT clause
1358 bool has_limit() const { return select_limit != nullptr; }
1359
1360 /// @return true if query block references full-text functions
1361 bool has_ft_funcs() const { return ftfunc_list->elements > 0; }
1362
1363 /// @returns true if query block is a recursive member of a recursive unit
1364 bool is_recursive() const { return recursive_reference != nullptr; }
1365
1366 /**
1367 Finds a group expression matching the given item, or nullptr if
1368 none. When there are multiple candidates, ones that match in name are
1369 given priority (such that “a AS c GROUP BY a,b,c” resolves to c, not a);
1370 if there is still a tie, the leftmost is given priority.
1371
1372 @param item The item to search for.
1373 @param [out] rollup_level If not nullptr, will be set to the group
1374 expression's index (0-based).
1375 */
1376 ORDER *find_in_group_list(Item *item, int *rollup_level) const;
1377 int group_list_size() const;
1378
1379 /// @returns true if query block contains windows
1380 bool has_windows() const { return m_windows.elements > 0; }
1381
1382 /// @returns true if query block contains window functions
1383 bool has_wfs();
1384
1385 void invalidate();
1386
1387 uint get_in_sum_expr() const { return in_sum_expr; }
1388
1389 bool add_item_to_list(Item *item);
1390 bool add_grouping_expr(THD *thd, Item *item);
1392 Table_ref *add_table_to_list(THD *thd, Table_ident *table, const char *alias,
1393 ulong table_options,
1395 enum_mdl_type mdl_type = MDL_SHARED_READ,
1396 List<Index_hint> *hints = nullptr,
1397 List<String> *partition_names = nullptr,
1398 LEX_STRING *option = nullptr,
1399 Parse_context *pc = nullptr);
1400 /**
1401 Add item to the hidden part of select list
1402
1403 @param item item to add
1404
1405 @return Pointer to reference of the added item
1406 */
1407 Item **add_hidden_item(Item *item);
1408
1409 /// Remove hidden items from select list
1410 void remove_hidden_items();
1411
1412 Table_ref *get_table_list() const { return m_table_list.first; }
1413 bool init_nested_join(THD *thd);
1415 Table_ref *nest_last_join(THD *thd, size_t table_cnt = 2);
1418
1419 /// Wrappers over fields / \c get_fields_list() that hide items where
1420 /// item->hidden, meant for range-based for loops.
1421 /// See \c sql/visible_fields.h.
1423 auto visible_fields() const { return VisibleFields(fields); }
1424
1426 size_t visible_column_count() const override { return num_visible_fields(); }
1427
1428 /// Check privileges for views that are merged into query block
1429 bool check_view_privileges(THD *thd, Access_bitmask want_privilege_first,
1430 Access_bitmask want_privilege_next);
1431 /// Check privileges for all columns referenced from query block
1432 bool check_column_privileges(THD *thd);
1433
1434 /// Check privileges for column references in subqueries of a query block
1436
1437 /// Resolve and prepare information about tables for one query block
1438 bool setup_tables(THD *thd, Table_ref *tables, bool select_insert);
1439
1440 /// Resolve OFFSET and LIMIT clauses
1441 bool resolve_limits(THD *thd);
1442
1443 /// Resolve derived table, view, table function information for a query block
1444 bool resolve_placeholder_tables(THD *thd, bool apply_semijoin);
1445
1446 /// Propagate exclusion from table uniqueness test into subqueries
1448
1449 /// Merge name resolution context objects of a subquery into its parent
1450 void merge_contexts(Query_block *inner);
1451
1452 /// Merge derived table into query block
1453 bool merge_derived(THD *thd, Table_ref *derived_table);
1454
1455 bool flatten_subqueries(THD *thd);
1456
1457 /**
1458 Update available semijoin strategies for semijoin nests.
1459
1460 Available semijoin strategies needs to be updated on every execution since
1461 optimizer_switch setting may have changed.
1462
1463 @param thd Pointer to THD object for session.
1464 Used to access optimizer_switch
1465 */
1467
1468 /**
1469 Returns which subquery execution strategies can be used for this query
1470 block.
1471
1472 @param thd Pointer to THD object for session.
1473 Used to access optimizer_switch
1474
1475 @retval SUBQ_MATERIALIZATION Subquery Materialization should be used
1476 @retval SUBQ_EXISTS In-to-exists execution should be used
1477 @retval CANDIDATE_FOR_IN2EXISTS_OR_MAT A cost-based decision should be made
1478 */
1479 Subquery_strategy subquery_strategy(const THD *thd) const;
1480
1481 /**
1482 Returns whether semi-join is enabled for this query block
1483
1484 @see @c Opt_hints_qb::semijoin_enabled for details on how hints
1485 affect this decision. If there are no hints for this query block,
1486 optimizer_switch setting determines whether semi-join is used.
1487
1488 @param thd Pointer to THD object for session.
1489 Used to access optimizer_switch
1490
1491 @return true if semijoin is enabled,
1492 false otherwise
1493 */
1494 bool semijoin_enabled(const THD *thd) const;
1495
1497 sj_candidates = sj_cand;
1498 }
1500 sj_candidates->push_back(predicate);
1501 }
1502 bool has_sj_candidates() const {
1503 return sj_candidates != nullptr && !sj_candidates->empty();
1504 }
1505
1506 bool has_subquery_transforms() const { return sj_candidates != nullptr; }
1507
1508 /// Add full-text function elements from a list into this query block
1510
1511 void set_lock_for_table(const Lock_descriptor &descriptor, Table_ref *table);
1512
1513 void set_lock_for_tables(thr_lock_type lock_type);
1514
1515 inline void init_order() {
1516 assert(order_list.elements == 0);
1517 order_list.elements = 0;
1518 order_list.first = nullptr;
1519 order_list.next = &order_list.first;
1520 }
1521 /*
1522 This method created for reiniting LEX in mysql_admin_table() and can be
1523 used only if you are going remove all Query_block & units except belonger
1524 to LEX (LEX::unit & LEX::select, for other purposes use
1525 Query_expression::exclude_level()
1526 */
1527 void cut_subtree() { slave = nullptr; }
1528 bool test_limit();
1529 /**
1530 Get offset for LIMIT.
1531
1532 Evaluate offset item if necessary.
1533
1534 @return Number of rows to skip.
1535
1536 @todo Integrate better with Query_expression::set_limit()
1537 */
1538 ha_rows get_offset(const THD *thd) const;
1539 /**
1540 Get limit.
1541
1542 Evaluate limit item if necessary.
1543
1544 @return Limit of rows in result.
1545
1546 @todo Integrate better with Query_expression::set_limit()
1547 */
1548 ha_rows get_limit(const THD *thd) const;
1549
1550 /// Assign a default name resolution object for this query block.
1551 bool set_context(Name_resolution_context *outer_context);
1552
1553 /// Setup the array containing references to base items
1554 bool setup_base_ref_items(THD *thd);
1555 void print(const THD *thd, String *str, enum_query_type query_type);
1556
1557 /**
1558 Print detail of the Query_block object.
1559
1560 @param thd Thread handler
1561 @param query_type Options to print out string output
1562 @param[out] str String of output.
1563 */
1564 void print_query_block(const THD *thd, String *str,
1565 enum_query_type query_type);
1566
1567 /**
1568 Print detail of the UPDATE statement.
1569
1570 @param thd Thread handler
1571 @param[out] str String of output
1572 @param query_type Options to print out string output
1573 */
1574 void print_update(const THD *thd, String *str, enum_query_type query_type);
1575
1576 /**
1577 Print detail of the DELETE statement.
1578
1579 @param thd Thread handler
1580 @param[out] str String of output
1581 @param query_type Options to print out string output
1582 */
1583 void print_delete(const THD *thd, String *str, enum_query_type query_type);
1584
1585 /**
1586 Print detail of the INSERT statement.
1587
1588 @param thd Thread handler
1589 @param[out] str String of output
1590 @param query_type Options to print out string output
1591 */
1592 void print_insert(const THD *thd, String *str, enum_query_type query_type);
1593
1594 /**
1595 Print detail of Hints.
1596
1597 @param thd Thread handler
1598 @param[out] str String of output
1599 @param query_type Options to print out string output
1600 */
1601 void print_hints(const THD *thd, String *str, enum_query_type query_type);
1602
1603 /**
1604 Print error.
1605
1606 @param thd Thread handler
1607 @param[out] str String of output
1608
1609 @retval false If there is no error
1610 @retval true else
1611 */
1612 bool print_error(const THD *thd, String *str);
1613
1614 /**
1615 Print select options.
1616
1617 @param[out] str String of output
1618 */
1620
1621 /**
1622 Print UPDATE options.
1623
1624 @param[out] str String of output
1625 */
1627
1628 /**
1629 Print DELETE options.
1630
1631 @param[out] str String of output
1632 */
1634
1635 /**
1636 Print INSERT options.
1637
1638 @param[out] str String of output
1639 */
1641
1642 /**
1643 Print list of tables.
1644
1645 @param thd Thread handler
1646 @param[out] str String of output
1647 @param table_list Table_ref object
1648 @param query_type Options to print out string output
1649 */
1650 void print_table_references(const THD *thd, String *str,
1651 Table_ref *table_list,
1652 enum_query_type query_type);
1653
1654 /**
1655 Print list of items in Query_block object.
1656
1657 @param thd Thread handle
1658 @param[out] str String of output
1659 @param query_type Options to print out string output
1660 */
1661 void print_item_list(const THD *thd, String *str, enum_query_type query_type);
1662
1663 /**
1664 Print assignments list. Used in UPDATE and
1665 INSERT ... ON DUPLICATE KEY UPDATE ...
1666
1667 @param thd Thread handle
1668 @param[out] str String of output
1669 @param query_type Options to print out string output
1670 @param fields List columns to be assigned.
1671 @param values List of values.
1672 */
1673 void print_update_list(const THD *thd, String *str,
1674 enum_query_type query_type,
1676 const mem_root_deque<Item *> &values);
1677
1678 /**
1679 Print column list to be inserted into. Used in INSERT.
1680
1681 @param thd Thread handle
1682 @param[out] str String of output
1683 @param query_type Options to print out string output
1684 */
1685 void print_insert_fields(const THD *thd, String *str,
1686 enum_query_type query_type);
1687
1688 /**
1689 Print list of values, used in INSERT and for general VALUES clause.
1690
1691 @param thd Thread handle
1692 @param[out] str String of output
1693 @param query_type Options to print out string output
1694 @param values List of values
1695 @param prefix Prefix to print before each row in value list
1696 = nullptr: No prefix wanted
1697 */
1698 void print_values(const THD *thd, String *str, enum_query_type query_type,
1699 const mem_root_deque<mem_root_deque<Item *> *> &values,
1700 const char *prefix);
1701
1702 /**
1703 Print list of tables in FROM clause.
1704
1705 @param thd Thread handler
1706 @param[out] str String of output
1707 @param query_type Options to print out string output
1708 */
1709 void print_from_clause(const THD *thd, String *str,
1710 enum_query_type query_type);
1711
1712 /**
1713 Print list of conditions in WHERE clause.
1714
1715 @param thd Thread handle
1716 @param[out] str String of output
1717 @param query_type Options to print out string output
1718 */
1719 void print_where_cond(const THD *thd, String *str,
1720 enum_query_type query_type);
1721
1722 /**
1723 Print list of items in GROUP BY clause.
1724
1725 @param thd Thread handle
1726 @param[out] str String of output
1727 @param query_type Options to print out string output
1728 */
1729 void print_group_by(const THD *thd, String *str, enum_query_type query_type);
1730
1731 /**
1732 Print list of items in HAVING clause.
1733
1734 @param thd Thread handle
1735 @param[out] str String of output
1736 @param query_type Options to print out string output
1737 */
1738 void print_having(const THD *thd, String *str, enum_query_type query_type);
1739
1740 /**
1741 Print list of items in QUALIFY clause.
1742
1743 @param thd Thread handle
1744 @param[out] str String of output
1745 @param query_type Options to print out string output
1746 */
1747 void print_qualify(const THD *thd, String *str,
1748 enum_query_type query_type) const;
1749
1750 /**
1751 Print details of Windowing functions.
1752
1753 @param thd Thread handler
1754 @param[out] str String of output
1755 @param query_type Options to print out string output
1756 */
1757 void print_windows(const THD *thd, String *str, enum_query_type query_type);
1758
1759 /**
1760 Print list of items in ORDER BY clause.
1761
1762 @param thd Thread handle
1763 @param[out] str String of output
1764 @param query_type Options to print out string output
1765 */
1766 void print_order_by(const THD *thd, String *str,
1767 enum_query_type query_type) const;
1768
1769 void print_limit(const THD *thd, String *str,
1770 enum_query_type query_type) const;
1771 bool save_properties(THD *thd);
1772
1773 /**
1774 Accept function for SELECT and DELETE.
1775
1776 @param visitor Select_lex_visitor Object
1777 */
1778 bool accept(Select_lex_visitor *visitor);
1779
1781
1782 /**
1783 Cleanup this subtree (this Query_block and all nested Query_blockes and
1784 Query_expressions).
1785 @param full if false only partial cleanup is done, JOINs and JOIN_TABs are
1786 kept to provide info for EXPLAIN CONNECTION; if true, complete cleanup is
1787 done, all JOINs are freed.
1788 */
1789 void cleanup(bool full) override;
1790 /*
1791 Recursively cleanup the join of this select lex and of all nested
1792 select lexes. This is not a full cleanup.
1793 */
1794 void cleanup_all_joins();
1795 /**
1796 Destroy contained objects, in particular temporary tables which may
1797 have their own mem_roots.
1798 */
1799 void destroy();
1800
1801 /// @return true when query block is not part of a set operation and is not a
1802 /// parenthesized query expression.
1805 }
1806
1807 /**
1808 @return true if query block is found during preparation to produce no data.
1809 Notice that if query is implicitly grouped, an aggregation row will
1810 still be returned.
1811 */
1812 bool is_empty_query() const { return m_empty_query; }
1813
1814 /// Set query block as returning no data
1815 /// @todo This may also be set when we have an always false WHERE clause
1817 assert(join == nullptr);
1818 m_empty_query = true;
1819 }
1820 /*
1821 For MODE_ONLY_FULL_GROUP_BY we need to know if
1822 this query block is the aggregation query of at least one aggregate
1823 function.
1824 */
1825 bool agg_func_used() const { return m_agg_func_used; }
1827
1828 void set_agg_func_used(bool val) { m_agg_func_used = val; }
1829
1831
1832 bool right_joins() const { return m_right_joins; }
1834
1835 /// Lookup for Query_block type
1836 enum_explain_type type() const;
1837
1838 /// Lookup for a type string
1839 const char *get_type_str() { return type_str[static_cast<int>(type())]; }
1841 return type_str[static_cast<int>(type)];
1842 }
1843
1845 bool is_cacheable() const { return !uncacheable; }
1846
1847 /// @returns true if this query block outputs at most one row.
1849 return (m_table_list.size() == 0 &&
1850 (!is_table_value_constructor || row_value_list->size() == 1));
1851 }
1852
1853 /// Include query block inside a query expression.
1854 void include_down(LEX *lex, Query_expression *outer);
1855
1856 /// Include a query block next to another query block.
1857 void include_neighbour(LEX *lex, Query_block *before);
1858
1859 /// Include query block inside a query expression, but do not link.
1861
1862 /// Include query block into global list.
1863 void include_in_global(Query_block **plink);
1864
1865 /// Include chain of query blocks into global list.
1867
1868 /// Renumber query blocks of contained query expressions
1869 void renumber(LEX *lex);
1870
1871 /**
1872 Does permanent transformations which are local to a query block (which do
1873 not merge it to another block).
1874 */
1875 bool apply_local_transforms(THD *thd, bool prune);
1876
1877 /// Pushes parts of the WHERE condition of this query block to materialized
1878 /// derived tables.
1880
1881 bool get_optimizable_conditions(THD *thd, Item **new_where,
1882 Item **new_having);
1883
1884 bool validate_outermost_option(LEX *lex, const char *wrong_option) const;
1885 bool validate_base_options(LEX *lex, ulonglong options) const;
1886
1887 bool walk(Item_processor processor, enum_walk walk, uchar *arg);
1888
1889 bool add_tables(THD *thd, const Mem_root_array<Table_ident *> *tables,
1890 ulong table_options, thr_lock_type lock_type,
1891 enum_mdl_type mdl_type);
1892
1893 bool resolve_rollup_wfs(THD *thd);
1894
1895 bool setup_conds(THD *thd);
1896 bool prepare(THD *thd, mem_root_deque<Item *> *insert_field_list);
1897 bool optimize(THD *thd, bool finalize_access_paths);
1898 void reset_nj_counters(mem_root_deque<Table_ref *> *join_list = nullptr);
1899
1900 // If the query block has exactly one single visible field, returns it.
1901 // If not, returns nullptr.
1902 Item *single_visible_field() const;
1903 size_t num_visible_fields() const;
1904
1905 // Whether the SELECT list is empty (hidden fields are ignored).
1906 // Typically used to distinguish INSERT INTO ... SELECT queries
1907 // from INSERT INTO ... VALUES queries.
1908 bool field_list_is_empty() const;
1909
1910 /// Creates a clone for the given expression by re-parsing the
1911 /// expression. Used in condition pushdown to derived tables.
1912 Item *clone_expression(THD *thd, Item *item, Table_ref *derived_table);
1913 /// Returns an expression from the select list of the query block
1914 /// using the field's index in a derived table.
1915 Item *get_derived_expr(uint expr_index);
1916
1918 AccessPath *child_path, TABLE *dst_table) const;
1919
1920 // ************************************************
1921 // * Members (most of these should not be public) *
1922 // ************************************************
1923
1925 /**
1926 All expressions needed after join and filtering, ie., select list,
1927 group by list, having clause, window clause, order by clause,
1928 including hidden fields.
1929 Does not include join conditions nor where clause.
1930
1931 This should ideally be changed into Mem_root_array<Item *>, but
1932 find_order_in_list() depends on pointer stability (it stores a pointer
1933 to an element in referenced_by[]). Similarly, there are some instances
1934 of thd->change_item_tree() that store pointers to elements in this list.
1935
1936 Because of this, adding or removing elements in the middle is not allowed;
1937 std::deque guarantees pointer stability only in the face of adding
1938 or removing elements from either end, ie., {push,pop}_{front_back}.
1939
1940 Currently, all hidden items must be before all visible items.
1941 This is primarily due to the requirement for pointer stability
1942 but also because change_to_use_tmp_fields() depends on it when mapping
1943 items to ref_item_array indexes. It would be good to get rid of this
1944 requirement in the future.
1945 */
1947
1948 /**
1949 All windows defined on the select, both named and inlined
1950 */
1952
1953 /**
1954 A pointer to ftfunc_list_alloc, list of full text search functions.
1955 */
1958
1959 /// The VALUES items of a table value constructor.
1961
1962 /// List of semi-join nests generated for this query block
1964
1965 /// List of tables in FROM clause - use Table_ref::next_local to traverse
1967
1968 /**
1969 ORDER BY clause.
1970 This list may be mutated during optimization (by remove_const() in the old
1971 optimizer or by RemoveRedundantOrderElements() in the hypergraph optimizer),
1972 so for prepared statements, we keep a copy of the ORDER.next pointers in
1973 order_list_ptrs, and re-establish the original list before each execution.
1974 */
1977
1978 /**
1979 GROUP BY clause. This list may be mutated during optimization (by
1980 \c remove_const() in the old optimizer or by
1981 RemoveRedundantOrderElements() in the hypergraph optimizer), so for prepared
1982 statements, we keep a copy of the ORDER.next pointers in \c group_list_ptrs,
1983 and re-establish the original list before each execution. The list can also
1984 be temporarily pruned and restored by \c Group_check (if transform done,
1985 cf. \c Query_block::m_gl_size_orig).
1986 */
1989 /**
1990 For an explicitly grouped, correlated, scalar subquery which is transformed
1991 to join with derived tables: the number of added non-column expressions.
1992 Used for better functional dependency analysis since this is checked during
1993 prepare *after* transformations. Transforms will append inner expressions
1994 to the group by list, rendering the check too optimistic. To remedy this,
1995 we temporarily remove the added compound (i.e. not simple column)
1996 expressions when doing the full group by check. This is bit too
1997 pessimistic: we can get occasionally false positives (full group by check
1998 error). The underlying problem is that we do not perform full group by
1999 checking before transformations. See also \c Group_check's ctor and dtor.
2000 */
2002
2003 // Used so that AggregateIterator knows which items to signal when the rollup
2004 // level changes. Obviously only used in the presence of rollup.
2009
2010 /// Query-block-level hints, for this query block
2012
2013 char *db{nullptr};
2014
2015 /**
2016 If this query block is a recursive member of a recursive unit: the
2017 Table_ref, in this recursive member, referencing the query
2018 name.
2019 */
2021
2022 /// Reference to LEX that this query block belongs to
2023 LEX *parent_lex{nullptr};
2024
2025 /**
2026 The set of those tables whose fields are referenced in the select list of
2027 this select level.
2028 */
2030 table_map outer_join{0}; ///< Bitmap of all inner tables from outer joins
2031
2032 /**
2033 Context for name resolution for all column references except columns
2034 from joined tables.
2035 */
2037
2038 /**
2039 Pointer to first object in list of Name res context objects that have
2040 this query block as the base query block.
2041 Includes field "context" which is embedded in this query block.
2042 */
2044
2045 /**
2046 After optimization it is pointer to corresponding JOIN. This member
2047 should be changed only when THD::LOCK_query_plan mutex is taken.
2048 */
2049 JOIN *join{nullptr};
2050 /// Set of table references contained in outer-most join nest
2052 /// Pointer to the set of table references in the currently active join
2054 /// table embedding the above list
2056 /**
2057 Points to first leaf table of query block. After setup_tables() is done,
2058 this is a list of base tables and derived tables. After derived tables
2059 processing is done, this is a list of base tables only.
2060 Use Table_ref::next_leaf to traverse the list.
2061 */
2063 /// Last table for LATERAL join, used by table functions
2065
2066 /// LIMIT clause, NULL if no limit is given
2068 /// LIMIT ... OFFSET clause, NULL if no offset is given
2070 /// Whether we have LIMIT 1 and no OFFSET.
2071 bool m_limit_1{false};
2072 /**
2073 Circular linked list of aggregate functions in nested query blocks.
2074 This is needed if said aggregate functions depend on outer values
2075 from this query block; if so, we want to add them as hidden items
2076 in our own field list, to be able to evaluate them.
2077 @see Item_sum::check_sum_func
2078 */
2080
2081 /**
2082 Array of pointers to "base" items; one each for every selected expression
2083 and referenced item in the query block. All members of "base_ref_items"
2084 are also present in the "fields" container.
2085 All references to columns (i.e. Item_field) are to buffers associated
2086 with the primary input tables.
2087
2088 Note: The order of expressions in "base_ref_items" may be different from
2089 the order of expressions in "fields".
2090 Note: The array must be created with sufficient size during resolving and
2091 must be preserved in size and location as long as statement exists.
2092 Note: Currently, items representing expressions must be added as follows:
2093 <original visible exprs> <hidden exprs> <generated visible exprs>.
2094 <hidden exprs> are added during resolving and may be an empty set.
2095 <generated visible exprs> are added during possible transformation
2096 stages and may also be an empty set.
2097 */
2099
2100 uint select_number{0}; ///< Query block number (used for EXPLAIN)
2101
2102 /**
2103 Saved values of the WHERE and HAVING clauses. Allowed values are:
2104 - COND_UNDEF if the condition was not specified in the query or if it
2105 has not been optimized yet
2106 - COND_TRUE if the condition is always true
2107 - COND_FALSE if the condition is impossible
2108 - COND_OK otherwise
2109 */
2112
2113 /// Parse context: indicates where the current expression is being parsed
2115 /// Parse context: is inside a set function if this is positive
2117 /// Parse context: is inside a window function if this is positive
2119
2120 /**
2121 Three fields used by semi-join transformations to know when semi-join is
2122 possible, and in which condition tree the subquery predicate is located.
2123 */
2133 RESOLVE_NONE}; ///< Indicates part of query being resolved
2134
2135 /**
2136 Number of fields used in select list or where clause of current select
2137 and all inner subselects.
2138 */
2140 /**
2141 Number of items in the select list, HAVING clause, QUALIFY clause and ORDER
2142 BY clause. It is used to reserve space in the base_ref_items array so that
2143 it is big enough to hold hidden items for any of the expressions or
2144 sub-expressions in those clauses.
2145 */
2147 /// Number of arguments of and/or/xor in where/having/on
2149 /// Number of predicates after preparation
2150 uint cond_count{0};
2151 /// Number of between predicates in where/having/on
2153 /// Maximal number of elements in multiple equalities
2155
2156 /**
2157 Number of Item_sum-derived objects in this SELECT. Keeps count of
2158 aggregate functions and window functions(to allocate items in ref array).
2159 See Query_block::setup_base_ref_items.
2160 */
2162 /// Number of Item_sum-derived objects in children and descendant SELECTs
2164
2165 /// Keep track for allocation of base_ref_items: scalar subqueries may be
2166 /// replaced by a field during scalar_to_derived transformation
2168
2169 /// Number of materialized derived tables and views in this query block.
2171 /// Number of partitioned tables
2173
2174 /**
2175 Number of wildcards used in the SELECT list. For example,
2176 SELECT *, t1.*, catalog.t2.* FROM t0, t1, t2;
2177 has 3 wildcards.
2178 */
2179 uint with_wild{0};
2180
2181 /// Original query table map before aj/sj processing.
2183 /// Number of leaf tables in this query block.
2185 /// Number of derived tables and views in this query block.
2187 /// Number of table functions in this query block
2189
2190 /**
2191 Nesting level of query block, outer-most query block has level 0,
2192 its subqueries have level 1, etc. @see also sql/item_sum.h.
2193 */
2195
2196 /**
2197 Indicates whether this query block contains non-primitive grouping (such as
2198 ROLLUP).
2199 */
2201
2202 /// @see enum_condition_context
2204
2205 /// If set, the query block is of the form VALUES row_list.
2207
2208 /// Describes context of this query block (e.g if it is a derived table).
2210
2211 /**
2212 result of this query can't be cached, bit field, can be :
2213 UNCACHEABLE_DEPENDENT
2214 UNCACHEABLE_RAND
2215 UNCACHEABLE_SIDEEFFECT
2216 */
2218
2219 void update_used_tables();
2221 bool save_cmd_properties(THD *thd);
2222
2223 /**
2224 This variable is required to ensure proper work of subqueries and
2225 stored procedures. Generally, one should use the states of
2226 Query_arena to determine if it's a statement prepare or first
2227 execution of a stored procedure. However, in case when there was an
2228 error during the first execution of a stored procedure, the SP body
2229 is not expelled from the SP cache. Therefore, a deeply nested
2230 subquery might be left unoptimized. So we need this per-subquery
2231 variable to inidicate the optimization/execution state of every
2232 subquery. Prepared statements work OK in that regard, as in
2233 case of an error during prepare the PS is not created.
2234 */
2236
2237 /// True when semi-join pull-out processing is complete
2238 bool sj_pullout_done{false};
2239
2240 /// Used by nested scalar_to_derived transformations
2242
2243 /// True: skip local transformations during prepare() call (used by INSERT)
2245
2247
2248 /// true when having fix field called in processing of this query block
2249 bool having_fix_field{false};
2250 /// true when GROUP BY fix field called in processing of this query block
2251 bool group_fix_field{false};
2252 /// true when resolving a window's ORDER BY or PARTITION BY, the window
2253 /// belonging to this query block.
2255
2256 /**
2257 True if contains or aggregates set functions.
2258 @note this is wrong when a locally found set function is aggregated
2259 in an outer query block.
2260 */
2261 bool with_sum_func{false};
2262
2263 /**
2264 HAVING clause contains subquery => we can't close tables before
2265 query processing end even if we use temporary table
2266 */
2268
2269 /**
2270 If true, use select_limit to limit number of rows selected.
2271 Applicable when no explicit limit is supplied, and only for the
2272 outermost query block of a SELECT statement.
2273 */
2275
2276 /// If true, limit object is added internally
2277 bool m_internal_limit{false};
2278
2279 /// exclude this query block from unique_table() check
2281
2282 bool no_table_names_allowed{false}; ///< used for global order by
2283
2284 /// Keeps track of the current ORDER BY expression we are resolving for
2285 /// ORDER BY, if any. Not used for GROUP BY or windowing ordering.
2287
2288 /// Hidden items added during optimization
2289 /// @note that using this means we modify resolved data during optimization
2291
2292 [[nodiscard]] bool limit_offset_preserves_first_row() const;
2293
2294 private:
2295 friend class Query_expression;
2296 friend class Condition_context;
2297
2298 /// Helper for save_properties()
2300 Group_list_ptrs **list_ptrs);
2301
2303 bool simplify_joins(THD *thd, mem_root_deque<Table_ref *> *join_list,
2304 bool top, bool in_sj, Item **new_conds,
2305 uint *changelog = nullptr);
2306 /// Remove semijoin condition for this query block
2307 void clear_sj_expressions(NESTED_JOIN *nested_join);
2308 /// Build semijoin condition for th query block
2309 bool build_sj_cond(THD *thd, NESTED_JOIN *nested_join,
2310 Query_block *subq_query_block, table_map outer_tables_map,
2311 Item **sj_cond, bool *simple_const);
2313 Table_ref *join_nest);
2314
2317 Item *join_cond, bool left_outer,
2318 bool use_inner_join);
2319 bool transform_subquery_to_derived(THD *thd, Table_ref **out_tl,
2320 Query_expression *subs_query_expression,
2321 Item_subselect *subq, bool use_inner_join,
2322 bool reject_multiple_rows,
2323 Item::Css_info *subquery,
2324 Item *lifted_where_cond);
2326 THD *thd, Item_exists_subselect *subq_pred);
2328 THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_expressions,
2329 mem_root_deque<Item *> &exprs_added_to_group_by, uint hidden_fields);
2331 Lifted_expressions_map *lifted_exprs,
2332 Item *selected_field_or_ref,
2333 const uint first_non_hidden);
2335 THD *thd, Lifted_expressions_map *lifted_exprs);
2337 THD *thd, List_iterator<Item> &inner_exprs, Item *selected_item,
2338 bool *selected_expr_added_to_group_by,
2339 mem_root_deque<Item *> *exprs_added_to_group_by);
2341 THD *thd, Table_ref *derived, Item::Css_info *subquery,
2342 Item *lifted_where, Lifted_expressions_map *lifted_where_expressions,
2343 bool *added_card_check, size_t *added_window_card_checks);
2345 THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs,
2346 bool added_card_check, size_t added_window_card_checks);
2347 /// Replace the first visible item in the select list with a wrapping
2348 /// MIN or MAX aggregate function.
2349 bool replace_first_item_with_min_max(THD *thd, int item_no, bool use_min);
2350 void replace_referenced_item(Item *const old_item, Item *const new_item);
2351 void remap_tables(THD *thd);
2353 Item *resolve_rollup_item(THD *thd, Item *item);
2354 bool resolve_rollup(THD *thd);
2355
2356 bool setup_wild(THD *thd);
2357 bool setup_order_final(THD *thd);
2358 bool setup_group(THD *thd);
2359 void fix_after_pullout(Query_block *parent_query_block,
2360 Query_block *removed_query_block);
2363 bool empty_order_list(Query_block *sl);
2365 bool in_update);
2366 bool find_common_table_expr(THD *thd, Table_ident *table_id, Table_ref *tl,
2367 Parse_context *pc, bool *found);
2368 /**
2369 Transform eligible scalar subqueries in the SELECT list, WHERE condition,
2370 HAVING condition or JOIN conditions of a query block[*] to an equivalent
2371 derived table of a LEFT OUTER join, e.g. as shown in this uncorrelated
2372 subquery:
2373
2374 [*] a.k.a "transformed query block" throughout this method and its minions.
2375
2376 <pre>
2377 SELECT * FROM t1
2378 WHERE t1.a > (SELECT COUNT(a) AS cnt FROM t2); ->
2379
2380 SELECT t1.* FROM t1 LEFT OUTER JOIN
2381 (SELECT COUNT(a) AS cnt FROM t2) AS derived
2382 ON TRUE WHERE t1.a > derived.cnt;
2383 </pre>
2384
2385 Grouping in the transformed query block may necessitate the grouping to be
2386 moved down to another derived table, cf. transform_grouped_to_derived.
2387
2388 Limitations:
2389 - only implicitly grouped subqueries (guaranteed to have cardinality one)
2390 are identified as scalar subqueries.
2391 _ Correlated subqueries are not handled
2392
2393 @param[in,out] thd the session context
2394 @returns true on error
2395 */
2398 Item **lifted_where);
2399 bool replace_item_in_expression(Item **expr, bool was_hidden,
2401 Item_transformer transformer);
2402 bool transform_grouped_to_derived(THD *thd, bool *break_off);
2403 bool replace_subquery_in_expr(THD *thd, Item::Css_info *subquery,
2404 Table_ref *tr, Item **expr);
2405 bool nest_derived(THD *thd, Item *join_cond,
2406 mem_root_deque<Table_ref *> *join_list,
2407 Table_ref *new_derived_table);
2408
2410
2411 // Delete unused columns from merged derived tables
2413
2414 bool prepare_values(THD *thd);
2415 bool check_only_full_group_by(THD *thd);
2416 /**
2417 Copies all non-aggregated calls to the full-text search MATCH function from
2418 the HAVING clause to the SELECT list (as hidden items), so that we can
2419 materialize their result and not only their input. This is needed when the
2420 result will be accessed after aggregation, as the result from MATCH cannot
2421 be recalculated from its input alone. It also needs the underlying scan to
2422 be positioned on the correct row. Storing the value before aggregation
2423 removes the need for evaluating MATCH again after materialization.
2424 */
2426
2427 //
2428 // Members:
2429 //
2430
2431 /**
2432 Pointer to collection of subqueries candidate for semi/antijoin
2433 conversion.
2434 Template parameter is "true": no need to run DTORs on pointers.
2435 */
2437
2438 /// How many expressions are part of the order by but not select list.
2440
2441 /**
2442 Intrusive linked list of all query blocks within the same
2443 query expression.
2444 */
2446
2447 /// The query expression containing this query block.
2449 /// The first query expression contained within this query block.
2451
2452 /// Intrusive double-linked global list of query blocks.
2455
2456 /// Result of this query block
2458
2459 /**
2460 Options assigned from parsing and throughout resolving,
2461 should not be modified after resolving is done.
2462 */
2464 /**
2465 Active options. Derived from base options, modifiers added during
2466 resolving and values from session variable option_bits. Since the latter
2467 may change, active options are refreshed per execution of a statement.
2468 */
2470
2471 /**
2472 If the query block includes non-primitive grouping, then these modifiers are
2473 represented as grouping sets. The variable 'm_num_grouping_sets' holds the
2474 count of grouping sets.
2475 */
2477
2478 public:
2480 nullptr}; ///< Used when resolving outer join condition
2481
2482 /**
2483 Initializes the grouping set if the query block includes GROUP BY
2484 modifiers.
2485 */
2486 bool allocate_grouping_sets(THD *thd);
2487
2488 /**
2489 Populates the grouping sets if the query block includes non-primitive
2490 grouping.
2491 */
2492 bool populate_grouping_sets(THD *thd);
2494
2495 private:
2496 /**
2497 Condition to be evaluated after all tables in a query block are joined.
2498 After all permanent transformations have been conducted by
2499 Query_block::prepare(), this condition is "frozen", any subsequent changes
2500 to it must be done with change_item_tree(), unless they only modify AND/OR
2501 items and use a copy created by Query_block::get_optimizable_conditions().
2502 Same is true for 'having_cond'.
2503 */
2505
2506 /// Condition to be evaluated on grouped rows after grouping.
2508
2509 /// Condition to be evaluated after window functions.
2511
2512 /// Number of GROUP BY expressions added to all_fields
2514
2515 /// A backup of the items in base_ref_items at the end of preparation, so that
2516 /// base_ref_items can be restored between executions of prepared statements.
2517 /// Empty if it's a regular statement.
2519
2520 /**
2521 True if query block has semi-join nests merged into it. Notice that this
2522 is updated earlier than sj_nests, so check this if info is needed
2523 before the full resolver process is complete.
2524 */
2525 bool has_sj_nests{false};
2526 bool has_aj_nests{false}; ///< @see has_sj_nests; counts antijoin nests.
2527 bool m_right_joins{false}; ///< True if query block has right joins
2528
2529 /// Allow merge of immediate unnamed derived tables
2531
2532 bool m_agg_func_used{false};
2534
2535 /**
2536 True if query block does not generate any rows before aggregation,
2537 determined during preparation (not optimization).
2538 */
2539 bool m_empty_query{false};
2540
2541 static const char
2543};
2544
2545inline bool Query_expression::is_union() const {
2546 Query_term *qt = query_term();
2547 while (qt->term_type() == QT_UNARY)
2548 qt = down_cast<Query_term_unary *>(qt)->child(0);
2549 return qt->term_type() == QT_UNION;
2550}
2551
2553 Query_term *qt = query_term();
2554 while (qt->term_type() == QT_UNARY)
2555 qt = down_cast<Query_term_unary *>(qt)->child(0);
2556 const Query_term_type type = qt->term_type();
2557 return type == QT_UNION || type == QT_INTERSECT || type == QT_EXCEPT;
2558}
2559
2560/// Utility RAII class to save/modify/restore the condition_context information
2561/// of a query block. @see enum_condition_context.
2563 public:
2565 Query_block *select_ptr,
2567 : select(nullptr), saved_value() {
2568 if (select_ptr) {
2569 select = select_ptr;
2571 // More restrictive wins over less restrictive:
2572 if (new_type == enum_condition_context::NEITHER ||
2573 (new_type == enum_condition_context::ANDS_ORS &&
2575 select->condition_context = new_type;
2576 }
2577 }
2580 }
2581
2582 private:
2585};
2586
2588 std::function<bool(Table_ref *)> action);
2589
2590/**
2591 Base class for secondary engine execution context objects. Secondary
2592 storage engines may create classes derived from this one which
2593 contain state they need to preserve between optimization and
2594 execution of statements. The context objects should be allocated on
2595 the execution MEM_ROOT.
2596*/
2598 public:
2599 /**
2600 Destructs the secondary engine execution context object. It is
2601 called after the query execution has completed. Secondary engines
2602 may override the destructor in subclasses and add code that
2603 performs cleanup tasks that are needed after query execution.
2604 */
2606};
2607
2609 char *user;
2613
2614 void reset();
2616
2621
2623 : m_db{db}, m_name{name}, m_alias{alias} {}
2624};
2625
2629 bool detistic = false;
2631 LEX_CSTRING language = NULL_CSTR; ///< CREATE|ALTER ... LANGUAGE <language>
2632
2633 /**
2634 List of imported libraries for this routine
2635 */
2637
2638 /**
2639 Add library names to the set of imported libraries.
2640
2641 We only allow one USING clause in CREATE statements, so repeated calls
2642 to this function should fail.
2643
2644 @param libs Set of libraries to be added
2645 @param mem_root MEM_ROOT to use for allocation
2646
2647 @returns true on failures; false otherwise
2648 */
2650 MEM_ROOT *mem_root) {
2651 assert(!libs.empty());
2652
2653 if (m_imported_libraries != nullptr) return true; // Allow a single USING.
2654
2655 if (libs.empty()) return false; // Nothing to do.
2656 if (create_imported_libraries_deque(mem_root)) return true;
2657
2658 while (!libs.empty()) {
2659 if (m_imported_libraries->push_back(libs.front())) return true;
2660 libs.pop_front();
2661 }
2662 return false;
2663 }
2664
2665 /**
2666 Add a library to the set of imported libraries.
2667
2668 @param database The library's database.
2669 @param name The library's name.
2670 @param alias The library's alias.
2671 @param mem_root MEM_ROOT to use for allocation
2672
2673 @returns true on failures; false otherwise
2674 */
2675 bool add_imported_library(std::string_view database, std::string_view name,
2676 std::string_view alias, MEM_ROOT *mem_root) {
2677 if (m_imported_libraries == nullptr)
2678 if (create_imported_libraries_deque(mem_root)) return true;
2679
2680 return m_imported_libraries->push_back({
2681 {strmake_root(mem_root, database.data(), database.length()),
2682 database.length()}, // sp_name_with_alias.m_db
2683 {strmake_root(mem_root, name.data(), name.length()),
2684 name.length()}, // sp_name_with_alias.m_name
2685 {strmake_root(mem_root, alias.data(), alias.length()),
2686 alias.length()} // sp_name_with_alias.m_alias
2687 });
2688 }
2689
2691 if (m_imported_libraries != nullptr) return true; // Already allocated.
2694 return m_imported_libraries == nullptr;
2695 }
2696
2697 /**
2698 Get the set of imported libraries for the routine
2699
2700 @returns The set of imported libraries, nullptr if no imported libraries
2701 */
2703 return m_imported_libraries;
2704 }
2705
2706 /**
2707 Reset the structure.
2708 */
2709 void reset(void) {
2712 detistic = false;
2715 m_imported_libraries = nullptr;
2716 }
2717};
2718
2719extern const LEX_STRING null_lex_str;
2720
2724
2725 /**
2726 FOLLOWS or PRECEDES as specified in the CREATE TRIGGER statement.
2727 */
2729
2730 /**
2731 Trigger name referenced in the FOLLOWS/PRECEDES clause of the CREATE TRIGGER
2732 statement.
2733 */
2735};
2736
2738
2739/*
2740 Class representing list of all tables used by statement and other
2741 information which is necessary for opening and locking its tables,
2742 like SQL command for this statement.
2743
2744 Also contains information about stored functions used by statement
2745 since during its execution we may have to add all tables used by its
2746 stored functions/triggers to this list in order to pre-open and lock
2747 them.
2748
2749 Also used by LEX::reset_n_backup/restore_backup_query_tables_list()
2750 methods to save and restore this information.
2751*/
2752
2754 public:
2756
2757 /**
2758 SQL command for this statement. Part of this class since the
2759 process of opening and locking tables for the statement needs
2760 this information to determine correct type of lock for some of
2761 the tables.
2762 */
2764 /* Global list of all tables used by this statement */
2766 /* Pointer to next_global member of last element in the previous list. */
2768 /*
2769 If non-0 then indicates that query requires prelocking and points to
2770 next_global member of last own element in query table list (i.e. last
2771 table which was not added to it as part of preparation to prelocking).
2772 0 - indicates that this query does not need prelocking.
2773 */
2775 /*
2776 Set of stored routines called by statement.
2777 (Note that we use lazy-initialization for this hash).
2778
2779 See Sroutine_hash_entry for explanation why this hash uses binary
2780 key comparison.
2781 */
2783 std::unique_ptr<malloc_unordered_map<std::string, Sroutine_hash_entry *>>
2785 /*
2786 List linking elements of 'sroutines' set. Allows you to add new elements
2787 to this set as you iterate through the list of existing elements.
2788 'sroutines_list_own_last' is pointer to ::next member of last element of
2789 this list which represents routine which is explicitly used by query.
2790 'sroutines_list_own_elements' number of explicitly used routines.
2791 We use these two members for restoring of 'sroutines_list' to the state
2792 in which it was right after query parsing.
2793 */
2797
2798 /**
2799 Does this LEX context have any stored functions
2800 */
2802
2803 /**
2804 Locking state of tables in this particular statement.
2805
2806 If we under LOCK TABLES or in prelocked mode we consider tables
2807 for the statement to be "locked" if there was a call to lock_tables()
2808 (which called handler::start_stmt()) for tables of this statement
2809 and there was no matching close_thread_tables() call.
2810
2811 As result this state may differ significantly from one represented
2812 by Open_tables_state::lock/locked_tables_mode more, which are always
2813 "on" under LOCK TABLES or in prelocked mode.
2814 */
2818 return (lock_tables_state == LTS_LOCKED);
2819 }
2820
2821 /**
2822 Number of tables which were open by open_tables() and to be locked
2823 by lock_tables().
2824 Note that we set this member only in some cases, when this value
2825 needs to be passed from open_tables() to lock_tables() which are
2826 separated by some amount of code.
2827 */
2829
2830 /*
2831 These constructor and destructor serve for creation/destruction
2832 of Query_tables_list instances which are used as backup storage.
2833 */
2836
2837 /* Initializes (or resets) Query_tables_list object for "real" use. */
2838 void reset_query_tables_list(bool init);
2841 *this = std::move(*state);
2842 }
2843
2844 /*
2845 Direct addition to the list of query tables.
2846 If you are using this function, you must ensure that the table
2847 object, in particular table->db member, is initialized.
2848 */
2850 *(table->prev_global = query_tables_last) = table;
2851 query_tables_last = &table->next_global;
2852 }
2854 void mark_as_requiring_prelocking(Table_ref **tables_own_last) {
2855 query_tables_own_last = tables_own_last;
2856 }
2857 /* Return pointer to first not-own table in query-tables or 0 */
2859 return (query_tables_own_last ? *query_tables_own_last : nullptr);
2860 }
2863 *query_tables_own_last = nullptr;
2865 query_tables_own_last = nullptr;
2866 }
2867 }
2868
2869 /**
2870 All types of unsafe statements.
2871
2872 @note The int values of the enum elements are used to point to
2873 bits in two bitmaps in two different places:
2874
2875 - Query_tables_list::binlog_stmt_flags
2876 - THD::binlog_unsafe_warning_flags
2877
2878 Hence in practice this is not an enum at all, but a map from
2879 symbols to bit indexes.
2880
2881 The ordering of elements in this enum must correspond to the order of
2882 elements in the array binlog_stmt_unsafe_errcode.
2883 */
2885 /**
2886 SELECT..LIMIT is unsafe because the set of rows returned cannot
2887 be predicted.
2888 */
2890 /**
2891 Access to log tables is unsafe because slave and master probably
2892 log different things.
2893 */
2895 /**
2896 Inserting into an autoincrement column in a stored routine is unsafe.
2897 Even with just one autoincrement column, if the routine is invoked more
2898 than once slave is not guaranteed to execute the statement graph same way
2899 as the master. And since it's impossible to estimate how many times a
2900 routine can be invoked at the query pre-execution phase (see lock_tables),
2901 the statement is marked pessimistically unsafe.
2902 */
2904 /**
2905 Using a UDF (user-defined function) is unsafe.
2906 */
2908 /**
2909 Using most system variables is unsafe, because slave may run
2910 with different options than master.
2911 */
2913 /**
2914 Using some functions is unsafe (e.g., UUID).
2915 */
2917
2918 /**
2919 Mixing transactional and non-transactional statements are unsafe if
2920 non-transactional reads or writes are occur after transactional
2921 reads or writes inside a transaction.
2922 */
2924
2925 /**
2926 Mixing self-logging and non-self-logging engines in a statement
2927 is unsafe.
2928 */
2930
2931 /**
2932 Statements that read from both transactional and non-transactional
2933 tables and write to any of them are unsafe.
2934 */
2936
2937 /**
2938 INSERT...IGNORE SELECT is unsafe because which rows are ignored depends
2939 on the order that rows are retrieved by SELECT. This order cannot be
2940 predicted and may differ on master and the slave.
2941 */
2943
2944 /**
2945 INSERT...SELECT...UPDATE is unsafe because which rows are updated depends
2946 on the order that rows are retrieved by SELECT. This order cannot be
2947 predicted and may differ on master and the slave.
2948 */
2950
2951 /**
2952 Query that writes to a table with auto_inc column after selecting from
2953 other tables are unsafe as the order in which the rows are retrieved by
2954 select may differ on master and slave.
2955 */
2957
2958 /**
2959 INSERT...REPLACE SELECT is unsafe because which rows are replaced depends
2960 on the order that rows are retrieved by SELECT. This order cannot be
2961 predicted and may differ on master and the slave.
2962 */
2964
2965 /**
2966 CREATE TABLE... IGNORE... SELECT is unsafe because which rows are ignored
2967 depends on the order that rows are retrieved by SELECT. This order cannot
2968 be predicted and may differ on master and the slave.
2969 */
2971
2972 /**
2973 CREATE TABLE...REPLACE... SELECT is unsafe because which rows are replaced
2974 depends on the order that rows are retrieved from SELECT. This order
2975 cannot be predicted and may differ on master and the slave
2976 */
2978
2979 /**
2980 CREATE TABLE...SELECT on a table with auto-increment column is unsafe
2981 because which rows are replaced depends on the order that rows are
2982 retrieved from SELECT. This order cannot be predicted and may differ on
2983 master and the slave
2984 */
2986
2987 /**
2988 UPDATE...IGNORE is unsafe because which rows are ignored depends on the
2989 order that rows are updated. This order cannot be predicted and may differ
2990 on master and the slave.
2991 */
2993
2994 /**
2995 INSERT... ON DUPLICATE KEY UPDATE on a table with more than one
2996 UNIQUE KEYS is unsafe.
2997 */
2999
3000 /**
3001 INSERT into auto-inc field which is not the first part in composed
3002 primary key.
3003 */
3005
3006 /**
3007 Using a plugin is unsafe.
3008 */
3012
3013 /**
3014 XA transactions and statements.
3015 */
3017
3018 /**
3019 If a substatement inserts into or updates a table that has a column with
3020 an unsafe DEFAULT expression, it may not have the same effect on the
3021 slave.
3022 */
3024
3025 /**
3026 DML or DDL statement that reads a ACL table is unsafe, because the row
3027 are read without acquiring SE row locks. This would allow ACL tables to
3028 be updated by concurrent thread. It would not have the same effect on the
3029 slave.
3030 */
3032
3033 /**
3034 Generating invisible primary key for a table created using CREATE TABLE...
3035 SELECT... is unsafe because order in which rows are retrieved by the
3036 SELECT determines which (if any) rows are inserted. This order cannot be
3037 predicted and values for generated invisible primary key column may
3038 differ on source and replica when @@session.binlog_format=STATEMENT.
3039 */
3041
3042 /* the last element of this enumeration type. */
3045 /**
3046 This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT
3047 (exclusive) set.
3048 */
3050 ((1 << BINLOG_STMT_UNSAFE_COUNT) - 1);
3051
3052 /**
3053 Maps elements of enum_binlog_stmt_unsafe to error codes.
3054 */
3056
3057 /**
3058 Determine if this statement is marked as unsafe.
3059
3060 @retval 0 if the statement is not marked as unsafe.
3061 @retval nonzero if the statement is marked as unsafe.
3062 */
3063 inline bool is_stmt_unsafe() const { return get_stmt_unsafe_flags() != 0; }
3064
3066 return binlog_stmt_flags & (1 << unsafe);
3067 }
3068
3069 /**
3070 Flag the current (top-level) statement as unsafe.
3071 The flag will be reset after the statement has finished.
3072
3073 @param unsafe_type The type of unsafety: one of the @c
3074 BINLOG_STMT_FLAG_UNSAFE_* flags in @c enum_binlog_stmt_flag.
3075 */
3076 inline void set_stmt_unsafe(enum_binlog_stmt_unsafe unsafe_type) {
3077 DBUG_TRACE;
3078 assert(unsafe_type >= 0 && unsafe_type < BINLOG_STMT_UNSAFE_COUNT);
3079 binlog_stmt_flags |= (1U << unsafe_type);
3080 return;
3081 }
3082
3083 /**
3084 Set the bits of binlog_stmt_flags determining the type of
3085 unsafeness of the current statement. No existing bits will be
3086 cleared, but new bits may be set.
3087
3088 @param flags A binary combination of zero or more bits, (1<<flag)
3089 where flag is a member of enum_binlog_stmt_unsafe.
3090 */
3092 DBUG_TRACE;
3093 assert((flags & ~BINLOG_STMT_UNSAFE_ALL_FLAGS) == 0);
3095 return;
3096 }
3097
3098 /**
3099 Return a binary combination of all unsafe warnings for the
3100 statement. If the statement has been marked as unsafe by the
3101 'flag' member of enum_binlog_stmt_unsafe, then the return value
3102 from this function has bit (1<<flag) set to 1.
3103 */
3105 DBUG_TRACE;
3107 }
3108
3109 /**
3110 Determine if this statement is a row injection.
3111
3112 @retval 0 if the statement is not a row injection
3113 @retval nonzero if the statement is a row injection
3114 */
3115 inline bool is_stmt_row_injection() const {
3116 constexpr uint32_t shift =
3117 static_cast<uint32_t>(BINLOG_STMT_UNSAFE_COUNT) +
3118 static_cast<uint32_t>(BINLOG_STMT_TYPE_ROW_INJECTION);
3119 return binlog_stmt_flags & (1U << shift);
3120 }
3121
3122 /**
3123 Flag the statement as a row injection. A row injection is either
3124 a BINLOG statement, or a row event in the relay log executed by
3125 the slave SQL thread.
3126 */
3128 constexpr uint32_t shift =
3129 static_cast<uint32_t>(BINLOG_STMT_UNSAFE_COUNT) +
3130 static_cast<uint32_t>(BINLOG_STMT_TYPE_ROW_INJECTION);
3131 DBUG_TRACE;
3132 binlog_stmt_flags |= (1U << shift);
3133 }
3134
3136 /*
3137 If a transactional table is about to be read. Note that
3138 a write implies a read.
3139 */
3141 /*
3142 If a non-transactional table is about to be read. Note that
3143 a write implies a read.
3144 */
3146 /*
3147 If a temporary transactional table is about to be read. Note
3148 that a write implies a read.
3149 */
3151 /*
3152 If a temporary non-transactional table is about to be read. Note
3153 that a write implies a read.
3154 */
3156 /*
3157 If a transactional table is about to be updated.
3158 */
3160 /*
3161 If a non-transactional table is about to be updated.
3162 */
3164 /*
3165 If a temporary transactional table is about to be updated.
3166 */
3168 /*
3169 If a temporary non-transactional table is about to be updated.
3170 */
3172 /*
3173 The last element of the enumeration. Please, if necessary add
3174 anything before this.
3175 */
3178
3179#ifndef NDEBUG
3180 static inline const char *stmt_accessed_table_string(
3181 enum_stmt_accessed_table accessed_table) {
3182 switch (accessed_table) {
3184 return "STMT_READS_TRANS_TABLE";
3185 break;
3187 return "STMT_READS_NON_TRANS_TABLE";
3188 break;
3190 return "STMT_READS_TEMP_TRANS_TABLE";
3191 break;
3193 return "STMT_READS_TEMP_NON_TRANS_TABLE";
3194 break;
3196 return "STMT_WRITES_TRANS_TABLE";
3197 break;
3199 return "STMT_WRITES_NON_TRANS_TABLE";
3200 break;
3202 return "STMT_WRITES_TEMP_TRANS_TABLE";
3203 break;
3205 return "STMT_WRITES_TEMP_NON_TRANS_TABLE";
3206 break;
3208 default:
3209 assert(0);
3210 break;
3211 }
3213 return "";
3214 }
3215#endif /* DBUG */
3216
3217#define BINLOG_DIRECT_ON \
3218 0xF0 /* unsafe when \
3219 --binlog-direct-non-trans-updates \
3220 is ON */
3221
3222#define BINLOG_DIRECT_OFF \
3223 0xF /* unsafe when \
3224 --binlog-direct-non-trans-updates \
3225 is OFF */
3226
3227#define TRX_CACHE_EMPTY 0x33 /* unsafe when trx-cache is empty */
3228
3229#define TRX_CACHE_NOT_EMPTY 0xCC /* unsafe when trx-cache is not empty */
3230
3231#define IL_LT_REPEATABLE 0xAA /* unsafe when < ISO_REPEATABLE_READ */
3232
3233#define IL_GTE_REPEATABLE 0x55 /* unsafe when >= ISO_REPEATABLE_READ */
3234
3235 /**
3236 Sets the type of table that is about to be accessed while executing a
3237 statement.
3239 @param accessed_table Enumeration type that defines the type of table,
3240 e.g. temporary, transactional, non-transactional.
3241 */
3242 inline void set_stmt_accessed_table(enum_stmt_accessed_table accessed_table) {
3243 DBUG_TRACE;
3244
3245 assert(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
3246 stmt_accessed_table_flag |= (1U << accessed_table);
3247
3248 return;
3249 }
3250
3251 /**
3252 Checks if a type of table is about to be accessed while executing a
3253 statement.
3254
3255 @param accessed_table Enumeration type that defines the type of table,
3256 e.g. temporary, transactional, non-transactional.
3258 @retval true if the type of the table is about to be accessed
3259 @retval false otherwise
3260 */
3261 inline bool stmt_accessed_table(enum_stmt_accessed_table accessed_table) {
3262 DBUG_TRACE;
3263
3264 assert(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
3265
3266 return (stmt_accessed_table_flag & (1U << accessed_table)) != 0;
3267 }
3268
3269 /*
3270 Checks if a mixed statement is unsafe.
3271
3272
3273 @param in_multi_stmt_transaction_mode defines if there is an on-going
3274 multi-transactional statement.
3275 @param binlog_direct defines if --binlog-direct-non-trans-updates is
3276 active.
3277 @param trx_cache_is_not_empty defines if the trx-cache is empty or not.
3278 @param trx_isolation defines the isolation level.
3279
3280 @return
3281 @retval true if the mixed statement is unsafe
3282 @retval false otherwise
3283 */
3284 inline bool is_mixed_stmt_unsafe(bool in_multi_stmt_transaction_mode,
3285 bool binlog_direct,
3286 bool trx_cache_is_not_empty,
3287 uint tx_isolation) {
3288 bool unsafe = false;
3289
3290 if (in_multi_stmt_transaction_mode) {
3291 const uint condition =
3292 (binlog_direct ? BINLOG_DIRECT_ON : BINLOG_DIRECT_OFF) &
3293 (trx_cache_is_not_empty ? TRX_CACHE_NOT_EMPTY : TRX_CACHE_EMPTY) &
3294 (tx_isolation >= ISO_REPEATABLE_READ ? IL_GTE_REPEATABLE
3296
3297 unsafe = (binlog_unsafe_map[stmt_accessed_table_flag] & condition);
3298
3299#if !defined(NDEBUG)
3300 DBUG_PRINT("LEX::is_mixed_stmt_unsafe",
3301 ("RESULT %02X %02X %02X\n", condition,
3304
3305 int type_in = 0;
3306 for (; type_in < STMT_ACCESS_TABLE_COUNT; type_in++) {
3308 DBUG_PRINT("LEX::is_mixed_stmt_unsafe",
3309 ("ACCESSED %s ", stmt_accessed_table_string(
3310 (enum_stmt_accessed_table)type_in)));
3311 }
3312#endif
3313 }
3314
3317 tx_isolation < ISO_REPEATABLE_READ)
3318 unsafe = true;
3321 tx_isolation < ISO_REPEATABLE_READ)
3322 unsafe = true;
3323
3324 return (unsafe);
3325 }
3326
3327 /**
3328 true if the parsed tree contains references to stored procedures, triggers
3329 or functions, false otherwise
3331 bool uses_stored_routines() const { return sroutines_list.elements != 0; }
3333 void set_using_match() { using_match = true; }
3334 bool get_using_match() { return using_match; }
3335
3337 bool is_stmt_unsafe_with_mixed_mode() const {
3339 }
3340
3341 private:
3342 /**
3343 Enumeration listing special types of statements.
3344
3345 Currently, the only possible type is ROW_INJECTION.
3346 */
3348 /**
3349 The statement is a row injection (i.e., either a BINLOG
3350 statement or a row event executed by the slave SQL thread).
3351 */
3353
3354 /** The last element of this enumeration type. */
3356 };
3357
3358 /**
3359 Bit field indicating the type of statement.
3360
3361 There are two groups of bits:
3362
3363 - The low BINLOG_STMT_UNSAFE_COUNT bits indicate the types of
3364 unsafeness that the current statement has.
3365
3366 - The next BINLOG_STMT_TYPE_COUNT bits indicate if the statement
3367 is of some special type.
3368
3369 This must be a member of LEX, not of THD: each stored procedure
3370 needs to remember its unsafeness state between calls and each
3371 stored procedure has its own LEX object (but no own THD object).
3372 */
3374
3375 /**
3376 Bit field that determines the type of tables that are about to be
3377 be accessed while executing a statement.
3378 */
3381 /**
3382 It will be set true if 'MATCH () AGAINST' is used in the statement.
3383 */
3384 bool using_match;
3385
3386 /**
3387 This flag is set to true if statement is unsafe to be binlogged in STATEMENT
3388 format, when in MIXED mode.
3389 Currently this flag is set to true if stored program used in statement has
3390 CREATE/DROP temporary table operation(s) as sub-statement(s).
3391 */
3392 bool stmt_unsafe_with_mixed_mode{false};
3393};
3394
3395/*
3396 st_parsing_options contains the flags for constructions that are
3397 allowed in the current statement.
3399
3401 bool allows_variable;
3402 bool allows_select_into;
3403
3404 st_parsing_options() { reset(); }
3405 void reset();
3406};
3408/**
3409 The state of the lexical parser, when parsing comments.
3410*/
3412 /**
3413 Not parsing comments.
3414 */
3415 NO_COMMENT,
3416
3417 /**
3418 Parsing comments that need to be preserved.
3419 (Copy '/' '*' and '*' '/' sequences to the preprocessed buffer.)
3420 Typically, these are user comments '/' '*' ... '*' '/'.
3421 */
3423
3424 /**
3425 Parsing comments that need to be discarded.
3426 (Don't copy '/' '*' '!' and '*' '/' sequences to the preprocessed buffer.)
3427 Typically, these are special comments '/' '*' '!' ... '*' '/',
3428 or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
3429 markers should not be expanded.
3430 */
3432};
3433
3434/**
3435 This class represents the character input stream consumed during lexical
3436 analysis.
3437
3438 In addition to consuming the input stream, this class performs some comment
3439 pre processing, by filtering out out-of-bound special text from the query
3440 input stream.
3441
3442 Two buffers, with pointers inside each, are maintained in parallel. The
3443 'raw' buffer is the original query text, which may contain out-of-bound
3444 comments. The 'cpp' (for comments pre processor) is the pre-processed buffer
3445 that contains only the query text that should be seen once out-of-bound data
3446 is removed.
3447*/
3448
3449class Lex_input_stream {
3450 public:
3451 /**
3452 Constructor
3454 @param grammar_selector_token_arg See grammar_selector_token.
3455 */
3456
3457 explicit Lex_input_stream(uint grammar_selector_token_arg)
3458 : grammar_selector_token(grammar_selector_token_arg) {}
3459
3460 /**
3461 Object initializer. Must be called before usage.
3463 @retval false OK
3464 @retval true Error
3465 */
3466 bool init(THD *thd, const char *buff, size_t length);
3467
3468 void reset(const char *buff, size_t length);
3469
3470 /**
3471 Set the echo mode.
3472
3473 When echo is true, characters parsed from the raw input stream are
3474 preserved. When false, characters parsed are silently ignored.
3475 @param echo the echo mode.
3476 */
3477 void set_echo(bool echo) { m_echo = echo; }
3478
3479 void save_in_comment_state() {
3482 }
3483
3487 }
3488
3489 /**
3490 Skip binary from the input stream.
3491 @param n number of bytes to accept.
3492 */
3493 void skip_binary(int n) {
3494 assert(m_ptr + n <= m_end_of_query);
3495 if (m_echo) {
3496 memcpy(m_cpp_ptr, m_ptr, n);
3497 m_cpp_ptr += n;
3498 }
3499 m_ptr += n;
3500 }
3501
3502 /**
3503 Get a character, and advance in the stream.
3504 @return the next character to parse.
3505 */
3506 unsigned char yyGet() {
3507 assert(m_ptr <= m_end_of_query);
3508 const char c = *m_ptr++;
3509 if (m_echo) *m_cpp_ptr++ = c;
3510 return c;
3511 }
3512
3513 /**
3514 Get the last character accepted.
3515 @return the last character accepted.
3516 */
3517 unsigned char yyGetLast() const { return m_ptr[-1]; }
3519 /**
3520 Look at the next character to parse, but do not accept it.
3521 */
3522 unsigned char yyPeek() const {
3523 assert(m_ptr <= m_end_of_query);
3524 return m_ptr[0];
3525 }
3526
3527 /**
3528 Look ahead at some character to parse.
3529 @param n offset of the character to look up
3530 */
3531 unsigned char yyPeekn(int n) const {
3532 assert(m_ptr + n <= m_end_of_query);
3533 return m_ptr[n];
3534 }
3535
3536 /**
3537 Cancel the effect of the last yyGet() or yySkip().
3538 Note that the echo mode should not change between calls to yyGet / yySkip
3539 and yyUnget. The caller is responsible for ensuring that.
3540 */
3541 void yyUnget() {
3542 m_ptr--;
3543 if (m_echo) m_cpp_ptr--;
3544 }
3546 /**
3547 Accept a character, by advancing the input stream.
3548 */
3549 void yySkip() {
3550 assert(m_ptr <= m_end_of_query);
3551 if (m_echo)
3552 *m_cpp_ptr++ = *m_ptr++;
3553 else
3554 m_ptr++;
3555 }
3556
3557 /**
3558 Accept multiple characters at once.
3559 @param n the number of characters to accept.
3560 */
3561 void yySkipn(int n) {
3562 assert(m_ptr + n <= m_end_of_query);
3563 if (m_echo) {
3564 memcpy(m_cpp_ptr, m_ptr, n);
3565 m_cpp_ptr += n;
3566 }
3567 m_ptr += n;
3568 }
3569
3570 /**
3571 Puts a character back into the stream, canceling
3572 the effect of the last yyGet() or yySkip().
3573 Note that the echo mode should not change between calls
3574 to unput, get, or skip from the stream.
3575 */
3576 char *yyUnput(char ch) {
3577 *--m_ptr = ch;
3578 if (m_echo) m_cpp_ptr--;
3579 return m_ptr;
3580 }
3581
3582 /**
3583 Inject a character into the pre-processed stream.
3584
3585 Note, this function is used to inject a space instead of multi-character
3586 C-comment. Thus there is no boundary checks here (basically, we replace
3587 N-chars by 1-char here).
3588 */
3589 char *cpp_inject(char ch) {
3590 *m_cpp_ptr = ch;
3591 return ++m_cpp_ptr;
3592 }
3593
3594 /**
3595 End of file indicator for the query text to parse.
3596 @return true if there are no more characters to parse
3597 */
3598 bool eof() const { return (m_ptr >= m_end_of_query); }
3599
3600 /**
3601 End of file indicator for the query text to parse.
3602 @param n number of characters expected
3603 @return true if there are less than n characters to parse
3605 bool eof(int n) const { return ((m_ptr + n) >= m_end_of_query); }
3606
3607 /** Get the raw query buffer. */
3608 const char *get_buf() const { return m_buf; }
3609
3610 /** Get the pre-processed query buffer. */
3611 const char *get_cpp_buf() const { return m_cpp_buf; }
3612
3613 /** Get the end of the raw query buffer. */
3614 const char *get_end_of_query() const { return m_end_of_query; }
3615
3616 /** Mark the stream position as the start of a new token. */
3617 void start_token() {
3619 m_tok_end = m_ptr;
3620
3623 }
3624
3625 /**
3626 Adjust the starting position of the current token.
3627 This is used to compensate for starting whitespace.
3628 */
3629 void restart_token() {
3632 }
3633
3634 /** Get the token start position, in the raw buffer. */
3635 const char *get_tok_start() const { return m_tok_start; }
3636
3637 /** Get the token start position, in the pre-processed buffer. */
3638 const char *get_cpp_tok_start() const { return m_cpp_tok_start; }
3639
3640 /** Get the token end position, in the raw buffer. */
3641 const char *get_tok_end() const { return m_tok_end; }
3642
3643 /** Get the token end position, in the pre-processed buffer. */
3644 const char *get_cpp_tok_end() const { return m_cpp_tok_end; }
3645
3646 /** Get the current stream pointer, in the raw buffer. */
3647 const char *get_ptr() const { return m_ptr; }
3648
3649 /** Get the current stream pointer, in the pre-processed buffer. */
3650 const char *get_cpp_ptr() const { return m_cpp_ptr; }
3651
3652 /** Get the length of the current token, in the raw buffer. */
3653 uint yyLength() const {
3654 /*
3655 The assumption is that the lexical analyser is always 1 character ahead,
3656 which the -1 account for.
3657 */
3658 assert(m_ptr > m_tok_start);
3659 return (uint)((m_ptr - m_tok_start) - 1);
3660 }
3661
3662 /** Get the utf8-body string. */
3663 const char *get_body_utf8_str() const { return m_body_utf8; }
3664
3665 /** Get the utf8-body length. */
3670 void body_utf8_start(THD *thd, const char *begin_ptr);
3671 void body_utf8_append(const char *ptr);
3672 void body_utf8_append(const char *ptr, const char *end_ptr);
3674 const CHARSET_INFO *txt_cs,
3675 const char *end_ptr);
3676
3677 uint get_lineno(const char *raw_ptr) const;
3678
3679 /** Current thread. */
3680 THD *m_thd;
3681
3682 /** Current line number. */
3683 uint yylineno;
3684
3685 /** Length of the last token parsed. */
3686 uint yytoklen;
3687
3688 /** Interface with bison, value of the last token parsed. */
3690
3691 /**
3692 LALR(2) resolution, look ahead token.
3693 Value of the next token to return, if any,
3694 or -1, if no token was parsed in advance.
3695 Note: 0 is a legal token, and represents YYEOF.
3696 */
3697 int lookahead_token;
3698
3699 /** LALR(2) resolution, value of the look ahead token.*/
3701
3702 /// Skip adding of the current token's digest since it is already added
3703 ///
3704 /// Usually we calculate a digest token by token at the top-level function
3705 /// of the lexer: MYSQLlex(). However, some complex ("hintable") tokens break
3706 /// that data flow: for example, the `SELECT /*+ HINT(t) */` is the single
3707 /// token from the main parser's point of view, and we add the "SELECT"
3708 /// keyword to the digest buffer right after the lex_one_token() call,
3709 /// but the "/*+ HINT(t) */" is a sequence of separate tokens from the hint
3710 /// parser's point of view, and we add those tokens to the digest buffer
3711 /// *inside* the lex_one_token() call. Thus, the usual data flow adds
3712 /// tokens from the "/*+ HINT(t) */" string first, and only than it appends
3713 /// the "SELECT" keyword token to that stream: "/*+ HINT(t) */ SELECT".
3714 /// This is not acceptable, since we use the digest buffer to restore
3715 /// query strings in their normalized forms, so the order of added tokens is
3716 /// important. Thus, we add tokens of "hintable" keywords to a digest buffer
3717 /// right in the hint parser and skip adding of them at the caller with the
3718 /// help of skip_digest flag.
3720
3721 void add_digest_token(uint token, Lexer_yystype *yylval);
3722
3723 void reduce_digest_token(uint token_left, uint token_right);
3724
3725 /**
3726 True if this scanner tokenizes a partial query (partition expression,
3727 generated column expression etc.)
3728
3729 @return true if parsing a partial query, otherwise false.
3730 */
3731 bool is_partial_parser() const { return grammar_selector_token >= 0; }
3732
3733 /**
3734 Outputs warnings on deprecated charsets in complete SQL statements
3736 @param [in] cs The character set/collation to check for a deprecation.
3737 @param [in] alias The name/alias of @p cs.
3738 */
3740 const char *alias) const {
3741 if (!is_partial_parser()) {
3743 }
3744 }
3745
3746 /**
3747 Outputs warnings on deprecated collations in complete SQL statements
3748
3749 @param [in] collation The collation to check for a deprecation.
3750 */
3752 if (!is_partial_parser()) {
3754 }
3755 }
3756
3758
3759 private:
3760 /** Pointer to the current position in the raw input stream. */
3761 char *m_ptr;
3762
3763 /** Starting position of the last token parsed, in the raw buffer. */
3764 const char *m_tok_start;
3765
3766 /** Ending position of the previous token parsed, in the raw buffer. */
3767 const char *m_tok_end;
3768
3769 /** End of the query text in the input stream, in the raw buffer. */
3770 const char *m_end_of_query;
3771
3772 /** Beginning of the query text in the input stream, in the raw buffer. */
3773 const char *m_buf;
3774
3775 /** Length of the raw buffer. */
3776 size_t m_buf_length;
3777
3778 /** Echo the parsed stream to the pre-processed buffer. */
3779 bool m_echo;
3780 bool m_echo_saved;
3781
3782 /** Pre-processed buffer. */
3783 char *m_cpp_buf;
3784
3785 /** Pointer to the current position in the pre-processed input stream. */
3786 char *m_cpp_ptr;
3787
3788 /**
3789 Starting position of the last token parsed,
3790 in the pre-processed buffer.
3791 */
3792 const char *m_cpp_tok_start;
3793
3794 /**
3795 Ending position of the previous token parsed,
3796 in the pre-processed buffer.
3797 */
3798 const char *m_cpp_tok_end;
3799
3800 /** UTF8-body buffer created during parsing. */
3801 char *m_body_utf8;
3802
3803 /** Pointer to the current position in the UTF8-body buffer. */
3804 char *m_body_utf8_ptr;
3805
3806 /**
3807 Position in the pre-processed buffer. The query from m_cpp_buf to
3808 m_cpp_utf_processed_ptr is converted to UTF8-body.
3809 */
3810 const char *m_cpp_utf8_processed_ptr;
3811
3812 public:
3813 /** Current state of the lexical analyser. */
3815
3816 /**
3817 Position of ';' in the stream, to delimit multiple queries.
3818 This delimiter is in the raw buffer.
3819 */
3820 const char *found_semicolon;
3821
3822 /** Token character bitmaps, to detect 7bit strings. */
3824
3825 /** SQL_MODE = IGNORE_SPACE. */
3826 bool ignore_space;
3827
3828 /**
3829 true if we're parsing a prepared statement: in this mode
3830 we should allow placeholders.
3831 */
3832 bool stmt_prepare_mode;
3833 /**
3834 true if we should allow multi-statements.
3835 */
3836 bool multi_statements;
3837
3838 /** State of the lexical analyser for comments. */
3841
3842 /**
3843 Starting position of the TEXT_STRING or IDENT in the pre-processed
3844 buffer.
3845
3846 NOTE: this member must be used within MYSQLlex() function only.
3847 */
3848 const char *m_cpp_text_start;
3849
3850 /**
3851 Ending position of the TEXT_STRING or IDENT in the pre-processed
3852 buffer.
3853
3854 NOTE: this member must be used within MYSQLlex() function only.
3855 */
3856 const char *m_cpp_text_end;
3857
3858 /**
3859 Character set specified by the character-set-introducer.
3860
3861 NOTE: this member must be used within MYSQLlex() function only.
3862 */
3864
3865 /**
3866 Current statement digest instrumentation.
3867 */
3869
3870 /**
3871 The synthetic 1st token to prepend token stream with.
3872
3873 This token value tricks parser to simulate multiple %start-ing points.
3874 Currently the grammar is aware of 4 such synthetic tokens:
3875 1. GRAMMAR_SELECTOR_PART for partitioning stuff from DD,
3876 2. GRAMMAR_SELECTOR_GCOL for generated column stuff from DD,
3877 3. GRAMMAR_SELECTOR_EXPR for generic single expressions from DD/.frm.
3878 4. GRAMMAR_SELECTOR_CTE for generic subquery expressions from CTEs.
3879 5. -1 when parsing with the main grammar (no grammar selector available).
3880
3881 @note yylex() is expected to return the value of type int:
3882 0 is for EOF and everything else for real token numbers.
3883 Bison, in its turn, generates positive token numbers.
3884 So, the negative grammar_selector_token means "not a token".
3885 In other words, -1 is "empty value".
3886 */
3887 const int grammar_selector_token;
3889 bool text_string_is_7bit() const { return !(tok_bitmap & 0x80); }
3893 public:
3894 String column;
3896 LEX_COLUMN(const String &x, const Access_bitmask &y) : column(x), rights(y) {}
3897};
3898
3899enum class role_enum;
3901/*
3902 This structure holds information about grantor's context
3903*/
3904class LEX_GRANT_AS {
3905 public:
3907 void cleanup();
3909 public:
3910 bool grant_as_used;
3912 LEX_USER *user;
3914};
3915
3916/*
3917 Some queries can be executed only using the secondary engine. The enum
3918 "execute_only_in_secondary_reasons" retains the explanations for queries that
3919 cannot be executed using the primary engine.
3923 CUBE,
3928};
3929
3931 Some queries can be executed only in using the hypergraph optimizer. The enum
3932 "execute_only_in_hypergraph_reasons" retains the explanations for the same.
3937};
3938
3939/**
3940 The LEX object currently serves three different purposes:
3941
3942 - It contains some universal properties of an SQL command, such as
3943 sql_command, presence of IGNORE in data change statement syntax, and list
3944 of tables (query_tables).
3945
3946 - It contains some execution state variables, like m_exec_started
3947 (set to true when execution is started), plugins (list of plugins used
3948 by statement), insert_update_values_map (a map of objects used by certain
3949 INSERT statements), etc.
3950
3951 - It contains a number of members that should be local to subclasses of
3952 Sql_cmd, like purge_value_list (for the PURGE command), kill_value_list
3953 (for the KILL command).
3954
3955 The LEX object is strictly a part of class Sql_cmd, for those SQL commands
3956 that are represented by an Sql_cmd class. For the remaining SQL commands,
3957 it is a standalone object linked to the current THD.
3958
3959 The lifecycle of a LEX object is as follows:
3960
3961 - The LEX object is constructed either on the execution mem_root
3962 (for regular statements), on a Prepared_statement mem_root (for
3963 prepared statements), on an SP mem_root (for stored procedure instructions),
3964 or created on the current mem_root for short-lived uses.
3965
3966 - Call lex_start() to initialize a LEX object before use.
3967 This initializes the execution state part of the object.
3968 It also calls LEX::reset() to ensure that all members are properly inited.
3969
3970 - Parse and resolve the statement, using the LEX as a work area.
3971
3972 - Execute an SQL command: call set_exec_started() when starting to execute
3973 (actually when starting to optimize).
3974 Typically call is_exec_started() to distinguish between preparation
3975 and optimization/execution stages of SQL command execution.
3976
3977 - Call clear_execution() when execution is finished. This will clear all
3978 execution state associated with the SQL command, it also includes calling
3979 LEX::reset_exec_started().
3980
3981 @todo - Create subclasses of Sql_cmd to contain data that are local
3982 to specific commands.
3983
3984 @todo - Create a Statement context object that will hold the execution state
3985 part of struct LEX.
3986
3987 @todo - Ensure that a LEX struct is never reused, thus making e.g
3988 LEX::reset() redundant.
3989*/
3991struct LEX : public Query_tables_list {
3992 friend bool lex_start(THD *thd);
3994 Query_expression *unit; ///< Outer-most query expression
3995 /// @todo: query_block can be replaced with unit->first-select()
3996 Query_block *query_block; ///< First query block
3997 Query_block *all_query_blocks_list; ///< List of all query blocks
3998 private:
3999 /* current Query_block in parsing */
4001
4003 Some queries can only be executed on a secondary engine, for example,
4004 queries with non-primitive grouping like CUBE.
4005 */
4007
4010
4012 Some queries can only be executed in hypergraph optimizer, for example,
4013 queries with QUALIFY clause.
4014 */
4019 bool m_splitting_window_expression = false;
4020
4021 public:
4022 inline Query_block *current_query_block() const {
4023 return m_current_query_block;
4024 }
4025
4026 /*
4027 We want to keep current_thd out of header files, so the debug assert
4028 is moved to the .cc file.
4029 */
4031 inline void set_current_query_block(Query_block *select) {
4032#ifndef NDEBUG
4034#endif
4036 }
4037 /// @return true if this is an EXPLAIN statement
4038 bool is_explain() const { return explain_format != nullptr; }
4039 bool is_explain_analyze = false;
4040
4041 /**
4042 Whether the currently-running statement should be prepared and executed
4043 with the hypergraph optimizer. This will not change after the statement is
4044 prepared, so you can use it in any optimization phase to e.g. figure out
4045 whether to inhibit some transformation that the hypergraph optimizer
4046 does not properly understand yet. If a different optimizer is requested,
4047 the statement must be re-prepared with the proper optimizer settings.
4048 */
4051 }
4052
4053 void set_using_hypergraph_optimizer(bool use_hypergraph) {
4055 }
4057 /// RAII class to set state \c m_splitting_window_expression for a scope
4059 private:
4060 LEX *m_lex{nullptr};
4061
4062 public:
4063 explicit Splitting_window_expression(LEX *lex, bool v) {
4064 m_lex = lex;
4066 }
4069 }
4070 };
4071
4074 }
4075
4076 void set_splitting_window_expression(bool v) {
4078 }
4079
4080 private:
4083 public:
4086 char *to_log; /* For PURGE BINARY LOGS TO */
4088 // Widcard from SHOW ... LIKE <wildcard> statements.
4092 nullptr, 0}; ///< Argument of the BINLOG event statement.
4099 THD *thd;
4100
4101 /* Optimizer hints */
4104 /* maintain a list of used plugins for this LEX */
4109 /// Table being inserted into (may be a view)
4111 /// Leaf table being inserted into (always a base table)
4113
4114 /** SELECT of CREATE VIEW statement */
4116
4117 /* Partition info structure filled in by PARTITION BY parse part */
4119
4121 The definer of the object being created (view, trigger, stored routine).
4122 I.e. the value of DEFINER clause.
4132
4133 // PURGE statement-specific fields:
4135
4136 // KILL statement-specific fields:
4138
4139 // other stuff:
4141 List<Item_func_set_user_var> set_var_list; // in-query assignment list
4142 /**
4143 List of placeholders ('?') for parameters of a prepared statement. Because
4144 we append to this list during parsing, it is naturally sorted by
4145 position of the '?' in the query string. The code which fills placeholders
4146 with user-supplied values, and the code which writes a query for
4147 statement-based logging, rely on this order.
4148 This list contains only real placeholders, not the clones which originate
4149 in a re-parsed CTE definition.
4150 */
4152
4154
4155 void insert_values_map(Item_field *f1, Field *f2) {
4157 insert_update_values_map = new std::map<Item_field *, Field *>;
4158 insert_update_values_map->insert(std::make_pair(f1, f2));
4159 }
4160 void destroy_values_map() {
4162 insert_update_values_map->clear();
4164 insert_update_values_map = nullptr;
4165 }
4166 }
4167 void clear_values_map() {
4170 }
4171 }
4172
4174 return result != nullptr && result->export_result_to_object_storage();
4175 }
4176
4177 bool has_values_map() const { return insert_update_values_map != nullptr; }
4178 std::map<Item_field *, Field *>::iterator begin_values_map() {
4179 return insert_update_values_map->begin();
4180 }
4181 std::map<Item_field *, Field *>::iterator end_values_map() {
4182 return insert_update_values_map->end();
4183 }
4184
4187 }
4188
4190 const bool execute_only_in_secondary_engine_param,
4193 execute_only_in_secondary_engine_param;
4197 }
4198
4202 }
4203
4207 case CUBE:
4208 return "CUBE";
4209 case TABLESAMPLE:
4210 return "TABLESAMPLE";
4212 return "OUTFILE to object store";
4214 return "Secondary engine temporary table creation";
4216 return "Secondary engine temporary table within this statement";
4217 default:
4218 return "UNDEFINED";
4219 }
4223 }
4225 bool execute_in_hypergraph_optimizer_param,
4228 execute_in_hypergraph_optimizer_param;
4230 }
4231
4235 ? "QUALIFY clause"
4236 : "UNDEFINED";
4237 }
4238
4240 const {
4242 }
4243
4244 private:
4245 /*
4246 With Visual Studio, an std::map will always allocate two small objects
4247 on the heap. Sometimes we put LEX objects in a MEM_ROOT, and never run
4248 the LEX DTOR. To avoid memory leaks, put this std::map on the heap,
4249 and call clear_values_map() at the end of each statement.
4250 */
4251 std::map<Item_field *, Field *> *insert_update_values_map;
4252
4253 public:
4254 /*
4255 A stack of name resolution contexts for the query. This stack is used
4256 at parse time to set local name resolution contexts for various parts
4257 of a query. For example, in a JOIN ... ON (some_condition) clause the
4258 Items in 'some_condition' must be resolved only against the operands
4259 of the the join, and not against the whole clause. Similarly, Items in
4260 subqueries should be resolved against the subqueries (and outer queries).
4261 The stack is used in the following way: when the parser detects that
4262 all Items in some clause need a local context, it creates a new context
4263 and pushes it on the stack. All newly created Items always store the
4264 top-most context in the stack. Once the parser leaves the clause that
4265 required a local context, the parser pops the top-most context.
4271 HA_CHECK_OPT check_opt; // check/repair options
4274 LEX_SOURCE_INFO mi; // used by CHANGE REPLICATION SOURCE
4279 ulong type;
4280 /**
4281 This field is used as a work field during resolving to validate
4282 the use of aggregate functions. For example in a query
4283 SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
4284 MIN(i) in the WHERE clause is not allowed since only non-aggregated data
4285 is present, whereas MIN(i) in the HAVING clause is allowed because HAVING
4286 operates on the output of a grouping operation.
4287 Each query block is assigned a nesting level. This field is a bit field
4288 that contains the value one in the position of that nesting level if
4289 aggregate functions are allowed for that query block.
4290 */
4292 /**
4293 Windowing functions are not allowed in HAVING - in contrast to grouped
4294 aggregate functions, since windowing in SQL logically follows after all
4295 grouping operations. Nor are they allowed inside grouped aggregate
4296 function arguments. One bit per query block, as also \c allow_sum_func. For
4297 ORDER BY and QUALIFY predicates, window functions \em are allowed unless
4298 they are contained in arguments of a grouped aggregate function. Nor are
4299 references to outer window functions (via alias) allowed in subqueries, but
4300 that is checked separately.
4301 */
4304 /// If true: during prepare, we did a subquery transformation (IN-to-EXISTS,
4305 /// SOME/ANY) that doesn't currently work for subquery to a derived table
4306 /// transformation.
4308
4310
4311 /*
4312 Usually `expr` rule of yacc is quite reused but some commands better
4313 not support subqueries which comes standard with this rule, like
4314 KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
4315 syntax error back.
4316 */
4317 bool expr_allows_subquery{true};
4318 /**
4319 If currently re-parsing a CTE's definition, this is the offset in bytes
4320 of that definition in the original statement which had the WITH
4321 clause. Otherwise this is 0.
4322 */
4324 /**
4325 If currently re-parsing a condition which is pushed down to a derived
4326 table, this will be set to true.
4327 */
4329 /**
4330 If currently re-parsing a condition that is being pushed down to a
4331 derived table, this has the positions of all the parameters that are
4332 part of that condition in the original statement. Otherwise it is empty.
4336 enum SSL_type ssl_type; /* defined in violite.h */
4342 /// QUERY ID for SHOW PROFILE
4344 uint profile_options;
4345 uint grant, grant_tot_col;
4346 /**
4347 Set to true when GRANT ... GRANT OPTION ... TO ...
4348 is used (vs. GRANT ... WITH GRANT OPTION).
4349 The flag is used by @ref mysql_grant to grant GRANT OPTION (@ref GRANT_ACL)
4350 to all dynamic privileges.
4354 int select_number; ///< Number of query block (by EXPLAIN)
4357 /**
4358 @todo ensure that correct CONTEXT_ANALYSIS_ONLY is set for all preparation
4359 code, so we can fully rely on this field.
4360 */
4362 bool drop_if_exists;
4363 /**
4364 refers to optional IF EXISTS clause in REVOKE sql. This flag when set to
4365 true will report warnings in case privilege being granted is not granted to
4366 given user/role. When set to false error is reported.
4367 */
4368 bool grant_if_exists;
4369 /**
4370 refers to optional IGNORE UNKNOWN USER clause in REVOKE sql. This flag when
4371 set to true will report warnings in case target user/role for which
4372 privilege being granted does not exists. When set to false error is
4373 reported.
4377 bool autocommit;
4379 // For show commands to show hidden columns and indexes.
4380 bool m_extended_show;
4381
4382 enum enum_yes_no_unknown tx_chain, tx_release;
4383
4384 /**
4385 Whether this query will return the same answer every time, given unchanged
4386 data. Used to be for the query cache, but is now used to find out if an
4387 expression is usable for partitioning.
4388 */
4391 private:
4392 /// True if statement references UDF functions
4393 bool m_has_udf{false};
4394 bool ignore;
4395 /// True if query has at least one external table
4398 public:
4399 bool is_ignore() const { return ignore; }
4400 void set_ignore(bool ignore_param) { ignore = ignore_param; }
4401 void set_has_udf() { m_has_udf = true; }
4402 bool has_udf() const { return m_has_udf; }
4408 /* Prepared statements SQL syntax:*/
4409 LEX_CSTRING prepared_stmt_name; /* Statement name (in all queries) */
4411 Prepared statement query text or name of variable that holds the
4412 prepared statement (in PREPARE ... queries)
4413 */
4415 /* If true, prepared_stmt_code is a name of variable that holds the query */
4417 /* Names of user variables holding parameters (in EXECUTE) */
4421 bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */
4422 bool all_privileges;
4426
4427 private:
4428 bool m_broken; ///< see mark_broken()
4429 /**
4430 Set to true when execution has started (after parsing, tables opened and
4431 query preparation is complete. Used to track arena state for SPs).
4432 */
4433 bool m_exec_started;
4434 /**
4435 Set to true when execution is completed, ie optimization has been done
4436 and execution is successful or ended in error.
4437 */
4439 /**
4440 Set to true when execution crosses global_connection_memory_status_limit.
4441 */
4443 /**
4444 Set to true when execution crosses connection_memory_status_limit.
4445 */
4447 /**
4448 Current SP parsing context.
4449 @see also sp_head::m_root_parsing_ctx.
4450 */
4453 /**
4454 Statement context for Query_block::make_active_options.
4455 */
4457
4458 public:
4459 /**
4460 Gets the options that have been set for this statement. The options are
4461 propagated to the Query_block objects and should usually be read with
4462 #Query_block::active_options().
4463
4464 @return a bit set of options set for this statement
4465 */
4467 /**
4468 Add options to values of m_statement_options. options is an ORed
4469 bit set of options defined in query_options.h
4471 @param options Add this set of options to the set already in
4472 m_statement_options
4476 }
4477 bool is_broken() const { return m_broken; }
4478 /**
4479 Certain permanent transformations (like in2exists), if they fail, may
4480 leave the LEX in an inconsistent state. They should call the
4481 following function, so that this LEX is not reused by another execution.
4483 @todo If lex_start () were a member function of LEX, the "broken"
4484 argument could always be "true" and thus could be removed.
4485 */
4486 void mark_broken(bool broken = true) {
4487 if (broken) {
4488 /*
4489 "OPEN <cursor>" cannot be re-prepared if the cursor uses no tables
4490 ("SELECT FROM DUAL"). Indeed in that case cursor_query is left empty
4491 in constructions of sp_instr_cpush, and thus
4492 sp_lex_instr::parse_expr() cannot re-prepare. So we mark the statement
4493 as broken only if tables are used.
4494 */
4495 if (is_metadata_used()) m_broken = true;
4496 } else
4497 m_broken = false;
4499
4501
4502 void cleanup(bool full) {
4503 unit->cleanup(full);
4504 if (full) {
4509
4510 bool is_exec_started() const { return m_exec_started; }
4511 void set_exec_started() { m_exec_started = true; }
4512 void reset_exec_started() {
4513 m_exec_started = false;
4514 m_exec_completed = false;
4515 }
4516 /**
4517 Check whether the statement has been executed (regardless of completion -
4518 successful or in error).
4519 Check this instead of Query_expression::is_executed() to determine
4520 the state of a complete statement.
4522 bool is_exec_completed() const { return m_exec_completed; }
4523 void set_exec_completed() { m_exec_completed = true; }
4536 }
4540 }
4542
4546
4547 /// Check if the current statement uses meta-data (uses a table or a stored
4548 /// routine).
4549 bool is_metadata_used() const {
4550 return query_tables != nullptr || has_udf() ||
4551 (sroutines != nullptr && !sroutines->empty());
4552 }
4553
4554 /// We have detected the presence of an alias of a window function with a
4555 /// window on query block qb. Check if the reference is illegal at this point
4556 /// during resolution.
4557 /// @param qb The query block of the window function
4558 /// @return true if window function is referenced from another query block
4559 /// than its window, or if window functions are disallowed at the current
4560 /// point during prepare, cf. also documentation of \c m_deny_window_func.
4561 bool deny_window_function(Query_block *qb) const {
4562 return qb != current_query_block() ||
4563 ((~allow_sum_func | m_deny_window_func) >>
4565 0x1;
4566 }
4568 public:
4570
4571 bool only_view; /* used for SHOW CREATE TABLE/VIEW */
4572 /*
4573 view created to be run from definer (standard behaviour)
4574 */
4576
4577 /**
4578 Intended to point to the next word after DEFINER-clause in the
4579 following statements:
4580
4581 - CREATE TRIGGER (points to "TRIGGER");
4582 - CREATE PROCEDURE (points to "PROCEDURE");
4583 - CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE");
4584 - CREATE EVENT (points to "EVENT")
4586 This pointer is required to add possibly omitted DEFINER-clause to the
4587 DDL-statement before dumping it to the binlog.
4588 */
4589 const char *stmt_definition_begin;
4590 const char *stmt_definition_end;
4591
4592 /**
4593 During name resolution search only in the table list given by
4594 Name_resolution_context::first_name_resolution_table and
4595 Name_resolution_context::last_name_resolution_table
4596 (see Item_field::fix_fields()).
4597 */
4599
4600 bool is_lex_started; /* If lex_start() did run. For debugging. */
4601 /// Set to true while resolving values in ON DUPLICATE KEY UPDATE clause
4604 class Explain_format *explain_format{nullptr};
4605
4606 // Maximum execution time for a statement.
4607 ulong max_execution_time;
4608
4610 To flag the current statement as dependent for binary logging
4611 on explicit_defaults_for_timestamp
4612 */
4614
4615 /**
4616 Used to inform the parser whether it should contextualize the parse
4617 tree. When we get a pure parser this will not be needed.
4618 */
4619 bool will_contextualize;
4620
4621 LEX();
4623 virtual ~LEX();
4624
4625 /// Destroy contained objects, but not the LEX object itself.
4626 void destroy() {
4627 if (unit == nullptr) return;
4628 unit->destroy();
4629 unit = nullptr;
4630 query_block = nullptr;
4631 all_query_blocks_list = nullptr;
4632 m_current_query_block = nullptr;
4633 explain_format = nullptr;
4635 }
4636
4637 /// Reset query context to initial state
4638 void reset();
4639
4640 /// Create an empty query block within this LEX object.
4642
4643 /// Create query expression object that contains one query block.
4644 Query_block *new_query(Query_block *curr_query_block);
4645
4646 /// Create query block and attach it to the current query expression.
4648
4649 /// Create top-level query expression and query block.
4650 bool new_top_level_query();
4651
4652 /// Create query expression and query block in existing memory objects.
4653 void new_static_query(Query_expression *sel_query_expression,
4654 Query_block *select);
4655
4656 /// Create query expression under current_query_block and a query block under
4657 /// the new query expression. The new query expression is linked in under
4658 /// current_query_block. The new query block is linked in under the new
4659 /// query expression.
4660 ///
4661 /// @param thd current session context
4662 /// @param current_query_block the root under which we create the new
4663 /// expression
4664 /// and block
4665 /// @param where_clause any where clause for the block
4666 /// @param having_clause any having clause for the block
4667 /// @param ctx the parsing context
4668 ///
4669 /// @returns the new query expression, or nullptr on error.
4671 THD *thd, Query_block *current_query_block, Item *where_clause,
4672 Item *having_clause, enum_parsing_context ctx);
4673
4674 inline bool is_ps_or_view_context_analysis() {
4677 }
4678
4679 inline bool is_view_context_analysis() {
4681 }
4682
4683 void clear_execution();
4684
4685 /**
4686 Set the current query as uncacheable.
4687
4688 @param curr_query_block Current select query block
4689 @param cause Why this query is uncacheable.
4690
4691 @details
4692 All query blocks representing subqueries, from the current one up to
4693 the outer-most one, but excluding the main query block, are also set
4694 as uncacheable.
4695 */
4696 void set_uncacheable(Query_block *curr_query_block, uint8 cause) {
4697 safe_to_cache_query = false;
4698
4699 if (m_current_query_block == nullptr) return;
4700 Query_block *sl;
4701 Query_expression *un;
4702 for (sl = curr_query_block, un = sl->master_query_expression(); un != unit;
4703 sl = sl->outer_query_block(), un = sl->master_query_expression()) {
4704 sl->uncacheable |= cause;
4705 un->uncacheable |= cause;
4706 }
4707 }
4709
4710 Table_ref *unlink_first_table(bool *link_to_local);
4711 void link_first_table_back(Table_ref *first, bool link_to_local);
4713
4715
4717 for (Table_ref *tr = insert_table->first_leaf_table(); tr != nullptr;
4718 tr = tr->next_leaf)
4719 tr->restore_properties();
4720 }
4721
4723
4724 bool can_use_merged();
4725 bool can_not_use_merged();
4726 bool need_correct_ident();
4727 /*
4728 Is this update command where 'WHITH CHECK OPTION' clause is important
4729
4730 SYNOPSIS
4731 LEX::which_check_option_applicable()
4732
4733 RETURN
4734 true have to take 'WHITH CHECK OPTION' clause into account
4735 false 'WHITH CHECK OPTION' clause do not need
4736 */
4737 inline bool which_check_option_applicable() {
4738 switch (sql_command) {
4739 case SQLCOM_UPDATE:
4741 case SQLCOM_INSERT:
4743 case SQLCOM_REPLACE:
4745 case SQLCOM_LOAD:
4746 return true;
4747 default:
4748 return false;
4749 }
4751
4753
4755 return context_stack.push_front(context);
4756 }
4757
4758 void pop_context() { context_stack.pop(); }
4759
4760 bool copy_db_to(char const **p_db, size_t *p_db_length) const;
4761
4762 bool copy_db_to(char **p_db, size_t *p_db_length) const {
4763 return copy_db_to(const_cast<const char **>(p_db), p_db_length);
4764 }
4765
4767
4770
4771 bool table_or_sp_used();
4772
4773 /**
4774 @brief check if the statement is a single-level join
4775 @return result of the check
4776 @retval true The statement doesn't contain subqueries, unions and
4777 stored procedure calls.
4778 @retval false There are subqueries, UNIONs or stored procedure calls.
4779 */
4780 bool is_single_level_stmt() {
4781 /*
4782 This check exploits the fact that the last added to all_select_list is
4783 on its top. So query_block (as the first added) will be at the tail
4784 of the list.
4785 */
4787 (sroutines == nullptr || sroutines->empty())) {
4789 return true;
4790 }
4791 return false;
4792 }
4793
4794 void release_plugins();
4795
4796 /**
4797 IS schema queries read some dynamic table statistics from SE.
4798 These statistics are cached, to avoid opening of table more
4799 than once while preparing a single output record buffer.
4800 */
4803
4804 bool accept(Select_lex_visitor *visitor);
4805
4806 bool set_wild(LEX_STRING);
4807 void clear_privileges();
4808
4809 bool make_sql_cmd(Parse_tree_root *parse_tree);
4810
4811 private:
4812 /**
4813 Context object used by secondary storage engines to store query
4814 state during optimization and execution.
4815 */
4817
4818 public:
4819 /**
4820 Gets the secondary engine execution context for this statement.
4821 */
4823 const {
4825 }
4826
4827 /**
4828 Sets the secondary engine execution context for this statement.
4829 The old context object is destroyed, if there is one. Can be set
4830 to nullptr to destroy the old context object and clear the
4831 pointer.
4832
4833 The supplied context object should be allocated on the execution
4834 MEM_ROOT, so that its memory doesn't have to be manually freed
4835 after query execution.
4836 */
4839
4840 /**
4841 Validates if a query can run with the old optimizer.
4842 @return True if the query cannot be run with old optimizer, false otherwise.
4845
4846 private:
4848
4849 public:
4852 }
4853
4856 }
4859
4860 private:
4861 bool rewrite_required{false};
4863 public:
4864 void set_rewrite_required() { rewrite_required = true; }
4865 void reset_rewrite_required() { rewrite_required = false; }
4866 bool is_rewrite_required() { return rewrite_required; }
4867};
4868
4870 RAII class to ease the call of LEX::mark_broken() if error.
4871 Used during preparation and optimization of DML queries.
4872*/
4874 public:
4875 Prepare_error_tracker(THD *thd_arg) : thd(thd_arg) {}
4877
4878 private:
4879 THD *const thd;
4880};
4881
4882/**
4883 The internal state of the syntax parser.
4884 This object is only available during parsing,
4885 and is private to the syntax parser implementation (sql_yacc.yy).
4886*/
4887class Yacc_state {
4888 public:
4890 reset();
4891 }
4892
4893 void reset() {
4894 if (yacc_yyss != nullptr) {
4896 yacc_yyss = nullptr;
4897 }
4898 if (yacc_yyvs != nullptr) {
4900 yacc_yyvs = nullptr;
4901 }
4902 if (yacc_yyls != nullptr) {
4904 yacc_yyls = nullptr;
4905 }
4908 }
4909
4910 ~Yacc_state();
4911
4912 /**
4913 Reset part of the state which needs resetting before parsing
4914 substatement.
4915 */
4919 }
4920
4921 /**
4922 Bison internal state stack, yyss, when dynamically allocated using
4923 my_yyoverflow().
4924 */
4926
4927 /**
4928 Bison internal semantic value stack, yyvs, when dynamically allocated using
4929 my_yyoverflow().
4930 */
4932
4933 /**
4934 Bison internal location value stack, yyls, when dynamically allocated using
4935 my_yyoverflow().
4936 */
4938
4939 /**
4940 Type of lock to be used for tables being added to the statement's
4941 table list in table_factor, table_alias_ref, single_multi and
4942 table_wild_one rules.
4943 Statements which use these rules but require lock type different
4944 from one specified by this member have to override it by using
4945 Query_block::set_lock_for_tables() method.
4946
4947 The default value of this member is TL_READ_DEFAULT. The only two
4948 cases in which we change it are:
4949 - When parsing SELECT HIGH_PRIORITY.
4950 - Rule for DELETE. In which we use this member to pass information
4951 about type of lock from delete to single_multi part of rule.
4952
4953 We should try to avoid introducing new use cases as we would like
4954 to get rid of this member eventually.
4955 */
4957
4958 /**
4959 The type of requested metadata lock for tables added to
4960 the statement table list.
4961 */
4963
4964 /*
4965 TODO: move more attributes from the LEX structure here.
4966 */
4967};
4968
4969/**
4970 Input parameters to the parser.
4971*/
4972struct Parser_input {
4973 /**
4974 True if the text parsed corresponds to an actual query,
4975 and not another text artifact.
4976 This flag is used to disable digest parsing of nested:
4977 - view definitions
4978 - table trigger definitions
4979 - table partition definitions
4980 - event scheduler event definitions
4981 */
4982 bool m_has_digest;
4983 /**
4984 True if the caller needs to compute a digest.
4985 This flag is used to request explicitly a digest computation,
4986 independently of the performance schema configuration.
4987 */
4988 bool m_compute_digest;
4989
4990 Parser_input() : m_has_digest(false), m_compute_digest(false) {}
4991};
4992
4993/**
4994 Internal state of the parser.
4995 The complete state consist of:
4996 - input parameters that control the parser behavior
4997 - state data used during lexical parsing,
4998 - state data used during syntactic parsing.
4999*/
5000class Parser_state {
5001 protected:
5002 /**
5003 Constructor for special parsers of partial SQL clauses (DD)
5004
5005 @param grammar_selector_token See Lex_input_stream::grammar_selector_token
5006 */
5007 explicit Parser_state(int grammar_selector_token)
5008 : m_input(), m_lip(grammar_selector_token), m_yacc(), m_comment(false) {}
5009
5010 public:
5011 Parser_state() : m_input(), m_lip(~0U), m_yacc(), m_comment(false) {}
5012
5013 /**
5014 Object initializer. Must be called before usage.
5016 @retval false OK
5017 @retval true Error
5018 */
5019 bool init(THD *thd, const char *buff, size_t length) {
5020 return m_lip.init(thd, buff, length);
5021 }
5022
5023 void reset(const char *found_semicolon, size_t length) {
5024 m_lip.reset(found_semicolon, length);
5026 }
5028 /// Signal that the current query has a comment
5029 void add_comment() { m_comment = true; }
5030 /// Check whether the current query has a comment
5031 bool has_comment() const { return m_comment; }
5032
5033 public:
5037 /**
5038 Current performance digest instrumentation.
5039 */
5041
5042 private:
5043 bool m_comment; ///< True if current query contains comments
5044};
5046/**
5047 Parser state for partition expression parser (.frm/DD stuff)
5048*/
5050 public:
5052
5054};
5056/**
5057 Parser state for generated column expression parser (.frm/DD stuff)
5058*/
5060 public:
5062
5064};
5066/**
5067 Parser state for single expression parser (.frm/DD stuff)
5068*/
5070 public:
5072
5073 Item *result;
5074};
5076/**
5077 Parser state for CTE subquery parser
5078*/
5080 public:
5082
5084};
5085
5087 Parser state for Derived table's condition parser.
5088 (Used in condition pushdown to derived tables)
5089*/
5091 public:
5095};
5096
5097struct st_lex_local : public LEX {
5098 static void *operator new(size_t size) noexcept {
5099 return (*THR_MALLOC)->Alloc(size);
5100 }
5101 static void *operator new(size_t size, MEM_ROOT *mem_root,
5102 const std::nothrow_t &arg
5103 [[maybe_unused]] = std::nothrow) noexcept {
5104 return mem_root->Alloc(size);
5105 }
5106 static void operator delete(void *ptr [[maybe_unused]],
5107 size_t size [[maybe_unused]]) {
5108 TRASH(ptr, size);
5109 }
5110 static void operator delete(
5111 void *, MEM_ROOT *, const std::nothrow_t &) noexcept { /* Never called */
5112 }
5113};
5114
5115extern void lex_free(void);
5116extern bool lex_start(THD *thd);
5117extern void lex_end(LEX *lex);
5118extern int my_sql_parser_lex(MY_SQL_PARSER_STYPE *, POS *, class THD *);
5119
5120extern void trim_whitespace(const CHARSET_INFO *cs, LEX_STRING *str);
5121
5122extern bool is_lex_native_function(const LEX_STRING *name);
5124bool is_keyword(const char *name, size_t len);
5125bool db_is_default_db(const char *db, size_t db_len, const THD *thd);
5126
5128
5129void print_derived_column_names(const THD *thd, String *str,
5131
5132/**
5133 @} (End of group GROUP_PARSER)
5134*/
5135
5136/**
5137 Check if the given string is invalid using the system charset.
5138
5139 @param string_val Reference to the string.
5140 @param charset_info Pointer to charset info.
5141
5142 @return true if the string has an invalid encoding using
5143 the system charset else false.
5144*/
5145
5146inline bool is_invalid_string(const LEX_CSTRING &string_val,
5147 const CHARSET_INFO *charset_info) {
5148 size_t valid_len;
5149 bool len_error;
5150
5151 if (validate_string(charset_info, string_val.str, string_val.length,
5152 &valid_len, &len_error)) {
5153 char hexbuf[7];
5154 octet2hex(
5155 hexbuf, string_val.str + valid_len,
5156 static_cast<uint>(std::min<size_t>(string_val.length - valid_len, 3)));
5157 my_error(ER_INVALID_CHARACTER_STRING, MYF(0), charset_info->csname, hexbuf);
5158 return true;
5159 }
5160 return false;
5161}
5162
5163/**
5164 Check if the given string is invalid using the system charset.
5165
5166 @param string_val Reference to the string.
5167 @param charset_info Pointer to charset info.
5168 @param[out] invalid_sub_str If string has an invalid encoding then invalid
5169 string in printable ASCII format is stored.
5170
5171 @return true if the string has an invalid encoding using
5172 the system charset else false.
5173*/
5174
5175inline bool is_invalid_string(const LEX_CSTRING &string_val,
5177 std::string &invalid_sub_str) {
5178 size_t valid_len;
5179 bool len_error;
5180
5181 if (validate_string(charset_info, string_val.str, string_val.length,
5182 &valid_len, &len_error)) {
5183 char printable_buff[32];
5185 printable_buff, sizeof(printable_buff), string_val.str + valid_len,
5186 static_cast<uint>(std::min<size_t>(string_val.length - valid_len, 3)),
5187 charset_info, 3);
5188 invalid_sub_str = printable_buff;
5189 return true;
5190 }
5191 return false;
5192}
5193
5194/**
5195 In debug mode, verify that we're not adding an item twice to the fields list
5196 with inconsistent hidden flags. Must be called before adding the item to
5197 fields.
5198 */
5200 [[maybe_unused]],
5201 Item *item [[maybe_unused]],
5202 bool hidden [[maybe_unused]]) {
5203#ifndef NDEBUG
5204 if (std::find(fields.begin(), fields.end(), item) != fields.end()) {
5205 // The item is already in the list, so we can't add it
5206 // with a different value for hidden.
5207 assert(item->hidden == hidden);
5208 }
5209#endif
5210}
5211
5212bool walk_item(Item *item, Select_lex_visitor *visitor);
5214bool accept_table(Table_ref *t, Select_lex_visitor *visitor);
5216 Select_lex_visitor *visitor);
5217Table_ref *nest_join(THD *thd, Query_block *select, Table_ref *embedding,
5218 mem_root_deque<Table_ref *> *jlist, size_t table_cnt,
5219 const char *legend);
5221/// RAII class to automate saving/restoring of current_query_block()
5223 public:
5224 explicit Change_current_query_block(THD *thd_arg)
5225 : thd(thd_arg), saved_query_block(thd->lex->current_query_block()) {}
5228
5229 private:
5230 THD *thd;
5232};
5234void get_select_options_str(ulonglong options, std::string *str);
5235
5236template <typename T>
5237inline bool WalkQueryExpression(Query_expression *query_expr, enum_walk walk,
5238 T &&functor) {
5239 return query_expr->walk(&Item::walk_helper_thunk<T>, walk,
5240 reinterpret_cast<uchar *>(&functor));
5241}
5242
5243#endif /* SQL_LEX_INCLUDED */
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:566
uint32_t Access_bitmask
Definition: auth_acls.h:34
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:205
RAII class to automate saving/restoring of current_query_block()
Definition: sql_lex.h:5218
void restore()
Definition: sql_lex.h:5222
Query_block * saved_query_block
Definition: sql_lex.h:5227
THD * thd
Definition: sql_lex.h:5226
Change_current_query_block(THD *thd_arg)
Definition: sql_lex.h:5220
~Change_current_query_block()
Definition: sql_lex.h:5223
Parser state for CTE subquery parser.
Definition: sql_lex.h:5075
Common_table_expr_parser_state()
Definition: sql_lex.cc:1217
PT_subquery * result
Definition: sql_lex.h:5079
Utility RAII class to save/modify/restore the condition_context information of a query block.
Definition: sql_lex.h:2562
enum_condition_context saved_value
Definition: sql_lex.h:2584
~Condition_context()
Definition: sql_lex.h:2578
Query_block * select
Definition: sql_lex.h:2583
Condition_context(Query_block *select_ptr, enum_condition_context new_type=enum_condition_context::NEITHER)
Definition: sql_lex.h:2564
Parser state for Derived table's condition parser.
Definition: sql_lex.h:5086
Item * result
Definition: sql_lex.h:5090
Derived_expr_parser_state()
Definition: sql_lex.cc:1220
Definition: event_parse_data.h:43
Base class for structured and hierarchical EXPLAIN output formatters.
Definition: opt_explain_format.h:506
Parser state for single expression parser (.frm/DD stuff)
Definition: sql_lex.h:5065
Expression_parser_state()
Definition: sql_lex.cc:1214
Item * result
Definition: sql_lex.h:5069
Definition: field.h:573
Parser state for generated column expression parser (.frm/DD stuff)
Definition: sql_lex.h:5055
Value_generator * result
Definition: sql_lex.h:5059
Gcol_expr_parser_state()
Definition: sql_lex.cc:1211
Definition: sql_lex.h:501
LEX_CSTRING key_name
Definition: sql_lex.h:511
void print(const THD *thd, String *str)
Print an index hint.
Definition: sql_lex.cc:2754
index_clause_map clause
Definition: sql_lex.h:506
enum index_hint_type type
Definition: sql_lex.h:504
Index_hint(const char *str, uint length)
Definition: sql_lex.h:513
Definition: item_cmpfunc.h:2496
Definition: item_subselect.h:459
Definition: item.h:4389
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:1082
Definition: item_func.h:3489
Definition: item_func.h:3540
This class is used to implement operations like SET @variable or @variable:= expression.
Definition: item_func.h:3299
A wrapper Item that normally returns its parameter, but becomes NULL when processing rows for rollup.
Definition: item_func.h:1719
A wrapper Item that contains a number of aggregate items, one for each level of rollup (see Item_roll...
Definition: item_sum.h:2722
Base class that is common to all subqueries and subquery predicates.
Definition: item_subselect.h:80
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:399
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
cond_result
Definition: item.h:993
@ COND_UNDEF
Definition: item.h:993
Definition: sql_optimizer.h:133
Definition: key_spec.h:67
RAII class to set state m_splitting_window_expression for a scope.
Definition: sql_lex.h:4054
LEX * m_lex
Definition: sql_lex.h:4056
~Splitting_window_expression()
Definition: sql_lex.h:4063
Splitting_window_expression(LEX *lex, bool v)
Definition: sql_lex.h:4059
Definition: sql_lex.h:3888
LEX_COLUMN(const String &x, const Access_bitmask &y)
Definition: sql_lex.h:3892
String column
Definition: sql_lex.h:3890
Access_bitmask rights
Definition: sql_lex.h:3891
Definition: sql_lex.h:3900
List< LEX_USER > * role_list
Definition: sql_lex.h:3909
void cleanup()
Definition: sql_lex.cc:5250
bool grant_as_used
Definition: sql_lex.h:3906
role_enum role_type
Definition: sql_lex.h:3907
LEX_USER * user
Definition: sql_lex.h:3908
LEX_GRANT_AS()
Definition: sql_lex.cc:5257
This class represents the character input stream consumed during lexical analysis.
Definition: sql_lexer_input_stream.h:70
void restart_token()
Adjust the starting position of the current token.
Definition: sql_lexer_input_stream.h:250
void body_utf8_start(THD *thd, const char *begin_ptr)
The operation is called from the parser in order to 1) designate the intention to have utf8 body; 1) ...
Definition: sql_lexer.cc:154
const int grammar_selector_token
The synthetic 1st token to prepend token stream with.
Definition: sql_lexer_input_stream.h:508
void skip_binary(int n)
Skip binary from the input stream.
Definition: sql_lexer_input_stream.h:114
bool skip_digest
Skip adding of the current token's digest since it is already added.
Definition: sql_lexer_input_stream.h:340
const char * m_cpp_text_end
Ending position of the TEXT_STRING or IDENT in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:477
const char * get_end_of_query() const
Get the end of the raw query buffer.
Definition: sql_lexer_input_stream.h:235
sql_digest_state * m_digest
Current statement digest instrumentation.
Definition: sql_lexer_input_stream.h:489
const char * get_cpp_tok_start() const
Get the token start position, in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:259
void body_utf8_append(const char *ptr)
The operation appends unprocessed part of the pre-processed buffer till the given pointer (ptr) and s...
Definition: sql_lexer.cc:217
char * m_cpp_ptr
Pointer to the current position in the pre-processed input stream.
Definition: sql_lexer_input_stream.h:407
uchar tok_bitmap
Token character bitmaps, to detect 7bit strings.
Definition: sql_lexer_input_stream.h:444
void restore_in_comment_state()
Definition: sql_lexer_input_stream.h:105
THD * m_thd
Current thread.
Definition: sql_lexer_input_stream.h:301
const char * get_tok_start() const
Get the token start position, in the raw buffer.
Definition: sql_lexer_input_stream.h:256
const CHARSET_INFO * query_charset
Definition: sql_lexer_input_stream.h:378
const char * get_buf() const
Get the raw query buffer.
Definition: sql_lexer_input_stream.h:229
bool multi_statements
true if we should allow multi-statements.
Definition: sql_lexer_input_stream.h:457
char * yyUnput(char ch)
Puts a character back into the stream, canceling the effect of the last yyGet() or yySkip().
Definition: sql_lexer_input_stream.h:197
uint get_body_utf8_length() const
Get the utf8-body length.
Definition: sql_lexer_input_stream.h:287
bool m_echo_saved
Definition: sql_lexer_input_stream.h:401
const char * m_cpp_tok_end
Ending position of the previous token parsed, in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:419
char * cpp_inject(char ch)
Inject a character into the pre-processed stream.
Definition: sql_lexer_input_stream.h:210
const char * found_semicolon
Position of ';' in the stream, to delimit multiple queries.
Definition: sql_lexer_input_stream.h:441
void warn_on_deprecated_collation(const CHARSET_INFO *collation) const
Outputs warnings on deprecated collations in complete SQL statements.
Definition: sql_lexer_input_stream.h:372
Lexer_yystype * lookahead_yylval
LALR(2) resolution, value of the look ahead token.
Definition: sql_lexer_input_stream.h:321
bool init(THD *thd, const char *buff, size_t length)
Object initializer.
Definition: sql_lexer.cc:74
enum my_lex_states next_state
Current state of the lexical analyser.
Definition: sql_lexer_input_stream.h:435
const char * get_tok_end() const
Get the token end position, in the raw buffer.
Definition: sql_lexer_input_stream.h:262
uint yyLength() const
Get the length of the current token, in the raw buffer.
Definition: sql_lexer_input_stream.h:274
char * m_body_utf8
UTF8-body buffer created during parsing.
Definition: sql_lexer_input_stream.h:422
const char * get_ptr() const
Get the current stream pointer, in the raw buffer.
Definition: sql_lexer_input_stream.h:268
enum_comment_state in_comment_saved
Definition: sql_lexer_input_stream.h:461
uint get_lineno(const char *raw_ptr) const
Definition: sql_lex.cc:1191
bool text_string_is_7bit() const
Definition: sql_lexer_input_stream.h:510
bool stmt_prepare_mode
true if we're parsing a prepared statement: in this mode we should allow placeholders.
Definition: sql_lexer_input_stream.h:453
const char * get_body_utf8_str() const
Get the utf8-body string.
Definition: sql_lexer_input_stream.h:284
void add_digest_token(uint token, Lexer_yystype *yylval)
Definition: sql_lexer.cc:263
const char * m_cpp_utf8_processed_ptr
Position in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:431
size_t m_buf_length
Length of the raw buffer.
Definition: sql_lexer_input_stream.h:397
const char * get_cpp_tok_end() const
Get the token end position, in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:265
const char * get_cpp_buf() const
Get the pre-processed query buffer.
Definition: sql_lexer_input_stream.h:232
void reduce_digest_token(uint token_left, uint token_right)
Definition: sql_lexer.cc:269
char * m_cpp_buf
Pre-processed buffer.
Definition: sql_lexer_input_stream.h:404
const char * m_cpp_text_start
Starting position of the TEXT_STRING or IDENT in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:469
const char * m_tok_start
Starting position of the last token parsed, in the raw buffer.
Definition: sql_lexer_input_stream.h:385
Lex_input_stream(uint grammar_selector_token_arg)
Constructor.
Definition: sql_lexer_input_stream.h:78
void save_in_comment_state()
Definition: sql_lexer_input_stream.h:100
unsigned char yyGet()
Get a character, and advance in the stream.
Definition: sql_lexer_input_stream.h:127
void warn_on_deprecated_charset(const CHARSET_INFO *cs, const char *alias) const
Outputs warnings on deprecated charsets in complete SQL statements.
Definition: sql_lexer_input_stream.h:360
void yySkip()
Accept a character, by advancing the input stream.
Definition: sql_lexer_input_stream.h:170
bool m_echo
Echo the parsed stream to the pre-processed buffer.
Definition: sql_lexer_input_stream.h:400
char * m_body_utf8_ptr
Pointer to the current position in the UTF8-body buffer.
Definition: sql_lexer_input_stream.h:425
uint yylineno
Current line number.
Definition: sql_lexer_input_stream.h:304
void yySkipn(int n)
Accept multiple characters at once.
Definition: sql_lexer_input_stream.h:182
enum_comment_state in_comment
State of the lexical analyser for comments.
Definition: sql_lexer_input_stream.h:460
int lookahead_token
LALR(2) resolution, look ahead token.
Definition: sql_lexer_input_stream.h:318
void body_utf8_append_literal(THD *thd, const LEX_STRING *txt, const CHARSET_INFO *txt_cs, const char *end_ptr)
The operation converts the specified text literal to the utf8 and appends the result to the utf8-body...
Definition: sql_lexer.cc:233
unsigned char yyGetLast() const
Get the last character accepted.
Definition: sql_lexer_input_stream.h:138
bool ignore_space
SQL_MODE = IGNORE_SPACE.
Definition: sql_lexer_input_stream.h:447
void set_echo(bool echo)
Set the echo mode.
Definition: sql_lexer_input_stream.h:98
Lexer_yystype * yylval
Interface with bison, value of the last token parsed.
Definition: sql_lexer_input_stream.h:310
void start_token()
Mark the stream position as the start of a new token.
Definition: sql_lexer_input_stream.h:238
void reset(const char *buff, size_t length)
Prepare Lex_input_stream instance state for use for handling next SQL statement.
Definition: sql_lexer.cc:102
void yyUnget()
Cancel the effect of the last yyGet() or yySkip().
Definition: sql_lexer_input_stream.h:162
char * m_ptr
Pointer to the current position in the raw input stream.
Definition: sql_lexer_input_stream.h:382
const char * m_end_of_query
End of the query text in the input stream, in the raw buffer.
Definition: sql_lexer_input_stream.h:391
unsigned char yyPeekn(int n) const
Look ahead at some character to parse.
Definition: sql_lexer_input_stream.h:152
unsigned char yyPeek() const
Look at the next character to parse, but do not accept it.
Definition: sql_lexer_input_stream.h:143
bool eof() const
End of file indicator for the query text to parse.
Definition: sql_lexer_input_stream.h:219
const CHARSET_INFO * m_underscore_cs
Character set specified by the character-set-introducer.
Definition: sql_lexer_input_stream.h:484
const char * m_tok_end
Ending position of the previous token parsed, in the raw buffer.
Definition: sql_lexer_input_stream.h:388
bool is_partial_parser() const
True if this scanner tokenizes a partial query (partition expression, generated column expression etc...
Definition: sql_lexer_input_stream.h:352
const char * m_buf
Begining of the query text in the input stream, in the raw buffer.
Definition: sql_lexer_input_stream.h:394
const char * m_cpp_tok_start
Starting position of the last token parsed, in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:413
uint yytoklen
Length of the last token parsed.
Definition: sql_lexer_input_stream.h:307
const char * get_cpp_ptr() const
Get the current stream pointer, in the pre-processed buffer.
Definition: sql_lexer_input_stream.h:271
Definition: sql_list.h:633
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Storage for name strings.
Definition: item.h:298
Global level hints.
Definition: opt_hints.h:352
Query block level hints.
Definition: opt_hints.h:378
Definition: parse_tree_nodes.h:1809
Represents the WITH clause: WITH [...], [...] SELECT ..., ^^^^^^^^^^^^^^^^^.
Definition: parse_tree_nodes.h:367
Base class for all top-level nodes of SQL statements.
Definition: parse_tree_nodes.h:163
Internal state of the parser.
Definition: sql_lexer_parser_state.h:44
Lex_input_stream m_lip
Definition: sql_lexer_parser_state.h:79
void add_comment()
Signal that the current query has a comment.
Definition: sql_lexer_parser_state.h:73
void reset(const char *found_semicolon, size_t length)
Definition: sql_lexer_parser_state.h:67
Yacc_state m_yacc
Definition: sql_lexer_parser_state.h:80
Parser_state()
Definition: sql_lex.h:5007
Parser_input m_input
Definition: sql_lexer_parser_state.h:78
bool has_comment() const
Check whether the current query has a comment.
Definition: sql_lexer_parser_state.h:75
bool m_comment
True if current query contains comments.
Definition: sql_lexer_parser_state.h:88
bool init(THD *thd, const char *buff, size_t length)
Object initializer.
Definition: sql_lexer_parser_state.h:63
PSI_digest_locker * m_digest_psi
Current performance digest instrumentation.
Definition: sql_lex.h:5036
Parser state for partition expression parser (.frm/DD stuff)
Definition: sql_lex.h:5045
Partition_expr_parser_state()
Definition: sql_lex.cc:1208
partition_info * result
Definition: sql_lex.h:5049
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
RAII class to ease the call of LEX::mark_broken() if error.
Definition: sql_lex.h:4869
~Prepare_error_tracker()
Definition: sql_lex.cc:139
THD *const thd
Definition: sql_lex.h:4875
Prepare_error_tracker(THD *thd_arg)
Definition: sql_lex.h:4871
Definition: protocol.h:33
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1174
void print_update_list(const THD *thd, String *str, enum_query_type query_type, const mem_root_deque< Item * > &fields, const mem_root_deque< Item * > &values)
Print assignments list.
Definition: sql_lex.cc:3336
void print_delete(const THD *thd, String *str, enum_query_type query_type)
Print detail of the DELETE statement.
Definition: sql_lex.cc:3116
void add_base_options(ulonglong options)
Add base options to a query block, also update active options.
Definition: sql_lex.h:1242
uint n_scalar_subqueries
Keep track for allocation of base_ref_items: scalar subqueries may be replaced by a field during scal...
Definition: sql_lex.h:2167
void label_children() override
Set the correct value of Query_term::m_sibling_idx recursively for set operations.
Definition: sql_lex.h:1210
void qbPrint(int level, std::ostringstream &buf) const
Minion of debugPrint.
Definition: query_term.cc:969
Query_block * next
Intrusive linked list of all query blocks within the same query expression.
Definition: sql_lex.h:2445
void cleanup_all_joins()
Definition: sql_union.cc:1469
uint select_number
Query block number (used for EXPLAIN)
Definition: sql_lex.h:2100
bool subquery_in_having
HAVING clause contains subquery => we can't close tables before query processing end even if we use t...
Definition: sql_lex.h:2267
Query_term_type term_type() const override
Get the node tree type.
Definition: sql_lex.h:1205
void print_where_cond(const THD *thd, String *str, enum_query_type query_type)
Print list of conditions in WHERE clause.
Definition: sql_lex.cc:3423
Item * where_cond() const
Definition: sql_lex.h:1217
bool is_grouped() const
Definition: sql_lex.h:1324
void print_insert_options(String *str)
Print INSERT options.
Definition: sql_lex.cc:3264
bool m_json_agg_func_used
Definition: sql_lex.h:2533
mem_root_deque< mem_root_deque< Item * > * > * row_value_list
The VALUES items of a table value constructor.
Definition: sql_lex.h:1960
bool is_dependent() const
Definition: sql_lex.h:1844
void print_qualify(const THD *thd, String *str, enum_query_type query_type) const
Print list of items in QUALIFY clause.
Definition: sql_lex.cc:3475
mem_root_deque< Item * > * get_fields_list()
Definition: sql_lex.h:1417
MaterializePathParameters::Operand setup_materialize_query_block(AccessPath *child_path, TABLE *dst_table) const
Make materialization parameters for a query block given its input path and destination table,...
Definition: sql_union.cc:706
bool with_sum_func
True if contains or aggregates set functions.
Definition: sql_lex.h:2261
Ref_item_array m_saved_base_items
A backup of the items in base_ref_items at the end of preparation, so that base_ref_items can be rest...
Definition: sql_lex.h:2518
bool is_explicitly_grouped() const
Definition: sql_lex.h:1300
Item * m_where_cond
Condition to be evaluated after all tables in a query block are joined.
Definition: sql_lex.h:2504
olap_type olap
Indicates whether this query block contains non-primitive grouping (such as ROLLUP).
Definition: sql_lex.h:2200
Item::cond_result having_value
Definition: sql_lex.h:2111
Item::cond_result cond_value
Saved values of the WHERE and HAVING clauses.
Definition: sql_lex.h:2110
bool setup_base_ref_items(THD *thd)
Setup the array containing references to base items.
Definition: sql_lex.cc:2600
uint get_in_sum_expr() const
Definition: sql_lex.h:1387
void print_values(const THD *thd, String *str, enum_query_type query_type, const mem_root_deque< mem_root_deque< Item * > * > &values, const char *prefix)
Print list of values, used in INSERT and for general VALUES clause.
Definition: sql_lex.cc:3377
bool group_fix_field
true when GROUP BY fix field called in processing of this query block
Definition: sql_lex.h:2251
void print_item_list(const THD *thd, String *str, enum_query_type query_type)
Print list of items in Query_block object.
Definition: sql_lex.cc:3312
Resolve_place resolve_place
Indicates part of query being resolved.
Definition: sql_lex.h:2132
bool m_right_joins
True if query block has right joins.
Definition: sql_lex.h:2527
Query_block(MEM_ROOT *mem_root, Item *where, Item *having)
Construct and initialize Query_block object.
Definition: sql_lex.cc:2258
bool is_implicitly_grouped() const
Definition: sql_lex.h:1307
void add_subquery_transform_candidate(Item_exists_subselect *predicate)
Definition: sql_lex.h:1499
size_t visible_column_count() const override
Return the number of visible columns of the query term.
Definition: sql_lex.h:1426
Item * m_having_cond
Condition to be evaluated on grouped rows after grouping.
Definition: sql_lex.h:2507
uint cond_count
Number of predicates after preparation.
Definition: sql_lex.h:2150
Query_result * m_query_result
Result of this query block.
Definition: sql_lex.h:2457
void cleanup(bool full) override
Cleanup this subtree (this Query_block and all nested Query_blockes and Query_expressions).
Definition: sql_union.cc:1440
bool absorb_limit_of(Query_block *block)
end of overridden methods from Query_term
Definition: query_term.cc:1028
Table_ref * end_lateral_table
Last table for LATERAL join, used by table functions.
Definition: sql_lex.h:2064
void print_hints(const THD *thd, String *str, enum_query_type query_type)
Print detail of Hints.
Definition: sql_lex.cc:3196
bool accept(Select_lex_visitor *visitor)
Accept function for SELECT and DELETE.
Definition: sql_lex.cc:3564
uint max_equal_elems
Maximal number of elements in multiple equalities.
Definition: sql_lex.h:2154
uint table_func_count
Number of table functions in this query block.
Definition: sql_lex.h:2188
Item ** qualify_cond_ref()
Definition: sql_lex.h:1224
Mem_root_array< Item_exists_subselect * > * sj_candidates
Pointer to collection of subqueries candidate for semi/antijoin conversion.
Definition: sql_lex.h:2436
bool having_fix_field
true when having fix field called in processing of this query block
Definition: sql_lex.h:2249
bool has_aj_nests
Definition: sql_lex.h:2526
uint hidden_items_from_optimization
Hidden items added during optimization.
Definition: sql_lex.h:2290
Query_block * link_next
Intrusive double-linked global list of query blocks.
Definition: sql_lex.h:2453
VisibleFieldsIterator types_iterator() override
Abstract over visible column types: if query block, we offer an iterator over visible fields,...
Definition: sql_lex.h:1425
void invalidate()
Invalidate by nulling out pointers to other Query_expressions and Query_blockes.
Definition: sql_lex.cc:2592
Opt_hints_qb * opt_hints_qb
Query-block-level hints, for this query block.
Definition: sql_lex.h:2011
Query_block * query_block() const override
The query_block which holds the ORDER BY and LIMIT information for this set operation.
Definition: sql_lex.h:1207
Query_block ** link_prev
Definition: sql_lex.h:2454
uint with_wild
Number of wildcards used in the SELECT list.
Definition: sql_lex.h:2179
Name_resolution_context context
Context for name resolution for all column references except columns from joined tables.
Definition: sql_lex.h:2036
Item ** where_cond_ref()
Definition: sql_lex.h:1218
void make_active_options(ulonglong added_options, ulonglong removed_options)
Make active options from base options, supplied options and environment:
Definition: sql_lex.cc:2440
void set_empty_query()
Set query block as returning no data.
Definition: sql_lex.h:1816
Query_expression * slave
The first query expression contained within this query block.
Definition: sql_lex.h:2450
bool is_item_list_lookup
Definition: sql_lex.h:2246
void mark_as_dependent(Query_block *last, bool aggregate)
Mark all query blocks from this to 'last' as dependent.
Definition: sql_lex.cc:2476
Table_ref * leaf_tables
Points to first leaf table of query block.
Definition: sql_lex.h:2062
bool save_order_properties(THD *thd, SQL_I_List< ORDER > *list, Group_list_ptrs **list_ptrs)
Helper for save_properties()
Definition: sql_lex.cc:4365
Item_sum * inner_sum_func_list
Circular linked list of aggregate functions in nested query blocks.
Definition: sql_lex.h:2079
Item ** having_cond_ref()
Definition: sql_lex.h:1221
bool first_execution
This variable is required to ensure proper work of subqueries and stored procedures.
Definition: sql_lex.h:2235
Item * having_cond() const
Definition: sql_lex.h:1220
void print_delete_options(String *str)
Print DELETE options.
Definition: sql_lex.cc:3256
bool add_ftfunc_to_list(Item_func_match *func)
Definition: sql_lex.cc:2584
void print_having(const THD *thd, String *str, enum_query_type query_type)
Print list of items in HAVING clause.
Definition: sql_lex.cc:3459
bool walk(Item_processor processor, enum_walk walk, uchar *arg)
Definition: sql_lex.cc:4813
bool m_agg_func_used
Definition: sql_lex.h:2532
Query_expression * first_inner_query_expression() const
Definition: sql_lex.h:1286
uint materialized_derived_table_count
Number of materialized derived tables and views in this query block.
Definition: sql_lex.h:2170
VisibleFieldsIterator visible_fields()
Wrappers over fields / get_fields_list() that hide items where item->hidden, meant for range-based fo...
Definition: sql_lex.h:1422
List< Item_func_match > * ftfunc_list
A pointer to ftfunc_list_alloc, list of full text search functions.
Definition: sql_lex.h:1956
uint in_sum_expr
Parse context: is inside a set function if this is positive.
Definition: sql_lex.h:2116
enum_condition_context condition_context
Definition: sql_lex.h:2203
void set_right_joins()
Definition: sql_lex.h:1833
uint n_sum_items
Number of Item_sum-derived objects in this SELECT.
Definition: sql_lex.h:2161
bool m_limit_1
Whether we have LIMIT 1 and no OFFSET.
Definition: sql_lex.h:2071
Query_block * outer_query_block() const
Definition: sql_lex.h:1287
void renumber(LEX *lex)
Renumber query blocks of contained query expressions.
Definition: sql_lex.cc:4539
mem_root_deque< Table_ref * > * m_current_table_nest
Pointer to the set of table references in the currently active join.
Definition: sql_lex.h:2053
List< Window > m_windows
All windows defined on the select, both named and inlined.
Definition: sql_lex.h:1951
Table_ref * find_table_by_name(const Table_ident *ident)
Finds a (possibly unresolved) table reference in the from clause by name.
Definition: sql_lex.cc:4884
uint leaf_table_count
Number of leaf tables in this query block.
Definition: sql_lex.h:2184
void set_having_cond(Item *cond)
Definition: sql_lex.h:1222
bool m_use_select_limit
If true, use select_limit to limit number of rows selected.
Definition: sql_lex.h:2274
bool has_limit() const
Definition: sql_lex.h:1358
void set_qualify_cond(Item *cond)
Definition: sql_lex.h:1225
bool validate_outermost_option(LEX *lex, const char *wrong_option) const
Check if an option that can be used only for an outer-most query block is applicable to this query bl...
Definition: sql_lex.cc:4718
table_map original_tables_map
Original query table map before aj/sj processing.
Definition: sql_lex.h:2182
void destroy()
Destroy contained objects, in particular temporary tables which may have their own mem_roots.
Definition: sql_union.cc:1480
uint derived_table_count
Number of derived tables and views in this query block.
Definition: sql_lex.h:2186
bool is_ordered() const
Definition: sql_lex.h:1335
void destroy_tree() override
Destroy the query term tree structure.
Definition: sql_lex.h:1211
uint partitioned_table_count
Number of partitioned tables.
Definition: sql_lex.h:2172
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
Definition: sql_lex.h:2005
void print_insert_fields(const THD *thd, String *str, enum_query_type query_type)
Print column list to be inserted into.
Definition: sql_lex.cc:3357
mem_root_deque< Item * > * types_array() override
Definition: query_term.cc:831
bool json_agg_func_used() const
Definition: sql_lex.h:1826
bool get_optimizable_conditions(THD *thd, Item **new_where, Item **new_having)
Returns disposable copies of WHERE/HAVING/ON conditions.
Definition: sql_lex.cc:4616
uint between_count
Number of between predicates in where/having/on.
Definition: sql_lex.h:2152
Query_result * query_result() const
Definition: sql_lex.h:1227
void include_in_global(Query_block **plink)
Include query block into global list.
Definition: sql_lex.cc:4555
bool agg_func_used() const
Definition: sql_lex.h:1825
Resolve_place
Three fields used by semi-join transformations to know when semi-join is possible,...
Definition: sql_lex.h:2124
@ RESOLVE_HAVING
Definition: sql_lex.h:2128
@ RESOLVE_NONE
Definition: sql_lex.h:2125
@ RESOLVE_SELECT_LIST
Definition: sql_lex.h:2130
@ RESOLVE_QUALIFY
Definition: sql_lex.h:2129
@ RESOLVE_JOIN_NEST
Definition: sql_lex.h:2126
@ RESOLVE_CONDITION
Definition: sql_lex.h:2127
void include_chain_in_global(Query_block **start)
Include chain of query blocks into global list.
Definition: sql_lex.cc:4566
SQL_I_List< ORDER > order_list
ORDER BY clause.
Definition: sql_lex.h:1975
char * db
Definition: sql_lex.h:2013
List< Item_func_match > ftfunc_list_alloc
Definition: sql_lex.h:1957
static const char * get_type_str(enum_explain_type type)
Definition: sql_lex.h:1840
void remove_base_options(ulonglong options)
Remove base options from a query block.
Definition: sql_lex.h:1253
enum_explain_type type() const
Lookup for Query_block type.
Definition: sql_lex.cc:4436
bool optimize_query_term(THD *, Query_expression *) override
Optimize the non-leaf query blocks.
Definition: sql_lex.h:1194
Item * offset_limit
LIMIT ... OFFSET clause, NULL if no offset is given.
Definition: sql_lex.h:2069
void set_sj_candidates(Mem_root_array< Item_exists_subselect * > *sj_cand)
Definition: sql_lex.h:1496
void print_order_by(const THD *thd, String *str, enum_query_type query_type) const
Print list of items in ORDER BY clause.
Definition: sql_lex.cc:3505
static const char * type_str[static_cast< int >(enum_explain_type::EXPLAIN_total)]
Definition: sql_lex.h:2542
bool add_grouping_expr(THD *thd, Item *item)
Add a grouping expression to the query block.
Definition: sql_lex.cc:2577
Query_expression * master
The query expression containing this query block.
Definition: sql_lex.h:2448
bool has_subquery_transforms() const
Definition: sql_lex.h:1506
Ref_item_array base_ref_items
Array of pointers to "base" items; one each for every selected expression and referenced item in the ...
Definition: sql_lex.h:2098
int hidden_order_field_count
How many expressions are part of the order by but not select list.
Definition: sql_lex.h:2439
enum_parsing_context parsing_place
Parse context: indicates where the current expression is being parsed.
Definition: sql_lex.h:2114
void init_order()
Definition: sql_lex.h:1515
uint8 uncacheable
result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCA...
Definition: sql_lex.h:2217
ulonglong m_base_options
Options assigned from parsing and throughout resolving, should not be modified after resolving is don...
Definition: sql_lex.h:2463
bool source_table_is_one_row() const
Definition: sql_lex.h:1848
uint in_window_expr
Parse context: is inside a window function if this is positive.
Definition: sql_lex.h:2118
void include_down(LEX *lex, Query_expression *outer)
Include query block inside a query expression.
Definition: sql_lex.cc:4490
void include_standalone(Query_expression *sel)
Include query block inside a query expression, but do not link.
Definition: sql_lex.cc:4527
Group_list_ptrs * group_list_ptrs
Definition: sql_lex.h:1988
uint saved_cond_count
Number of arguments of and/or/xor in where/having/on.
Definition: sql_lex.h:2148
Subquery_strategy subquery_strategy(const THD *thd) const
Returns which subquery execution strategies can be used for this query block.
Definition: sql_lex.cc:4639
Query_block * next_query_block() const
Definition: sql_lex.h:1288
Name_resolution_context * first_context
Pointer to first object in list of Name res context objects that have this query block as the base qu...
Definition: sql_lex.h:2043
void include_neighbour(LEX *lex, Query_block *before)
Include a query block next to another query block.
Definition: sql_lex.cc:4508
bool is_table_value_constructor
If set, the query block is of the form VALUES row_list.
Definition: sql_lex.h:2206
Item * get_derived_expr(uint expr_index)
Returns an expression from the select list of the query block using the field's index in a derived ta...
Definition: sql_derived.cc:1317
bool semijoin_enabled(const THD *thd) const
Returns whether semi-join is enabled for this query block.
Definition: sql_lex.cc:4665
Query_expression * master_query_expression() const
Definition: sql_lex.h:1285
void update_semijoin_strategies(THD *thd)
Update available semijoin strategies for semijoin nests.
Definition: sql_lex.cc:4670
uint select_n_having_items
Number of items in the select list, HAVING clause, QUALIFY clause and ORDER BY clause.
Definition: sql_lex.h:2146
Table_ref * get_table_list() const
Definition: sql_lex.h:1412
void print_update(const THD *thd, String *str, enum_query_type query_type)
Print detail of the UPDATE statement.
Definition: sql_lex.cc:3079
bool is_simple_query_block() const
Definition: sql_lex.h:1803
void print_table_references(const THD *thd, String *str, Table_ref *table_list, enum_query_type query_type)
Print list of tables.
Definition: sql_lex.cc:3278
int m_current_order_by_number
Keeps track of the current ORDER BY expression we are resolving for ORDER BY, if any.
Definition: sql_lex.h:2286
bool has_tables() const
Definition: sql_lex.h:1297
void debugPrint(int level, std::ostringstream &buf) const override
Query_term methods overridden.
Definition: query_term.cc:1006
bool m_internal_limit
If true, limit object is added internally.
Definition: sql_lex.h:2277
int hidden_group_field_count
Number of GROUP BY expressions added to all_fields.
Definition: sql_lex.h:2513
bool is_recursive() const
Definition: sql_lex.h:1364
int get_number_of_grouping_sets() const
Definition: sql_lex.h:2493
void print_windows(const THD *thd, String *str, enum_query_type query_type)
Print details of Windowing functions.
Definition: sql_lex.cc:3483
bool no_table_names_allowed
used for global order by
Definition: sql_lex.h:2282
bool validate_base_options(LEX *lex, ulonglong options) const
Validate base options for a query block.
Definition: sql_lex.cc:4755
void set_where_cond(Item *cond)
Definition: sql_lex.h:1219
Item * select_limit
LIMIT clause, NULL if no limit is given.
Definition: sql_lex.h:2067
ulonglong active_options() const
Definition: sql_lex.h:1266
bool save_properties(THD *thd)
Save properties of a prepared statement needed for repeated optimization.
Definition: sql_lex.cc:4388
Table_ref * embedding
table embedding the above list
Definition: sql_lex.h:2055
bool open_result_tables(THD *, int) override
Open tmp tables for the tree of set operation query results, by recursing.
Definition: query_term.cc:1020
table_map select_list_tables
The set of those tables whose fields are referenced in the select list of this select level.
Definition: sql_lex.h:2029
bool m_was_implicitly_grouped
Used by nested scalar_to_derived transformations.
Definition: sql_lex.h:2241
bool has_sj_nests
True if query block has semi-join nests merged into it.
Definition: sql_lex.h:2525
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
Definition: sql_lex.h:2007
SQL_I_List< ORDER > group_list
GROUP BY clause.
Definition: sql_lex.h:1987
SQL_I_List< Table_ref > m_table_list
List of tables in FROM clause - use Table_ref::next_local to traverse.
Definition: sql_lex.h:1966
uint select_n_where_fields
Number of fields used in select list or where clause of current select and all inner subselects.
Definition: sql_lex.h:2139
bool skip_local_transforms
True: skip local transformations during prepare() call (used by INSERT)
Definition: sql_lex.h:2244
void print_limit(const THD *thd, String *str, enum_query_type query_type) const
Definition: sql_lex.cc:2723
const char * get_type_str()
Lookup for a type string.
Definition: sql_lex.h:1839
Table_ref * resolve_nest
Used when resolving outer join condition.
Definition: sql_lex.h:2479
bool is_empty_query() const
Definition: sql_lex.h:1812
void print_query_block(const THD *thd, String *str, enum_query_type query_type)
Print detail of the Query_block object.
Definition: sql_lex.cc:3055
mem_root_deque< Table_ref * > m_table_nest
Set of table references contained in outer-most join nest.
Definition: sql_lex.h:2051
bool set_context(Name_resolution_context *outer_context)
Assign a default name resolution object for this query block.
Definition: sql_lex.cc:2275
bool m_window_order_fix_field
true when resolving a window's ORDER BY or PARTITION BY, the window belonging to this query block.
Definition: sql_lex.h:2254
void set_json_agg_func_used(bool val)
Definition: sql_lex.h:1830
bool allow_merge_derived
Allow merge of immediate unnamed derived tables.
Definition: sql_lex.h:2530
bool add_tables(THD *thd, const Mem_root_array< Table_ident * > *tables, ulong table_options, thr_lock_type lock_type, enum_mdl_type mdl_type)
Add tables from an array to a list of used tables.
Definition: sql_lex.cc:2300
void print_select_options(String *str)
Print select options.
Definition: sql_lex.cc:3242
void set_query_result(Query_result *result)
Definition: sql_lex.h:1226
mem_root_deque< Table_ref * > sj_nests
List of semi-join nests generated for this query block.
Definition: sql_lex.h:1963
Table_ref * recursive_reference
If this query block is a recursive member of a recursive unit: the Table_ref, in this recursive membe...
Definition: sql_lex.h:2020
bool add_item_to_list(Item *item)
Definition: sql_lex.cc:2560
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: sql_lex.cc:3016
bool is_non_primitive_grouped() const
Definition: sql_lex.h:1314
bool exclude_from_table_unique_test
exclude this query block from unique_table() check
Definition: sql_lex.h:2280
bool sj_pullout_done
True when semi-join pull-out processing is complete.
Definition: sql_lex.h:2238
AccessPath * make_set_op_access_path(THD *thd, Query_term_set_op *parent, Mem_root_array< AppendPathParameters > *union_all_subpaths, bool calc_found_rows) override
Recursively constructs the access path of the set operation, possibly materializing in a tmp table if...
Definition: query_term.cc:819
int nest_level
Nesting level of query block, outer-most query block has level 0, its subqueries have level 1,...
Definition: sql_lex.h:2194
const char * operator_string() const override
Get the node type description.
Definition: sql_lex.h:1206
Group_list_ptrs * order_list_ptrs
Definition: sql_lex.h:1976
uint n_child_sum_items
Number of Item_sum-derived objects in children and descendant SELECTs.
Definition: sql_lex.h:2163
bool save_cmd_properties(THD *thd)
Save prepared statement properties for a query block and underlying query expressions.
Definition: sql_lex.cc:4905
void set_agg_func_used(bool val)
Definition: sql_lex.h:1828
bool print_error(const THD *thd, String *str)
Print error.
Definition: sql_lex.cc:3221
bool prepare_query_term(THD *thd, Query_expression *qe, Change_current_query_block *save_query_block, mem_root_deque< Item * > *insert_field_list, Query_result *common_result, ulonglong added_options, ulonglong removed_options, ulonglong create_option) override
a) Prepare query blocks, both leaf blocks and blocks reresenting order by/limit in query primaries wi...
Definition: query_term.cc:764
Item * qualify_cond() const
Definition: sql_lex.h:1223
bool is_cacheable() const
Definition: sql_lex.h:1845
ha_rows get_offset(const THD *thd) const
Get offset for LIMIT.
Definition: sql_lex.cc:2539
void add_active_options(ulonglong options)
Adjust the active option set.
Definition: sql_lex.h:1263
ha_rows get_limit(const THD *thd) const
Get limit.
Definition: sql_lex.cc:2546
Item * clone_expression(THD *thd, Item *item, Table_ref *derived_table)
Creates a clone for the given expression by re-parsing the expression.
Definition: sql_derived.cc:838
void set_base_options(ulonglong options_arg)
Set base options for a query block (and active options too)
Definition: sql_lex.h:1232
void print_update_options(String *str)
Print UPDATE options.
Definition: sql_lex.cc:3249
void print_insert(const THD *thd, String *str, enum_query_type query_type)
Print detail of the INSERT statement.
Definition: sql_lex.cc:3148
table_map all_tables_map() const
Definition: sql_lex.h:1281
bool right_joins() const
Definition: sql_lex.h:1832
JOIN * join
After optimization it is pointer to corresponding JOIN.
Definition: sql_lex.h:2049
ulonglong m_active_options
Active options.
Definition: sql_lex.h:2469
decltype(SQL_I_List< ORDER >::elements) m_no_of_added_exprs
For an explicitly grouped, correlated, scalar subquery which is transformed to join with derived tabl...
Definition: sql_lex.h:2001
void restore_cmd_properties()
Restore prepared statement properties for this query block and all underlying query expressions so th...
Definition: sql_lex.cc:4926
Item * m_qualify_cond
Condition to be evaluated after window functions.
Definition: sql_lex.h:2510
void cut_subtree()
Definition: sql_lex.h:1527
bool has_sj_candidates() const
Definition: sql_lex.h:1502
void print_from_clause(const THD *thd, String *str, enum_query_type query_type)
Print list of tables in FROM clause.
Definition: sql_lex.cc:3405
bool m_empty_query
True if query block does not generate any rows before aggregation, determined during preparation (not...
Definition: sql_lex.h:2539
table_map outer_join
Bitmap of all inner tables from outer joins.
Definition: sql_lex.h:2030
size_t m_added_non_hidden_fields
Definition: sql_lex.h:1924
int m_num_grouping_sets
If the query block includes non-primitive grouping, then these modifiers are represented as grouping ...
Definition: sql_lex.h:2476
Query_block * next_select_in_list() const
Definition: sql_lex.h:1292
void print_group_by(const THD *thd, String *str, enum_query_type query_type)
Print list of items in GROUP BY clause.
Definition: sql_lex.cc:3438
auto visible_fields() const
Definition: sql_lex.h:1423
bool can_skip_distinct() const
Based on the structure of the query at resolution time, it is possible to conclude that DISTINCT is u...
Definition: sql_lex.h:1352
bool is_distinct() const
Definition: sql_lex.h:1327
void set_tables_readonly()
Set associated tables as read_only, ie.
Definition: sql_lex.h:1274
mem_root_deque< Item * > fields
All expressions needed after join and filtering, ie., select list, group by list, having clause,...
Definition: sql_lex.h:1946
LEX * parent_lex
Reference to LEX that this query block belongs to.
Definition: sql_lex.h:2023
bool test_limit()
Definition: sql_lex.cc:2512
bool has_windows() const
Definition: sql_lex.h:1380
bool has_ft_funcs() const
Definition: sql_lex.h:1361
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:638
bool is_executed() const
Check state of execution of the contained query expression.
Definition: sql_lex.h:1053
bool merge_heuristic(const LEX *lex) const
True if heuristics suggest to merge this query expression.
Definition: sql_lex.cc:3950
bool optimize(THD *thd, TABLE *materialize_destination, bool finalize_access_paths)
If and only if materialize_destination is non-nullptr, it means that the caller intends to materializ...
Definition: sql_union.cc:500
Query_block * non_simple_result_query_block() const
Return the query block iff !is_simple() holds.
Definition: sql_lex.h:670
void reset_executed()
Reset this query expression for repeated evaluation within same execution.
Definition: sql_lex.h:1032
void change_to_access_path_without_in2exists(THD *thd)
Definition: sql_union.cc:1365
unique_ptr_destroy_only< RowIterator > m_root_iterator
An iterator you can read from to get all records for this query.
Definition: sql_lex.h:758
bool m_contains_except_all
Definition: sql_lex.h:821
Query_expression(enum_parsing_context parsing_context)
Construct and initialize Query_expression object.
Definition: sql_lex.cc:2207
void set_explain_marker_from(THD *thd, const Query_expression *u)
Definition: sql_lex.cc:2532
void set_prepared()
Definition: sql_lex.h:1018
bool executed
Query expression has been executed.
Definition: sql_lex.h:743
bool walk(Item_processor processor, enum_walk walk, uchar *arg)
Definition: sql_union.cc:1357
void clear_root_access_path()
Definition: sql_lex.h:886
void set_explain_marker(THD *thd, enum_parsing_context m)
Definition: sql_lex.cc:2526
bool has_top_level_distinct() const
Definition: sql_lex.h:726
unique_ptr_destroy_only< RowIterator > release_root_iterator()
Definition: sql_lex.h:876
void exclude_tree()
Exclude subtree of current unit from tree of SELECTs.
Definition: sql_lex.cc:2385
Query_term_set_op * set_operation() const
Convenience method to avoid down casting, i.e.
Definition: sql_lex.h:666
void set_executed()
Definition: sql_lex.h:1026
Mem_root_array< MaterializePathParameters::Operand > m_operands
If there is an unfinished materialization (see optimize()), contains one element for each operand (qu...
Definition: sql_lex.h:766
enum_parsing_context explain_marker
Marker for subqueries in WHERE, HAVING, ORDER BY, GROUP BY and SELECT item lists.
Definition: sql_lex.h:739
Query_term * find_blocks_query_term(const Query_block *qb) const
Definition: sql_lex.h:677
enum_parsing_context get_explain_marker(const THD *thd) const
Definition: sql_lex.cc:2520
Query_expression * next_query_expression() const
Definition: sql_lex.h:870
Query_term * query_term() const
Getter for m_query_term, q.v.
Definition: sql_lex.h:659
Query_expression * next
Intrusive double-linked list of all query expressions immediately contained within the same query blo...
Definition: sql_lex.h:643
bool create_iterators(THD *thd)
Creates iterators for the access paths created by optimize().
Definition: sql_union.cc:656
Query_block * global_parameters() const
Return the query block holding the top level ORDER BY, LIMIT and OFFSET.
Definition: sql_lex.h:813
bool explain_query_term(THD *explain_thd, const THD *query_thd, Query_term *qt)
Definition: sql_union.cc:857
Query_block * slave
The first query block in this query expression.
Definition: sql_lex.h:652
bool has_stored_program() const
Definition: sql_lex.h:790
bool change_query_result(THD *thd, Query_result_interceptor *result, Query_result_interceptor *old_result)
Change the query result object used to return the final result of the unit, replacing occurrences of ...
Definition: sql_union.cc:1297
size_t num_visible_fields() const
Definition: sql_union.cc:1331
bool is_simple() const
Definition: sql_lex.h:788
bool optimized
All query blocks in query expression are optimized.
Definition: sql_lex.h:742
Query_block * outer_query_block() const
Definition: sql_lex.h:864
void exclude_level()
Exclude this unit and immediately contained query_block objects.
Definition: sql_lex.cc:2323
Query_block * first_query_block() const
Definition: sql_lex.h:867
Query_block * master
The query block wherein this query expression is contained, NULL if the query block is the outer-most...
Definition: sql_lex.h:650
Query_block * last_distinct() const
Return the Query_block of the last query term in a n-ary set operation that is the right side of the ...
Definition: sql_lex.h:718
enum_clean_state cleaned
cleanliness state
Definition: sql_lex.h:800
bool prepare(THD *thd, Query_result *result, mem_root_deque< Item * > *insert_field_list, ulonglong added_options, ulonglong removed_options)
Prepares all query blocks of a query expression.
Definition: sql_union.cc:359
bool check_materialized_derived_query_blocks(THD *thd)
Sets up query blocks belonging to the query expression of a materialized derived table.
Definition: sql_derived.cc:967
Query_expression ** prev
Definition: sql_lex.h:644
void DebugPrintQueryPlan(THD *thd, const char *keyword) const
Definition: sql_union.cc:680
void set_query_term(Query_term *qt)
Setter for m_query_term, q.v.
Definition: sql_lex.h:661
ha_rows offset_limit_cnt
Definition: sql_lex.h:818
Query_term * m_query_term
Definition: sql_lex.h:655
AccessPath * m_root_access_path
Definition: sql_lex.h:759
Mem_root_array< MaterializePathParameters::Operand > release_query_blocks_to_materialize()
See optimize().
Definition: sql_lex.h:918
bool has_any_limit() const
Checks if this query expression has limit defined.
Definition: sql_lex.cc:3882
bool ExecuteIteratorQuery(THD *thd)
Definition: sql_union.cc:1032
void set_optimized()
Definition: sql_lex.h:1022
void cleanup(bool full)
Cleanup this query expression object after preparation or one round of execution.
Definition: sql_union.cc:1206
friend bool parse_view_definition(THD *thd, Table_ref *view_ref)
Parse a view definition.
Definition: sql_view.cc:1218
mem_root_deque< Item * > * get_unit_column_types()
Get column type information for this query expression.
Definition: sql_union.cc:1327
Query_block * create_post_processing_block(Query_term_set_op *term)
Create a block to be used for ORDERING and LIMIT/OFFSET processing of a query term,...
Definition: sql_lex.cc:741
bool replace_items(Item_transformer t, uchar *arg)
Replace all targeted items using transformer provided and info in arg.
Definition: item_subselect.cc:3315
RowIterator * root_iterator() const
Definition: sql_lex.h:875
bool is_leaf_block(Query_block *qb)
Definition: sql_lex.cc:763
bool force_create_iterators(THD *thd)
Ensures that there are iterators created for the access paths created by optimize(),...
Definition: sql_union.cc:648
Query_block * first_recursive
First query block (in this UNION) which references the CTE.
Definition: sql_lex.h:839
bool prepared
All query blocks in query expression are prepared.
Definition: sql_lex.h:741
void assert_not_fully_clean()
Asserts that none of {this unit and its children units} is fully cleaned up.
Definition: sql_union.cc:1262
void renumber_selects(LEX *lex)
Renumber query blocks of a query expression according to supplied LEX.
Definition: sql_lex.cc:3966
bool accept(Select_lex_visitor *visitor)
Definition: sql_lex.cc:3534
Query_result * query_result() const
Definition: sql_lex.h:873
ha_rows send_records
Definition: sql_lex.h:1088
enum_parsing_context place() const
If unit is a subquery, which forms an object of the upper level (an Item_subselect,...
Definition: sql_lex.cc:4807
void accumulate_used_tables(table_map map)
If unit is a subquery, which forms an object of the upper level (an Item_subselect,...
Definition: sql_lex.cc:4799
ha_rows select_limit_cnt
Definition: sql_lex.h:818
void create_access_paths(THD *thd)
Convert the executor structures to a set of access paths, storing the result in m_root_access_path.
Definition: sql_union.cc:773
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: sql_lex.cc:2711
Table_ref * derived_table
If this query expression is underlying of a derived table, the derived table.
Definition: sql_lex.h:834
void restore_cmd_properties()
Loop over all query blocks and restore information needed for optimization, including binding data fo...
Definition: sql_lex.cc:3989
bool finalize(THD *thd)
For any non-finalized query block, finalize it so that we are allowed to create iterators.
Definition: sql_union.cc:636
Query_terms< order, visit_leaves > query_terms() const
Return iterator object over query terms rooted in m_query_term, using either post order visiting (def...
Definition: sql_lex.h:703
bool set_limit(THD *thd, Query_block *provider)
Set limit and offset for query expression object.
Definition: sql_lex.cc:3863
bool m_reject_multiple_rows
This query expression represents a scalar subquery and we need a run-time check that the cardinality ...
Definition: sql_lex.h:855
bool ClearForExecution()
Do everything that would be needed before running Init() on the root iterator.
Definition: sql_union.cc:997
Item_subselect * item
Points to subquery if this query expression is used in one, otherwise NULL.
Definition: sql_lex.h:824
enum_clean_state
Values for Query_expression::cleaned.
Definition: sql_lex.h:793
@ UC_PART_CLEAN
Unit were cleaned, except JOIN and JOIN_TABs were kept for possible EXPLAIN.
Definition: sql_lex.h:795
@ UC_CLEAN
Unit completely cleaned, all underlying JOINs were freed.
Definition: sql_lex.h:797
@ UC_DIRTY
Unit isn't cleaned.
Definition: sql_lex.h:794
void invalidate()
Invalidate by nulling out pointers to other Query expressions and Query blocks.
Definition: sql_lex.cc:2425
bool can_materialize_directly_into_result() const
Whether there is a chance that optimize() is capable of materializing directly into a result table if...
Definition: sql_union.cc:334
PT_with_clause * m_with_clause
The WITH clause which is the first part of this query expression.
Definition: sql_lex.h:829
bool explain(THD *explain_thd, const THD *query_thd)
Explain query starting from this unit.
Definition: sql_union.cc:929
bool is_mergeable() const
Return true if query expression can be merged into an outer query, based on technical constraints.
Definition: sql_lex.cc:3921
Query_result * m_query_result
Object to which the result for this query expression is sent.
Definition: sql_lex.h:750
bool is_prepared() const
Check state of preparation of the contained query expression.
Definition: sql_lex.h:1045
table_map m_lateral_deps
If 'this' is body of lateral derived table: map of tables in the same FROM clause as this derived tab...
Definition: sql_lex.h:849
bool is_optimized() const
Check state of optimization of the contained query expression.
Definition: sql_lex.h:1047
void set_query_result(Query_result *res)
Set new query result object for this query expression.
Definition: sql_lex.h:923
void include_down(LEX *lex, Query_block *outer)
Include a query expression below a query block.
Definition: sql_lex.cc:3895
void destroy()
Destroy contained objects, in particular temporary tables which may have their own mem_roots.
Definition: sql_union.cc:1237
mem_root_deque< Item * > * get_field_list()
Get field list for this query expression.
Definition: sql_union.cc:1345
bool execute(THD *thd)
Execute a query expression that may be a UNION and/or have an ordered result.
Definition: sql_union.cc:1175
bool clear_correlated_query_blocks()
Empties all correlated query blocks defined within the query expression; that is, correlated CTEs def...
Definition: sql_union.cc:983
bool save_cmd_properties(THD *thd)
Save prepared statement properties for a query expression and underlying query blocks.
Definition: sql_lex.cc:3978
bool m_has_stored_program
Definition: sql_lex.h:745
AccessPath * root_access_path() const
Definition: sql_lex.h:879
uint8 uncacheable
result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCA...
Definition: sql_lex.h:782
bool unfinished_materialization() const
See optimize().
Definition: sql_lex.h:914
void clear_execution()
Clear execution state, needed before new execution of prepared statement.
Definition: sql_lex.h:1037
bool is_recursive() const
Definition: sql_lex.h:1105
Definition: query_result.h:191
Definition: sql_union.h:40
Definition: query_result.h:60
Definition: sql_lex.h:2753
bool is_mixed_stmt_unsafe(bool in_multi_stmt_transaction_mode, bool binlog_direct, bool trx_cache_is_not_empty, uint tx_isolation)
Definition: sql_lex.h:3280
bool uses_stored_routines() const
true if the parsed tree contains references to stored procedures, triggers or functions,...
Definition: sql_lex.h:3327
void set_stmt_row_injection()
Flag the statement as a row injection.
Definition: sql_lex.h:3127
std::unique_ptr< malloc_unordered_map< std::string, Sroutine_hash_entry * > > sroutines
Definition: sql_lex.h:2784
void set_stmt_unsafe(enum_binlog_stmt_unsafe unsafe_type)
Flag the current (top-level) statement as unsafe.
Definition: sql_lex.h:3076
static const char * stmt_accessed_table_string(enum_stmt_accessed_table accessed_table)
Definition: sql_lex.h:3180
enum_binlog_stmt_type
Enumeration listing special types of statements.
Definition: sql_lex.h:3343
@ BINLOG_STMT_TYPE_ROW_INJECTION
The statement is a row injection (i.e., either a BINLOG statement or a row event executed by the slav...
Definition: sql_lex.h:3348
@ BINLOG_STMT_TYPE_COUNT
The last element of this enumeration type.
Definition: sql_lex.h:3351
Table_ref ** query_tables_last
Definition: sql_lex.h:2767
bool is_stmt_unsafe_with_mixed_mode() const
Definition: sql_lex.h:3333
void reset_query_tables_list(bool init)
Definition: sql_lex.cc:3629
static const int BINLOG_STMT_UNSAFE_ALL_FLAGS
This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT (exclusive) set.
Definition: sql_lex.h:3049
~Query_tables_list()=default
enum_sql_command sql_command
SQL command for this statement.
Definition: sql_lex.h:2763
void set_stmt_unsafe_flags(uint32 flags)
Set the bits of binlog_stmt_flags determining the type of unsafeness of the current statement.
Definition: sql_lex.h:3091
uint32 get_stmt_unsafe_flags() const
Return a binary combination of all unsafe warnings for the statement.
Definition: sql_lex.h:3104
void set_stmt_unsafe_with_mixed_mode()
Definition: sql_lex.h:3332
Query_tables_list()=default
bool is_stmt_unsafe() const
Determine if this statement is marked as unsafe.
Definition: sql_lex.h:3063
bool is_stmt_unsafe(enum_binlog_stmt_unsafe unsafe)
Definition: sql_lex.h:3065
uint table_count
Number of tables which were open by open_tables() and to be locked by lock_tables().
Definition: sql_lex.h:2828
uint32 stmt_accessed_table_flag
Bit field that determines the type of tables that are about to be be accessed while executing a state...
Definition: sql_lex.h:3375
enum_stmt_accessed_table
Definition: sql_lex.h:3135
@ STMT_READS_TEMP_TRANS_TABLE
Definition: sql_lex.h:3150
@ STMT_WRITES_TEMP_TRANS_TABLE
Definition: sql_lex.h:3167
@ STMT_WRITES_TRANS_TABLE
Definition: sql_lex.h:3159
@ STMT_WRITES_TEMP_NON_TRANS_TABLE
Definition: sql_lex.h:3171
@ STMT_READS_TRANS_TABLE
Definition: sql_lex.h:3140
@ STMT_READS_TEMP_NON_TRANS_TABLE
Definition: sql_lex.h:3155
@ STMT_ACCESS_TABLE_COUNT
Definition: sql_lex.h:3176
@ STMT_READS_NON_TRANS_TABLE
Definition: sql_lex.h:3145
@ STMT_WRITES_NON_TRANS_TABLE
Definition: sql_lex.h:3163
bool stmt_unsafe_with_mixed_mode
This flag is set to true if statement is unsafe to be binlogged in STATEMENT format,...
Definition: sql_lex.h:3388
uint sroutines_list_own_elements
Definition: sql_lex.h:2796
void mark_as_requiring_prelocking(Table_ref **tables_own_last)
Definition: sql_lex.h:2854
bool is_stmt_row_injection() const
Determine if this statement is a row injection.
Definition: sql_lex.h:3115
@ START_SROUTINES_HASH_SIZE
Definition: sql_lex.h:2782
enum_lock_tables_state lock_tables_state
Definition: sql_lex.h:2816
void set_query_tables_list(Query_tables_list *state)
Definition: sql_lex.h:2840
void set_using_match()
Definition: sql_lex.h:3329
bool stmt_accessed_table(enum_stmt_accessed_table accessed_table)
Checks if a type of table is about to be accessed while executing a statement.
Definition: sql_lex.h:3257
SQL_I_List< Sroutine_hash_entry > sroutines_list
Definition: sql_lex.h:2794
void destroy_query_tables_list()
Definition: sql_lex.cc:3674
Sroutine_hash_entry ** sroutines_list_own_last
Definition: sql_lex.h:2795
bool using_match
It will be set true if 'MATCH () AGAINST' is used in the statement.
Definition: sql_lex.h:3380
void set_stmt_accessed_table(enum_stmt_accessed_table accessed_table)
Sets the type of table that is about to be accessed while executing a statement.
Definition: sql_lex.h:3238
static const int binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT]
Maps elements of enum_binlog_stmt_unsafe to error codes.
Definition: sql_lex.h:3055
enum_binlog_stmt_unsafe
All types of unsafe statements.
Definition: sql_lex.h:2884
@ BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION
Using some functions is unsafe (e.g., UUID).
Definition: sql_lex.h:2916
@ BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE
Mixing self-logging and non-self-logging engines in a statement is unsafe.
Definition: sql_lex.h:2929
@ BINLOG_STMT_UNSAFE_COUNT
Definition: sql_lex.h:3043
@ BINLOG_STMT_UNSAFE_XA
XA transactions and statements.
Definition: sql_lex.h:3016
@ BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC
CREATE TABLE...SELECT on a table with auto-increment column is unsafe because which rows are replaced...
Definition: sql_lex.h:2985
@ BINLOG_STMT_UNSAFE_DEFAULT_EXPRESSION_IN_SUBSTATEMENT
If a substatement inserts into or updates a table that has a column with an unsafe DEFAULT expression...
Definition: sql_lex.h:3023
@ BINLOG_STMT_UNSAFE_NOWAIT
Definition: sql_lex.h:3011
@ BINLOG_STMT_UNSAFE_FULLTEXT_PLUGIN
Using a plugin is unsafe.
Definition: sql_lex.h:3009
@ BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS
INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEYS is unsafe.
Definition: sql_lex.h:2998
@ BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST
INSERT into auto-inc field which is not the first part in composed primary key.
Definition: sql_lex.h:3004
@ BINLOG_STMT_UNSAFE_CREATE_SELECT_WITH_GIPK
Generating invisible primary key for a table created using CREATE TABLE... SELECT....
Definition: sql_lex.h:3040
@ BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS
Mixing transactional and non-transactional statements are unsafe if non-transactional reads or writes...
Definition: sql_lex.h:2923
@ BINLOG_STMT_UNSAFE_SYSTEM_VARIABLE
Using most system variables is unsafe, because slave may run with different options than master.
Definition: sql_lex.h:2912
@ BINLOG_STMT_UNSAFE_INSERT_IGNORE_SELECT
INSERT...IGNORE SELECT is unsafe because which rows are ignored depends on the order that rows are re...
Definition: sql_lex.h:2942
@ BINLOG_STMT_UNSAFE_MIXED_STATEMENT
Statements that read from both transactional and non-transactional tables and write to any of them ar...
Definition: sql_lex.h:2935
@ BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS
Inserting into an autoincrement column in a stored routine is unsafe.
Definition: sql_lex.h:2903
@ BINLOG_STMT_UNSAFE_SKIP_LOCKED
Definition: sql_lex.h:3010
@ BINLOG_STMT_UNSAFE_CREATE_IGNORE_SELECT
CREATE TABLE... IGNORE... SELECT is unsafe because which rows are ignored depends on the order that r...
Definition: sql_lex.h:2970
@ BINLOG_STMT_UNSAFE_ACL_TABLE_READ_IN_DML_DDL
DML or DDL statement that reads a ACL table is unsafe, because the row are read without acquiring SE ...
Definition: sql_lex.h:3031
@ BINLOG_STMT_UNSAFE_INSERT_SELECT_UPDATE
INSERT...SELECT...UPDATE is unsafe because which rows are updated depends on the order that rows are ...
Definition: sql_lex.h:2949
@ BINLOG_STMT_UNSAFE_LIMIT
SELECT..LIMIT is unsafe because the set of rows returned cannot be predicted.
Definition: sql_lex.h:2889
@ BINLOG_STMT_UNSAFE_REPLACE_SELECT
INSERT...REPLACE SELECT is unsafe because which rows are replaced depends on the order that rows are ...
Definition: sql_lex.h:2963
@ BINLOG_STMT_UNSAFE_CREATE_REPLACE_SELECT
CREATE TABLE...REPLACE... SELECT is unsafe because which rows are replaced depends on the order that ...
Definition: sql_lex.h:2977
@ BINLOG_STMT_UNSAFE_UDF
Using a UDF (user-defined function) is unsafe.
Definition: sql_lex.h:2907
@ BINLOG_STMT_UNSAFE_UPDATE_IGNORE
UPDATE...IGNORE is unsafe because which rows are ignored depends on the order that rows are updated.
Definition: sql_lex.h:2992
@ BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT
Query that writes to a table with auto_inc column after selecting from other tables are unsafe as the...
Definition: sql_lex.h:2956
@ BINLOG_STMT_UNSAFE_SYSTEM_TABLE
Access to log tables is unsafe because slave and master probably log different things.
Definition: sql_lex.h:2894
Query_tables_list & operator=(Query_tables_list &&)=default
bool has_stored_functions
Does this LEX context have any stored functions.
Definition: sql_lex.h:2801
Table_ref * query_tables
Definition: sql_lex.h:2765
bool requires_prelocking()
Definition: sql_lex.h:2853
void chop_off_not_own_tables()
Definition: sql_lex.h:2861
Table_ref * first_not_own_table()
Definition: sql_lex.h:2858
Table_ref ** query_tables_own_last
Definition: sql_lex.h:2774
bool get_using_match()
Definition: sql_lex.h:3330
uint32 binlog_stmt_flags
Bit field indicating the type of statement.
Definition: sql_lex.h:3369
bool is_query_tables_locked() const
Definition: sql_lex.h:2817
enum_lock_tables_state
Locking state of tables in this particular statement.
Definition: sql_lex.h:2815
@ LTS_LOCKED
Definition: sql_lex.h:2815
@ LTS_NOT_LOCKED
Definition: sql_lex.h:2815
void add_to_query_tables(Table_ref *table)
Definition: sql_lex.h:2849
Common base class for n-ary set operations, including unary.
Definition: query_term.h:555
Query term tree structure.
Definition: query_term.h:216
virtual Query_block * query_block() const =0
The query_block which holds the ORDER BY and LIMIT information for this set operation.
Query_term_set_op * m_parent
Back pointer to the node whose child we are, or nullptr (root term).
Definition: query_term.h:527
virtual Query_term_type term_type() const =0
Get the node tree type.
Query_term_set_op * parent() const
Getter for m_parent, q.v.
Definition: query_term.h:423
Containing class for iterator over the query term tree.
Definition: query_term.h:807
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:82
Simple intrusive linked list.
Definition: sql_list.h:48
Base class for secondary engine execution context objects.
Definition: sql_lex.h:2597
virtual ~Secondary_engine_execution_context()=default
Destructs the secondary engine execution context object.
Abstract base class for traversing the Query_block tree.
Definition: select_lex_visitor.h:40
Context object used by semijoin equality decorrelation code.
Definition: sql_resolver.cc:2399
This class represent server options as set by the parser.
Definition: sql_servers.h:71
Representation of an SQL command.
Definition: sql_cmd.h:83
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:227
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
LEX * lex
Definition: sql_class.h:1001
Class representing a table function.
Definition: table_function.h:53
Definition: sql_lex.h:308
Table_ident(Query_expression *s)
This constructor is used only for the case when we create a derived table.
Definition: sql_lex.h:329
void change_db(const char *db_name)
Definition: sql_lex.h:348
Query_expression * sel
Definition: sql_lex.h:312
Table_ident(Protocol *protocol, const LEX_CSTRING &db_arg, const LEX_CSTRING &table_arg, bool force)
Definition: sql_lex.cc:156
Table_ident(const LEX_CSTRING &table_arg)
Definition: sql_lex.h:319
bool is_table_function() const
Definition: sql_lex.h:345
bool is_derived_table() const
Definition: sql_lex.h:347
Table_ident(LEX_CSTRING &table_arg, Table_function *table_func_arg)
Definition: sql_lex.h:339
LEX_CSTRING table
Definition: sql_lex.h:311
Table_function * table_function
Definition: sql_lex.h:313
LEX_CSTRING db
Definition: sql_lex.h:310
Table_ident(const LEX_CSTRING &db_arg, const LEX_CSTRING &table_arg)
Definition: sql_lex.h:317
Definition: table.h:2904
Table_ref * first_leaf_table()
Return first leaf table of a base table or a view/derived table.
Definition: table.h:3335
Table_ref * next_leaf
Definition: table.h:3819
Used for storing information associated with generated column, default values generated from expressi...
Definition: field.h:481
Definition: visible_fields.h:98
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:110
The internal state of the syntax parser.
Definition: sql_lexer_yacc_state.h:246
Yacc_state()
Definition: sql_lexer_yacc_state.h:248
void reset()
Definition: sql_lexer_yacc_state.h:252
thr_lock_type m_lock_type
Type of lock to be used for tables being added to the statement's table list in table_factor,...
Definition: sql_lexer_yacc_state.h:321
uchar * yacc_yyvs
Bison internal semantic value stack, yyvs, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:296
enum_mdl_type m_mdl_type
The type of requested metadata lock for tables added to the statement table list.
Definition: sql_lexer_yacc_state.h:327
~Yacc_state()
Definition: sql_lexer_yacc_state.h:269
uchar * yacc_yyss
Bison internal state stack, yyss, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:290
void reset_before_substatement()
Reset part of the state which needs resetting before parsing substatement.
Definition: sql_lexer_yacc_state.h:281
uchar * yacc_yyls
Bison internal location value stack, yyls, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:302
The class hold dynamic table statistics for a table.
Definition: table_stats.h:103
void invalidate_cache(void)
Definition: table_stats.h:216
The class hold dynamic table statistics for a table.
Definition: tablespace_stats.h:64
void invalidate_cache(void)
Definition: tablespace_stats.h:111
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
Element_type & front()
Returns the first element in the deque.
Definition: mem_root_deque.h:256
void pop_front()
Removes the first element from the deque.
Definition: mem_root_deque.h:249
bool empty() const
Definition: mem_root_deque.h:462
Definition: partition_info.h:209
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
Definition: sp_head.h:124
The class represents parse-time context, which keeps track of declared variables/parameters,...
Definition: sp_pcontext.h:252
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
Acl_type
Definition: sql_lex.h:267
uint to_uint(enum_sp_type val)
Definition: sql_lex.h:250
const char * index_hint_type_name[]
Definition: sql_lex.cc:136
enum_sp_data_access
Definition: sql_lex.h:208
void print_derived_column_names(const THD *thd, String *str, const Create_col_name_list *column_names)
Prints into 'str' a comma-separated list of column names, enclosed in parenthesis.
Definition: sql_lex.cc:2192
Acl_type lex_type_to_acl_type(ulong lex_type)
Definition: sql_lex.cc:5281
#define TYPE_ENUM_LIBRARY
Definition: sql_lex.h:264
bool db_is_default_db(const char *db, size_t db_len, const THD *thd)
Definition: sql_lex.cc:2915
bool check_select_for_locking_clause(THD *)
enum_sp_type acl_type_to_enum_sp_type(Acl_type type)
Definition: sql_lex.cc:5295
sub_select_type
Definition: sql_lex.h:476
#define TYPE_ENUM_PROCEDURE
Definition: sql_lex.h:261
execute_only_in_secondary_reasons
Definition: sql_lex.h:3917
enum_alter_user_attribute
Definition: sql_lex.h:294
void binlog_unsafe_map_init()
Definition: sql_lex.cc:5136
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_lex.h:1143
longlong to_longlong(enum_sp_type val)
Definition: sql_lex.h:246
enum_view_create_mode
Definition: sql_lex.h:288
bool walk_join_list(mem_root_deque< Table_ref * > &list, std::function< bool(Table_ref *)> action)
Definition: sql_resolver.cc:2694
execute_only_in_hypergraph_reasons
Definition: sql_lex.h:3930
bool is_union() const
Definition: sql_lex.h:2545
#define TYPE_ENUM_INVALID
Definition: sql_lex.h:265
uint binlog_unsafe_map[256]
Definition: sql_lex.cc:5041
void lex_end(LEX *lex)
Call this function after preparation and execution of a query.
Definition: sql_lex.cc:534
enum_sp_type to_sp_type(longlong val)
Definition: sql_lex.h:238
Acl_type enum_sp_type_to_acl_type(enum_sp_type type)
Definition: sql_lex.cc:5309
enum_explain_type
Query_block type enum.
Definition: sql_lex.h:1149
#define TYPE_ENUM_FUNCTION
Definition: sql_lex.h:260
const LEX_STRING null_lex_str
LEX_STRING constant for null-string to be used in parser and other places.
Definition: sql_lex.cc:92
enum_sp_type
enum_sp_type defines type codes of stored programs.
Definition: sql_lex.h:225
void lex_free(void)
Definition: sql_lex.cc:165
bool is_set_operation() const
Definition: sql_lex.h:2552
constexpr const int MAX_SELECT_NESTING
Definition: sql_lex.h:140
void trim_whitespace(const CHARSET_INFO *cs, LEX_STRING *str)
Definition: sql_lex.cc:2161
bool is_lex_native_function(const LEX_STRING *name)
Check if name is a sql function.
Definition: sql_lex.cc:964
uchar index_clause_map
Definition: sql_lex.h:487
int my_sql_parser_lex(MY_SQL_PARSER_STYPE *, POS *, class THD *)
yylex() function implementation for the main parser
Definition: sql_lex.cc:1365
enum_sp_suid_behaviour
Definition: sql_lex.h:202
const size_t INITIAL_LEX_PLUGIN_LIST_SIZE
Definition: sql_lex.h:139
bool is_keyword(const char *name, size_t len)
Definition: sql_lex.cc:949
const LEX_CSTRING sp_data_access_name[]
Definition: sql_lex.h:281
enum_keep_diagnostics
Definition: sql_lex.h:194
bool lex_start(THD *thd)
Call lex_start() before every query that is to be prepared and executed.
Definition: sql_lex.cc:510
struct struct_replica_connection LEX_REPLICA_CONNECTION
@ SP_READS_SQL_DATA
Definition: sql_lex.h:212
@ SP_MODIFIES_SQL_DATA
Definition: sql_lex.h:213
@ SP_NO_SQL
Definition: sql_lex.h:211
@ SP_DEFAULT_ACCESS
Definition: sql_lex.h:209
@ SP_CONTAINS_SQL
Definition: sql_lex.h:210
@ UNSPECIFIED_TYPE
Definition: sql_lex.h:477
@ DERIVED_TABLE_TYPE
Definition: sql_lex.h:479
@ GLOBAL_OPTIONS_TYPE
Definition: sql_lex.h:478
@ TABLESAMPLE
Definition: sql_lex.h:3920
@ OUTFILE_OBJECT_STORE
Definition: sql_lex.h:3921
@ SUPPORTED_IN_PRIMARY
Definition: sql_lex.h:3918
@ CUBE
Definition: sql_lex.h:3919
@ TEMPORARY_TABLE_USAGE
Definition: sql_lex.h:3923
@ TEMPORARY_TABLE_CREATION
Definition: sql_lex.h:3922
@ QUALIFY_CLAUSE
Definition: sql_lex.h:3932
@ SUPPORTED_IN_BOTH_OPTIMIZERS
Definition: sql_lex.h:3931
@ EXPLAIN_total
fake type, total number of all valid types
@ NO_COMMENT
Not parsing comments.
Definition: sql_lex.h:3411
@ DISCARD_COMMENT
Parsing comments that need to be discarded.
Definition: sql_lex.h:3427
@ PRESERVE_COMMENT
Parsing comments that need to be preserved.
Definition: sql_lex.h:3418
@ SP_IS_SUID
Definition: sql_lex.h:205
@ SP_IS_DEFAULT_SUID
Definition: sql_lex.h:203
@ SP_IS_NOT_SUID
Definition: sql_lex.h:204
@ DA_KEEP_UNSPECIFIED
keep semantics is unspecified
Definition: sql_lex.h:199
@ DA_KEEP_DIAGNOSTICS
keep the diagnostics area
Definition: sql_lex.h:196
@ DA_KEEP_PARSE_ERROR
keep diagnostics area after parse error
Definition: sql_lex.h:198
@ DA_KEEP_COUNTS
keep @warning_count / @error_count
Definition: sql_lex.h:197
@ DA_KEEP_NOTHING
keep nothing
Definition: sql_lex.h:195
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:216
char * strmake_root(MEM_ROOT *root, const char *str, size_t len)
Definition: my_alloc.cc:286
bool change_query_result(THD *thd, Query_result_interceptor *new_result, Query_result_interceptor *old_result)
Change the Query_result object of the query block.
Definition: sql_select.cc:4274
bool optimize(THD *thd, bool finalize_access_paths)
Optimize a query block and all inner query expressions.
Definition: sql_select.cc:2115
bool check_column_privileges(THD *thd)
Check privileges for all columns referenced from query block.
Definition: sql_select.cc:2157
bool check_privileges_for_subqueries(THD *thd)
Check privileges for column references in subqueries of a query block.
Definition: sql_select.cc:2262
bool transform_scalar_subqueries_to_join_with_derived(THD *thd)
Transform eligible scalar subqueries in the SELECT list, WHERE condition, HAVING condition or JOIN co...
Definition: sql_resolver.cc:8766
Item * single_visible_field() const
Definition: sql_resolver.cc:4908
bool remove_redundant_subquery_clauses(THD *thd)
For a table subquery predicate (IN/ANY/ALL/EXISTS/etc): since it does not support LIMIT the following...
Definition: sql_resolver.cc:4018
void delete_unused_merged_columns(mem_root_deque< Table_ref * > *tables)
Delete unused columns from merged tables.
Definition: sql_resolver.cc:5314
bool check_only_full_group_by(THD *thd)
Runs checks mandated by ONLY_FULL_GROUP_BY.
Definition: sql_resolver.cc:4538
void clear_sj_expressions(NESTED_JOIN *nested_join)
Remove semijoin condition for this query block.
Definition: sql_resolver.cc:2256
bool apply_local_transforms(THD *thd, bool prune)
Does permanent transformations which are local to a query block (which do not merge it to another blo...
Definition: sql_resolver.cc:805
void replace_referenced_item(Item *const old_item, Item *const new_item)
Replace item in select list and preserve its reference count.
Definition: sql_resolver.cc:8213
bool record_join_nest_info(mem_root_deque< Table_ref * > *tables)
Record join nest info in the select block.
Definition: sql_resolver.cc:2028
bool replace_first_item_with_min_max(THD *thd, int item_no, bool use_min)
Replace the first visible item in the select list with a wrapping MIN or MAX aggregate function.
Definition: sql_resolver.cc:7722
bool limit_offset_preserves_first_row() const
Check if the LIMIT/OFFSET clause is specified in a way that makes it always preserve the first row re...
Definition: sql_resolver.cc:1416
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block)
Definition: sql_resolver.cc:2215
bool transform_grouped_to_derived(THD *thd, bool *break_off)
Minion of transform_scalar_subqueries_to_join_with_derived.
Definition: sql_resolver.cc:6654
bool decorrelate_condition(Semijoin_decorrelation &sj_decor, Table_ref *join_nest)
Decorrelate the WHERE clause or a join condition of a subquery used in an IN or EXISTS predicate.
Definition: sql_resolver.cc:2580
bool setup_conds(THD *thd)
Resolve WHERE condition and join conditions.
Definition: sql_resolver.cc:1495
bool add_ftfunc_list(List< Item_func_match > *ftfuncs)
Add full-text function elements from a list into this query block.
Definition: sql_resolver.cc:3955
bool setup_join_cond(THD *thd, mem_root_deque< Table_ref * > *tables, bool in_update)
Resolve join conditions for a join nest.
Definition: sql_resolver.cc:1556
void remove_hidden_items()
Remove hidden items from select list.
Definition: sql_resolver.cc:5358
void remap_tables(THD *thd)
Re-map table numbers for all tables in a query block.
Definition: sql_resolver.cc:1325
void repoint_contexts_of_join_nests(mem_root_deque< Table_ref * > join_list)
Go through a list of tables and join nests, recursively, and repoint its query_block pointer.
Definition: sql_resolver.cc:3970
void prune_sj_exprs(Item_func_eq *item, mem_root_deque< Table_ref * > *nest)
Recursively look for removed item inside any nested joins' sj_{inner,outer}_exprs.
Definition: sql_resolver.cc:5293
void propagate_unique_test_exclusion()
Propagate exclusion from table uniqueness test into subqueries.
Definition: sql_resolver.cc:3937
void mark_item_as_maybe_null_if_non_primitive_grouped(Item *item) const
Marks occurrences of group by fields in a function's arguments as nullable, so that we do not optimiz...
Definition: sql_resolver.cc:4894
bool convert_subquery_to_semijoin(THD *thd, Item_exists_subselect *subq_pred)
Convert a subquery predicate of this query block into a Table_ref semi-join nest.
Definition: sql_resolver.cc:2874
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block)
Fix used tables information for a subquery after query transformations.
Definition: sql_resolver.cc:2201
bool lift_fulltext_from_having_to_select_list(THD *thd)
Copies all non-aggregated calls to the full-text search MATCH function from the HAVING clause to the ...
Definition: sql_resolver.cc:9040
bool setup_wild(THD *thd)
Expand all '*' in list of expressions with the matching column references.
Definition: sql_resolver.cc:1438
bool add_inner_func_calls_to_select_list(THD *thd, Lifted_expressions_map *lifted_exprs)
Definition: sql_resolver.cc:7632
bool remove_aggregates(THD *thd, Query_block *select)
A minion of transform_grouped_to_derived.
Definition: sql_resolver.cc:6459
bool prepare_values(THD *thd)
Prepare a table value constructor query block for optimization.
Definition: sql_resolver.cc:723
bool resolve_placeholder_tables(THD *thd, bool apply_semijoin)
Resolve derived table, view, table function information for a query block.
Definition: sql_resolver.cc:1358
bool simplify_joins(THD *thd, mem_root_deque< Table_ref * > *join_list, bool top, bool in_sj, Item **new_conds, uint *changelog=nullptr)
Simplify joins replacing outer joins by inner joins whenever it's possible.
Definition: sql_resolver.cc:1745
void update_used_tables()
Update used tables information for all local expressions.
Definition: sql_resolver.cc:910
bool resolve_limits(THD *thd)
Resolve OFFSET and LIMIT clauses.
Definition: sql_resolver.cc:963
int group_list_size() const
Definition: sql_resolver.cc:4688
bool empty_order_list(Query_block *sl)
Empty the ORDER list.
Definition: sql_resolver.cc:4115
bool prepare(THD *thd, mem_root_deque< Item * > *insert_field_list)
Prepare query block for optimization.
Definition: sql_resolver.cc:182
void reset_nj_counters(mem_root_deque< Table_ref * > *join_list=nullptr)
Set NESTED_JOIN::counter=0 in all nested joins in passed list.
Definition: sql_resolver.cc:1612
bool check_view_privileges(THD *thd, Access_bitmask want_privilege_first, Access_bitmask want_privilege_next)
Check privileges for views that are merged into query block.
Definition: sql_resolver.cc:1202
bool add_inner_fields_to_select_list(THD *thd, Lifted_expressions_map *lifted_exprs, Item *selected_field_or_ref, const uint first_non_hidden)
Minion of decorrelate_derived_scalar_subquery_pre.
Definition: sql_resolver.cc:7572
bool resolve_rollup_wfs(THD *thd)
Replace group by field references inside window functions with references in the presence of ROLLUP.
Definition: sql_resolver.cc:5157
bool field_list_is_empty() const
Definition: sql_resolver.cc:4924
Item ** add_hidden_item(Item *item)
Add item to the hidden part of select list.
Definition: sql_resolver.cc:5349
void merge_contexts(Query_block *inner)
Merge name resolution context objects of a subquery into its parent.
Definition: sql_resolver.cc:3987
bool add_inner_exprs_to_group_by(THD *thd, List_iterator< Item > &inner_exprs, Item *selected_item, bool *selected_expr_added_to_group_by, mem_root_deque< Item * > *exprs_added_to_group_by)
Run through the inner expressions and add them to the block's GROUP BY if not already present.
Definition: sql_resolver.cc:7517
bool transform_table_subquery_to_join_with_derived(THD *thd, Item_exists_subselect *subq_pred)
Replace a table subquery ([NOT] {IN, EXISTS}, $cmp$ ALL, $cmp$ ANY) with a join to a derived table.
Definition: sql_resolver.cc:5500
bool flatten_subqueries(THD *thd)
Convert semi-join subquery predicates into semi-join join nests.
Definition: sql_resolver.cc:3700
bool replace_subquery_in_expr(THD *thd, Item::Css_info *subquery, Table_ref *tr, Item **expr)
A minion of transform_scalar_subqueries_to_join_with_derived.
Definition: sql_resolver.cc:7153
size_t num_visible_fields() const
Definition: sql_resolver.cc:4920
ORDER * find_in_group_list(Item *item, int *rollup_level) const
Finds a group expression matching the given item, or nullptr if none.
Definition: sql_resolver.cc:4652
bool resolve_table_value_constructor_values(THD *thd)
Resolve the rows of a table value constructor and aggregate the type of each column across rows.
Definition: sql_resolver.cc:5374
bool merge_derived(THD *thd, Table_ref *derived_table)
Merge derived table into query block.
Definition: sql_resolver.cc:3337
bool setup_tables(THD *thd, Table_ref *tables, bool select_insert)
Resolve and prepare information about tables for one query block.
Definition: sql_resolver.cc:1239
bool supported_correlated_scalar_subquery(THD *thd, Item::Css_info *subquery, Item **lifted_where)
Called when the scalar subquery is correlated.
Definition: sql_resolver.cc:8500
bool replace_item_in_expression(Item **expr, bool was_hidden, Item::Item_replacement *info, Item_transformer transformer)
Minion of transform_grouped_to_derived.
Definition: sql_resolver.cc:6576
bool setup_order_final(THD *thd)
Do final setup of ORDER BY clause, after the query block is fully resolved.
Definition: sql_resolver.cc:4572
bool setup_counts_over_partitions(THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_expressions, mem_root_deque< Item * > &exprs_added_to_group_by, uint hidden_fields)
Add all COUNT(0) to SELECT list of the derived table to be used for cardinality checking of the trans...
Definition: sql_resolver.cc:7420
bool nest_derived(THD *thd, Item *join_cond, mem_root_deque< Table_ref * > *join_list, Table_ref *new_derived_table)
Push the generated derived table to the correct location inside a join nest.
Definition: sql_resolver.cc:7306
bool decorrelate_derived_scalar_subquery_post(THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs, bool added_card_check, size_t added_window_card_checks)
See explanation in companion method decorrelate_derived_scalar_subquery_pre.
Definition: sql_resolver.cc:8138
bool allocate_grouping_sets(THD *thd)
Initializes the grouping set if the query block includes GROUP BY modifiers.
Definition: sql_resolver.cc:2625
bool setup_group(THD *thd)
Resolve and set up the GROUP BY list.
Definition: sql_resolver.cc:4619
Table_ref * synthesize_derived(THD *thd, Query_expression *unit, Item *join_cond, bool left_outer, bool use_inner_join)
Create a new Table_ref object for this query block, for either: 1) a derived table which will replace...
Definition: sql_resolver.cc:6363
bool decorrelate_derived_scalar_subquery_pre(THD *thd, Table_ref *derived, Item::Css_info *subquery, Item *lifted_where, Lifted_expressions_map *lifted_where_expressions, bool *added_card_check, size_t *added_window_card_checks)
We have a correlated scalar subquery, so we must do several things:
Definition: sql_resolver.cc:7812
bool push_conditions_to_derived_tables(THD *thd)
Pushes parts of the WHERE condition of this query block to materialized derived tables.
Definition: sql_resolver.cc:674
bool resolve_rollup(THD *thd)
Resolve items in SELECT list and ORDER BY list for rollup processing.
Definition: sql_resolver.cc:5062
bool has_wfs()
Definition: sql_resolver.cc:4696
bool transform_subquery_to_derived(THD *thd, Table_ref **out_tl, Query_expression *subs_query_expression, Item_subselect *subq, bool use_inner_join, bool reject_multiple_rows, Item::Css_info *subquery, Item *lifted_where_cond)
Converts a subquery to a derived table and inserts it into the FROM clause of the owning query block.
Definition: sql_resolver.cc:8245
bool build_sj_cond(THD *thd, NESTED_JOIN *nested_join, Query_block *subq_query_block, table_map outer_tables_map, Item **sj_cond, bool *simple_const)
Build semijoin condition for th query block.
Definition: sql_resolver.cc:2283
Item * resolve_rollup_item(THD *thd, Item *item)
Resolve an item (and its tree) for rollup processing by replacing items matching grouped expressions ...
Definition: sql_resolver.cc:4970
bool populate_grouping_sets(THD *thd)
Populates the grouping sets if the query block includes non-primitive grouping.
Definition: sql_resolver.cc:2673
bool add_joined_table(Table_ref *table)
Add a table to the current join list.
Definition: sql_parse.cc:6383
void set_lock_for_tables(thr_lock_type lock_type)
Set lock for all tables in current query block.
Definition: sql_parse.cc:6414
bool find_common_table_expr(THD *thd, Table_ident *table_id, Table_ref *tl, Parse_context *pc, bool *found)
Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name,...
Definition: sql_parse.cc:5797
Table_ref * end_nested_join()
End a nested join table list.
Definition: sql_parse.cc:6298
bool init_nested_join(THD *thd)
Initialize a new table list for a nested join.
Definition: sql_parse.cc:6271
Table_ref * nest_join(THD *thd, Query_block *select, Table_ref *embedding, mem_root_deque< Table_ref * > *jlist, size_t table_cnt, const char *legend)
Plumbing for nest_last_join, q.v.
Definition: sql_parse.cc:6325
Table_ref * add_table_to_list(THD *thd, Table_ident *table, const char *alias, ulong table_options, thr_lock_type flags=TL_UNLOCK, enum_mdl_type mdl_type=MDL_SHARED_READ, List< Index_hint > *hints=nullptr, List< String > *partition_names=nullptr, LEX_STRING *option=nullptr, Parse_context *pc=nullptr)
Add a table to list of used tables.
Definition: sql_parse.cc:6008
void set_lock_for_table(const Lock_descriptor &descriptor, Table_ref *table)
Definition: sql_parse.cc:6391
Table_ref * nest_last_join(THD *thd, size_t table_cnt=2)
Nest last join operations.
Definition: sql_parse.cc:6365
struct PSI_digest_locker PSI_digest_locker
Definition: psi_statement_bits.h:112
static int flags[50]
Definition: hp_test1.cc:40
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:721
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:437
#define T
Definition: jit_executor_value.cc:373
constexpr const LEX_CSTRING EMPTY_CSTR
Definition: lex_string.h:48
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:47
A better implementation of the UNIX ctype(3) library.
Various macros useful for communicating with memory debuggers, such as Valgrind.
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:71
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:480
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1141
Header for compiler-dependent features.
#define MY_ASSERT_UNREACHABLE()
Definition: my_compiler.h:78
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
#define DBUG_TRACE
Definition: my_dbug.h:146
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
#define MYF(v)
Definition: my_inttypes.h:97
uint32_t uint32
Definition: my_inttypes.h:67
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_UPDATE
Definition: my_sqlcommand.h:51
@ SQLCOM_LOAD
Definition: my_sqlcommand.h:77
@ SQLCOM_INSERT
Definition: my_sqlcommand.h:52
@ SQLCOM_INSERT_SELECT
Definition: my_sqlcommand.h:53
@ SQLCOM_REPLACE
Definition: my_sqlcommand.h:87
@ SQLCOM_UPDATE_MULTI
Definition: my_sqlcommand.h:122
@ SQLCOM_REPLACE_SELECT
Definition: my_sqlcommand.h:88
Common header for many mysys elements.
uint64_t nesting_map
Definition: my_table_map.h:31
uint64_t table_map
Definition: my_table_map.h:30
uint32 my_thread_id
Definition: my_thread_local.h:34
static bool backup
Definition: myisampack.cc:198
static bool column_names
Definition: mysql.cc:174
static const CHARSET_INFO * charset_info
Definition: mysql.cc:248
Common definition between mysql server & client.
char * octet2hex(char *to, const char *str, unsigned int len)
static char * where
Definition: mysqldump.cc:153
const char * collation
Definition: audit_api_message_emit.cc:184
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
Definition: commit_order_queue.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:39
size_t size(const char *const c)
Definition: base64.h:46
Definition: options.cc:57
const char * db_name
Definition: rules_table_service.cc:55
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2872
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2880
olap_type
Definition: olap.h:31
@ UNSPECIFIED_OLAP_TYPE
Definition: olap.h:31
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:61
@ CTX_NONE
Empty value.
Definition: parse_tree_node_base.h:62
#define UNCACHEABLE_DEPENDENT
Definition: parse_tree_node_base.h:50
enum_yes_no_unknown
Definition: parser_yystype.h:167
struct result result
Definition: result.h:34
Performance schema instrumentation interface.
#define SELECT_DISTINCT
Definition: query_options.h:52
#define OPTION_NO_CONST_TABLES
Definition: query_options.h:78
Query_term_type
This class hierarchy is used to represent SQL structures between <query expression> and <query specif...
Definition: query_term.h:96
@ QT_UNARY
Represents a query primary with parentesized query expression body with order by clause and/or limit/...
Definition: query_term.h:103
@ QT_EXCEPT
Definition: query_term.h:107
@ QT_UNION
Definition: query_term.h:108
@ QT_INTERSECT
Represents the three set operations.
Definition: query_term.h:106
@ QT_QUERY_BLOCK
Represents Query specification, table value constructor and explicit table.
Definition: query_term.h:99
Visit_leaves
Query term iterator template argument type: whether to visit leaf nodes.
Definition: query_term.h:114
@ VL_VISIT_LEAVES
Definition: query_term.h:114
Visit_order
Query term iterator template argument type: how to visit nodes in tree.
Definition: query_term.h:112
@ QTC_POST_ORDER
Definition: query_term.h:112
required string type
Definition: replication_group_member_actions.proto:34
repeated Action action
Definition: replication_group_member_actions.proto:43
"public" interface to sys_var - server configuration variables.
enum_var_type
Definition: set_var.h:92
enum_tx_isolation
Definition: handler.h:3222
@ ISO_REPEATABLE_READ
Definition: handler.h:3225
index_hint_type
Definition: table.h:1416
role_enum
Definition: sql_admin.h:255
my_lex_states
Definition: sql_chars.h:37
File containing constants that can be used throughout the server.
constexpr const uint8_t CONTEXT_ANALYSIS_ONLY_PREPARE
Don't evaluate this subquery during statement prepare even if it's a constant one.
Definition: sql_const.h:174
enum_walk
Enumeration for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:289
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:307
constexpr const uint8_t CONTEXT_ANALYSIS_ONLY_VIEW
Special Query_block::prepare mode: changing of query is prohibited.
Definition: sql_const.h:182
enum_condition_context
Enumeration for Query_block::condition_context.
Definition: sql_const.h:313
Contains classes representing SQL-data change statements.
enum_duplicates
Definition: sql_data_change.h:48
bool walk_item(Item *item, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3520
#define IL_GTE_REPEATABLE
Definition: sql_lex.h:3229
void get_select_options_str(ulonglong options, std::string *str)
Definition: sql_lex.cc:5259
#define TRX_CACHE_EMPTY
Definition: sql_lex.h:3223
#define IL_LT_REPEATABLE
Definition: sql_lex.h:3227
void assert_consistent_hidden_flags(const mem_root_deque< Item * > &fields, Item *item, bool hidden)
In debug mode, verify that we're not adding an item twice to the fields list with inconsistent hidden...
Definition: sql_lex.h:5195
#define BINLOG_DIRECT_OFF
Definition: sql_lex.h:3220
bool WalkQueryExpression(Query_expression *query_expr, enum_walk walk, T &&functor)
Definition: sql_lex.h:5233
#define BINLOG_DIRECT_ON
Definition: sql_lex.h:3217
bool is_invalid_string(const LEX_CSTRING &string_val, const CHARSET_INFO *charset_info)
(End of group GROUP_PARSER)
Definition: sql_lex.h:5142
bool accept_for_order(SQL_I_List< ORDER > orders, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3526
#define TRX_CACHE_NOT_EMPTY
Definition: sql_lex.h:3225
bool accept_for_join(mem_root_deque< Table_ref * > *tables, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3548
bool accept_table(Table_ref *t, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3556
enum_comment_state
The state of the lexical parser, when parsing comments.
Definition: sql_lexer_input_stream.h:47
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:106
@ MDL_SHARED_READ
Definition: sql_lexer_yacc_state.h:169
static const Query_options options
Definition: sql_show_processlist.cc:69
Our own string classes, used pervasively throughout the executor.
size_t convert_to_printable(char *to, size_t to_len, const char *from, size_t from_len, const CHARSET_INFO *from_cs, size_t nbytes=0)
Convert string to printable ASCII string.
Definition: sql_string.cc:1025
bool validate_string(const CHARSET_INFO *cs, const char *str, size_t length, size_t *valid_length, bool *length_error)
Check if an input byte sequence is a valid character string of a given charset.
Definition: sql_string.cc:1131
case opt name
Definition: sslopt-case.h:29
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:238
Definition: m_ctype.h:421
const char * csname
Definition: m_ctype.h:426
Definition: handler.h:3831
Struct to hold information about the table that should be created.
Definition: handler.h:3238
Minion class under Collect_scalar_subquery_info ("Css").
Definition: item.h:2945
Definition: item.h:3201
Definition: table.h:2727
Definition: sql_lex.h:472
bool all
Definition: sql_lex.h:473
Structure to hold parameters for CHANGE REPLICATION SOURCE, START REPLICA, and STOP REPLICA.
Definition: sql_lex.h:365
void initialize()
Initializes everything to zero/NULL/empty.
Definition: sql_lex.cc:4999
uint port
Definition: sql_lex.h:374
const char * channel
Definition: sql_lex.h:381
bool replica_until
Definition: sql_lex.h:387
char * bind_addr
Definition: sql_lex.h:373
enum LEX_SOURCE_INFO::@186 ssl_verify_server_cert
char * network_namespace
Definition: sql_lex.h:373
char * ssl_crl
Definition: sql_lex.h:403
char * public_key_path
Definition: sql_lex.h:414
char * view_id
Definition: sql_lex.h:380
enum LEX_SOURCE_INFO::@186 m_source_connection_auto_failover
ulong relay_log_pos
Definition: sql_lex.h:416
char * tls_version
Definition: sql_lex.h:403
char * relay_log_name
Definition: sql_lex.h:415
enum LEX_SOURCE_INFO::@186 heartbeat_opt
@ LEX_MI_ANONYMOUS_TO_GTID_UUID
Definition: sql_lex.h:456
@ LEX_MI_ANONYMOUS_TO_GTID_LOCAL
Definition: sql_lex.h:455
@ LEX_MI_ANONYMOUS_TO_GTID_UNCHANGED
Definition: sql_lex.h:453
@ LEX_MI_ANONYMOUS_TO_GTID_OFF
Definition: sql_lex.h:454
int sql_delay
Definition: sql_lex.h:376
float heartbeat_period
Definition: sql_lex.h:375
char * tls_ciphersuites_string
Definition: sql_lex.h:413
ulong server_id
Definition: sql_lex.h:378
enum LEX_SOURCE_INFO::@186 m_gtid_only
ulong retry_count
Definition: sql_lex.h:378
char * ssl_ca
Definition: sql_lex.h:402
ulonglong pos
Definition: sql_lex.h:377
uint connect_retry
Definition: sql_lex.h:374
LEX_SOURCE_INFO & operator=(const LEX_SOURCE_INFO &)
char * ssl_cert
Definition: sql_lex.h:402
Prealloced_array< ulong, 2 > repl_ignore_server_ids
Definition: sql_lex.h:419
@ LEX_MI_UNCHANGED
Definition: sql_lex.h:395
@ LEX_MI_DISABLE
Definition: sql_lex.h:396
@ LEX_MI_ENABLE
Definition: sql_lex.h:397
char * ssl_key
Definition: sql_lex.h:402
@ UNTIL_SQL_AFTER_GTIDS
Definition: sql_lex.h:384
@ UNTIL_SQL_BEFORE_GTIDS
Definition: sql_lex.h:383
enum LEX_SOURCE_INFO::@186 port_opt
void set_unspecified()
Sets all fields to their "unspecified" value.
Definition: sql_lex.cc:5036
char * user
Definition: sql_lex.h:373
int require_row_format
Flag indicating if row format should be enforced for this channel event stream.
Definition: sql_lex.h:434
uint zstd_compression_level
Definition: sql_lex.h:418
char * log_file_name
Definition: sql_lex.h:373
enum_tls_ciphersuites
Definition: sql_lex.h:407
@ SPECIFIED_NULL
Definition: sql_lex.h:409
@ SPECIFIED_STRING
Definition: sql_lex.h:410
@ UNSPECIFIED
Definition: sql_lex.h:408
char * password
Definition: sql_lex.h:373
const char * privilege_checks_hostname
Definition: sql_lex.h:429
enum LEX_SOURCE_INFO::@188 assign_gtids_to_anonymous_transactions_type
char * host
Definition: sql_lex.h:373
enum LEX_SOURCE_INFO::@186 get_public_key
char * compression_algorithm
Definition: sql_lex.h:417
bool privilege_checks_none
Flag that is set to true whenever PRIVILEGE_CHECKS_USER is set to NULL as a part of a CHANGE REPLICAT...
Definition: sql_lex.h:424
char * ssl_cipher
Definition: sql_lex.h:402
enum enum_tls_ciphersuites tls_ciphersuites
Definition: sql_lex.h:412
char * gtid
Definition: sql_lex.h:379
@ LEX_MI_PK_CHECK_OFF
Definition: sql_lex.h:448
@ LEX_MI_PK_CHECK_STREAM
Definition: sql_lex.h:446
@ LEX_MI_PK_CHECK_UNCHANGED
Definition: sql_lex.h:445
@ LEX_MI_PK_CHECK_ON
Definition: sql_lex.h:447
@ LEX_MI_PK_CHECK_GENERATE
Definition: sql_lex.h:449
enum LEX_SOURCE_INFO::@185 gtid_until_condition
LEX_SOURCE_INFO()
Definition: sql_lex.h:370
enum LEX_SOURCE_INFO::@186 retry_count_opt
bool until_after_gaps
Definition: sql_lex.h:386
enum LEX_SOURCE_INFO::@186 auto_position
LEX_SOURCE_INFO(const LEX_SOURCE_INFO &)
enum LEX_SOURCE_INFO::@186 ssl
enum LEX_SOURCE_INFO::@187 require_table_primary_key_check
Identifies what is the slave policy on primary keys in tables.
const char * assign_gtids_to_anonymous_transactions_manual_uuid
Definition: sql_lex.h:459
char * ssl_crlpath
Definition: sql_lex.h:403
bool for_channel
Definition: sql_lex.h:388
enum LEX_SOURCE_INFO::@186 repl_ignore_server_ids_opt
char * ssl_capath
Definition: sql_lex.h:402
const char * privilege_checks_username
Username and hostname parts of the PRIVILEGE_CHECKS_USER, when it's set to a user.
Definition: sql_lex.h:429
Definition: table.h:2771
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3987
bool export_result_to_object_storage() const
Definition: sql_lex.h:4169
execute_only_in_secondary_reasons get_not_supported_in_primary_reason() const
Definition: sql_lex.h:4196
void set_uncacheable(Query_block *curr_query_block, uint8 cause)
Set the current query as uncacheable.
Definition: sql_lex.h:4692
LEX_USER * grant_user
Definition: sql_lex.h:4090
bool binlog_need_explicit_defaults_ts
Definition: sql_lex.h:4609
uint grant_tot_col
Definition: sql_lex.h:4341
LEX_STRING prepared_stmt_code
Definition: sql_lex.h:4410
const char * x509_issuer
Definition: sql_lex.h:4083
bool all_privileges
Definition: sql_lex.h:4418
bool is_exec_started() const
Definition: sql_lex.h:4506
bool use_only_table_context
During name resolution search only in the table list given by Name_resolution_context::first_name_res...
Definition: sql_lex.h:4594
bool ignore_unknown_user
refers to optional IGNORE UNKNOWN USER clause in REVOKE sql.
Definition: sql_lex.h:4371
std::vector< uint > reparse_derived_table_params_at
If currently re-parsing a condition that is being pushed down to a derived table, this has the positi...
Definition: sql_lex.h:4330
void restore_backup_query_tables_list(Query_tables_list *backup)
Definition: sql_lex.cc:4313
execute_only_in_secondary_reasons m_execute_only_in_secondary_engine_reason
Definition: sql_lex.h:4004
uint8 create_view_check
Definition: sql_lex.h:4352
Prealloced_array< plugin_ref, INITIAL_LEX_PLUGIN_LIST_SIZE > Plugins_array
Definition: sql_lex.h:4102
bool new_top_level_query()
Create top-level query expression and query block.
Definition: sql_lex.cc:778
bool need_correct_ident()
Definition: sql_lex.cc:3805
execute_only_in_hypergraph_reasons m_execute_only_in_hypergraph_reason
Definition: sql_lex.h:4012
bool can_execute_only_in_hypergraph_optimizer() const
Definition: sql_lex.h:4217
LEX_ALTER alter_password
Definition: sql_lex.h:4091
bool m_broken
see mark_broken()
Definition: sql_lex.h:4424
const char * ssl_cipher
Definition: sql_lex.h:4083
bool table_or_sp_used()
Definition: sql_lex.cc:4329
Query_block * new_set_operation_query(Query_block *curr_query_block)
Create query block and attach it to the current query expression.
Definition: sql_lex.cc:702
void first_lists_tables_same()
Definition: sql_lex.cc:4203
bool validate_use_in_old_optimizer()
Validates if a query can run with the old optimizer.
Definition: sql_lex.cc:5237
Secondary_engine_execution_context * m_secondary_engine_context
Context object used by secondary storage engines to store query state during optimization and executi...
Definition: sql_lex.h:4812
bool was_replication_command_executed() const
Definition: sql_lex.h:4846
LEX_CSTRING prepared_stmt_name
Definition: sql_lex.h:4405
List< Name_resolution_context > context_stack
Definition: sql_lex.h:4263
bool autocommit
Definition: sql_lex.h:4373
Table_ref * insert_table
Table being inserted into (may be a view)
Definition: sql_lex.h:4106
void destroy()
Destroy contained objects, but not the LEX object itself.
Definition: sql_lex.h:4622
Query_result * result
Definition: sql_lex.h:4086
void destroy_values_map()
Definition: sql_lex.h:4156
void set_was_replication_command_executed()
Definition: sql_lex.h:4850
void set_current_query_block(Query_block *select)
Definition: sql_lex.h:4027
uint start_transaction_opt
Definition: sql_lex.h:4349
void new_static_query(Query_expression *sel_query_expression, Query_block *select)
Create query expression and query block in existing memory objects.
Definition: sql_lex.cc:810
bool deny_window_function(Query_block *qb) const
We have detected the presence of an alias of a window function with a window on query block qb.
Definition: sql_lex.h:4557
HA_CHECK_OPT check_opt
Definition: sql_lex.h:4267
bool drop_if_exists
Definition: sql_lex.h:4358
Table_ref * unlink_first_table(bool *link_to_local)
Definition: sql_lex.cc:4153
bool is_metadata_used() const
Check if the current statement uses meta-data (uses a table or a stored routine).
Definition: sql_lex.h:4545
bool is_lex_started
Definition: sql_lex.h:4596
bool is_explain() const
Definition: sql_lex.h:4034
char * to_log
Definition: sql_lex.h:4082
bool no_write_to_binlog
Definition: sql_lex.h:4374
bool drop_temporary
Definition: sql_lex.h:4372
void insert_values_map(Item_field *f1, Field *f2)
Definition: sql_lex.h:4151
Plugins_array plugins
Definition: sql_lex.h:4103
List< LEX_USER > * default_roles
Definition: sql_lex.h:4125
bool m_has_udf
True if statement references UDF functions.
Definition: sql_lex.h:4389
void mark_broken(bool broken=true)
Certain permanent transformations (like in2exists), if they fail, may leave the LEX in an inconsisten...
Definition: sql_lex.h:4482
bool has_external_tables() const
Definition: sql_lex.h:4401
bool is_ignore() const
Definition: sql_lex.h:4395
void set_has_external_tables()
Definition: sql_lex.h:4400
Alter_info * alter_info
Definition: sql_lex.h:4403
const char * stmt_definition_end
Definition: sql_lex.h:4586
void set_exec_completed()
Definition: sql_lex.h:4519
List< LEX_CSTRING > dynamic_privileges
Definition: sql_lex.h:4124
ulonglong m_statement_options
Statement context for Query_block::make_active_options.
Definition: sql_lex.h:4452
List< LEX_COLUMN > columns
Definition: sql_lex.h:4123
void cleanup_after_one_table_open()
Definition: sql_lex.cc:4272
void reset_has_external_tables()
Definition: sql_lex.h:4399
Query_expression * unit
Outer-most query expression.
Definition: sql_lex.h:3990
bool verbose
Definition: sql_lex.h:4374
enum_view_create_mode create_view_mode
Definition: sql_lex.h:4336
bool has_values_map() const
Definition: sql_lex.h:4173
Opt_hints_global * opt_hints_global
Definition: sql_lex.h:4098
void set_splitting_window_expression(bool v)
Definition: sql_lex.h:4072
bool make_sql_cmd(Parse_tree_root *parse_tree)
Uses parse_tree to instantiate an Sql_cmd object and assigns it to the Lex.
Definition: sql_lex.cc:5083
List< LEX_USER > users_list
Definition: sql_lex.h:4122
bool can_execute_only_in_secondary_engine() const
Definition: sql_lex.h:4181
bool is_crossed_connection_memory_status_limit() const
Definition: sql_lex.h:4524
List< Item_param > param_list
List of placeholders ('?') for parameters of a prepared statement.
Definition: sql_lex.h:4147
bool grant_if_exists
refers to optional IF EXISTS clause in REVOKE sql.
Definition: sql_lex.h:4364
bool splitting_window_expression() const
Definition: sql_lex.h:4068
dd::info_schema::Table_statistics m_IS_table_stats
IS schema queries read some dynamic table statistics from SE.
Definition: sql_lex.h:4797
LEX_RESET_REPLICA reset_replica_info
Definition: sql_lex.h:4274
enum enum_duplicates duplicates
Definition: sql_lex.h:4333
bool is_single_level_stmt()
check if the statement is a single-level join
Definition: sql_lex.h:4776
bool m_extended_show
Definition: sql_lex.h:4376
USER_RESOURCES mqh
Definition: sql_lex.h:4273
bool using_hypergraph_optimizer() const
Whether the currently-running statement should be prepared and executed with the hypergraph optimizer...
Definition: sql_lex.h:4045
bool only_view
Definition: sql_lex.h:4567
bool save_cmd_properties(THD *thd)
Definition: sql_lex.h:4718
sp_pcontext * sp_current_parsing_ctx
Current SP parsing context.
Definition: sql_lex.h:4447
bool will_contextualize
Used to inform the parser whether it should contextualize the parse tree.
Definition: sql_lex.h:4615
st_sp_chistics sp_chistics
Definition: sql_lex.h:4565
KEY_CREATE_INFO key_create_info
Definition: sql_lex.h:4269
enum enum_tx_isolation tx_isolation
Definition: sql_lex.h:4334
void set_sp_current_parsing_ctx(sp_pcontext *ctx)
Definition: sql_lex.h:4539
uint32 next_binlog_file_nr
Definition: sql_lex.h:4421
bool check_preparation_invalid(THD *thd)
Check whether preparation state for prepared statement is invalid.
Definition: sql_lex.cc:844
void set_execute_only_in_hypergraph_optimizer(bool execute_in_hypergraph_optimizer_param, execute_only_in_hypergraph_reasons reason)
Definition: sql_lex.h:4220
dd::info_schema::Tablespace_statistics m_IS_tablespace_stats
Definition: sql_lex.h:4798
const char * get_only_supported_in_hypergraph_reason_str() const
Definition: sql_lex.h:4228
sp_pcontext * get_sp_current_parsing_ctx()
Definition: sql_lex.h:4537
LEX_STRING binlog_stmt_arg
Argument of the BINLOG event statement.
Definition: sql_lex.h:4087
Query_block * new_query(Query_block *curr_query_block)
Create query expression object that contains one query block.
Definition: sql_lex.cc:643
THD * thd
Definition: sql_lex.h:4095
bool rewrite_required
Definition: sql_lex.h:4857
bool m_splitting_window_expression
Definition: sql_lex.h:4015
bool contains_plaintext_password
Definition: sql_lex.h:4419
LEX_STRING name
Definition: sql_lex.h:4080
uint8 create_view_algorithm
Definition: sql_lex.h:4351
LEX_SOURCE_INFO mi
Definition: sql_lex.h:4270
ulong max_execution_time
Definition: sql_lex.h:4603
void restore_cmd_properties()
Definition: sql_lex.h:4710
bool grant_privilege
Set to true when GRANT ... GRANT OPTION ... TO ... is used (vs.
Definition: sql_lex.h:4348
bool m_exec_completed
Set to true when execution is completed, ie optimization has been done and execution is successful or...
Definition: sql_lex.h:4434
LEX_STRING ident
Definition: sql_lex.h:4089
bool m_can_execute_only_in_secondary_engine
Definition: sql_lex.h:4002
ulonglong bulk_insert_row_cnt
Definition: sql_lex.h:4127
void set_has_udf()
Definition: sql_lex.h:4397
bool has_udf() const
Definition: sql_lex.h:4398
List< Item_func_set_user_var > set_var_list
Definition: sql_lex.h:4137
uint8 create_view_suid
Definition: sql_lex.h:4571
bool push_context(Name_resolution_context *context)
Definition: sql_lex.h:4750
void pop_context()
Definition: sql_lex.h:4754
bool m_was_replication_command_executed
Definition: sql_lex.h:4843
enum enum_yes_no_unknown tx_chain tx_release
Definition: sql_lex.h:4378
void clear_privileges()
Definition: sql_lex.cc:3598
LEX()
Definition: sql_lex.cc:3690
partition_info * part_info
Definition: sql_lex.h:4114
bool m_using_hypergraph_optimizer
Definition: sql_lex.h:4077
char * help_arg
Definition: sql_lex.h:4081
Server_options server_options
Definition: sql_lex.h:4272
bool copy_db_to(char const **p_db, size_t *p_db_length) const
This method should be called only during parsing.
Definition: sql_lex.cc:3836
enum_alter_user_attribute alter_user_attribute
Definition: sql_lex.h:4092
bool m_can_execute_only_in_hypergraph_optimizer
Definition: sql_lex.h:4011
std::map< Item_field *, Field * >::iterator end_values_map()
Definition: sql_lex.h:4177
List< Item > purge_value_list
Definition: sql_lex.h:4130
Query_block * current_query_block() const
Definition: sql_lex.h:4018
std::map< Item_field *, Field * > * insert_update_values_map
Definition: sql_lex.h:4247
bool ignore
Definition: sql_lex.h:4390
Name_resolution_context * current_context()
Definition: sql_lex.h:4762
enum SSL_type ssl_type
Definition: sql_lex.h:4332
bool is_explain_analyze
Definition: sql_lex.h:4035
HA_CREATE_INFO * create_info
Definition: sql_lex.h:4268
void set_using_hypergraph_optimizer(bool use_hypergraph)
Definition: sql_lex.h:4049
void assert_ok_set_current_query_block()
Definition: sql_lex.cc:386
Query_block * new_empty_query_block()
Create an empty query block within this LEX object.
Definition: sql_lex.cc:586
bool in_update_value_clause
Set to true while resolving values in ON DUPLICATE KEY UPDATE clause.
Definition: sql_lex.h:4598
Query_block * all_query_blocks_list
List of all query blocks.
Definition: sql_lex.h:3993
void release_plugins()
Definition: sql_lex.cc:545
uint reparse_common_table_expr_at
If currently re-parsing a CTE's definition, this is the offset in bytes of that definition in the ori...
Definition: sql_lex.h:4319
bool safe_to_cache_query
Whether this query will return the same answer every time, given unchanged data.
Definition: sql_lex.h:4385
sp_name * spname
Definition: sql_lex.h:4416
bool prepared_stmt_code_is_varref
Definition: sql_lex.h:4412
void set_ignore(bool ignore_param)
Definition: sql_lex.h:4396
my_thread_id show_profile_query_id
QUERY ID for SHOW PROFILE.
Definition: sql_lex.h:4339
List< set_var_base > var_list
Definition: sql_lex.h:4136
bool reparse_derived_table_condition
If currently re-parsing a condition which is pushed down to a derived table, this will be set to true...
Definition: sql_lex.h:4324
LEX_STRING alter_user_comment_text
Definition: sql_lex.h:4093
bool is_ps_or_view_context_analysis()
Definition: sql_lex.h:4670
bool m_crossed_connection_memory_status_limit
Set to true when execution crosses connection_memory_status_limit.
Definition: sql_lex.h:4442
Query_block * query_block
First query block.
Definition: sql_lex.h:3992
ulonglong statement_options()
Gets the options that have been set for this statement.
Definition: sql_lex.h:4462
bool which_check_option_applicable()
Definition: sql_lex.h:4733
void set_execute_only_in_secondary_engine(const bool execute_only_in_secondary_engine_param, execute_only_in_secondary_reasons reason)
Definition: sql_lex.h:4185
bool set_wild(LEX_STRING)
Definition: sql_lex.cc:4990
uint grant
Definition: sql_lex.h:4341
bool is_crossed_global_connection_memory_status_limit() const
Definition: sql_lex.h:4521
enum_keep_diagnostics keep_diagnostics
Definition: sql_lex.h:4420
bool is_rewrite_required()
Definition: sql_lex.h:4862
Table_ref * insert_table_leaf
Leaf table being inserted into (always a base table)
Definition: sql_lex.h:4108
LEX_USER * definer
Definition: sql_lex.h:4120
void set_rewrite_required()
Definition: sql_lex.h:4860
List< Item > kill_value_list
Definition: sql_lex.h:4133
const char * get_not_supported_in_primary_reason_str()
Definition: sql_lex.h:4200
uint replica_thd_opt
Definition: sql_lex.h:4349
bool m_has_external_tables
True if query has at least one external table.
Definition: sql_lex.h:4392
void restore_properties_for_insert()
Definition: sql_lex.h:4712
void clear_values_map()
Definition: sql_lex.h:4163
void set_secondary_engine_execution_context(Secondary_engine_execution_context *context)
Sets the secondary engine execution context for this statement.
Definition: sql_lex.cc:5229
bool is_broken() const
Definition: sql_lex.h:4473
bool sp_lex_in_use
Definition: sql_lex.h:4417
List< LEX_STRING > prepared_stmt_params
Definition: sql_lex.h:4414
LEX_REPLICA_CONNECTION replica_connection
Definition: sql_lex.h:4271
Secondary_engine_execution_context * secondary_engine_execution_context() const
Gets the secondary engine execution context for this statement.
Definition: sql_lex.h:4818
st_parsing_options parsing_options
Definition: sql_lex.h:4402
int select_number
Number of query block (by EXPLAIN)
Definition: sql_lex.h:4350
void add_statement_options(ulonglong options)
Add options to values of m_statement_options.
Definition: sql_lex.h:4470
uint profile_options
Definition: sql_lex.h:4340
Query_expression * create_query_expr_and_block(THD *thd, Query_block *current_query_block, Item *where_clause, Item *having_clause, enum_parsing_context ctx)
Create query expression under current_query_block and a query block under the new query expression.
Definition: sql_lex.cc:596
nesting_map m_deny_window_func
Windowing functions are not allowed in HAVING - in contrast to grouped aggregate functions,...
Definition: sql_lex.h:4298
LEX_GRANT_AS grant_as
Definition: sql_lex.h:4094
String * wild
Definition: sql_lex.h:4085
bool expr_allows_subquery
Definition: sql_lex.h:4313
void reset()
Reset query context to initial state.
Definition: sql_lex.cc:409
bool m_exec_started
Set to true when execution has started (after parsing, tables opened and query preparation is complet...
Definition: sql_lex.h:4429
void clear_execution()
Clear execution state for a statement after it has been prepared or executed, and before it is (re-)e...
Definition: sql_lex.cc:557
bool locate_var_assignment(const Name_string &name)
Locate an assignment to a user variable with a given name, within statement.
Definition: sql_lex.cc:4346
Sql_cmd * m_sql_cmd
Definition: sql_lex.h:4305
execute_only_in_hypergraph_reasons get_only_supported_in_hypergraph_reason() const
Definition: sql_lex.h:4235
void reset_rewrite_required()
Definition: sql_lex.h:4861
LEX_STRING create_view_query_block
SELECT of CREATE VIEW statement.
Definition: sql_lex.h:4111
bool m_crossed_global_connection_memory_status_limit
Set to true when execution crosses global_connection_memory_status_limit.
Definition: sql_lex.h:4438
bool set_channel_name(LEX_CSTRING name={})
Set replication channel name.
Definition: sql_lex.cc:5102
bool accept(Select_lex_visitor *visitor)
Definition: sql_lex.cc:4986
void reset_exec_started()
Definition: sql_lex.h:4508
sp_head * sphead
Definition: sql_lex.h:4415
void reset_n_backup_query_tables_list(Query_tables_list *backup)
Definition: sql_lex.cc:4296
udf_func udf
Definition: sql_lex.h:4266
void set_trg_event_type_for_tables()
Set the initial purpose of this Table_ref object in the list of used tables.
Definition: sql_lex.cc:4018
void set_crossed_global_connection_memory_status_limit()
Definition: sql_lex.h:4527
void link_first_table_back(Table_ref *first, bool link_to_local)
Definition: sql_lex.cc:4239
const char * stmt_definition_begin
Intended to point to the next word after DEFINER-clause in the following statements:
Definition: sql_lex.h:4585
bool is_exec_completed() const
Check whether the statement has been executed (regardless of completion - successful or in error).
Definition: sql_lex.h:4518
enum enum_var_type option_type
Definition: sql_lex.h:4335
uint8 context_analysis_only
Definition: sql_lex.h:4357
bool can_use_merged()
check if command can use VIEW with MERGE algorithm (for top VIEWs)
Definition: sql_lex.cc:3728
bool can_not_use_merged()
Check if command can't use merged views in any part of command.
Definition: sql_lex.cc:3782
std::map< Item_field *, Field * >::iterator begin_values_map()
Definition: sql_lex.h:4174
bool m_subquery_to_derived_is_impossible
If true: during prepare, we did a subquery transformation (IN-to-EXISTS, SOME/ANY) that doesn't curre...
Definition: sql_lex.h:4303
void set_exec_started()
Definition: sql_lex.h:4507
Query_block * m_current_query_block
Definition: sql_lex.h:3996
Item_sum * in_sum_func
Definition: sql_lex.h:4265
virtual ~LEX()
Definition: sql_lex.cc:393
class Explain_format * explain_format
Definition: sql_lex.h:4600
void cleanup(bool full)
Definition: sql_lex.h:4498
void reset_crossed_memory_status_limit()
Definition: sql_lex.h:4533
nesting_map allow_sum_func
This field is used as a work field during resolving to validate the use of aggregate functions.
Definition: sql_lex.h:4287
const char * x509_subject
Definition: sql_lex.h:4083
friend bool lex_start(THD *thd)
Call lex_start() before every query that is to be prepared and executed.
Definition: sql_lex.cc:510
bool is_view_context_analysis()
Definition: sql_lex.h:4675
void set_crossed_connection_memory_status_limit()
Definition: sql_lex.h:4530
ulong type
Definition: sql_lex.h:4275
Helper singleton class used to track information needed to perform the transform of a correlated scal...
Definition: sql_resolver.cc:7367
Definition: thr_lock.h:99
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:145
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Definition: mysql_lex_string.h:35
Bison "location" class.
Definition: parse_location.h:43
Definition: materialize_path_parameters.h:42
Struct NESTED_JOIN is used to represent how tables are connected through outer join operations and se...
Definition: nested_join.h:78
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:415
Definition: table.h:290
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:421
Input parameters to the parser.
Definition: sql_lexer_parser_input.h:32
Parser_input()
Definition: sql_lexer_parser_input.h:50
bool m_compute_digest
True if the caller needs to compute a digest.
Definition: sql_lexer_parser_input.h:48
bool m_has_digest
True if the text parsed corresponds to an actual query, and not another text artifact.
Definition: sql_lexer_parser_input.h:42
Definition: table.h:1425
Definition: simset.h:36
Definition: result.h:30
Definition: sql_lex.h:2617
LEX_CSTRING m_db
Definition: sql_lex.h:2618
LEX_STRING m_name
Definition: sql_lex.h:2619
LEX_CSTRING m_alias
Definition: sql_lex.h:2620
sp_name_with_alias(LEX_CSTRING db, LEX_STRING name, LEX_CSTRING alias)
Definition: sql_lex.h:2622
State data storage for digest_start, digest_add_token.
Definition: sql_digest_stream.h:36
Definition: sql_lex.h:5093
Definition: sql_lex.h:3396
void reset()
Definition: sql_lex.cc:169
bool allows_select_into
Definition: sql_lex.h:3398
bool allows_variable
Definition: sql_lex.h:3397
st_parsing_options()
Definition: sql_lex.h:3400
Definition: sql_lex.h:2626
mem_root_deque< sp_name_with_alias > * m_imported_libraries
List of imported libraries for this routine.
Definition: sql_lex.h:2636
LEX_CSTRING comment
Definition: sql_lex.h:2627
void reset(void)
Reset the structure.
Definition: sql_lex.h:2709
enum enum_sp_data_access daccess
Definition: sql_lex.h:2630
bool detistic
Definition: sql_lex.h:2629
enum enum_sp_suid_behaviour suid
Definition: sql_lex.h:2628
LEX_CSTRING language
CREATE|ALTER ... LANGUAGE <language>
Definition: sql_lex.h:2631
bool add_imported_library(std::string_view database, std::string_view name, std::string_view alias, MEM_ROOT *mem_root)
Add a library to the set of imported libraries.
Definition: sql_lex.h:2675
const mem_root_deque< sp_name_with_alias > * get_imported_libraries()
Get the set of imported libraries for the routine.
Definition: sql_lex.h:2702
bool add_imported_libraries(mem_root_deque< sp_name_with_alias > &libs, MEM_ROOT *mem_root)
Add library names to the set of imported libraries.
Definition: sql_lex.h:2649
bool create_imported_libraries_deque(MEM_ROOT *mem_root)
Definition: sql_lex.h:2690
Definition: sql_lex.h:2721
enum enum_trigger_event_type event
Definition: sql_lex.h:2723
LEX_CSTRING anchor_trigger_name
Trigger name referenced in the FOLLOWS/PRECEDES clause of the CREATE TRIGGER statement.
Definition: sql_lex.h:2734
enum enum_trigger_order_type ordering_clause
FOLLOWS or PRECEDES as specified in the CREATE TRIGGER statement.
Definition: sql_lex.h:2728
enum enum_trigger_action_time_type action_time
Definition: sql_lex.h:2722
Definition: sql_lex.h:2608
void reset()
Cleans slave connection info.
Definition: sql_lex.cc:177
char * user
Definition: sql_lex.h:2609
char * plugin_dir
Definition: sql_lex.h:2612
char * plugin_auth
Definition: sql_lex.h:2611
char * password
Definition: sql_lex.h:2610
Definition: sql_udf.h:44
Definition: sql_connect.h:41
thr_lock_type
Definition: thr_lock.h:51
@ TL_UNLOCK
Definition: thr_lock.h:53
@ TL_READ_DEFAULT
Definition: thr_lock.h:61
This file defines all base public constants related to triggers in MySQL.
enum_trigger_event_type
Constants to enumerate possible event types on which triggers can be fired.
Definition: trigger_def.h:42
enum_trigger_order_type
Possible trigger ordering clause values:
Definition: trigger_def.h:64
enum_trigger_action_time_type
Constants to enumerate possible timings when triggers can be fired.
Definition: trigger_def.h:52
Definition: lexer_yystype.h:33
Definition: parser_yystype.h:342
Definition: dtoa.cc:595
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:44
Vio Lite.
SSL_type
Definition: violite.h:307
An adapter class to support iteration over an iterator of Item * (typically mem_root_deque<Item *>),...
VisibleFieldsIterator VisibleFields(mem_root_deque< Item * > &fields)
Definition: visible_fields.h:119
int n
Definition: xcom_base.cc:509