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