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