MySQL  8.0.27
Source Code Documentation
table.h
Go to the documentation of this file.
1 #ifndef TABLE_INCLUDED
2 #define TABLE_INCLUDED
3 
4 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 #include <assert.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include <string>
30 
31 #include "field_types.h"
32 #include "lex_string.h"
33 #include "libbinlogevents/include/table_id.h" // Table_id
34 #include "m_ctype.h"
35 #include "map_helpers.h"
36 #include "mem_root_deque.h"
37 #include "my_alloc.h"
38 #include "my_base.h"
39 #include "my_bitmap.h"
40 #include "my_compiler.h"
41 
42 #include "my_inttypes.h"
43 #include "my_sys.h"
44 #include "my_table_map.h"
47 #include "sql/dd/types/foreign_key.h" // dd::Foreign_key::enum_rule
48 #include "sql/enum_query_type.h" // enum_query_type
49 #include "sql/key.h"
50 #include "sql/key_spec.h"
51 #include "sql/mdl.h" // MDL_wait_for_subgraph
52 #include "sql/mem_root_array.h"
53 #include "sql/opt_costmodel.h" // Cost_model_table
54 #include "sql/partition_info.h"
55 #include "sql/record_buffer.h" // Record_buffer
56 #include "sql/sql_bitmap.h" // Bitmap
57 #include "sql/sql_const.h"
58 #include "sql/sql_list.h"
59 #include "sql/sql_plist.h"
60 #include "sql/sql_plugin_ref.h"
61 #include "sql/sql_sort.h" // Sort_result
62 #include "thr_lock.h"
63 #include "typelib.h"
64 
65 class Field;
66 
67 namespace histograms {
68 class Histogram;
69 }
70 
73 class COND_EQUAL;
74 class Field_json;
75 /* Structs that defines the TABLE */
76 class File_parser;
77 class Value_generator;
78 class GRANT_TABLE;
79 class Handler_share;
80 class Index_hint;
81 class Item;
82 class Item_field;
83 class Json_diff_vector;
84 class Json_seekable_path;
85 class Json_wrapper;
86 class Opt_hints_qb;
87 class Opt_hints_table;
88 class Query_result_union;
89 class Query_block;
90 class Query_expression;
91 class Security_context;
92 class SortingIterator;
93 class String;
94 class THD;
97 class Temp_table_param;
98 class handler;
99 class partition_info;
100 enum enum_stats_auto_recalc : int;
101 enum Value_generator_source : short;
102 enum row_type : int;
103 struct AccessPath;
104 struct HA_CREATE_INFO;
105 struct LEX;
106 struct NESTED_JOIN;
107 struct Partial_update_info;
108 struct TABLE;
109 struct TABLE_LIST;
110 struct TABLE_SHARE;
111 struct handlerton;
113 typedef int8 plan_idx;
114 
115 namespace dd {
116 class Table;
117 class View;
118 
119 enum class enum_table_type;
120 } // namespace dd
121 class Common_table_expr;
122 
126 
130 
132 
134 
135 enum class enum_json_diff_operation;
136 
138 
140 
142 
143 #define store_record(A, B) \
144  memcpy((A)->B, (A)->record[0], (size_t)(A)->s->reclength)
145 #define restore_record(A, B) \
146  memcpy((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
147 #define cmp_record(A, B) \
148  memcmp((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
149 
150 #define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
151 #define tmp_file_prefix_length 4
152 #define TMP_TABLE_KEY_EXTRA 8
153 #define PLACEHOLDER_TABLE_ROW_ESTIMATE 2
154 
155 /**
156  Enumerate possible types of a table from re-execution
157  standpoint.
158  TABLE_LIST class has a member of this type.
159  At prepared statement prepare, this member is assigned a value
160  as of the current state of the database. Before (re-)execution
161  of a prepared statement, we check that the value recorded at
162  prepare matches the type of the object we obtained from the
163  table definition cache.
164 
165  @sa check_and_update_table_version()
166  @sa Execute_observer
167  @sa Prepared_statement::reprepare()
168 */
169 
171  /** Initial value set by the parser */
177 };
178 
179 /**
180  Enumerate possible status of a identifier name while determining
181  its validity
182 */
184 
185 /*************************************************************************/
186 
187 /**
188  Object_creation_ctx -- interface for creation context of database objects
189  (views, stored routines, events, triggers). Creation context -- is a set
190  of attributes, that should be fixed at the creation time and then be used
191  each time the object is parsed or executed.
192 */
193 
195  public:
197 
198  void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
199 
200  protected:
201  Object_creation_ctx() = default;
202  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
203  virtual void delete_backup_ctx() = 0;
204 
205  virtual void change_env(THD *thd) const = 0;
206 
207  public:
208  virtual ~Object_creation_ctx() = default;
209 };
210 
211 /*************************************************************************/
212 
213 /**
214  Default_object_creation_ctx -- default implementation of
215  Object_creation_ctx.
216 */
217 
219  public:
221 
223 
224  protected:
226 
227  Default_object_creation_ctx(const CHARSET_INFO *client_cs,
228  const CHARSET_INFO *connection_cl);
229 
230  protected:
231  Object_creation_ctx *create_backup_ctx(THD *thd) const override;
232  void delete_backup_ctx() override;
233 
234  void change_env(THD *thd) const override;
235 
236  protected:
237  /**
238  client_cs stores the value of character_set_client session variable.
239  The only character set attribute is used.
240 
241  Client character set is included into query context, because we save
242  query in the original character set, which is client character set. So,
243  in order to parse the query properly we have to switch client character
244  set on parsing.
245  */
247 
248  /**
249  connection_cl stores the value of collation_connection session
250  variable. Both character set and collation attributes are used.
251 
252  Connection collation is included into query context, becase it defines
253  the character set and collation of text literals in internal
254  representation of query (item-objects).
255  */
257 };
258 
259 /**
260  View_creation_ctx -- creation context of view objects.
261 */
262 
264  public:
265  static View_creation_ctx *create(THD *thd);
266 
267  static View_creation_ctx *create(THD *thd, TABLE_LIST *view);
268 
269  private:
271 };
272 
273 /*************************************************************************/
274 
275 /** Order clause list element */
276 
278 
279 struct ORDER {
280  /// @returns true if item pointer is same as original
281  bool is_item_original() const { return item[0] == item_initial; }
282 
283  ORDER *next{nullptr};
284 
285  /**
286  The initial ordering expression. Usually substituted during resolving
287  and must not be used during optimization and execution.
288  */
289  Item *item_initial{nullptr}; /* Storage for initial item */
290 
291  public:
292  /**
293  Points at the item in the select fields. Note that this means that
294  after resolving, it points into a slice (see JOIN::ref_items),
295  even though the item is not of type Item_ref!
296  */
298 
300 
302  ORDER_NOT_RELEVANT}; /* Requested direction of ordering */
303  bool in_field_list{false}; /* true if in select field list */
304  /**
305  Tells whether this ORDER element was referenced with an alias or with an
306  expression, in the query:
307  SELECT a AS foo GROUP BY foo: true.
308  SELECT a AS foo GROUP BY a: false.
309  */
310  bool used_alias{false};
311  /**
312  When GROUP BY is implemented with a temporary table (i.e. the table takes
313  care to store only unique group rows, table->group != nullptr), each GROUP
314  BY expression is stored in a column of the table, which is
315  'field_in_tmp_table'.
316  Such field may point into table->record[0] (if we only use it to get its
317  value from a tmp table's row), or into 'buff' (if we use it to do index
318  lookup into the tmp table).
319  */
321  char *buff{nullptr}; /* If tmp-table group */
323  bool is_position{false}; /* An item expresses a position in a ORDER clause */
324  bool is_explicit{false}; /* Whether ASC/DESC is explicitly specified */
325 };
326 
327 /**
328  State information for internal tables grants.
329  This structure is part of the TABLE_LIST, and is updated
330  during the ACL check process.
331  @sa GRANT_INFO
332 */
334  /** True if the internal lookup by schema name was done. */
335  bool m_schema_lookup_done{false};
336  /** Cached internal schema access. */
338  /** True if the internal lookup by table name was done. */
339  bool m_table_lookup_done{false};
340  /** Cached internal table access. */
342 };
343 
344 /**
345  @brief The current state of the privilege checking process for the current
346  user, SQL statement and SQL object.
347 
348  @details The privilege checking process is divided into phases depending on
349  the level of the privilege to be checked and the type of object to be
350  accessed. Due to the mentioned scattering of privilege checking
351  functionality, it is necessary to keep track of the state of the process.
352 
353  A GRANT_INFO also serves as a cache of the privilege hash tables. Relevant
354  members are grant_table and version.
355  */
356 struct GRANT_INFO {
357  GRANT_INFO();
358  /**
359  @brief A copy of the privilege information regarding the current host,
360  database, object and user.
361 
362  @details The version of this copy is found in GRANT_INFO::version.
363  */
365  /**
366  @brief Used for cache invalidation when caching privilege information.
367 
368  @details The privilege information is stored on disk, with dedicated
369  caches residing in memory: table-level and column-level privileges,
370  respectively, have their own dedicated caches.
371 
372  The GRANT_INFO works as a level 1 cache with this member updated to the
373  current value of the global variable @c grant_version (@c static variable
374  in sql_acl.cc). It is updated Whenever the GRANT_INFO is refreshed from
375  the level 2 cache. The level 2 cache is the @c column_priv_hash structure
376  (@c static variable in sql_acl.cc)
377 
378  @see grant_version
379  */
381  /**
382  @brief The set of privileges that the current user has fulfilled for a
383  certain host, database, and object.
384 
385  @details This field is continually updated throughout the access checking
386  process. In each step the "wanted privilege" is checked against the
387  fulfilled privileges. When/if the intersection of these sets is empty,
388  access is granted.
389 
390  The set is implemented as a bitmap, with the bits defined in sql_acl.h.
391  */
392  ulong privilege{0};
393  /** The grant state for internal tables. */
395 };
396 
403 };
404 
405 /**
406  Category of table found in the table share.
407 */
409  /**
410  Unknown value.
411  */
413 
414  /**
415  Temporary table.
416  The table is visible only in the session.
417  Therefore,
418  - FLUSH TABLES WITH READ LOCK
419  - SET GLOBAL READ_ONLY = ON
420  do not apply to this table.
421  Note that LOCK TABLE t FOR READ/WRITE
422  can be used on temporary tables.
423  Temporary tables are not part of the table cache.
424 
425  2016-06-14 Contrary to what's written in these comments, the truth is:
426  - tables created by CREATE TEMPORARY TABLE have TABLE_CATEGORY_USER
427  - tables created by create_tmp_table() (internal ones) have
428  TABLE_CATEGORY_TEMPORARY.
429  ha_innodb.cc relies on this observation (so: grep it). If you clean this
430  up, you may also want to look at 'no_tmp_table'; its enum values' meanings
431  have degraded over time: INTERNAL_TMP_TABLE is not used for some internal
432  tmp tables (derived tables). Unification of both enums would be
433  great. Whatever the result, we need to be able to distinguish the two
434  types of temporary tables above, as usage patterns are more restricted for
435  the second type, and allow more optimizations.
436  */
438 
439  /**
440  User table.
441  These tables do honor:
442  - LOCK TABLE t FOR READ/WRITE
443  - FLUSH TABLES WITH READ LOCK
444  - SET GLOBAL READ_ONLY = ON
445  User tables are cached in the table cache.
446  */
448 
449  /**
450  System table, maintained by the server.
451  These tables do honor:
452  - LOCK TABLE t FOR READ/WRITE
453  - FLUSH TABLES WITH READ LOCK
454  - SET GLOBAL READ_ONLY = ON
455  Typically, writes to system tables are performed by
456  the server implementation, not explicitly be a user.
457  System tables are cached in the table cache.
458  */
460 
461  /**
462  Information schema tables.
463  These tables are an interface provided by the system
464  to inspect the system metadata.
465  These tables do *not* honor:
466  - LOCK TABLE t FOR READ/WRITE
467  - FLUSH TABLES WITH READ LOCK
468  - SET GLOBAL READ_ONLY = ON
469  as there is no point in locking explicitly
470  an INFORMATION_SCHEMA table.
471  Nothing is directly written to information schema tables.
472  Note that this value is not used currently,
473  since information schema tables are not shared,
474  but implemented as session specific temporary tables.
475  */
476  /*
477  TODO: Fixing the performance issues of I_S will lead
478  to I_S tables in the table cache, which should use
479  this table type.
480  */
482 
483  /**
484  Log tables.
485  These tables are an interface provided by the system
486  to inspect the system logs.
487  These tables do *not* honor:
488  - LOCK TABLE t FOR READ/WRITE
489  - FLUSH TABLES WITH READ LOCK
490  - SET GLOBAL READ_ONLY = ON
491  as there is no point in locking explicitly
492  a LOG table.
493  An example of LOG tables are:
494  - mysql.slow_log
495  - mysql.general_log,
496  which *are* updated even when there is either
497  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
498  User queries do not write directly to these tables
499  (there are exceptions for log tables).
500  The server implementation perform writes.
501  Log tables are cached in the table cache.
502  */
504 
505  /**
506  Performance schema tables.
507  These tables are an interface provided by the system
508  to inspect the system performance data.
509  These tables do *not* honor:
510  - LOCK TABLE t FOR READ/WRITE
511  - FLUSH TABLES WITH READ LOCK
512  - SET GLOBAL READ_ONLY = ON
513  as there is no point in locking explicitly
514  a PERFORMANCE_SCHEMA table.
515  An example of PERFORMANCE_SCHEMA tables are:
516  - performance_schema.*
517  which *are* updated (but not using the handler interface)
518  even when there is either
519  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
520  User queries do not write directly to these tables
521  (there are exceptions for SETUP_* tables).
522  The server implementation perform writes.
523  Performance tables are cached in the table cache.
524  */
526 
527  /**
528  Replication Information Tables.
529  These tables are used to store replication information.
530  These tables do *not* honor:
531  - LOCK TABLE t FOR READ/WRITE
532  - FLUSH TABLES WITH READ LOCK
533  - SET GLOBAL READ_ONLY = ON
534  as there is no point in locking explicitly
535  a Replication Information table.
536  An example of replication tables are:
537  - mysql.slave_master_info
538  - mysql.slave_relay_log_info,
539  which *are* updated even when there is either
540  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
541  User queries do not write directly to these tables.
542  Replication tables are cached in the table cache.
543  */
545 
546  /**
547  Gtid Table.
548  The table is used to store gtids.
549  The table does *not* honor:
550  - LOCK TABLE t FOR READ/WRITE
551  - FLUSH TABLES WITH READ LOCK
552  - SET GLOBAL READ_ONLY = ON
553  as there is no point in locking explicitly
554  a Gtid table.
555  An example of gtid_executed table is:
556  - mysql.gtid_executed,
557  which is updated even when there is either
558  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
559  Gtid table is cached in the table cache.
560  */
562 
563  /**
564  A data dictionary table.
565  Table's with this category will skip checking the
566  TABLE_SHARE versions because these table structures
567  are fixed upon server bootstrap.
568  */
570 
571  /**
572  A ACL metadata table.
573  For table in this category we will skip row locks when SQL statement
574  reads them.
575  */
577 };
579 
580 extern ulong refresh_version;
581 
586 };
587 
591 };
592 
594  protected:
595  bool has_keys;
596  virtual void report_error(uint code, const char *fmt, ...) = 0;
597 
598  public:
600  virtual ~Table_check_intact() = default;
601 
602  /**
603  Checks whether a table is intact. Should be done *just* after the table has
604  been opened.
605 
606  @param[in] thd Thread handle
607  @param[in] table The table to check
608  @param[in] table_def Expected structure of the table (column name
609  and type)
610 
611  @retval false OK
612  @retval true There was an error.
613  */
614  bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def);
615 };
616 
617 /**
618  Class representing the fact that some thread waits for table
619  share to be flushed. Is used to represent information about
620  such waits in MDL deadlock detector.
621 */
622 
627 
628  public:
629  Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg,
630  uint deadlock_weight_arg)
631  : m_ctx(ctx_arg),
632  m_share(share_arg),
633  m_deadlock_weight(deadlock_weight_arg) {}
634 
635  MDL_context *get_ctx() const { return m_ctx; }
636 
637  bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor) override;
638 
639  uint get_deadlock_weight() const override;
640 
641  /**
642  Pointers for participating in the list of waiters for table share.
643  */
646 };
647 
648 typedef I_P_List<
653 
657  /**
658  Name of unique key matching FK in parent table, "" if there is no
659  unique key.
660  */
664  /**
665  Arrays with names of referencing columns of the FK.
666  */
669 
675 
676 /**
677  Definition of name for generated keys, owned by TABLE_SHARE
678 */
679 struct Key_name {
681 };
682 
683 /**
684  This structure is shared between different table objects. There is one
685  instance of table share per one table in the database.
686 */
687 
688 struct TABLE_SHARE {
689  TABLE_SHARE() = default;
690 
691  /**
692  Create a new TABLE_SHARE with the given version number.
693  @param version the version of the TABLE_SHARE
694  @param secondary set to true if the TABLE_SHARE represents a table
695  in a secondary storage engine
696  */
697  TABLE_SHARE(unsigned long version, bool secondary)
698  : m_version(version), m_secondary_engine(secondary) {}
699 
700  /*
701  A map of [uint, Histogram] values, where the key is the field index. The
702  map is populated with any histogram statistics when it is loaded/created.
703  */
705  nullptr};
706 
707  /**
708  Find the histogram for the given field index.
709 
710  @param field_index the index of the field we want to find a histogram for
711 
712  @retval nullptr if no histogram is found
713  @retval a pointer to a histogram if one is found
714  */
715  const histograms::Histogram *find_histogram(uint field_index) const;
716 
717  /** Category of this table. */
719 
721  /**
722  Used to allocate new handler for internal temporary table when the
723  size limitation of the primary storage engine is exceeded.
724  */
726 
727  TYPELIB keynames; /* Pointers to keynames */
728  TYPELIB *intervals{nullptr}; /* pointer to interval info */
729  mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */
730  TABLE_SHARE *next{nullptr}, **prev{nullptr}; /* Link to unused shares */
731  /**
732  Array of table_cache_instances pointers to elements of table caches
733  respresenting this table in each of Table_cache instances.
734  Allocated along with the share itself in alloc_table_share().
735  Each element of the array is protected by Table_cache::m_lock in the
736  corresponding Table_cache. False sharing should not be a problem in
737  this case as elements of this array are supposed to be updated rarely.
738  */
740 
741  /* The following is copied to each TABLE on OPEN */
742  Field **field{nullptr};
744  KEY *key_info{nullptr}; /* data of keys defined for the table */
745  uint *blob_field{nullptr}; /* Index to blobs in Field arrray*/
746 
747  uchar *default_values{nullptr}; /* row with default values */
748  LEX_STRING comment{nullptr, 0}; /* Comment about table */
749  LEX_STRING compress{nullptr, 0}; /* Compression algorithm */
750  LEX_STRING encrypt_type{nullptr, 0}; /* encryption algorithm */
751 
752  /** Secondary storage engine. */
754 
756  nullptr}; /* Default charset of string fields */
757 
759  /*
760  Key which is used for looking-up table in table cache and in the list
761  of thread's temporary tables. Has the form of:
762  "database_name\0table_name\0" + optional part for temporary tables.
763 
764  Note that all three 'table_cache_key', 'db' and 'table_name' members
765  must be set (and be non-zero) for tables in table cache. They also
766  should correspond to each other.
767  To ensure this one can use set_table_cache() methods.
768  */
770  LEX_CSTRING db{nullptr, 0}; /* Pointer to db */
771  LEX_CSTRING table_name{nullptr, 0}; /* Table name (for open) */
772  LEX_STRING path{nullptr, 0}; /* Path to .frm file (from datadir) */
773  LEX_CSTRING normalized_path{nullptr, 0}; /* unpack_filename(path) */
775 
778 
779  /**
780  The set of indexes that are not disabled for this table. I.e. it excludes
781  indexes disabled by `ALTER TABLE ... DISABLE KEYS`, however it does
782  include invisible indexes. The data dictionary populates this bitmap.
783  */
785 
786  /// The set of visible and enabled indexes for this table.
789  ha_rows min_rows{0}, max_rows{0}; /* create information */
790  ulong avg_row_length{0}; /* create information */
791  ulong mysql_version{0}; /* 0 if .frm is created before 5.0 */
792  ulong reclength{0}; /* Recordlength */
793  ulong stored_rec_length{0}; /* Stored record length
794  (no generated-only generated fields) */
796 
797  plugin_ref db_plugin{nullptr}; /* storage engine plugin */
798  inline handlerton *db_type() const /* table_type for handler */
799  {
800  // assert(db_plugin);
801  return db_plugin ? plugin_data<handlerton *>(db_plugin) : NULL;
802  }
803  /**
804  Value of ROW_FORMAT option for the table as provided by user.
805  Can be different from the real row format used by the storage
806  engine. ROW_TYPE_DEFAULT value indicates that no explicit
807  ROW_FORMAT was specified for the table. @sa real_row_type.
808  */
809  enum row_type row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
810  /** Real row format used for the table by the storage engine. */
811  enum row_type real_row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
813 
814  /**
815  Only for internal temporary tables.
816  Count of TABLEs (having this TABLE_SHARE) which have a "handler"
817  (table->file!=nullptr) which is open (ha_open() has been called).
818  */
820 
821  /**
822  Only for internal temporary tables.
823  Count of TABLEs (having this TABLE_SHARE) which have opened this table.
824  */
826 
827  // Can only be 1,2,4,8 or 16, but use uint32_t since that how it is
828  // represented in InnoDB
829  std::uint32_t key_block_size{0}; /* create key_block_size, if used */
830  uint stats_sample_pages{0}; /* number of pages to sample during
831  stats estimation, if used, otherwise 0. */
833  stats_auto_recalc{}; /* Automatic recalc of stats.
834  Zero-initialized to HA_STATS_AUTO_RECALC_DEFAULT
835  */
837  uint fields{0}; /* Number of fields */
838  uint rec_buff_length{0}; /* Size of table->record[] buffer */
839  uint keys{0}; /* Number of keys defined for the table*/
840  uint key_parts{0}; /* Number of key parts of all keys
841  defined for the table
842  */
843  uint max_key_length{0}; /* Length of the longest key */
844  uint max_unique_length{0}; /* Length of the longest unique key */
846  /**
847  Whether this is a temporary table that already has a UNIQUE index (removing
848  duplicate rows on insert), so that the optimizer does not need to run
849  DISTINCT itself.
850  */
851  bool is_distinct{false};
852 
853  uint null_fields{0}; /* number of null fields */
854  uint blob_fields{0}; /* number of blob fields */
855  uint varchar_fields{0}; /* number of varchar fields */
856  /**
857  For materialized derived tables; @see add_derived_key().
858  'first' means: having the lowest position in key_info.
859  */
861  /**
862  For materialized derived tables: allocated size of key_info array.
863  */
865  /**
866  For materialized derived tables: allocated size of base_key_parts array of
867  all TABLE objects. Used for generated keys.
868  */
870  /**
871  Array of names for generated keys, used for materialized derived tables.
872  Shared among all TABLE objects referring to this table share.
873  */
874  Key_name *key_names{nullptr};
875  /**
876  Records per key array, used for materialized derived tables.
877  This is a contiguous array, with size given by max_tmp_key_parts.
878  The array is shared with all TABLE objects referring to this table share.
879  */
880  ulong *base_rec_per_key{nullptr};
881  /**
882  Records per key array, float rep., used for materialized derived tables.
883  This is a contiguous array, with size given by max_tmp_key_parts.
884  The array is shared with all TABLE objects referring to this table share.
885  */
887  /**
888  Bitmap with flags representing some of table options/attributes.
889 
890  @sa HA_OPTION_PACK_RECORD, HA_OPTION_PACK_KEYS, ...
891 
892  @note This is basically copy of HA_CREATE_INFO::table_options bitmap
893  at the time of table opening/usage.
894  */
896  /**
897  Bitmap with flags representing some of table options/attributes which
898  are in use by storage engine.
899 
900  @note db_options_in_use is normally copy of db_create_options but can
901  be overriden by SE. E.g. MyISAM does this at handler::open() and
902  hander::info() time.
903  */
905  uint rowid_field_offset{0}; /* Field_nr +1 to rowid field */
906  /* Primary key index number, used in TABLE::key_info[] */
908  uint next_number_index{0}; /* autoincrement key number */
909  uint next_number_key_offset{0}; /* autoinc keypart offset in a key */
910  uint next_number_keypart{0}; /* autoinc keypart number in a key */
911  bool error{false}; /* error during open_table_def() */
913  /// Number of generated fields
915  /// Number of fields having the default value generated
917  bool system{false}; /* Set if system table (one record) */
918  bool db_low_byte_first{false}; /* Portable row format */
919  bool crashed{false};
920  bool is_view{false};
921  bool m_open_in_progress{false}; /* True: alloc'ed, false: def opened */
922  Table_id table_map_id; /* for row-based replication */
923 
924  /*
925  Cache for row-based replication table share checks that does not
926  need to be repeated. Possible values are: -1 when cache value is
927  not calculated yet, 0 when table *shall not* be replicated, 1 when
928  table *may* be replicated.
929  */
931 
932  /*
933  Storage media to use for this table (unless another storage
934  media has been specified on an individual column - in versions
935  where that is supported)
936  */
938 
939  /* Name of the tablespace used for this table */
940  const char *tablespace{nullptr};
941 
942  /**
943  Partition meta data. Allocated from TABLE_SHARE::mem_root,
944  created when reading from the dd tables,
945  used as template for each TABLE instance.
946  The reason for having it on the TABLE_SHARE is to be able to reuse the
947  partition_elements containing partition names, values etc. instead of
948  allocating them for each TABLE instance.
949  TODO: Currently it is filled in and then only used for generating
950  the partition_info_str. The plan is to clone/copy/reference each
951  TABLE::part_info instance from it.
952  What is missing before it can be completed:
953  1) The partition expression, currently created only during parsing which
954  also needs the current TABLE instance as context for name resolution etc.
955  2) The partition values, currently the DD stores them as text so it needs
956  to be converted to field images (which is now done by first parsing the
957  value text into an Item, then saving the Item result/value into a field
958  and then finally copy the field image).
959  */
961  // TODO: Remove these four variables:
962  /**
963  Filled in when reading from frm.
964  This can simply be removed when removing the .frm support,
965  since it is already stored in the new DD.
966  */
967  bool auto_partitioned{false};
968  /**
969  Storing the full partitioning clause (PARTITION BY ...) which is used
970  when creating new partition_info object for each new TABLE object by
971  parsing this string.
972  These two will be needed until the missing parts above is fixed.
973  */
974  char *partition_info_str{nullptr};
976 
977  /**
978  Cache the checked structure of this table.
979 
980  The pointer data is used to describe the structure that
981  a instance of the table must have. Each element of the
982  array specifies a field that must exist on the table.
983 
984  The pointer is cached in order to perform the check only
985  once -- when the table is loaded from the disk.
986  */
988 
989  /** Main handler's share */
991 
992  /** Instrumentation for this table share. */
994 
995  /**
996  List of tickets representing threads waiting for the share to be flushed.
997  */
999 
1000  /**
1001  View object holding view definition read from DD. This object is not
1002  cached, and is owned by the table share. We are not able to read it
1003  on demand since we may then get a cache miss while holding LOCK_OPEN.
1004  */
1005  const dd::View *view_object{nullptr};
1006 
1007  /**
1008  Data-dictionary object describing explicit temporary table represented
1009  by this share. NULL for other table types (non-temporary tables, internal
1010  temporary tables). This object is owned by TABLE_SHARE and should be
1011  deleted along with it.
1012  */
1014 
1015  /// For materialized derived tables; @see add_derived_key().
1017 
1018  /**
1019  Arrays with descriptions of foreign keys in which this table participates
1020  as child or parent. We only cache in them information from dd::Table object
1021  which is sufficient for use by prelocking algorithm/to check if table is
1022  referenced by a foreign key.
1023  */
1028 
1029  // List of check constraint share instances.
1031 
1032  /**
1033  Schema's read only mode - ON (true) or OFF (false). This is filled in
1034  when the share is initialized with meta data from DD. If the schema is
1035  altered, the tables and share are removed. This can be done since
1036  ALTER SCHEMA acquires exclusive meta data locks on the tables in the
1037  schema. We set this only for non-temporary tables. Otherwise, the value
1038  of the member below is 'NOT_SET'.
1039  */
1042 
1043  /**
1044  Set share's table cache key and update its db and table name appropriately.
1045 
1046  @param key_buff Buffer with already built table cache key to be
1047  referenced from share.
1048  @param key_length Key length.
1049 
1050  @note
1051  Since 'key_buff' buffer will be referenced from share it should has same
1052  life-time as share itself.
1053  This method automatically ensures that TABLE_SHARE::table_name/db have
1054  appropriate values by using table cache key as their source.
1055  */
1056 
1057  void set_table_cache_key(char *key_buff, size_t key_length) {
1058  table_cache_key.str = key_buff;
1060  /*
1061  Let us use the fact that the key is "db/0/table_name/0" + optional
1062  part for temporary tables.
1063  */
1065  db.length = strlen(db.str);
1066  table_name.str = db.str + db.length + 1;
1067  table_name.length = strlen(table_name.str);
1068  }
1069 
1070  /**
1071  Set share's table cache key and update its db and table name appropriately.
1072 
1073  @param key_buff Buffer to be used as storage for table cache key
1074  (should be at least key_length bytes).
1075  @param key Value for table cache key.
1076  @param key_length Key length.
1077 
1078  NOTE
1079  Since 'key_buff' buffer will be used as storage for table cache key
1080  it should has same life-time as share itself.
1081  */
1082 
1083  void set_table_cache_key(char *key_buff, const char *key, size_t key_length) {
1084  memcpy(key_buff, key, key_length);
1085  set_table_cache_key(key_buff, key_length);
1086  }
1087 
1089 
1090  /** Returns the version of this TABLE_SHARE. */
1091  unsigned long version() const { return m_version; }
1092 
1093  /**
1094  Set the version of this TABLE_SHARE to zero. This marks the
1095  TABLE_SHARE for automatic removal from the table definition cache
1096  once it is no longer referenced.
1097  */
1098  void clear_version();
1099 
1100  /** Is this table share being expelled from the table definition cache? */
1101  bool has_old_version() const { return version() != refresh_version; }
1102 
1103  /**
1104  Convert unrelated members of TABLE_SHARE to one enum
1105  representing its type.
1106 
1107  @todo perhaps we need to have a member instead of a function.
1108  */
1110  if (is_view) return TABLE_REF_VIEW;
1111  switch (tmp_table) {
1112  case NO_TMP_TABLE:
1113  return TABLE_REF_BASE_TABLE;
1114  case SYSTEM_TMP_TABLE:
1115  return TABLE_REF_I_S_TABLE;
1116  default:
1117  return TABLE_REF_TMP_TABLE;
1118  }
1119  }
1120  /**
1121  Return a table metadata version.
1122  * for base tables and views, we return table_map_id.
1123  It is assigned from a global counter incremented for each
1124  new table loaded into the table definition cache (TDC).
1125  * for temporary tables it's table_map_id again. But for
1126  temporary tables table_map_id is assigned from
1127  thd->query_id. The latter is assigned from a thread local
1128  counter incremented for every new SQL statement. Since
1129  temporary tables are thread-local, each temporary table
1130  gets a unique id.
1131  * for everything else (e.g. information schema tables),
1132  the version id is zero.
1133 
1134  This choice of version id is a large compromise
1135  to have a working prepared statement validation in 5.1. In
1136  future version ids will be persistent, as described in WL#4180.
1137 
1138  Let's try to explain why and how this limited solution allows
1139  to validate prepared statements.
1140 
1141  Firstly, sets (in mathematical sense) of version numbers
1142  never intersect for different table types. Therefore,
1143  version id of a temporary table is never compared with
1144  a version id of a view, and vice versa.
1145 
1146  Secondly, for base tables and views, we know that each DDL flushes
1147  the respective share from the TDC. This ensures that whenever
1148  a table is altered or dropped and recreated, it gets a new
1149  version id.
1150  Unfortunately, since elements of the TDC are also flushed on
1151  LRU basis, this choice of version ids leads to false positives.
1152  E.g. when the TDC size is too small, we may have a SELECT
1153  * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which
1154  in turn will lead to a validation error and a subsequent
1155  reprepare of all prepared statements. This is
1156  considered acceptable, since as long as prepared statements are
1157  automatically reprepared, spurious invalidation is only
1158  a performance hit. Besides, no better simple solution exists.
1159 
1160  For temporary tables, using thd->query_id ensures that if
1161  a temporary table was altered or recreated, a new version id is
1162  assigned. This suits validation needs very well and will perhaps
1163  never change.
1164 
1165  Metadata of information schema tables never changes.
1166  Thus we can safely assume 0 for a good enough version id.
1167 
1168  Finally, by taking into account table type, we always
1169  track that a change has taken place when a view is replaced
1170  with a base table, a base table is replaced with a temporary
1171  table and so on.
1172 
1173  @retval 0 For schema tables, DD tables and system views.
1174  non-0 For bases tables, views and temporary tables.
1175 
1176  @sa TABLE_LIST::is_table_ref_id_equal()
1177  */
1179 
1180  /** Determine if the table is missing a PRIMARY KEY. */
1181  bool is_missing_primary_key() const {
1182  assert(primary_key <= MAX_KEY);
1183  return primary_key == MAX_KEY;
1184  }
1185 
1187 
1188  bool visit_subgraph(Wait_for_flush *waiting_ticket,
1189  MDL_wait_for_graph_visitor *gvisitor);
1190 
1191  bool wait_for_old_version(THD *thd, struct timespec *abstime,
1192  uint deadlock_weight);
1193 
1194  /**
1195  The set of indexes that the optimizer may use when creating an execution
1196  plan.
1197  */
1198  Key_map usable_indexes(const THD *thd) const;
1199 
1200  /** Release resources and free memory occupied by the table share. */
1201  void destroy();
1202 
1203  /**
1204  How many TABLE objects use this TABLE_SHARE.
1205  @return the reference count
1206  */
1207  unsigned int ref_count() const {
1208  assert(assert_ref_count_is_locked(this));
1209  return m_ref_count;
1210  }
1211 
1212  /**
1213  Increment the reference count by one.
1214  @return the new reference count
1215  */
1216  unsigned int increment_ref_count() {
1217  assert(assert_ref_count_is_locked(this));
1218  assert(!m_open_in_progress);
1219  return ++m_ref_count;
1220  }
1221 
1222  /**
1223  Decrement the reference count by one.
1224  @return the new reference count
1225  */
1226  unsigned int decrement_ref_count() {
1227  assert(assert_ref_count_is_locked(this));
1228  assert(!m_open_in_progress);
1229  assert(m_ref_count > 0);
1230  return --m_ref_count;
1231  }
1232 
1233  /// Does this TABLE_SHARE represent a table in a primary storage engine?
1234  bool is_primary_engine() const { return !m_secondary_engine; }
1235 
1236  /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1237  bool is_secondary_engine() const { return m_secondary_engine; }
1238 
1239  /**
1240  Does this TABLE_SHARE represent a primary table that has a shadow
1241  copy in a secondary storage engine?
1242  */
1243  bool has_secondary_engine() const {
1244  return is_primary_engine() && secondary_engine.str != nullptr;
1245  }
1246 
1247  /** Returns whether this table is referenced by a foreign key. */
1249 
1250  private:
1251  /// How many TABLE objects use this TABLE_SHARE.
1252  unsigned int m_ref_count{0};
1253 
1254  /**
1255  TABLE_SHARE version, if changed the TABLE_SHARE must be reopened.
1256  NOTE: The TABLE_SHARE will not be reopened during LOCK TABLES in
1257  close_thread_tables!!!
1258  */
1259  unsigned long m_version{0};
1260 
1261  /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1262  bool m_secondary_engine{false};
1263 };
1264 
1265 /**
1266  Class is used as a BLOB field value storage for
1267  intermediate GROUP_CONCAT results. Used only for
1268  GROUP_CONCAT with DISTINCT or ORDER BY options.
1269  */
1270 
1272  private:
1274  /**
1275  Sign that some values were cut
1276  during saving into the storage.
1277  */
1279 
1280  public:
1281  Blob_mem_storage();
1283 
1284  void reset() {
1286  truncated_value = false;
1287  }
1288  /**
1289  Fuction creates duplicate of 'from'
1290  string in 'storage' MEM_ROOT.
1291 
1292  @param from string to copy
1293  @param length string length
1294 
1295  @retval Pointer to the copied string.
1296  @retval 0 if an error occurred.
1297  */
1298  char *store(const char *from, size_t length) {
1299  return (char *)memdup_root(&storage, from, length);
1300  }
1303  }
1304  bool is_truncated_value() const { return truncated_value; }
1305 };
1306 
1307 /**
1308  Class that represents a single change to a column value in partial
1309  update of a JSON column.
1310 */
1311 class Binary_diff final {
1312  /// The offset of the start of the change.
1313  size_t m_offset;
1314 
1315  /// The size of the portion that is to be replaced.
1316  size_t m_length;
1317 
1318  public:
1319  /**
1320  Create a new Binary_diff object.
1321 
1322  @param offset the offset of the beginning of the change
1323  @param length the length of the section that is to be replaced
1324  */
1325  Binary_diff(size_t offset, size_t length)
1326  : m_offset(offset), m_length(length) {}
1327 
1328  /// @return the offset of the changed data
1329  size_t offset() const { return m_offset; }
1330 
1331  /// @return the length of the changed data
1332  size_t length() const { return m_length; }
1333 
1334  /**
1335  Get a pointer to the start of the replacement data.
1336 
1337  @param field the column that is updated
1338  @return a pointer to the start of the replacement data
1339  */
1340  const char *new_data(const Field *field) const;
1341 
1342  /**
1343  Get a pointer to the start of the old data to be replaced.
1344 
1345  @param field the column that is updated
1346  @return a pointer to the start of old data to be replaced.
1347  */
1348  const char *old_data(const Field *field) const;
1349 };
1350 
1351 /**
1352  Vector of Binary_diff objects.
1353 
1354  The Binary_diff objects in the vector should be ordered on offset, and none
1355  of the diffs should be overlapping or adjacent.
1356 */
1358 
1359 /**
1360  Flags for TABLE::m_status (maximum 8 bits).
1361  The flags define the state of the row buffer in TABLE::record[0].
1362 */
1363 /**
1364  STATUS_NOT_STARTED is set when table is not accessed yet.
1365  Neither STATUS_NOT_FOUND nor STATUS_NULL_ROW can be set when this flag is set.
1366 */
1367 #define STATUS_NOT_STARTED 1
1368 /**
1369  Means we were searching for a row and didn't find it. This is used by
1370  storage engines (@see handler::index_read_map()) and the executor, both
1371  when doing an exact row lookup and advancing a scan (no more rows in range).
1372 */
1373 #define STATUS_NOT_FOUND 2
1374 /// Reserved for use by multi-table update. Means the row has been updated.
1375 #define STATUS_UPDATED 16
1376 /**
1377  Means that table->null_row is set. This is an artificial NULL-filled row
1378  (one example: in outer join, if no match has been found in inner table).
1379 */
1380 #define STATUS_NULL_ROW 32
1381 /// Reserved for use by multi-table delete. Means the row has been deleted.
1382 #define STATUS_DELETED 64
1383 
1384 /* Information for one open table */
1386 
1387 /* Bitmap of table's fields */
1389 
1390 /*
1391  NOTE: Despite being a struct (for historical reasons), TABLE has
1392  a nontrivial destructor.
1393 */
1394 struct TABLE {
1395  TABLE_SHARE *s{nullptr};
1396  handler *file{nullptr};
1397  TABLE *next{nullptr}, *prev{nullptr};
1398 
1399  private:
1400  /**
1401  Links for the lists of used/unused TABLE objects for the particular
1402  table in the specific instance of Table_cache (in other words for
1403  specific Table_cache_element object).
1404  Declared as private to avoid direct manipulation with those objects.
1405  One should use methods of I_P_List template instead.
1406  */
1407  TABLE *cache_next{nullptr}, **cache_prev{nullptr};
1408 
1409  /*
1410  Give Table_cache_element access to the above two members to allow
1411  using them for linking TABLE objects in a list.
1412  */
1413  friend class Table_cache_element;
1414 
1415  public:
1416  /**
1417  A bitmap marking the hidden generated columns that exists for functional
1418  indexes.
1419  */
1421  /**
1422  The current session using this table object.
1423  Should be NULL when object is not in use.
1424  For an internal temporary table, it is NULL when the table is closed.
1425  Used for two purposes:
1426  - Signal that the object is in use, and by which session.
1427  - Pass the thread handler to storage handlers.
1428  The field should NOT be used as a general THD reference, instead use
1429  a passed THD reference, or, if there is no such, current_thd.
1430  The reason for this is that we cannot guarantee the field is not NULL.
1431  */
1432  THD *in_use{nullptr};
1433  Field **field{nullptr}; /* Pointer to fields */
1434  /// Count of hidden fields, if internal temporary table; 0 otherwise.
1436 
1437  uchar *record[2]{nullptr, nullptr}; /* Pointer to records */
1438  uchar *write_row_record{nullptr}; /* Used as optimisation in
1439  THD::write_row */
1440  uchar *insert_values{nullptr}; /* used by INSERT ... UPDATE */
1441 
1442  /// Buffer for use in multi-row reads. Initially empty.
1444 
1445  /*
1446  Map of keys that can be used to retrieve all data from this table
1447  needed by the query without reading the row.
1448  */
1451 
1452  /* Merge keys are all keys that had a column reffered to in the query */
1454 
1455  /*
1456  possible_quick_keys is a superset of quick_keys to use with EXPLAIN of
1457  JOIN-less commands (single-table UPDATE and DELETE).
1458 
1459  When explaining regular JOINs, we use JOIN_TAB::keys to output the
1460  "possible_keys" column value. However, it is not available for
1461  single-table UPDATE and DELETE commands, since they don't use JOIN
1462  optimizer at the top level. OTOH they directly use the range optimizer,
1463  that collects all keys usable for range access here.
1464  */
1466 
1467  /*
1468  A set of keys that can be used in the query that references this
1469  table.
1470 
1471  All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be
1472  subtracted from this set upon instantiation. Thus for any TABLE t it holds
1473  that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
1474  must not introduce any new keys here (see setup_tables).
1475 
1476  The set is implemented as a bitmap.
1477  */
1479  /* Map of keys that can be used to calculate GROUP BY without sorting */
1481  /* Map of keys that can be used to calculate ORDER BY without sorting */
1483  KEY *key_info{nullptr}; /* data of keys defined for the table */
1484  /**
1485  Key part array for generated keys, used for materialized derived tables.
1486  This is a contiguous array, with size given by s->max_tmp_key_parts.
1487  */
1489 
1490  Field *next_number_field{nullptr}; /* Set if next_number is activated */
1491  Field *found_next_number_field{nullptr}; /* Set on open */
1492  /// Pointer to generated columns
1493  Field **vfield{nullptr};
1494  /// Pointer to fields having the default value generated
1496  /// Field used by unique constraint
1497  Field *hash_field{nullptr};
1498  Field *fts_doc_id_field{nullptr}; /* Set if FTS_DOC_ID field is present */
1499 
1500  /* Table's triggers, 0 if there are no of them */
1502  TABLE_LIST *pos_in_table_list{nullptr}; /* Element referring to this table */
1503  /* Position in thd->locked_table_list under LOCK TABLES */
1505  ORDER *group{nullptr};
1506  const char *alias{nullptr}; ///< alias or table name
1507  uchar *null_flags{nullptr}; ///< Pointer to the null flags of record[0]
1509  nullptr}; ///< Saved null_flags while null_row is true
1510 
1511  /* containers */
1513  /*
1514  Bitmap of fields that one or more query condition refers to. Only
1515  used if optimizer_condition_fanout_filter is turned 'on'.
1516  Currently, only the WHERE clause and ON clause of inner joins is
1517  taken into account but not ON conditions of outer joins.
1518  Furthermore, HAVING conditions apply to groups and are therefore
1519  not useful as table condition filters.
1520  */
1522 
1523  /**
1524  Bitmap of table fields (columns), which are explicitly set in the
1525  INSERT INTO statement. It is declared here to avoid memory allocation
1526  on MEM_ROOT).
1527 
1528  @sa fields_set_during_insert.
1529  */
1531 
1532  /**
1533  Set over all columns that the optimizer intends to read. This is used
1534  for two purposes: First, to tell the storage engine which ones it needs
1535  to populate. (In particular, NDB can save a lot of bandwidth here.)
1536  Second, functions that need to store and restore rows, such as hash join
1537  or filesort, need to know which ones to keep.
1538 
1539  Set during resolving; every field that gets resolved, sets its own bit
1540  in the read set. In some cases, we switch the read set around during
1541  various phases; note that it is a pointer.
1542 
1543  In addition, for binary logging purposes, the bitmaps are set according
1544  to the settings of @@binlog_row_image. Therefore, for logging purposes,
1545  some additional fields, to those specified by the optimizer, may be
1546  flagged in the read and write sets.
1547  @c TABLE::mark_columns_per_binlog_row_image for additional details.
1548  */
1549  MY_BITMAP *read_set{nullptr};
1550 
1552 
1553  /**
1554  A pointer to the bitmap of table fields (columns), which are explicitly set
1555  in the INSERT INTO statement.
1556 
1557  fields_set_during_insert points to def_fields_set_during_insert
1558  for base (non-temporary) tables. In other cases, it is NULL.
1559  Triggers can not be defined for temporary tables, so this bitmap does not
1560  matter for temporary tables.
1561 
1562  @sa def_fields_set_during_insert.
1563  */
1565 
1566  /*
1567  The ID of the query that opened and is using this table. Has different
1568  meanings depending on the table type.
1569 
1570  Temporary tables:
1571 
1572  table->query_id is set to thd->query_id for the duration of a statement
1573  and is reset to 0 once it is closed by the same statement. A non-zero
1574  table->query_id means that a statement is using the table even if it's
1575  not the current statement (table is in use by some outer statement).
1576 
1577  Non-temporary tables:
1578 
1579  Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
1580  for the duration of a statement and is reset to 0 once it is closed by
1581  the same statement. A non-zero query_id is used to control which tables
1582  in the list of pre-opened and locked tables are actually being used.
1583  */
1585 
1586  /*
1587  For each key that has quick_keys.is_set(key) == true: estimate of #records
1588  and max #key parts that range access would use.
1589  */
1591 
1592  /* Bitmaps of key parts that =const for the entire join. */
1594 
1597 
1598  /*
1599  Estimate of number of records that satisfy SARGable part of the table
1600  condition, or table->file->records if no SARGable condition could be
1601  constructed.
1602  This value is used by join optimizer as an estimate of number of records
1603  that will pass the table condition (condition that depends on fields of
1604  this table and constants)
1605  */
1607 
1608  uint lock_position{0}; /* Position in MYSQL_LOCK.table */
1609  uint lock_data_start{0}; /* Start pos. in MYSQL_LOCK.locks */
1610  uint lock_count{0}; /* Number of locks */
1611  uint db_stat{0}; /* mode of file as in handler.h */
1612  int current_lock{0}; /* Type of lock on table */
1613 
1614  // List of table check constraints.
1616 
1617  private:
1618  /**
1619  If true, this table is inner w.r.t. some outer join operation, all columns
1620  are nullable (in the query), and null_row may be true.
1621  */
1622  bool nullable{false};
1623 
1624  uint8 m_status{0}; /* What's in record[0] */
1625  public:
1626  /*
1627  If true, the current table row is considered to have all columns set to
1628  NULL, including columns declared as "not null" (see nullable).
1629  @todo make it private, currently join buffering changes it through a pointer
1630  */
1631  bool null_row{false};
1632 
1633  bool copy_blobs{false}; /* copy_blobs when storing */
1634 
1635  /*
1636  TODO: Each of the following flags take up 8 bits. They can just as easily
1637  be put into one single unsigned long and instead of taking up 18
1638  bytes, it would take up 4.
1639  */
1640  bool force_index{false};
1641 
1642  /**
1643  Flag set when the statement contains FORCE INDEX FOR ORDER BY
1644  See TABLE_LIST::process_index_hints().
1645  */
1646  bool force_index_order{false};
1647 
1648  /**
1649  Flag set when the statement contains FORCE INDEX FOR GROUP BY
1650  See TABLE_LIST::process_index_hints().
1651  */
1652  bool force_index_group{false};
1653  bool const_table{false};
1654  /// True if writes to this table should not write rows and just write keys.
1655  bool no_rows{false};
1656 
1657  /**
1658  If set, the optimizer has found that row retrieval should access index
1659  tree only.
1660  */
1661  bool key_read{false};
1662  /**
1663  Certain statements which need the full row, set this to ban index-only
1664  access.
1665  */
1666  bool no_keyread{false};
1667  /**
1668  If set, indicate that the table is not replicated by the server.
1669  */
1670  bool no_replicate{false};
1671  bool no_cache{false};
1672  /* To signal that the table is associated with a HANDLER statement */
1673  bool open_by_handler{false};
1674  /**
1675  To indicate that value of the auto_increment field was provided
1676  explicitly by the user or from some other source (e.g. in case of
1677  INSERT ... SELECT, ALTER TABLE or LOAD DATA) and not as default
1678  or result of conversion from NULL value.
1679 
1680  @note Since auto_increment fields are always non-NULL we can't find
1681  out using methods of Field class if 0 value stored in such field
1682  was provided explicitly or is result of applying default/conversion
1683  from NULL value. In the former case no new auto_increment value
1684  needs to be generated in MODE_NO_AUTO_VALUE_ON_ZERO mode, while
1685  the latter cases require new value generation. Hence the need
1686  for this flag.
1687  @note Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode and only
1688  by handler::write_row().
1689  */
1691  bool alias_name_used{false}; /* true if table_name is alias */
1692  bool get_fields_in_item_tree{false}; /* Signal to fix_field */
1693 
1694  private:
1695  /**
1696  This TABLE object is invalid and cannot be reused. TABLE object might have
1697  inconsistent info or handler might not allow some operations.
1698 
1699  For example, TABLE might have inconsistent info about partitioning.
1700  We also use this flag to avoid calling handler::reset() for partitioned
1701  InnoDB tables after in-place ALTER TABLE API commit phase and to force
1702  closing table after REPAIR TABLE has failed during its prepare phase as
1703  well.
1704 
1705  @note This member can be set only by thread that owns/has opened the
1706  table and while holding its THD::LOCK_thd_data lock.
1707  It can be read without locking by this owner thread, or by some other
1708  thread concurrently after acquring owner's THD::LOCK_thd_data.
1709 
1710  @note The TABLE will not be reopened under LOCK TABLES in
1711  close_thread_tables().
1712  */
1713  bool m_invalid_dict{false};
1714 
1715  /**
1716  This TABLE object is invalid and cannot be reused as it has outdated
1717  rec_per_key and handler stats.
1718 
1719  @note This member is protected from concurrent access to it by lock of
1720  Table Cache's partition to which this TABLE object belongs,
1721  */
1722  bool m_invalid_stats{false};
1723 
1724  /**
1725  For tmp tables. true <=> tmp table has been instantiated.
1726  Also indicates that table was successfully opened since
1727  we immediately delete tmp tables which we fail to open.
1728  */
1729  bool created{false};
1730 
1731  public:
1732  /// For a materializable derived or SJ table: true if has been materialized
1733  bool materialized{false};
1734  struct /* field connections */
1735  {
1736  class JOIN_TAB *join_tab{nullptr};
1737  class QEP_TAB *qep_tab{nullptr};
1738  thr_lock_type lock_type{TL_UNLOCK}; /* How table is used */
1740  bool not_exists_optimize{false};
1741  /*
1742  true <=> range optimizer found that there is no rows satisfying
1743  table conditions.
1744  */
1745  bool impossible_range{false};
1747 
1748  /**
1749  @todo This member should not be declared in-line. That makes it
1750  impossible for any function that does memory allocation to take a const
1751  reference to a TABLE object.
1752  */
1754  /**
1755  Initialized in Item_func_group_concat::setup for appropriate
1756  temporary table if GROUP_CONCAT is used with ORDER BY | DISTINCT
1757  and BLOB field count > 0.
1758  */
1760 
1761  /**
1762  Not owned by the TABLE; used only from filesort_free_buffers().
1763  See comments on SortingIterator::CleanupAfterQuery().
1764  */
1767 
1768  /**
1769  The result of applying a unique opertion (by row ID) to the table, if done.
1770  In particular, this is done in some forms of index merge.
1771  */
1773  partition_info *part_info{nullptr}; /* Partition related information */
1774  /* If true, all partitions have been pruned away */
1777 
1778  private:
1779  /// Cost model object for operations on this table
1781 #ifndef NDEBUG
1782  /**
1783  Internal tmp table sequential number. Increased in the order of
1784  creation. Used for debugging purposes when many tmp tables are used
1785  during execution (e.g several windows with window functions)
1786  */
1788 #endif
1789  public:
1790  void reset();
1791  void init(THD *thd, TABLE_LIST *tl);
1792  bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root,
1793  CHARSET_INFO *charset, const char *alias, Field **fld,
1794  uint *blob_fld, bool is_virtual);
1795  bool fill_item_list(mem_root_deque<Item *> *item_list) const;
1796  void reset_item_list(const mem_root_deque<Item *> &item_list) const;
1797  void clear_column_bitmaps(void);
1798  void prepare_for_position(void);
1799 
1802  uint key_parts = 0) const;
1804  void mark_auto_increment_column(void);
1805  void mark_columns_needed_for_update(THD *thd, bool mark_binlog_columns);
1809  void mark_generated_columns(bool is_update);
1810  void mark_gcol_in_maps(const Field *field);
1811  void mark_check_constraint_columns(bool is_update);
1812  void column_bitmaps_set(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg);
1813  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
1814  MY_BITMAP *write_set_arg) {
1815  read_set = read_set_arg;
1816  write_set = write_set_arg;
1817  }
1818  inline void use_all_columns() {
1820  }
1821  inline void default_column_bitmaps() {
1824  }
1825  void invalidate_dict();
1826  void invalidate_stats();
1827  /**
1828  @note Can be called by thread owning table without additional locking, and
1829  by any other thread which has acquired owner's THD::LOCK_thd_data lock.
1830  */
1831  inline bool has_invalid_dict() const {
1832  assert(assert_invalid_dict_is_locked(this));
1833  return !db_stat || m_invalid_dict;
1834  }
1835  /// @note Can be called by thread owning Table_cache::m_lock
1836  inline bool has_invalid_stats() {
1837  assert(assert_invalid_stats_is_locked(this));
1838  return m_invalid_stats;
1839  }
1840  /// @returns first non-hidden column
1842  /// @returns count of visible fields
1844  bool alloc_tmp_keys(uint new_key_count, uint new_key_part_count,
1845  bool modify_share);
1846  bool add_tmp_key(Field_map *key_parts, bool invisible, bool modify_share);
1847  void copy_tmp_key(int old_idx, bool modify_share);
1848  void drop_unused_tmp_keys(bool modify_share);
1849 
1850  void set_keyread(bool flag);
1851 
1852  /**
1853  Check whether the given index has a virtual generated columns.
1854 
1855  @param index_no the given index to check
1856 
1857  @returns true if if index is defined over at least one virtual generated
1858  column
1859  */
1860  inline bool index_contains_some_virtual_gcol(uint index_no) const {
1861  assert(index_no < s->keys);
1862  return key_info[index_no].flags & HA_VIRTUAL_GEN_KEY;
1863  }
1864  void update_const_key_parts(Item *conds);
1865 
1867 
1868  ptrdiff_t default_values_offset() const {
1869  return (ptrdiff_t)(s->default_values - record[0]);
1870  }
1871 
1872  /// @returns true if a storage engine handler object is assigned to table
1873  bool has_storage_handler() const { return file != nullptr; }
1874 
1875  /// Set storage handler for temporary table
1876  void set_storage_handler(handler *file_arg) {
1877  // Ensure consistent call order
1878  assert((file == nullptr && file_arg != nullptr) ||
1879  (file != nullptr && file_arg == nullptr));
1880  assert(!is_created());
1881  assert(file_arg->inited == handler::NONE);
1882  file = file_arg;
1883  }
1884  /// Return true if table is instantiated, and false otherwise.
1885  bool is_created() const { return created; }
1886 
1887  /**
1888  Set the table as "created", and enable flags in storage engine
1889  that could not be enabled without an instantiated table.
1890  */
1891  void set_created();
1892  /**
1893  Set the contents of table to be "deleted", ie "not created", after having
1894  deleted the contents.
1895  */
1896  void set_deleted() { created = materialized = false; }
1897  /// Set table as nullable, ie it is inner wrt some outer join
1898  void set_nullable() { nullable = true; }
1899 
1900  /// Return whether table is nullable
1901  bool is_nullable() const { return nullable; }
1902 
1903  /// @return true if table contains one or more generated columns
1904  bool has_gcol() const { return vfield; }
1905 
1906  /**
1907  Life cycle of the row buffer is as follows:
1908  - The initial state is "not started".
1909  - When reading a row through the storage engine handler, the status is set
1910  as "has row" or "no row", depending on whether a row was found or not.
1911  The "not started" state is cleared, as well as the "null row" state,
1912  the updated state and the deleted state.
1913  - When making a row available in record[0], make sure to update row status
1914  similarly to how the storage engine handler does it.
1915  - If a NULL-extended row is needed in join execution, the "null row" state
1916  is set. Note that this can be combined with "has row" if a row was read
1917  but condition on it was evaluated to false (happens for single-row
1918  lookup), or "no row" if no more rows could be read.
1919  Note also that for the "null row" state, the NULL bits inside the
1920  row are set to one, so the row inside the row buffer is no longer usable,
1921  unless the NULL bits are saved in a separate buffer.
1922  - The "is updated" and "is deleted" states are set when row is updated or
1923  deleted, respectively.
1924  */
1925  /// Set status for row buffer as "not started"
1928  null_row = false;
1929  }
1930 
1931  /// @return true if a row operation has been done
1932  bool is_started() const { return !(m_status & STATUS_NOT_STARTED); }
1933 
1934  /// Set status for row buffer: contains row
1935  void set_found_row() {
1936  m_status = 0;
1937  null_row = false;
1938  }
1939 
1940  /**
1941  Set status for row buffer: contains no row. This is set when
1942  - A lookup operation finds no row
1943  - A scan operation scans past the last row of the range.
1944  - An error in generating key values before calling storage engine.
1945  */
1946  void set_no_row() {
1948  null_row = false;
1949  }
1950 
1951  /**
1952  Set "row found" status from handler result
1953 
1954  @param status 0 if row was found, <> 0 if row was not found
1955  */
1958  null_row = false;
1959  }
1960 
1961  /**
1962  Set current row as "null row", for use in null-complemented outer join.
1963  The row buffer may or may not contain a valid row.
1964  set_null_row() and reset_null_row() are used by the join executor to
1965  signal the presence or absence of a NULL-extended row for an outer joined
1966  table. Null rows may also be used to specify rows that are all NULL in
1967  grouing operations.
1968  @note this is a destructive operation since the NULL value bit vector
1969  is overwritten. Caching operations must be aware of this.
1970  */
1971  void set_null_row() {
1972  null_row = true;
1974  if (s->null_bytes > 0) memset(null_flags, 255, s->null_bytes);
1975  }
1976 
1977  /// Clear "null row" status for the current row
1979  null_row = false;
1981  }
1982 
1983  /// Set "updated" property for the current row
1985  assert(is_started() && has_row());
1987  }
1988 
1989  /// Set "deleted" property for the current row
1991  assert(is_started() && has_row());
1993  }
1994 
1995  /// @return true if there is a row in row buffer
1996  bool has_row() const { return !(m_status & STATUS_NOT_FOUND); }
1997 
1998  /// @return true if current row is null-extended
1999  bool has_null_row() const { return null_row; }
2000 
2001  /// @return true if current row has been updated (multi-table update)
2002  bool has_updated_row() const { return m_status & STATUS_UPDATED; }
2003 
2004  /// @return true if current row has been deleted (multi-table delete)
2005  bool has_deleted_row() const { return m_status & STATUS_DELETED; }
2006 
2007  /// Save the NULL flags of the current row into the designated buffer
2009  if (s->null_bytes > 0) memcpy(null_flags_saved, null_flags, s->null_bytes);
2010  }
2011 
2012  /// Restore the NULL flags of the current row from the designated buffer
2014  if (s->null_bytes > 0) memcpy(null_flags, null_flags_saved, s->null_bytes);
2015  }
2016 
2017  /// Empties internal temporary table (deletes rows, closes scan)
2018  bool empty_result_table();
2019 
2020  /**
2021  Initialize the optimizer cost model.
2022 
2023  This function should be called each time a new query is started.
2024 
2025  @param cost_model_server the main cost model object for the query
2026  */
2027  void init_cost_model(const Cost_model_server *cost_model_server) {
2028  m_cost_model.init(cost_model_server, this);
2029  }
2030 
2031  /**
2032  Return the cost model object for this table.
2033  */
2034  const Cost_model_table *cost_model() const { return &m_cost_model; }
2035 
2036  /**
2037  Fix table's generated columns' (GC) and/or default expressions
2038 
2039  @details When a table is opened from the dictionary, the Value Generator
2040  expressions are fixed during opening (see fix_value_generators_fields()).
2041  After query execution, Item::cleanup() is called on them
2042  (see cleanup_value_generator_items()). When the table is opened from the
2043  table cache, the Value Generetor(s) need to be fixed again and this
2044  function does that.
2045 
2046  @param[in] thd the current thread
2047  */
2048  void refix_value_generator_items(THD *thd);
2049 
2050  /**
2051  Helper function for refix_value_generator_items() that fixes one column's
2052  expression (be it GC or default expression) and check constraint expression.
2053 
2054  @param[in,out] g_expr the expression who's items needs to be fixed
2055  */
2057 
2058  /**
2059  Clean any state in items associated with generated columns to be ready for
2060  the next statement.
2061  */
2063 
2064 #ifndef NDEBUG
2066 #endif
2067  /**
2068  Update covering keys depending on max read key length.
2069 
2070  Update available covering keys for the table, based on a constrained field
2071  and the identified covering prefix keys: If the matched part of field is
2072  longer than the index prefix,
2073  the prefix index cannot be used as a covering index.
2074 
2075  @param[in] field Pointer to field object
2076  @param[in] key_read_length Max read key length
2077  @param[in] covering_prefix_keys Covering prefix keys
2078  */
2079  void update_covering_prefix_keys(Field *field, uint16 key_read_length,
2080  Key_map *covering_prefix_keys);
2081 
2082  private:
2083  /**
2084  Bitmap that tells which columns are eligible for partial update in an
2085  update statement.
2086 
2087  The bitmap is lazily allocated in the TABLE's mem_root when
2088  #mark_column_for_partial_update() is called.
2089  */
2091 
2092  /**
2093  Object which contains execution time state used for partial update
2094  of JSON columns.
2095 
2096  It is allocated in the execution mem_root by #setup_partial_update() if
2097  there are columns that have been marked as eligible for partial update.
2098  */
2100 
2101  /**
2102  This flag decides whether or not we should log the drop temporary table
2103  command.
2104  */
2106 
2107  public:
2108  /**
2109  Does this table have any columns that can be updated using partial update
2110  in the current row?
2111 
2112  @return whether any columns in the current row can be updated using partial
2113  update
2114  */
2115  bool has_binary_diff_columns() const;
2116 
2117  /**
2118  Get the list of binary diffs that have been collected for a given column in
2119  the current row, or `nullptr` if partial update cannot be used for that
2120  column.
2121 
2122  @param field the column to get binary diffs for
2123  @return the list of binary diffs for the column, or `nullptr` if the column
2124  cannot be updated using partial update
2125  */
2126  const Binary_diff_vector *get_binary_diffs(const Field *field) const;
2127 
2128  /**
2129  Mark a given column as one that can potentially be updated using
2130  partial update during execution of an update statement.
2131 
2132  Whether it is actually updated using partial update, is not
2133  determined until execution time, since that depends both on the
2134  data that is in the column and the new data that is written to the
2135  column.
2136 
2137  This function should be called during preparation of an update
2138  statement.
2139 
2140  @param field a column which is eligible for partial update
2141  @retval false on success
2142  @retval true on out-of-memory
2143  */
2145 
2146  /**
2147  Has this column been marked for partial update?
2148 
2149  Note that this only tells if the column satisfies the syntactical
2150  requirements for being partially updated. Use #is_binary_diff_enabled() or
2151  #is_logical_diff_enabled() instead to see if partial update should be used
2152  on the column.
2153 
2154  @param field the column to check
2155  @return whether the column has been marked for partial update
2156  */
2157  bool is_marked_for_partial_update(const Field *field) const;
2158 
2159  /**
2160  Does this table have any columns that were marked with
2161  #mark_column_for_partial_update()?
2162 
2163  Note that this only tells if any of the columns satisfy the syntactical
2164  requirements for being partially updated. Use
2165  #has_binary_diff_columns(), #is_binary_diff_enabled() or
2166  #is_logical_diff_enabled() instead to see if partial update should be used
2167  on a column.
2168  */
2170 
2171  /**
2172  Enable partial update of JSON columns in this table. It is only
2173  enabled for the columns that have previously been marked for
2174  partial update using #mark_column_for_partial_update().
2175 
2176  @param logical_diffs should logical JSON diffs be collected in addition
2177  to the physical binary diffs?
2178 
2179  This function should be called once per statement execution, when
2180  the update statement is optimized.
2181 
2182  @retval false on success
2183  @retval true on out-of-memory
2184  */
2185  bool setup_partial_update(bool logical_diffs);
2186 
2187  /**
2188  @see setup_partial_update(bool)
2189 
2190  This is a wrapper that auto-computes the value of the parameter
2191  logical_diffs.
2192 
2193  @retval false on success
2194  @retval true on out-of-memory
2195  */
2196  bool setup_partial_update();
2197 
2198  /**
2199  Add a binary diff for a column that is updated using partial update.
2200 
2201  @param field the column that is being updated
2202  @param offset the offset of the changed portion
2203  @param length the length of the changed portion
2204 
2205  @retval false on success
2206  @retval true on out-of-memory
2207  */
2208  bool add_binary_diff(const Field *field, size_t offset, size_t length);
2209 
2210  /**
2211  Clear the diffs that have been collected for partial update of
2212  JSON columns, and re-enable partial update for any columns where
2213  partial update was temporarily disabled for the current row.
2214  Should be called between each row that is updated.
2215  */
2217 
2218  /**
2219  Clean up state used for partial update of JSON columns.
2220 
2221  This function should be called at the end of each statement
2222  execution.
2223  */
2224  void cleanup_partial_update();
2225 
2226  /**
2227  Temporarily disable collection of binary diffs for a column in the current
2228  row.
2229 
2230  This function is called during execution to disable partial update of a
2231  column that was previously marked as eligible for partial update with
2232  #mark_column_for_partial_update() during preparation.
2233 
2234  Partial update of this column will be re-enabled when we go to the next
2235  row.
2236 
2237  @param field the column to stop collecting binary diffs for
2238  */
2240 
2241  /**
2242  Temporarily disable collection of Json_diff objects describing the
2243  logical changes of a JSON column in the current row.
2244 
2245  Collection of logical JSON diffs is re-enabled when we go to the next row.
2246 
2247  @param field the column to stop collecting logical JSON diffs for
2248  */
2250 
2251  /**
2252  Get a buffer that can be used to hold the partially updated column value
2253  while performing partial update.
2254  */
2256 
2257  /**
2258  Add a logical JSON diff describing a logical change to a JSON column in
2259  partial update.
2260 
2261  @param field the column that is updated
2262  @param path the JSON path that is changed
2263  @param operation the operation to perform
2264  @param new_value the new value in the path
2265 
2266  @throws std::bad_alloc if memory cannot be allocated
2267  */
2269  enum_json_diff_operation operation,
2270  const Json_wrapper *new_value);
2271 
2272  /**
2273  Get the list of JSON diffs that have been collected for a given column in
2274  the current row, or `nullptr` if partial update cannot be used for that
2275  column.
2276 
2277  @param field the column to get JSON diffs for
2278  @return the list of JSON diffs for the column, or `nullptr` if the column
2279  cannot be updated using partial update
2280  */
2281  const Json_diff_vector *get_logical_diffs(const Field_json *field) const;
2282 
2283  /**
2284  Is partial update using binary diffs enabled on this JSON column?
2285 
2286  @param field the column to check
2287  @return whether the column can be updated with binary diffs
2288  */
2289  bool is_binary_diff_enabled(const Field *field) const;
2290 
2291  /**
2292  Is partial update using logical diffs enabled on this JSON column?
2293 
2294  @param field the column to check
2295  @return whether the column can be updated with JSON diffs
2296  */
2297  bool is_logical_diff_enabled(const Field *field) const;
2298 
2299  /**
2300  Virtual fields of type BLOB have a flag m_keep_old_value. This flag is set
2301  to false for all such fields in this table.
2302  */
2304 
2305  /**
2306  Set the variable should_binlog_drop_if_temp_flag, so that
2307  the logging of temporary tables can be decided.
2308 
2309  @param should_binlog the value to set flag should_binlog_drop_if_temp_flag
2310  */
2311  void set_binlog_drop_if_temp(bool should_binlog);
2312 
2313  /**
2314  @return whether should_binlog_drop_if_temp_flag flag is
2315  set or not
2316  */
2317  bool should_binlog_drop_if_temp(void) const;
2318 };
2319 
2320 static inline void empty_record(TABLE *table) {
2321  restore_record(table, s->default_values);
2322  if (table->s->null_bytes > 0)
2323  memset(table->null_flags, 255, table->s->null_bytes);
2324 }
2325 
2326 #define MY_I_S_MAYBE_NULL 1
2327 #define MY_I_S_UNSIGNED 2
2328 
2330  /**
2331  This is used as column name.
2332  */
2333  const char *field_name;
2334  /**
2335  For string-type columns, this is the maximum number of
2336  characters. Otherwise, it is the 'display-length' for the column.
2337  For the data type MYSQL_TYPE_DATETIME this field specifies the
2338  number of digits in the fractional part of time value.
2339  */
2341  /**
2342  This denotes data type for the column. For the most part, there seems to
2343  be one entry in the enum for each SQL data type, although there seem to
2344  be a number of additional entries in the enum.
2345  */
2347  int value;
2348  /**
2349  This is used to set column attributes. By default, columns are @c NOT
2350  @c NULL and @c SIGNED, and you can deviate from the default
2351  by setting the appropriate flags. You can use either one of the flags
2352  @c MY_I_S_MAYBE_NULL and @c MY_I_S_UNSIGNED or
2353  combine them using the bitwise or operator @c |. Both flags are
2354  defined in table.h.
2355  */
2356  uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.)
2357  const char *old_name;
2358  uint open_method; // Not used
2359 };
2360 
2362  const char *table_name;
2364  /* Fill table with data */
2365  int (*fill_table)(THD *thd, TABLE_LIST *tables, Item *cond);
2366  /* Handle fileds for old SHOW */
2367  int (*old_format)(THD *thd, ST_SCHEMA_TABLE *schema_table);
2368  int (*process_table)(THD *thd, TABLE_LIST *tables, TABLE *table, bool res,
2370  bool hidden;
2371 };
2372 
2373 /**
2374  Strategy for how to process a view or derived table (merge or materialization)
2375 */
2380 };
2381 
2382 #define VIEW_SUID_INVOKER 0
2383 #define VIEW_SUID_DEFINER 1
2384 #define VIEW_SUID_DEFAULT 2
2385 
2386 /* view WITH CHECK OPTION parameter options */
2387 #define VIEW_CHECK_NONE 0
2388 #define VIEW_CHECK_LOCAL 1
2389 #define VIEW_CHECK_CASCADED 2
2390 
2391 /* result of view WITH CHECK OPTION parameter check */
2392 #define VIEW_CHECK_OK 0
2393 #define VIEW_CHECK_ERROR 1
2394 #define VIEW_CHECK_SKIP 2
2395 
2396 /** The threshold size a blob field buffer before it is freed */
2397 #define MAX_TDC_BLOB_SIZE 65536
2398 
2399 /**
2400  Struct that describes an expression selected from a derived table or view.
2401 */
2403  /**
2404  Points to an item that represents the expression.
2405  If the item is determined to be unused, the pointer is set to NULL.
2406  */
2408  /// Name of selected expression
2409  const char *name;
2410 };
2411 
2412 /*
2413  Column reference of a NATURAL/USING join. Since column references in
2414  joins can be both from views and stored tables, may point to either a
2415  Field (for tables), or a Field_translator (for views).
2416 */
2417 
2419  public:
2420  Field_translator *view_field; /* Column reference of merge view. */
2421  Item_field *table_field; /* Column reference of table or temp view. */
2422  TABLE_LIST *table_ref; /* Original base table/view reference. */
2423  /*
2424  True if a common join column of two NATURAL/USING join operands. Notice
2425  that when we have a hierarchy of nested NATURAL/USING joins, a column can
2426  be common at some level of nesting but it may not be common at higher
2427  levels of nesting. Thus this flag may change depending on at which level
2428  we are looking at some column.
2429  */
2431 
2432  public:
2433  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
2434  Natural_join_column(Item_field *field_param, TABLE_LIST *tab);
2435  const char *name();
2436  Item *create_item(THD *thd);
2437  Field *field();
2438  const char *table_name();
2439  const char *db_name();
2440  GRANT_INFO *grant();
2441 };
2442 
2443 /**
2444  This is generic enum. It may be reused in the ACL statements
2445  for clauses that can map to the values defined in this enum.
2446 */
2448  UNCHANGED, /* The clause is not specified */
2449  DEFAULT, /* Default value of clause is specified */
2450  YES, /* Value that maps to True is specified */
2451  NO /* Value that maps to False is specified */
2452 };
2453 
2454 struct LEX_MFA {
2460  /*
2461  The following flags are indicators for the SQL syntax used while
2462  parsing CREATE/ALTER user. While other members are self-explanatory,
2463  'uses_authentication_string_clause' signifies if the password is in
2464  hash form (if the var was set to true) or not.
2465  */
2470  /* flag set during CREATE USER .. INITIAL AUTHENTICATION BY */
2472  /* flag set during ALTER USER .. ADD nth FACTOR */
2474  /* flag set during ALTER USER .. MODIFY nth FACTOR */
2476  /* flag set during ALTER USER .. DROP nth FACTOR */
2478  /*
2479  flag used during authentication and to decide if server should
2480  be in sandbox mode or not
2481  */
2483  /* flag set during ALTER USER .. nth FACTOR UNREGISTER */
2485  /* flag set during ALTER USER .. INITIATE REGISTRATION */
2487  /* flag set during ALTER USER .. FINISH REGISTRATION */
2489 
2490  LEX_MFA() { reset(); }
2491  void reset() {
2492  plugin = EMPTY_CSTR;
2493  auth = NULL_CSTR;
2496  nth_factor = 1;
2497  uses_identified_by_clause = false;
2500  has_password_generator = false;
2501  passwordless = false;
2502  add_factor = false;
2503  drop_factor = false;
2504  modify_factor = false;
2505  requires_registration = false;
2506  unregister = false;
2507  init_registration = false;
2508  finish_registration = false;
2509  }
2510  void copy(LEX_MFA *m, MEM_ROOT *alloc);
2511 };
2512 
2513 /*
2514  This structure holds the specifications relating to
2515  ALTER user ... PASSWORD EXPIRE ...
2516 */
2517 struct LEX_ALTER {
2534  /* Holds the specification of 'PASSWORD REQUIRE CURRENT' clause. */
2536  void cleanup() {
2540  expire_after_days = 0;
2542  account_locked = false;
2544  update_password_history = false;
2550  update_password_lock_time = false;
2553  password_lock_time = 0;
2554  }
2555 };
2556 
2557 /*
2558  This structure holds the specifications related to
2559  mysql user and the associated auth details.
2560 */
2561 struct LEX_USER {
2569  /* restrict MFA methods to atmost 3 authentication plugins */
2573 
2574  void init() {
2575  user = NULL_CSTR;
2576  host = NULL_CSTR;
2578  uses_replace_clause = false;
2579  retain_current_password = false;
2580  discard_old_password = false;
2581  alter_status.account_locked = false;
2597  mfa_list.clear();
2598  with_initial_auth = false;
2599  }
2600 
2601  LEX_USER() { init(); }
2602 
2603  bool add_mfa_identifications(LEX_MFA *factor2, LEX_MFA *factor3 = nullptr);
2604 
2605  /*
2606  Allocates the memory in the THD mem pool and initialize the members of
2607  this struct. It is preferable to use this method to create a LEX_USER
2608  rather allocating the memory in the THD and initializing the members
2609  explicitly.
2610  */
2611  static LEX_USER *alloc(THD *thd);
2612  static LEX_USER *alloc(THD *thd, LEX_STRING *user, LEX_STRING *host);
2613  /*
2614  Initialize the members of this struct. It is preferable to use this method
2615  to initialize a LEX_USER rather initializing the members explicitly.
2616  */
2617  static LEX_USER *init(LEX_USER *to_init, THD *thd, LEX_STRING *user,
2618  LEX_STRING *host);
2619 };
2620 
2621 /**
2622  Derive type of metadata lock to be requested for table used by a DML
2623  statement from the type of THR_LOCK lock requested for this table.
2624 */
2625 
2626 inline enum enum_mdl_type mdl_type_for_dml(enum thr_lock_type lock_type) {
2627  return lock_type >= TL_WRITE_ALLOW_WRITE
2629  : MDL_SHARED_WRITE)
2630  : MDL_SHARED_READ;
2631 }
2632 
2633 /**
2634  Type of table which can be open for an element of table list.
2635 */
2636 
2640  OT_BASE_ONLY
2641 };
2642 
2643 /**
2644  This structure is used to keep info about possible key for the result table
2645  of a derived table/view.
2646  The 'referenced_by' is the table map of tables to which this possible
2647  key corresponds.
2648  The 'used_field' is a map of fields of which this key consists of.
2649  See also the comment for the TABLE_LIST::update_derived_keys function.
2650 */
2651 
2653  public:
2657 };
2658 
2659 class Table_function;
2660 /*
2661  Table reference in the FROM clause.
2662 
2663  These table references can be of several types that correspond to
2664  different SQL elements. Below we list all types of TABLE_LISTs with
2665  the necessary conditions to determine when a TABLE_LIST instance
2666  belongs to a certain type.
2667 
2668  1) table (TABLE_LIST::view == NULL)
2669  - base table
2670  (TABLE_LIST::derived == NULL)
2671  - subquery - TABLE_LIST::table is a temp table
2672  (TABLE_LIST::derived != NULL)
2673  - information schema table
2674  (TABLE_LIST::schema_table != NULL)
2675  NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
2676  2) view (TABLE_LIST::view != NULL)
2677  - merge (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
2678  also (TABLE_LIST::field_translation != NULL)
2679  - temptable(TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TEMPTABLE)
2680  also (TABLE_LIST::field_translation == NULL)
2681  3) nested table reference (TABLE_LIST::nested_join != NULL)
2682  - table sequence - e.g. (t1, t2, t3)
2683  TODO: how to distinguish from a JOIN?
2684  - general JOIN
2685  TODO: how to distinguish from a table sequence?
2686  - NATURAL JOIN
2687  (TABLE_LIST::natural_join != NULL)
2688  - JOIN ... USING
2689  (TABLE_LIST::join_using_fields != NULL)
2690  - semi-join
2691  ;
2692 */
2693 
2694 struct TABLE_LIST {
2695  TABLE_LIST() = default;
2696 
2697  /**
2698  Only to be used by legacy code that temporarily needs a TABLE_LIST, more
2699  specifically: Query_result_create::binlog_show_create_table().
2700  */
2701  explicit TABLE_LIST(TABLE *table_arg) : table(table_arg) {}
2702 
2703  /// Constructor that can be used when the strings are null terminated.
2704  TABLE_LIST(const char *db_name, const char *table_name,
2705  enum thr_lock_type lock_type)
2706  : TABLE_LIST(db_name, strlen(db_name), table_name, strlen(table_name),
2707  table_name, lock_type) {}
2708 
2709  /**
2710  Creates a TABLE_LIST object with pre-allocated strings for database, table
2711  and alias.
2712  */
2713  TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2714  const char *table_name_arg, size_t table_name_length_arg,
2715  const char *alias_arg, enum thr_lock_type lock_type_arg)
2716  : db(db_name_arg),
2717  table_name(table_name_arg),
2718  alias(alias_arg),
2719  m_map(1),
2720  table(table_arg),
2721  m_lock_descriptor{lock_type_arg},
2722  db_length(db_length_arg),
2723  table_name_length(table_name_length_arg) {
2726  }
2727 
2728  /// Constructor that can be used when the strings are null terminated.
2729  TABLE_LIST(const char *db_name, const char *table_name, const char *alias,
2730  enum thr_lock_type lock_type)
2731  : TABLE_LIST(db_name, strlen(db_name), table_name, strlen(table_name),
2732  alias, lock_type) {}
2733 
2734  /**
2735  This constructor can be used when a TABLE_LIST is needed for an existing
2736  temporary table. These typically have very long table names, since it is
2737  a fully qualified path. For this reason, the table is set to the alias.
2738  The database name is left blank. The lock descriptor is set to TL_READ.
2739  */
2740  TABLE_LIST(TABLE *table_arg, const char *alias_arg)
2741  : db(""),
2742  table_name(alias_arg),
2743  alias(alias_arg),
2744  m_map(1),
2745  table(table_arg),
2747  db_length(0),
2748  table_name_length(strlen(alias_arg)) {
2751  }
2752 
2753  /**
2754  Sets an explicit enum_mdl_type value, without initializing
2755  m_lock_descriptor.
2756  */
2757  TABLE_LIST(TABLE *table_arg, const char *alias_arg, enum_mdl_type mdl_type)
2758  : db(table_arg->s->db.str),
2759  table_name(table_arg->s->table_name.str),
2760  alias(alias_arg),
2761  m_map(1),
2762  table(table_arg),
2763  db_length(table_arg->s->db.length),
2764  table_name_length(table_arg->s->table_name.length) {
2766  MDL_TRANSACTION);
2767  }
2768 
2769  TABLE_LIST(const char *db_name, const char *table_name_arg,
2770  enum thr_lock_type lock_type_arg,
2771  enum enum_mdl_type mdl_request_type)
2772  : db(db_name),
2773  table_name(table_name_arg),
2774  alias(table_name_arg),
2775  m_map(1),
2776  m_lock_descriptor{lock_type_arg},
2777  db_length(strlen(db_name)),
2778  table_name_length(strlen(table_name_arg)) {
2781  mdl_request.set_type(mdl_request_type);
2782  }
2783 
2784  TABLE_LIST(const char *db_name, size_t db_length_arg,
2785  const char *table_name_arg, size_t table_name_length_arg,
2786  enum thr_lock_type lock_type_arg,
2787  enum enum_mdl_type mdl_request_type)
2788  : db(db_name),
2789  table_name(table_name_arg),
2790  alias(table_name_arg),
2791  m_map(1),
2792  m_lock_descriptor{lock_type_arg},
2793  db_length(db_length_arg),
2794  table_name_length(table_name_length_arg) {
2797  mdl_request.set_type(mdl_request_type);
2798  }
2799 
2800  TABLE_LIST(const char *db_name, size_t db_length_arg,
2801  const char *table_name_arg, size_t table_name_length_arg,
2802  enum thr_lock_type lock_type_arg)
2803  : db(db_name),
2804  table_name(table_name_arg),
2805  alias(table_name_arg),
2806  m_map(1),
2807  m_lock_descriptor{lock_type_arg},
2808  db_length(db_length_arg),
2809  table_name_length(table_name_length_arg) {}
2810 
2811  /**
2812  Sets an explicit enum_mdl_type value, without initializing
2813  m_lock_descriptor.
2814  */
2815  TABLE_LIST(const char *db_name, size_t db_length_arg,
2816  const char *table_name_arg, size_t table_name_length_arg,
2817  const char *alias_arg, enum enum_mdl_type mdl_request_type)
2818  : db(db_name),
2819  table_name(table_name_arg),
2820  alias(alias_arg),
2821  m_map(1),
2822  db_length(db_length_arg),
2823  table_name_length(table_name_length_arg) {
2826  mdl_request.set_type(mdl_request_type);
2827  }
2828 
2829  TABLE_LIST(const char *db_name, size_t db_length_arg,
2830  const char *table_name_arg, size_t table_name_length_arg,
2831  const char *alias_arg, enum thr_lock_type lock_type_arg,
2832  enum enum_mdl_type mdl_request_type)
2833  : db(db_name),
2834  table_name(table_name_arg),
2835  alias(alias_arg),
2836  m_map(1),
2837  m_lock_descriptor{lock_type_arg},
2838  db_length(db_length_arg),
2839  table_name_length(table_name_length_arg) {
2842  mdl_request.set_type(mdl_request_type);
2843  }
2844 
2845  TABLE_LIST(const char *db_name_arg, size_t db_length_arg,
2846  const char *table_name_arg, size_t table_name_length_arg,
2847  const char *alias_arg, enum thr_lock_type lock_type_arg)
2848  : db(db_name_arg),
2849  table_name(table_name_arg),
2850  alias(alias_arg),
2851  m_map(1),
2852  m_lock_descriptor{lock_type_arg},
2853  db_length(db_length_arg),
2854  table_name_length(table_name_length_arg) {
2857  }
2858 
2859  /// Create a TABLE_LIST object representing a nested join
2860  static TABLE_LIST *new_nested_join(MEM_ROOT *allocator, const char *alias,
2862  mem_root_deque<TABLE_LIST *> *belongs_to,
2863  Query_block *select);
2864  Item **join_cond_ref() { return &m_join_cond; }
2865  Item *join_cond() const { return m_join_cond; }
2866  void set_join_cond(Item *val) {
2867  // If optimization has started, it's too late to change m_join_cond.
2868  assert(m_join_cond_optim == nullptr || m_join_cond_optim == (Item *)1);
2869  m_join_cond = val;
2870  }
2873  /*
2874  Either we are setting to "empty", or there must pre-exist a
2875  permanent condition.
2876  */
2877  assert(cond == nullptr || cond == (Item *)1 || m_join_cond != nullptr);
2878  m_join_cond_optim = cond;
2879  }
2881 
2882  /// @returns true if semi-join nest
2883  bool is_sj_nest() const { return m_is_sj_or_aj_nest && !m_join_cond; }
2884  /// @returns true if anti-join nest
2885  bool is_aj_nest() const { return m_is_sj_or_aj_nest && m_join_cond; }
2886  /// @returns true if anti/semi-join nest
2887  bool is_sj_or_aj_nest() const { return m_is_sj_or_aj_nest; }
2888  /// Makes the next a semi/antijoin nest
2890  assert(!m_is_sj_or_aj_nest);
2891  m_is_sj_or_aj_nest = true;
2892  }
2893 
2894  /// Merge tables from a query block into a nested join structure
2895  bool merge_underlying_tables(Query_block *select);
2896 
2897  /// Reset table
2898  void reset();
2899 
2900  /// Evaluate the check option of a view
2901  int view_check_option(THD *thd) const;
2902 
2903  /// Cleanup field translations for a view
2904  void cleanup_items();
2905 
2906  /// Produce a textual identification of this object
2907  void print(const THD *thd, String *str, enum_query_type query_type) const;
2908 
2909  /// Check which single table inside a view that matches a table map
2910  bool check_single_table(TABLE_LIST **table_ref, table_map map);
2911 
2912  /// Allocate a buffer for inserted column values
2914 
2916  /**
2917  Retrieve the last (right-most) leaf in a nested join tree with
2918  respect to name resolution.
2919 
2920 
2921  Given that 'this' is a nested table reference, recursively walk
2922  down the right-most children of 'this' until we reach a leaf
2923  table reference with respect to name resolution.
2924 
2925  The right-most child of a nested table reference is the first
2926  element in the list of children because the children are inserted
2927  in reverse order.
2928 
2929  @return
2930  - If 'this' is a nested table reference - the right-most child
2931  of the tree rooted in 'this',
2932  - else - 'this'
2933  */
2935  bool is_leaf_for_name_resolution() const;
2936 
2937  /// Return the outermost view this table belongs to, or itself
2938  inline const TABLE_LIST *top_table() const {
2939  return belong_to_view ? belong_to_view : this;
2940  }
2941 
2942  inline TABLE_LIST *top_table() {
2943  return const_cast<TABLE_LIST *>(
2944  const_cast<const TABLE_LIST *>(this)->top_table());
2945  }
2946 
2947  /// Prepare check option for a view
2948  bool prepare_check_option(THD *thd, bool is_cascaded = false);
2949 
2950  /// Merge WHERE condition of view or derived table into outer query
2951  bool merge_where(THD *thd);
2952 
2953  /// Prepare replace filter for a view (used for REPLACE command)
2954  bool prepare_replace_filter(THD *thd);
2955 
2956  /// Return true if this represents a named view
2957  bool is_view() const { return view != nullptr; }
2958 
2959  /// Return true if this represents a derived table (an unnamed view)
2960  bool is_derived() const { return derived != nullptr && view == nullptr; }
2961 
2962  /// Return true if this represents a named view or a derived table
2963  bool is_view_or_derived() const { return derived != nullptr; }
2964 
2965  /// Return true if this represents a table function
2966  bool is_table_function() const { return table_function != nullptr; }
2967  /**
2968  @returns true if this is a recursive reference inside the definition of a
2969  recursive CTE.
2970  @note that it starts its existence as a dummy derived table, until the
2971  end of resolution when it's not a derived table anymore, just a reference
2972  to the materialized temporary table. Whereas a non-recursive
2973  reference to the recursive CTE is a derived table.
2974  */
2976 
2977  /// @returns true if this is a base table (permanent or temporary)
2978  bool is_base_table() const {
2979  return !(is_view_or_derived() || is_table_function() ||
2981  }
2982  /**
2983  @see is_recursive_reference().
2984  @returns true if error
2985  */
2986  bool set_recursive_reference();
2987 
2988  /**
2989  @returns true for a table that represents an optimizer internal table,
2990  is a derived table, a recursive reference, a table function.
2991  Internal tables are only visible inside a query expression, and is hence
2992  not visible in any schema, or need any kind of privilege checking.
2993  */
2994  bool is_internal() const {
2996  }
2997 
2998  /**
2999  @returns true for a table that is a placeholder, ie a derived table,
3000  a view, a recursive reference, a table function or a schema table.
3001  A table is also considered to be a placeholder if it does not have a
3002  TABLE object for some other reason.
3003  */
3004  bool is_placeholder() const {
3006  is_table_function() || schema_table || table == nullptr;
3007  }
3008 
3009  /// Return true if view or derived table and can be merged
3010  bool is_mergeable() const;
3011 
3012  /**
3013  Checks if this is a table that contains zero rows or one row, and that can
3014  be materialized during optimization.
3015 
3016  @returns true if materializable table contains one or zero rows, and
3017  materialization during optimization is permitted
3018 
3019  Returning true, if the hypergraph optimizer is not active, implies that the
3020  table is materialized during optimization, so it need not be optimized
3021  during execution. The hypergraph optimizer does not care about const tables,
3022  so such tables are not executed during optimization time when it is active.
3023  */
3024  bool materializable_is_const() const;
3025 
3026  /// Return true if this is a derived table or view that is merged
3028 
3029  /// Set table to be merged
3030  void set_merged() {
3033  }
3034 
3035  /// Return true if this is a materializable derived table/view
3036  bool uses_materialization() const {
3038  }
3039 
3040  /// Set table to be materialized
3042  // @todo We should do this only once, but currently we cannot:
3043  // assert(effective_algorithm == VIEW_ALGORITHM_UNDEFINED);
3046  }
3047 
3048  /// Return true if table is updatable
3049  bool is_updatable() const { return m_updatable; }
3050 
3051  /// Set table as updatable. (per default, a table is non-updatable)
3052  void set_updatable() { m_updatable = true; }
3053 
3054  /// Return true if table is insertable-into
3055  bool is_insertable() const { return m_insertable; }
3056 
3057  /// Set table as insertable-into. (per default, a table is not insertable)
3058  void set_insertable() { m_insertable = true; }
3059 
3060  /// Return true if table is being updated
3061  bool is_updated() const { return m_updated; }
3062 
3063  /// Set table and all referencing views as being updated
3064  void set_updated() {
3065  for (TABLE_LIST *tr = this; tr != nullptr; tr = tr->referencing_view)
3066  tr->m_updated = true;
3067  }
3068 
3069  /// Return true if table is being inserted into
3070  bool is_inserted() const { return m_inserted; }
3071 
3072  /// Set table and all referencing views as being inserted into
3073  void set_inserted() {
3074  for (TABLE_LIST *tr = this; tr != nullptr; tr = tr->referencing_view)
3075  tr->m_inserted = true;
3076  }
3077 
3078  /// Return true if table is being deleted from
3079  bool is_deleted() const { return m_deleted; }
3080 
3081  /// Set table and all referencing views as being deleted from
3082  void set_deleted() {
3083  for (TABLE_LIST *tr = this; tr != nullptr; tr = tr->referencing_view)
3084  tr->m_deleted = true;
3085  }
3086 
3087  /// Set table as full-text search (default is not fulltext searched)
3089 
3090  /// Returns true if a MATCH function references this table.
3092 
3093  /**
3094  Set table as readonly, ie it is neither updatable, insertable nor
3095  deletable during this statement.
3096  */
3097  void set_readonly() {
3098  m_updatable = false;
3099  m_insertable = false;
3100  }
3101 
3102  /**
3103  Return true if this is a view or derived table that is defined over
3104  more than one base table, and false otherwise.
3105  */
3106  bool is_multiple_tables() const {
3107  if (is_view_or_derived()) {
3108  assert(is_merged()); // Cannot be a materialized view
3109  return leaf_tables_count() > 1;
3110  } else {
3111  assert(nested_join == nullptr); // Must be a base table
3112  return false;
3113  }
3114  }
3115 
3116  /// Return no. of base tables a merged view or derived table is defined over.
3117  uint leaf_tables_count() const;
3118 
3119  /// Return first leaf table of a base table or a view/derived table
3121  TABLE_LIST *tr = this;
3122  while (tr->merge_underlying_list) tr = tr->merge_underlying_list;
3123  return tr;
3124  }
3125 
3126  /// Return any leaf table that is not an inner table of an outer join
3127  /// @todo WL#6570 with prepare-once, replace with first_leaf_table()
3128  /// when WL#6059 is merged in (it really converts RIGHT JOIN to
3129  /// LEFT JOIN so the first leaf is part of a LEFT JOIN,
3130  /// guaranteed).
3132  TABLE_LIST *tr = this;
3133  while (tr->merge_underlying_list) {
3134  tr = tr->merge_underlying_list;
3135  /*
3136  "while" is used, however, an "if" might be sufficient since there is
3137  no more than one inner table in a join nest (with outer_join true).
3138  */
3139  while (tr->outer_join) tr = tr->next_local;
3140  }
3141  return tr;
3142  }
3143  /**
3144  Set the LEX object of a view (will also define this as a view).
3145  @note: The value 1 is used to indicate a view but without a valid
3146  query object. Use only if the LEX object is not going to
3147  be used in later processing.
3148  */
3149  void set_view_query(LEX *lex) { view = lex; }
3150 
3151  /// Return the valid LEX object for a view.
3152  LEX *view_query() const {
3153  assert(view != nullptr && view != (LEX *)1);
3154  return view;
3155  }
3156 
3157  /**
3158  Set the query expression of a derived table or view.
3159  (Will also define this as a derived table, unless it is a named view.)
3160  */
3162  derived = query_expr;
3163  }
3164 
3165  /// Return the query expression of a derived table or view.
3167  assert(derived);
3168  return derived;
3169  }
3170 
3171  /// Resolve a derived table or view reference
3172  bool resolve_derived(THD *thd, bool apply_semijoin);
3173 
3174  /// Optimize the query expression representing a derived table/view
3175  bool optimize_derived(THD *thd);
3176 
3177  /// Create result table for a materialized derived table/view
3178  bool create_materialized_table(THD *thd);
3179 
3180  /// Materialize derived table
3181  bool materialize_derived(THD *thd);
3182 
3183  /// Check if we can push outer where condition to this derived table
3185 
3186  /// Get derived table expression
3187  Item *get_derived_expr(uint expr_index);
3188 
3189  /// Get cloned item for a derived table column. This creates the clone
3190  /// and resolves it in the context provided.
3191  Item *get_clone_for_derived_expr(THD *thd, Item *item,
3192  Name_resolution_context *context);
3193 
3194  /// Clean up the query expression for a materialized derived table
3195  void cleanup_derived(THD *thd);
3196 
3197  /// Prepare security context for a view
3198  bool prepare_security(THD *thd);
3199 
3202 
3203  /**
3204  Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query,
3205  TABLE::keys_in_use_for_group_by, TABLE::keys_in_use_for_order_by,
3206  TABLE::force_index and TABLE::covering_keys.
3207  */
3208  bool process_index_hints(const THD *thd, TABLE *table);
3209 
3210  /**
3211  Compare the version of metadata from the previous execution
3212  (if any) with values obtained from the current table
3213  definition cache element.
3214 
3215  @sa check_and_update_table_version()
3216  */
3218  return (m_table_ref_type == s->get_table_ref_type() &&
3220  }
3221 
3222  /**
3223  Record the value of metadata version of the corresponding
3224  table definition cache element in this parse tree node.
3225 
3226  @sa check_and_update_table_version()
3227  */
3230  }
3231 
3232  void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
3233  ulonglong table_ref_version_arg) {
3234  m_table_ref_type = table_ref_type_arg;
3235  m_table_ref_version = table_ref_version_arg;
3236  }
3237 
3238  /**
3239  If a derived table, returns query block id of first underlying query block.
3240  Zero if not derived.
3241  */
3242  uint query_block_id() const;
3243 
3244  /**
3245  This is for showing in EXPLAIN.
3246  If a derived table, returns query block id of first underlying query block
3247  of first materialized TABLE_LIST instance. Zero if not derived.
3248  */
3250 
3251  /**
3252  @brief Returns the name of the database that the referenced table belongs
3253  to.
3254  */
3255  const char *get_db_name() const { return db; }
3256 
3257  /**
3258  @brief Returns the name of the table that this TABLE_LIST represents.
3259 
3260  @details The unqualified table name or view name for a table or view,
3261  respectively.
3262  */
3263  const char *get_table_name() const { return table_name; }
3264  int fetch_number_of_rows();
3265  bool update_derived_keys(THD *, Field *, Item **, uint, bool *);
3266  bool generate_keys();
3267 
3268  /// Setup a derived table to use materialization
3269  bool setup_materialized_derived(THD *thd);
3271 
3272  /// Setup a table function to use materialization
3273  bool setup_table_function(THD *thd);
3274 
3275  bool create_field_translation(THD *thd);
3276 
3277  /**
3278  @brief Returns the outer join nest that this TABLE_LIST belongs to, if any.
3279 
3280  @details There are two kinds of join nests, outer-join nests and semi-join
3281  nests. This function returns non-NULL in the following cases:
3282  @li 1. If this table/nest is embedded in a nest and this nest IS NOT a
3283  semi-join nest. (In other words, it is an outer-join nest.)
3284  @li 2. If this table/nest is embedded in a nest and this nest IS a
3285  semi-join nest, but this semi-join nest is embedded in another
3286  nest. (This other nest will be an outer-join nest, since all inner
3287  joined nested semi-join nests have been merged in
3288  @c simplify_joins() ).
3289  Note: This function assumes that @c simplify_joins() has been performed.
3290  Before that, join nests will be present for all types of join.
3291 
3292  @return outer join nest, or NULL if none.
3293  */
3294 
3296  if (!embedding) return nullptr;
3297  if (embedding->is_sj_nest()) return embedding->embedding;
3298  return embedding;
3299  }
3300  /**
3301  Return true if this table is an inner table of some outer join.
3302 
3303  Examine all the embedding join nests of the table.
3304  @note This function works also before redundant join nests have been
3305  eliminated.
3306 
3307  @return true if table is an inner table of some outer join, false otherwise.
3308  */
3309 
3311  if (outer_join) return true;
3312  for (TABLE_LIST *emb = embedding; emb; emb = emb->embedding) {
3313  if (emb->outer_join) return true;
3314  }
3315  return false;
3316  }
3317 
3318  /**
3319  Return the base table entry of an updatable table.
3320  In DELETE and UPDATE, a view used as a target table must be mergeable,
3321  updatable and defined over a single table.
3322  */
3324  const TABLE_LIST *tbl = this;
3325  assert(tbl->is_updatable() && !tbl->is_multiple_tables());
3326  while (tbl->is_view_or_derived()) {
3327  tbl = tbl->merge_underlying_list;
3328  assert(tbl->is_updatable() && !tbl->is_multiple_tables());
3329  }
3330  return tbl;
3331  }
3332 
3334  return const_cast<TABLE_LIST *>(
3335  static_cast<const TABLE_LIST *>(this)->updatable_base_table());
3336  }
3337 
3338  /**
3339  Mark that there is a NATURAL JOIN or JOIN ... USING between two tables.
3340 
3341  This function marks that table b should be joined with a either via
3342  a NATURAL JOIN or via JOIN ... USING. Both join types are special
3343  cases of each other, so we treat them together. The function
3344  setup_conds() creates a list of equal condition between all fields
3345  of the same name for NATURAL JOIN or the fields in
3346  TABLE_LIST::join_using_fields for JOIN ... USING.
3347  The list of equality conditions is stored
3348  either in b->join_cond(), or in JOIN::conds, depending on whether there
3349  was an outer join.
3350 
3351  EXAMPLE
3352  @verbatim
3353  SELECT * FROM t1 NATURAL LEFT JOIN t2
3354  <=>
3355  SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
3356 
3357  SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
3358  <=>
3359  SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
3360 
3361  SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
3362  <=>
3363  SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
3364  @endverbatim
3365 
3366  @param b Right join argument.
3367  */
3368  void add_join_natural(TABLE_LIST *b) { b->natural_join = this; }
3369 
3370  /**
3371  Set granted privileges for a table.
3372 
3373  Can be used when generating temporary tables that are also used in
3374  resolver process, such as when generating a UNION table
3375 
3376  @param privilege Privileges granted for this table.
3377  */
3378  void set_privileges(ulong privilege) { grant.privilege |= privilege; }
3379 
3380  bool save_properties();
3381  void restore_properties();
3382 
3383  /*
3384  List of tables local to a subquery or the top-level SELECT (used by
3385  SQL_I_List). Considers views as leaves (unlike 'next_leaf' below).
3386  Created at parse time in Query_block::add_table_to_list() ->
3387  table_list.link_in_list().
3388  */
3390  /* link in a global list of all queries tables */
3391  TABLE_LIST *next_global{nullptr}, **prev_global{nullptr};
3392  const char *db{nullptr}, *table_name{nullptr}, *alias{nullptr};
3393  /*
3394  Target tablespace name: When creating or altering tables, this
3395  member points to the tablespace_name in the HA_CREATE_INFO struct.
3396  */
3398  char *option{nullptr}; /* Used by cache index */
3399 
3400  /** Table level optimizer hints for this table. */
3402  /* Hints for query block of this table. */
3404 
3405  void set_lock(const Lock_descriptor &descriptor) {
3406  m_lock_descriptor = descriptor;
3407  }
3408 
3410 
3411  private:
3412  /**
3413  The members below must be kept aligned so that (1 << m_tableno) == m_map.
3414  A table that takes part in a join operation must be assigned a unique
3415  table number.
3416  */
3417  uint m_tableno{0}; ///< Table number within query block
3418  table_map m_map{0}; ///< Table map, derived from m_tableno
3419  /**
3420  If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this
3421  member points to C. May also be generated from JOIN ... USING clause.
3422  It may be modified only by permanent transformations (permanent = done
3423  once for all executions of a prepared statement).
3424  */
3425  Item *m_join_cond{nullptr};
3426  bool m_is_sj_or_aj_nest{false};
3427 
3428  public:
3429  /*
3430  (Valid only for semi-join nests) Bitmap of tables that are within the
3431  semi-join (this is different from bitmap of all nest's children because
3432  tables that were pulled out of the semi-join nest remain listed as
3433  nest's children).
3434  */
3436 
3437  /*
3438  During parsing - left operand of NATURAL/USING join where 'this' is
3439  the right operand. After parsing (this->natural_join == this) iff
3440  'this' represents a NATURAL or USING join operation. Thus after
3441  parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
3442  */
3444  /*
3445  True if 'this' represents a nested join that is a NATURAL JOIN.
3446  For one of the operands of 'this', the member 'natural_join' points
3447  to the other operand of 'this'.
3448  */
3449  bool is_natural_join{false};
3450  /* Field names in a USING clause for JOIN ... USING. */
3452  /*
3453  Explicitly store the result columns of either a NATURAL/USING join or
3454  an operand of such a join.
3455  */
3457  /* true if join_columns contains all columns of this table reference. */
3459 
3460  /*
3461  List of nodes in a nested join tree, that should be considered as
3462  leaves with respect to name resolution. The leaves are: views,
3463  top-most nodes representing NATURAL/USING joins, subqueries, and
3464  base tables. All of these TABLE_LIST instances contain a
3465  materialized list of columns. The list is local to a subquery.
3466  */
3468  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
3470  TABLE *table{nullptr}; /* opened table */
3471  Table_id table_id{}; /* table id (from binlog) for opened table */
3472  /*
3473  Query_result for derived table to pass it from table creation to table
3474  filling procedure
3475  */
3477  /*
3478  Reference from aux_tables to local list entry of main select of
3479  multi-delete statement:
3480  delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
3481  here it will be reference of first occurrence of t1 to second (as you
3482  can see this lists can't be merged)
3483  */
3485 
3486  /*
3487  Holds the function used as the table function
3488  */
3490 
3491  /**
3492  If we've previously made an access path for “derived”, it is cached here.
3493  This is useful if we need to plan the query block twice (the hypergraph
3494  optimizer can do so, with and without in2exists predicates), both saving
3495  work and avoiding issues when we try to throw away the old items_to_copy
3496  for a new (identical) one.
3497  */
3499 
3500  private:
3501  /**
3502  This field is set to non-null for derived tables and views. It points
3503  to the Query_expression representing the derived table/view.
3504  E.g. for a query
3505  @verbatim SELECT * FROM (SELECT a FROM t1) b @endverbatim
3506  */
3507  Query_expression *derived{nullptr}; /* Query_expression of derived table */
3508 
3509  /// If non-NULL, the CTE which this table is derived from.
3511  /**
3512  If the user has specified column names with the syntaxes "table name
3513  parenthesis column names":
3514  WITH qn(column names) AS (select...)
3515  or
3516  FROM (select...) dt(column names)
3517  or
3518  CREATE VIEW v(column_names) AS ...
3519  then this points to the list of column names. NULL otherwise.
3520  */
3522 
3523  public:
3524  ST_SCHEMA_TABLE *schema_table{nullptr}; /* Information_schema table */
3526  /*
3527  True when the view field translation table is used to convert
3528  schema table fields for backwards compatibility with SHOW command.
3529  */
3532  /* link to query_block where this table was used */
3534 
3535  private:
3536  LEX *view{nullptr}; /* link on VIEW lex for merging */
3537 
3538  public:
3539  /// Array of selected expressions from a derived table or view.
3541 
3542  /// pointer to element after last one in translation table above
3544  /*
3545  List (based on next_local) of underlying tables of this view. I.e. it
3546  does not include the tables of subqueries used in the view. Is set only
3547  for merged views.
3548  */
3550  /*
3551  - 0 for base tables
3552  - in case of the view it is the list of all (not only underlying
3553  tables but also used in subquery ones) tables of the view.
3554  */
3556  /* most upper view this table belongs to */
3558  /*
3559  The view directly referencing this table
3560  (non-zero only for merged underlying tables of a view).
3561  */
3563  /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
3565  /*
3566  Security context (non-zero only for tables which belong
3567  to view with SQL SECURITY DEFINER)
3568  */
3570  /*
3571  This view security context (non-zero only for views with
3572  SQL SECURITY DEFINER)
3573  */
3575  /*
3576  List of all base tables local to a subquery including all view
3577  tables. Unlike 'next_local', this in this list views are *not*
3578  leaves. Created in setup_tables() -> make_leaf_tables().
3579  */
3581  Item *derived_where_cond{nullptr}; ///< WHERE condition from derived table
3582  Item *check_option{nullptr}; ///< WITH CHECK OPTION condition
3583  Item *replace_filter{nullptr}; ///< Filter for REPLACE command
3584  LEX_STRING select_stmt{nullptr, 0}; ///< text of (CREATE/SELECT) statement
3585  LEX_STRING source{nullptr, 0}; ///< source of CREATE VIEW
3586  LEX_STRING timestamp{nullptr, 0}; ///< GMT time stamp of last operation
3587  LEX_USER definer; ///< definer of view
3588  /**
3589  @note: This field is currently not reliable when read from dictionary:
3590  If an underlying view is changed, updatable_view is not changed,
3591  due to lack of dependency checking in dictionary implementation.
3592  Prefer to use is_updatable() during preparation and optimization.
3593  */
3594  ulonglong updatable_view{0}; ///< VIEW can be updated
3595  /**
3596  @brief The declared algorithm, if this is a view.
3597  @details One of
3598  - VIEW_ALGORITHM_UNDEFINED
3599  - VIEW_ALGORITHM_TEMPTABLE
3600  - VIEW_ALGORITHM_MERGE
3601  @todo Replace with an enum
3602  */
3604  ulonglong view_suid{0}; ///< view is suid (true by default)
3605  ulonglong with_check{0}; ///< WITH CHECK OPTION
3606  /**
3607  Context that is used to resolve a merged derived table's
3608  fields. Needed when a field from a merged derived table
3609  is cloned. Used during condition pushdown to derived tables.
3610  */
3612 
3613  private:
3614  /// The view algorithm that is actually used, if this is a view.
3617 
3618  public:
3620 
3621  public:
3622  /// True if right argument of LEFT JOIN; false in other cases (i.e. if left
3623  /// argument of LEFT JOIN, if argument of INNER JOIN; RIGHT JOINs are
3624  /// converted to LEFT JOIN during contextualization).
3625  bool outer_join{false};
3626  /// True if was originally the left argument of a RIGHT JOIN, before we
3627  /// made it the right argument of a LEFT JOIN.
3628  bool join_order_swapped{false};
3629  uint shared{0}; /* Used in multi-upd */
3630  size_t db_length{0};
3632 
3633  private:
3634  /// True if VIEW/TABLE is updatable, based on analysis of query (SQL rules).
3635  bool m_updatable{false};
3636  /// True if VIEW/TABLE is insertable, based on analysis of query (SQL rules).
3637  bool m_insertable{false};
3638  /// True if table is target of UPDATE statement, or updated in IODKU stmt.
3639  bool m_updated{false};
3640  /// True if table is target of INSERT statement.
3641  bool m_inserted{false};
3642  /// True if table is target of DELETE statement, or deleted in REPLACE stmt.
3643  bool m_deleted{false};
3644  bool m_fulltext_searched{false}; ///< True if fulltext searched
3645  public:
3646  bool straight{false}; /* optimize with prev table */
3647  /**
3648  True for tables and views being changed in a data change statement.
3649  Also true for tables subject to a SELECT ... FOR UPDATE.
3650  Also used by replication to filter out statements that can be ignored,
3651  especially important for multi-table UPDATE and DELETE.
3652  */
3653  bool updating{false};
3654  /// preload only non-leaf nodes (IS THIS USED???)
3655  bool ignore_leaves{false};
3656  /**
3657  The set of tables in the query block that this table depends on.
3658  Can be set due to outer join, join order hints or NOT EXISTS relationship.
3659  */
3661  /// The outer tables that an outer join's join condition depends on
3663  /**
3664  Is non-NULL if this table reference is a nested join, ie it represents
3665  the inner tables of an outer join, the tables contained in the
3666  parentheses of an inner join (eliminated during resolving), the tables
3667  referenced in a derived table or view, in a semi-join nest, the tables
3668  from the subquery.
3669  */
3671  /// The nested join containing this table reference.
3673  /// The join list immediately containing this table reference
3675  /// stop PS caching
3676  bool cacheable_table{false};
3677  /**
3678  Specifies which kind of table should be open for this element
3679  of table list.
3680  */
3682  /* true if this merged view contain auto_increment field */
3684  /// true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
3686  /// true <=> Filter condition is processed
3688 
3690  char timestamp_buffer[20]{0}; /* buffer for timestamp (19+1) */
3691  /*
3692  This TABLE_LIST object is just placeholder for prelocking, it will be
3693  used for implicit LOCK TABLES only and won't be used in real statement.
3694  */
3696  /**
3697  Indicates that if TABLE_LIST object corresponds to the table/view
3698  which requires special handling.
3699  */
3700  enum {
3701  /* Normal open. */
3703  /* Associate a table share only if the the table exists. */
3705  /*
3706  Associate a table share only if the the table exists.
3707  Also upgrade metadata lock to exclusive if table doesn't exist.
3708  */
3710  /* Don't associate a table share. */
3711  OPEN_STUB
3712  } open_strategy{OPEN_NORMAL};
3713  bool internal_tmp_table{false};
3714  /** true if an alias for this table was specified in the SQL. */
3715  bool is_alias{false};
3716  /** true if the table is referred to in the statement using a fully
3717  qualified name (@<db_name@>.@<table_name@>).
3718  */
3719  bool is_fqtn{false};
3720  /**
3721  If true, this table is a derived (materialized) table which was created
3722  from a scalar subquery, cf.
3723  Query_block::transform_scalar_subqueries_to_join_with_derived
3724  */
3726 
3727  /* View creation context. */
3728 
3730 
3731  /*
3732  Attributes to save/load view creation context in/from frm-file.
3733 
3734  They are required only to be able to use existing parser to load
3735  view-definition file. As soon as the parser parsed the file, view
3736  creation context is initialized and the attributes become redundant.
3737 
3738  These attributes MUST NOT be used for any purposes but the parsing.
3739  */
3740 
3743 
3744  /*
3745  View definition (SELECT-statement) in the UTF-form.
3746  */
3747 
3749 
3750  // True, If this is a system view
3751  bool is_system_view{false};
3752 
3753  /*
3754  Set to 'true' if this is a DD table being opened in the context of a
3755  dictionary operation. Note that when 'false', this may still be a DD
3756  table when opened in a non-DD context, e.g. as part of an I_S view
3757  query.
3758  */
3759  bool is_dd_ctx_table{false};
3760 
3761  /* End of view definition context. */
3762 
3763  /* List of possible keys. Valid only for materialized derived tables/views. */
3765 
3766  /**
3767  Indicates what triggers we need to pre-load for this TABLE_LIST
3768  when opening an associated TABLE. This is filled after
3769  the parsed tree is created.
3770  */
3773  bool has_db_lookup_value{false};
3776  bool schema_table_filled{false};
3777 
3779 
3780  /// if true, EXPLAIN can't explain view due to insufficient rights.
3781  bool view_no_explain{false};
3782 
3783  /* List to carry partition names from PARTITION (...) clause in statement */
3785 
3786  /// Set table number
3788  assert(tableno < MAX_TABLES);
3789  m_tableno = tableno;
3790  m_map = (table_map)1 << tableno;
3791  }
3792  /// Return table number
3793  uint tableno() const { return m_tableno; }
3794 
3795  /// Return table map derived from table number
3796  table_map map() const {
3797  assert(((table_map)1 << m_tableno) == m_map);
3798  return m_map;
3799  }
3800 
3801  /// If non-NULL, the CTE which this table is derived from.
3804  /// @see m_derived_column_names
3806  return m_derived_column_names;
3807  }
3810  }
3811 
3812  private:
3813  /*
3814  A group of members set and used only during JOIN::optimize().
3815  */
3816  /**
3817  Optimized copy of m_join_cond (valid for one single
3818  execution). Initialized by Query_block::get_optimizable_conditions().
3819  */
3821 
3822  public:
3823  COND_EQUAL *cond_equal{nullptr}; ///< Used with outer join
3824  /// true <=> this table is a const one and was optimized away.
3825 
3826  bool optimized_away{false};
3827  /**
3828  true <=> all possible keys for a derived table were collected and
3829  could be re-used while statement re-execution.
3830  */
3831 
3832  bool derived_keys_ready{false};
3833 
3834  private:
3835  /// If a recursive reference inside the definition of a CTE.
3837  // End of group for optimization
3838 
3839  /** See comments for set_metadata_id() */
3841  /** See comments for TABLE_SHARE::get_table_ref_version() */
3843 
3844  /*
3845  All members whose names are suffixed with "_saved" are duplicated in
3846  class TABLE but actually belong in this class. They are saved from class
3847  TABLE when preparing a statement and restored when executing the statement.
3848  They are not required for a regular (non-prepared) statement.
3849  */
3855  bool nullable_saved{false};
3856  bool force_index_saved{false};
3864 };
3865 
3866 /*
3867  Iterator over the fields of a generic table reference.
3868 */
3869 
3871  public:
3872  virtual ~Field_iterator() = default;
3873  virtual void set(TABLE_LIST *) = 0;
3874  virtual void next() = 0;
3875  virtual bool end_of_fields() = 0; /* Return 1 at end of list */
3876  virtual const char *name() = 0;
3877  virtual Item *create_item(THD *) = 0;
3878  virtual Field *field() = 0;
3879 };
3880 
3881 /*
3882  Iterator over the fields of a base table, view with temporary
3883  table, or subquery.
3884 */
3885 
3888 
3889  public:
3891  void set(TABLE_LIST *table) override { ptr = table->table->field; }
3892  void set_table(TABLE *table) { ptr = table->field; }
3893  void next() override { ptr++; }
3894  bool end_of_fields() override { return *ptr == nullptr; }
3895  const char *name() override;
3896  Item *create_item(THD *thd) override;
3897  Field *field() override { return *ptr; }
3898 };
3899 
3900 /**
3901  Iterator over the fields of a merged derived table or view.
3902 */
3903 
3907 
3908  public:
3910  void set(TABLE_LIST *table) override;
3911  void next() override { ptr++; }
3912  bool end_of_fields() override { return ptr == array_end; }
3913  const char *name() override;
3914  Item *create_item(THD *thd) override;
3915  Item **item_ptr() { return &ptr->item; }
3916  Field *field() override { return nullptr; }
3917  inline Item *item() { return ptr->item; }
3919 };
3920 
3921 /*
3922  Field_iterator interface to the list of materialized fields of a
3923  NATURAL/USING join.
3924 */
3925 
3929 
3930  public:
3932  ~Field_iterator_natural_join() override = default;
3933  void set(TABLE_LIST *table) override;
3934  void next() override;
3935  bool end_of_fields() override { return !cur_column_ref; }
3936  const char *name() override { return cur_column_ref->name(); }
3937  Item *create_item(THD *thd) override {
3938  return cur_column_ref->create_item(thd);
3939  }
3940  Field *field() override { return cur_column_ref->field(); }
3942 };
3943 
3944 /**
3945  Generic iterator over the fields of an arbitrary table reference.
3946 
3947  This class unifies the various ways of iterating over the columns
3948  of a table reference depending on the type of SQL entity it
3949  represents. If such an entity represents a nested table reference,
3950  this iterator encapsulates the iteration over the columns of the
3951  members of the table reference.
3952 
3953  The implementation assumes that all underlying NATURAL/USING table
3954  references already contain their result columns and are linked into
3955  the list TABLE_LIST::next_name_resolution_table.
3956 */
3957 
3964  void set_field_iterator();
3965 
3966  public:
3968  void set(TABLE_LIST *table) override;
3969  void next() override;
3970  bool end_of_fields() override {
3971  return (table_ref == last_leaf && field_it->end_of_fields());
3972  }
3973  const char *name() override { return field_it->name(); }
3974  const char *get_table_name();
3975  const char *get_db_name();
3976  GRANT_INFO *grant();
3977  Item *create_item(THD *thd) override { return field_it->create_item(thd); }
3978  Field *field() override { return field_it->field(); }
3980  TABLE_LIST *parent_table_ref);
3982 };
3983 
3986  char *db, *table;
3988 };
3989 
3991  MY_BITMAP *bitmap) {
3992  my_bitmap_map *old = bitmap->bitmap;
3993  bitmap->bitmap = table->s->all_set.bitmap; // does not repoint last_word_ptr
3994  return old;
3995 }
3996 
3997 static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
3998  my_bitmap_map *old) {
3999  bitmap->bitmap = old;
4000 }
4001 
4002 /* The following is only needed for debugging */
4003 
4005  [[maybe_unused]],
4006  MY_BITMAP *bitmap
4007  [[maybe_unused]]) {
4008 #ifndef NDEBUG
4009  return tmp_use_all_columns(table, bitmap);
4010 #else
4011  return nullptr;
4012 #endif
4013 }
4014 
4015 static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap
4016  [[maybe_unused]],
4017  my_bitmap_map *old
4018  [[maybe_unused]]) {
4019 #ifndef NDEBUG
4020  tmp_restore_column_map(bitmap, old);
4021 #endif
4022 }
4023 
4024 /*
4025  Variant of the above : handle both read and write sets.
4026  Provide for the possiblity of the read set being the same as the write set
4027 */
4028 static inline void dbug_tmp_use_all_columns(
4029  TABLE *table [[maybe_unused]], my_bitmap_map **save [[maybe_unused]],
4030  MY_BITMAP *read_set [[maybe_unused]],
4031  MY_BITMAP *write_set [[maybe_unused]]) {
4032 #ifndef NDEBUG
4033  save[0] = read_set->bitmap;
4034  save[1] = write_set->bitmap;
4035  (void)tmp_use_all_columns(table, read_set);
4036  (void)tmp_use_all_columns(table, write_set);
4037 #endif
4038 }
4039 
4040 static inline void dbug_tmp_restore_column_maps(
4041  MY_BITMAP *read_set [[maybe_unused]], MY_BITMAP *write_set [[maybe_unused]],
4042  my_bitmap_map **old [[maybe_unused]]) {
4043 #ifndef NDEBUG
4044  tmp_restore_column_map(read_set, old[0]);
4045  tmp_restore_column_map(write_set, old[1]);
4046 #endif
4047 }
4048 
4049 void init_mdl_requests(TABLE_LIST *table_list);
4050 
4051 /**
4052  Unpacks the definition of a generated column, default expression or check
4053  constraint expression passed as argument. Parses the text obtained from
4054  TABLE_SHARE and produces an Item.
4055 
4056  @param thd Thread handler
4057  @param table Table with the checked field
4058  @param val_generator The expression to unpack.
4059  @param source Source of value generator(a generated column,
4060  a regular column with generated default value or
4061  a check constraint).
4062  @param source_name Name of the source (generated column, a reguler
4063  column with generated default value or a check
4064  constraint).
4065  @param field Pointer to Field object
4066  @param is_create_table Indicates that table is opened as part
4067  of CREATE or ALTER and does not yet exist in SE
4068  @param error_reported updated flag for the caller that no other error
4069  messages are to be generated.
4070 
4071  @retval true Failure.
4072  @retval false Success.
4073 */
4074 
4075 bool unpack_value_generator(THD *thd, TABLE *table,
4076  Value_generator **val_generator,
4078  const char *source_name, Field *field,
4079  bool is_create_table, bool *error_reported);
4080 
4081 /**
4082  Unpack the partition expression. Parse the partition expression
4083  to produce an Item.
4084 
4085  @param[in] thd Thread handler
4086  @param[in] outparam Table object
4087  @param[in] share TABLE_SHARE object
4088  @param[in] engine_type Engine type of the partitions.
4089  @param[in] is_create_table Indicates that table is opened as part of
4090  CREATE or ALTER and does not yet exist in SE
4091 
4092  @retval true Failure.
4093  @retval false Success.
4094 */
4095 
4096 bool unpack_partition_info(THD *thd, TABLE *outparam, TABLE_SHARE *share,
4097  handlerton *engine_type, bool is_create_table);
4098 
4099 int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
4100  uint db_stat, uint prgflag, uint ha_open_flags,
4101  TABLE *outparam, bool is_create_table,
4102  const dd::Table *table_def_param);
4103 TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
4104  const char *key, size_t key_length,
4105  bool open_secondary);
4106 void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
4107  size_t key_length, const char *table_name,
4108  const char *path, MEM_ROOT *mem_root);
4109 void free_table_share(TABLE_SHARE *share);
4111 Ident_name_check check_db_name(const char *name, size_t length);
4113  bool preserve_lettercase);
4114 bool check_column_name(const char *name);
4115 Ident_name_check check_table_name(const char *name, size_t length);
4116 int rename_file_ext(const char *from, const char *to, const char *ext);
4117 char *get_field(MEM_ROOT *mem, Field *field);
4118 bool get_field(MEM_ROOT *mem, Field *field, class String *res);
4119 
4120 int closefrm(TABLE *table, bool free_share);
4121 void free_blobs(TABLE *table);
4122 void free_blob_buffers_and_reset(TABLE *table, uint32 size);
4123 int set_zone(int nr, int min_zone, int max_zone);
4124 void append_unescaped(String *res, const char *pos, size_t length);
4125 char *fn_rext(char *name);
4127  const LEX_CSTRING &name);
4128 
4129 /* performance schema */
4131 
4133 extern LEX_CSTRING SLOW_LOG_NAME;
4134 
4135 /* information schema */
4137 
4138 /* mysql schema name and DD ID */
4140 static const uint MYSQL_SCHEMA_DD_ID = 1;
4141 
4142 /* mysql tablespace name and DD ID */
4144 static const uint MYSQL_TABLESPACE_DD_ID = 1;
4145 
4146 /* replication's tables */
4147 extern LEX_CSTRING RLI_INFO_NAME;
4148 extern LEX_CSTRING MI_INFO_NAME;
4150 
4151 inline bool is_infoschema_db(const char *name, size_t len) {
4152  return (
4155 }
4156 
4157 inline bool is_infoschema_db(const char *name) {
4159 }
4160 
4161 inline bool is_perfschema_db(const char *name, size_t len) {
4162  return (PERFORMANCE_SCHEMA_DB_NAME.length == len &&
4164  name));
4165 }
4166 
4167 inline bool is_perfschema_db(const char *name) {
4169  name);
4170 }
4171 
4172 /**
4173  Check if the table belongs to the P_S, excluding setup and threads tables.
4174 
4175  @note Performance Schema tables must be accessible independently of the
4176  LOCK TABLE mode. This function is needed to handle the special case
4177  of P_S tables being used under LOCK TABLE mode.
4178 */
4179 inline bool belongs_to_p_s(TABLE_LIST *tl) {
4180  return (!strcmp("performance_schema", tl->db) &&
4181  strcmp(tl->table_name, "threads") &&
4182  strstr(tl->table_name, "setup_") == nullptr);
4183 }
4184 
4185 /**
4186  return true if the table was created explicitly.
4187 */
4188 inline bool is_user_table(TABLE *table) {
4189  const char *name = table->s->table_name.str;
4190  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
4191 }
4192 
4193 bool is_simple_order(ORDER *order);
4194 
4195 uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n,
4196  TABLE_SHARE *share, handler *handler_file,
4197  uint *usable_parts, bool use_extended_sk);
4198 void setup_key_part_field(TABLE_SHARE *share, handler *handler_file,
4199  uint primary_key_n, KEY *keyinfo, uint key_n,
4200  uint key_part_n, uint *usable_parts,
4201  bool part_of_key_not_extended);
4202 
4203 const uchar *get_field_name(const uchar *arg, size_t *length);
4204 
4205 void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec);
4206 bool update_generated_write_fields(const MY_BITMAP *bitmap, TABLE *table);
4208  uint active_index = MAX_KEY);
4209 
4210 /**
4211  Check if a TABLE_LIST instance represents a pre-opened temporary table.
4212 */
4213 
4214 inline bool is_temporary_table(const TABLE_LIST *tl) {
4215  if (tl->is_view() || tl->schema_table) return false;
4216 
4217  if (!tl->table) return false;
4218 
4219  /*
4220  NOTE: 'table->s' might be NULL for specially constructed TABLE
4221  instances. See SHOW TRIGGERS for example.
4222  */
4223 
4224  if (!tl->table->s) return false;
4225 
4226  return tl->table->s->tmp_table != NO_TMP_TABLE;
4227 }
4228 
4229 /**
4230  After parsing, a Common Table Expression is accessed through a
4231  TABLE_LIST. This class contains all information about the CTE which the
4232  TABLE_LIST needs.
4233 
4234  @note that before and during parsing, the CTE is described by a
4235  PT_common_table_expr.
4236 */
4238  public:
4241  TABLE *clone_tmp_table(THD *thd, TABLE_LIST *tl);
4243  /// Remove one table reference.
4244  void remove_table(TABLE_LIST *tr);
4245  /// Empties the materialized CTE and informs all of its clones.
4246  bool clear_all_references();
4247  /**
4248  All references to this CTE in the statement, except those inside the
4249  query expression defining this CTE.
4250  In other words, all non-recursive references.
4251  */
4253  /// True if it's a recursive CTE
4255  /**
4256  List of all TABLE_LISTSs reading/writing to the tmp table created to
4257  materialize this CTE. Due to shared materialization, only the first one
4258  has a TABLE generated by create_tmp_table(); other ones have a TABLE
4259  generated by open_table_from_share().
4260  */
4262  /// Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
4264 };
4265 
4266 /**
4267  This iterates on those references to a derived table / view / CTE which are
4268  materialized. If a recursive CTE, this includes recursive references.
4269  Upon construction it is passed a non-recursive materialized reference
4270  to the derived table (TABLE_LIST*).
4271  For a CTE it may return more than one reference; for a derived table or a
4272  view, there is only one (as references to a same view are treated as
4273  independent objects).
4274  References are returned as TABLE*.
4275 */
4277  TABLE_LIST *const start; ///< The reference provided in construction.
4278  size_t ref_idx{0}; ///< Current index in cte->tmp_tables
4279  bool m_is_first{true}; ///< True when at first reference in list
4280  public:
4281  explicit Derived_refs_iterator(TABLE_LIST *start_arg) : start(start_arg) {}
4283  const Common_table_expr *cte = start->common_table_expr();
4284  m_is_first = ref_idx == 0;
4285  // Derived tables and views have a single reference.
4286  if (cte == nullptr) {
4287  return ref_idx++ == 0 ? start->table : nullptr;
4288  }
4289  /*
4290  CTEs may have multiple references. Return the next one, but notice that
4291  some references may have been deleted.
4292  */
4293  while (ref_idx < cte->tmp_tables.size()) {
4294  TABLE *table = cte->tmp_tables[ref_idx++]->table;
4295  if (table != nullptr) return table;
4296  }
4297  return nullptr;
4298  }
4299  void rewind() {
4300  ref_idx = 0;
4301  m_is_first = true;
4302  }
4303  /// @returns true if the last get_next() returned the first element.
4304  bool is_first() const {
4305  // Call after get_next() has been called:
4306  assert(ref_idx > 0);
4307  return m_is_first;
4308  }
4309 };
4310 
4311 /**
4312  RAII class to reset TABLE::autoinc_field_has_explicit_non_null_value after
4313  processing individual row in INSERT or LOAD DATA statements.
4314 */
4316  public:
4318  : m_table(table) {}
4321  }
4322 
4323  private:
4325 };
4326 
4327 // Whether we can ask the storage engine for the row ID of the last row read.
4328 //
4329 // Some operations needs a row ID to operate correctly (i.e. weedout). Normally,
4330 // the row ID is provided by the storage engine by calling handler::position().
4331 // But there are cases when position() should not be called:
4332 //
4333 // 1. If we have a const table (rows are fetched during optimization), we
4334 // should not call position().
4335 // 2. If we have a NULL-complemented row, calling position() would give a
4336 // random row ID back, as there has not been any row read.
4337 //
4338 // Operations that needs the row ID must also check the value of
4339 // QEP_TAB::rowid_status to see whether they actually need a row ID.
4340 // See QEP_TAB::rowid_status for more details.
4341 inline bool can_call_position(const TABLE *table) {
4342  return !table->const_table && !(table->is_nullable() && table->null_row);
4343 }
4344 
4345 //////////////////////////////////////////////////////////////////////////
4346 
4347 /*
4348  NOTE:
4349  These structures are added to read .frm file in upgrade scenario.
4350 
4351  They should not be used any where else in the code.
4352  They will be removed in future release.
4353  Any new code should not be added in this section.
4354 */
4355 
4356 /**
4357  These members were removed from TABLE_SHARE as they are not used in
4358  in the code. open_binary_frm() uses these members while reading
4359  .frm files.
4360 */
4362  public:
4365  null_field_first(false),
4366  stored_fields(0),
4367  view_def(nullptr),
4368  frm_version(0),
4369  fieldnames() {}
4370 
4373  uint stored_fields; /* Number of stored fields
4374  (i.e. without generated-only ones) */
4375 
4376  enum utype {
4389  EMPTY_VAL, // EMPTY_VAL rather than EMPTY since EMPTY can conflict with
4390  // system headers.
4402  GENERATED_FIELD = 128
4403  };
4404 
4405  /**
4406  For shares representing views File_parser object with view
4407  definition read from .FRM file.
4408  */
4411  TYPELIB fieldnames; /* Pointer to fieldnames */
4412 };
4413 
4414 /**
4415  Create TABLE_SHARE from .frm file.
4416 
4417  FRM_context object is used to store the value removed from
4418  TABLE_SHARE. These values are used only for .frm file parsing.
4419 
4420  @param[in] thd Thread handle.
4421  @param[in] path Path of the frm file.
4422  @param[out] share TABLE_SHARE to be populated.
4423  @param[out] frm_context FRM_context object.
4424  @param[in] db Database name.
4425  @param[in] table Table name.
4426  @param[in] is_fix_view_cols_and_deps Fix view column data, table
4427  and routine dependency.
4428 
4429  @retval TABLE_SHARE ON SUCCESS
4430  @retval NULL ON FAILURE
4431 */
4432 bool create_table_share_for_upgrade(THD *thd, const char *path,
4433  TABLE_SHARE *share,
4434  FRM_context *frm_context, const char *db,
4435  const char *table,
4436  bool is_fix_view_cols_and_deps);
4437 //////////////////////////////////////////////////////////////////////////
4438 
4439 /**
4440  Create a copy of the key_info from TABLE_SHARE object to TABLE object.
4441 
4442  Wherever prefix key is present, allocate a new Field object, having its
4443  field_length set to the prefix key length, and point the table's matching
4444  key_part->field to this new Field object.
4445 
4446  This ensures that unpack_partition_info() reads the correct prefix length of
4447  partitioned fields
4448 
4449  @param table Table for which key_info is to be allocated
4450  @param root MEM_ROOT in which to allocate key_info
4451 
4452  @retval false Success
4453  @retval true Failed to allocate memory for table.key_info in root
4454 */
4455 
4457 
4458 #endif /* TABLE_INCLUDED */
int64 query_id_t
Definition: binlog.h:70
Per internal schema ACL access rules.
Definition: auth_common.h:137
Per internal table ACL access rules.
Definition: auth_common.h:102
RAII class to reset TABLE::autoinc_field_has_explicit_non_null_value after processing individual row ...
Definition: table.h:4315
Autoinc_field_has_explicit_non_null_value_reset_guard(TABLE *table)
Definition: table.h:4317
~Autoinc_field_has_explicit_non_null_value_reset_guard()
Definition: table.h:4319
Class that represents a single change to a column value in partial update of a JSON column.
Definition: table.h:1311
const char * old_data(const Field *field) const
Get a pointer to the start of the old data to be replaced.
Definition: table.cc:7635
size_t length() const
Definition: table.h:1332
size_t m_length
The size of the portion that is to be replaced.
Definition: table.h:1316
const char * new_data(const Field *field) const
Get a pointer to the start of the replacement data.
Definition: table.cc:7626
Binary_diff(size_t offset, size_t length)
Create a new Binary_diff object.
Definition: table.h:1325
size_t m_offset
The offset of the start of the change.
Definition: table.h:1313
size_t offset() const
Definition: table.h:1329
Definition: sql_bitmap.h:137
Class is used as a BLOB field value storage for intermediate GROUP_CONCAT results.
Definition: table.h:1271
bool truncated_value
Sign that some values were cut during saving into the storage.
Definition: table.h:1278
char * store(const char *from, size_t length)
Fuction creates duplicate of 'from' string in 'storage' MEM_ROOT.
Definition: table.h:1298
Blob_mem_storage()
Definition: table.cc:4045
void reset()
Definition: table.h:1284
void set_truncated_value(bool is_truncated_value)
Definition: table.h:1301
MEM_ROOT storage
Definition: table.h:1273
~Blob_mem_storage()
Definition: table.cc:4049
bool is_truncated_value() const
Definition: table.h:1304
Definition: item_cmpfunc.h:2609
After parsing, a Common Table Expression is accessed through a TABLE_LIST.
Definition: table.h:4237
void remove_table(TABLE_LIST *tr)
Remove one table reference.
Definition: sql_derived.cc:243
Common_table_expr(MEM_ROOT *mem_root)
Definition: table.h:4239
LEX_STRING name
Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
Definition: table.h:4263
TABLE * clone_tmp_table(THD *thd, TABLE_LIST *tl)
Produces, from the first tmp TABLE object, a clone TABLE object for TABLE_LIST 'tl',...
Definition: sql_derived.cc:170
bool clear_all_references()
Empties the materialized CTE and informs all of its clones.
Definition: sql_union.cc:1110
Mem_root_array< TABLE_LIST * > tmp_tables
List of all TABLE_LISTSs reading/writing to the tmp table created to materialize this CTE.
Definition: table.h:4261
bool recursive
True if it's a recursive CTE.
Definition: table.h:4254
Mem_root_array< TABLE_LIST * > references
All references to this CTE in the statement, except those inside the query expression defining this C...
Definition: table.h:4252
bool substitute_recursive_reference(THD *thd, Query_block *sl)
Replaces the recursive reference in query block 'sl' with a clone of the first tmp table.
Definition: sql_derived.cc:230
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:41
API for getting cost estimates for operations on table data.
Definition: opt_costmodel.h:229
void init(const Cost_model_server *cost_model_server, const TABLE *table)
Initializes the cost model object.
Definition: opt_costmodel.cc:60
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:218
void change_env(THD *thd) const override
Definition: table.cc:209
void delete_backup_ctx() override
Definition: table.cc:207
Default_object_creation_ctx(THD *thd)
Definition: table.cc:194
Object_creation_ctx * create_backup_ctx(THD *thd) const override
Definition: table.cc:202
const CHARSET_INFO * get_connection_cl()
Definition: table.h:222
const CHARSET_INFO * m_connection_cl
connection_cl stores the value of collation_connection session variable.
Definition: table.h:256
const CHARSET_INFO * get_client_cs()
Definition: table.h:220
const CHARSET_INFO * m_client_cs
client_cs stores the value of character_set_client session variable.
Definition: table.h:246
This structure is used to keep info about possible key for the result table of a derived table/view.
Definition: table.h:2652
table_map referenced_by
Definition: table.h:2654
Field_map used_fields
Definition: table.h:2655
uint key_part_count
Definition: table.h:2656
This iterates on those references to a derived table / view / CTE which are materialized.
Definition: table.h:4276
bool is_first() const
Definition: table.h:4304
Derived_refs_iterator(TABLE_LIST *start_arg)
Definition: table.h:4281
TABLE * get_next()
Definition: table.h:4282
TABLE_LIST *const start
The reference provided in construction.
Definition: table.h:4277
bool m_is_first
True when at first reference in list.
Definition: table.h:4279
size_t ref_idx
Current index in cte->tmp_tables.
Definition: table.h:4278
void rewind()
Definition: table.h:4299
These members were removed from TABLE_SHARE as they are not used in in the code.
Definition: table.h:4361
utype
Definition: table.h:4376
@ CASEUP
Definition: table.h:4381
@ NO
Definition: table.h:4386
@ NONE
Definition: table.h:4377
@ REL
Definition: table.h:4387
@ NEXT_NUMBER
Definition: table.h:4393
@ DATE
Definition: table.h:4378
@ PNR
Definition: table.h:4382
@ BIT_FIELD
Definition: table.h:4395
@ TIMESTAMP_OLD_FIELD
Definition: table.h:4396
@ GENERATED_FIELD
Definition: table.h:4402
@ INTERVAL_FIELD
Definition: table.h:4394
@ TIMESTAMP_UN_FIELD
Definition: table.h:4400
@ NOEMPTY
Definition: table.h:4380
@ CHECK
Definition: table.h:4388
@ YES
Definition: table.h:4385
@ TIMESTAMP_DNUN_FIELD
Definition: table.h:4401
@ BLOB_FIELD
Definition: table.h:4398
@ UNKNOWN_FIELD
Definition: table.h:4391
@ CASEDN
Definition: table.h:4392
@ TIMESTAMP_DN_FIELD
Definition: table.h:4399
@ PGNR
Definition: table.h:4384
@ EMPTY_VAL
Definition: table.h:4389
@ CAPITALIZE
Definition: table.h:4397
@ SHIELD
Definition: table.h:4379
@ BGNR
Definition: table.h:4383
bool null_field_first
Definition: table.h:4372
uchar frm_version
Definition: table.h:4410
handlerton * default_part_db_type
Definition: table.h:4371
TYPELIB fieldnames
Definition: table.h:4411
const File_parser * view_def
For shares representing views File_parser object with view definition read from .FRM file.
Definition: table.h:4409
uint stored_fields
Definition: table.h:4373
FRM_context()
Definition: table.h:4363
Definition: table.h:3926
~Field_iterator_natural_join() override=default
void set(TABLE_LIST *table) override
Definition: table.cc:5146
Field * field() override
Definition: table.h:3940
void next() override
Definition: table.cc:5152
Natural_join_column * cur_column_ref
Definition: table.h:3928
const char * name() override
Definition: table.h:3936
Field_iterator_natural_join()
Definition: table.h:3931
Item * create_item(THD *thd) override
Definition: table.h:3937
List_iterator_fast< Natural_join_column > column_ref_it
Definition: table.h:3927
bool end_of_fields() override
Definition: table.h:3935
Natural_join_column * column_ref()
Definition: table.h:3941
Generic iterator over the fields of an arbitrary table reference.
Definition: table.h:3958
const char * name() override
Definition: table.h:3973
Natural_join_column * get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref)
Create new or return existing column reference to a column of a natural/using join.
Definition: table.cc:5293
Field_iterator * field_it
Definition: table.h:3963
Field_iterator_view view_field_it
Definition: table.h:3961
const char * get_table_name()
Definition: table.cc:5225
const char * get_db_name()
Definition: table.cc:5232
Field_iterator_table_ref()
Definition: table.h:3967
TABLE_LIST * first_leaf
Definition: table.h:3959
Item * create_item(THD *thd) override
Definition: table.h:3977
GRANT_INFO * grant()
Definition: table.cc:5252
void next() override
Definition: table.cc:5211
Field * field() override
Definition: table.h:3978
void set(TABLE_LIST *table) override
Definition: table.cc:5202
Field_iterator_table table_field_it
Definition: table.h:3960
TABLE_LIST * last_leaf
Definition: table.h:3959
Natural_join_column * get_natural_column_ref()
Return an existing reference to a column of a natural/using join.
Definition: table.cc:5373
void set_field_iterator()
Definition: table.cc:5159
TABLE_LIST * table_ref
Definition: table.h:3959
bool end_of_fields() override
Definition: table.h:3970
Field_iterator_natural_join natural_join_it
Definition: table.h:3962
Definition: table.h:3886
const char * name() override
Definition: table.cc:5066
Field * field() override
Definition: table.h:3897
Field ** ptr
Definition: table.h:3887
void set(TABLE_LIST *table) override
Definition: table.h:3891
Item * create_item(THD *thd) override
Definition: table.cc:5068
void set_table(TABLE *table)
Definition: table.h:3892
void next() override
Definition: table.h:3893
Field_iterator_table()
Definition: table.h:3890
bool end_of_fields() override
Definition: table.h:3894
Iterator over the fields of a merged derived table or view.
Definition: table.h:3904
void next() override
Definition: table.h:3911
Item * item()
Definition: table.h:3917
TABLE_LIST * view
Definition: table.h:3906
Field_iterator_view()
Definition: table.h:3909
void set(TABLE_LIST *table) override
Definition: table.cc:5059
Field_translator * field_translator()
Definition: table.h:3918
Field_translator * array_end
Definition: table.h:3905
Field * field() override
Definition: table.h:3916
Item ** item_ptr()
Definition: table.h:3915
Item * create_item(THD *thd) override
Definition: table.cc:5086
const char * name() override
Definition: table.cc:5084
Field_translator * ptr
Definition: table.h:3905
bool end_of_fields() override
Definition: table.h:3912
Definition: table.h:3870
virtual Item * create_item(THD *)=0
virtual void next()=0
virtual ~Field_iterator()=default
virtual Field * field()=0
virtual const char * name()=0
virtual bool end_of_fields()=0
virtual void set(TABLE_LIST *)=0
A field that stores a JSON value.
Definition: field.h:3941
Definition: field.h:590
Definition: parse_file.h:86
Definition: sql_auth_cache.h:466
Base class to be used by handlers different shares.
Definition: handler.h:3673
Intrusive parameterized list.
Definition: sql_plist.h:74
Definition: sql_lex.h:487
Definition: item.h:4027
A wrapper Item that normally returns its parameter, but becomes NULL when processing rows for rollup.
Definition: item_func.h:1578
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
Query optimization plan node.
Definition: sql_select.h:597
Vector of logical diffs describing changes to a JSON column.
Definition: json_diff.h:137
A path expression which can be used to seek to a position inside a JSON value.
Definition: json_path.h:299
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1167
Definition: key.h:56
Definition: key.h:112
ulong flags
dupp key and pack flags
Definition: key.h:117
Context of the owner of metadata locks.
Definition: mdl.h:1407
A pending metadata lock request.
Definition: mdl.h:798
void set_type(enum_mdl_type type_arg)
Set type of lock request.
Definition: mdl.h:849
A granted metadata lock.
Definition: mdl.h:980
An abstract class for inspection of a connected subgraph of the wait-for graph.
Definition: mdl.h:915
Abstract class representing an edge in the waiters graph to be traversed by deadlock detection algori...
Definition: mdl.h:941
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:418
Definition: table.h:2418
Item * create_item(THD *thd)
Definition: table.cc:5019
Item_field * table_field
Definition: table.h:2421
Field_translator * view_field
Definition: table.h:2420
const char * name()
Definition: table.cc:5010
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab)
Definition: table.cc:4987
bool is_common
Definition: table.h:2430
const char * db_name()
Definition: table.cc:5043
GRANT_INFO * grant()
Definition: table.cc:5057
Field * field()
Definition: table.cc:5030
const char * table_name()
Definition: table.cc:5038
TABLE_LIST * table_ref
Definition: table.h:2422
Object_creation_ctx – interface for creation context of database objects (views, stored routines,...
Definition: table.h:194
void restore_env(THD *thd, Object_creation_ctx *backup_ctx)
Definition: table.cc:182
Object_creation_ctx()=default
virtual Object_creation_ctx * create_backup_ctx(THD *thd) const =0
virtual void change_env(THD *thd) const =0
virtual void delete_backup_ctx()=0
virtual ~Object_creation_ctx()=default
Object_creation_ctx * set_n_backup(THD *thd)
Definition: table.cc:172
Query block level hints.
Definition: opt_hints.h:371
Table level hints.
Definition: opt_hints.h:548
Definition: sql_executor.h:256
uint index() const
Definition: sql_opt_exec_shared.h:511
TABLE * table() const
Definition: sql_opt_exec_shared.h:493
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1123
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:629
Definition: sql_union.h:39
This class represents a buffer that can be used for multi-row reads.
Definition: record_buffer.h:46
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:53
Definition: sql_sort.h:144
An adapter that takes in another RowIterator and produces the same rows, just in sorted order.
Definition: sorting_iterator.h:55
Class to represent check constraint in the TABLE_SHARE.
Definition: sql_check_constraint.h:109
Class to represent check constraint in the TABLE instance.
Definition: sql_check_constraint.h:144
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Element that represents the table in the specific table cache.
Definition: table_cache.h:228
Definition: table.h:593
Table_check_intact()
Definition: table.h:599
bool has_keys
Definition: table.h:595
virtual void report_error(uint code, const char *fmt,...)=0
bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def)
Checks whether a table is intact.
Definition: table.cc:3702
virtual ~Table_check_intact()=default
Class representing a table function.
Definition: table_function.h:52
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:39
This class holds all information about triggers of a table.
Definition: table_trigger_dispatcher.h:63
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:98
Used for storing information associated with generated column, default values generated from expressi...
Definition: field.h:481
View_creation_ctx – creation context of view objects.
Definition: table.h:263
static View_creation_ctx * create(THD *thd)
Definition: table.cc:220
View_creation_ctx(THD *thd)
Definition: table.h:270
Class representing the fact that some thread waits for table share to be flushed.
Definition: table.h:623
MDL_context * m_ctx
Definition: table.h:624
Wait_for_flush ** prev_in_share
Definition: table.h:645
Wait_for_flush * next_in_share
Pointers for participating in the list of waiters for table share.
Definition: table.h:644
TABLE_SHARE * m_share
Definition: table.h:625
uint m_deadlock_weight
Definition: table.h:626
bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor) override
Traverse portion of wait-for graph which is reachable through edge represented by this flush ticket i...
Definition: table.cc:3840
MDL_context * get_ctx() const
Definition: table.h:635
Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg, uint deadlock_weight_arg)
Definition: table.h:629
uint get_deadlock_weight() const override
Definition: table.cc:3844
void clear()
Definition: sql_list.h:141
enum_rule
Definition: foreign_key.h:53
Definition: table.h:46
Definition: view.h:38
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4131
enum handler::@45 inited
@ NONE
Definition: handler.h:4217
Histogram base class.
Definition: histogram.h:136
Definition: partition_info.h:208
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Dialog Client Authentication nullptr
Definition: dialog.cc:352
char * pos
Definition: do_ctype.cc:76
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
This file contains the field type.
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
void * memdup_root(MEM_ROOT *root, const void *str, size_t len)
Definition: my_alloc.cc:287
struct PSI_table_share PSI_table_share
Definition: psi_table_bits.h:99
static void free_share(st_blackhole_share *share)
Definition: ha_blackhole.cc:281
static int flag
Definition: hp_test1.cc:39
static uint keys
Definition: hp_test2.cc:45
enum_json_diff_operation
Enum that describes what kind of operation a Json_diff object represents.
Definition: json_diff.h:51
float rec_per_key_t
Data type for records per key estimates that are stored in the KEY::rec_per_key_float[] array.
Definition: key.h:95
enum_order
Definition: key_spec.h:64
@ ORDER_NOT_RELEVANT
Definition: key_spec.h:64
constexpr const LEX_CSTRING EMPTY_CSTR
Definition: lex_string.h:46
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:45
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1512
#define my_strcasecmp(s, a, b)
Definition: m_ctype.h:677
#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5)
Definition: mdl.h:901
@ MDL_TRANSACTION
Locks with transaction duration are automatically released at the end of transaction.
Definition: mdl.h:342
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:195
@ MDL_SHARED_WRITE
Definition: mdl.h:268
@ MDL_SHARED_WRITE_LOW_PRIO
Definition: mdl.h:274
@ MDL_SHARED_READ
Definition: mdl.h:258
static MI_KEYDEF keyinfo[10]
Definition: mi_test1.cc:46
static uint key_length
Definition: mi_test1.cc:42
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
#define HA_VIRTUAL_GEN_KEY
Set if a key is on any virtual generated columns.
Definition: my_base.h:551
ulong key_part_map
Definition: my_base.h:1006
my_off_t ha_rows
Definition: my_base.h:1138
ha_storage_media
Definition: my_base.h:114
@ HA_SM_DEFAULT
Definition: my_base.h:115
uint32 my_bitmap_map
Definition: my_bitmap.h:39
#define bitmap_buffer_size(bits)
Definition: my_bitmap.h:71
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint8_t uint8
Definition: my_inttypes.h:62
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
int8_t int8
Definition: my_inttypes.h:61
uint16_t uint16
Definition: my_inttypes.h:64
uint32_t uint32
Definition: my_inttypes.h:66
Common header for many mysys elements.
uint64_t table_map
Definition: my_table_map.h:29
#define NAME_CHAR_LEN
Field/table name length.
Definition: mysql_com.h:59
ABI for instrumented mutexes.
Log info(cout, "NOTE")
static char * path
Definition: mysqldump.cc:130
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1056
Definition: buf0block_hint.cc:29
const std::string charset("charset")
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
enum_table_type
Definition: abstract_table.h:52
Definition: os0file.h:85