MySQL  8.0.17
Source Code Documentation
sql_lex.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /**
24  @defgroup GROUP_PARSER Parser
25  @{
26 */
27 
28 #ifndef SQL_LEX_INCLUDED
29 #define SQL_LEX_INCLUDED
30 
31 #include <string.h>
32 #include <sys/types.h>
33 #include <algorithm>
34 #include <map>
35 #include <memory>
36 #include <new>
37 #include <string>
38 #include <type_traits>
39 #include <utility>
40 
41 #include "lex_string.h"
42 #include "m_ctype.h"
43 #include "m_string.h"
44 #include "map_helpers.h"
45 #include "memory_debugging.h"
46 #include "my_base.h"
47 #include "my_compiler.h"
48 #include "my_dbug.h"
49 #include "my_inttypes.h"
50 #include "my_sqlcommand.h"
51 #include "my_sys.h"
52 #include "my_table_map.h"
53 #include "my_thread_local.h"
54 #include "my_time.h"
56 #include "mysql/psi/psi_base.h"
57 #include "mysql_com.h"
58 #include "mysqld_error.h"
59 #include "prealloced_array.h" // Prealloced_array
60 #include "sql/dd/info_schema/table_stats.h" // dd::info_schema::Table_stati...
61 #include "sql/dd/info_schema/tablespace_stats.h" // dd::info_schema::Tablesp...
62 #include "sql/enum_query_type.h"
63 #include "sql/field.h"
64 #include "sql/handler.h"
65 #include "sql/item.h" // Name_resolution_context
66 #include "sql/item_subselect.h" // chooser_compare_func_creator
67 #include "sql/key_spec.h" // KEY_CREATE_INFO
68 #include "sql/lex_symbol.h" // LEX_SYMBOL
69 #include "sql/lexer_yystype.h" // Lexer_yystype
70 #include "sql/mdl.h"
71 #include "sql/mem_root_array.h" // Mem_root_array
72 #include "sql/opt_hints.h"
73 #include "sql/parse_tree_hints.h"
74 #include "sql/parse_tree_node_base.h" // enum_parsing_context
75 #include "sql/parser_yystype.h"
76 #include "sql/query_options.h" // OPTION_NO_CONST_TABLES
77 #include "sql/set_var.h"
78 #include "sql/sql_alter.h" // Alter_info
79 #include "sql/sql_array.h"
80 #include "sql/sql_connect.h" // USER_RESOURCES
81 #include "sql/sql_const.h"
82 #include "sql/sql_data_change.h" // enum_duplicates
83 #include "sql/sql_list.h"
84 #include "sql/sql_plugin_ref.h"
85 #include "sql/sql_servers.h" // Server_options
86 #include "sql/sql_udf.h" // Item_udftype
87 #include "sql/table.h" // TABLE_LIST
88 #include "sql/thr_malloc.h"
89 #include "sql/trigger_def.h" // enum_trigger_action_time_type
90 #include "sql_chars.h"
91 #include "sql_string.h"
92 #include "thr_lock.h" // thr_lock_type
93 #include "violite.h" // SSL_type
94 
95 class Item_cond;
96 class Item_sum;
97 class Event_parse_data;
98 class Item_func_match;
99 class Parse_tree_root;
100 class Window;
101 class sp_pcontext;
102 enum class enum_jt_column;
103 enum class enum_jtc_on : uint16;
104 struct sql_digest_state;
105 
107 
108 /*
109  There are 8 different type of table access so there is no more than
110  combinations 2^8 = 256:
111 
112  . STMT_READS_TRANS_TABLE
113 
114  . STMT_READS_NON_TRANS_TABLE
115 
116  . STMT_READS_TEMP_TRANS_TABLE
117 
118  . STMT_READS_TEMP_NON_TRANS_TABLE
119 
120  . STMT_WRITES_TRANS_TABLE
121 
122  . STMT_WRITES_NON_TRANS_TABLE
123 
124  . STMT_WRITES_TEMP_TRANS_TABLE
125 
126  . STMT_WRITES_TEMP_NON_TRANS_TABLE
127 
128  The unsafe conditions for each combination is represented within a byte
129  and stores the status of the option --binlog-direct-non-trans-updates,
130  whether the trx-cache is empty or not, and whether the isolation level
131  is lower than ISO_REPEATABLE_READ:
132 
133  . option (OFF/ON)
134  . trx-cache (empty/not empty)
135  . isolation (>= ISO_REPEATABLE_READ / < ISO_REPEATABLE_READ)
136 
137  bits 0 : . OFF, . empty, . >= ISO_REPEATABLE_READ
138  bits 1 : . OFF, . empty, . < ISO_REPEATABLE_READ
139  bits 2 : . OFF, . not empty, . >= ISO_REPEATABLE_READ
140  bits 3 : . OFF, . not empty, . < ISO_REPEATABLE_READ
141  bits 4 : . ON, . empty, . >= ISO_REPEATABLE_READ
142  bits 5 : . ON, . empty, . < ISO_REPEATABLE_READ
143  bits 6 : . ON, . not empty, . >= ISO_REPEATABLE_READ
144  bits 7 : . ON, . not empty, . < ISO_REPEATABLE_READ
145 */
146 extern uint binlog_unsafe_map[256];
147 /*
148  Initializes the array with unsafe combinations and its respective
149  conditions.
150 */
152 
153 /*
154  If we encounter a diagnostics statement (GET DIAGNOSTICS, or e.g.
155  the old SHOW WARNINGS|ERRORS, or "diagnostics variables" such as
156  @@warning_count | @@error_count, we'll set some hints so this
157  information is not lost. DA_KEEP_UNSPECIFIED is used in LEX constructor to
158  avoid leaving variables uninitialized.
159  */
161  DA_KEEP_NOTHING = 0, /**< keep nothing */
162  DA_KEEP_DIAGNOSTICS, /**< keep the diagnostics area */
163  DA_KEEP_COUNTS, /**< keep \@warning_count / \@error_count */
164  DA_KEEP_PARSE_ERROR, /**< keep diagnostics area after parse error */
165  DA_KEEP_UNSPECIFIED /**< keep semantics is unspecified */
166 };
167 
172 };
173 
180 };
181 
182 /**
183  enum_sp_type defines type codes of stored programs.
184 
185  @note these codes are used when dealing with the mysql.routines system table,
186  so they must not be changed.
187 
188  @note the following macros were used previously for the same purpose. Now they
189  are used for ACL only.
190 */
192 
194  DBUG_ASSERT(val >= 1 && val <= 4);
195  return static_cast<enum_sp_type>(val);
196 }
197 
199  return static_cast<longlong>(val);
200 }
201 
202 inline uint to_uint(enum_sp_type val) { return static_cast<uint>(val); }
203 
204 /*
205  Values for the type enum. This reflects the order of the enum declaration
206  in the CREATE TABLE command. These values are used to enumerate object types
207  for the ACL statements.
208 
209  These values were also used for enumerating stored program types. However, now
210  enum_sp_type should be used for that instead of them.
211 */
212 #define TYPE_ENUM_FUNCTION 1
213 #define TYPE_ENUM_PROCEDURE 2
214 #define TYPE_ENUM_TRIGGER 3
215 #define TYPE_ENUM_PROXY 4
216 
217 enum class Acl_type {
218  TABLE = 0,
221 };
222 
224  {STRING_WITH_LEN("")},
225  {STRING_WITH_LEN("CONTAINS SQL")},
226  {STRING_WITH_LEN("NO SQL")},
227  {STRING_WITH_LEN("READS SQL DATA")},
228  {STRING_WITH_LEN("MODIFIES SQL DATA")}};
229 
231  VIEW_CREATE_NEW, // check that there are not such VIEW/table
232  VIEW_ALTER, // check that VIEW with such name exists
233  VIEW_CREATE_OR_REPLACE // check only that there are not such table
234 };
235 
236 /* Options to add_table_to_list() */
237 #define TL_OPTION_UPDATING 1
238 #define TL_OPTION_FORCE_INDEX 2
239 #define TL_OPTION_IGNORE_LEAVES 4
240 #define TL_OPTION_ALIAS 8
241 
242 /* Structure for db & table in sql_yacc */
243 extern LEX_CSTRING EMPTY_CSTR;
244 extern LEX_CSTRING NULL_CSTR;
245 
246 class Table_function;
247 
248 class Table_ident {
249  public:
254 
255  Table_ident(Protocol *protocol, const LEX_CSTRING &db_arg,
256  const LEX_CSTRING &table_arg, bool force);
257  Table_ident(const LEX_CSTRING &db_arg, const LEX_CSTRING &table_arg)
258  : db(db_arg), table(table_arg), sel(NULL), table_function(NULL) {}
259  Table_ident(const LEX_CSTRING &table_arg)
260  : table(table_arg), sel(NULL), table_function(NULL) {
261  db = NULL_CSTR;
262  }
263  /**
264  This constructor is used only for the case when we create a derived
265  table. A derived table has no name and doesn't belong to any database.
266  Later, if there was an alias specified for the table, it will be set
267  by add_table_to_list.
268  */
270  db = EMPTY_CSTR; /* a subject to casedn_str */
271  table = EMPTY_CSTR;
272  }
273  /*
274  This constructor is used only for the case when we create a table function.
275  It has no name and doesn't belong to any database as it exists only
276  during query execution. Later, if there was an alias specified for the
277  table, it will be set by add_table_to_list.
278  */
279  Table_ident(LEX_CSTRING &table_arg, Table_function *table_func_arg)
280  : table(table_arg), sel(NULL), table_function(table_func_arg) {
281  /* We must have a table name here as this is used with add_table_to_list */
282  db = EMPTY_CSTR; /* a subject to casedn_str */
283  }
284  // True if we can tell from syntax that this is a table function.
285  bool is_table_function() const { return (table_function != nullptr); }
286  // True if we can tell from syntax that this is an unnamed derived table.
287  bool is_derived_table() const { return sel; }
288  void change_db(const char *db_name) {
289  db.str = db_name;
290  db.length = strlen(db_name);
291  }
292 };
293 
296 
297 /**
298  Structure to hold parameters for CHANGE MASTER, START SLAVE, and STOP SLAVE.
299 
300  Remark: this should not be confused with Master_info (and perhaps
301  would better be renamed to st_lex_replication_info). Some fields,
302  e.g., delay, are saved in Relay_log_info, not in Master_info.
303 */
305  /*
306  The array of IGNORE_SERVER_IDS has a preallocation, and is not expected
307  to grow to any significant size, so no instrumentation.
308  */
310  initialize();
311  }
318  char *gtid;
319  char *view_id;
320  const char *channel; // identifier similar to database name
321  enum {
328 
329  /*
330  Enum is used for making it possible to detect if the user
331  changed variable or if it should be left at old value
332  */
333  enum {
337  } ssl,
346 
347  /// Initializes everything to zero/NULL/empty.
348  void initialize();
349  /// Sets all fields to their "unspecified" value.
350  void set_unspecified();
351 
352  private:
353  // Not copyable or assignable.
356 };
357 
359  bool all;
360 };
361 
370 };
371 
372 /*
373  String names used to print a statement with index hints.
374  Keep in sync with index_hint_type.
375 */
376 extern const char *index_hint_type_name[];
378 
379 /*
380  Bits in index_clause_map : one for each possible FOR clause in
381  USE/FORCE/IGNORE INDEX index hint specification
382 */
383 #define INDEX_HINT_MASK_JOIN (1)
384 #define INDEX_HINT_MASK_GROUP (1 << 1)
385 #define INDEX_HINT_MASK_ORDER (1 << 2)
386 
387 #define INDEX_HINT_MASK_ALL \
388  (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | INDEX_HINT_MASK_ORDER)
389 
390 /* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
391 class Index_hint {
392  public:
393  /* The type of the hint : USE/FORCE/IGNORE */
395  /* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
397  /*
398  The index name. Empty (str=NULL) name represents an empty list
399  USE INDEX () clause
400  */
402 
403  Index_hint(const char *str, uint length) {
404  key_name.str = str;
406  }
407 
408  void print(const THD *thd, String *str);
409 };
410 
411 /*
412  Class SELECT_LEX_UNIT represents a query expression.
413  Class SELECT_LEX represents a query block.
414  A query expression contains one or more query blocks (more than one means
415  that we have a UNION query).
416  These classes are connected as follows:
417  Both classes have a master, a slave, a next and a prev field.
418  For class SELECT_LEX, master and slave connect to objects of type
419  SELECT_LEX_UNIT, whereas for class SELECT_LEX_UNIT, they connect
420  to SELECT_LEX.
421  master is pointer to outer node.
422  slave is pointer to the first inner node
423 
424  neighbors are two SELECT_LEX or SELECT_LEX_UNIT objects on
425  the same level.
426 
427  The structures are linked with the following pointers:
428  - list of neighbors (next/prev) (prev of first element point to slave
429  pointer of outer structure)
430  - For SELECT_LEX, this is a list of query blocks.
431  - For SELECT_LEX_UNIT, this is a list of subqueries.
432 
433  - pointer to outer node (master), which is
434  If this is SELECT_LEX_UNIT
435  - pointer to outer select_lex.
436  If this is SELECT_LEX
437  - pointer to outer SELECT_LEX_UNIT.
438 
439  - pointer to inner objects (slave), which is either:
440  If this is an SELECT_LEX_UNIT:
441  - first query block that belong to this query expression.
442  If this is an SELECT_LEX
443  - first query expression that belong to this query block (subqueries).
444 
445  - list of all SELECT_LEX objects (link_next/link_prev)
446  This is to be used for things like derived tables creation, where we
447  go through this list and create the derived tables.
448 
449  If query expression contain several query blocks (UNION now,
450  INTERSECT etc later) then it has a special select_lex called
451  fake_select_lex. It used for storing global parameters (like ORDER BY,
452  LIMIT) and executing union.
453  Subqueries used in global ORDER BY clause will be attached to this
454  fake_select_lex, which will allow them to correctly resolve fields of
455  the containing UNION and outer selects.
456 
457  For example for following query:
458 
459  select *
460  from table1
461  where table1.field IN (select * from table1_1_1 union
462  select * from table1_1_2)
463  union
464  select *
465  from table2
466  where table2.field=(select (select f1 from table2_1_1_1_1
467  where table2_1_1_1_1.f2=table2_1_1.f3)
468  from table2_1_1
469  where table2_1_1.f1=table2.f2)
470  union
471  select * from table3;
472 
473  we will have following structure:
474 
475  select1: (select * from table1 ...)
476  select2: (select * from table2 ...)
477  select3: (select * from table3)
478  select1.1.1: (select * from table1_1_1)
479  ...
480 
481  main unit
482  fake0
483  select1 select2 select3
484  |^^ |^
485  s||| ||master
486  l||| |+---------------------------------+
487  a||| +---------------------------------+|
488  v|||master slave ||
489  e||+-------------------------+ ||
490  V| neighbor | V|
491  unit1.1<+==================>unit1.2 unit2.1
492  fake1.1
493  select1.1.1 select 1.1.2 select1.2.1 select2.1.1
494  |^
495  ||
496  V|
497  unit2.1.1.1
498  select2.1.1.1.1
499 
500 
501  relation in main unit will be following:
502  (bigger picture for:
503  main unit
504  fake0
505  select1 select2 select3
506  in the above picture)
507 
508  main unit
509  |^^^^|fake_select_lex
510  |||||+--------------------------------------------+
511  ||||+--------------------------------------------+|
512  |||+------------------------------+ ||
513  ||+--------------+ | ||
514  slave||master | | ||
515  V| neighbor | neighbor | master|V
516  select1<========>select2<========>select3 fake0
517 
518  list of all select_lex will be following (as it will be constructed by
519  parser):
520 
521  select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
522  |
523  +---------------------------------------------------------------------+
524  |
525  +->select1.1.1->select1.1.2
526 
527 */
528 
529 class JOIN;
530 class PT_with_clause;
531 class Query_result;
532 class Query_result_union;
533 struct LEX;
534 
535 /**
536  This class represents a query expression (one query block or
537  several query blocks combined with UNION).
538 */
540  /**
541  Intrusive double-linked list of all query expressions
542  immediately contained within the same query block.
543  */
546 
547  /**
548  The query block wherein this query expression is contained,
549  NULL if the query block is the outer-most one.
550  */
552  /// The first query block in this query expression.
554 
555  private:
556  /**
557  Marker for subqueries in WHERE, HAVING, ORDER BY, GROUP BY and
558  SELECT item lists.
559  Must be read/written when holding LOCK_query_plan.
560 
561  See Item_subselect::explain_subquery_checker
562  */
564 
565  bool prepared; ///< All query blocks in query expression are prepared
566  bool optimized; ///< All query blocks in query expression are optimized
567  bool executed; ///< Query expression has been executed
568 
571  TABLE *table; /* temporary table using for appending UNION results */
572  /// Object to which the result for this query expression is sent
574 
575  public:
576  /**
577  result of this query can't be cached, bit field, can be :
578  UNCACHEABLE_DEPENDENT
579  UNCACHEABLE_RAND
580  UNCACHEABLE_SIDEEFFECT
581  */
583 
584  explicit SELECT_LEX_UNIT(enum_parsing_context parsing_context);
585 
586  /// @return true for a query expression without UNION or multi-level ORDER
587  bool is_simple() const { return !(is_union() || fake_select_lex); }
588 
589  /// Values for SELECT_LEX_UNIT::cleaned
591  UC_DIRTY, ///< Unit isn't cleaned
592  UC_PART_CLEAN, ///< Unit were cleaned, except JOIN and JOIN_TABs were
593  ///< kept for possible EXPLAIN
594  UC_CLEAN ///< Unit completely cleaned, all underlying JOINs were
595  ///< freed
596  };
597  enum_clean_state cleaned; ///< cleanliness state
598 
599  // list of fields which points to temporary table for union
601  /*
602  list of types of items inside union (used for union & derived tables)
603 
604  Item_type_holders from which this list consist may have pointers to Field,
605  pointers is valid only after preparing SELECTS of this unit and before
606  any SELECT of this unit execution
607 
608  TODO:
609  Possibly this member should be protected, and its direct use replaced
610  by get_unit_column_types(). Check the places where it is used.
611  */
613 
614  /**
615  Pointer to query block containing global parameters for query.
616  Global parameters may include ORDER BY, LIMIT and OFFSET.
617 
618  If this is a union of multiple query blocks, the global parameters are
619  stored in fake_select_lex. If the union doesn't use a temporary table,
620  SELECT_LEX_UNIT::prepare() nulls out fake_select_lex, but saves a copy
621  in saved_fake_select_lex in order to preserve the global parameters.
622 
623  If this is not a union, and the query expression has no multi-level
624  ORDER BY/LIMIT, global parameters are in the single query block.
625 
626  @return query block containing the global parameters
627  */
628  inline SELECT_LEX *global_parameters() const {
629  if (fake_select_lex != NULL)
630  return fake_select_lex;
631  else if (saved_fake_select_lex != NULL)
632  return saved_fake_select_lex;
633  return first_select();
634  }
635  /* LIMIT clause runtime counters */
637  /// Points to subquery if this query expression is used in one, otherwise NULL
639  /**
640  Helper query block for query expression with UNION or multi-level
641  ORDER BY/LIMIT
642  */
644  /**
645  SELECT_LEX that stores LIMIT and OFFSET for UNION ALL when no
646  fake_select_lex is used.
647  */
649  /**
650  Points to last query block which has UNION DISTINCT on its left.
651  In a list of UNIONed blocks, UNION is left-associative; so UNION DISTINCT
652  eliminates duplicates in all blocks up to the first one on its right
653  included. Which is why we only need to remember that query block.
654  */
656 
657  /**
658  The WITH clause which is the first part of this query expression. NULL if
659  none.
660  */
662  /**
663  If this query expression is underlying of a derived table, the derived
664  table. NULL if none.
665  */
667  /**
668  First query block (in this UNION) which references the CTE.
669  NULL if not the query expression of a recursive CTE.
670  */
672 
673  /**
674  If 'this' is body of lateral derived table:
675  map of tables in the same FROM clause as this derived table, and to which
676  the derived table's body makes references.
677  In pre-resolution stages, this is OUTER_REF_TABLE_BIT, just to indicate
678  that this has LATERAL; after resolution, which has found references in the
679  body, this is the proper map (with no PSEUDO_TABLE_BITS anymore).
680  */
682  /**
683  True if the with-recursive algorithm has produced the complete result.
684  In a recursive CTE, a JOIN is executed several times in a loop, and
685  should not be cleaned up (e.g. by join_free()) before all iterations of
686  the loop are done (i.e. before the CTE's result is complete).
687  */
689 
690  /// @return true if query expression can be merged into an outer query
691  bool is_mergeable() const;
692 
693  /// @return true if query expression is recommended to be merged
694  bool merge_heuristic(const LEX *lex) const;
695 
696  /// @return the query block this query expression belongs to as subquery
697  SELECT_LEX *outer_select() const { return master; }
698 
699  /// @return the first query block inside this query expression
700  SELECT_LEX *first_select() const { return slave; }
701 
702  /// @return the next query expression within same query block (next subquery)
703  SELECT_LEX_UNIT *next_unit() const { return next; }
704 
705  /// @return the query result object in use for this query expression
707 
708  /**
709  If this unit is recursive, then this returns the Query_result which holds
710  the rows of the recursive reference read by 'reader':
711  - fake_select_lex reads rows from the union's result
712  - other recursive query blocks read rows from the derived table's result.
713  @param reader Recursive query block belonging to this unit
714  */
715  const Query_result *recursive_result(SELECT_LEX *reader) const;
716 
717  /// Set new query result object for this query expression
719 
720  bool prepare(THD *thd, Query_result *result, ulonglong added_options,
721  ulonglong removed_options);
722  bool optimize(THD *thd);
723  bool execute(THD *thd);
724  bool explain(THD *explain_thd, const THD *query_thd);
725  bool cleanup(THD *thd, bool full);
726  inline void unclean() { cleaned = UC_DIRTY; }
727  void reinit_exec_mechanism();
728 
729  void print(const THD *thd, String *str, enum_query_type query_type);
730  bool accept(Select_lex_visitor *visitor);
731 
732  bool add_fake_select_lex(THD *thd);
733  bool prepare_fake_select_lex(THD *thd);
734  void set_prepared() { prepared = true; }
735  void set_optimized() { optimized = true; }
736  void set_executed() { executed = true; }
737  void reset_executed() { executed = false; }
738  bool is_prepared() const { return prepared; }
739  bool is_optimized() const { return optimized; }
740  bool is_executed() const { return executed; }
742  Query_result_interceptor *old_result);
743  bool prepare_limit(THD *thd, SELECT_LEX *provider);
744  bool set_limit(THD *thd, SELECT_LEX *provider);
745 
746  inline bool is_union() const;
747  bool union_needs_tmp_table(LEX *lex);
748  /// @returns true if mixes UNION DISTINCT and UNION ALL
749  bool mixed_union_operators() const;
750 
751  /// Include a query expression below a query block.
752  void include_down(LEX *lex, SELECT_LEX *outer);
753 
754  /// Exclude this unit and immediately contained select_lex objects
755  void exclude_level();
756 
757  /// Exclude subtree of current unit from tree of SELECTs
758  void exclude_tree(THD *thd);
759 
760  /// Renumber query blocks of a query expression according to supplied LEX
761  void renumber_selects(LEX *lex);
762 
763  friend class SELECT_LEX;
764 
767 
768  enum_parsing_context get_explain_marker(const THD *thd) const;
770  void set_explain_marker_from(THD *thd, const SELECT_LEX_UNIT *u);
771 
772 #ifndef DBUG_OFF
773  /**
774  Asserts that none of {this unit and its children units} is fully cleaned
775  up.
776  */
777  void assert_not_fully_clean();
778 #else
779  void assert_not_fully_clean() {}
780 #endif
781  void invalidate();
782 
783  bool is_recursive() const { return first_recursive != nullptr; }
784 
786 
787  bool clear_corr_ctes();
788 
789  void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select);
790 
791  /**
792  If unit is a subquery, which forms an object of the upper level (an
793  Item_subselect, a derived TABLE_LIST), adds to this object a map
794  of tables of the upper level which the unit references.
795  */
798  if (item)
800  else if (m_lateral_deps)
801  m_lateral_deps |= map;
802  }
803 
804  /**
805  If unit is a subquery, which forms an object of the upper level (an
806  Item_subselect, a derived TABLE_LIST), returns the place of this object
807  in the upper level query block.
808  */
811  return item ? item->place() : CTX_DERIVED;
812  }
813 
814  bool walk(Item_processor processor, enum_walk walk, uchar *arg);
815 
816  /*
817  An exception: this is the only function that needs to adjust
818  explain_marker.
819  */
820  friend bool parse_view_definition(THD *thd, TABLE_LIST *view_ref);
821 };
822 
824 
825 /**
826  SELECT_LEX type enum
827 */
828 enum class enum_explain_type {
829  EXPLAIN_NONE = 0,
837  // Total:
838  EXPLAIN_total ///< fake type, total number of all valid types
839  // Don't insert new types below this line!
840 };
841 
842 /**
843  This class represents a query block, aka a query specification, which is
844  a query consisting of a SELECT keyword, followed by a table list,
845  optionally followed by a WHERE clause, a GROUP BY, etc.
846 */
847 class SELECT_LEX {
848  public:
849  Item *where_cond() const { return m_where_cond; }
850  void set_where_cond(Item *cond) { m_where_cond = cond; }
851  Item *having_cond() const { return m_having_cond; }
852  void set_having_cond(Item *cond) { m_having_cond = cond; }
853  void set_query_result(Query_result *result) { m_query_result = result; }
855  bool change_query_result(THD *thd, Query_result_interceptor *new_result,
856  Query_result_interceptor *old_result);
857 
858  /// Set base options for a query block (and active options too)
859  void set_base_options(ulonglong options_arg) {
860  DBUG_EXECUTE_IF("no_const_tables", options_arg |= OPTION_NO_CONST_TABLES;);
861 
862  // Make sure we do not overwrite options by accident
864  m_base_options = options_arg;
865  m_active_options = options_arg;
866  }
867 
868  /// Add base options to a query block, also update active options
873  }
874 
875  /**
876  Remove base options from a query block.
877  Active options are also updated, and we assume here that "extra" options
878  cannot override removed base options.
879  */
884  }
885 
886  /// Make active options from base options, supplied options and environment:
887  void make_active_options(ulonglong added_options, ulonglong removed_options);
888 
889  /// Adjust the active option set
891 
892  /// @return the active query options
894 
895  /**
896  Set associated tables as read_only, ie. they cannot be inserted into,
897  updated or deleted from during this statement.
898  Commonly used for query blocks that are part of derived tables or
899  views that are materialized.
900  */
902  // Set all referenced base tables as read only.
903  for (TABLE_LIST *tr = leaf_tables; tr != nullptr; tr = tr->next_leaf)
904  tr->set_readonly();
905  }
906 
907  /// @returns a map of all tables references in the query block
908  table_map all_tables_map() const { return (1ULL << leaf_table_count) - 1; }
909 
910  private:
911  /**
912  Intrusive double-linked list of all query blocks within the same
913  query expression.
914  */
917 
918  /// The query expression containing this query block.
920  /// The first query expression contained within this query block.
922 
923  /// Intrusive double-linked global list of query blocks.
926 
927  /// Result of this query block
929 
930  /**
931  Options assigned from parsing and throughout resolving,
932  should not be modified after resolving is done.
933  */
935  /**
936  Active options. Derived from base options, modifiers added during
937  resolving and values from session variable option_bits. Since the latter
938  may change, active options are refreshed per execution of a statement.
939  */
941 
942  public:
943  /**
944  result of this query can't be cached, bit field, can be :
945  UNCACHEABLE_DEPENDENT
946  UNCACHEABLE_RAND
947  UNCACHEABLE_SIDEEFFECT
948  */
950 
951  /// True: skip local transformations during prepare() call (used by INSERT)
953 
954  /// Describes context of this query block (e.g if it is a derived table).
956  bool no_table_names_allowed; ///< used for global order by
957  /**
958  Context for name resolution for all column references except columns
959  from joined tables.
960  */
962  /**
963  Pointer to first object in list of Name res context objects that have
964  this query block as the base query block.
965  Includes field "context" which is embedded in this query block.
966  */
968  /**
969  Three fields used by semi-join transformations to know when semi-join is
970  possible, and in which condition tree the subquery predicate is located.
971  */
978  };
979  Resolve_place resolve_place; ///< Indicates part of query being resolved
980  TABLE_LIST *resolve_nest; ///< Used when resolving outer join condition
981  /**
982  Disables semi-join flattening when resolving a subtree in which flattening
983  is not allowed. The flag should be true while resolving items that are not
984  on the AND-top-level of a condition tree.
985  */
987  char *db;
988 
989  private:
990  /**
991  Condition to be evaluated after all tables in a query block are joined.
992  After all permanent transformations have been conducted by
993  SELECT_LEX::prepare(), this condition is "frozen", any subsequent changes
994  to it must be done with change_item_tree(), unless they only modify AND/OR
995  items and use a copy created by SELECT_LEX::get_optimizable_conditions().
996  Same is true for 'having_cond'.
997  */
999 
1000  /// Condition to be evaluated on grouped rows after grouping.
1002 
1003  public:
1004  /**
1005  Saved values of the WHERE and HAVING clauses. Allowed values are:
1006  - COND_UNDEF if the condition was not specified in the query or if it
1007  has not been optimized yet
1008  - COND_TRUE if the condition is always true
1009  - COND_FALSE if the condition is impossible
1010  - COND_OK otherwise
1011  */
1014 
1015  /// Reference to LEX that this query block belongs to
1017  /// Indicates whether this query block contains the WITH ROLLUP clause
1019  /// List of tables in FROM clause - use TABLE_LIST::next_local to traverse
1021 
1022  /**
1023  GROUP BY clause.
1024  This list may be mutated during optimization (by remove_const()),
1025  so for prepared statements, we keep a copy of the ORDER.next pointers in
1026  group_list_ptrs, and re-establish the original list before each execution.
1027  */
1030 
1031  /**
1032  All windows defined on the select, both named and inlined
1033  */
1035 
1036  /**
1037  List of columns and expressions:
1038  SELECT: Columns and expressions in the SELECT list.
1039  UPDATE: Columns in the SET clause.
1040  */
1043 
1044  /// Number of GROUP BY expressions added to all_fields
1046 
1047  List<Item> &fields_list; ///< hold field list
1048  List<Item> all_fields; ///< to store all expressions used in query
1049  /**
1050  Usually a pointer to ftfunc_list_alloc, but in UNION this is used to create
1051  fake select_lex that consolidates result fields of UNION
1052  */
1055  /**
1056  After optimization it is pointer to corresponding JOIN. This member
1057  should be changed only when THD::LOCK_query_plan mutex is taken.
1058  */
1060  /// join list of the top level
1062  /// list for the currently parsed join
1064  /// table embedding the above list
1066  /// List of semi-join nests generated for this query block
1068  /**
1069  Points to first leaf table of query block. After setup_tables() is done,
1070  this is a list of base tables and derived tables. After derived tables
1071  processing is done, this is a list of base tables only.
1072  Use TABLE_LIST::next_leaf to traverse the list.
1073  */
1075  /// Number of leaf tables in this query block.
1077  /// Number of derived tables and views in this query block.
1079  /// Number of table functions in this query block
1081  /// Number of materialized derived tables and views in this query block.
1083  /**
1084  True if query block has semi-join nests merged into it. Notice that this
1085  is updated earlier than sj_nests, so check this if info is needed
1086  before the full resolver process is complete.
1087  */
1089  bool has_aj_nests; ///< @see has_sj_nests; counts antijoin nests.
1090  /// Number of partitioned tables
1092 
1093  /**
1094  ORDER BY clause.
1095  This list may be mutated during optimization (by remove_const()),
1096  so for prepared statements, we keep a copy of the ORDER.next pointers in
1097  order_list_ptrs, and re-establish the original list before each execution.
1098  */
1101 
1102  /// LIMIT clause, NULL if no limit is given
1104  /// LIMIT ... OFFSET clause, NULL if no offset is given
1106 
1107  /**
1108  Array of pointers to "base" items; one each for every selected expression
1109  and referenced item in the query block. All references to fields are to
1110  buffers associated with the primary input tables.
1111  */
1113 
1114  /**
1115  number of items in select_list and HAVING clause used to get number
1116  bigger then can be number of entries that will be added to all item
1117  list during split_sum_func
1118  */
1120  uint cond_count; ///< number of arguments of and/or/xor in where/having/on
1121  uint between_count; ///< number of between predicates in where/having/on
1122  uint max_equal_elems; ///< maximal number of elements in multiple equalities
1123  /**
1124  Number of fields used in select list or where clause of current select
1125  and all inner subselects.
1126  */
1128 
1129  /// Parse context: indicates where the current expression is being parsed
1131  /// Parse context: is inside a set function if this is positive
1133 
1134  /**
1135  True if contains or aggregates set functions.
1136  @note this is wrong when a locally found set function is aggregated
1137  in an outer query block.
1138  */
1140  /// Number of Item_sum-derived objects in this SELECT
1142  /// Number of Item_sum-derived objects in children and descendant SELECTs
1144 
1145  uint select_number; ///< Query block number (used for EXPLAIN)
1146  /**
1147  Nesting level of query block, outer-most query block has level 0,
1148  its subqueries have level 1, etc. @see also sql/item_sum.h.
1149  */
1151  /// Circular linked list of sum func in nested selects
1153  /**
1154  Number of wildcards used in the SELECT list. For example,
1155  SELECT *, t1.*, catalog.t2.* FROM t0, t1, t2;
1156  has 3 wildcards.
1157  */
1159  bool braces; ///< SELECT ... UNION (SELECT ... ) <- this braces
1160  /// true when having fix field called in processing of this query block
1162  /// true when GROUP BY fix field called in processing of this query block
1164 
1165  /// explicit LIMIT clause is used
1167  /**
1168  HAVING clause contains subquery => we can't close tables before
1169  query processing end even if we use temporary table
1170  */
1172  /**
1173  This variable is required to ensure proper work of subqueries and
1174  stored procedures. Generally, one should use the states of
1175  Query_arena to determine if it's a statement prepare or first
1176  execution of a stored procedure. However, in case when there was an
1177  error during the first execution of a stored procedure, the SP body
1178  is not expelled from the SP cache. Therefore, a deeply nested
1179  subquery might be left unoptimized. So we need this per-subquery
1180  variable to inidicate the optimization/execution state of every
1181  subquery. Prepared statements work OK in that regard, as in
1182  case of an error during prepare the PS is not created.
1183  */
1185  /// True when semi-join pull-out processing is complete
1187  /// exclude this query block from unique_table() check
1189  /// Allow merge of immediate unnamed derived tables
1191  /**
1192  If this query block is a recursive member of a recursive unit: the
1193  TABLE_LIST, in this recursive member, referencing the query
1194  name.
1195  */
1197  /**
1198  To pass the first steps of resolution, a recursive reference is made to
1199  be a dummy derived table; after the temporary table is created based on
1200  the non-recursive members' types, the recursive reference is made to be a
1201  reference to the tmp table. Its dummy-derived-table unit is saved in this
1202  member, so that when the statement's execution ends, the reference can be
1203  restored to be a dummy derived table for the next execution, which is
1204  necessary if we have a prepared statement.
1205  WL#6570 should allow to remove this.
1206  */
1208  /**
1209  The set of those tables whose fields are referenced in the select list of
1210  this select level.
1211  */
1213  table_map outer_join; ///< Bitmap of all inner tables from outer joins
1214 
1215  /// Query-block-level hints, for this query block
1217 
1218  // Last table for LATERAL join, used by table functions
1220  /**
1221  @note the group_by and order_by lists below will probably be added to the
1222  constructor when the parser is converted into a true bottom-up design.
1223 
1224  //SQL_I_LIST<ORDER> *group_by, SQL_I_LIST<ORDER> order_by
1225  */
1226  SELECT_LEX(Item *where, Item *having);
1227 
1228  SELECT_LEX_UNIT *master_unit() const { return master; }
1230  SELECT_LEX *outer_select() const { return master->outer_select(); }
1231  SELECT_LEX *next_select() const { return next; }
1232 
1233  /**
1234  @return true If STRAIGHT_JOIN applies to all tables.
1235  @return false Else.
1236  */
1238  bool straight_join = true;
1239  /// false for exmaple in t1 STRAIGHT_JOIN t2 JOIN t3.
1240  for (TABLE_LIST *tbl = leaf_tables->next_leaf; tbl; tbl = tbl->next_leaf)
1241  straight_join &= tbl->straight;
1242  return straight_join || (active_options() & SELECT_STRAIGHT_JOIN);
1243  }
1244 
1246  SELECT_LEX *mylast = this;
1247  for (; mylast->next_select(); mylast = mylast->next_select()) {
1248  }
1249  return mylast;
1250  }
1251 
1253 
1254  void mark_as_dependent(SELECT_LEX *last, bool aggregate);
1255 
1256  /// @return true if query block is explicitly grouped (non-empty GROUP BY)
1257  bool is_explicitly_grouped() const { return group_list.elements > 0; }
1258 
1259  /**
1260  @return true if this query block is implicitly grouped, ie it is not
1261  explicitly grouped but contains references to set functions.
1262  The query will return max. 1 row (@see also is_single_grouped()).
1263  */
1264  bool is_implicitly_grouped() const {
1265  return m_agg_func_used && group_list.elements == 0;
1266  }
1267 
1268  /**
1269  True if this query block is implicitly grouped.
1270 
1271  @note Not reliable before name resolution.
1272 
1273  @return true if this query block is implicitly grouped and returns exactly
1274  one row, which happens when it does not have a HAVING clause.
1275 
1276  @remark This function is currently unused.
1277  */
1278  bool is_single_grouped() const {
1279  return m_agg_func_used && group_list.elements == 0 && m_having_cond == NULL;
1280  }
1281 
1282  /**
1283  @return true if this query block is explicitly or implicitly grouped.
1284  @note a query with DISTINCT is not considered to be aggregated.
1285  @note in standard SQL, a query with HAVING is defined as grouped, however
1286  MySQL allows HAVING without any aggregation to be the same as WHERE.
1287  */
1288  bool is_grouped() const { return group_list.elements > 0 || m_agg_func_used; }
1289 
1290  /// @return true if this query block contains DISTINCT at start of select list
1291  bool is_distinct() const { return active_options() & SELECT_DISTINCT; }
1292 
1293  /**
1294  @return true if this query block contains an ORDER BY clause.
1295 
1296  @note returns false if ORDER BY has been eliminated, e.g if the query
1297  can return max. 1 row.
1298  */
1299  bool is_ordered() const { return order_list.elements > 0; }
1300 
1301  /// @return true if this query block has a LIMIT clause
1302  bool has_limit() const { return select_limit != NULL; }
1303 
1304  /// @return true if query block references full-text functions
1305  bool has_ft_funcs() const { return ftfunc_list->elements > 0; }
1306 
1307  /// @returns true if query block is a recursive member of a recursive unit
1308  bool is_recursive() const { return recursive_reference != nullptr; }
1309 
1310  /// @returns true if query block contains window functions
1311  bool has_windows() const { return m_windows.elements > 0; }
1312 
1313  void invalidate();
1314 
1315  bool set_braces(bool value);
1316  uint get_in_sum_expr() const { return in_sum_expr; }
1317 
1318  bool add_item_to_list(Item *item);
1319  bool add_ftfunc_to_list(Item_func_match *func);
1320  void add_order_to_list(ORDER *order);
1322  THD *thd, Table_ident *table, const char *alias, ulong table_options,
1324  List<Index_hint> *hints = 0, List<String> *partition_names = 0,
1325  LEX_STRING *option = 0, Parse_context *pc = NULL);
1327  bool init_nested_join(THD *thd);
1329  TABLE_LIST *nest_last_join(THD *thd, size_t table_cnt = 2);
1330  bool add_joined_table(TABLE_LIST *table);
1333 
1334  // Check privileges for views that are merged into query block
1335  bool check_view_privileges(THD *thd, ulong want_privilege_first,
1336  ulong want_privilege_next);
1337 
1338  // Resolve and prepare information about tables for one query block
1339  bool setup_tables(THD *thd, TABLE_LIST *tables, bool select_insert);
1340 
1341  // Resolve derived table, view, table function information for a query block
1342  bool resolve_placeholder_tables(THD *thd, bool apply_semijoin);
1343 
1344  // Propagate exclusion from table uniqueness test into subqueries
1346 
1347  // Add full-text function elements from a list into this query block
1348  bool add_ftfunc_list(List<Item_func_match> *ftfuncs);
1349 
1351 
1352  void set_lock_for_tables(thr_lock_type lock_type);
1353 
1354  inline void init_order() {
1356  order_list.elements = 0;
1357  order_list.first = 0;
1359  }
1360  /*
1361  This method created for reiniting LEX in mysql_admin_table() and can be
1362  used only if you are going remove all SELECT_LEX & units except belonger
1363  to LEX (LEX::unit & LEX::select, for other purposes use
1364  SELECT_LEX_UNIT::exclude_level()
1365  */
1366  void cut_subtree() { slave = 0; }
1367  bool test_limit();
1368  /**
1369  Get offset for LIMIT.
1370 
1371  Evaluate offset item if necessary.
1372 
1373  @return Number of rows to skip.
1374 
1375  @todo Integrate better with SELECT_LEX_UNIT::set_limit()
1376  */
1377  ha_rows get_offset(THD *thd);
1378  /**
1379  Get limit.
1380 
1381  Evaluate limit item if necessary.
1382 
1383  @return Limit of rows in result.
1384 
1385  @todo Integrate better with SELECT_LEX_UNIT::set_limit()
1386  */
1387  ha_rows get_limit(THD *thd);
1388 
1389  /// Assign a default name resolution object for this query block.
1390  bool set_context(Name_resolution_context *outer_context);
1391 
1392  /// Setup the array containing references to base items
1393  bool setup_base_ref_items(THD *thd);
1394  void print(const THD *thd, String *str, enum_query_type query_type);
1395 
1396  /**
1397  Print detail of the SELECT_LEX object.
1398 
1399  @param thd Thread handler
1400  @param query_type Options to print out string output
1401  @param[out] str String of output.
1402  */
1403  void print_select(const THD *thd, String *str, enum_query_type query_type);
1404 
1405  /**
1406  Print detail of the UPDATE statement.
1407 
1408  @param thd Thread handler
1409  @param[out] str String of output
1410  @param query_type Options to print out string output
1411  */
1412  void print_update(const THD *thd, String *str, enum_query_type query_type);
1413 
1414  /**
1415  Print detail of the DELETE statement.
1416 
1417  @param thd Thread handler
1418  @param[out] str String of output
1419  @param query_type Options to print out string output
1420  */
1421  void print_delete(const THD *thd, String *str, enum_query_type query_type);
1422 
1423  /**
1424  Print detail of the INSERT statement.
1425 
1426  @param thd Thread handler
1427  @param[out] str String of output
1428  @param query_type Options to print out string output
1429  */
1430  void print_insert(const THD *thd, String *str, enum_query_type query_type);
1431 
1432  /**
1433  Print detail of Hints.
1434 
1435  @param thd Thread handler
1436  @param[out] str String of output
1437  @param query_type Options to print out string output
1438  */
1439  void print_hints(const THD *thd, String *str, enum_query_type query_type);
1440 
1441  /**
1442  Print error.
1443 
1444  @param thd Thread handler
1445  @param[out] str String of output
1446 
1447  @return
1448  @retval false If there is no error
1449  @retval true else
1450  */
1451  bool print_error(const THD *thd, String *str);
1452 
1453  /**
1454  Print select options.
1455 
1456  @param[out] str String of output
1457  */
1458  void print_select_options(String *str);
1459 
1460  /**
1461  Print UPDATE options.
1462 
1463  @param[out] str String of output
1464  */
1465  void print_update_options(String *str);
1466 
1467  /**
1468  Print DELETE options.
1469 
1470  @param[out] str String of output
1471  */
1472  void print_delete_options(String *str);
1473 
1474  /**
1475  Print INSERT options.
1476 
1477  @param[out] str String of output
1478  */
1479  void print_insert_options(String *str);
1480 
1481  /**
1482  Print list of tables.
1483 
1484  @param thd Thread handler
1485  @param[out] str String of output
1486  @param table_list TABLE_LIST object
1487  @param query_type Options to print out string output
1488  */
1489  void print_table_references(const THD *thd, String *str,
1491  enum_query_type query_type);
1492 
1493  /**
1494  Print list of items in SELECT_LEX object.
1495 
1496  @param thd Thread handle
1497  @param[out] str String of output
1498  @param query_type Options to print out string output
1499  */
1500  void print_item_list(const THD *thd, String *str, enum_query_type query_type);
1501 
1502  /**
1503  Print assignments list. Used in UPDATE and
1504  INSERT ... ON DUPLICATE KEY UPDATE ...
1505 
1506  @param thd Thread handle
1507  @param[out] str String of output
1508  @param query_type Options to print out string output
1509  @param fields List columns to be assigned.
1510  @param values List of values.
1511  */
1512  void print_update_list(const THD *thd, String *str,
1513  enum_query_type query_type, List<Item> fields,
1514  List<Item> values);
1515 
1516  /**
1517  Print column list to be inserted into. Used in INSERT.
1518 
1519  @param thd Thread handle
1520  @param[out] str String of output
1521  @param query_type Options to print out string output
1522  */
1523  void print_insert_fields(const THD *thd, String *str,
1524  enum_query_type query_type);
1525 
1526  /**
1527  Print list of values to be inserted. Used in INSERT.
1528 
1529  @param thd Thread handle
1530  @param[out] str String of output
1531  @param query_type Options to print out string output
1532  */
1533  void print_insert_values(const THD *thd, String *str,
1534  enum_query_type query_type);
1535 
1536  /**
1537  Print list of tables in FROM clause.
1538 
1539  @param thd Thread handler
1540  @param[out] str String of output
1541  @param query_type Options to print out string output
1542  */
1543  void print_from_clause(const THD *thd, String *str,
1544  enum_query_type query_type);
1545 
1546  /**
1547  Print list of conditions in WHERE clause.
1548 
1549  @param thd Thread handle
1550  @param[out] str String of output
1551  @param query_type Options to print out string output
1552  */
1553  void print_where_cond(const THD *thd, String *str,
1554  enum_query_type query_type);
1555 
1556  /**
1557  Print list of items in GROUP BY clause.
1558 
1559  @param thd Thread handle
1560  @param[out] str String of output
1561  @param query_type Options to print out string output
1562  */
1563  void print_group_by(const THD *thd, String *str, enum_query_type query_type);
1564 
1565  /**
1566  Print list of items in HAVING clause.
1567 
1568  @param thd Thread handle
1569  @param[out] str String of output
1570  @param query_type Options to print out string output
1571  */
1572  void print_having(const THD *thd, String *str, enum_query_type query_type);
1573 
1574  /**
1575  Print details of Windowing functions.
1576 
1577  @param thd Thread handler
1578  @param[out] str String of output
1579  @param query_type Options to print out string output
1580  */
1581  void print_windows(const THD *thd, String *str, enum_query_type query_type);
1582 
1583  /**
1584  Print list of items in ORDER BY clause.
1585 
1586  @param thd Thread handle
1587  @param[out] str String of output
1588  @param query_type Options to print out string output
1589  */
1590  void print_order_by(const THD *thd, String *str, enum_query_type query_type);
1591 
1592  static void print_order(const THD *thd, String *str, ORDER *order,
1593  enum_query_type query_type);
1594  void print_limit(const THD *thd, String *str, enum_query_type query_type);
1595  void fix_prepare_information(THD *thd);
1596 
1597  /**
1598  Accept function for SELECT and DELETE.
1599 
1600  @param visitor Select_lex_visitor Object
1601  */
1602  bool accept(Select_lex_visitor *visitor);
1603 
1604  /**
1605  Cleanup this subtree (this SELECT_LEX and all nested SELECT_LEXes and
1606  SELECT_LEX_UNITs).
1607  @param thd thread handle
1608  @param full if false only partial cleanup is done, JOINs and JOIN_TABs are
1609  kept to provide info for EXPLAIN CONNECTION; if true, complete cleanup is
1610  done, all JOINs are freed.
1611  */
1612  bool cleanup(THD *thd, bool full);
1613  /*
1614  Recursively cleanup the join of this select lex and of all nested
1615  select lexes. This is not a full cleanup.
1616  */
1617  void cleanup_all_joins();
1618 
1619  /// Return true if this query block is part of a UNION
1620  bool is_part_of_union() const { return master_unit()->is_union(); }
1621 
1622  /**
1623  @return true if query block is found during preparation to produce no data.
1624  Notice that if query is implicitly grouped, an aggregation row will
1625  still be returned.
1626  */
1627  bool is_empty_query() const { return m_empty_query; }
1628 
1629  /// Set query block as returning no data
1630  /// @todo This may also be set when we have an always false WHERE clause
1632  DBUG_ASSERT(join == NULL);
1633  m_empty_query = true;
1634  }
1635  /*
1636  For MODE_ONLY_FULL_GROUP_BY we need to know if
1637  this query block is the aggregation query of at least one aggregate
1638  function.
1639  */
1640  bool agg_func_used() const { return m_agg_func_used; }
1641  bool json_agg_func_used() const { return m_json_agg_func_used; }
1642 
1643  void set_agg_func_used(bool val) { m_agg_func_used = val; }
1644 
1646 
1647  /// Lookup for SELECT_LEX type
1649 
1650  /// Lookup for a type string
1651  const char *get_type_str() { return type_str[static_cast<int>(type())]; }
1652  static const char *get_type_str(enum_explain_type type) {
1653  return type_str[static_cast<int>(type)];
1654  }
1655 
1657  bool is_cacheable() const { return !uncacheable; }
1658 
1659  /// Include query block inside a query expression.
1660  void include_down(LEX *lex, SELECT_LEX_UNIT *outer);
1661 
1662  /// Include a query block next to another query block.
1663  void include_neighbour(LEX *lex, SELECT_LEX *before);
1664 
1665  /// Include query block inside a query expression, but do not link.
1666  void include_standalone(SELECT_LEX_UNIT *sel, SELECT_LEX **ref);
1667 
1668  /// Include query block into global list.
1669  void include_in_global(SELECT_LEX **plink);
1670 
1671  /// Include chain of query blocks into global list.
1673 
1674  /// Renumber query blocks of contained query expressions
1675  void renumber(LEX *lex);
1676 
1677  /**
1678  Does permanent transformations which are local to a query block (which do
1679  not merge it to another block).
1680  */
1681  bool apply_local_transforms(THD *thd, bool prune);
1682 
1683  bool get_optimizable_conditions(THD *thd, Item **new_where,
1684  Item **new_having);
1685 
1686  bool validate_outermost_option(LEX *lex, const char *wrong_option) const;
1687  bool validate_base_options(LEX *lex, ulonglong options) const;
1688 
1689  bool walk(Item_processor processor, enum_walk walk, uchar *arg);
1690 
1691  private:
1692  // Delete unused columns from merged derived tables
1694 
1697 
1698  /**
1699  True if query block does not generate any rows before aggregation,
1700  determined during preparation (not optimization).
1701  */
1703 
1704  /// Helper for fix_prepare_information()
1706  Group_list_ptrs **list_ptrs);
1707  static const char
1709 
1710  friend class SELECT_LEX_UNIT;
1712  bool simplify_joins(THD *thd, List<TABLE_LIST> *join_list, bool top,
1713  bool in_sj, Item **new_conds, uint *changelog = NULL);
1714  /// Merge derived table into query block
1715  public:
1717  /// Remove semijoin condition for this query block
1718  void clear_sj_expressions(NESTED_JOIN *nested_join);
1719  /// Build semijoin condition for th query block
1720  bool build_sj_cond(THD *thd, NESTED_JOIN *nested_join,
1721  SELECT_LEX *subq_select, table_map outer_tables_map,
1722  Item **sj_cond);
1723  bool decorrelate_condition(TABLE_LIST *sj_nest, TABLE_LIST *join_nest);
1725 
1726  private:
1728  void remap_tables(THD *thd);
1729  bool resolve_subquery(THD *thd);
1730  bool resolve_rollup_item(THD *thd, Item *item);
1731  bool resolve_rollup(THD *thd);
1732 
1733  public:
1734  bool resolve_rollup_wfs(THD *thd);
1735  bool change_group_ref_for_func(THD *thd, Item *func, bool *changed);
1736  bool change_group_ref_for_cond(THD *thd, Item_cond *cond, bool *changed);
1737  bool flatten_subqueries(THD *thd);
1739  sj_candidates = sj_cand;
1740  }
1741 
1742  bool has_sj_candidates() const {
1743  return sj_candidates != NULL && !sj_candidates->empty();
1744  }
1745  bool is_in_select_list(Item *i);
1746 
1747  private:
1748  bool setup_wild(THD *thd);
1749  bool setup_order_final(THD *thd);
1750  bool setup_group(THD *thd);
1754  void empty_order_list(SELECT_LEX *sl);
1755  bool setup_join_cond(THD *thd, List<TABLE_LIST> *tables, bool in_update);
1756  bool find_common_table_expr(THD *thd, Table_ident *table_id, TABLE_LIST *tl,
1757  Parse_context *pc, bool *found);
1758 
1759  /**
1760  Pointer to collection of subqueries candidate for semi/antijoin
1761  conversion.
1762  Template parameter is "true": no need to run DTORs on pointers.
1763  */
1765 
1766  public:
1767  /// How many expressions are part of the order by but not select list.
1769 
1770  bool setup_conds(THD *thd);
1771  bool prepare(THD *thd);
1772  bool optimize(THD *thd);
1774  bool check_only_full_group_by(THD *thd);
1775 
1776  /// Merge name resolution context objects of a subquery into its parent
1777  void merge_contexts(SELECT_LEX *inner);
1778 
1779  /**
1780  Returns which subquery execution strategies can be used for this query
1781  block.
1782 
1783  @param thd Pointer to THD object for session.
1784  Used to access optimizer_switch
1785 
1786  @retval EXEC_MATERIALIZATION Subquery Materialization should be used
1787  @retval EXEC_EXISTS In-to-exists execution should be used
1788  @retval EXEC_EXISTS_OR_MAT A cost-based decision should be made
1789  */
1791 
1792  /**
1793  Returns whether semi-join is enabled for this query block
1794 
1795  @see @c Opt_hints_qb::semijoin_enabled for details on how hints
1796  affect this decision. If there are no hints for this query block,
1797  optimizer_switch setting determines whether semi-join is used.
1798 
1799  @param thd Pointer to THD object for session.
1800  Used to access optimizer_switch
1801 
1802  @return true if semijoin is enabled,
1803  false otherwise
1804  */
1805  bool semijoin_enabled(THD *thd) const;
1806  /**
1807  Update available semijoin strategies for semijoin nests.
1808 
1809  Available semijoin strategies needs to be updated on every execution since
1810  optimizer_switch setting may have changed.
1811 
1812  @param thd Pointer to THD object for session.
1813  Used to access optimizer_switch
1814  */
1815  void update_semijoin_strategies(THD *thd);
1817 
1818  /**
1819  Add item to the hidden part of select list
1820 
1821  @param item item to add
1822 
1823  @return Pointer to reference of the added item
1824  */
1826 
1827  bool add_tables(THD *thd, const Mem_root_array<Table_ident *> *tables,
1828  ulong table_options, thr_lock_type lock_type,
1829  enum_mdl_type mdl_type);
1830 
1831  TABLE_LIST *find_table_by_name(const Table_ident *ident);
1832 };
1833 
1834 inline bool SELECT_LEX_UNIT::is_union() const {
1835  return first_select()->next_select() &&
1837 }
1838 
1839 /**
1840  Utility RAII class to save/modify/restore the
1841  semijoin_disallowed flag.
1842 */
1844  public:
1845  Disable_semijoin_flattening(SELECT_LEX *select_ptr, bool apply)
1846  : select(NULL), saved_value() {
1847  if (select_ptr && apply) {
1848  select = select_ptr;
1850  select->semijoin_disallowed = true;
1851  }
1852  }
1855  }
1856 
1857  private:
1860 };
1861 
1862 /**
1863  Base class for secondary engine execution context objects. Secondary
1864  storage engines may create classes derived from this one which
1865  contain state they need to preserve between optimization and
1866  execution of statements. The context objects should be allocated on
1867  the execution MEM_ROOT.
1868 */
1870  public:
1871  /**
1872  Destructs the secondary engine execution context object. It is
1873  called after the query execution has completed. Secondary engines
1874  may override the destructor in subclasses and add code that
1875  performs cleanup tasks that are needed after query execution.
1876  */
1877  virtual ~Secondary_engine_execution_context() = default;
1878 };
1879 
1880 typedef struct struct_slave_connection {
1881  char *user;
1882  char *password;
1884  char *plugin_dir;
1885 
1886  void reset();
1888 
1892  bool detistic;
1894 };
1895 
1896 extern const LEX_STRING null_lex_str;
1897 extern const LEX_STRING empty_lex_str;
1898 
1902 
1903  /**
1904  FOLLOWS or PRECEDES as specified in the CREATE TRIGGER statement.
1905  */
1907 
1908  /**
1909  Trigger name referenced in the FOLLOWS/PRECEDES clause of the CREATE TRIGGER
1910  statement.
1911  */
1913 };
1914 
1916 
1917 class Sroutine_hash_entry;
1918 
1919 /*
1920  Class representing list of all tables used by statement and other
1921  information which is necessary for opening and locking its tables,
1922  like SQL command for this statement.
1923 
1924  Also contains information about stored functions used by statement
1925  since during its execution we may have to add all tables used by its
1926  stored functions/triggers to this list in order to pre-open and lock
1927  them.
1928 
1929  Also used by LEX::reset_n_backup/restore_backup_query_tables_list()
1930  methods to save and restore this information.
1931 */
1932 
1934  public:
1936 
1937  /**
1938  SQL command for this statement. Part of this class since the
1939  process of opening and locking tables for the statement needs
1940  this information to determine correct type of lock for some of
1941  the tables.
1942  */
1944  /* Global list of all tables used by this statement */
1946  /* Pointer to next_global member of last element in the previous list. */
1948  /*
1949  If non-0 then indicates that query requires prelocking and points to
1950  next_global member of last own element in query table list (i.e. last
1951  table which was not added to it as part of preparation to prelocking).
1952  0 - indicates that this query does not need prelocking.
1953  */
1955  /*
1956  Set of stored routines called by statement.
1957  (Note that we use lazy-initialization for this hash).
1958 
1959  See Sroutine_hash_entry for explanation why this hash uses binary
1960  key comparison.
1961  */
1963  std::unique_ptr<malloc_unordered_map<std::string, Sroutine_hash_entry *>>
1965  /*
1966  List linking elements of 'sroutines' set. Allows you to add new elements
1967  to this set as you iterate through the list of existing elements.
1968  'sroutines_list_own_last' is pointer to ::next member of last element of
1969  this list which represents routine which is explicitly used by query.
1970  'sroutines_list_own_elements' number of explicitly used routines.
1971  We use these two members for restoring of 'sroutines_list' to the state
1972  in which it was right after query parsing.
1973  */
1977 
1978  /**
1979  Locking state of tables in this particular statement.
1980 
1981  If we under LOCK TABLES or in prelocked mode we consider tables
1982  for the statement to be "locked" if there was a call to lock_tables()
1983  (which called handler::start_stmt()) for tables of this statement
1984  and there was no matching close_thread_tables() call.
1985 
1986  As result this state may differ significantly from one represented
1987  by Open_tables_state::lock/locked_tables_mode more, which are always
1988  "on" under LOCK TABLES or in prelocked mode.
1989  */
1992  bool is_query_tables_locked() const {
1993  return (lock_tables_state == LTS_LOCKED);
1994  }
1995 
1996  /**
1997  Number of tables which were open by open_tables() and to be locked
1998  by lock_tables().
1999  Note that we set this member only in some cases, when this value
2000  needs to be passed from open_tables() to lock_tables() which are
2001  separated by some amount of code.
2002  */
2004 
2005  /*
2006  These constructor and destructor serve for creation/destruction
2007  of Query_tables_list instances which are used as backup storage.
2008  */
2011 
2012  /* Initializes (or resets) Query_tables_list object for "real" use. */
2013  void reset_query_tables_list(bool init);
2016  *this = std::move(*state);
2017  }
2018 
2019  /*
2020  Direct addition to the list of query tables.
2021  If you are using this function, you must ensure that the table
2022  object, in particular table->db member, is initialized.
2023  */
2025  *(table->prev_global = query_tables_last) = table;
2026  query_tables_last = &table->next_global;
2027  }
2029  void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last) {
2030  query_tables_own_last = tables_own_last;
2031  }
2032  /* Return pointer to first not-own table in query-tables or 0 */
2035  }
2037  if (query_tables_own_last) {
2038  *query_tables_own_last = 0;
2041  }
2042  }
2043 
2044  /**
2045  All types of unsafe statements.
2046 
2047  @note The int values of the enum elements are used to point to
2048  bits in two bitmaps in two different places:
2049 
2050  - Query_tables_list::binlog_stmt_flags
2051  - THD::binlog_unsafe_warning_flags
2052 
2053  Hence in practice this is not an enum at all, but a map from
2054  symbols to bit indexes.
2055 
2056  The ordering of elements in this enum must correspond to the order of
2057  elements in the array binlog_stmt_unsafe_errcode.
2058  */
2060  /**
2061  SELECT..LIMIT is unsafe because the set of rows returned cannot
2062  be predicted.
2063  */
2065  /**
2066  Access to log tables is unsafe because slave and master probably
2067  log different things.
2068  */
2070  /**
2071  Inserting into an autoincrement column in a stored routine is unsafe.
2072  Even with just one autoincrement column, if the routine is invoked more
2073  than once slave is not guaranteed to execute the statement graph same way
2074  as the master. And since it's impossible to estimate how many times a
2075  routine can be invoked at the query pre-execution phase (see lock_tables),
2076  the statement is marked pessimistically unsafe.
2077  */
2079  /**
2080  Using a UDF (user-defined function) is unsafe.
2081  */
2083  /**
2084  Using most system variables is unsafe, because slave may run
2085  with different options than master.
2086  */
2088  /**
2089  Using some functions is unsafe (e.g., UUID).
2090  */
2092 
2093  /**
2094  Mixing transactional and non-transactional statements are unsafe if
2095  non-transactional reads or writes are occur after transactional
2096  reads or writes inside a transaction.
2097  */
2099 
2100  /**
2101  Mixing self-logging and non-self-logging engines in a statement
2102  is unsafe.
2103  */
2105 
2106  /**
2107  Statements that read from both transactional and non-transactional
2108  tables and write to any of them are unsafe.
2109  */
2111 
2112  /**
2113  INSERT...IGNORE SELECT is unsafe because which rows are ignored depends
2114  on the order that rows are retrieved by SELECT. This order cannot be
2115  predicted and may differ on master and the slave.
2116  */
2118 
2119  /**
2120  INSERT...SELECT...UPDATE is unsafe because which rows are updated depends
2121  on the order that rows are retrieved by SELECT. This order cannot be
2122  predicted and may differ on master and the slave.
2123  */
2125 
2126  /**
2127  Query that writes to a table with auto_inc column after selecting from
2128  other tables are unsafe as the order in which the rows are retrieved by
2129  select may differ on master and slave.
2130  */
2132 
2133  /**
2134  INSERT...REPLACE SELECT is unsafe because which rows are replaced depends
2135  on the order that rows are retrieved by SELECT. This order cannot be
2136  predicted and may differ on master and the slave.
2137  */
2139 
2140  /**
2141  CREATE TABLE... IGNORE... SELECT is unsafe because which rows are ignored
2142  depends on the order that rows are retrieved by SELECT. This order cannot
2143  be predicted and may differ on master and the slave.
2144  */
2146 
2147  /**
2148  CREATE TABLE...REPLACE... SELECT is unsafe because which rows are replaced
2149  depends on the order that rows are retrieved from SELECT. This order
2150  cannot be predicted and may differ on master and the slave
2151  */
2153 
2154  /**
2155  CREATE TABLE...SELECT on a table with auto-increment column is unsafe
2156  because which rows are replaced depends on the order that rows are
2157  retrieved from SELECT. This order cannot be predicted and may differ on
2158  master and the slave
2159  */
2161 
2162  /**
2163  UPDATE...IGNORE is unsafe because which rows are ignored depends on the
2164  order that rows are updated. This order cannot be predicted and may differ
2165  on master and the slave.
2166  */
2168 
2169  /**
2170  INSERT... ON DUPLICATE KEY UPDATE on a table with more than one
2171  UNIQUE KEYS is unsafe.
2172  */
2174 
2175  /**
2176  INSERT into auto-inc field which is not the first part in composed
2177  primary key.
2178  */
2180 
2181  /**
2182  Using a plugin is unsafe.
2183  */
2187 
2188  /**
2189  XA transactions and statements.
2190  */
2192 
2193  /**
2194  If a substatement inserts into or updates a table that has a column with
2195  an unsafe DEFAULT expression, it may not have the same effect on the
2196  slave.
2197  */
2199 
2200  /* the last element of this enumeration type. */
2202  };
2203  /**
2204  This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT
2205  (exclusive) set.
2206  */
2207  static const int BINLOG_STMT_UNSAFE_ALL_FLAGS =
2208  ((1 << BINLOG_STMT_UNSAFE_COUNT) - 1);
2209 
2210  /**
2211  Maps elements of enum_binlog_stmt_unsafe to error codes.
2212  */
2214 
2215  /**
2216  Determine if this statement is marked as unsafe.
2217 
2218  @retval 0 if the statement is not marked as unsafe.
2219  @retval nonzero if the statement is marked as unsafe.
2220  */
2221  inline bool is_stmt_unsafe() const { return get_stmt_unsafe_flags() != 0; }
2222 
2224  return binlog_stmt_flags & (1 << unsafe);
2225  }
2226 
2227  /**
2228  Flag the current (top-level) statement as unsafe.
2229  The flag will be reset after the statement has finished.
2230 
2231  @param unsafe_type The type of unsafety: one of the @c
2232  BINLOG_STMT_FLAG_UNSAFE_* flags in @c enum_binlog_stmt_flag.
2233  */
2234  inline void set_stmt_unsafe(enum_binlog_stmt_unsafe unsafe_type) {
2235  DBUG_ENTER("set_stmt_unsafe");
2236  DBUG_ASSERT(unsafe_type >= 0 && unsafe_type < BINLOG_STMT_UNSAFE_COUNT);
2237  binlog_stmt_flags |= (1U << unsafe_type);
2239  }
2240 
2241  /**
2242  Set the bits of binlog_stmt_flags determining the type of
2243  unsafeness of the current statement. No existing bits will be
2244  cleared, but new bits may be set.
2245 
2246  @param flags A binary combination of zero or more bits, (1<<flag)
2247  where flag is a member of enum_binlog_stmt_unsafe.
2248  */
2250  DBUG_ENTER("set_stmt_unsafe_flags");
2254  }
2255 
2256  /**
2257  Return a binary combination of all unsafe warnings for the
2258  statement. If the statement has been marked as unsafe by the
2259  'flag' member of enum_binlog_stmt_unsafe, then the return value
2260  from this function has bit (1<<flag) set to 1.
2261  */
2263  DBUG_ENTER("get_stmt_unsafe_flags");
2265  }
2266 
2267  /**
2268  Determine if this statement is a row injection.
2269 
2270  @retval 0 if the statement is not a row injection
2271  @retval nonzero if the statement is a row injection
2272  */
2273  inline bool is_stmt_row_injection() const {
2274  return binlog_stmt_flags &
2276  }
2277 
2278  /**
2279  Flag the statement as a row injection. A row injection is either
2280  a BINLOG statement, or a row event in the relay log executed by
2281  the slave SQL thread.
2282  */
2283  inline void set_stmt_row_injection() {
2284  DBUG_ENTER("set_stmt_row_injection");
2288  }
2289 
2291  /*
2292  If a transactional table is about to be read. Note that
2293  a write implies a read.
2294  */
2296  /*
2297  If a non-transactional table is about to be read. Note that
2298  a write implies a read.
2299  */
2301  /*
2302  If a temporary transactional table is about to be read. Note
2303  that a write implies a read.
2304  */
2306  /*
2307  If a temporary non-transactional table is about to be read. Note
2308  that a write implies a read.
2309  */
2311  /*
2312  If a transactional table is about to be updated.
2313  */
2315  /*
2316  If a non-transactional table is about to be updated.
2317  */
2319  /*
2320  If a temporary transactional table is about to be updated.
2321  */
2323  /*
2324  If a temporary non-transactional table is about to be updated.
2325  */
2327  /*
2328  The last element of the enumeration. Please, if necessary add
2329  anything before this.
2330  */
2332  };
2333 
2334 #ifndef DBUG_OFF
2335  static inline const char *stmt_accessed_table_string(
2336  enum_stmt_accessed_table accessed_table) {
2337  switch (accessed_table) {
2339  return "STMT_READS_TRANS_TABLE";
2340  break;
2342  return "STMT_READS_NON_TRANS_TABLE";
2343  break;
2345  return "STMT_READS_TEMP_TRANS_TABLE";
2346  break;
2348  return "STMT_READS_TEMP_NON_TRANS_TABLE";
2349  break;
2351  return "STMT_WRITES_TRANS_TABLE";
2352  break;
2354  return "STMT_WRITES_NON_TRANS_TABLE";
2355  break;
2357  return "STMT_WRITES_TEMP_TRANS_TABLE";
2358  break;
2360  return "STMT_WRITES_TEMP_NON_TRANS_TABLE";
2361  break;
2363  default:
2364  DBUG_ASSERT(0);
2365  break;
2366  }
2368  return "";
2369  }
2370 #endif /* DBUG */
2371 
2372 #define BINLOG_DIRECT_ON \
2373  0xF0 /* unsafe when \
2374  --binlog-direct-non-trans-updates \
2375  is ON */
2376 
2377 #define BINLOG_DIRECT_OFF \
2378  0xF /* unsafe when \
2379  --binlog-direct-non-trans-updates \
2380  is OFF */
2381 
2382 #define TRX_CACHE_EMPTY 0x33 /* unsafe when trx-cache is empty */
2383 
2384 #define TRX_CACHE_NOT_EMPTY 0xCC /* unsafe when trx-cache is not empty */
2385 
2386 #define IL_LT_REPEATABLE 0xAA /* unsafe when < ISO_REPEATABLE_READ */
2387 
2388 #define IL_GTE_REPEATABLE 0x55 /* unsafe when >= ISO_REPEATABLE_READ */
2389 
2390  /**
2391  Sets the type of table that is about to be accessed while executing a
2392  statement.
2393 
2394  @param accessed_table Enumeration type that defines the type of table,
2395  e.g. temporary, transactional, non-transactional.
2396  */
2398  DBUG_ENTER("LEX::set_stmt_accessed_table");
2399 
2400  DBUG_ASSERT(accessed_table >= 0 &&
2401  accessed_table < STMT_ACCESS_TABLE_COUNT);
2402  stmt_accessed_table_flag |= (1U << accessed_table);
2403 
2405  }
2406 
2407  /**
2408  Checks if a type of table is about to be accessed while executing a
2409  statement.
2410 
2411  @param accessed_table Enumeration type that defines the type of table,
2412  e.g. temporary, transactional, non-transactional.
2413 
2414  @return
2415  @retval true if the type of the table is about to be accessed
2416  @retval false otherwise
2417  */
2418  inline bool stmt_accessed_table(enum_stmt_accessed_table accessed_table) {
2419  DBUG_ENTER("LEX::stmt_accessed_table");
2420 
2421  DBUG_ASSERT(accessed_table >= 0 &&
2422  accessed_table < STMT_ACCESS_TABLE_COUNT);
2423 
2424  DBUG_RETURN((stmt_accessed_table_flag & (1U << accessed_table)) != 0);
2425  }
2426 
2427  /*
2428  Checks if a mixed statement is unsafe.
2429 
2430 
2431  @param in_multi_stmt_transaction_mode defines if there is an on-going
2432  multi-transactional statement.
2433  @param binlog_direct defines if --binlog-direct-non-trans-updates is
2434  active.
2435  @param trx_cache_is_not_empty defines if the trx-cache is empty or not.
2436  @param trx_isolation defines the isolation level.
2437 
2438  @return
2439  @retval true if the mixed statement is unsafe
2440  @retval false otherwise
2441  */
2442  inline bool is_mixed_stmt_unsafe(bool in_multi_stmt_transaction_mode,
2443  bool binlog_direct,
2444  bool trx_cache_is_not_empty,
2445  uint tx_isolation) {
2446  bool unsafe = false;
2447 
2448  if (in_multi_stmt_transaction_mode) {
2449  uint condition =
2450  (binlog_direct ? BINLOG_DIRECT_ON : BINLOG_DIRECT_OFF) &
2451  (trx_cache_is_not_empty ? TRX_CACHE_NOT_EMPTY : TRX_CACHE_EMPTY) &
2452  (tx_isolation >= ISO_REPEATABLE_READ ? IL_GTE_REPEATABLE
2453  : IL_LT_REPEATABLE);
2454 
2455  unsafe = (binlog_unsafe_map[stmt_accessed_table_flag] & condition);
2456 
2457 #if !defined(DBUG_OFF)
2458  DBUG_PRINT("LEX::is_mixed_stmt_unsafe",
2459  ("RESULT %02X %02X %02X\n", condition,
2462 
2463  int type_in = 0;
2464  for (; type_in < STMT_ACCESS_TABLE_COUNT; type_in++) {
2466  DBUG_PRINT("LEX::is_mixed_stmt_unsafe",
2467  ("ACCESSED %s ", stmt_accessed_table_string(
2468  (enum_stmt_accessed_table)type_in)));
2469  }
2470 #endif
2471  }
2472 
2475  tx_isolation < ISO_REPEATABLE_READ)
2476  unsafe = true;
2479  tx_isolation < ISO_REPEATABLE_READ)
2480  unsafe = true;
2481 
2482  return (unsafe);
2483  }
2484 
2485  /**
2486  true if the parsed tree contains references to stored procedures
2487  or functions, false otherwise
2488  */
2489  bool uses_stored_routines() const { return sroutines_list.elements != 0; }
2490 
2491  void set_using_match() { using_match = true; }
2492  bool get_using_match() { return using_match; }
2493 
2494  private:
2495  /**
2496  Enumeration listing special types of statements.
2497 
2498  Currently, the only possible type is ROW_INJECTION.
2499  */
2501  /**
2502  The statement is a row injection (i.e., either a BINLOG
2503  statement or a row event executed by the slave SQL thread).
2504  */
2506 
2507  /** The last element of this enumeration type. */
2509  };
2510 
2511  /**
2512  Bit field indicating the type of statement.
2513 
2514  There are two groups of bits:
2515 
2516  - The low BINLOG_STMT_UNSAFE_COUNT bits indicate the types of
2517  unsafeness that the current statement has.
2518 
2519  - The next BINLOG_STMT_TYPE_COUNT bits indicate if the statement
2520  is of some special type.
2521 
2522  This must be a member of LEX, not of THD: each stored procedure
2523  needs to remember its unsafeness state between calls and each
2524  stored procedure has its own LEX object (but no own THD object).
2525  */
2527 
2528  /**
2529  Bit field that determines the type of tables that are about to be
2530  be accessed while executing a statement.
2531  */
2533 
2534  /**
2535  It will be set true if 'MATCH () AGAINST' is used in the statement.
2536  */
2538 };
2539 
2540 /*
2541  st_parsing_options contains the flags for constructions that are
2542  allowed in the current statement.
2543 */
2544 
2548 
2550  void reset();
2551 };
2552 
2553 /**
2554  The state of the lexical parser, when parsing comments.
2555 */
2557  /**
2558  Not parsing comments.
2559  */
2561 
2562  /**
2563  Parsing comments that need to be preserved.
2564  (Copy '/' '*' and '*' '/' sequences to the preprocessed buffer.)
2565  Typically, these are user comments '/' '*' ... '*' '/'.
2566  */
2568 
2569  /**
2570  Parsing comments that need to be discarded.
2571  (Don't copy '/' '*' '!' and '*' '/' sequences to the preprocessed buffer.)
2572  Typically, these are special comments '/' '*' '!' ... '*' '/',
2573  or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
2574  markers should not be expanded.
2575  */
2577 };
2578 
2579 /**
2580  This class represents the character input stream consumed during lexical
2581  analysis.
2582 
2583  In addition to consuming the input stream, this class performs some comment
2584  pre processing, by filtering out out-of-bound special text from the query
2585  input stream.
2586 
2587  Two buffers, with pointers inside each, are maintained in parallel. The
2588  'raw' buffer is the original query text, which may contain out-of-bound
2589  comments. The 'cpp' (for comments pre processor) is the pre-processed buffer
2590  that contains only the query text that should be seen once out-of-bound data
2591  is removed.
2592 */
2593 
2595  public:
2596  /**
2597  Constructor
2598 
2599  @param grammar_selector_token_arg See grammar_selector_token.
2600  */
2601 
2602  explicit Lex_input_stream(uint grammar_selector_token_arg)
2603  : grammar_selector_token(grammar_selector_token_arg) {}
2604 
2605  /**
2606  Object initializer. Must be called before usage.
2607 
2608  @retval false OK
2609  @retval true Error
2610  */
2611  bool init(THD *thd, const char *buff, size_t length);
2612 
2613  void reset(const char *buff, size_t length);
2614 
2615  /**
2616  Set the echo mode.
2617 
2618  When echo is true, characters parsed from the raw input stream are
2619  preserved. When false, characters parsed are silently ignored.
2620  @param echo the echo mode.
2621  */
2622  void set_echo(bool echo) { m_echo = echo; }
2623 
2625  m_echo_saved = m_echo;
2627  }
2628 
2630  m_echo = m_echo_saved;
2632  }
2633 
2634  /**
2635  Skip binary from the input stream.
2636  @param n number of bytes to accept.
2637  */
2638  void skip_binary(int n) {
2640  if (m_echo) {
2641  memcpy(m_cpp_ptr, m_ptr, n);
2642  m_cpp_ptr += n;
2643  }
2644  m_ptr += n;
2645  }
2646 
2647  /**
2648  Get a character, and advance in the stream.
2649  @return the next character to parse.
2650  */
2651  unsigned char yyGet() {
2653  char c = *m_ptr++;
2654  if (m_echo) *m_cpp_ptr++ = c;
2655  return c;
2656  }
2657 
2658  /**
2659  Get the last character accepted.
2660  @return the last character accepted.
2661  */
2662  unsigned char yyGetLast() const { return m_ptr[-1]; }
2663 
2664  /**
2665  Look at the next character to parse, but do not accept it.
2666  */
2667  unsigned char yyPeek() const {
2669  return m_ptr[0];
2670  }
2671 
2672  /**
2673  Look ahead at some character to parse.
2674  @param n offset of the character to look up
2675  */
2676  unsigned char yyPeekn(int n) const {
2678  return m_ptr[n];
2679  }
2680 
2681  /**
2682  Cancel the effect of the last yyGet() or yySkip().
2683  Note that the echo mode should not change between calls to yyGet / yySkip
2684  and yyUnget. The caller is responsible for ensuring that.
2685  */
2686  void yyUnget() {
2687  m_ptr--;
2688  if (m_echo) m_cpp_ptr--;
2689  }
2690 
2691  /**
2692  Accept a character, by advancing the input stream.
2693  */
2694  void yySkip() {
2696  if (m_echo)
2697  *m_cpp_ptr++ = *m_ptr++;
2698  else
2699  m_ptr++;
2700  }
2701 
2702  /**
2703  Accept multiple characters at once.
2704  @param n the number of characters to accept.
2705  */
2706  void yySkipn(int n) {
2708  if (m_echo) {
2709  memcpy(m_cpp_ptr, m_ptr, n);
2710  m_cpp_ptr += n;
2711  }
2712  m_ptr += n;
2713  }
2714 
2715  /**
2716  Puts a character back into the stream, canceling
2717  the effect of the last yyGet() or yySkip().
2718  Note that the echo mode should not change between calls
2719  to unput, get, or skip from the stream.
2720  */
2721  char *yyUnput(char ch) {
2722  *--m_ptr = ch;
2723  if (m_echo) m_cpp_ptr--;
2724  return m_ptr;
2725  }
2726 
2727  /**
2728  Inject a character into the pre-processed stream.
2729 
2730  Note, this function is used to inject a space instead of multi-character
2731  C-comment. Thus there is no boundary checks here (basically, we replace
2732  N-chars by 1-char here).
2733  */
2734  char *cpp_inject(char ch) {
2735  *m_cpp_ptr = ch;
2736  return ++m_cpp_ptr;
2737  }
2738 
2739  /**
2740  End of file indicator for the query text to parse.
2741  @return true if there are no more characters to parse
2742  */
2743  bool eof() const { return (m_ptr >= m_end_of_query); }
2744 
2745  /**
2746  End of file indicator for the query text to parse.
2747  @param n number of characters expected
2748  @return true if there are less than n characters to parse
2749  */
2750  bool eof(int n) const { return ((m_ptr + n) >= m_end_of_query); }
2751 
2752  /** Get the raw query buffer. */
2753  const char *get_buf() const { return m_buf; }
2754 
2755  /** Get the pre-processed query buffer. */
2756  const char *get_cpp_buf() const { return m_cpp_buf; }
2757 
2758  /** Get the end of the raw query buffer. */
2759  const char *get_end_of_query() const { return m_end_of_query; }
2760 
2761  /** Mark the stream position as the start of a new token. */
2762  void start_token() {
2763  m_tok_start = m_ptr;
2764  m_tok_end = m_ptr;
2765 
2768  }
2769 
2770  /**
2771  Adjust the starting position of the current token.
2772  This is used to compensate for starting whitespace.
2773  */
2774  void restart_token() {
2775  m_tok_start = m_ptr;
2777  }
2778 
2779  /** Get the token start position, in the raw buffer. */
2780  const char *get_tok_start() const { return m_tok_start; }
2781 
2782  /** Get the token start position, in the pre-processed buffer. */
2783  const char *get_cpp_tok_start() const { return m_cpp_tok_start; }
2784 
2785  /** Get the token end position, in the raw buffer. */
2786  const char *get_tok_end() const { return m_tok_end; }
2787 
2788  /** Get the token end position, in the pre-processed buffer. */
2789  const char *get_cpp_tok_end() const { return m_cpp_tok_end; }
2790 
2791  /** Get the current stream pointer, in the raw buffer. */
2792  const char *get_ptr() const { return m_ptr; }
2793 
2794  /** Get the current stream pointer, in the pre-processed buffer. */
2795  const char *get_cpp_ptr() const { return m_cpp_ptr; }
2796 
2797  /** Get the length of the current token, in the raw buffer. */
2798  uint yyLength() const {
2799  /*
2800  The assumption is that the lexical analyser is always 1 character ahead,
2801  which the -1 account for.
2802  */
2804  return (uint)((m_ptr - m_tok_start) - 1);
2805  }
2806 
2807  /** Get the utf8-body string. */
2808  const char *get_body_utf8_str() const { return m_body_utf8; }
2809 
2810  /** Get the utf8-body length. */
2812  return (uint)(m_body_utf8_ptr - m_body_utf8);
2813  }
2814 
2815  void body_utf8_start(THD *thd, const char *begin_ptr);
2816  void body_utf8_append(const char *ptr);
2817  void body_utf8_append(const char *ptr, const char *end_ptr);
2818  void body_utf8_append_literal(THD *thd, const LEX_STRING *txt,
2819  const CHARSET_INFO *txt_cs,
2820  const char *end_ptr);
2821 
2822  uint get_lineno(const char *raw_ptr) const;
2823 
2824  /** Current thread. */
2826 
2827  /** Current line number. */
2829 
2830  /** Length of the last token parsed. */
2832 
2833  /** Interface with bison, value of the last token parsed. */
2835 
2836  /**
2837  LALR(2) resolution, look ahead token.
2838  Value of the next token to return, if any,
2839  or -1, if no token was parsed in advance.
2840  Note: 0 is a legal token, and represents YYEOF.
2841  */
2843 
2844  /** LALR(2) resolution, value of the look ahead token.*/
2846 
2847  /// Skip adding of the current token's digest since it is already added
2848  ///
2849  /// Usually we calculate a digest token by token at the top-level function
2850  /// of the lexer: MYSQLlex(). However, some complex ("hintable") tokens break
2851  /// that data flow: for example, the `SELECT /*+ HINT(t) */` is the single
2852  /// token from the main parser's point of view, and we add the "SELECT"
2853  /// keyword to the digest buffer right after the lex_one_token() call,
2854  /// but the "/*+ HINT(t) */" is a sequence of separate tokens from the hint
2855  /// parser's point of view, and we add those tokens to the digest buffer
2856  /// *inside* the lex_one_token() call. Thus, the usual data flow adds
2857  /// tokens from the "/*+ HINT(t) */" string first, and only than it appends
2858  /// the "SELECT" keyword token to that stream: "/*+ HINT(t) */ SELECT".
2859  /// This is not acceptable, since we use the digest buffer to restore
2860  /// query strings in their normalized forms, so the order of added tokens is
2861  /// important. Thus, we add tokens of "hintable" keywords to a digest buffer
2862  /// right in the hint parser and skip adding of them at the caller with the
2863  /// help of skip_digest flag.
2864  bool skip_digest;
2865 
2866  void add_digest_token(uint token, Lexer_yystype *yylval);
2867 
2868  void reduce_digest_token(uint token_left, uint token_right);
2869 
2870  /**
2871  True if this scanner tokenizes a partial query (partition expression,
2872  generated column expression etc.)
2873 
2874  @return true if parsing a partial query, otherwise false.
2875  */
2876  bool is_partial_parser() const { return grammar_selector_token >= 0; }
2877 
2878  /**
2879  Outputs warnings on deprecated charsets in complete SQL statements
2880 
2881  @param [in] cs The character set/collation to check for a deprecation.
2882  @param [in] alias The name/alias of @p cs.
2883  */
2885  const char *alias) const {
2886  if (!is_partial_parser()) {
2887  ::warn_on_deprecated_charset(m_thd, cs, alias);
2888  }
2889  }
2890 
2891  /**
2892  Outputs warnings on deprecated collations in complete SQL statements
2893 
2894  @param [in] collation The collation to check for a deprecation.
2895  */
2896  void warn_on_deprecated_collation(const CHARSET_INFO *collation) const {
2897  if (!is_partial_parser()) {
2899  }
2900  }
2901 
2903 
2904  private:
2905  /** Pointer to the current position in the raw input stream. */
2906  char *m_ptr;
2907 
2908  /** Starting position of the last token parsed, in the raw buffer. */
2909  const char *m_tok_start;
2910 
2911  /** Ending position of the previous token parsed, in the raw buffer. */
2912  const char *m_tok_end;
2913 
2914  /** End of the query text in the input stream, in the raw buffer. */
2915  const char *m_end_of_query;
2916 
2917  /** Begining of the query text in the input stream, in the raw buffer. */
2918  const char *m_buf;
2919 
2920  /** Length of the raw buffer. */
2922 
2923  /** Echo the parsed stream to the pre-processed buffer. */
2924  bool m_echo;
2926 
2927  /** Pre-processed buffer. */
2928  char *m_cpp_buf;
2929 
2930  /** Pointer to the current position in the pre-processed input stream. */
2931  char *m_cpp_ptr;
2932 
2933  /**
2934  Starting position of the last token parsed,
2935  in the pre-processed buffer.
2936  */
2937  const char *m_cpp_tok_start;
2938 
2939  /**
2940  Ending position of the previous token parsed,
2941  in the pre-processed buffer.
2942  */
2943  const char *m_cpp_tok_end;
2944 
2945  /** UTF8-body buffer created during parsing. */
2947 
2948  /** Pointer to the current position in the UTF8-body buffer. */
2950 
2951  /**
2952  Position in the pre-processed buffer. The query from m_cpp_buf to
2953  m_cpp_utf_processed_ptr is converted to UTF8-body.
2954  */
2956 
2957  public:
2958  /** Current state of the lexical analyser. */
2960 
2961  /**
2962  Position of ';' in the stream, to delimit multiple queries.
2963  This delimiter is in the raw buffer.
2964  */
2965  const char *found_semicolon;
2966 
2967  /** Token character bitmaps, to detect 7bit strings. */
2969 
2970  /** SQL_MODE = IGNORE_SPACE. */
2972 
2973  /**
2974  true if we're parsing a prepared statement: in this mode
2975  we should allow placeholders.
2976  */
2978  /**
2979  true if we should allow multi-statements.
2980  */
2982 
2983  /** State of the lexical analyser for comments. */
2986 
2987  /**
2988  Starting position of the TEXT_STRING or IDENT in the pre-processed
2989  buffer.
2990 
2991  NOTE: this member must be used within MYSQLlex() function only.
2992  */
2993  const char *m_cpp_text_start;
2994 
2995  /**
2996  Ending position of the TEXT_STRING or IDENT in the pre-processed
2997  buffer.
2998 
2999  NOTE: this member must be used within MYSQLlex() function only.
3000  */
3001  const char *m_cpp_text_end;
3002 
3003  /**
3004  Character set specified by the character-set-introducer.
3005 
3006  NOTE: this member must be used within MYSQLlex() function only.
3007  */
3009 
3010  /**
3011  Current statement digest instrumentation.
3012  */
3014 
3015  /**
3016  The synthetic 1st token to prepend token stream with.
3017 
3018  This token value tricks parser to simulate multiple %start-ing points.
3019  Currently the grammar is aware of 4 such synthetic tokens:
3020  1. GRAMMAR_SELECTOR_PART for partitioning stuff from DD,
3021  2. GRAMMAR_SELECTOR_GCOL for generated column stuff from DD,
3022  3. GRAMMAR_SELECTOR_EXPR for generic single expressions from DD/.frm.
3023  4. GRAMMAR_SELECTOR_CTE for generic subquery expressions from CTEs.
3024  5. -1 when parsing with the main grammar (no grammar selector available).
3025 
3026  @note yylex() is expected to return the value of type int:
3027  0 is for EOF and everything else for real token numbers.
3028  Bison, in its turn, generates positive token numbers.
3029  So, the negative grammar_selector_token means "not a token".
3030  In other words, -1 is "empty value".
3031  */
3033 
3034  bool text_string_is_7bit() const { return !(tok_bitmap & 0x80); }
3035 };
3036 
3037 class LEX_COLUMN {
3038  public:
3041  LEX_COLUMN(const String &x, const uint &y) : column(x), rights(y) {}
3042 };
3043 
3044 enum class role_enum;
3045 
3046 /*
3047  This structure holds information about grantor's context
3048 */
3050  public:
3051  LEX_GRANT_AS();
3052  void cleanup();
3053 
3054  public:
3059 };
3060 
3061 /* The state of the lex parsing. This is saved in the THD struct */
3062 
3063 struct LEX : public Query_tables_list {
3064  friend bool lex_start(THD *thd);
3065 
3066  SELECT_LEX_UNIT *unit; ///< Outer-most query expression
3067  /// @todo: select_lex can be replaced with unit->first-select()
3068  SELECT_LEX *select_lex; ///< First query block
3069  SELECT_LEX *all_selects_list; ///< List of all query blocks
3070  private:
3071  /* current SELECT_LEX in parsing */
3073 
3074  public:
3075  inline SELECT_LEX *current_select() const { return m_current_select; }
3076 
3077  /*
3078  We want to keep current_thd out of header files, so the debug assert
3079  is moved to the .cc file.
3080  */
3082  inline void set_current_select(SELECT_LEX *select) {
3083 #ifndef DBUG_OFF
3085 #endif
3086  m_current_select = select;
3087  }
3088  /// @return true if this is an EXPLAIN statement
3089  bool is_explain() const { return explain_format != nullptr; }
3091  char *help_arg;
3092  char *to_log; /* For PURGE MASTER LOGS TO */
3094  // Widcard from SHOW ... LIKE <wildcard> statements.
3097  LEX_STRING binlog_stmt_arg; ///< Argument of the BINLOG event statement.
3104 
3105  /* Optimizer hints */
3107 
3108  /* maintain a list of used plugins for this LEX */
3112 
3113  /// Table being inserted into (may be a view)
3115  /// Leaf table being inserted into (always a base table)
3117 
3118  /** SELECT of CREATE VIEW statement */
3120 
3121  /* Partition info structure filled in by PARTITION BY parse part */
3123 
3124  /*
3125  The definer of the object being created (view, trigger, stored routine).
3126  I.e. the value of DEFINER clause.
3127  */
3129 
3134 
3136 
3137  // PURGE statement-specific fields:
3139 
3140  // KILL statement-specific fields:
3142 
3143  // other stuff:
3145  List<Item_func_set_user_var> set_var_list; // in-query assignment list
3146  /**
3147  List of placeholders ('?') for parameters of a prepared statement. Because
3148  we append to this list during parsing, it is naturally sorted by
3149  position of the '?' in the query string. The code which fills placeholders
3150  with user-supplied values, and the code which writes a query for
3151  statement-based logging, rely on this order.
3152  This list contains only real placeholders, not the clones which originate
3153  in a re-parsed CTE definition.
3154  */
3156 
3157  bool locate_var_assignment(const Name_string &name);
3158 
3159  void insert_values_map(Field *f1, Field *f2) {
3161  insert_update_values_map = new std::map<Field *, Field *>;
3162  insert_update_values_map->insert(std::make_pair(f1, f2));
3163  }
3166  insert_update_values_map->clear();
3167  delete insert_update_values_map;
3169  }
3170  }
3171  bool has_values_map() const { return insert_update_values_map != NULL; }
3172  std::map<Field *, Field *>::iterator begin_values_map() {
3173  return insert_update_values_map->begin();
3174  }
3175  std::map<Field *, Field *>::iterator end_values_map() {
3176  return insert_update_values_map->end();
3177  }
3178 
3179  private:
3180  /*
3181  With Visual Studio, an std::map will always allocate two small objects
3182  on the heap. Sometimes we put LEX objects in a MEM_ROOT, and never run
3183  the LEX DTOR. To avoid memory leaks, put this std::map on the heap,
3184  and call clear_values_map() at the end of each statement.
3185  */
3186  std::map<Field *, Field *> *insert_update_values_map;
3187 
3188  public:
3189  /*
3190  A stack of name resolution contexts for the query. This stack is used
3191  at parse time to set local name resolution contexts for various parts
3192  of a query. For example, in a JOIN ... ON (some_condition) clause the
3193  Items in 'some_condition' must be resolved only against the operands
3194  of the the join, and not against the whole clause. Similarly, Items in
3195  subqueries should be resolved against the subqueries (and outer queries).
3196  The stack is used in the following way: when the parser detects that
3197  all Items in some clause need a local context, it creates a new context
3198  and pushes it on the stack. All newly created Items always store the
3199  top-most context in the stack. Once the parser leaves the clause that
3200  required a local context, the parser pops the top-most context.
3201  */
3203 
3206  HA_CHECK_OPT check_opt; // check/repair options
3209  LEX_MASTER_INFO mi; // used by CHANGE MASTER
3215  /**
3216  This field is used as a work field during resolving to validate
3217  the use of aggregate functions. For example in a query
3218  SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
3219  MIN(i) in the WHERE clause is not allowed since only non-aggregated data
3220  is present, whereas MIN(i) in the HAVING clause is allowed because HAVING
3221  operates on the output of a grouping operation.
3222  Each query block is assigned a nesting level. This field is a bit field
3223  that contains the value one in the position of that nesting level if
3224  aggregate functions are allowed for that query block.
3225  */
3227  /**
3228  Windowing functions are not allowed in HAVING - in contrast to group
3229  aggregates - then we need to be stricter than allow_sum_func.
3230  One bit per query block, as allow_sum_func.
3231  */
3233 
3235 
3236  /*
3237  Usually `expr` rule of yacc is quite reused but some commands better
3238  not support subqueries which comes standard with this rule, like
3239  KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
3240  syntax error back.
3241  */
3243  /**
3244  If currently re-parsing a CTE's definition, this is the offset in bytes
3245  of that definition in the original statement which had the WITH
3246  clause. Otherwise this is 0.
3247  */
3249 
3250  enum SSL_type ssl_type; /* defined in violite.h */
3255 
3256  /// QUERY ID for SHOW PROFILE
3262  int select_number; ///< Number of query block (by EXPLAIN)
3265  /**
3266  @todo ensure that correct CONTEXT_ANALYSIS_ONLY is set for all preparation
3267  code, so we can fully rely on this field.
3268  */
3274  // For show commands to show hidden columns and indexes.
3276 
3278 
3279  /**
3280  Whether this query will return the same answer every time, given unchanged
3281  data. Used to be for the query cache, but is now used to find out if an
3282  expression is usable for partitioning.
3283  */
3286 
3287  private:
3288  bool ignore;
3289 
3290  public:
3291  bool is_ignore() const { return ignore; }
3292  void set_ignore(bool ignore_param) { ignore = ignore_param; }
3295  /* Prepared statements SQL syntax:*/
3296  LEX_CSTRING prepared_stmt_name; /* Statement name (in all queries) */
3297  /*
3298  Prepared statement query text or name of variable that holds the
3299  prepared statement (in PREPARE ... queries)
3300  */
3302  /* If true, prepared_stmt_code is a name of variable that holds the query */
3304  /* Names of user variables holding parameters (in EXECUTE) */
3308  bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */
3313 
3314  private:
3315  bool m_broken; ///< see mark_broken()
3316  /**
3317  Set to true when execution has started (after parsing, tables opened and
3318  query preparation is complete. Used to track arena state for SPs).
3319  */
3321  /// Current SP parsing context.
3322  /// @see also sp_head::m_root_parsing_ctx.
3324 
3325  /**
3326  Statement context for SELECT_LEX::make_active_options.
3327  */
3329 
3330  public:
3331  /// @return a bit set of options set for this statement
3333  /**
3334  Add options to values of m_statement_options. options is an ORed
3335  bit set of options defined in query_options.h
3336 
3337  @param options Add this set of options to the set already in
3338  m_statement_options
3339  */
3342  }
3343  bool is_broken() const { return m_broken; }
3344  /**
3345  Certain permanent transformations (like in2exists), if they fail, may
3346  leave the LEX in an inconsistent state. They should call the
3347  following function, so that this LEX is not reused by another execution.
3348 
3349  @todo If lex_start () were a member function of LEX, the "broken"
3350  argument could always be "true" and thus could be removed.
3351  */
3352  void mark_broken(bool broken = true) {
3353  if (broken) {
3354  /*
3355  "OPEN <cursor>" cannot be re-prepared if the cursor uses no tables
3356  ("SELECT FROM DUAL"). Indeed in that case cursor_query is left empty
3357  in constructions of sp_instr_cpush, and thus
3358  sp_lex_instr::parse_expr() cannot re-prepare. So we mark the statement
3359  as broken only if tables are used.
3360  */
3361  if (is_metadata_used()) m_broken = true;
3362  } else
3363  m_broken = false;
3364  }
3365 
3366  bool is_exec_started() const { return m_exec_started; }
3367 
3371 
3373  sp_current_parsing_ctx = ctx;
3374  }
3375 
3376  /// Check if the current statement uses meta-data (uses a table or a stored
3377  /// routine).
3378  bool is_metadata_used() const {
3379  return query_tables != NULL ||
3380  (sroutines != nullptr && !sroutines->empty());
3381  }
3382 
3383  public:
3385 
3387 
3388  bool only_view; /* used for SHOW CREATE TABLE/VIEW */
3389  /*
3390  view created to be run from definer (standard behaviour)
3391  */
3393 
3394  /**
3395  Intended to point to the next word after DEFINER-clause in the
3396  following statements:
3397 
3398  - CREATE TRIGGER (points to "TRIGGER");
3399  - CREATE PROCEDURE (points to "PROCEDURE");
3400  - CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE");
3401  - CREATE EVENT (points to "EVENT")
3402 
3403  This pointer is required to add possibly omitted DEFINER-clause to the
3404  DDL-statement before dumping it to the binlog.
3405  */
3407  const char *stmt_definition_end;
3408 
3409  /**
3410  During name resolution search only in the table list given by
3411  Name_resolution_context::first_name_resolution_table and
3412  Name_resolution_context::last_name_resolution_table
3413  (see Item_field::fix_fields()).
3414  */
3416 
3417  bool is_lex_started; /* If lex_start() did run. For debugging. */
3418  /// Set to true while resolving values in ON DUPLICATE KEY UPDATE clause
3420 
3422 
3423  // Maximum execution time for a statement.
3425 
3426  /*
3427  To flag the current statement as dependent for binary logging
3428  on explicit_defaults_for_timestamp
3429  */
3431 
3432  /**
3433  Used to inform the parser whether it should contextualize the parse
3434  tree. When we get a pure parser this will not be needed.
3435  */
3437 
3438  LEX();
3439 
3440  virtual ~LEX();
3441 
3442  /// Reset query context to initial state
3443  void reset();
3444 
3445  /// Create an empty query block within this LEX object.
3447 
3448  /// Create query expression object that contains one query block.
3449  SELECT_LEX *new_query(SELECT_LEX *curr_select);
3450 
3451  /// Create query block and attach it to the current query expression.
3452  SELECT_LEX *new_union_query(SELECT_LEX *curr_select, bool distinct,
3453  bool check_syntax = true);
3454 
3455  /// Create top-level query expression and query block.
3456  bool new_top_level_query();
3457 
3458  /// Create query expression and query block in existing memory objects.
3459  void new_static_query(SELECT_LEX_UNIT *sel_unit, SELECT_LEX *select);
3460 
3462  return (context_analysis_only &
3464  }
3465 
3468  }
3469 
3470  /**
3471  Set the current query as uncacheable.
3472 
3473  @param curr_select Current select query block
3474  @param cause Why this query is uncacheable.
3475 
3476  @details
3477  All query blocks representing subqueries, from the current one up to
3478  the outer-most one, but excluding the main query block, are also set
3479  as uncacheable.
3480  */
3481  void set_uncacheable(SELECT_LEX *curr_select, uint8 cause) {
3482  safe_to_cache_query = false;
3483 
3484  if (m_current_select == NULL) return;
3485  SELECT_LEX *sl;
3486  SELECT_LEX_UNIT *un;
3487  for (sl = curr_select, un = sl->master_unit(); un != unit;
3488  sl = sl->outer_select(), un = sl->master_unit()) {
3489  sl->uncacheable |= cause;
3490  un->uncacheable |= cause;
3491  }
3492  }
3494 
3495  TABLE_LIST *unlink_first_table(bool *link_to_local);
3496  void link_first_table_back(TABLE_LIST *first, bool link_to_local);
3497  void first_lists_tables_same();
3498 
3499  bool can_use_merged();
3500  bool can_not_use_merged();
3501  bool need_correct_ident();
3502  /*
3503  Is this update command where 'WHITH CHECK OPTION' clause is important
3504 
3505  SYNOPSIS
3506  LEX::which_check_option_applicable()
3507 
3508  RETURN
3509  true have to take 'WHITH CHECK OPTION' clause into account
3510  false 'WHITH CHECK OPTION' clause do not need
3511  */
3513  switch (sql_command) {
3514  case SQLCOM_UPDATE:
3515  case SQLCOM_UPDATE_MULTI:
3516  case SQLCOM_INSERT:
3517  case SQLCOM_INSERT_SELECT:
3518  case SQLCOM_REPLACE:
3519  case SQLCOM_REPLACE_SELECT:
3520  case SQLCOM_LOAD:
3521  return true;
3522  default:
3523  return false;
3524  }
3525  }
3526 
3528 
3530  return context_stack.push_front(context);
3531  }
3532 
3534 
3535  bool copy_db_to(char const **p_db, size_t *p_db_length) const;
3536 
3537  bool copy_db_to(char **p_db, size_t *p_db_length) const {
3538  return copy_db_to(const_cast<const char **>(p_db), p_db_length);
3539  }
3540 
3542 
3545 
3546  bool table_or_sp_used();
3547 
3548  /**
3549  @brief check if the statement is a single-level join
3550  @return result of the check
3551  @retval true The statement doesn't contain subqueries, unions and
3552  stored procedure calls.
3553  @retval false There are subqueries, UNIONs or stored procedure calls.
3554  */
3556  /*
3557  This check exploits the fact that the last added to all_select_list is
3558  on its top. So select_lex (as the first added) will be at the tail
3559  of the list.
3560  */
3561  if (select_lex == all_selects_list &&
3562  (sroutines == nullptr || sroutines->empty())) {
3564  return true;
3565  }
3566  return false;
3567  }
3568 
3569  /**
3570  IS schema queries read some dynamic table statistics from SE.
3571  These statistics are cached, to avoid opening of table more
3572  than once while preparing a single output record buffer.
3573  */
3576 
3577  bool accept(Select_lex_visitor *visitor);
3578 
3579  bool set_wild(LEX_STRING);
3580  void clear_privileges();
3581 
3582  bool make_sql_cmd(Parse_tree_root *parse_tree);
3583 
3584  private:
3585  /**
3586  Context object used by secondary storage engines to store query
3587  state during optimization and execution.
3588  */
3590 
3591  public:
3592  /**
3593  Gets the secondary engine execution context for this statement.
3594  */
3596  const {
3598  }
3599 
3600  /**
3601  Sets the secondary engine execution context for this statement.
3602  The old context object is destroyed, if there is one. Can be set
3603  to nullptr to destroy the old context object and clear the
3604  pointer.
3605 
3606  The supplied context object should be allocated on the execution
3607  MEM_ROOT, so that its memory doesn't have to be manually freed
3608  after query execution.
3609  */
3612 };
3613 
3614 /**
3615  The internal state of the syntax parser.
3616  This object is only available during parsing,
3617  and is private to the syntax parser implementation (sql_yacc.yy).
3618 */
3619 class Yacc_state {
3620  public:
3622 
3623  void reset() {
3624  if (yacc_yyss != NULL) {
3625  my_free(yacc_yyss);
3626  yacc_yyss = NULL;
3627  }
3628  if (yacc_yyvs != NULL) {
3629  my_free(yacc_yyvs);
3630  yacc_yyvs = NULL;
3631  }
3632  if (yacc_yyls != NULL) {
3633  my_free(yacc_yyls);
3634  yacc_yyls = NULL;
3635  }
3638  }
3639 
3640  ~Yacc_state();
3641 
3642  /**
3643  Reset part of the state which needs resetting before parsing
3644  substatement.
3645  */
3649  }
3650 
3651  /**
3652  Bison internal state stack, yyss, when dynamically allocated using
3653  my_yyoverflow().
3654  */
3656 
3657  /**
3658  Bison internal semantic value stack, yyvs, when dynamically allocated using
3659  my_yyoverflow().
3660  */
3662 
3663  /**
3664  Bison internal location value stack, yyls, when dynamically allocated using
3665  my_yyoverflow().
3666  */
3668 
3669  /**
3670  Type of lock to be used for tables being added to the statement's
3671  table list in table_factor, table_alias_ref, single_multi and
3672  table_wild_one rules.
3673  Statements which use these rules but require lock type different
3674  from one specified by this member have to override it by using
3675  SELECT_LEX::set_lock_for_tables() method.
3676 
3677  The default value of this member is TL_READ_DEFAULT. The only two
3678  cases in which we change it are:
3679  - When parsing SELECT HIGH_PRIORITY.
3680  - Rule for DELETE. In which we use this member to pass information
3681  about type of lock from delete to single_multi part of rule.
3682 
3683  We should try to avoid introducing new use cases as we would like
3684  to get rid of this member eventually.
3685  */
3687 
3688  /**
3689  The type of requested metadata lock for tables added to
3690  the statement table list.
3691  */
3693 
3694  /*
3695  TODO: move more attributes from the LEX structure here.
3696  */
3697 };
3698 
3699 /**
3700  Input parameters to the parser.
3701 */
3704 
3706 };
3707 
3708 /**
3709  Internal state of the parser.
3710  The complete state consist of:
3711  - input parameters that control the parser behavior
3712  - state data used during lexical parsing,
3713  - state data used during syntactic parsing.
3714 */
3716  protected:
3717  /**
3718  Constructor for special parsers of partial SQL clauses (DD)
3719 
3720  @param grammar_selector_token See Lex_input_stream::grammar_selector_token
3721  */
3722  explicit Parser_state(int grammar_selector_token)
3723  : m_input(), m_lip(grammar_selector_token), m_yacc(), m_comment(false) {}
3724 
3725  public:
3727 
3728  /**
3729  Object initializer. Must be called before usage.
3730 
3731  @retval false OK
3732  @retval true Error
3733  */
3734  bool init(THD *thd, const char *buff, size_t length) {
3735  return m_lip.init(thd, buff, length);
3736  }
3737 
3738  void reset(const char *found_semicolon, size_t length) {
3739  m_lip.reset(found_semicolon, length);
3740  m_yacc.reset();
3741  }
3742 
3743  /// Signal that the current query has a comment
3744  void add_comment() { m_comment = true; }
3745  /// Check whether the current query has a comment
3746  bool has_comment() const { return m_comment; }
3747 
3748  public:
3752  /**
3753  Current performance digest instrumentation.
3754  */
3756 
3757  private:
3758  bool m_comment; ///< True if current query contains comments
3759 };
3760 
3761 /**
3762  Parser state for partition expression parser (.frm/DD stuff)
3763 */
3765  public:
3767 
3769 };
3770 
3771 /**
3772  Parser state for generated column expression parser (.frm/DD stuff)
3773 */
3775  public:
3777 
3779 };
3780 
3781 /**
3782  Parser state for single expression parser (.frm/DD stuff)
3783 */
3785  public:
3787 
3789 };
3790 
3791 /**
3792  Parser state for CTE subquery parser
3793 */
3795  public:
3797 
3799 };
3800 
3801 struct st_lex_local : public LEX {
3802  static void *operator new(size_t size) noexcept {
3803  return (*THR_MALLOC)->Alloc(size);
3804  }
3805  static void *operator new(size_t size, MEM_ROOT *mem_root,
3806  const std::nothrow_t &arg MY_ATTRIBUTE((unused)) =
3807  std::nothrow) noexcept {
3808  return mem_root->Alloc(size);
3809  }
3810  static void operator delete(void *ptr MY_ATTRIBUTE((unused)),
3811  size_t size MY_ATTRIBUTE((unused))) {
3812  TRASH(ptr, size);
3813  }
3814  static void operator delete(
3815  void *, MEM_ROOT *, const std::nothrow_t &)noexcept { /* Never called */
3816  }
3817 };
3818 
3819 extern bool lex_init(void);
3820 extern void lex_free(void);
3821 extern bool lex_start(THD *thd);
3822 extern void lex_end(LEX *lex);
3823 extern int MYSQLlex(union YYSTYPE *, struct YYLTYPE *, class THD *);
3824 
3825 extern void trim_whitespace(const CHARSET_INFO *cs, LEX_STRING *str);
3826 
3827 extern bool is_lex_native_function(const LEX_STRING *name);
3828 
3829 bool is_keyword(const char *name, size_t len);
3830 bool db_is_default_db(const char *db, size_t db_len, const THD *thd);
3831 
3833 
3834 void print_derived_column_names(const THD *thd, String *str,
3836 
3837 /**
3838  @} (End of group GROUP_PARSER)
3839 */
3840 
3841 /**
3842  Check if the given string is invalid using the system charset.
3843 
3844  @param string_val Reference to the string.
3845  @param charset_info Pointer to charset info.
3846 
3847  @return true if the string has an invalid encoding using
3848  the system charset else false.
3849 */
3850 
3851 inline bool is_invalid_string(const LEX_CSTRING &string_val,
3852  const CHARSET_INFO *charset_info) {
3853  size_t valid_len;
3854  bool len_error;
3855 
3856  if (validate_string(charset_info, string_val.str, string_val.length,
3857  &valid_len, &len_error)) {
3858  char hexbuf[7];
3859  octet2hex(
3860  hexbuf, string_val.str + valid_len,
3861  static_cast<uint>(std::min<size_t>(string_val.length - valid_len, 3)));
3862  my_error(ER_INVALID_CHARACTER_STRING, MYF(0), charset_info->csname, hexbuf);
3863  return true;
3864  }
3865  return false;
3866 }
3867 
3868 bool walk_item(Item *item, Select_lex_visitor *visitor);
3870 bool accept_table(TABLE_LIST *t, Select_lex_visitor *visitor);
3871 bool accept_for_join(List<TABLE_LIST> *tables, Select_lex_visitor *visitor);
3872 #endif /* SQL_LEX_INCLUDED */
TABLE_LIST * leaf_tables
Points to first leaf table of query block.
Definition: sql_lex.h:1074
Definition: sql_udf.h:42
static const char * stmt_accessed_table_string(enum_stmt_accessed_table accessed_table)
Definition: sql_lex.h:2335
#define TRASH(A, B)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:70
TABLE * table
Definition: sql_lex.h:571
SELECT_LEX * union_distinct
Points to last query block which has UNION DISTINCT on its left.
Definition: sql_lex.h:655
Parser_input m_input
Definition: sql_lex.h:3749
INSERT into auto-inc field which is not the first part in composed primary key.
Definition: sql_lex.h:2179
If a substatement inserts into or updates a table that has a column with an unsafe DEFAULT expression...
Definition: sql_lex.h:2198
bool prepare_fake_select_lex(THD *thd)
Prepare the fake_select_lex query block.
Definition: sql_union.cc:381
char * ssl_cipher
Definition: sql_lex.h:3093
SELECT_LEX * global_parameters() const
Pointer to query block containing global parameters for query.
Definition: sql_lex.h:628
bool check_view_privileges(THD *thd, ulong want_privilege_first, ulong want_privilege_next)
Check privileges for the view tables merged into a query block.
Definition: sql_resolver.cc:834
bool db_is_default_db(const char *db, size_t db_len, const THD *thd)
Definition: sql_lex.cc:2752
unsigned long long int ulonglong
Definition: my_inttypes.h:74
Representation of an SQL command.
Definition: sql_cmd.h:63
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:4482
#define DBUG_RETURN(a1)
Definition: my_dbug.h:139
char * relay_log_name
Definition: sql_lex.h:343
Definition: partition_info.h:208
Item ** add_hidden_item(Item *item)
Add item to the hidden part of select list.
Definition: sql_resolver.cc:4580
Definition: sql_lex.h:176
char * ssl_cert
Definition: sql_lex.h:340
bool change_group_ref_for_cond(THD *thd, Item_cond *cond, bool *changed)
Similar to change_group_ref_for_func, except we are looking into an AND or OR conditions instead of f...
Definition: sql_resolver.cc:4313
LEX_CSTRING prepared_stmt_name
Definition: sql_lex.h:3296
This file defines all base public constants related to triggers in MySQL.
List< Item_param > param_list
List of placeholders (&#39;?&#39;) for parameters of a prepared statement.
Definition: sql_lex.h:3155
bool add_ftfunc_list(List< Item_func_match > *ftfuncs)
Add a list of full-text function elements into a query block.
Definition: sql_resolver.cc:3568
static bool column_names
Definition: mysql.cc:155
bool optimize(THD *thd)
Optimize all query blocks of a query expression, including fake_select_lex.
Definition: sql_union.cc:707
bool add_joined_table(TABLE_LIST *table)
Add a table to the current join list.
Definition: sql_parse.cc:6124
void remove_base_options(ulonglong options)
Remove base options from a query block.
Definition: sql_lex.h:880
bool has_values_map() const
Definition: sql_lex.h:3171
void print_update_options(String *str)
Print UPDATE options.
Definition: sql_lex.cc:3092
bool is_union() const
Definition: sql_lex.h:1834
unsigned char uchar
Definition: my_inttypes.h:51
bool cleanup(THD *thd, bool full)
Cleanup this query expression object after preparation or one round of execution. ...
Definition: sql_union.cc:1266
~Yacc_state()
Definition: sql_lex.cc:758
#define SELECT_DISTINCT
Definition: query_options.h:51
SQL_I_List< ORDER > group_list
GROUP BY clause.
Definition: sql_lex.h:1028
Definition: sql_optimizer.h:177
Structure to hold parameters for CHANGE MASTER, START SLAVE, and STOP SLAVE.
Definition: sql_lex.h:304
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:3246
Our own string classes, used pervasively throughout the executor.
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:1212
bool safe_to_cache_query
Whether this query will return the same answer every time, given unchanged data.
Definition: sql_lex.h:3284
The internal state of the syntax parser.
Definition: sql_lex.h:3619
uint reparse_common_table_expr_at
If currently re-parsing a CTE&#39;s definition, this is the offset in bytes of that definition in the ori...
Definition: sql_lex.h:3248
LEX_CSTRING key_name
Definition: sql_lex.h:401
void destroy_query_tables_list()
Definition: sql_lex.cc:3499
bool optimize(THD *thd)
Optimize a query block and all inner query expressions.
Definition: sql_select.cc:1741
Utility RAII class to save/modify/restore the semijoin_disallowed flag.
Definition: sql_lex.h:1843
void trim_whitespace(const CHARSET_INFO *cs, LEX_STRING *str)
Definition: sql_lex.cc:1935
"public" interface to sys_var - server configuration variables.
bool decorrelate_join_conds(TABLE_LIST *sj_nest, List< TABLE_LIST > *join_list)
Decorrelate join conditions for a subquery.
Definition: sql_resolver.cc:2348
sp_name * spname
Definition: sql_lex.h:3307
bool merge_derived(THD *thd, TABLE_LIST *derived_table)
Merge derived table into query block.
Definition: sql_resolver.cc:2986
Parser_state()
Definition: sql_lex.h:3726
Definition: sql_lex.h:179
const char * db_name
Definition: rules_table_service.cc:54
enum LEX_MASTER_INFO::@101 heartbeat_opt
ulonglong table_map
Definition: my_table_map.h:32
char * host
Definition: sql_lex.h:312
bool resolve_rollup_wfs(THD *thd)
Replace group by field references inside window functions with references in the the presence of ROLL...
Definition: sql_resolver.cc:4428
char * x509_issuer
Definition: sql_lex.h:3093
char * password
Definition: sql_lex.h:312
char * plugin_dir
Definition: sql_lex.h:1884
void set_base_options(ulonglong options_arg)
Set base options for a query block (and active options too)
Definition: sql_lex.h:859
Definition: mysql_lex_string.h:34
The class hold dynamic table statistics for a table.
Definition: table_stats.h:102
void set_where_cond(Item *cond)
Definition: sql_lex.h:850
bool expr_allows_subselect
Definition: sql_lex.h:3242
List< Item > * get_unit_column_types()
Get column type information for this query expression.
Definition: sql_union.cc:1383
bool grant_as_used
Definition: sql_lex.h:3055
ha_rows get_limit(THD *thd)
Get limit.
Definition: sql_lex.cc:2410
const char * m_cpp_text_end
Ending position of the TEXT_STRING or IDENT in the pre-processed buffer.
Definition: sql_lex.h:3001
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:2207
Group_list_ptrs * group_list_ptrs
Definition: sql_lex.h:1029
TABLE_LIST * next_global
Definition: table.h:3028
bool build_sj_cond(THD *thd, NESTED_JOIN *nested_join, SELECT_LEX *subq_select, table_map outer_tables_map, Item **sj_cond)
Build semijoin condition for th query block.
Definition: sql_resolver.cc:2070
bool allows_variable
Definition: sql_lex.h:2546
bool prepared
All query blocks in query expression are prepared.
Definition: sql_lex.h:565
Definition: handler.h:3173
Access to log tables is unsafe because slave and master probably log different things.
Definition: sql_lex.h:2069
bool setup_join_cond(THD *thd, List< TABLE_LIST > *tables, bool in_update)
Resolve join conditions for a join nest.
Definition: sql_resolver.cc:1384
bool no_write_to_binlog
Definition: sql_lex.h:3273
Definition: sql_lex.h:3063
void make_active_options(ulonglong added_options, ulonglong removed_options)
Make active options from base options, supplied options and environment:
Definition: sql_lex.cc:2297
bool is_explain() const
Definition: sql_lex.h:3089
Query_tables_list & operator=(Query_tables_list &&)=default
Definition: sql_lex.h:365
bool in_update_value_clause
Set to true while resolving values in ON DUPLICATE KEY UPDATE clause.
Definition: sql_lex.h:3419
Event_parse_data * event_parse_data
Definition: sql_lex.h:3386
CREATE TABLE...SELECT on a table with auto-increment column is unsafe because which rows are replaced...
Definition: sql_lex.h:2160
bool set_braces(bool value)
Definition: sql_lex.cc:2476
void restore_in_comment_state()
Definition: sql_lex.h:2629
bool saved_value
Definition: sql_lex.h:1859
bool accept(Select_lex_visitor *visitor)
Definition: sql_lex.cc:3361
Definition: sql_lex.h:177
static const char * type_str[static_cast< int >(enum_explain_type::EXPLAIN_total)]
Definition: sql_lex.h:1708
SELECT_LEX * last_select()
Definition: sql_lex.h:1245
const string name("\ame\)
T ** next
A reference to the next element in the list.
Definition: sql_list.h:51
Order clause list element.
Definition: table.h:269
LEX_USER * grant_user
Definition: sql_lex.h:3099
bool setup_base_ref_items(THD *thd)
Setup the array containing references to base items.
Definition: sql_lex.cc:2481
TABLE_LIST * unlink_first_table(bool *link_to_local)
Definition: sql_lex.cc:3974
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_lex.cc:349
Definition: sql_lex.h:1933
void propagate_unique_test_exclusion()
Propagate exclusion from unique table check into all subqueries belonging to this query block...
Definition: sql_resolver.cc:3551
SELECT_LEX * m_current_select
Definition: sql_lex.h:3072
SELECT_LEX_UNIT * sel
Definition: sql_lex.h:252
Using a UDF (user-defined function) is unsafe.
Definition: sql_lex.h:2082
Item::cond_result cond_value
Saved values of the WHERE and HAVING clauses.
Definition: sql_lex.h:1012
LEX_STRING prepared_stmt_code
Definition: sql_lex.h:3301
ulonglong m_base_options
Options assigned from parsing and throughout resolving, should not be modified after resolving is don...
Definition: sql_lex.h:934
enum LEX_MASTER_INFO::@101 retry_count_opt
enum_explain_type type()
Lookup for SELECT_LEX type.
Definition: sql_lex.cc:4215
File containing constants that can be used throughout the server.
bool check_only_full_group_by(THD *thd)
Runs checks mandated by ONLY_FULL_GROUP_BY.
Definition: sql_resolver.cc:4034
const char * get_cpp_ptr() const
Get the current stream pointer, in the pre-processed buffer.
Definition: sql_lex.h:2795
Definition: my_sqlcommand.h:52
Inserting into an autoincrement column in a stored routine is unsafe.
Definition: sql_lex.h:2078
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:55
#define IL_LT_REPEATABLE
Definition: sql_lex.h:2386
Definition: sql_lex.h:1880
SELECT_LEX * saved_fake_select_lex
SELECT_LEX that stores LIMIT and OFFSET for UNION ALL when no fake_select_lex is used.
Definition: sql_lex.h:648
Lexer_yystype * lookahead_yylval
LALR(2) resolution, value of the look ahead token.
Definition: sql_lex.h:2845
List< Item > * get_field_list()
Get field list for this query expression.
Definition: sql_union.cc:1399
bool has_sj_candidates() const
Definition: sql_lex.h:1742
partition_info * part_info
Definition: sql_lex.h:3122
Some integer typedefs for easier portability.
TABLE_LIST * get_table_list() const
Definition: sql_lex.h:1326
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
Prealloced_array< ulong, 2 > repl_ignore_server_ids
Definition: sql_lex.h:345
void print_limit(const THD *thd, String *str, enum_query_type query_type)
Definition: sql_lex.cc:2576
enum enum_trigger_action_time_type action_time
Definition: sql_lex.h:1900
bool accept(Select_lex_visitor *visitor)
Accept function for SELECT and DELETE.
Definition: sql_lex.cc:3390
KEY_CREATE_INFO key_create_info
Definition: sql_lex.h:3208
void set_sj_candidates(Mem_root_array< Item_exists_subselect *> *sj_cand)
Definition: sql_lex.h:1738
enum_keep_diagnostics
Definition: sql_lex.h:160
is the single *token from the main parser s point of and we add the SELECT *keyword to the digest buffer right after the *but the is a sequence of separate tokens from the hint *parser s point of and we add those tokens to the digest buffer **inside *the the usual data flow adds *tokens from the string and only than it appends *the SELECT keyword token to that since we use the digest buffer to restore *query strings in their normalized so the order of added tokens is *important we add tokens of hintable keywords to a digest buffer *right in the hint parser and skip adding of them at the caller with the *help of skip_digest flag *bool skip_digest
Definition: sql_lex.h:2857
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select)
Fix used tables information for a subquery after query transformations.
Definition: sql_union.cc:1429
Parser_state(int grammar_selector_token)
Constructor for special parsers of partial SQL clauses (DD)
Definition: sql_lex.h:3722
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:583
INSERT...REPLACE SELECT is unsafe because which rows are replaced depends on the order that rows are ...
Definition: sql_lex.h:2138
bool is_partial_parser() const
True if this scanner tokenizes a partial query (partition expression, generated column expression etc...
Definition: sql_lex.h:2876
void set_empty_query()
Set query block as returning no data.
Definition: sql_lex.h:1631
char * yyUnput(char ch)
Puts a character back into the stream, canceling the effect of the last yyGet() or yySkip()...
Definition: sql_lex.h:2721
bool subquery_in_having
HAVING clause contains subquery => we can&#39;t close tables before query processing end even if we use t...
Definition: sql_lex.h:1171
SELECT_LEX * fake_select_lex
Helper query block for query expression with UNION or multi-level ORDER BY/LIMIT. ...
Definition: sql_lex.h:643
void set_optimized()
Definition: sql_lex.h:735
bool print_error(const THD *thd, String *str)
Print error.
Definition: sql_lex.cc:3053
const char * m_tok_start
Starting position of the last token parsed, in the raw buffer.
Definition: sql_lex.h:2909
uint binlog_unsafe_map[256]
Definition: sql_lex.cc:4708
sp_pcontext * sp_current_parsing_ctx
Current SP parsing context.
Definition: sql_lex.h:3323
void include_standalone(SELECT_LEX_UNIT *sel, SELECT_LEX **ref)
Include query block inside a query expression, but do not link.
Definition: sql_lex.cc:4283
INSERT...IGNORE SELECT is unsafe because which rows are ignored depends on the order that rows are re...
Definition: sql_lex.h:2117
void print_windows(const THD *thd, String *str, enum_query_type query_type)
Print details of Windowing functions.
Definition: sql_lex.cc:3310
void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last)
Definition: sql_lex.h:2029
bool mixed_union_operators() const
Definition: sql_union.cc:1414
uint sroutines_list_own_elements
Definition: sql_lex.h:1976
ulong type
Definition: sql_lex.h:3214
bool test_limit()
Definition: sql_lex.cc:2368
ulonglong pos
Definition: sql_lex.h:316
void insert_values_map(Field *f1, Field *f2)
Definition: sql_lex.h:3159
bool grant_privilege
Definition: sql_lex.h:3260
void reset(const char *found_semicolon, size_t length)
Definition: sql_lex.h:3738
Table_ident(const LEX_CSTRING &db_arg, const LEX_CSTRING &table_arg)
Definition: sql_lex.h:257
const char * str
Definition: mysql_lex_string.h:40
Table_function * table_function
Definition: sql_lex.h:253
List< TABLE_LIST > top_join_list
join list of the top level
Definition: sql_lex.h:1061
char * network_namespace
Definition: sql_lex.h:312
float heartbeat_period
Definition: sql_lex.h:314
struct module_t * m
Definition: dbug_analyze.cc:469
bool first_execution
This variable is required to ensure proper work of subqueries and stored procedures.
Definition: sql_lex.h:1184
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:534
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:847
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_lex.cc:333
keep diagnostics area after parse error
Definition: sql_lex.h:164
Query_result * result
Definition: sql_lex.h:3096
void invalidate()
Invalidate by nulling out pointers to other SELECT_LEX_UNITs and SELECT_LEXes.
Definition: sql_lex.cc:2282
ulong retry_count
Definition: sql_lex.h:317
Definition: field.h:709
enum_comment_state in_comment
State of the lexical analyser for comments.
Definition: sql_lex.h:2984
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 occurences of o...
Definition: sql_union.cc:1354
enum_duplicates
Definition: sql_data_change.h:45
Server_options server_options
Definition: sql_lex.h:3211
Definition: my_sqlcommand.h:86
char * m_cpp_buf
Pre-processed buffer.
Definition: sql_lex.h:2928
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:179
bool m_json_agg_func_used
Definition: sql_lex.h:1696
index_clause_map clause
Definition: sql_lex.h:396
THD * thd
Definition: sql_lex.h:3102
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:2442
Abstract base class for traversing the SELECT_LEX tree.
Definition: select_lex_visitor.h:39
SELECT_LEX * link_next
Intrusive double-linked global list of query blocks.
Definition: sql_lex.h:924
dd::info_schema::Tablespace_statistics m_IS_tablespace_stats
Definition: sql_lex.h:3575
bool requires_prelocking()
Definition: sql_lex.h:2028
keep the diagnostics area
Definition: sql_lex.h:162
enum enum_duplicates duplicates
Definition: sql_lex.h:3251
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:79
const char * found_semicolon
Position of &#39;;&#39; in the stream, to delimit multiple queries.
Definition: sql_lex.h:2965
bool is_ignore() const
Definition: sql_lex.h:3291
enum_sql_command
Definition: my_sqlcommand.h:45
enum_lock_tables_state
Locking state of tables in this particular statement.
Definition: sql_lex.h:1990
TABLE_LIST * query_tables
Definition: sql_lex.h:1945
TABLE_LIST ** query_tables_own_last
Definition: sql_lex.h:1954
bool m_empty_query
True if query block does not generate any rows before aggregation, determined during preparation (not...
Definition: sql_lex.h:1702
List< Window > m_windows
All windows defined on the select, both named and inlined.
Definition: sql_lex.h:1034
enum_mdl_type m_mdl_type
The type of requested metadata lock for tables added to the statement table list. ...
Definition: sql_lex.h:3692
bool sp_lex_in_use
Definition: sql_lex.h:3308
Index_hint(const char *str, uint length)
Definition: sql_lex.h:403
HA_CHECK_OPT check_opt
Definition: sql_lex.h:3206
void set_using_match()
Definition: sql_lex.h:2491
bool walk_item(Item *item, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3347
bool init(THD *thd, const char *buff, size_t length)
Object initializer.
Definition: sql_lex.h:3734
Definition: item_cmpfunc.h:2063
void assert_ok_set_current_select()
Definition: sql_lex.cc:385
Definition: mysql_lex_string.h:39
bool walk(Item_processor processor, enum_walk walk, uchar *arg)
Definition: sql_union.cc:1466
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
sp_head * sphead
Definition: sql_lex.h:3306
void add_base_options(ulonglong options)
Add base options to a query block, also update active options.
Definition: sql_lex.h:869
SELECT_LEX * new_union_query(SELECT_LEX *curr_select, bool distinct, bool check_syntax=true)
Create query block and attach it to the current query expression.
Definition: sql_lex.cc:633
Item_sum * inner_sum_func_list
Circular linked list of sum func in nested selects.
Definition: sql_lex.h:1152
Definition: query_result.h:48
enum_view_create_mode create_view_mode
Definition: sql_lex.h:3254
Table_ident(const LEX_CSTRING &table_arg)
Definition: sql_lex.h:259
bool accept_for_join(List< TABLE_LIST > *tables, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3372
List< set_var_base > var_list
Definition: sql_lex.h:3144
#define top()
Definition: dbug_analyze.cc:129
void add_digest_token(uint token, Lexer_yystype *yylval)
Definition: sql_lex.cc:373
uint8 create_view_algorithm
Definition: sql_lex.h:3263
enum olap_type olap
Indicates whether this query block contains the WITH ROLLUP clause.
Definition: sql_lex.h:1018
enum_exec_method
The method chosen to execute the predicate, currently used for IN, =ANY and EXISTS predicates...
Definition: item_subselect.h:345
Secondary_engine_execution_context * secondary_engine_execution_context() const
Gets the secondary engine execution context for this statement.
Definition: sql_lex.h:3595
bool skip_local_transforms
True: skip local transformations during prepare() call (used by INSERT)
Definition: sql_lex.h:952
bool validate_base_options(LEX *lex, ulonglong options) const
Validate base options for a query block.
Definition: sql_lex.cc:4518
std::unique_ptr< malloc_unordered_map< std::string, Sroutine_hash_entry * > > sroutines
Definition: sql_lex.h:1964
void unclean()
Definition: sql_lex.h:726
void reset_executed()
Definition: sql_lex.h:737
void save_in_comment_state()
Definition: sql_lex.h:2624
SELECT_LEX * select_lex
First query block.
Definition: sql_lex.h:3068
List< LEX_USER > * role_list
Definition: sql_lex.h:3058
bool autocommit
Definition: sql_lex.h:3272
SELECT_LEX * all_selects_list
List of all query blocks.
Definition: sql_lex.h:3069
uint select_number
Query block number (used for EXPLAIN)
Definition: sql_lex.h:1145
Opt_hints_qb * opt_hints_qb
Query-block-level hints, for this query block.
Definition: sql_lex.h:1216
bool is_lex_native_function(const LEX_STRING *name)
Check if name is a sql function.
Definition: sql_lex.cc:870
my_lex_states
Definition: sql_chars.h:37
bool setup_group(THD *thd)
Resolve and set up the GROUP BY list.
Definition: sql_resolver.cc:4113
class udf_list * list
bool set_limit(THD *thd, SELECT_LEX *provider)
Set limit and offset for query expression object.
Definition: sql_lex.cc:3695
Acl_type
Definition: sql_lex.h:217
This class represent server options as set by the parser.
Definition: sql_servers.h:70
bool need_correct_ident()
Definition: sql_lex.cc:3625
SELECT_LEX_UNIT * master
The query expression containing this query block.
Definition: sql_lex.h:919
uint get_body_utf8_length() const
Get the utf8-body length.
Definition: sql_lex.h:2811
Alter_info * alter_info
Definition: sql_lex.h:3294
uint max_equal_elems
maximal number of elements in multiple equalities
Definition: sql_lex.h:1122
PSI_digest_locker * m_digest_psi
Current performance digest instrumentation.
Definition: sql_lex.h:3755
uint partitioned_table_count
Number of partitioned tables.
Definition: sql_lex.h:1091
partition_info * result
Definition: sql_lex.h:3768
bool has_windows() const
Definition: sql_lex.h:1311
Plugins_array plugins
Definition: sql_lex.h:3111
const LEX_STRING null_lex_str
LEX_STRING constant for null-string to be used in parser and other places.
Definition: sql_lex.cc:86
DBUG_VOID_RETURN
Definition: dbug_analyze.cc:151
Structure that represents element in the set of stored routines used by statement or routine...
Definition: sp.h:225
bool is_grouped() const
Definition: sql_lex.h:1288
uint32 next_binlog_file_nr
Definition: sql_lex.h:3312
void invalidate()
Invalidate by nulling out pointers to other SELECT_LEX_UNITs and SELECT_LEXes.
Definition: sql_lex.cc:2467
List< Item > purge_value_list
Definition: sql_lex.h:3138
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:2249
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:38
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
TABLE_LIST ** prev_global
Definition: table.h:3028
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:2213
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:434
const Query_result * recursive_result(SELECT_LEX *reader) const
If this unit is recursive, then this returns the Query_result which holds the rows of the recursive r...
Definition: sql_union.cc:1405
void renumber_selects(LEX *lex)
Renumber query blocks of a query expression according to supplied LEX.
Definition: sql_lex.cc:3808
bool stmt_prepare_mode
true if we&#39;re parsing a prepared statement: in this mode we should allow placeholders.
Definition: sql_lex.h:2977
bool resolve_subquery(THD *thd)
Resolve predicate involving subquery.
Definition: sql_resolver.cc:1116
bool is_mergeable() const
Return true if query expression can be merged into an outer query, based on technical constraints...
Definition: sql_lex.cc:3761
LEX_GRANT_AS grant_as
Definition: sql_lex.h:3101
void set_executed()
Definition: sql_lex.h:736
List< Item > item_list
List of columns and expressions: SELECT: Columns and expressions in the SELECT list.
Definition: sql_lex.h:1041
SELECT_LEX_UNIT * master_unit() const
Definition: sql_lex.h:1228
Yacc_state m_yacc
Definition: sql_lex.h:3751
void print_hints(const THD *thd, String *str, enum_query_type query_type)
Print detail of Hints.
Definition: sql_lex.cc:3030
Parser state for partition expression parser (.frm/DD stuff)
Definition: sql_lex.h:3764
void add_active_options(ulonglong options)
Adjust the active option set.
Definition: sql_lex.h:890
int hidden_group_field_count
Number of GROUP BY expressions added to all_fields.
Definition: sql_lex.h:1045
Using most system variables is unsafe, because slave may run with different options than master...
Definition: sql_lex.h:2087
const char * m_cpp_text_start
Starting position of the TEXT_STRING or IDENT in the pre-processed buffer.
Definition: sql_lex.h:2993
#define OPTION_NO_CONST_TABLES
Definition: query_options.h:77
Unit isn&#39;t cleaned.
Definition: sql_lex.h:591
keep @warning_count / @error_count
Definition: sql_lex.h:163
bool is_item_list_lookup
Definition: sql_lex.h:1042
TABLE_LIST * derived_table
If this query expression is underlying of a derived table, the derived table.
Definition: sql_lex.h:666
Partition_expr_parser_state()
Definition: sql_lex.cc:1050
Item * m_having_cond
Condition to be evaluated on grouped rows after grouping.
Definition: sql_lex.h:1001
protocol
Definition: memcached.h:112
bool lex_init(void)
Definition: sql_lex.cc:150
"Derived" subquery
Definition: parse_tree_node_base.h:67
void print_delete_options(String *str)
Print DELETE options.
Definition: sql_lex.cc:3099
Definition: sql_lex.h:976
bool is_ordered() const
Definition: sql_lex.h:1299
Definition: item_subselect.h:73
uint grant_tot_col
Definition: sql_lex.h:3259
ulonglong m_statement_options
Statement context for SELECT_LEX::make_active_options.
Definition: sql_lex.h:3328
void warn_on_deprecated_charset(const CHARSET_INFO *cs, const char *alias) const
Outputs warnings on deprecated charsets in complete SQL statements.
Definition: sql_lex.h:2884
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
enum_view_create_mode
Definition: sql_lex.h:230
List< Item > types
Definition: sql_lex.h:612
#define TYPE_ENUM_PROCEDURE
Definition: sql_lex.h:213
Base class for structured and hierarchical EXPLAIN output formatters.
Definition: opt_explain_format.h:501
TABLE_LIST * resolve_nest
Used when resolving outer join condition.
Definition: sql_lex.h:980
bool is_query_tables_locked() const
Definition: sql_lex.h:1992
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
void yyUnget()
Cancel the effect of the last yyGet() or yySkip().
Definition: sql_lex.h:2686
void set_trg_event_type_for_tables()
Set the initial purpose of this TABLE_LIST object in the list of used tables.
Definition: sql_lex.cc:3838
struct struct_slave_connection LEX_SLAVE_CONNECTION
SELECT_LEX * master
The query block wherein this query expression is contained, NULL if the query block is the outer-most...
Definition: sql_lex.h:551
Prealloced_array< plugin_ref, INITIAL_LEX_PLUGIN_LIST_SIZE > Plugins_array
Definition: sql_lex.h:3110
PT_subquery * result
Definition: sql_lex.h:3798
LEX_CSTRING table
Definition: sql_lex.h:251
bool add_ftfunc_to_list(Item_func_match *func)
Definition: sql_lex.cc:2459
bool drop_if_exists
Definition: sql_lex.h:3270
Definition: thr_lock.h:52
bool allow_merge_derived
Allow merge of immediate unnamed derived tables.
Definition: sql_lex.h:1190
static bool backup
Definition: myisampack.cc:194
Parser state for generated column expression parser (.frm/DD stuff)
Definition: sql_lex.h:3774
uchar * yacc_yyss
Bison internal state stack, yyss, when dynamically allocated using my_yyoverflow().
Definition: sql_lex.h:3655
bool got_all_recursive_rows
True if the with-recursive algorithm has produced the complete result.
Definition: sql_lex.h:688
SELECT_LEX(Item *where, Item *having)
Definition: sql_lex.cc:2041
void include_down(LEX *lex, SELECT_LEX_UNIT *outer)
Include query block inside a query expression.
Definition: sql_lex.cc:4243
uint cond_count
number of arguments of and/or/xor in where/having/on
Definition: sql_lex.h:1120
const LEX_CSTRING sp_data_access_name[]
Definition: sql_lex.h:223
LEX_CSTRING db
Definition: sql_lex.h:250
void set_explain_marker_from(THD *thd, const SELECT_LEX_UNIT *u)
Definition: sql_lex.cc:2387
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:155
INSERT...SELECT...UPDATE is unsafe because which rows are updated depends on the order that rows are ...
Definition: sql_lex.h:2124
Base class for secondary engine execution context objects.
Definition: sql_lex.h:1869
std::map< Field *, Field * > * insert_update_values_map
Definition: sql_lex.h:3186
LEX_SLAVE_CONNECTION slave_connection
Definition: sql_lex.h:3210
Query that writes to a table with auto_inc column after selecting from other tables are unsafe as the...
Definition: sql_lex.h:2131
Definition: sql_lex.h:975
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:519
Definition: table.h:1294
Definition: sql_lex.h:248
uint rights
Definition: sql_lex.h:3040
void reset()
Definition: sql_lex.cc:168
List< LEX_COLUMN > columns
Definition: sql_lex.h:3131
SELECT_LEX * slave
The first query block in this query expression.
Definition: sql_lex.h:553
bool resolve_rollup(THD *thd)
Resolve items in SELECT list and ORDER BY list for rollup processing.
Definition: sql_resolver.cc:4388
uint8 context_analysis_only
Definition: sql_lex.h:3269
bool is_executed() const
Definition: sql_lex.h:740
void restore_backup_query_tables_list(Query_tables_list *backup)
Definition: sql_lex.cc:4132
Opt_hints_global * opt_hints_global
Definition: sql_lex.h:3106
static EXTENSION_DAEMON_DESCRIPTOR descriptor
Definition: stdin_check.c:32
Common definition between mysql server & client.
enum LEX_MASTER_INFO::@101 ssl_verify_server_cert
Definition: sql_lex.h:1899
bool no_table_names_allowed
used for global order by
Definition: sql_lex.h:956
int nest_level
Nesting level of query block, outer-most query block has level 0, its subqueries have level 1...
Definition: sql_lex.h:1150
sp_pcontext * get_sp_current_parsing_ctx()
Definition: sql_lex.h:3370
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:3589
bool prepared_stmt_code_is_varref
Definition: sql_lex.h:3303
Query block level hints.
Definition: opt_hints.h:364
SELECT_LEX_UNIT * next_unit() const
Definition: sql_lex.h:703
Performance schema instrumentation interface.
void set_current_select(SELECT_LEX *select)
Definition: sql_lex.h:3082
void set_tables_readonly()
Set associated tables as read_only, ie.
Definition: sql_lex.h:901
enum_keep_diagnostics keep_diagnostics
Definition: sql_lex.h:3311
cond_result
Definition: item.h:735
Table_ident(LEX_CSTRING &table_arg, Table_function *table_func_arg)
Definition: sql_lex.h:279
struct PSI_digest_locker PSI_digest_locker
Definition: psi_statement_bits.h:87
bool add_fake_select_lex(THD *thd)
Create a fake SELECT_LEX for a unit.
Definition: sql_parse.cc:6233
unsigned char yyPeekn(int n) const
Look ahead at some character to parse.
Definition: sql_lex.h:2676
Using some functions is unsafe (e.g., UUID).
Definition: sql_lex.h:2091
ulonglong nesting_map
Definition: my_table_map.h:33
void skip_binary(int n)
Skip binary from the input stream.
Definition: sql_lex.h:2638
const CHARSET_INFO * query_charset
Definition: sql_lex.h:2902
LEX()
Definition: sql_lex.cc:3515
void change_db(const char *db_name)
Definition: sql_lex.h:288
bool can_not_use_merged()
Check if command can&#39;t use merged views in any part of command.
Definition: sql_lex.cc:3602
st_parsing_options()
Definition: sql_lex.h:2549
void set_explain_marker(THD *thd, enum_parsing_context m)
Definition: sql_lex.cc:2381
enum_clean_state
Values for SELECT_LEX_UNIT::cleaned.
Definition: sql_lex.h:590
const char * get_type_str()
Lookup for a type string.
Definition: sql_lex.h:1651
void print_order_by(const THD *thd, String *str, enum_query_type query_type)
Print list of items in ORDER BY clause.
Definition: sql_lex.cc:3332
TABLE_LIST * end_lateral_table
Definition: sql_lex.h:1219
unsigned char yyGetLast() const
Get the last character accepted.
Definition: sql_lex.h:2662
Definition: sql_lex.h:1889
enum enum_trigger_event_type event
Definition: sql_lex.h:1901
sys_var * trg_new_row_fake_var
Definition: sql_lex.cc:81
Various macros useful for communicating with memory debuggers, such as Valgrind.
keep nothing
Definition: sql_lex.h:161
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:165
bool exclude_from_table_unique_test
exclude this query block from unique_table() check
Definition: sql_lex.h:1188
enum LEX_MASTER_INFO::@101 get_public_key
Definition: key_spec.h:66
Internal state of the parser.
Definition: sql_lex.h:3715
uint select_n_having_items
number of items in select_list and HAVING clause used to get number bigger then can be number of entr...
Definition: sql_lex.h:1119
Definition: sql_lex.h:2545
ulonglong statement_options()
Definition: sql_lex.h:3332
SELECT_LEX_UNIT * recursive_dummy_unit
To pass the first steps of resolution, a recursive reference is made to be a dummy derived table; aft...
Definition: sql_lex.h:1207
enum_comment_state
The state of the lexical parser, when parsing comments.
Definition: sql_lex.h:2556
This file includes constants used by all storage engines.
char * m_ptr
Pointer to the current position in the raw input stream.
Definition: sql_lex.h:2906
Lex_input_stream(uint grammar_selector_token_arg)
Constructor.
Definition: sql_lex.h:2602
bool for_channel
Definition: sql_lex.h:327
LEX_ALTER alter_password
Definition: sql_lex.h:3100
List< Item > * get_item_list()
Definition: sql_lex.h:1332
const int grammar_selector_token
The synthetic 1st token to prepend token stream with.
Definition: sql_lex.h:3032
const char * m_cpp_tok_start
Starting position of the last token parsed, in the pre-processed buffer.
Definition: sql_lex.h:2937
void set_agg_func_used(bool val)
Definition: sql_lex.h:1643
LEX_USER * definer
Definition: sql_lex.h:3128
bool drop_temporary
Definition: sql_lex.h:3271
Definition: table.h:2342
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_lex.cc:272
void start_token()
Mark the stream position as the start of a new token.
Definition: sql_lex.h:2762
friend bool parse_view_definition(THD *thd, TABLE_LIST *view_ref)
Parse a view definition.
Definition: sql_view.cc:1183
bool merge_heuristic(const LEX *lex) const
True if heuristics suggest to merge this query expression.
Definition: sql_lex.cc:3790
bool text_string_is_7bit() const
Definition: sql_lex.h:3034
bool simplify_joins(THD *thd, List< TABLE_LIST > *join_list, bool top, bool in_sj, Item **new_conds, uint *changelog=NULL)
Simplify joins replacing outer joins by inner joins whenever it&#39;s possible.
Definition: sql_resolver.cc:1581
List< Item > & fields_list
hold field list
Definition: sql_lex.h:1047
TABLE_LIST * convert_right_join()
Convert a right join into equivalent left join.
Definition: sql_parse.cc:6161
void cleanup_after_one_table_open()
Definition: sql_lex.cc:4093
bool is_in_select_list(Item *i)
Definition: sql_resolver.cc:3511
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
void binlog_unsafe_map_init()
Definition: sql_lex.cc:4775
void print_update(const THD *thd, String *str, enum_query_type query_type)
Print detail of the UPDATE statement.
Definition: sql_lex.cc:2916
enum_sql_command sql_command
SQL command for this statement.
Definition: sql_lex.h:1943
const char * get_cpp_tok_end() const
Get the token end position, in the pre-processed buffer.
Definition: sql_lex.h:2789
Query_tables_list()
Definition: sql_lex.h:2009
char * user
Definition: sql_lex.h:312
bool semijoin_disallowed
Disables semi-join flattening when resolving a subtree in which flattening is not allowed...
Definition: sql_lex.h:986
bool is_broken() const
Definition: sql_lex.h:3343
TABLE_LIST * recursive_reference
If this query block is a recursive member of a recursive unit: the TABLE_LIST, in this recursive memb...
Definition: sql_lex.h:1196
enum_yes_no_unknown
Definition: parser_yystype.h:66
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: sql_lex.cc:2540
uint connect_retry
Definition: sql_lex.h:313
Item_subselect * item
Points to subquery if this query expression is used in one, otherwise NULL.
Definition: sql_lex.h:638
A class representing one system variable - that is something that can be accessed as @global...
Definition: set_var.h:102
structure to define some default "config_option" option settings
Definition: innodb_config.h:180
bool ignore
Definition: sql_lex.h:3288
Definition: sql_lex.h:1990
void set_prepared()
Definition: sql_lex.h:734
String column
Definition: sql_lex.h:3039
uchar * yacc_yyls
Bison internal location value stack, yyls, when dynamically allocated using my_yyoverflow().
Definition: sql_lex.h:3667
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:3264
Item * select_limit
LIMIT clause, NULL if no limit is given.
Definition: sql_lex.h:1103
static const char * get_type_str(enum_explain_type type)
Definition: sql_lex.h:1652
Definition: sql_lex.h:977
LEX_STRING create_view_select
SELECT of CREATE VIEW statement.
Definition: sql_lex.h:3119
void warn_on_deprecated_collation(const CHARSET_INFO *collation) const
Outputs warnings on deprecated collations in complete SQL statements.
Definition: sql_lex.h:2896
~Disable_semijoin_flattening()
Definition: sql_lex.h:1853
enum LEX_MASTER_INFO::@101 ssl
const LEX_STRING empty_lex_str
Definition: sql_lex.cc:87
ulong relay_log_pos
Definition: sql_lex.h:344
bool m_echo_saved
Definition: sql_lex.h:2925
bool can_use_merged()
check if command can use VIEW with MERGE algorithm (for top VIEWs)
Definition: sql_lex.cc:3549
bool uses_stored_routines() const
true if the parsed tree contains references to stored procedures or functions, false otherwise ...
Definition: sql_lex.h:2489
bool explicit_limit
explicit LIMIT clause is used
Definition: sql_lex.h:1166
Definition: sql_lex.h:169
void assert_not_fully_clean()
Asserts that none of {this unit and its children units} is fully cleaned up.
Definition: sql_union.cc:1305
SELECT_LEX_UNIT * slave
The first query expression contained within this query block.
Definition: sql_lex.h:921
Struct NESTED_JOIN is used to represent how tables are connected through outer join operations and se...
Definition: nested_join.h:77
List< LEX_CSTRING > dynamic_privileges
Definition: sql_lex.h:3132
char * m_body_utf8
UTF8-body buffer created during parsing.
Definition: sql_lex.h:2946
void include_down(LEX *lex, SELECT_LEX *outer)
Include a query expression below a query block.
Definition: sql_lex.cc:3737
void first_lists_tables_same()
Definition: sql_lex.cc:4024
#define DBUG_ENTER(a)
Definition: my_dbug.h:135
uint derived_table_count
Number of derived tables and views in this query block.
Definition: sql_lex.h:1078
thr_lock_type
Definition: thr_lock.h:50
bool accept_table(TABLE_LIST *t, Select_lex_visitor *visitor)
Definition: sql_lex.cc:3381
const CHARSET_INFO * m_underscore_cs
Character set specified by the character-set-introducer.
Definition: sql_lex.h:3008
Item * where_cond() const
Definition: sql_lex.h:849
Definition: sql_lex.h:170
enum LEX_MASTER_INFO::@101 repl_ignore_server_ids_opt
uint profile_options
Definition: sql_lex.h:3258
void new_static_query(SELECT_LEX_UNIT *sel_unit, SELECT_LEX *select)
Create query expression and query block in existing memory objects.
Definition: sql_lex.cc:731
Resolve_place
Three fields used by semi-join transformations to know when semi-join is possible, and in which condition tree the subquery predicate is located.
Definition: sql_lex.h:972
void reset_query_tables_list(bool init)
Definition: sql_lex.cc:3456
List< TABLE_LIST > * join_list
list for the currently parsed join
Definition: sql_lex.h:1063
uint materialized_derived_table_count
Number of materialized derived tables and views in this query block.
Definition: sql_lex.h:1082
Definition: sql_lex.h:334
Bison "location" class.
Definition: parse_location.h:43
SELECT_LEX * current_select() const
Definition: sql_lex.h:3075
enum_clean_state cleaned
cleanliness state
Definition: sql_lex.h:597
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:2397
void set_echo(bool echo)
Set the echo mode.
Definition: sql_lex.h:2622
Expression_parser_state()
Definition: sql_lex.cc:1056
void clear_values_map()
Definition: sql_lex.h:3164
Mixing self-logging and non-self-logging engines in a statement is unsafe.
Definition: sql_lex.h:2104
const char * m_cpp_tok_end
Ending position of the previous token parsed, in the pre-processed buffer.
Definition: sql_lex.h:2943
Definition: sql_lex.h:369
bool is_recursive() const
Definition: sql_lex.h:783
Value_generator * gcol_info
Definition: sql_lex.h:3103
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:4000
bool copy_db_to(char **p_db, size_t *p_db_length) const
Definition: sql_lex.h:3537
bool until_after_gaps
Definition: sql_lex.h:325
Definition: event_parse_data.h:43
virtual ~LEX()
Definition: sql_lex.cc:392
uint start_transaction_opt
Definition: sql_lex.h:3261
enum SSL_type ssl_type
Definition: sql_lex.h:3250
enum_sp_type to_sp_type(longlong val)
Definition: sql_lex.h:193
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:3198
TABLE_LIST * 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=0, List< String > *partition_names=0, LEX_STRING *option=0, Parse_context *pc=NULL)
Add a table to list of used tables.
Definition: sql_parse.cc:5772
bool is_explicitly_grouped() const
Definition: sql_lex.h:1257
bool executed
Query expression has been executed.
Definition: sql_lex.h:567
unsigned char yyPeek() const
Look at the next character to parse, but do not accept it.
Definition: sql_lex.h:2667
Class Item_sum is the base class used for special expressions that SQL calls &#39;set functions&#39;...
Definition: item_sum.h:385
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:4165
void print_table_references(const THD *thd, String *str, TABLE_LIST *table_list, enum_query_type query_type)
Print list of tables.
Definition: sql_lex.cc:3121
Mem_root_array< Item_exists_subselect * > * sj_candidates
Pointer to collection of subqueries candidate for semi/antijoin conversion.
Definition: sql_lex.h:1764
bool is_part_of_union() const
Return true if this query block is part of a UNION.
Definition: sql_lex.h:1620
Definition: sql_lex.h:367
enum_jt_column
Type of columns for JSON_TABLE function.
Definition: table_function.h:186
uint get_lineno(const char *raw_ptr) const
Definition: sql_lex.cc:1033
TABLE_LIST ** query_tables_last
Definition: sql_lex.h:1947
CREATE TABLE...REPLACE...
Definition: sql_lex.h:2152
Query_result * query_result() const
Definition: sql_lex.h:706
void set_uncacheable(SELECT_LEX *curr_select, uint8 cause)
Set the current query as uncacheable.
Definition: sql_lex.h:3481
SELECT_LEX * new_empty_query_block()
Create an empty query block within this LEX object.
Definition: sql_lex.cc:530
uint between_count
number of between predicates in where/having/on
Definition: sql_lex.h:1121
bool allows_select_into
Definition: sql_lex.h:2547
const char * m_end_of_query
End of the query text in the input stream, in the raw buffer.
Definition: sql_lex.h:2915
Item * result
Definition: sql_lex.h:3788
bool has_aj_nests
Definition: sql_lex.h:1089
const char * channel
Definition: sql_lex.h:320
enum LEX_MASTER_INFO::@100 gtid_until_condition
size_t length
Definition: mysql_lex_string.h:41
virtual ~Secondary_engine_execution_context()=default
Destructs the secondary engine execution context object.
JOIN * join
After optimization it is pointer to corresponding JOIN.
Definition: sql_lex.h:1059
void delete_unused_merged_columns(List< TABLE_LIST > *tables)
Delete unused columns from merged tables.
Definition: sql_resolver.cc:4529
SELECT_LEX * first_recursive
First query block (in this UNION) which references the CTE.
Definition: sql_lex.h:671
This class represents the character input stream consumed during lexical analysis.
Definition: sql_lex.h:2594
void exclude_level()
Exclude this unit and immediately contained select_lex objects.
Definition: sql_lex.cc:2184
SELECT_LEX_UNIT(enum_parsing_context parsing_context)
Construct and initialize SELECT_LEX_UNIT object.
Definition: sql_lex.cc:1982
Statements that read from both transactional and non-transactional tables and write to any of them ar...
Definition: sql_lex.h:2110
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:3415
Name_resolution_context context
Context for name resolution for all column references except columns from joined tables.
Definition: sql_lex.h:961
SQL_I_List< Sroutine_hash_entry > sroutines_list
Definition: sql_lex.h:1974
List< Name_resolution_context > context_stack
Definition: sql_lex.h:3202
XA transactions and statements.
Definition: sql_lex.h:2191
The class represents parse-time context, which keeps track of declared variables/parameters, conditions, handlers, cursors and labels.
Definition: sp_pcontext.h:250
bool is_single_level_stmt()
check if the statement is a single-level join
Definition: sql_lex.h:3555
char * m_body_utf8_ptr
Pointer to the current position in the UTF8-body buffer.
Definition: sql_lex.h:2949
bool explain(THD *explain_thd, const THD *query_thd)
Explain query starting from this unit.
Definition: sql_union.cc:786
void set_query_tables_list(Query_tables_list *state)
Definition: sql_lex.h:2015
table_map m_lateral_deps
If &#39;this&#39; is body of lateral derived table: map of tables in the same FROM clause as this derived tab...
Definition: sql_lex.h:681
void reset(const char *buff, size_t length)
Prepare Lex_input_stream instance state for use for handling next SQL statement.
Definition: sql_lex.cc:220
char * help_arg
Definition: sql_lex.h:3091
SELECT..LIMIT is unsafe because the set of rows returned cannot be predicted.
Definition: sql_lex.h:2064
The statement is a row injection (i.e., either a BINLOG statement or a row event executed by the slav...
Definition: sql_lex.h:2505
bool sj_pullout_done
True when semi-join pull-out processing is complete.
Definition: sql_lex.h:1186
Header for compiler-dependent features.
bool is_prepared() const
Definition: sql_lex.h:738
enum_parsing_context parsing_place
Parse context: indicates where the current expression is being parsed.
Definition: sql_lex.h:1130
String * wild
Definition: sql_lex.h:3095
uint to_uint(enum_sp_type val)
Definition: sql_lex.h:202
bool lex_start(THD *thd)
Call lex_start() before every query that is to be prepared and executed.
Definition: sql_lex.cc:489
enum_sp_suid_behaviour
Definition: sql_lex.h:168
INSERT...
Definition: sql_lex.h:2173
dd::info_schema::Table_statistics m_IS_table_stats
IS schema queries read some dynamic table statistics from SE.
Definition: sql_lex.h:3574
Resolve_place resolve_place
Indicates part of query being resolved.
Definition: sql_lex.h:979
bool will_contextualize
Used to inform the parser whether it should contextualize the parse tree.
Definition: sql_lex.h:3436
enum index_hint_type type
Definition: sql_lex.h:394
TABLE_LIST * insert_table_leaf
Leaf table being inserted into (always a base table)
Definition: sql_lex.h:3116
List< Item_func_set_user_var > set_var_list
Definition: sql_lex.h:3145
bool check_select_for_locking_clause(THD *)
SELECT_LEX * outer_select() const
Definition: sql_lex.h:1230
void add_statement_options(ulonglong options)
Add options to values of m_statement_options.
Definition: sql_lex.h:3340
const char * m_buf
Begining of the query text in the input stream, in the raw buffer.
Definition: sql_lex.h:2918
void remove_semijoin_candidate(Item_exists_subselect *sub_query)
Removes pointer to a sub query from sj_candidates array.
Definition: sql_lex.cc:4467
Definition: thr_lock.h:98
bool is_invalid_string(const LEX_CSTRING &string_val, const CHARSET_INFO *charset_info)
(End of group GROUP_PARSER)
Definition: sql_lex.h:3851
bool ignore_space
SQL_MODE = IGNORE_SPACE.
Definition: sql_lex.h:2971
void add_order_to_list(ORDER *order)
Definition: sql_lex.cc:2449
Table_ident(SELECT_LEX_UNIT *s)
This constructor is used only for the case when we create a derived table.
Definition: sql_lex.h:269
udf_func udf
Definition: sql_lex.h:3205
Definition: item_func.h:3268
unsigned int len
Definition: dbug_analyze.cc:216
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:4750
void print(const THD *thd, String *str)
Print an index hint.
Definition: sql_lex.cc:2607
uint16_t uint16
Definition: my_inttypes.h:60
void chop_off_not_own_tables()
Definition: sql_lex.h:2036
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:1186
Definition: item.h:666
Definition: sql_lex.h:358
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:1127
void remap_tables(THD *thd)
Re-map table numbers for all tables in a query block.
Definition: sql_resolver.cc:953
Mixing transactional and non-transactional statements are unsafe if non-transactional reads or writes...
Definition: sql_lex.h:2098
bool find_common_table_expr(THD *thd, Table_ident *table_id, TABLE_LIST *tl, Parse_context *pc, bool *found)
Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl&#39;, and the matched with-list-element.
Definition: sql_parse.cc:5569
void empty_order_list(SELECT_LEX *sl)
Empty the ORDER list.
Definition: sql_resolver.cc:3714
unsigned int uint
Definition: uca-dump.cc:29
USER_RESOURCES mqh
Definition: sql_lex.h:3212
bool has_ft_funcs() const
Definition: sql_lex.h:1305
bool walk(Item_processor processor, enum_walk walk, uchar *arg)
Definition: sql_lex.cc:4566
Item * having_cond() const
Definition: sql_lex.h:851
void cut_subtree()
Definition: sql_lex.h:1366
Lex_input_stream m_lip
Definition: sql_lex.h:3750
Definition: parse_tree_nodes.h:1945
void print_update_list(const THD *thd, String *str, enum_query_type query_type, List< Item > fields, List< Item > values)
Print assignments list.
Definition: sql_lex.cc:3180
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:1112
bool m_comment
True if current query contains comments.
Definition: sql_lex.h:3758
Item * offset_limit
LIMIT ... OFFSET clause, NULL if no offset is given.
Definition: sql_lex.h:1105
long long int longlong
Definition: my_inttypes.h:73
PT_with_clause * m_with_clause
The WITH clause which is the first part of this query expression.
Definition: sql_lex.h:661
#define MYF(v)
Definition: my_inttypes.h:124
static const CHARSET_INFO * charset_info
Definition: mysql.cc:219
uint table_count
Number of tables which were open by open_tables() and to be locked by lock_tables().
Definition: sql_lex.h:2003
bool verbose
Definition: sql_lex.h:3273
void merge_contexts(SELECT_LEX *inner)
Merge name resolution context objects of a subquery into its parent.
Definition: sql_resolver.cc:3601
void reduce_digest_token(uint token_left, uint token_right)
Definition: sql_lex.cc:379
t
Definition: dbug_analyze.cc:147
Definition: item_subselect.h:333
Unit were cleaned, except JOIN and JOIN_TABs were kept for possible EXPLAIN.
Definition: sql_lex.h:592
bool slave_until
Definition: sql_lex.h:326
bool is_optimized() const
Definition: sql_lex.h:739
uint32_t uint32
Definition: my_inttypes.h:62
bool is_single_grouped() const
True if this query block is implicitly grouped.
Definition: sql_lex.h:1278
Performance schema instrumentation interface.
bool setup_conds(THD *thd)
Resolve WHERE condition and join conditions.
Definition: sql_resolver.cc:1325
Value_generator * result
Definition: sql_lex.h:3778
enum_sp_type
enum_sp_type defines type codes of stored programs.
Definition: sql_lex.h:191
enum LEX_MASTER_INFO::@101 auto_position
void print_select_options(String *str)
Print select options.
Definition: sql_lex.cc:3074
enum LEX_MASTER_INFO::@101 port_opt
#define UNCACHEABLE_DEPENDENT
Definition: parse_tree_node_base.h:44
const char * index_hint_type_name[]
Definition: sql_lex.cc:129
Parser state for single expression parser (.frm/DD stuff)
Definition: sql_lex.h:3784
bool setup_wild(THD *thd)
Expand all &#39;*&#39; in list of expressions with the matching column references.
Definition: sql_resolver.cc:1263
void set_secondary_engine_execution_context(Secondary_engine_execution_context *context)
Sets the secondary engine execution context for this statement.
Definition: sql_lex.cc:4868
uint with_wild
Number of wildcards used in the SELECT list.
Definition: sql_lex.h:1158
void set_json_agg_func_used(bool val)
Definition: sql_lex.h:1645
List< LEX_USER > users_list
Definition: sql_lex.h:3130
bool binlog_need_explicit_defaults_ts
Definition: sql_lex.h:3430
LEX_COLUMN(const String &x, const uint &y)
Definition: sql_lex.h:3041
void include_in_global(SELECT_LEX **plink)
Include query block into global list.
Definition: sql_lex.cc:4310
uint8 create_view_check
Definition: sql_lex.h:3264
uint table_func_count
Number of table functions in this query block.
Definition: sql_lex.h:1080
char * bind_addr
Definition: sql_lex.h:312
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:539
Definition: sql_lex.h:364
void set_stmt_row_injection()
Flag the statement as a row injection.
Definition: sql_lex.h:2283
friend bool lex_start(THD *thd)
Call lex_start() before every query that is to be prepared and executed.
Definition: sql_lex.cc:489
char * to_log
Definition: sql_lex.h:3092
Definition: my_sqlcommand.h:50
bool get_optimizable_conditions(THD *thd, Item **new_where, Item **new_having)
Returns disposable copies of WHERE/HAVING/ON conditions.
Definition: sql_lex.cc:4372
bool eof() const
End of file indicator for the query text to parse.
Definition: sql_lex.h:2743
bool json_agg_func_used() const
Definition: sql_lex.h:1641
const char * m_tok_end
Ending position of the previous token parsed, in the raw buffer.
Definition: sql_lex.h:2912
void include_neighbour(LEX *lex, SELECT_LEX *before)
Include a query block next to another query block.
Definition: sql_lex.cc:4262
Definition: m_ctype.h:359
uint8_t uint8
Definition: my_inttypes.h:58
TABLE_LIST result_table_list
Definition: sql_lex.h:569
Definition: sql_lex.h:336
bool m_extended_show
Definition: sql_lex.h:3275
bool is_cacheable() const
Definition: sql_lex.h:1657
uchar * yacc_yyvs
Bison internal semantic value stack, yyvs, when dynamically allocated using my_yyoverflow().
Definition: sql_lex.h:3661
~Query_tables_list()
Definition: sql_lex.h:2010
Definition: sql_lex.h:974
TABLE_LIST * first_not_own_table()
Definition: sql_lex.h:2033
uint8 uncacheable
result of this query can&#39;t be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCA...
Definition: sql_lex.h:949
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:397
TABLE_LIST * next_leaf
Definition: table.h:3209
SELECT_LEX_UNIT ** prev
Definition: sql_lex.h:545
LEX_USER * user
Definition: sql_lex.h:3057
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:99
void fix_prepare_information_for_order(THD *thd, SQL_I_List< ORDER > *list, Group_list_ptrs **list_ptrs)
Helper for fix_prepare_information()
Definition: sql_lex.cc:4174
LEX_RESET_SLAVE reset_slave_info
Definition: sql_lex.h:3213