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