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