MySQL  8.0.17
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, 2019, Oracle and/or its affiliates. All rights reserved.
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 <string.h>
27 #include <sys/types.h>
28 #include <string>
29 
30 #include "field_types.h"
31 #include "lex_string.h"
32 #include "m_ctype.h"
33 #include "map_helpers.h"
34 #include "my_alloc.h"
35 #include "my_base.h"
36 #include "my_bitmap.h"
37 #include "my_compiler.h"
38 #include "my_dbug.h"
39 #include "my_inttypes.h"
40 #include "my_sys.h"
41 #include "my_table_map.h"
44 #include "sql/dd/types/foreign_key.h" // dd::Foreign_key::enum_rule
45 #include "sql/enum_query_type.h" // enum_query_type
46 #include "sql/key.h"
47 #include "sql/key_spec.h"
48 #include "sql/mdl.h" // MDL_wait_for_subgraph
49 #include "sql/mem_root_array.h"
50 #include "sql/opt_costmodel.h" // Cost_model_table
51 #include "sql/record_buffer.h" // Record_buffer
52 #include "sql/sql_bitmap.h" // Bitmap
53 #include "sql/sql_const.h"
54 #include "sql/sql_list.h"
55 #include "sql/sql_plist.h"
56 #include "sql/sql_plugin_ref.h"
57 #include "sql/sql_sort.h" // Filesort_info
58 #include "table_id.h" // Table_id
59 #include "thr_lock.h"
60 #include "typelib.h"
61 
62 #include "sql/mem_root_array.h"
63 
64 class Field;
65 
66 namespace histograms {
67 class Histogram;
68 }
69 
72 class COND_EQUAL;
73 class Field_json;
74 /* Structs that defines the TABLE */
75 class File_parser;
76 class Value_generator;
77 class GRANT_TABLE;
78 class Handler_share;
79 class Index_hint;
80 class Item;
81 class Item_field;
82 class Json_diff_vector;
83 class Json_seekable_path;
84 class Json_wrapper;
85 class Opt_hints_qb;
86 class Opt_hints_table;
87 class Query_result_union;
88 class SELECT_LEX;
89 class SELECT_LEX_UNIT;
90 class Security_context;
91 class String;
92 class THD;
95 class Temp_table_param;
96 class handler;
97 class partition_info;
98 enum enum_stats_auto_recalc : int;
99 enum Value_generator_source : short;
100 enum row_type : int;
101 struct HA_CREATE_INFO;
102 struct LEX;
103 struct NESTED_JOIN;
104 struct Partial_update_info;
105 struct TABLE;
106 struct TABLE_LIST;
107 struct TABLE_SHARE;
108 struct handlerton;
109 typedef int8 plan_idx;
110 
111 namespace dd {
112 class Table;
113 class View;
114 
115 enum class enum_table_type;
116 } // namespace dd
117 class Common_table_expr;
118 
122 
126 
128 
130 
131 enum class enum_json_diff_operation;
132 
134 
135 #define store_record(A, B) \
136  memcpy((A)->B, (A)->record[0], (size_t)(A)->s->reclength)
137 #define restore_record(A, B) \
138  memcpy((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
139 #define cmp_record(A, B) \
140  memcmp((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
141 
142 #define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
143 #define tmp_file_prefix_length 4
144 #define TMP_TABLE_KEY_EXTRA 8
145 #define PLACEHOLDER_TABLE_ROW_ESTIMATE 2
146 
147 /**
148  Enumerate possible types of a table from re-execution
149  standpoint.
150  TABLE_LIST class has a member of this type.
151  At prepared statement prepare, this member is assigned a value
152  as of the current state of the database. Before (re-)execution
153  of a prepared statement, we check that the value recorded at
154  prepare matches the type of the object we obtained from the
155  table definition cache.
156 
157  @sa check_and_update_table_version()
158  @sa Execute_observer
159  @sa Prepared_statement::reprepare()
160 */
161 
163  /** Initial value set by the parser */
169 };
170 
171 /**
172  Enumerate possible status of a identifier name while determining
173  its validity
174 */
176 
177 /*************************************************************************/
178 
179 /**
180  Object_creation_ctx -- interface for creation context of database objects
181  (views, stored routines, events, triggers). Creation context -- is a set
182  of attributes, that should be fixed at the creation time and then be used
183  each time the object is parsed or executed.
184 */
185 
187  public:
189 
190  void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
191 
192  protected:
194  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
195  virtual void delete_backup_ctx() = 0;
196 
197  virtual void change_env(THD *thd) const = 0;
198 
199  public:
200  virtual ~Object_creation_ctx() {}
201 };
202 
203 /*************************************************************************/
204 
205 /**
206  Default_object_creation_ctx -- default implementation of
207  Object_creation_ctx.
208 */
209 
211  public:
213 
215 
216  protected:
218 
219  Default_object_creation_ctx(const CHARSET_INFO *client_cs,
220  const CHARSET_INFO *connection_cl);
221 
222  protected:
223  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
224  virtual void delete_backup_ctx();
225 
226  virtual void change_env(THD *thd) const;
227 
228  protected:
229  /**
230  client_cs stores the value of character_set_client session variable.
231  The only character set attribute is used.
232 
233  Client character set is included into query context, because we save
234  query in the original character set, which is client character set. So,
235  in order to parse the query properly we have to switch client character
236  set on parsing.
237  */
239 
240  /**
241  connection_cl stores the value of collation_connection session
242  variable. Both character set and collation attributes are used.
243 
244  Connection collation is included into query context, becase it defines
245  the character set and collation of text literals in internal
246  representation of query (item-objects).
247  */
249 };
250 
251 /**
252  View_creation_ctx -- creation context of view objects.
253 */
254 
256  public:
257  static View_creation_ctx *create(THD *thd);
258 
259  static View_creation_ctx *create(THD *thd, TABLE_LIST *view);
260 
261  private:
263 };
264 
265 /*************************************************************************/
266 
267 /** Order clause list element */
268 
269 struct ORDER {
271  /**
272  Points at the item in the select fields. Note that this means that
273  after resolving, it points into a slice (see JOIN::ref_items),
274  even though the item is not of type Item_ref!
275  */
277  Item *item_ptr; /* Storage for initial item */
278 
279  enum_order direction; /* Requested direction of ordering */
280  bool in_field_list; /* true if in select field list */
281  /**
282  Tells whether this ORDER element was referenced with an alias or with an
283  expression, in the query:
284  SELECT a AS foo GROUP BY foo: true.
285  SELECT a AS foo GROUP BY a: false.
286  */
288  /**
289  When GROUP BY is implemented with a temporary table (i.e. the table takes
290  care to store only unique group rows, table->group != nullptr), each GROUP
291  BY expression is stored in a column of the table, which is
292  'field_in_tmp_table'.
293  Such field may point into table->record[0] (if we only use it to get its
294  value from a tmp table's row), or into 'buff' (if we use it to do index
295  lookup into the tmp table).
296  */
298  char *buff; /* If tmp-table group */
300  bool is_position; /* An item expresses a position in a ORDER clause */
301  bool is_explicit; /* Whether ASC/DESC is explicitly specified */
302 };
303 
304 /**
305  State information for internal tables grants.
306  This structure is part of the TABLE_LIST, and is updated
307  during the ACL check process.
308  @sa GRANT_INFO
309 */
311  /** True if the internal lookup by schema name was done. */
312  bool m_schema_lookup_done{false};
313  /** Cached internal schema access. */
315  /** True if the internal lookup by table name was done. */
316  bool m_table_lookup_done{false};
317  /** Cached internal table access. */
319 };
320 
321 /**
322  @brief The current state of the privilege checking process for the current
323  user, SQL statement and SQL object.
324 
325  @details The privilege checking process is divided into phases depending on
326  the level of the privilege to be checked and the type of object to be
327  accessed. Due to the mentioned scattering of privilege checking
328  functionality, it is necessary to keep track of the state of the process.
329 
330  A GRANT_INFO also serves as a cache of the privilege hash tables. Relevant
331  members are grant_table and version.
332  */
333 struct GRANT_INFO {
334  GRANT_INFO();
335  /**
336  @brief A copy of the privilege information regarding the current host,
337  database, object and user.
338 
339  @details The version of this copy is found in GRANT_INFO::version.
340  */
342  /**
343  @brief Used for cache invalidation when caching privilege information.
344 
345  @details The privilege information is stored on disk, with dedicated
346  caches residing in memory: table-level and column-level privileges,
347  respectively, have their own dedicated caches.
348 
349  The GRANT_INFO works as a level 1 cache with this member updated to the
350  current value of the global variable @c grant_version (@c static variable
351  in sql_acl.cc). It is updated Whenever the GRANT_INFO is refreshed from
352  the level 2 cache. The level 2 cache is the @c column_priv_hash structure
353  (@c static variable in sql_acl.cc)
354 
355  @see grant_version
356  */
358  /**
359  @brief The set of privileges that the current user has fulfilled for a
360  certain host, database, and object.
361 
362  @details This field is continually updated throughout the access checking
363  process. In each step the "wanted privilege" is checked against the
364  fulfilled privileges. When/if the intersection of these sets is empty,
365  access is granted.
366 
367  The set is implemented as a bitmap, with the bits defined in sql_acl.h.
368  */
370  /** The grant state for internal tables. */
372 };
373 
380 };
381 
382 /**
383  Category of table found in the table share.
384 */
386  /**
387  Unknown value.
388  */
390 
391  /**
392  Temporary table.
393  The table is visible only in the session.
394  Therefore,
395  - FLUSH TABLES WITH READ LOCK
396  - SET GLOBAL READ_ONLY = ON
397  do not apply to this table.
398  Note that LOCK TABLE t FOR READ/WRITE
399  can be used on temporary tables.
400  Temporary tables are not part of the table cache.
401 
402  2016-06-14 Contrary to what's written in these comments, the truth is:
403  - tables created by CREATE TEMPORARY TABLE have TABLE_CATEGORY_USER
404  - tables created by create_tmp_table() (internal ones) have
405  TABLE_CATEGORY_TEMPORARY.
406  ha_innodb.cc relies on this observation (so: grep it). If you clean this
407  up, you may also want to look at 'no_tmp_table'; its enum values' meanings
408  have degraded over time: INTERNAL_TMP_TABLE is not used for some internal
409  tmp tables (derived tables). Unification of both enums would be
410  great. Whatever the result, we need to be able to distinguish the two
411  types of temporary tables above, as usage patterns are more restricted for
412  the second type, and allow more optimizations.
413  */
415 
416  /**
417  User table.
418  These tables do honor:
419  - LOCK TABLE t FOR READ/WRITE
420  - FLUSH TABLES WITH READ LOCK
421  - SET GLOBAL READ_ONLY = ON
422  User tables are cached in the table cache.
423  */
425 
426  /**
427  System table, maintained by the server.
428  These tables do honor:
429  - LOCK TABLE t FOR READ/WRITE
430  - FLUSH TABLES WITH READ LOCK
431  - SET GLOBAL READ_ONLY = ON
432  Typically, writes to system tables are performed by
433  the server implementation, not explicitly be a user.
434  System tables are cached in the table cache.
435  */
437 
438  /**
439  Information schema tables.
440  These tables are an interface provided by the system
441  to inspect the system metadata.
442  These tables do *not* honor:
443  - LOCK TABLE t FOR READ/WRITE
444  - FLUSH TABLES WITH READ LOCK
445  - SET GLOBAL READ_ONLY = ON
446  as there is no point in locking explicitly
447  an INFORMATION_SCHEMA table.
448  Nothing is directly written to information schema tables.
449  Note that this value is not used currently,
450  since information schema tables are not shared,
451  but implemented as session specific temporary tables.
452  */
453  /*
454  TODO: Fixing the performance issues of I_S will lead
455  to I_S tables in the table cache, which should use
456  this table type.
457  */
459 
460  /**
461  Log tables.
462  These tables are an interface provided by the system
463  to inspect the system logs.
464  These tables do *not* honor:
465  - LOCK TABLE t FOR READ/WRITE
466  - FLUSH TABLES WITH READ LOCK
467  - SET GLOBAL READ_ONLY = ON
468  as there is no point in locking explicitly
469  a LOG table.
470  An example of LOG tables are:
471  - mysql.slow_log
472  - mysql.general_log,
473  which *are* updated even when there is either
474  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
475  User queries do not write directly to these tables
476  (there are exceptions for log tables).
477  The server implementation perform writes.
478  Log tables are cached in the table cache.
479  */
481 
482  /**
483  Performance schema tables.
484  These tables are an interface provided by the system
485  to inspect the system performance data.
486  These tables do *not* honor:
487  - LOCK TABLE t FOR READ/WRITE
488  - FLUSH TABLES WITH READ LOCK
489  - SET GLOBAL READ_ONLY = ON
490  as there is no point in locking explicitly
491  a PERFORMANCE_SCHEMA table.
492  An example of PERFORMANCE_SCHEMA tables are:
493  - performance_schema.*
494  which *are* updated (but not using the handler interface)
495  even when there is either
496  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
497  User queries do not write directly to these tables
498  (there are exceptions for SETUP_* tables).
499  The server implementation perform writes.
500  Performance tables are cached in the table cache.
501  */
503 
504  /**
505  Replication Information Tables.
506  These tables are used to store replication information.
507  These tables do *not* honor:
508  - LOCK TABLE t FOR READ/WRITE
509  - FLUSH TABLES WITH READ LOCK
510  - SET GLOBAL READ_ONLY = ON
511  as there is no point in locking explicitly
512  a Replication Information table.
513  An example of replication tables are:
514  - mysql.slave_master_info
515  - mysql.slave_relay_log_info,
516  which *are* updated even when there is either
517  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
518  User queries do not write directly to these tables.
519  Replication tables are cached in the table cache.
520  */
522 
523  /**
524  Gtid Table.
525  The table is used to store gtids.
526  The table does *not* honor:
527  - LOCK TABLE t FOR READ/WRITE
528  - FLUSH TABLES WITH READ LOCK
529  - SET GLOBAL READ_ONLY = ON
530  as there is no point in locking explicitly
531  a Gtid table.
532  An example of gtid_executed table is:
533  - mysql.gtid_executed,
534  which is updated even when there is either
535  a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
536  Gtid table is cached in the table cache.
537  */
539 
540  /**
541  A data dictionary table.
542  Table's with this category will skip checking the
543  TABLE_SHARE versions because these table structures
544  are fixed upon server bootstrap.
545  */
547 };
549 
550 extern ulong refresh_version;
551 
556 };
557 
561 };
562 
564  protected:
565  bool has_keys;
566  virtual void report_error(uint code, const char *fmt, ...) = 0;
567 
568  public:
570  virtual ~Table_check_intact() {}
571 
572  /**
573  Checks whether a table is intact.
574 
575  @param thd Session.
576  @param table Table to check.
577  @param table_def Table definition struct.
578  */
579  bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def);
580 };
581 
582 /**
583  Class representing the fact that some thread waits for table
584  share to be flushed. Is used to represent information about
585  such waits in MDL deadlock detector.
586 */
587 
592 
593  public:
594  Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg,
595  uint deadlock_weight_arg)
596  : m_ctx(ctx_arg),
597  m_share(share_arg),
598  m_deadlock_weight(deadlock_weight_arg) {}
599 
600  MDL_context *get_ctx() const { return m_ctx; }
601 
602  virtual bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor);
603 
604  virtual uint get_deadlock_weight() const;
605 
606  /**
607  Pointers for participating in the list of waiters for table share.
608  */
611 };
612 
613 typedef I_P_List<
618 
622  /**
623  Name of unique key matching FK in parent table, "" if there is no
624  unique key.
625  */
629  /**
630  Arrays with names of referencing columns of the FK.
631  */
634 
640 
641 /**
642  This structure is shared between different table objects. There is one
643  instance of table share per one table in the database.
644 */
645 
646 struct TABLE_SHARE {
647  TABLE_SHARE() = default;
648 
649  /**
650  Create a new TABLE_SHARE with the given version number.
651  @param version the version of the TABLE_SHARE
652  @param secondary set to true if the TABLE_SHARE represents a table
653  in a secondary storage engine
654  */
655  TABLE_SHARE(unsigned long version, bool secondary)
656  : m_version(version), m_secondary_engine(secondary) {}
657 
658  /*
659  A map of [uint, Histogram] values, where the key is the field index. The
660  map is populated with any histogram statistics when it is loaded/created.
661  */
663  nullptr};
664 
665  /**
666  Find the histogram for the given field index.
667 
668  @param field_index the index of the field we want to find a histogram for
669 
670  @retval nullptr if no histogram is found
671  @retval a pointer to a histogram if one is found
672  */
673  const histograms::Histogram *find_histogram(uint field_index);
674 
675  /** Category of this table. */
677 
678  /* hash of field names (contains pointers to elements of field array) */
681  TYPELIB keynames; /* Pointers to keynames */
682  TYPELIB *intervals{nullptr}; /* pointer to interval info */
683  mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */
684  TABLE_SHARE *next{nullptr}, **prev{nullptr}; /* Link to unused shares */
685  /**
686  Array of table_cache_instances pointers to elements of table caches
687  respresenting this table in each of Table_cache instances.
688  Allocated along with the share itself in alloc_table_share().
689  Each element of the array is protected by Table_cache::m_lock in the
690  corresponding Table_cache. False sharing should not be a problem in
691  this case as elements of this array are supposed to be updated rarely.
692  */
694 
695  /* The following is copied to each TABLE on OPEN */
696  Field **field{nullptr};
698  KEY *key_info{nullptr}; /* data of keys defined for the table */
699  uint *blob_field{nullptr}; /* Index to blobs in Field arrray*/
700 
701  uchar *default_values{nullptr}; /* row with default values */
702  LEX_STRING comment{nullptr, 0}; /* Comment about table */
703  LEX_STRING compress{nullptr, 0}; /* Compression algorithm */
704  LEX_STRING encrypt_type{nullptr, 0}; /* encryption algorithm */
705 
706  /** Secondary storage engine. */
708 
710  nullptr}; /* Default charset of string fields */
711 
713  /*
714  Key which is used for looking-up table in table cache and in the list
715  of thread's temporary tables. Has the form of:
716  "database_name\0table_name\0" + optional part for temporary tables.
717 
718  Note that all three 'table_cache_key', 'db' and 'table_name' members
719  must be set (and be non-zero) for tables in table cache. They also
720  should correspond to each other.
721  To ensure this one can use set_table_cache() methods.
722  */
724  LEX_CSTRING db{nullptr, 0}; /* Pointer to db */
725  LEX_CSTRING table_name{nullptr, 0}; /* Table name (for open) */
726  LEX_STRING path{nullptr, 0}; /* Path to .frm file (from datadir) */
727  LEX_STRING normalized_path{nullptr, 0}; /* unpack_filename(path) */
729 
730  /**
731  The set of indexes that are not disabled for this table. I.e. it excludes
732  indexes disabled by `ALTER TABLE ... DISABLE KEYS`, however it does
733  include invisible indexes. The data dictionary populates this bitmap.
734  */
736 
737  /// The set of visible and enabled indexes for this table.
740  ha_rows min_rows{0}, max_rows{0}; /* create information */
741  ulong avg_row_length{0}; /* create information */
742  ulong mysql_version{0}; /* 0 if .frm is created before 5.0 */
743  ulong reclength{0}; /* Recordlength */
744  ulong stored_rec_length{0}; /* Stored record length
745  (no generated-only generated fields) */
746 
747  plugin_ref db_plugin{nullptr}; /* storage engine plugin */
748  inline handlerton *db_type() const /* table_type for handler */
749  {
750  // DBUG_ASSERT(db_plugin);
751  return db_plugin ? plugin_data<handlerton *>(db_plugin) : NULL;
752  }
753  /**
754  Value of ROW_FORMAT option for the table as provided by user.
755  Can be different from the real row format used by the storage
756  engine. ROW_TYPE_DEFAULT value indicates that no explicit
757  ROW_FORMAT was specified for the table. @sa real_row_type.
758  */
759  enum row_type row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
760  /** Real row format used for the table by the storage engine. */
761  enum row_type real_row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
763 
764  /**
765  Only for internal temporary tables.
766  Count of TABLEs (having this TABLE_SHARE) which have a "handler"
767  (table->file!=nullptr).
768  */
770 
771  uint key_block_size{0}; /* create key_block_size, if used */
772  uint stats_sample_pages{0}; /* number of pages to sample during
773  stats estimation, if used, otherwise 0. */
775  stats_auto_recalc{}; /* Automatic recalc of stats.
776  Zero-initialized to HA_STATS_AUTO_RECALC_DEFAULT
777  */
779  uint fields{0}; /* Number of fields */
780  uint rec_buff_length{0}; /* Size of table->record[] buffer */
781  uint keys{0}; /* Number of keys defined for the table*/
782  uint key_parts{0}; /* Number of key parts of all keys
783  defined for the table
784  */
785  uint max_key_length{0}; /* Length of the longest key */
786  uint max_unique_length{0}; /* Length of the longest unique key */
788  uint null_fields{0}; /* number of null fields */
789  uint blob_fields{0}; /* number of blob fields */
790  uint varchar_fields{0}; /* number of varchar fields */
791  /**
792  For materialized derived tables; @see add_derived_key().
793  'first' means: having the lowest position in key_info.
794  */
796  /**
797  For materialized derived tables: maximum size of key_info array. Used for
798  debugging purpose only.
799  */
801 
802  /**
803  Bitmap with flags representing some of table options/attributes.
804 
805  @sa HA_OPTION_PACK_RECORD, HA_OPTION_PACK_KEYS, ...
806 
807  @note This is basically copy of HA_CREATE_INFO::table_options bitmap
808  at the time of table opening/usage.
809  */
811  /**
812  Bitmap with flags representing some of table options/attributes which
813  are in use by storage engine.
814 
815  @note db_options_in_use is normally copy of db_create_options but can
816  be overriden by SE. E.g. MyISAM does this at handler::open() and
817  hander::info() time.
818  */
820  uint rowid_field_offset{0}; /* Field_nr +1 to rowid field */
821  /* Primary key index number, used in TABLE::key_info[] */
823  uint next_number_index{0}; /* autoincrement key number */
824  uint next_number_key_offset{0}; /* autoinc keypart offset in a key */
825  uint next_number_keypart{0}; /* autoinc keypart number in a key */
826  bool error{false}; /* error during open_table_def() */
828  /// Number of generated fields
830  /// Number of fields having the default value generated
832  bool system{false}; /* Set if system table (one record) */
833  bool db_low_byte_first{false}; /* Portable row format */
834  bool crashed{false};
835  bool is_view{false};
836  bool m_open_in_progress{false}; /* True: alloc'ed, false: def opened */
837  Table_id table_map_id; /* for row-based replication */
838 
839  /*
840  Cache for row-based replication table share checks that does not
841  need to be repeated. Possible values are: -1 when cache value is
842  not calculated yet, 0 when table *shall not* be replicated, 1 when
843  table *may* be replicated.
844  */
846 
847  /*
848  Storage media to use for this table (unless another storage
849  media has been specified on an individual column - in versions
850  where that is supported)
851  */
853 
854  /* Name of the tablespace used for this table */
855  char *tablespace{nullptr};
856 
857  /**
858  Partition meta data. Allocated from TABLE_SHARE::mem_root,
859  created when reading from the dd tables,
860  used as template for each TABLE instance.
861  The reason for having it on the TABLE_SHARE is to be able to reuse the
862  partition_elements containing partition names, values etc. instead of
863  allocating them for each TABLE instance.
864  TODO: Currently it is filled in and then only used for generating
865  the partition_info_str. The plan is to clone/copy/reference each
866  TABLE::part_info instance from it.
867  What is missing before it can be completed:
868  1) The partition expression, currently created only during parsing which
869  also needs the current TABLE instance as context for name resolution etc.
870  2) The partition values, currently the DD stores them as text so it needs
871  to be converted to field images (which is now done by first parsing the
872  value text into an Item, then saving the Item result/value into a field
873  and then finally copy the field image).
874  */
876  // TODO: Remove these four variables:
877  /**
878  Filled in when reading from frm.
879  This can simply be removed when removing the .frm support,
880  since it is already stored in the new DD.
881  */
882  bool auto_partitioned{false};
883  /**
884  Storing the full partitioning clause (PARTITION BY ...) which is used
885  when creating new partition_info object for each new TABLE object by
886  parsing this string.
887  These two will be needed until the missing parts above is fixed.
888  */
889  char *partition_info_str{nullptr};
891 
892  /**
893  Cache the checked structure of this table.
894 
895  The pointer data is used to describe the structure that
896  a instance of the table must have. Each element of the
897  array specifies a field that must exist on the table.
898 
899  The pointer is cached in order to perform the check only
900  once -- when the table is loaded from the disk.
901  */
903 
904  /** Main handler's share */
906 
907  /** Instrumentation for this table share. */
909 
910  /**
911  List of tickets representing threads waiting for the share to be flushed.
912  */
914 
915  /**
916  View object holding view definition read from DD. This object is not
917  cached, and is owned by the table share. We are not able to read it
918  on demand since we may then get a cache miss while holding LOCK_OPEN.
919  */
920  const dd::View *view_object{nullptr};
921 
922  /**
923  Data-dictionary object describing explicit temporary table represented
924  by this share. NULL for other table types (non-temporary tables, internal
925  temporary tables). This object is owned by TABLE_SHARE and should be
926  deleted along with it.
927  */
929 
930  /// For materialized derived tables; @see add_derived_key().
932 
933  /**
934  Arrays with descriptions of foreign keys in which this table participates
935  as child or parent. We only cache in them information from dd::Table object
936  which is sufficient for use by prelocking algorithm.
937  */
942 
943  // List of check constraint share instances.
945 
946  /**
947  Set share's table cache key and update its db and table name appropriately.
948 
949  @param key_buff Buffer with already built table cache key to be
950  referenced from share.
951  @param key_length Key length.
952 
953  @note
954  Since 'key_buff' buffer will be referenced from share it should has same
955  life-time as share itself.
956  This method automatically ensures that TABLE_SHARE::table_name/db have
957  appropriate values by using table cache key as their source.
958  */
959 
960  void set_table_cache_key(char *key_buff, size_t key_length) {
961  table_cache_key.str = key_buff;
963  /*
964  Let us use the fact that the key is "db/0/table_name/0" + optional
965  part for temporary tables.
966  */
968  db.length = strlen(db.str);
969  table_name.str = db.str + db.length + 1;
970  table_name.length = strlen(table_name.str);
971  }
972 
973  /**
974  Set share's table cache key and update its db and table name appropriately.
975 
976  @param key_buff Buffer to be used as storage for table cache key
977  (should be at least key_length bytes).
978  @param key Value for table cache key.
979  @param key_length Key length.
980 
981  NOTE
982  Since 'key_buff' buffer will be used as storage for table cache key
983  it should has same life-time as share itself.
984  */
985 
986  void set_table_cache_key(char *key_buff, const char *key, size_t key_length) {
987  memcpy(key_buff, key, key_length);
988  set_table_cache_key(key_buff, key_length);
989  }
990 
992 
993  /** Returns the version of this TABLE_SHARE. */
994  unsigned long version() const { return m_version; }
995 
996  /**
997  Set the version of this TABLE_SHARE to zero. This marks the
998  TABLE_SHARE for automatic removal from the table definition cache
999  once it is no longer referenced.
1000  */
1001  void clear_version();
1002 
1003  /** Is this table share being expelled from the table definition cache? */
1004  bool has_old_version() const { return version() != refresh_version; }
1005 
1006  /**
1007  Convert unrelated members of TABLE_SHARE to one enum
1008  representing its type.
1009 
1010  @todo perhaps we need to have a member instead of a function.
1011  */
1013  if (is_view) return TABLE_REF_VIEW;
1014  switch (tmp_table) {
1015  case NO_TMP_TABLE:
1016  return TABLE_REF_BASE_TABLE;
1017  case SYSTEM_TMP_TABLE:
1018  return TABLE_REF_I_S_TABLE;
1019  default:
1020  return TABLE_REF_TMP_TABLE;
1021  }
1022  }
1023  /**
1024  Return a table metadata version.
1025  * for base tables and views, we return table_map_id.
1026  It is assigned from a global counter incremented for each
1027  new table loaded into the table definition cache (TDC).
1028  * for temporary tables it's table_map_id again. But for
1029  temporary tables table_map_id is assigned from
1030  thd->query_id. The latter is assigned from a thread local
1031  counter incremented for every new SQL statement. Since
1032  temporary tables are thread-local, each temporary table
1033  gets a unique id.
1034  * for everything else (e.g. information schema tables),
1035  the version id is zero.
1036 
1037  This choice of version id is a large compromise
1038  to have a working prepared statement validation in 5.1. In
1039  future version ids will be persistent, as described in WL#4180.
1040 
1041  Let's try to explain why and how this limited solution allows
1042  to validate prepared statements.
1043 
1044  Firstly, sets (in mathematical sense) of version numbers
1045  never intersect for different table types. Therefore,
1046  version id of a temporary table is never compared with
1047  a version id of a view, and vice versa.
1048 
1049  Secondly, for base tables and views, we know that each DDL flushes
1050  the respective share from the TDC. This ensures that whenever
1051  a table is altered or dropped and recreated, it gets a new
1052  version id.
1053  Unfortunately, since elements of the TDC are also flushed on
1054  LRU basis, this choice of version ids leads to false positives.
1055  E.g. when the TDC size is too small, we may have a SELECT
1056  * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which
1057  in turn will lead to a validation error and a subsequent
1058  reprepare of all prepared statements. This is
1059  considered acceptable, since as long as prepared statements are
1060  automatically reprepared, spurious invalidation is only
1061  a performance hit. Besides, no better simple solution exists.
1062 
1063  For temporary tables, using thd->query_id ensures that if
1064  a temporary table was altered or recreated, a new version id is
1065  assigned. This suits validation needs very well and will perhaps
1066  never change.
1067 
1068  Metadata of information schema tables never changes.
1069  Thus we can safely assume 0 for a good enough version id.
1070 
1071  Finally, by taking into account table type, we always
1072  track that a change has taken place when a view is replaced
1073  with a base table, a base table is replaced with a temporary
1074  table and so on.
1075 
1076  @retval 0 For schema tables, DD tables and system views.
1077  non-0 For bases tables, views and temporary tables.
1078 
1079  @sa TABLE_LIST::is_table_ref_id_equal()
1080  */
1082 
1083  /** Determine if the table is missing a PRIMARY KEY. */
1084  bool is_missing_primary_key() const {
1086  return primary_key == MAX_KEY;
1087  }
1088 
1090 
1091  bool visit_subgraph(Wait_for_flush *waiting_ticket,
1092  MDL_wait_for_graph_visitor *gvisitor);
1093 
1094  bool wait_for_old_version(THD *thd, struct timespec *abstime,
1095  uint deadlock_weight);
1096 
1097  /**
1098  The set of indexes that the optimizer may use when creating an execution
1099  plan.
1100  */
1101  Key_map usable_indexes(const THD *thd) const;
1102 
1103  /** Release resources and free memory occupied by the table share. */
1104  void destroy();
1105 
1106  /**
1107  How many TABLE objects use this TABLE_SHARE.
1108  @return the reference count
1109  */
1110  unsigned int ref_count() const {
1112  return m_ref_count;
1113  }
1114 
1115  /**
1116  Increment the reference count by one.
1117  @return the new reference count
1118  */
1119  unsigned int increment_ref_count() {
1122  return ++m_ref_count;
1123  }
1124 
1125  /**
1126  Decrement the reference count by one.
1127  @return the new reference count
1128  */
1129  unsigned int decrement_ref_count() {
1132  DBUG_ASSERT(m_ref_count > 0);
1133  return --m_ref_count;
1134  }
1135 
1136  /// Does this TABLE_SHARE represent a table in a primary storage engine?
1137  bool is_primary_engine() const { return !m_secondary_engine; }
1138 
1139  /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1140  bool is_secondary_engine() const { return m_secondary_engine; }
1141 
1142  /**
1143  Does this TABLE_SHARE represent a primary table that has a shadow
1144  copy in a secondary storage engine?
1145  */
1146  bool has_secondary_engine() const {
1147  return is_primary_engine() && secondary_engine.str != nullptr;
1148  }
1149 
1150  private:
1151  /// How many TABLE objects use this TABLE_SHARE.
1152  unsigned int m_ref_count{0};
1153 
1154  /**
1155  TABLE_SHARE version, if changed the TABLE_SHARE must be reopened.
1156  NOTE: The TABLE_SHARE will not be reopened during LOCK TABLES in
1157  close_thread_tables!!!
1158  */
1159  unsigned long m_version{0};
1160 
1161  /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1162  bool m_secondary_engine{false};
1163 };
1164 
1165 /**
1166  Class is used as a BLOB field value storage for
1167  intermediate GROUP_CONCAT results. Used only for
1168  GROUP_CONCAT with DISTINCT or ORDER BY options.
1169  */
1170 
1172  private:
1174  /**
1175  Sign that some values were cut
1176  during saving into the storage.
1177  */
1179 
1180  public:
1181  Blob_mem_storage();
1183 
1184  void reset() {
1186  truncated_value = false;
1187  }
1188  /**
1189  Fuction creates duplicate of 'from'
1190  string in 'storage' MEM_ROOT.
1191 
1192  @param from string to copy
1193  @param length string length
1194 
1195  @retval Pointer to the copied string.
1196  @retval 0 if an error occurred.
1197  */
1198  char *store(const char *from, size_t length) {
1199  return (char *)memdup_root(&storage, from, length);
1200  }
1203  }
1204  bool is_truncated_value() const { return truncated_value; }
1205 };
1206 
1207 /**
1208  Class that represents a single change to a column value in partial
1209  update of a JSON column.
1210 */
1212  /// The offset of the start of the change.
1213  size_t m_offset;
1214 
1215  /// The size of the portion that is to be replaced.
1216  size_t m_length;
1217 
1218  public:
1219  /**
1220  Create a new Binary_diff object.
1221 
1222  @param offset the offset of the beginning of the change
1223  @param length the length of the section that is to be replaced
1224  */
1225  Binary_diff(size_t offset, size_t length)
1226  : m_offset(offset), m_length(length) {}
1227 
1228  /// @return the offset of the changed data
1229  size_t offset() const { return m_offset; }
1230 
1231  /// @return the length of the changed data
1232  size_t length() const { return m_length; }
1233 
1234  /**
1235  Get a pointer to the start of the replacement data.
1236 
1237  @param field the column that is updated
1238  @return a pointer to the start of the replacement data
1239  */
1240  const char *new_data(Field *field) const;
1241 
1242  /**
1243  Get a pointer to the start of the old data to be replaced.
1244 
1245  @param field the column that is updated
1246  @return a pointer to the start of old data to be replaced.
1247  */
1248  const char *old_data(Field *field) const;
1249 };
1250 
1251 /**
1252  Vector of Binary_diff objects.
1253 
1254  The Binary_diff objects in the vector should be ordered on offset, and none
1255  of the diffs should be overlapping or adjacent.
1256 */
1258 
1259 /**
1260  Flags for TABLE::m_status (maximum 8 bits).
1261  The flags define the state of the row buffer in TABLE::record[0].
1262 */
1263 /**
1264  STATUS_NOT_STARTED is set when table is not accessed yet.
1265  Neither STATUS_NOT_FOUND nor STATUS_NULL_ROW can be set when this flag is set.
1266 */
1267 #define STATUS_NOT_STARTED 1
1268 /**
1269  Means we were searching for a row and didn't find it. This is used by
1270  storage engines (@see handler::index_read_map()) and the executor, both
1271  when doing an exact row lookup and advancing a scan (no more rows in range).
1272 */
1273 #define STATUS_NOT_FOUND 2
1274 /// Reserved for use by multi-table update. Means the row has been updated.
1275 #define STATUS_UPDATED 16
1276 /**
1277  Means that table->null_row is set. This is an artificial NULL-filled row
1278  (one example: in outer join, if no match has been found in inner table).
1279 */
1280 #define STATUS_NULL_ROW 32
1281 /// Reserved for use by multi-table delete. Means the row has been deleted.
1282 #define STATUS_DELETED 64
1283 
1284 /* Information for one open table */
1286 
1287 /* Bitmap of table's fields */
1289 
1290 /*
1291  NOTE: Despite being a struct (for historical reasons), TABLE has
1292  a nontrivial destructor.
1293 */
1294 struct TABLE {
1295  TABLE_SHARE *s{nullptr};
1296  handler *file{nullptr};
1297  TABLE *next{nullptr}, *prev{nullptr};
1298 
1299  private:
1300  /**
1301  Links for the lists of used/unused TABLE objects for the particular
1302  table in the specific instance of Table_cache (in other words for
1303  specific Table_cache_element object).
1304  Declared as private to avoid direct manipulation with those objects.
1305  One should use methods of I_P_List template instead.
1306  */
1307  TABLE *cache_next{nullptr}, **cache_prev{nullptr};
1308 
1309  /*
1310  Give Table_cache_element access to the above two members to allow
1311  using them for linking TABLE objects in a list.
1312  */
1313  friend class Table_cache_element;
1314 
1315  public:
1316  /**
1317  A bitmap marking the hidden generated columns that exists for functional
1318  indexes.
1319  */
1321 
1322  THD *in_use{nullptr}; /* Which thread uses this */
1323  Field **field{nullptr}; /* Pointer to fields */
1324  /// Count of hidden fields, if internal temporary table; 0 otherwise.
1326 
1327  uchar *record[2]{nullptr, nullptr}; /* Pointer to records */
1328  uchar *write_row_record{nullptr}; /* Used as optimisation in
1329  THD::write_row */
1330  uchar *insert_values{nullptr}; /* used by INSERT ... UPDATE */
1331 
1332  /// Buffer for use in multi-row reads. Initially empty.
1334 
1335  /*
1336  Map of keys that can be used to retrieve all data from this table
1337  needed by the query without reading the row.
1338  */
1341 
1342  /* Merge keys are all keys that had a column reffered to in the query */
1344 
1345  /*
1346  possible_quick_keys is a superset of quick_keys to use with EXPLAIN of
1347  JOIN-less commands (single-table UPDATE and DELETE).
1348 
1349  When explaining regular JOINs, we use JOIN_TAB::keys to output the
1350  "possible_keys" column value. However, it is not available for
1351  single-table UPDATE and DELETE commands, since they don't use JOIN
1352  optimizer at the top level. OTOH they directly use the range optimizer,
1353  that collects all keys usable for range access here.
1354  */
1356 
1357  /*
1358  A set of keys that can be used in the query that references this
1359  table.
1360 
1361  All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be
1362  subtracted from this set upon instantiation. Thus for any TABLE t it holds
1363  that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
1364  must not introduce any new keys here (see setup_tables).
1365 
1366  The set is implemented as a bitmap.
1367  */
1369  /* Map of keys that can be used to calculate GROUP BY without sorting */
1371  /* Map of keys that can be used to calculate ORDER BY without sorting */
1373  KEY *key_info{nullptr}; /* data of keys defined for the table */
1374 
1375  Field *next_number_field{nullptr}; /* Set if next_number is activated */
1376  Field *found_next_number_field{nullptr}; /* Set on open */
1377  /// Pointer to generated columns
1378  Field **vfield{nullptr};
1379  /// Pointer to fields having the default value generated
1381  /// Field used by unique constraint
1382  Field *hash_field{nullptr};
1383  Field *fts_doc_id_field{nullptr}; /* Set if FTS_DOC_ID field is present */
1384 
1385  /* Table's triggers, 0 if there are no of them */
1387  TABLE_LIST *pos_in_table_list{nullptr}; /* Element referring to this table */
1388  /* Position in thd->locked_table_list under LOCK TABLES */
1390  ORDER *group{nullptr};
1391  const char *alias{nullptr}; ///< alias or table name
1392  uchar *null_flags{nullptr}; ///< Pointer to the null flags of record[0]
1394  nullptr}; ///< Saved null_flags while null_row is true
1395 
1396  /* containers */
1398  /*
1399  Bitmap of fields that one or more query condition refers to. Only
1400  used if optimizer_condition_fanout_filter is turned 'on'.
1401  Currently, only the WHERE clause and ON clause of inner joins is
1402  taken into account but not ON conditions of outer joins.
1403  Furthermore, HAVING conditions apply to groups and are therefore
1404  not useful as table condition filters.
1405  */
1407 
1408  /**
1409  Bitmap of table fields (columns), which are explicitly set in the
1410  INSERT INTO statement. It is declared here to avoid memory allocation
1411  on MEM_ROOT).
1412 
1413  @sa fields_set_during_insert.
1414  */
1416 
1417  MY_BITMAP *read_set{nullptr}, *write_set{nullptr}; /* Active column sets */
1418 
1419  /**
1420  A pointer to the bitmap of table fields (columns), which are explicitly set
1421  in the INSERT INTO statement.
1422 
1423  fields_set_during_insert points to def_fields_set_during_insert
1424  for base (non-temporary) tables. In other cases, it is NULL.
1425  Triggers can not be defined for temporary tables, so this bitmap does not
1426  matter for temporary tables.
1427 
1428  @sa def_fields_set_during_insert.
1429  */
1431 
1432  /*
1433  The ID of the query that opened and is using this table. Has different
1434  meanings depending on the table type.
1435 
1436  Temporary tables:
1437 
1438  table->query_id is set to thd->query_id for the duration of a statement
1439  and is reset to 0 once it is closed by the same statement. A non-zero
1440  table->query_id means that a statement is using the table even if it's
1441  not the current statement (table is in use by some outer statement).
1442 
1443  Non-temporary tables:
1444 
1445  Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
1446  for the duration of a statement and is reset to 0 once it is closed by
1447  the same statement. A non-zero query_id is used to control which tables
1448  in the list of pre-opened and locked tables are actually being used.
1449  */
1451 
1452  /*
1453  For each key that has quick_keys.is_set(key) == true: estimate of #records
1454  and max #key parts that range access would use.
1455  */
1457 
1458  /* Bitmaps of key parts that =const for the entire join. */
1460 
1463 
1464  /*
1465  Estimate of number of records that satisfy SARGable part of the table
1466  condition, or table->file->records if no SARGable condition could be
1467  constructed.
1468  This value is used by join optimizer as an estimate of number of records
1469  that will pass the table condition (condition that depends on fields of
1470  this table and constants)
1471  */
1473 
1474  uint lock_position{0}; /* Position in MYSQL_LOCK.table */
1475  uint lock_data_start{0}; /* Start pos. in MYSQL_LOCK.locks */
1476  uint lock_count{0}; /* Number of locks */
1477  uint db_stat{0}; /* mode of file as in handler.h */
1478  int current_lock{0}; /* Type of lock on table */
1479 
1480  // List of table check constraints.
1482 
1483  private:
1484  /**
1485  If true, this table is inner w.r.t. some outer join operation, all columns
1486  are nullable (in the query), and null_row may be true.
1487  */
1488  bool nullable{false};
1489 
1490  uint8 m_status{0}; /* What's in record[0] */
1491  public:
1492  /*
1493  If true, the current table row is considered to have all columns set to
1494  NULL, including columns declared as "not null" (see nullable).
1495  @todo make it private, currently join buffering changes it through a pointer
1496  */
1497  bool null_row{false};
1498 
1499  bool copy_blobs{false}; /* copy_blobs when storing */
1500 
1501  /*
1502  TODO: Each of the following flags take up 8 bits. They can just as easily
1503  be put into one single unsigned long and instead of taking up 18
1504  bytes, it would take up 4.
1505  */
1506  bool force_index{false};
1507 
1508  /**
1509  Flag set when the statement contains FORCE INDEX FOR ORDER BY
1510  See TABLE_LIST::process_index_hints().
1511  */
1512  bool force_index_order{false};
1513 
1514  /**
1515  Flag set when the statement contains FORCE INDEX FOR GROUP BY
1516  See TABLE_LIST::process_index_hints().
1517  */
1518  bool force_index_group{false};
1519  /**
1520  Whether this is a temporary table that already has a UNIQUE index (removing
1521  duplicate rows on insert), so that the optimizer does not need to run
1522  DISTINCT itself.
1523  */
1524  bool is_distinct{false};
1525  bool const_table{false};
1526  /// True if writes to this table should not write rows and just write keys.
1527  bool no_rows{false};
1528 
1529  /**
1530  If set, the optimizer has found that row retrieval should access index
1531  tree only.
1532  */
1533  bool key_read{false};
1534  /**
1535  Certain statements which need the full row, set this to ban index-only
1536  access.
1537  */
1538  bool no_keyread{false};
1539  /**
1540  If set, indicate that the table is not replicated by the server.
1541  */
1542  bool no_replicate{false};
1543  bool fulltext_searched{false};
1544  bool no_cache{false};
1545  /* To signal that the table is associated with a HANDLER statement */
1546  bool open_by_handler{false};
1547  /*
1548  To indicate that a non-null value of the auto_increment field
1549  was provided by the user or retrieved from the current record.
1550  Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
1551  */
1553  bool alias_name_used{false}; /* true if table_name is alias */
1554  bool get_fields_in_item_tree{false}; /* Signal to fix_field */
1555  /**
1556  This table must be reopened and is not to be reused.
1557  NOTE: The TABLE will not be reopened during LOCK TABLES in
1558  close_thread_tables!!!
1559  */
1560  bool m_needs_reopen{false};
1561 
1562  private:
1563  /**
1564  For tmp tables. true <=> tmp table has been instantiated.
1565  Also indicates that table was successfully opened since
1566  we immediately delete tmp tables which we fail to open.
1567  */
1568  bool created{false};
1569 
1570  public:
1571  /// For a materializable derived or SJ table: true if has been materialized
1572  bool materialized{false};
1573  struct /* field connections */
1574  {
1575  class JOIN_TAB *join_tab{nullptr};
1576  class QEP_TAB *qep_tab{nullptr};
1577  thr_lock_type lock_type{TL_UNLOCK}; /* How table is used */
1579  bool not_exists_optimize{false};
1580  /*
1581  true <=> range optimizer found that there is no rows satisfying
1582  table conditions.
1583  */
1584  bool impossible_range{false};
1585  } reginfo;
1586 
1587  /**
1588  @todo This member should not be declared in-line. That makes it
1589  impossible for any function that does memory allocation to take a const
1590  reference to a TABLE object.
1591  */
1593  /**
1594  Initialized in Item_func_group_concat::setup for appropriate
1595  temporary table if GROUP_CONCAT is used with ORDER BY | DISTINCT
1596  and BLOB field count > 0.
1597  */
1600  /**
1601  The result of applying a unique opertion (by row ID) to the table, if done.
1602  In particular, this is done in some forms of index merge.
1603  */
1605  partition_info *part_info{nullptr}; /* Partition related information */
1606  /* If true, all partitions have been pruned away */
1609 
1610  private:
1611  /// Cost model object for operations on this table
1613 #ifndef DBUG_OFF
1614  /**
1615  Internal tmp table sequential number. Increased in the order of
1616  creation. Used for debugging purposes when many tmp tables are used
1617  during execution (e.g several windows with window functions)
1618  */
1620 #endif
1621  public:
1622  void init(THD *thd, TABLE_LIST *tl);
1623  bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root,
1624  CHARSET_INFO *charset, const char *alias, Field **fld,
1625  uint *blob_fld, bool is_virtual);
1626  bool fill_item_list(List<Item> *item_list) const;
1627  void reset_item_list(List<Item> *item_list) const;
1628  void clear_column_bitmaps(void);
1629  void prepare_for_position(void);
1630 
1631  void mark_column_used(Field *field, enum enum_mark_columns mark);
1633  uint key_parts = 0);
1635  void mark_auto_increment_column(void);
1636  void mark_columns_needed_for_update(THD *thd, bool mark_binlog_columns);
1640  void mark_generated_columns(bool is_update);
1641  void mark_gcol_in_maps(Field *field);
1642  void mark_check_constraint_columns(bool is_update);
1643  void column_bitmaps_set(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg);
1644  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
1645  MY_BITMAP *write_set_arg) {
1646  read_set = read_set_arg;
1647  write_set = write_set_arg;
1648  }
1649  inline void use_all_columns() {
1651  }
1652  inline void default_column_bitmaps() {
1655  }
1656  /** Should this instance of the table be reopened? */
1657  inline bool needs_reopen() { return !db_stat || m_needs_reopen; }
1658  /// @returns first non-hidden column
1660  /// @returns count of visible fields
1662  bool alloc_tmp_keys(uint key_count, bool modify_share);
1663  bool add_tmp_key(Field_map *key_parts, char *key_name, bool invisible,
1664  bool modify_share);
1665  void copy_tmp_key(int old_idx, bool modify_share);
1666  void drop_unused_tmp_keys(bool modify_share);
1667 
1668  void set_keyread(bool flag);
1669 
1670  /**
1671  Check whether the given index has a virtual generated columns.
1672 
1673  @param index_no the given index to check
1674 
1675  @returns true if if index is defined over at least one virtual generated
1676  column
1677  */
1678  inline bool index_contains_some_virtual_gcol(uint index_no) {
1679  DBUG_ASSERT(index_no < s->keys);
1680  return key_info[index_no].flags & HA_VIRTUAL_GEN_KEY;
1681  }
1682  bool update_const_key_parts(Item *conds);
1683 
1685 
1686  ptrdiff_t default_values_offset() const {
1687  return (ptrdiff_t)(s->default_values - record[0]);
1688  }
1689 
1690  /// Return true if table is instantiated, and false otherwise.
1691  bool is_created() const { return created; }
1692 
1693  /**
1694  Set the table as "created", and enable flags in storage engine
1695  that could not be enabled without an instantiated table.
1696  */
1697  void set_created();
1698  /**
1699  Set the contents of table to be "deleted", ie "not created", after having
1700  deleted the contents.
1701  */
1702  void set_deleted() { created = materialized = false; }
1703  /// Set table as nullable, ie it is inner wrt some outer join
1704  void set_nullable() { nullable = true; }
1705 
1706  /// Return whether table is nullable
1707  bool is_nullable() const { return nullable; }
1708 
1709  /// @return true if table contains one or more generated columns
1710  bool has_gcol() const { return vfield; }
1711 
1712  /**
1713  Life cycle of the row buffer is as follows:
1714  - The initial state is "not started".
1715  - When reading a row through the storage engine handler, the status is set
1716  as "has row" or "no row", depending on whether a row was found or not.
1717  The "not started" state is cleared, as well as the "null row" state,
1718  the updated state and the deleted state.
1719  - When making a row available in record[0], make sure to update row status
1720  similarly to how the storage engine handler does it.
1721  - If a NULL-extended row is needed in join execution, the "null row" state
1722  is set. Note that this can be combined with "has row" if a row was read
1723  but condition on it was evaluated to false (happens for single-row
1724  lookup), or "no row" if no more rows could be read.
1725  Note also that for the "null row" state, the NULL bits inside the
1726  row are set to one, so the row inside the row buffer is no longer usable,
1727  unless the NULL bits are saved in a separate buffer.
1728  - The "is updated" and "is deleted" states are set when row is updated or
1729  deleted, respectively.
1730  */
1731  /// Set status for row buffer as "not started"
1734  null_row = false;
1735  }
1736 
1737  /// @return true if a row operation has been done
1738  bool is_started() const { return !(m_status & STATUS_NOT_STARTED); }
1739 
1740  /// Set status for row buffer: contains row
1741  void set_found_row() {
1742  m_status = 0;
1743  null_row = false;
1744  }
1745 
1746  /**
1747  Set status for row buffer: contains no row. This is set when
1748  - A lookup operation finds no row
1749  - A scan operation scans past the last row of the range.
1750  - An error in generating key values before calling storage engine.
1751  */
1752  void set_no_row() {
1754  null_row = false;
1755  }
1756 
1757  /**
1758  Set "row found" status from handler result
1759 
1760  @param status 0 if row was found, <> 0 if row was not found
1761  */
1764  null_row = false;
1765  }
1766 
1767  /**
1768  Set current row as "null row", for use in null-complemented outer join.
1769  The row buffer may or may not contain a valid row.
1770  set_null_row() and reset_null_row() are used by the join executor to
1771  signal the presence or absence of a NULL-extended row for an outer joined
1772  table. Null rows may also be used to specify rows that are all NULL in
1773  grouing operations.
1774  @note this is a destructive operation since the NULL value bit vector
1775  is overwritten. Caching operations must be aware of this.
1776  */
1777  void set_null_row() {
1778  null_row = true;
1780  if (s->null_bytes > 0) memset(null_flags, 255, s->null_bytes);
1781  }
1782 
1783  /// Clear "null row" status for the current row
1785  null_row = false;
1787  }
1788 
1789  /// Set "updated" property for the current row
1791  DBUG_ASSERT(is_started() && has_row());
1793  }
1794 
1795  /// Set "deleted" property for the current row
1797  DBUG_ASSERT(is_started() && has_row());
1799  }
1800 
1801  /// @return true if there is a row in row buffer
1802  bool has_row() const { return !(m_status & STATUS_NOT_FOUND); }
1803 
1804  /// @return true if current row is null-extended
1805  bool has_null_row() const { return null_row; }
1806 
1807  /// @return true if current row has been updated (multi-table update)
1808  bool has_updated_row() const { return m_status & STATUS_UPDATED; }
1809 
1810  /// @return true if current row has been deleted (multi-table delete)
1811  bool has_deleted_row() const { return m_status & STATUS_DELETED; }
1812 
1813  /// Save the NULL flags of the current row into the designated buffer
1815  if (s->null_bytes > 0) memcpy(null_flags_saved, null_flags, s->null_bytes);
1816  }
1817 
1818  /// Restore the NULL flags of the current row from the designated buffer
1820  if (s->null_bytes > 0) memcpy(null_flags, null_flags_saved, s->null_bytes);
1821  }
1822 
1823  /// Empties internal temporary table (deletes rows, closes scan)
1824  bool empty_result_table();
1825 
1826  /**
1827  Initialize the optimizer cost model.
1828 
1829  This function should be called each time a new query is started.
1830 
1831  @param cost_model_server the main cost model object for the query
1832  */
1833  void init_cost_model(const Cost_model_server *cost_model_server) {
1834  m_cost_model.init(cost_model_server, this);
1835  }
1836 
1837  /**
1838  Return the cost model object for this table.
1839  */
1840  const Cost_model_table *cost_model() const { return &m_cost_model; }
1841 
1842  /**
1843  Fix table's generated columns' (GC) and/or default expressions
1844 
1845  @details When a table is opened from the dictionary, the Value Generator
1846  expressions are fixed during opening (see fix_value_generators_fields()).
1847  After query execution, Item::cleanup() is called on them
1848  (see cleanup_value_generator_items()). When the table is opened from the
1849  table cache, the Value Generetor(s) need to be fixed again and this
1850  function does that.
1851 
1852  @param[in] thd the current thread
1853  @return true if error, else false
1854  */
1855  bool refix_value_generator_items(THD *thd);
1856 
1857  /**
1858  Helper function for refix_value_generator_items() that fixes one column's
1859  expression (be it GC or default expression) and check constraint expression.
1860 
1861  @param[in] thd current thread
1862  @param[in,out] g_expr the expression who's items needs to be fixed
1863  @param[in] table the table it blongs to
1864  @param[in] field the column it blongs to (for GC and Default
1865  expression).
1866  @param[in] source Source of value generator(a generated column, a
1867  regular column with generated default value or
1868  a check constraint).
1869  @param[in] source_name Name of the source (generated column, a reguler
1870  column with generated default value or a check
1871  constraint).
1872 
1873  @return true if error, else false
1874  */
1876  Field *field, TABLE *table,
1877  Value_generator_source source,
1878  const char *source_name);
1879 
1880  /**
1881  Clean any state in items associated with generated columns to be ready for
1882  the next statement.
1883  */
1885 
1886 #ifndef DBUG_OFF
1888 #endif
1889  /**
1890  Update covering keys depending on max read key length.
1891 
1892  Update available covering keys for the table, based on a constrained field
1893  and the identified covering prefix keys: If the matched part of field is
1894  longer than the index prefix,
1895  the prefix index cannot be used as a covering index.
1896 
1897  @param[in] field Pointer to field object
1898  @param[in] key_read_length Max read key length
1899  @param[in] covering_prefix_keys Covering prefix keys
1900  */
1901  void update_covering_prefix_keys(Field *field, uint16 key_read_length,
1902  Key_map *covering_prefix_keys);
1903 
1904  private:
1905  /**
1906  Bitmap that tells which columns are eligible for partial update in an
1907  update statement.
1908 
1909  The bitmap is lazily allocated in the TABLE's mem_root when
1910  #mark_column_for_partial_update() is called.
1911  */
1913 
1914  /**
1915  Object which contains execution time state used for partial update
1916  of JSON columns.
1917 
1918  It is allocated in the execution mem_root by #setup_partial_update() if
1919  there are columns that have been marked as eligible for partial update.
1920  */
1922 
1923  /**
1924  This flag decides whether or not we should log the drop temporary table
1925  command.
1926  */
1928 
1929  public:
1930  /**
1931  Does this table have any columns that can be updated using partial update
1932  in the current row?
1933 
1934  @return whether any columns in the current row can be updated using partial
1935  update
1936  */
1937  bool has_binary_diff_columns() const;
1938 
1939  /**
1940  Get the list of binary diffs that have been collected for a given column in
1941  the current row, or `nullptr` if partial update cannot be used for that
1942  column.
1943 
1944  @param field the column to get binary diffs for
1945  @return the list of binary diffs for the column, or `nullptr` if the column
1946  cannot be updated using partial update
1947  */
1948  const Binary_diff_vector *get_binary_diffs(const Field *field) const;
1949 
1950  /**
1951  Mark a given column as one that can potentially be updated using
1952  partial update during execution of an update statement.
1953 
1954  Whether it is actually updated using partial update, is not
1955  determined until execution time, since that depends both on the
1956  data that is in the column and the new data that is written to the
1957  column.
1958 
1959  This function should be called during preparation of an update
1960  statement.
1961 
1962  @param field a column which is eligible for partial update
1963  @retval false on success
1964  @retval true on out-of-memory
1965  */
1967 
1968  /**
1969  Has this column been marked for partial update?
1970 
1971  Note that this only tells if the column satisfies the syntactical
1972  requirements for being partially updated. Use #is_binary_diff_enabled() or
1973  #is_logical_diff_enabled() instead to see if partial update should be used
1974  on the column.
1975 
1976  @param field the column to check
1977  @return whether the column has been marked for partial update
1978  */
1979  bool is_marked_for_partial_update(const Field *field) const;
1980 
1981  /**
1982  Does this table have any columns that were marked with
1983  #mark_column_for_partial_update()?
1984 
1985  Note that this only tells if any of the columns satisfy the syntactical
1986  requirements for being partially updated. Use
1987  #has_binary_diff_columns(), #is_binary_diff_enabled() or
1988  #is_logical_diff_enabled() instead to see if partial update should be used
1989  on a column.
1990  */
1992 
1993  /**
1994  Enable partial update of JSON columns in this table. It is only
1995  enabled for the columns that have previously been marked for
1996  partial update using #mark_column_for_partial_update().
1997 
1998  @param logical_diffs should logical JSON diffs be collected in addition
1999  to the physical binary diffs?
2000 
2001  This function should be called once per statement execution, when
2002  the update statement is optimized.
2003 
2004  @retval false on success
2005  @retval true on out-of-memory
2006  */
2007  bool setup_partial_update(bool logical_diffs);
2008 
2009  /**
2010  @see setup_partial_update(bool)
2011 
2012  This is a wrapper that auto-computes the value of the parameter
2013  logical_diffs.
2014 
2015  @retval false on success
2016  @retval true on out-of-memory
2017  */
2018  bool setup_partial_update();
2019 
2020  /**
2021  Add a binary diff for a column that is updated using partial update.
2022 
2023  @param field the column that is being updated
2024  @param offset the offset of the changed portion
2025  @param length the length of the changed portion
2026 
2027  @retval false on success
2028  @retval true on out-of-memory
2029  */
2030  bool add_binary_diff(const Field *field, size_t offset, size_t length);
2031 
2032  /**
2033  Clear the diffs that have been collected for partial update of
2034  JSON columns, and re-enable partial update for any columns where
2035  partial update was temporarily disabled for the current row.
2036  Should be called between each row that is updated.
2037  */
2039 
2040  /**
2041  Clean up state used for partial update of JSON columns.
2042 
2043  This function should be called at the end of each statement
2044  execution.
2045  */
2046  void cleanup_partial_update();
2047 
2048  /**
2049  Temporarily disable collection of binary diffs for a column in the current
2050  row.
2051 
2052  This function is called during execution to disable partial update of a
2053  column that was previously marked as eligible for partial update with
2054  #mark_column_for_partial_update() during preparation.
2055 
2056  Partial update of this column will be re-enabled when we go to the next
2057  row.
2058 
2059  @param field the column to stop collecting binary diffs for
2060  */
2062 
2063  /**
2064  Temporarily disable collection of Json_diff objects describing the
2065  logical changes of a JSON column in the current row.
2066 
2067  Collection of logical JSON diffs is re-enabled when we go to the next row.
2068 
2069  @param field the column to stop collecting logical JSON diffs for
2070  */
2072 
2073  /**
2074  Get a buffer that can be used to hold the partially updated column value
2075  while performing partial update.
2076  */
2078 
2079  /**
2080  Add a logical JSON diff describing a logical change to a JSON column in
2081  partial update.
2082 
2083  @param field the column that is updated
2084  @param path the JSON path that is changed
2085  @param operation the operation to perform
2086  @param new_value the new value in the path
2087 
2088  @throws std::bad_alloc if memory cannot be allocated
2089  */
2091  enum_json_diff_operation operation,
2092  const Json_wrapper *new_value);
2093 
2094  /**
2095  Get the list of JSON diffs that have been collected for a given column in
2096  the current row, or `nullptr` if partial update cannot be used for that
2097  column.
2098 
2099  @param field the column to get JSON diffs for
2100  @return the list of JSON diffs for the column, or `nullptr` if the column
2101  cannot be updated using partial update
2102  */
2103  const Json_diff_vector *get_logical_diffs(const Field_json *field) const;
2104 
2105  /**
2106  Is partial update using binary diffs enabled on this JSON column?
2107 
2108  @param field the column to check
2109  @return whether the column can be updated with binary diffs
2110  */
2111  bool is_binary_diff_enabled(const Field *field) const;
2112 
2113  /**
2114  Is partial update using logical diffs enabled on this JSON column?
2115 
2116  @param field the column to check
2117  @return whether the column can be updated with JSON diffs
2118  */
2119  bool is_logical_diff_enabled(const Field *field) const;
2120 
2121  /**
2122  Virtual fields of type BLOB have a flag m_keep_old_value. This flag is set
2123  to false for all such fields in this table.
2124  */
2126 
2127  /**
2128  Set the variable should_binlog_drop_if_temp_flag, so that
2129  the logging of temporary tables can be decided.
2130 
2131  @param should_binlog the value to set flag should_binlog_drop_if_temp_flag
2132  */
2133  void set_binlog_drop_if_temp(bool should_binlog);
2134 
2135  /**
2136  @return whether should_binlog_drop_if_temp_flag flag is
2137  set or not
2138  */
2139  bool should_binlog_drop_if_temp(void) const;
2140 };
2141 
2142 static inline void empty_record(TABLE *table) {
2143  restore_record(table, s->default_values);
2144  if (table->s->null_bytes > 0)
2145  memset(table->null_flags, 255, table->s->null_bytes);
2146 }
2147 
2152 };
2153 
2165 };
2166 
2167 #define MY_I_S_MAYBE_NULL 1
2168 #define MY_I_S_UNSIGNED 2
2169 
2171  /**
2172  This is used as column name.
2173  */
2174  const char *field_name;
2175  /**
2176  For string-type columns, this is the maximum number of
2177  characters. Otherwise, it is the 'display-length' for the column.
2178  For the data type MYSQL_TYPE_DATETIME this field specifies the
2179  number of digits in the fractional part of time value.
2180  */
2182  /**
2183  This denotes data type for the column. For the most part, there seems to
2184  be one entry in the enum for each SQL data type, although there seem to
2185  be a number of additional entries in the enum.
2186  */
2188  int value;
2189  /**
2190  This is used to set column attributes. By default, columns are @c NOT
2191  @c NULL and @c SIGNED, and you can deviate from the default
2192  by setting the appropriate flags. You can use either one of the flags
2193  @c MY_I_S_MAYBE_NULL and @c MY_I_S_UNSIGNED or
2194  combine them using the bitwise or operator @c |. Both flags are
2195  defined in table.h.
2196  */
2197  uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.)
2198  const char *old_name;
2199  uint open_method; // Not used
2200 };
2201 
2203  const char *table_name;
2205  /* Create information_schema table */
2206  TABLE *(*create_table)(THD *thd, TABLE_LIST *table_list);
2207  /* Fill table with data */
2208  int (*fill_table)(THD *thd, TABLE_LIST *tables, Item *cond);
2209  /* Handle fileds for old SHOW */
2210  int (*old_format)(THD *thd, ST_SCHEMA_TABLE *schema_table);
2211  int (*process_table)(THD *thd, TABLE_LIST *tables, TABLE *table, bool res,
2214  bool hidden;
2216 };
2217 
2218 #define JOIN_TYPE_LEFT 1
2219 #define JOIN_TYPE_RIGHT 2
2220 
2221 /**
2222  Strategy for how to process a view or derived table (merge or materialization)
2223 */
2228 };
2229 
2230 #define VIEW_SUID_INVOKER 0
2231 #define VIEW_SUID_DEFINER 1
2232 #define VIEW_SUID_DEFAULT 2
2233 
2234 /* view WITH CHECK OPTION parameter options */
2235 #define VIEW_CHECK_NONE 0
2236 #define VIEW_CHECK_LOCAL 1
2237 #define VIEW_CHECK_CASCADED 2
2238 
2239 /* result of view WITH CHECK OPTION parameter check */
2240 #define VIEW_CHECK_OK 0
2241 #define VIEW_CHECK_ERROR 1
2242 #define VIEW_CHECK_SKIP 2
2243 
2244 /** The threshold size a blob field buffer before it is freed */
2245 #define MAX_TDC_BLOB_SIZE 65536
2246 
2247 /**
2248  Struct that describes an expression selected from a derived table or view.
2249 */
2251  /**
2252  Points to an item that represents the expression.
2253  If the item is determined to be unused, the pointer is set to NULL.
2254  */
2256  /// Name of selected expression
2257  const char *name;
2258 };
2259 
2260 /*
2261  Column reference of a NATURAL/USING join. Since column references in
2262  joins can be both from views and stored tables, may point to either a
2263  Field (for tables), or a Field_translator (for views).
2264 */
2265 
2267  public:
2268  Field_translator *view_field; /* Column reference of merge view. */
2269  Item_field *table_field; /* Column reference of table or temp view. */
2270  TABLE_LIST *table_ref; /* Original base table/view reference. */
2271  /*
2272  True if a common join column of two NATURAL/USING join operands. Notice
2273  that when we have a hierarchy of nested NATURAL/USING joins, a column can
2274  be common at some level of nesting but it may not be common at higher
2275  levels of nesting. Thus this flag may change depending on at which level
2276  we are looking at some column.
2277  */
2279 
2280  public:
2281  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
2282  Natural_join_column(Item_field *field_param, TABLE_LIST *tab);
2283  const char *name();
2284  Item *create_item(THD *thd);
2285  Field *field();
2286  const char *table_name();
2287  const char *db_name();
2288  GRANT_INFO *grant();
2289 };
2290 
2291 /**
2292  This is generic enum. It may be reused in the ACL statements
2293  for clauses that can map to the values defined in this enum.
2294 */
2296  UNCHANGED, /* The clause is not specified */
2297  DEFAULT, /* Default value of clause is specified */
2298  YES, /* Value that maps to True is specified */
2299  NO /* Value that maps to False is specified */
2300 };
2301 
2302 /*
2303  This structure holds the specifications relating to
2304  ALTER user ... PASSWORD EXPIRE ...
2305 */
2306 struct LEX_ALTER {
2319  /* Holds the specification of 'PASSWORD REQUIRE CURRENT' clause. */
2321  void cleanup() {
2325  expire_after_days = 0;
2327  account_locked = false;
2329  update_password_history = false;
2335  }
2336 };
2337 
2338 /*
2339  This structure holds the specifications related to
2340  mysql user and the associated auth details.
2341 */
2342 struct LEX_USER {
2348  /*
2349  The following flags are indicators for the SQL syntax used while
2350  parsing CREATE/ALTER user. While other members are self-explanatory,
2351  'uses_authentication_string_clause' signifies if the password is in
2352  hash form (if the var was set to true) or not.
2353  */
2361  /*
2362  Allocates the memory in the THD mem pool and initialize the members of
2363  this struct. It is prefererable to use this method to create a LEX_USER
2364  rather allocating the memory in the THD and initilizing the members
2365  explicitiyly.
2366  */
2367  static LEX_USER *alloc(THD *thd, LEX_STRING *user, LEX_STRING *host);
2368 };
2369 
2370 /**
2371  Derive type of metadata lock to be requested for table used by a DML
2372  statement from the type of THR_LOCK lock requested for this table.
2373 */
2374 
2375 inline enum enum_mdl_type mdl_type_for_dml(enum thr_lock_type lock_type) {
2376  return lock_type >= TL_WRITE_ALLOW_WRITE
2378  : MDL_SHARED_WRITE)
2379  : MDL_SHARED_READ;
2380 }
2381 
2382 /**
2383  Type of table which can be open for an element of table list.
2384 */
2385 
2390 };
2391 
2392 /**
2393  This structure is used to keep info about possible key for the result table
2394  of a derived table/view.
2395  The 'referenced_by' is the table map of tables to which this possible
2396  key corresponds.
2397  The 'used_field' is a map of fields of which this key consists of.
2398  See also the comment for the TABLE_LIST::update_derived_keys function.
2399 */
2400 
2402  public:
2405 };
2406 
2407 class Table_function;
2408 /*
2409  Table reference in the FROM clause.
2410 
2411  These table references can be of several types that correspond to
2412  different SQL elements. Below we list all types of TABLE_LISTs with
2413  the necessary conditions to determine when a TABLE_LIST instance
2414  belongs to a certain type.
2415 
2416  1) table (TABLE_LIST::view == NULL)
2417  - base table
2418  (TABLE_LIST::derived == NULL)
2419  - subquery - TABLE_LIST::table is a temp table
2420  (TABLE_LIST::derived != NULL)
2421  - information schema table
2422  (TABLE_LIST::schema_table != NULL)
2423  NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
2424  2) view (TABLE_LIST::view != NULL)
2425  - merge (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
2426  also (TABLE_LIST::field_translation != NULL)
2427  - temptable(TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TEMPTABLE)
2428  also (TABLE_LIST::field_translation == NULL)
2429  3) nested table reference (TABLE_LIST::nested_join != NULL)
2430  - table sequence - e.g. (t1, t2, t3)
2431  TODO: how to distinguish from a JOIN?
2432  - general JOIN
2433  TODO: how to distinguish from a table sequence?
2434  - NATURAL JOIN
2435  (TABLE_LIST::natural_join != NULL)
2436  - JOIN ... USING
2437  (TABLE_LIST::join_using_fields != NULL)
2438  - semi-join
2439  ;
2440 */
2441 
2442 struct TABLE_LIST {
2443  TABLE_LIST() = default;
2444 
2445  explicit TABLE_LIST(TABLE *table_arg) : table(table_arg) {}
2446 
2447  TABLE_LIST(const char *db_name_arg, size_t db_length_arg,
2448  const char *table_name_arg, size_t table_name_length_arg,
2449  const char *alias_arg, enum thr_lock_type lock_type_arg)
2450  : TABLE_LIST(nullptr, db_name_arg, db_length_arg, table_name_arg,
2451  table_name_length_arg, alias_arg, lock_type_arg) {}
2452 
2453  TABLE_LIST(const char *db_name_arg, size_t db_length_arg,
2454  const char *table_name_arg, size_t table_name_length_arg,
2455  const char *alias_arg, enum thr_lock_type lock_type_arg,
2456  enum enum_mdl_type mdl_request_type)
2457  : TABLE_LIST(nullptr, db_name_arg, db_length_arg, table_name_arg,
2458  table_name_length_arg, alias_arg, lock_type_arg) {
2459  mdl_request.set_type(mdl_request_type);
2460  }
2461 
2462  TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2463  const char *table_name_arg, size_t table_name_length_arg,
2464  const char *alias_arg, enum thr_lock_type lock_type_arg)
2465  : db(db_name_arg),
2466  table_name(table_name_arg),
2467  alias(alias_arg),
2468  m_map(1),
2469  table(table_arg),
2470  m_lock_descriptor{lock_type_arg},
2471  db_length(db_length_arg),
2472  table_name_length(table_name_length_arg) {
2475  }
2476 
2477  /**
2478  Sets an explicit enum_mdl_type value, without initializing
2479  m_lock_descriptor.
2480  */
2481  TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2482  const char *table_name_arg, size_t table_name_length_arg,
2483  const char *alias_arg, enum_mdl_type mdl_type)
2484  : db(db_name_arg),
2485  table_name(table_name_arg),
2486  alias(alias_arg),
2487  m_map(1),
2488  table(table_arg),
2489  db_length(db_length_arg),
2490  table_name_length(table_name_length_arg) {
2492  MDL_TRANSACTION);
2493  }
2494 
2495  /**
2496  Do not use this function in new code. It exists only for legacy code.
2497  Prepare TABLE_LIST that consists of one table instance to use in
2498  simple_open_and_lock_tables
2499  */
2500  inline void init_one_table(const char *db_name_arg, size_t db_length_arg,
2501  const char *table_name_arg,
2502  size_t table_name_length_arg,
2503  const char *alias_arg,
2504  enum thr_lock_type lock_type_arg) {
2505  *this = TABLE_LIST();
2506  m_map = 1;
2507  db = db_name_arg;
2508  db_length = db_length_arg;
2509  table_name = table_name_arg;
2510  table_name_length = table_name_length_arg;
2511  alias = alias_arg;
2512  m_lock_descriptor.type = lock_type_arg;
2515  }
2516 
2517  /**
2518  Do not use this function in new code. It exists only for legacy code.
2519  Auxiliary method which prepares TABLE_LIST consisting of one table instance
2520  to be used in simple open_and_lock_tables and takes type of MDL lock on the
2521  table as explicit parameter.
2522  */
2523 
2524  inline void init_one_table(const char *db_name_arg, size_t db_length_arg,
2525  const char *table_name_arg,
2526  size_t table_name_length_arg,
2527  const char *alias_arg,
2528  enum thr_lock_type lock_type_arg,
2529  enum enum_mdl_type mdl_request_type) {
2530  init_one_table(db_name_arg, db_length_arg, table_name_arg,
2531  table_name_length_arg, alias_arg, lock_type_arg);
2532  mdl_request.set_type(mdl_request_type);
2533  }
2534 
2535  /// Create a TABLE_LIST object representing a nested join
2536  static TABLE_LIST *new_nested_join(MEM_ROOT *allocator, const char *alias,
2538  List<TABLE_LIST> *belongs_to,
2539  SELECT_LEX *select);
2540 
2541  Item **join_cond_ref() { return &m_join_cond; }
2542  Item *join_cond() const { return m_join_cond; }
2543  void set_join_cond(Item *val) {
2544  // If optimization has started, it's too late to change m_join_cond.
2546  m_join_cond = val;
2547  }
2550  /*
2551  Either we are setting to "empty", or there must pre-exist a
2552  permanent condition.
2553  */
2554  DBUG_ASSERT(cond == NULL || cond == (Item *)1 || m_join_cond != NULL);
2555  m_join_cond_optim = cond;
2556  }
2558 
2559  /// @returns true if semi-join nest
2560  bool is_sj_nest() const { return m_is_sj_or_aj_nest && !m_join_cond; }
2561  /// @returns true if anti-join nest
2562  bool is_aj_nest() const { return m_is_sj_or_aj_nest && m_join_cond; }
2563  /// @returns true if anti/semi-join nest
2564  bool is_sj_or_aj_nest() const { return m_is_sj_or_aj_nest; }
2565  /// Makes the next a semi/antijoin nest
2568  m_is_sj_or_aj_nest = true;
2569  }
2570 
2571  /// Merge tables from a query block into a nested join structure
2572  bool merge_underlying_tables(SELECT_LEX *select);
2573 
2574  /// Reset table
2575  void reset();
2576 
2577  /// Evaluate the check option of a view
2578  int view_check_option(THD *thd) const;
2579 
2580  /// Cleanup field translations for a view
2581  void cleanup_items();
2582 
2583  /// Produce a textual identification of this object
2584  void print(const THD *thd, String *str, enum_query_type query_type) const;
2585 
2586  /// Check which single table inside a view that matches a table map
2587  bool check_single_table(TABLE_LIST **table_ref, table_map map);
2588 
2589  /// Allocate a buffer for inserted column values
2591 
2594  bool is_leaf_for_name_resolution() const;
2595 
2596  /// Return the outermost view this table belongs to, or itself
2597  inline const TABLE_LIST *top_table() const {
2598  return belong_to_view ? belong_to_view : this;
2599  }
2600 
2601  inline TABLE_LIST *top_table() {
2602  return const_cast<TABLE_LIST *>(
2603  const_cast<const TABLE_LIST *>(this)->top_table());
2604  }
2605 
2606  /// Prepare check option for a view
2607  bool prepare_check_option(THD *thd, bool is_cascaded = false);
2608 
2609  /// Merge WHERE condition of view or derived table into outer query
2610  bool merge_where(THD *thd);
2611 
2612  /// Prepare replace filter for a view (used for REPLACE command)
2613  bool prepare_replace_filter(THD *thd);
2614 
2615  /// Return true if this represents a named view
2616  bool is_view() const { return view != NULL; }
2617 
2618  /// Return true if this represents a derived table (an unnamed view)
2619  bool is_derived() const { return derived != NULL && view == NULL; }
2620 
2621  /// Return true if this represents a named view or a derived table
2622  bool is_view_or_derived() const { return derived != NULL; }
2623 
2624  /// Return true if this represents a table function
2625  bool is_table_function() const { return table_function != NULL; }
2626  /**
2627  @returns true if this is a recursive reference inside the definition of a
2628  recursive CTE.
2629  @note that it starts its existence as a dummy derived table, until the
2630  end of resolution when it's not a derived table anymore, just a reference
2631  to the materialized temporary table. Whereas a non-recursive
2632  reference to the recursive CTE is a derived table.
2633  */
2635 
2636  /**
2637  @see is_recursive_reference().
2638  @returns true if error
2639  */
2640  bool set_recursive_reference();
2641 
2642  /**
2643  @returns true for a table that represents an optimizer internal table,
2644  is a derived table, a recursive reference, a table function.
2645  Internal tables are only visible inside a query expression, and is hence
2646  not visible in any schema, or need any kind of privilege checking.
2647  */
2648  bool is_internal() const {
2650  }
2651 
2652  /**
2653  @returns true for a table that is a placeholder, ie a derived table,
2654  a view, a recursive reference, a table function or a schema table.
2655  A table is also considered to be a placeholder if it does not have a
2656  TABLE object for some other reason.
2657  */
2658  bool is_placeholder() const {
2660  is_table_function() || schema_table || table == nullptr;
2661  }
2662 
2663  /// Return true if view or derived table and can be merged
2664  bool is_mergeable() const;
2665 
2666  /**
2667  @returns true if materializable table contains one or zero rows.
2668 
2669  Returning true implies that the table is materialized during optimization,
2670  so it need not be optimized during execution.
2671  */
2672  bool materializable_is_const() const;
2673 
2674  /// Return true if this is a derived table or view that is merged
2676 
2677  /// Set table to be merged
2678  void set_merged() {
2681  }
2682 
2683  /// Return true if this is a materializable derived table/view
2684  bool uses_materialization() const {
2686  }
2687 
2688  /// Set table to be materialized
2690  // @todo We should do this only once, but currently we cannot:
2691  // DBUG_ASSERT(effective_algorithm == VIEW_ALGORITHM_UNDEFINED);
2694  }
2695 
2696  /// Return true if table is updatable
2697  bool is_updatable() const { return m_updatable; }
2698 
2699  /// Set table as updatable. (per default, a table is non-updatable)
2700  void set_updatable() { m_updatable = true; }
2701 
2702  /// Return true if table is insertable-into
2703  bool is_insertable() const { return m_insertable; }
2704 
2705  /// Set table as insertable-into. (per default, a table is not insertable)
2706  void set_insertable() { m_insertable = true; }
2707 
2708  /**
2709  Set table as readonly, ie it is neither updatable, insertable nor
2710  deletable during this statement.
2711  */
2712  void set_readonly() {
2713  m_updatable = false;
2714  m_insertable = false;
2715  }
2716 
2717  /**
2718  Return true if this is a view or derived table that is defined over
2719  more than one base table, and false otherwise.
2720  */
2721  bool is_multiple_tables() const {
2722  if (is_view_or_derived()) {
2723  DBUG_ASSERT(is_merged()); // Cannot be a materialized view
2724  return leaf_tables_count() > 1;
2725  } else {
2726  DBUG_ASSERT(nested_join == NULL); // Must be a base table
2727  return false;
2728  }
2729  }
2730 
2731  /// Return no. of base tables a merged view or derived table is defined over.
2732  uint leaf_tables_count() const;
2733 
2734  /// Return first leaf table of a base table or a view/derived table
2736  TABLE_LIST *tr = this;
2737  while (tr->merge_underlying_list) tr = tr->merge_underlying_list;
2738  return tr;
2739  }
2740 
2741  /// Return any leaf table that is not an inner table of an outer join
2742  /// @todo when WL#6570 is implemented, replace with first_leaf_table()
2744  TABLE_LIST *tr = this;
2745  while (tr->merge_underlying_list) {
2746  tr = tr->merge_underlying_list;
2747  /*
2748  "while" is used, however, an "if" might be sufficient since there is
2749  no more than one inner table in a join nest (with outer_join true).
2750  */
2751  while (tr->outer_join) tr = tr->next_local;
2752  }
2753  return tr;
2754  }
2755  /**
2756  Set the LEX object of a view (will also define this as a view).
2757  @note: The value 1 is used to indicate a view but without a valid
2758  query object. Use only if the LEX object is not going to
2759  be used in later processing.
2760  */
2761  void set_view_query(LEX *lex) { view = lex; }
2762 
2763  /// Return the valid LEX object for a view.
2764  LEX *view_query() const {
2765  DBUG_ASSERT(view != NULL && view != (LEX *)1);
2766  return view;
2767  }
2768 
2769  /**
2770  Set the query expression of a derived table or view.
2771  (Will also define this as a derived table, unless it is a named view.)
2772  */
2773  void set_derived_unit(SELECT_LEX_UNIT *query_expr) { derived = query_expr; }
2774 
2775  /// Return the query expression of a derived table or view.
2778  return derived;
2779  }
2780 
2781  /// Save names of materialized table @see reset_name_temporary
2783  view_db.str = db;
2787  }
2788 
2789  /// Set temporary name from underlying temporary table:
2794  db = "";
2795  db_length = 0;
2796  }
2797 
2798  /// Reset original name for temporary table.
2802  /*
2803  When printing a query using a view or CTE, we need the table's name and
2804  the alias; the name has been destroyed if the table was materialized,
2805  so we restore it:
2806  */
2810  if (is_view()) // restore database's name too
2811  {
2812  DBUG_ASSERT(db != view_db.str);
2813  db = view_db.str;
2815  }
2816  }
2817 
2818  /// Resolve a derived table or view reference
2819  bool resolve_derived(THD *thd, bool apply_semijoin);
2820 
2821  /// Optimize the query expression representing a derived table/view
2822  bool optimize_derived(THD *thd);
2823 
2824  /// Create result table for a materialized derived table/view
2825  bool create_materialized_table(THD *thd);
2826 
2827  /// Materialize derived table
2828  bool materialize_derived(THD *thd);
2829 
2830  /// Clean up the query expression for a materialized derived table
2831  bool cleanup_derived(THD *thd);
2832 
2833  /// Prepare security context for a view
2834  bool prepare_security(THD *thd);
2835 
2838 
2839  /// Cleanup for re-execution in a prepared statement or a stored procedure.
2840  void reinit_before_use(THD *thd);
2841 
2842  /**
2843  Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query,
2844  TABLE::keys_in_use_for_group_by, TABLE::keys_in_use_for_order_by,
2845  TABLE::force_index and TABLE::covering_keys.
2846  */
2847  bool process_index_hints(const THD *thd, TABLE *table);
2848 
2849  /**
2850  Compare the version of metadata from the previous execution
2851  (if any) with values obtained from the current table
2852  definition cache element.
2853 
2854  @sa check_and_update_table_version()
2855  */
2857  return (m_table_ref_type == s->get_table_ref_type() &&
2859  }
2860 
2861  /**
2862  Record the value of metadata version of the corresponding
2863  table definition cache element in this parse tree node.
2864 
2865  @sa check_and_update_table_version()
2866  */
2869  }
2870 
2871  void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
2872  ulonglong table_ref_version_arg) {
2873  m_table_ref_type = table_ref_type_arg;
2874  m_table_ref_version = table_ref_version_arg;
2875  }
2876 
2877  /**
2878  If a derived table, returns query block id of first underlying query block.
2879  Zero if not derived.
2880  */
2881  uint query_block_id() const;
2882 
2883  /**
2884  This is for showing in EXPLAIN.
2885  If a derived table, returns query block id of first underlying query block
2886  of first materialized TABLE_LIST instance. Zero if not derived.
2887  */
2889 
2890  /**
2891  @brief Returns the name of the database that the referenced table belongs
2892  to.
2893  */
2894  const char *get_db_name() const { return view != NULL ? view_db.str : db; }
2895 
2896  /**
2897  @brief Returns the name of the table that this TABLE_LIST represents.
2898 
2899  @details The unqualified table name or view name for a table or view,
2900  respectively.
2901  */
2902  const char *get_table_name() const {
2903  return view != NULL ? view_name.str : table_name;
2904  }
2905  int fetch_number_of_rows();
2906  bool update_derived_keys(THD *, Field *, Item **, uint, bool *);
2907  bool generate_keys();
2908 
2909  /// Setup a derived table to use materialization
2910  bool setup_materialized_derived(THD *thd);
2912 
2913  /// Setup a table function to use materialization
2914  bool setup_table_function(THD *thd);
2915 
2916  bool create_field_translation(THD *thd);
2917 
2918  /**
2919  @brief Returns the outer join nest that this TABLE_LIST belongs to, if any.
2920 
2921  @details There are two kinds of join nests, outer-join nests and semi-join
2922  nests. This function returns non-NULL in the following cases:
2923  @li 1. If this table/nest is embedded in a nest and this nest IS NOT a
2924  semi-join nest. (In other words, it is an outer-join nest.)
2925  @li 2. If this table/nest is embedded in a nest and this nest IS a
2926  semi-join nest, but this semi-join nest is embedded in another
2927  nest. (This other nest will be an outer-join nest, since all inner
2928  joined nested semi-join nests have been merged in
2929  @c simplify_joins() ).
2930  Note: This function assumes that @c simplify_joins() has been performed.
2931  Before that, join nests will be present for all types of join.
2932 
2933  @return outer join nest, or NULL if none.
2934  */
2935 
2937  if (!embedding) return NULL;
2938  if (embedding->is_sj_nest()) return embedding->embedding;
2939  return embedding;
2940  }
2941  /**
2942  Return true if this table is an inner table of some outer join.
2943 
2944  Examine all the embedding join nests of the table.
2945  @note This function works also before redundant join nests have been
2946  eliminated.
2947 
2948  @return true if table is an inner table of some outer join, false otherwise.
2949  */
2950 
2952  if (outer_join) return true;
2953  for (TABLE_LIST *emb = embedding; emb; emb = emb->embedding) {
2954  if (emb->outer_join) return true;
2955  }
2956  return false;
2957  }
2958 
2959  /**
2960  Return the base table entry of an updatable table.
2961  In DELETE and UPDATE, a view used as a target table must be mergeable,
2962  updatable and defined over a single table.
2963  */
2965  const TABLE_LIST *tbl = this;
2966  DBUG_ASSERT(tbl->is_updatable() && !tbl->is_multiple_tables());
2967  while (tbl->is_view_or_derived()) {
2968  tbl = tbl->merge_underlying_list;
2969  DBUG_ASSERT(tbl->is_updatable() && !tbl->is_multiple_tables());
2970  }
2971  return tbl;
2972  }
2973 
2975  return const_cast<TABLE_LIST *>(
2976  static_cast<const TABLE_LIST *>(this)->updatable_base_table());
2977  }
2978 
2979  /**
2980  Mark that there is a NATURAL JOIN or JOIN ... USING between two tables.
2981 
2982  This function marks that table b should be joined with a either via
2983  a NATURAL JOIN or via JOIN ... USING. Both join types are special
2984  cases of each other, so we treat them together. The function
2985  setup_conds() creates a list of equal condition between all fields
2986  of the same name for NATURAL JOIN or the fields in
2987  TABLE_LIST::join_using_fields for JOIN ... USING.
2988  The list of equality conditions is stored
2989  either in b->join_cond(), or in JOIN::conds, depending on whether there
2990  was an outer join.
2991 
2992  EXAMPLE
2993  @verbatim
2994  SELECT * FROM t1 NATURAL LEFT JOIN t2
2995  <=>
2996  SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
2997 
2998  SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
2999  <=>
3000  SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
3001 
3002  SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
3003  <=>
3004  SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
3005  @endverbatim
3006 
3007  @param b Right join argument.
3008  */
3009  void add_join_natural(TABLE_LIST *b) { b->natural_join = this; }
3010 
3011  /**
3012  Set granted privileges for a table.
3013 
3014  Can be used when generating temporary tables that are also used in
3015  resolver process, such as when generating a UNION table
3016 
3017  @param privilege Privileges granted for this table.
3018  */
3019  void set_privileges(ulong privilege) { grant.privilege |= privilege; }
3020  /*
3021  List of tables local to a subquery or the top-level SELECT (used by
3022  SQL_I_List). Considers views as leaves (unlike 'next_leaf' below).
3023  Created at parse time in SELECT_LEX::add_table_to_list() ->
3024  table_list.link_in_list().
3025  */
3027  /* link in a global list of all queries tables */
3028  TABLE_LIST *next_global{nullptr}, **prev_global{nullptr};
3029  const char *db{nullptr}, *table_name{nullptr}, *alias{nullptr};
3030  /*
3031  Target tablespace name: When creating or altering tables, this
3032  member points to the tablespace_name in the HA_CREATE_INFO struct.
3033  */
3035  char *schema_table_name{nullptr};
3036  char *option{nullptr}; /* Used by cache index */
3037 
3038  /** Table level optimizer hints for this table. */
3040  /* Hints for query block of this table. */
3042 
3045  }
3046 
3048 
3049  private:
3050  /**
3051  The members below must be kept aligned so that (1 << m_tableno) == m_map.
3052  A table that takes part in a join operation must be assigned a unique
3053  table number.
3054  */
3055  uint m_tableno{0}; ///< Table number within query block
3056  table_map m_map{0}; ///< Table map, derived from m_tableno
3057  /**
3058  If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this
3059  member points to C. May also be generated from JOIN ... USING clause.
3060  It may be modified only by permanent transformations (permanent = done
3061  once for all executions of a prepared statement).
3062  */
3063  Item *m_join_cond{nullptr};
3064  bool m_is_sj_or_aj_nest{false};
3065 
3066  public:
3067  /*
3068  (Valid only for semi-join nests) Bitmap of tables that are within the
3069  semi-join (this is different from bitmap of all nest's children because
3070  tables that were pulled out of the semi-join nest remain listed as
3071  nest's children).
3072  */
3074 
3075  /*
3076  During parsing - left operand of NATURAL/USING join where 'this' is
3077  the right operand. After parsing (this->natural_join == this) iff
3078  'this' represents a NATURAL or USING join operation. Thus after
3079  parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
3080  */
3082  /*
3083  True if 'this' represents a nested join that is a NATURAL JOIN.
3084  For one of the operands of 'this', the member 'natural_join' points
3085  to the other operand of 'this'.
3086  */
3087  bool is_natural_join{false};
3088  /* Field names in a USING clause for JOIN ... USING. */
3090  /*
3091  Explicitly store the result columns of either a NATURAL/USING join or
3092  an operand of such a join.
3093  */
3095  /* true if join_columns contains all columns of this table reference. */
3097 
3098  /*
3099  List of nodes in a nested join tree, that should be considered as
3100  leaves with respect to name resolution. The leaves are: views,
3101  top-most nodes representing NATURAL/USING joins, subqueries, and
3102  base tables. All of these TABLE_LIST instances contain a
3103  materialized list of columns. The list is local to a subquery.
3104  */
3106  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
3108  TABLE *table{nullptr}; /* opened table */
3109  Table_id table_id{}; /* table id (from binlog) for opened table */
3110  /*
3111  Query_result for derived table to pass it from table creation to table
3112  filling procedure
3113  */
3115  /*
3116  Reference from aux_tables to local list entry of main select of
3117  multi-delete statement:
3118  delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
3119  here it will be reference of first occurrence of t1 to second (as you
3120  can see this lists can't be merged)
3121  */
3123 
3124  /*
3125  Holds the function used as the table function
3126  */
3128 
3129  private:
3130  /**
3131  This field is set to non-null for derived tables and views. It points
3132  to the SELECT_LEX_UNIT representing the derived table/view.
3133  E.g. for a query
3134  @verbatim SELECT * FROM (SELECT a FROM t1) b @endverbatim
3135  */
3136  SELECT_LEX_UNIT *derived{nullptr}; /* SELECT_LEX_UNIT of derived table */
3137 
3138  /// If non-NULL, the CTE which this table is derived from.
3140  /**
3141  If the user has specified column names with the syntaxes "table name
3142  parenthesis column names":
3143  WITH qn(column names) AS (select...)
3144  or
3145  FROM (select...) dt(column names)
3146  or
3147  CREATE VIEW v(column_names) AS ...
3148  then this points to the list of column names. NULL otherwise.
3149  */
3151 
3152  public:
3153  ST_SCHEMA_TABLE *schema_table{nullptr}; /* Information_schema table */
3155  /*
3156  True when the view field translation table is used to convert
3157  schema table fields for backwards compatibility with SHOW command.
3158  */
3161  /* link to select_lex where this table was used */
3163 
3164  private:
3165  LEX *view{nullptr}; /* link on VIEW lex for merging */
3166 
3167  public:
3168  /// Array of selected expressions from a derived table or view.
3170 
3171  /// pointer to element after last one in translation table above
3173  /*
3174  List (based on next_local) of underlying tables of this view. I.e. it
3175  does not include the tables of subqueries used in the view. Is set only
3176  for merged views.
3177  */
3179  /*
3180  - 0 for base tables
3181  - in case of the view it is the list of all (not only underlying
3182  tables but also used in subquery ones) tables of the view.
3183  */
3185  /* most upper view this table belongs to */
3187  /*
3188  The view directly referencing this table
3189  (non-zero only for merged underlying tables of a view).
3190  */
3192  /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
3194  /*
3195  Security context (non-zero only for tables which belong
3196  to view with SQL SECURITY DEFINER)
3197  */
3199  /*
3200  This view security context (non-zero only for views with
3201  SQL SECURITY DEFINER)
3202  */
3204  /*
3205  List of all base tables local to a subquery including all view
3206  tables. Unlike 'next_local', this in this list views are *not*
3207  leaves. Created in setup_tables() -> make_leaf_tables().
3208  */
3210  Item *derived_where_cond{nullptr}; ///< WHERE condition from derived table
3211  Item *check_option{nullptr}; ///< WITH CHECK OPTION condition
3212  Item *replace_filter{nullptr}; ///< Filter for REPLACE command
3213  LEX_STRING select_stmt{nullptr, 0}; ///< text of (CREATE/SELECT) statement
3214  LEX_STRING source{nullptr, 0}; ///< source of CREATE VIEW
3215  LEX_CSTRING view_db{nullptr, 0}; ///< saved view database
3216  LEX_CSTRING view_name{nullptr, 0}; ///< saved view name
3217  LEX_STRING timestamp{nullptr, 0}; ///< GMT time stamp of last operation
3218  LEX_USER definer; ///< definer of view
3219  /**
3220  @note: This field is currently not reliable when read from dictionary:
3221  If an underlying view is changed, updatable_view is not changed,
3222  due to lack of dependency checking in dictionary implementation.
3223  Prefer to use is_updatable() during preparation and optimization.
3224  */
3225  ulonglong updatable_view{0}; ///< VIEW can be updated
3226  /**
3227  @brief The declared algorithm, if this is a view.
3228  @details One of
3229  - VIEW_ALGORITHM_UNDEFINED
3230  - VIEW_ALGORITHM_TEMPTABLE
3231  - VIEW_ALGORITHM_MERGE
3232  @todo Replace with an enum
3233  */
3235  ulonglong view_suid{0}; ///< view is suid (true by default)
3236  ulonglong with_check{0}; ///< WITH CHECK OPTION
3237 
3238  private:
3239  /// The view algorithm that is actually used, if this is a view.
3242 
3243  public:
3245 
3246  public:
3247  uint outer_join{0}; /* Which join type */
3248  uint shared{0}; /* Used in multi-upd */
3249  size_t db_length{0};
3251 
3252  private:
3253  bool m_updatable{false}; /* VIEW/TABLE can be updated */
3254  bool m_insertable{false}; /* VIEW/TABLE can be inserted into */
3255  public:
3256  bool straight{false}; /* optimize with prev table */
3257  /**
3258  True for tables and views being changed in a data change statement.
3259  Also used by replication to filter out statements that can be ignored,
3260  especially important for multi-table UPDATE and DELETE.
3261  */
3262  bool updating{false};
3263  /// True if using an index is preferred over a table scan.
3264  bool force_index{false};
3265  /// preload only non-leaf nodes (IS THIS USED???)
3266  bool ignore_leaves{false};
3267  /**
3268  The set of tables in the query block that this table depends on.
3269  Can be set due to outer join, join order hints or NOT EXISTS relationship.
3270  */
3272  /// The outer tables that an outer join's join condition depends on
3274  /**
3275  Is non-NULL if this table reference is a nested join, ie it represents
3276  the inner tables of an outer join, the tables contained in the
3277  parentheses of an inner join (eliminated during resolving), the tables
3278  referenced in a derived table or view, in a semi-join nest, the tables
3279  from the subquery.
3280  */
3282  /// The nested join containing this table reference.
3284  /// The join list immediately containing this table reference
3286  /// stop PS caching
3287  bool cacheable_table{false};
3288  /**
3289  Specifies which kind of table should be open for this element
3290  of table list.
3291  */
3293  /* true if this merged view contain auto_increment field */
3295  /// true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
3297  /// true <=> Filter condition is processed
3299 
3301  char timestamp_buffer[20]{0}; /* buffer for timestamp (19+1) */
3302  /*
3303  This TABLE_LIST object is just placeholder for prelocking, it will be
3304  used for implicit LOCK TABLES only and won't be used in real statement.
3305  */
3307  /**
3308  Indicates that if TABLE_LIST object corresponds to the table/view
3309  which requires special handling.
3310  */
3311  enum {
3312  /* Normal open. */
3314  /* Associate a table share only if the the table exists. */
3316  /*
3317  Associate a table share only if the the table exists.
3318  Also upgrade metadata lock to exclusive if table doesn't exist.
3319  */
3321  /* Don't associate a table share. */
3323  } open_strategy{OPEN_NORMAL};
3324  bool internal_tmp_table{false};
3325  /** true if an alias for this table was specified in the SQL. */
3326  bool is_alias{false};
3327  /** true if the table is referred to in the statement using a fully
3328  qualified name (@<db_name@>.@<table_name@>).
3329  */
3330  bool is_fqtn{false};
3331 
3332  /* View creation context. */
3333 
3335 
3336  /*
3337  Attributes to save/load view creation context in/from frm-file.
3338 
3339  They are required only to be able to use existing parser to load
3340  view-definition file. As soon as the parser parsed the file, view
3341  creation context is initialized and the attributes become redundant.
3342 
3343  These attributes MUST NOT be used for any purposes but the parsing.
3344  */
3345 
3348 
3349  /*
3350  View definition (SELECT-statement) in the UTF-form.
3351  */
3352 
3354 
3355  // True, If this is a system view
3356  bool is_system_view{false};
3357 
3358  /*
3359  Set to 'true' if this is a DD table being opened in the context of a
3360  dictionary operation. Note that when 'false', this may still be a DD
3361  table when opened in a non-DD context, e.g. as part of an I_S view
3362  query.
3363  */
3364  bool is_dd_ctx_table{false};
3365 
3366  /* End of view definition context. */
3367 
3368  /* List of possible keys. Valid only for materialized derived tables/views. */
3370 
3371  /**
3372  Indicates what triggers we need to pre-load for this TABLE_LIST
3373  when opening an associated TABLE. This is filled after
3374  the parsed tree is created.
3375  */
3378  bool has_db_lookup_value{false};
3382 
3384 
3385  /// if true, EXPLAIN can't explain view due to insufficient rights.
3386  bool view_no_explain{false};
3387 
3388  /* List to carry partition names from PARTITION (...) clause in statement */
3390 
3391  /// Set table number
3394  m_tableno = tableno;
3395  m_map = (table_map)1 << tableno;
3396  }
3397  /// Return table number
3398  uint tableno() const { return m_tableno; }
3399 
3400  /// Return table map derived from table number
3401  table_map map() const {
3402  DBUG_ASSERT(((table_map)1 << m_tableno) == m_map);
3403  return m_map;
3404  }
3405 
3406  /// If non-NULL, the CTE which this table is derived from.
3409  /// @see m_derived_column_names
3411  return m_derived_column_names;
3412  }
3415  }
3416  void propagate_table_maps(table_map map_arg);
3417 
3418  private:
3419  /*
3420  A group of members set and used only during JOIN::optimize().
3421  */
3422  /**
3423  Optimized copy of m_join_cond (valid for one single
3424  execution). Initialized by SELECT_LEX::get_optimizable_conditions().
3425  @todo it would be goo dto reset it in reinit_before_use(), if
3426  reinit_stmt_before_use() had a loop including join nests.
3427  */
3429 
3430  public:
3431  COND_EQUAL *cond_equal{nullptr}; ///< Used with outer join
3432  /// true <=> this table is a const one and was optimized away.
3433  bool optimized_away{false};
3434  /**
3435  true <=> all possible keys for a derived table were collected and
3436  could be re-used while statement re-execution.
3437  */
3438  bool derived_keys_ready{false};
3439 
3440  private:
3441  /// If a recursive reference inside the definition of a CTE.
3443  // End of group for optimization
3444 
3445  private:
3446  /** See comments for set_metadata_id() */
3448  /** See comments for TABLE_SHARE::get_table_ref_version() */
3450 };
3451 
3452 /*
3453  Iterator over the fields of a generic table reference.
3454 */
3455 
3457  public:
3458  Field_iterator() {} /* Remove gcc warning */
3459  virtual ~Field_iterator() {}
3460  virtual void set(TABLE_LIST *) = 0;
3461  virtual void next() = 0;
3462  virtual bool end_of_fields() = 0; /* Return 1 at end of list */
3463  virtual const char *name() = 0;
3464  virtual Item *create_item(THD *) = 0;
3465  virtual Field *field() = 0;
3466 };
3467 
3468 /*
3469  Iterator over the fields of a base table, view with temporary
3470  table, or subquery.
3471 */
3472 
3475 
3476  public:
3478  void set(TABLE_LIST *table) { ptr = table->table->field; }
3479  void set_table(TABLE *table) { ptr = table->field; }
3480  void next() { ptr++; }
3481  bool end_of_fields() { return *ptr == 0; }
3482  const char *name();
3483  Item *create_item(THD *thd);
3484  Field *field() { return *ptr; }
3485 };
3486 
3487 /**
3488  Iterator over the fields of a merged derived table or view.
3489 */
3490 
3494 
3495  public:
3497  void set(TABLE_LIST *table);
3498  void next() { ptr++; }
3499  bool end_of_fields() { return ptr == array_end; }
3500  const char *name();
3501  Item *create_item(THD *thd);
3502  Item **item_ptr() { return &ptr->item; }
3503  Field *field() { return 0; }
3504  inline Item *item() { return ptr->item; }
3506 };
3507 
3508 /*
3509  Field_iterator interface to the list of materialized fields of a
3510  NATURAL/USING join.
3511 */
3512 
3516 
3517  public:
3520  void set(TABLE_LIST *table);
3521  void next();
3522  bool end_of_fields() { return !cur_column_ref; }
3523  const char *name() { return cur_column_ref->name(); }
3524  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
3525  Field *field() { return cur_column_ref->field(); }
3527 };
3528 
3529 /**
3530  Generic iterator over the fields of an arbitrary table reference.
3531 
3532  This class unifies the various ways of iterating over the columns
3533  of a table reference depending on the type of SQL entity it
3534  represents. If such an entity represents a nested table reference,
3535  this iterator encapsulates the iteration over the columns of the
3536  members of the table reference.
3537 
3538  The implementation assumes that all underlying NATURAL/USING table
3539  references already contain their result columns and are linked into
3540  the list TABLE_LIST::next_name_resolution_table.
3541 */
3542 
3549  void set_field_iterator();
3550 
3551  public:
3553  void set(TABLE_LIST *table);
3554  void next();
3555  bool end_of_fields() {
3556  return (table_ref == last_leaf && field_it->end_of_fields());
3557  }
3558  const char *name() { return field_it->name(); }
3559  const char *get_table_name();
3560  const char *get_db_name();
3561  GRANT_INFO *grant();
3562  Item *create_item(THD *thd) { return field_it->create_item(thd); }
3563  Field *field() { return field_it->field(); }
3565  TABLE_LIST *parent_table_ref);
3567 };
3568 
3569 /**
3570  An iterator over an intrusive list in TABLE_LIST objects. Can be used for
3571  iterating an intrusive list in e.g. range-based for loops.
3572 
3573  @tparam Next_pointer The intrusive list's "next" member.
3574 */
3575 template <TABLE_LIST *TABLE_LIST::*Next_pointer>
3577  public:
3578  /**
3579  Constructs an iterator.
3580 
3581  @param start The TABLE_LIST where that the iterator will start iterating
3582  from.
3583  */
3585 
3586  TABLE_LIST *operator++() { return m_current = m_current->*Next_pointer; }
3587 
3589 
3590  bool operator!=(const Table_list_iterator &other) const {
3591  return m_current != other.m_current;
3592  }
3593 
3594  private:
3596 };
3597 
3600 
3601 /**
3602  Provides a list interface on TABLE_LIST objects. The interface is similar to
3603  std::vector, but has only the bare minimum to allow for iteration.
3604 
3605  @tparam Iterator_type Must have an implicit constructor from a TABLE_LIST
3606  pointer, and support pre-increment, non-equality and dereference operators.
3607 */
3608 template <typename Iterator_type>
3610  public:
3611  /**
3612  Constructs the list adapter.
3613 
3614  @param first The TABLE_LIST that is considered first in the list.
3615  */
3617 
3618  /// An iterator pointing to the first TABLE_LIST.
3619  Iterator_type begin() { return m_first; }
3620 
3621  /// A past-the-end iterator.
3622  Iterator_type end() { return nullptr; }
3623 
3624  private:
3626 };
3627 
3628 /// A list interface over the TABLE_LIST::next_local pointer.
3630 
3631 /// A list interface over the TABLE_LIST::next_global pointer.
3633 
3636  char *db, *table;
3638 };
3639 
3641  MY_BITMAP *bitmap) {
3642  my_bitmap_map *old = bitmap->bitmap;
3643  bitmap->bitmap = table->s->all_set.bitmap; // does not repoint last_word_ptr
3644  return old;
3645 }
3646 
3647 static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
3648  my_bitmap_map *old) {
3649  bitmap->bitmap = old;
3650 }
3651 
3652 /* The following is only needed for debugging */
3653 
3655  TABLE *table MY_ATTRIBUTE((unused)),
3656  MY_BITMAP *bitmap MY_ATTRIBUTE((unused))) {
3657 #ifndef DBUG_OFF
3658  return tmp_use_all_columns(table, bitmap);
3659 #else
3660  return 0;
3661 #endif
3662 }
3663 
3664 static inline void dbug_tmp_restore_column_map(
3665  MY_BITMAP *bitmap MY_ATTRIBUTE((unused)),
3666  my_bitmap_map *old MY_ATTRIBUTE((unused))) {
3667 #ifndef DBUG_OFF
3668  tmp_restore_column_map(bitmap, old);
3669 #endif
3670 }
3671 
3672 /*
3673  Variant of the above : handle both read and write sets.
3674  Provide for the possiblity of the read set being the same as the write set
3675 */
3676 static inline void dbug_tmp_use_all_columns(
3677  TABLE *table MY_ATTRIBUTE((unused)),
3678  my_bitmap_map **save MY_ATTRIBUTE((unused)),
3679  MY_BITMAP *read_set MY_ATTRIBUTE((unused)),
3680  MY_BITMAP *write_set MY_ATTRIBUTE((unused))) {
3681 #ifndef DBUG_OFF
3682  save[0] = read_set->bitmap;
3683  save[1] = write_set->bitmap;
3684  (void)tmp_use_all_columns(table, read_set);
3685  (void)tmp_use_all_columns(table, write_set);
3686 #endif
3687 }
3688 
3689 static inline void dbug_tmp_restore_column_maps(
3690  MY_BITMAP *read_set MY_ATTRIBUTE((unused)),
3691  MY_BITMAP *write_set MY_ATTRIBUTE((unused)),
3692  my_bitmap_map **old MY_ATTRIBUTE((unused))) {
3693 #ifndef DBUG_OFF
3694  tmp_restore_column_map(read_set, old[0]);
3695  tmp_restore_column_map(write_set, old[1]);
3696 #endif
3697 }
3698 
3699 void init_mdl_requests(TABLE_LIST *table_list);
3700 
3701 /**
3702  Unpacks the definition of a generated column, default expression or check
3703  constraint expression passed as argument. Parses the text obtained from
3704  TABLE_SHARE and produces an Item.
3705 
3706  @param thd Thread handler
3707  @param table Table with the checked field
3708  @param val_generator The expression to unpack.
3709  @param source Source of value generator(a generated column,
3710  a regular column with generated default value or
3711  a check constraint).
3712  @param source_name Name of the source (generated column, a reguler
3713  column with generated default value or a check
3714  constraint).
3715  @param field Pointer to Field object
3716  @param is_create_table Indicates that table is opened as part
3717  of CREATE or ALTER and does not yet exist in SE
3718  @param error_reported updated flag for the caller that no other error
3719  messages are to be generated.
3720 
3721  @retval true Failure.
3722  @retval false Success.
3723 */
3724 
3725 bool unpack_value_generator(THD *thd, TABLE *table,
3726  Value_generator **val_generator,
3727  Value_generator_source source,
3728  const char *source_name, Field *field,
3729  bool is_create_table, bool *error_reported);
3730 
3731 /**
3732  Unpack the partition expression. Parse the partition expression
3733  to produce an Item.
3734 
3735  @param[in] thd Thread handler
3736  @param[in] outparam Table object
3737  @param[in] share TABLE_SHARE object
3738  @param[in] engine_type Engine type of the partitions.
3739  @param[in] is_create_table Indicates that table is opened as part of
3740  CREATE or ALTER and does not yet exist in SE
3741 
3742  @retval true Failure.
3743  @retval false Success.
3744 */
3745 
3746 bool unpack_partition_info(THD *thd, TABLE *outparam, TABLE_SHARE *share,
3747  handlerton *engine_type, bool is_create_table);
3748 
3749 int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
3750  uint db_stat, uint prgflag, uint ha_open_flags,
3751  TABLE *outparam, bool is_create_table,
3752  const dd::Table *table_def_param);
3753 TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
3754  const char *key, size_t key_length,
3755  bool open_secondary);
3756 void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
3757  size_t key_length, const char *table_name,
3758  const char *path, MEM_ROOT *mem_root);
3759 void free_table_share(TABLE_SHARE *share);
3761 Ident_name_check check_db_name(const char *name, size_t length);
3763  bool preserve_lettercase);
3764 bool check_column_name(const char *name);
3765 Ident_name_check check_table_name(const char *name, size_t length);
3766 int rename_file_ext(const char *from, const char *to, const char *ext);
3767 char *get_field(MEM_ROOT *mem, Field *field);
3768 bool get_field(MEM_ROOT *mem, Field *field, class String *res);
3769 
3770 int closefrm(TABLE *table, bool free_share);
3771 void free_blobs(TABLE *table);
3772 void free_blob_buffers_and_reset(TABLE *table, uint32 size);
3773 int set_zone(int nr, int min_zone, int max_zone);
3774 void append_unescaped(String *res, const char *pos, size_t length);
3775 char *fn_rext(char *name);
3777  const LEX_CSTRING &name);
3778 
3779 /* performance schema */
3781 
3783 extern LEX_STRING SLOW_LOG_NAME;
3784 
3785 /* information schema */
3787 
3788 /* mysql schema name and DD ID */
3790 static const uint MYSQL_SCHEMA_DD_ID = 1;
3791 
3792 /* mysql tablespace name and DD ID */
3794 static const uint MYSQL_TABLESPACE_DD_ID = 1;
3795 
3796 /* replication's tables */
3797 extern LEX_STRING RLI_INFO_NAME;
3798 extern LEX_STRING MI_INFO_NAME;
3800 
3801 inline bool is_infoschema_db(const char *name, size_t len) {
3802  return (
3805 }
3806 
3807 inline bool is_infoschema_db(const char *name) {
3809 }
3810 
3811 inline bool is_perfschema_db(const char *name, size_t len) {
3812  return (PERFORMANCE_SCHEMA_DB_NAME.length == len &&
3814  name));
3815 }
3816 
3817 inline bool is_perfschema_db(const char *name) {
3819  name);
3820 }
3821 
3822 /**
3823  return true if the table was created explicitly.
3824 */
3825 inline bool is_user_table(TABLE *table) {
3826  const char *name = table->s->table_name.str;
3827  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
3828 }
3829 
3830 bool is_simple_order(ORDER *order);
3831 
3832 uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n,
3833  TABLE_SHARE *share, handler *handler_file,
3834  uint *usable_parts);
3835 void setup_key_part_field(TABLE_SHARE *share, handler *handler_file,
3836  uint primary_key_n, KEY *keyinfo, uint key_n,
3837  uint key_part_n, uint *usable_parts,
3838  bool part_of_key_not_extended);
3839 
3840 const uchar *get_field_name(const uchar *arg, size_t *length);
3841 
3842 void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec);
3843 bool update_generated_write_fields(const MY_BITMAP *bitmap, TABLE *table);
3844 bool update_generated_read_fields(uchar *buf, TABLE *table,
3845  uint active_index = MAX_KEY);
3846 
3847 /**
3848  Check if a TABLE_LIST instance represents a pre-opened temporary table.
3849 */
3850 
3851 inline bool is_temporary_table(TABLE_LIST *tl) {
3852  if (tl->is_view() || tl->schema_table) return false;
3853 
3854  if (!tl->table) return false;
3855 
3856  /*
3857  NOTE: 'table->s' might be NULL for specially constructed TABLE
3858  instances. See SHOW TRIGGERS for example.
3859  */
3860 
3861  if (!tl->table->s) return false;
3862 
3863  return tl->table->s->tmp_table != NO_TMP_TABLE;
3864 }
3865 
3866 /**
3867  After parsing, a Common Table Expression is accessed through a
3868  TABLE_LIST. This class contains all information about the CTE which the
3869  TABLE_LIST needs.
3870 
3871  @note that before and during parsing, the CTE is described by a
3872  PT_common_table_expr.
3873 */
3875  public:
3878  TABLE *clone_tmp_table(THD *thd, TABLE_LIST *tl);
3880  /**
3881  All references to this CTE in the statement, except those inside the
3882  query expression defining this CTE.
3883  In other words, all non-recursive references.
3884  */
3886  /// True if it's a recursive CTE
3888  /**
3889  List of all TABLE_LISTSs reading/writing to the tmp table created to
3890  materialize this CTE. Due to shared materialization, only the first one
3891  has a TABLE generated by create_tmp_table(); other ones have a TABLE
3892  generated by open_table_from_share().
3893  */
3895  /// Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
3897 };
3898 
3899 /**
3900  This iterates on those references to a derived table / view / CTE which are
3901  materialized. If a recursive CTE, this includes recursive references.
3902  Upon construction it is passed a non-recursive materialized reference
3903  to the derived table (TABLE_LIST*).
3904  For a CTE it may return more than one reference; for a derived table or a
3905  view, there is only one (as references to a same view are treated as
3906  independent objects).
3907  References are returned as TABLE*.
3908 */
3910  TABLE_LIST *const start; ///< The reference provided in construction.
3911  int ref_idx; ///< Current index in cte->tmp_tables
3912  public:
3913  explicit Derived_refs_iterator(TABLE_LIST *start_arg)
3914  : start(start_arg), ref_idx(-1) {}
3916  ref_idx++;
3917  const Common_table_expr *cte = start->common_table_expr();
3918  if (!cte) return (ref_idx < 1) ? start->table : nullptr;
3919  return ((uint)ref_idx < cte->tmp_tables.size())
3920  ? cte->tmp_tables[ref_idx]->table
3921  : nullptr;
3922  }
3923  void rewind() { ref_idx = -1; }
3924  /// @returns true if the last get_next() returned the first element.
3925  bool is_first() const { return ref_idx == 0; }
3926 };
3927 
3928 //////////////////////////////////////////////////////////////////////////
3929 
3930 /*
3931  NOTE:
3932  These structures are added to read .frm file in upgrade scenario.
3933 
3934  They should not be used any where else in the code.
3935  They will be removed in future release.
3936  Any new code should not be added in this section.
3937 */
3938 
3939 /**
3940  These members were removed from TABLE_SHARE as they are not used in
3941  in the code. open_binary_frm() uses these members while reading
3942  .frm files.
3943 */
3945  public:
3949  stored_fields(0),
3950  view_def(NULL),
3951  frm_version(0),
3952  fieldnames() {}
3953 
3956  uint stored_fields; /* Number of stored fields
3957  (i.e. without generated-only ones) */
3958 
3959  enum utype {
3972  EMPTY_VAL, // EMPTY_VAL rather than EMPTY since EMPTY can conflict with
3973  // system headers.
3986  };
3987 
3988  /**
3989  For shares representing views File_parser object with view
3990  definition read from .FRM file.
3991  */
3994  TYPELIB fieldnames; /* Pointer to fieldnames */
3995 };
3996 
3997 /**
3998  Create TABLE_SHARE from .frm file.
3999 
4000  FRM_context object is used to store the value removed from
4001  TABLE_SHARE. These values are used only for .frm file parsing.
4002 
4003  @param[in] thd Thread handle.
4004  @param[in] path Path of the frm file.
4005  @param[out] share TABLE_SHARE to be populated.
4006  @param[out] frm_context FRM_context object.
4007  @param[in] db Database name.
4008  @param[in] table Table name.
4009  @param[in] is_fix_view_cols_and_deps Fix view column data, table
4010  and routine dependency.
4011 
4012  @retval TABLE_SHARE ON SUCCESS
4013  @retval NULL ON FAILURE
4014 */
4015 bool create_table_share_for_upgrade(THD *thd, const char *path,
4016  TABLE_SHARE *share,
4017  FRM_context *frm_context, const char *db,
4018  const char *table,
4019  bool is_fix_view_cols_and_deps);
4020 //////////////////////////////////////////////////////////////////////////
4021 
4022 #endif /* TABLE_INCLUDED */
static my_bitmap_map * dbug_tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:3654
LEX_STRING * update_method
Definition: table.h:2160
LEX_STRING * foreign_table
Definition: table.h:2157
uint fields
Definition: table.h:779
ulong avg_row_length
Definition: table.h:741
Key_map keys_in_use_for_group_by
Definition: table.h:1370
Definition: table.h:3983
bool end_of_fields()
Definition: table.h:3481
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1141
bool no_cache
Definition: table.h:1544
Definition: table.h:3456
Definition: sql_plugin_ref.h:44
After parsing, a Common Table Expression is accessed through a TABLE_LIST.
Definition: table.h:3874
TABLE * prev
Definition: table.h:1297
dd::Foreign_key::enum_rule update_rule
Definition: table.h:627
bool m_schema_lookup_done
True if the internal lookup by schema name was done.
Definition: table.h:312
bool uses_identified_by_clause
Definition: table.h:2354
void restore_null_flags()
Restore the NULL flags of the current row from the designated buffer.
Definition: table.h:1819
bool has_binary_diff_columns() const
Does this table have any columns that can be updated using partial update in the current row...
Definition: table.cc:7434
Definition: item.h:3349
void set_common_table_expr(Common_table_expr *c)
Definition: table.h:3408
uint field_length
For string-type columns, this is the maximum number of characters.
Definition: table.h:2181
unsigned long long int ulonglong
Definition: my_inttypes.h:74
Definition: mdl.h:252
bool open_by_handler
Definition: table.h:1546
dd::Foreign_key::enum_rule update_rule
Definition: table.h:638
void set_deleted()
Set the contents of table to be "deleted", ie "not created", after having deleted the contents...
Definition: table.h:1702
bool auto_partitioned
Filled in when reading from frm.
Definition: table.h:882
void * memdup_root(MEM_ROOT *root, const void *str, size_t len)
Definition: my_alloc.cc:273
Definition: partition_info.h:208
Definition: table.h:3320
A granted metadata lock.
Definition: mdl.h:963
void cleanup_partial_update()
Clean up state used for partial update of JSON columns.
Definition: table.cc:7493
Filesort_info sort
Definition: table.h:1599
bool is_mergeable() const
Return true if view or derived table and can be merged.
Definition: table.cc:6479
This file contains the field type.
bool replace_filter_processed
true <=> Filter condition is processed
Definition: table.h:3298
Item * item()
Definition: table.h:3504
uint i_s_requested_object
Definition: table.h:3377
Field * next_number_field
Definition: table.h:1375
const char * get_table_name() const
Returns the name of the table that this TABLE_LIST represents.
Definition: table.h:2902
This iterates on those references to a derived table / view / CTE which are materialized.
Definition: table.h:3909
#define STATUS_NOT_STARTED
Flags for TABLE::m_status (maximum 8 bits).
Definition: table.h:1267
uchar * null_flags_saved
Saved null_flags while null_row is true.
Definition: table.h:1393
Definition: table.h:3473
unsigned char uchar
Definition: my_inttypes.h:51
Field * field_in_tmp_table
When GROUP BY is implemented with a temporary table (i.e.
Definition: table.h:297
void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec)
Repoint a table&#39;s fields from old_rec to new_rec.
Definition: table.cc:7020
const Lock_descriptor & lock_descriptor() const
Definition: table.h:3047
Definition: table.h:3962
uint blob_fields
Definition: table.h:789
char * str
Definition: mysql_lex_string.h:35
dd::Foreign_key::enum_rule delete_rule
Definition: table.h:638
bool materialize_derived(THD *thd)
Materialize derived table.
Definition: sql_derived.cc:791
MY_BITMAP pack_row_tmp_set
Definition: table.h:1397
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, const dd::Table *table_def_param)
Open a table based on a TABLE_SHARE.
Definition: table.cc:2803
Table_list_adapter< Local_tables_iterator > Local_tables_list
A list interface over the TABLE_LIST::next_local pointer.
Definition: table.h:3629
LEX * view_query() const
Return the valid LEX object for a view.
Definition: table.h:2764
enum_open_type
Type of table which can be open for an element of table list.
Definition: table.h:2386
TABLE_LIST * referencing_view
Definition: table.h:3191
bool use_default_password_history
Definition: table.h:2314
void add_logical_diff(const Field_json *field, const Json_seekable_path &path, enum_json_diff_operation operation, const Json_wrapper *new_value)
Add a logical JSON diff describing a logical change to a JSON column in partial update.
Definition: table.cc:7607
t pos
Definition: dbug_analyze.cc:148
void setup_key_part_field(TABLE_SHARE *share, handler *handler_file, uint primary_key_n, KEY *keyinfo, uint key_n, uint key_part_n, uint *usable_parts, bool part_of_key_not_extended)
Setup key-related fields of Field object for given key and key part.
Definition: table.cc:723
unsigned int ref_count() const
How many TABLE objects use this TABLE_SHARE.
Definition: table.h:1110
ulonglong algorithm
The declared algorithm, if this is a view.
Definition: table.h:3234
Item * create_item(THD *thd)
Definition: table.cc:5092
Field_iterator_table()
Definition: table.h:3477
void rewind()
Definition: table.h:3923
ulonglong get_table_ref_version() const
Return a table metadata version.
Definition: table.cc:4043
const char * db_name
Definition: rules_table_service.cc:54
Definition: table.h:2388
uint next_number_keypart
Definition: table.h:825
bool operator!=(const Table_list_iterator &other) const
Definition: table.h:3590
List< LEX_STRING > referenced_fields
Definition: table.h:2164
ulonglong table_map
Definition: my_table_map.h:32
bool check_option_processed
true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
Definition: table.h:3296
LEX_STRING PERFORMANCE_SCHEMA_DB_NAME
Definition: table.cc:126
enum_order
Definition: key_spec.h:64
Definition: mysql_lex_string.h:34
ha_rows quick_condition_rows
Definition: table.h:1472
uint primary_key
Definition: table.h:822
Provides a list interface on TABLE_LIST objects.
Definition: table.h:3609
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:236
bool force_index
True if using an index is preferred over a table scan.
Definition: table.h:3264
bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root, CHARSET_INFO *charset, const char *alias, Field **fld, uint *blob_fld, bool is_virtual)
Initialize table as internal tmp table.
Definition: table.cc:4153
This class holds all information about triggers of a table.
Definition: table_trigger_dispatcher.h:62
uint next_number_index
Definition: table.h:823
uint query_block_id() const
If a derived table, returns query block id of first underlying query block.
Definition: table.cc:6289
uint stats_sample_pages
Definition: table.h:772
TABLE_LIST(const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg, enum enum_mdl_type mdl_request_type)
Definition: table.h:2453
TABLE_LIST * next_global
Definition: table.h:3028
TABLE_LIST * embedding
The nested join containing this table reference.
Definition: table.h:3283
TABLE * table
Definition: field.h:805
uint lock_data_start
Definition: table.h:1475
bool check_read_removal(uint index)
Read removal is possible if the selected quick read method is using full unique index.
Definition: table.cc:6974
dd::Table * tmp_table_def
Data-dictionary object describing explicit temporary table represented by this share.
Definition: table.h:928
Base class to be used by handlers different shares.
Definition: handler.h:3512
Definition: sql_lex.h:3063
String * get_partial_update_buffer()
Get a buffer that can be used to hold the partially updated column value while performing partial upd...
Definition: table.cc:7500
Lock_descriptor m_lock_descriptor
Definition: table.h:3241
void copy_tmp_key(int old_idx, bool modify_share)
For a materialized derived table: copies a KEY definition from a position to the first not-yet-used p...
Definition: table.cc:6008
partition_info * part_info
Definition: table.h:1605
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1318
Definition: table.h:375
const char * get_db_name() const
Returns the name of the database that the referenced table belongs to.
Definition: table.h:2894
void set_found_row()
Set status for row buffer: contains row.
Definition: table.h:1741
const TABLE_FIELD_TYPE * field
Definition: table.h:560
const TABLE_LIST * top_table() const
Return the outermost view this table belongs to, or itself.
Definition: table.h:2597
void set_truncated_value(bool is_truncated_value)
Definition: table.h:1201
size_t m_offset
The offset of the start of the change.
Definition: table.h:1213
Definition: table.h:376
MY_BITMAP tmp_set
Definition: table.h:1397
SELECT_LEX_UNIT * derived
This field is set to non-null for derived tables and views.
Definition: table.h:3136
void next()
Definition: table.cc:5217
LEX_STRING RLI_INFO_NAME
Definition: table.cc:142
unsigned long m_version
TABLE_SHARE version, if changed the TABLE_SHARE must be reopened.
Definition: table.h:1159
const string name("\ame\)
Order clause list element.
Definition: table.h:269
void set_join_cond(Item *val)
Definition: table.h:2543
TYPELIB keynames
Definition: table.h:681
Element that represents the table in the specific table cache.
Definition: table_cache.h:226
bool updating
True for tables and views being changed in a data change statement.
Definition: table.h:3262
Definition: mi_test3.cc:54
int ref_idx
Current index in cte->tmp_tables.
Definition: table.h:3911
bool uses_authentication_string_clause
Definition: table.h:2356
uint last_null_bit_pos
Definition: table.h:778
bool no_keyread
Certain statements which need the full row, set this to ban index-only access.
Definition: table.h:1538
bool uses_replace_clause
Definition: table.h:2357
Wait_for_flush * next_in_share
Pointers for participating in the list of waiters for table share.
Definition: table.h:609
This structure is shared between different table objects.
Definition: table.h:646
Field ** vfield
Pointer to generated columns.
Definition: table.h:1378
Definition: table.h:3982
uint next_number_key_offset
Definition: table.h:824
static void tmp_restore_column_map(MY_BITMAP *bitmap, my_bitmap_map *old)
Definition: table.h:3647
bool should_binlog_drop_if_temp_flag
This flag decides whether or not we should log the drop temporary table command.
Definition: table.h:1927
uint partition_info_str_len
Definition: table.h:890
bool is_aj_nest() const
Definition: table.h:2562
MEM_ROOT storage
Definition: table.h:1173
File containing constants that can be used throughout the server.
uint rowid_field_offset
Definition: table.h:820
ulong key_part_map
Definition: my_base.h:998
KEY * key_info
Definition: table.h:698
GRANT_INFO * grant()
Definition: table.cc:5264
Field ** visible_field_ptr() const
Definition: table.h:1659
LEX_CSTRING type
Definition: table.h:554
Table_id table_id
Definition: table.h:3109
Some integer typedefs for easier portability.
table_map join_cond_dep_tables
The outer tables that an outer join&#39;s join condition depends on.
Definition: table.h:3273
ulonglong with_check
WITH CHECK OPTION.
Definition: table.h:3236
enum_table_ref_type
Enumerate possible types of a table from re-execution standpoint.
Definition: table.h:162
TABLE_SHARE(unsigned long version, bool secondary)
Create a new TABLE_SHARE with the given version number.
Definition: table.h:655
Vector of logical diffs describing changes to a JSON column.
Definition: json_diff.h:137
Table_function * table_function
Definition: table.h:3127
Unknown value.
Definition: table.h:389
bool merge_where(THD *thd)
Merge WHERE condition of view or derived table into outer query.
Definition: table.cc:4459
Natural_join_column * get_natural_column_ref()
Return an existing reference to a column of a natural/using join.
Definition: table.cc:5384
Definition: view.h:38
unsigned int increment_ref_count()
Increment the reference count by one.
Definition: table.h:1119
uchar * insert_values
Definition: table.h:1330
static const uint MYSQL_TABLESPACE_DD_ID
Definition: table.h:3794
void disable_logical_diffs_for_current_row(const Field *field) const
Temporarily disable collection of Json_diff objects describing the logical changes of a JSON column i...
Definition: table.cc:7671
uint max_tmp_keys
For materialized derived tables: maximum size of key_info array.
Definition: table.h:800
LEX_STRING compress
Definition: table.h:703
Field ** field
Definition: table.h:696
bool has_db_lookup_value
Definition: table.h:3378
enum_schema_table_state
Definition: table.h:2148
Field * hash_field
Field used by unique constraint.
Definition: table.h:1382
uint keys
Definition: table.h:781
Definition: table.h:2170
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form)
Definition: table.cc:3481
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:210
Definition: sql_bitmap.h:135
Key_map keys_in_use_for_order_by
Definition: table.h:1372
const char * db
Definition: table.h:3029
void drop_unused_tmp_keys(bool modify_share)
For a materialized derived table: after copy_tmp_key() has copied all definitions of used KEYs...
Definition: table.cc:6040
bool force_index_group
Flag set when the statement contains FORCE INDEX FOR GROUP BY See TABLE_LIST::process_index_hints().
Definition: table.h:1518
const char * new_data(Field *field) const
Get a pointer to the start of the replacement data.
Definition: table.cc:7590
bool check_single_table(TABLE_LIST **table_ref, table_map map)
Check which single table inside a view that matches a table map.
Definition: table.cc:4735
System table, maintained by the server.
Definition: table.h:436
A data dictionary table.
Definition: table.h:546
uint foreign_keys
Arrays with descriptions of foreign keys in which this table participates as child or parent...
Definition: table.h:938
uint16 expire_after_days
Definition: table.h:2310
Definition: table.h:3322
uint hidden_field_count
Count of hidden fields, if internal temporary table; 0 otherwise.
Definition: table.h:1325
const char * str
Definition: mysql_lex_string.h:40
enum TABLE_LIST::@108 OPEN_NORMAL
Indicates that if TABLE_LIST object corresponds to the table/view which requires special handling...
virtual void delete_backup_ctx()
Definition: table.cc:205
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:847
TABLE_LIST * table_ref
Definition: table.h:2270
bool m_updatable
Definition: table.h:3253
const CHARSET_INFO * table_charset
Definition: table.h:709
Definition: field.h:709
void print(const THD *thd, String *str, enum_query_type query_type) const
Produce a textual identification of this object.
Definition: sql_lex.cc:2763
bool update_const_key_parts(Item *conds)
Update TABLE::const_key_parts for single table UPDATE/DELETE query.
Definition: table.cc:6938
Definition: table.h:3977
LEX_CSTRING user
Definition: table.h:2343
TABLE_LIST * updatable_base_table()
Definition: table.h:2974
const Binary_diff_vector * get_binary_diffs(const Field *field) const
Get the list of binary diffs that have been collected for a given column in the current row...
Definition: table.cc:7525
bool has_row() const
Definition: table.h:1802
LEX_CSTRING cset
Definition: table.h:555
PSI_table_share * m_psi
Instrumentation for this table share.
Definition: table.h:908
bool prelocking_placeholder
Definition: table.h:3306
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:179
Definition: table.h:166
int(* fill_table)(THD *thd, TABLE_LIST *tables, Item *cond)
Definition: table.h:2208
bool is_multiple_tables() const
Return true if this is a view or derived table that is defined over more than one base table...
Definition: table.h:2721
Item ** join_cond_ref()
Definition: table.h:2541
LEX_STRING * referenced_db
Definition: table.h:2158
Item * item
Points to an item that represents the expression.
Definition: table.h:2255
void free_table_share(TABLE_SHARE *share)
Free table share and memory used by it.
Definition: table.cc:591
bool is_secondary_engine() const
Does this TABLE_SHARE represent a table in a secondary storage engine?
Definition: table.h:1140
void set_merged()
Set table to be merged.
Definition: table.h:2678
List< Index_hint > * index_hints
Definition: table.h:3107
uint db_options_in_use
Bitmap with flags representing some of table options/attributes which are in use by storage engine...
Definition: table.h:819
LEX_CSTRING table_name
Definition: table.h:725
Definition: table.h:2150
enum enum_table_category TABLE_CATEGORY
Definition: table.h:548
bool all_partitions_pruned_away
Definition: table.h:1607
void mark_columns_needed_for_delete(THD *thd)
Definition: table.cc:5600
bool assert_ref_count_is_locked(const TABLE_SHARE *)
Assert that the LOCK_open mutex is held when the reference count of a TABLE_SHARE is accessed...
Definition: table.cc:508
Table_cache_element ** cache_element
Array of table_cache_instances pointers to elements of table caches respresenting this table in each ...
Definition: table.h:693
void prepare_for_position(void)
Tell handler we are going to call position() and rnd_pos() later.
Definition: table.cc:5436
Field_iterator()
Definition: table.h:3458
uint gen_def_field_count
Number of fields having the default value generated.
Definition: table.h:831
bool m_is_recursive_reference
If a recursive reference inside the definition of a CTE.
Definition: table.h:3442
const Create_col_name_list * m_derived_column_names
If the user has specified column names with the syntaxes "table name parenthesis column names": WITH ...
Definition: table.h:3150
bool has_null_row() const
Definition: table.h:1805
Definition: mysql_lex_string.h:39
Ident_name_check check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase)
Check if database name is valid, and convert to lower case if necessary.
Definition: table.cc:3611
This class represents a buffer that can be used for multi-row reads.
Definition: record_buffer.h:46
TYPELIB fieldnames
Definition: table.h:3994
bool created
For tmp tables.
Definition: table.h:1568
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
void disable_binary_diffs_for_current_row(const Field *field)
Temporarily disable collection of binary diffs for a column in the current row.
Definition: table.cc:7416
ha_rows min_rows
Definition: table.h:740
void set_table_cache_key(char *key_buff, size_t key_length)
Set share&#39;s table cache key and update its db and table name appropriately.
Definition: table.h:960
Definition: table.h:3969
Lex_acl_attrib_udyn
This is generic enum.
Definition: table.h:2295
const uchar * get_field_name(const uchar *arg, size_t *length)
TABLE * get_next()
Definition: table.h:3915
TABLE_SHARE * alloc_table_share(const char *db, const char *table_name, const char *key, size_t key_length, bool open_secondary)
Allocate and setup a TABLE_SHARE structure.
Definition: table.cc:362
MY_BITMAP * read_set
Definition: table.h:1417
const char * table_name
Definition: table.h:3029
TABLE_LIST * view
Definition: table.h:3493
Object_creation_ctx – interface for creation context of database objects (views, stored routines, events, triggers).
Definition: table.h:186
State information for internal tables grants.
Definition: table.h:310
void free_blob_buffers_and_reset(TABLE *table, uint32 size)
Reclaims temporary blob storage which is bigger than a threshold.
Definition: table.cc:3341
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:52
uint count
Definition: table.h:559
my_bitmap_map * bitmap
Definition: my_bitmap.h:43
tmp_table_type tmp_table
Definition: table.h:762
uint key_parts
Definition: table.h:782
void mark_columns_per_binlog_row_image(THD *thd)
Definition: table.cc:5750
LEX_CSTRING referenced_table_name
Definition: table.h:621
#define STATUS_DELETED
Reserved for use by multi-table delete. Means the row has been deleted.
Definition: table.h:1282
bool update_password_expired_fields
Definition: table.h:2307
TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum_mdl_type mdl_type)
Sets an explicit enum_mdl_type value, without initializing m_lock_descriptor.
Definition: table.h:2481
query_id_t query_id
Definition: table.h:1450
const Create_col_name_list * derived_column_names() const
Definition: table.h:3410
Definition: thr_lock.h:72
bool cacheable_table
stop PS caching
Definition: table.h:3287
enum_mark_columns
Definition: sql_const.h:377
Contains the class Table_id, mainly used for row based replication.
SELECT_LEX * select_lex
Definition: table.h:3162
void default_column_bitmaps()
Definition: table.h:1652
LEX_STRING name
Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
Definition: table.h:3896
uint find_first_unused_tmp_key(const Key_map &k)
For a materialized derived table: informs the share that certain not-yet-used keys are going to be us...
Definition: table.cc:5995
const char * alias
alias or table name
Definition: table.h:1391
Performance schema instrumentation interface.
class JOIN_TAB * join_tab
Definition: table.h:1575
virtual ~Field_iterator()
Definition: table.h:3459
ST_SCHEMA_TABLE * schema_table
Definition: table.h:3153
bool impossible_range
Definition: table.h:1584
uint quick_key_parts[MAX_KEY]
Definition: table.h:1461
Definition: table.h:1285
static View_creation_ctx * create(THD *thd)
Definition: table.cc:218
uchar * default_values
Definition: table.h:701
enum_order direction
Definition: table.h:279
#define STATUS_NOT_FOUND
Means we were searching for a row and didn&#39;t find it.
Definition: table.h:1273
Field * field()
Definition: table.cc:5037
Item ** join_cond_optim_ref()
Definition: table.h:2557
LEX_STRING * referenced_table
Definition: table.h:2159
TABLE_LIST ** prev_global
Definition: table.h:3028
uint db_stat
Definition: table.h:1477
List_iterator_fast< Natural_join_column > column_ref_it
Definition: table.h:3514
Temporary table.
Definition: table.h:414
const ACL_internal_table_access * m_table_access
Cached internal table access.
Definition: table.h:318
Field ** gen_def_fields_ptr
Pointer to fields having the default value generated.
Definition: table.h:1380
void init_one_table(const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg, enum enum_mdl_type mdl_request_type)
Do not use this function in new code.
Definition: table.h:2524
Definition: table.h:3975
bool is_system_view
Definition: table.h:3356
bool end_of_fields()
Definition: table.h:3522
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3987
THD * in_use
Definition: table.h:1322
TABLE_SHARE_FOREIGN_KEY_PARENT_INFO * foreign_key_parent
Definition: table.h:941
TABLE_LIST()=default
bool is_temporary_table(TABLE_LIST *tl)
Check if a TABLE_LIST instance represents a pre-opened temporary table.
Definition: table.h:3851
bool is_recursive_reference() const
Definition: table.h:2634
User table.
Definition: table.h:424
TABLE * table
Definition: table.h:3108
void set_keyread(bool flag)
Definition: table.cc:6068
Key_map covering_keys
Definition: table.h:1339
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:3885
void set_binlog_drop_if_temp(bool should_binlog)
Set the variable should_binlog_drop_if_temp_flag, so that the logging of temporary tables can be deci...
Definition: table.cc:7834
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
Definition: table.h:379
TABLE_LIST * natural_join
Definition: table.h:3081
virtual void delete_backup_ctx()=0
bool m_open_in_progress
Definition: table.h:836
bool is_insertable() const
Return true if table is insertable-into.
Definition: table.h:2703
Item * join_cond() const
Definition: table.h:2542
Gtid Table.
Definition: table.h:538
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
List< LEX_STRING > foreign_fields
Definition: table.h:2163
plugin_ref db_plugin
Definition: table.h:747
bool end_of_fields()
Definition: table.h:3499
uchar * null_flags
Pointer to the null flags of record[0].
Definition: table.h:1392
bool has_keys
Definition: table.h:565
uint tmp_handler_count
Only for internal temporary tables.
Definition: table.h:769
uint first_unused_tmp_key
For materialized derived tables;.
Definition: table.h:795
bool has_secondary_engine() const
Does this TABLE_SHARE represent a primary table that has a shadow copy in a secondary storage engine...
Definition: table.h:1146
TABLE_LIST * first_leaf_for_name_resolution()
Retrieve the first (left-most) leaf in a nested join tree with respect to name resolution.
Definition: table.cc:4807
Definition: thr_lock.h:52
ha_rows max_rows
Definition: table.h:740
static MEM_ROOT mem
Definition: sql_servers.cc:97
LEX_CSTRING INFORMATION_SCHEMA_NAME
Definition: table.cc:123
const ACL_internal_schema_access * m_schema_access
Cached internal schema access.
Definition: table.h:314
const char * name()
Definition: table.cc:5074
LEX_STRING * foreign_id
Definition: table.h:2155
Definition: table.h:3984
bool m_insertable
Definition: table.h:3254
Field_translator * ptr
Definition: table.h:3492
bool is_distinct
Whether this is a temporary table that already has a UNIQUE index (removing duplicate rows on insert)...
Definition: table.h:1524
Definition: table.h:3979
Definition: table.h:168
bool check_column_name(const char *name)
Definition: table.cc:3677
ulonglong updatable_view
Definition: table.h:3225
int rename_file_ext(const char *from, const char *to, const char *ext)
Definition: table.cc:3502
Abstract class representing an edge in the waiters graph to be traversed by deadlock detection algori...
Definition: mdl.h:925
Definition: table.h:1294
TABLE * next
Definition: table.h:1297
LEX_CSTRING * column_name
Arrays with names of referencing columns of the FK.
Definition: table.h:632
uint total_key_length
Definition: table.h:787
bool has_gcol() const
Definition: table.h:1710
virtual Object_creation_ctx * create_backup_ctx(THD *thd) const
Definition: table.cc:200
const TABLE_LIST * updatable_base_table() const
Return the base table entry of an updatable table.
Definition: table.h:2964
TABLE ** cache_prev
Definition: table.h:1307
const char * get_table_name()
Definition: table.cc:5231
void cleanup()
Definition: table.h:2321
static EXTENSION_DAEMON_DESCRIPTOR descriptor
Definition: stdin_check.c:32
bool is_derived() const
Return true if this represents a derived table (an unnamed view)
Definition: table.h:2619
LEX_STRING * foreign_db
Definition: table.h:2156
bool is_view
Definition: table.h:835
const CHARSET_INFO * get_client_cs()
Definition: table.h:212
int set_zone(int nr, int min_zone, int max_zone)
Definition: table.cc:3426
virtual bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor)
Traverse portion of wait-for graph which is reachable through edge represented by this flush ticket i...
Definition: table.cc:3851
Query block level hints.
Definition: opt_hints.h:364
Cost_model_table m_cost_model
Cost model object for operations on this table.
Definition: table.h:1612
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:2951
Definition: table.h:3978
const char * alias
Definition: table.h:3029
static TABLE_LIST * new_nested_join(MEM_ROOT *allocator, const char *alias, TABLE_LIST *embedding, List< TABLE_LIST > *belongs_to, SELECT_LEX *select)
Create a TABLE_LIST object representing a nested join.
Definition: table.cc:4375
void set_lock(const Lock_descriptor &descriptor)
Definition: table.h:3043
bool update_generated_write_fields(const MY_BITMAP *bitmap, TABLE *table)
Calculate data for each generated field marked for write in the corresponding column map...
Definition: table.cc:7134
Key_map possible_quick_keys
Definition: table.h:1355
KEY * key_info
Definition: table.h:1373
bool fulltext_searched
Definition: table.h:1543
TABLE_LIST * next_name_resolution_table
Definition: table.h:3105
virtual Object_creation_ctx * create_backup_ctx(THD *thd) const =0
const File_parser * view_def
For shares representing views File_parser object with view definition read from .FRM file...
Definition: table.h:3992
void append_unescaped(String *res, const char *pos, size_t length)
Store an SQL quoted string.
Definition: table.cc:3444
Item ** item_ptr()
Definition: table.h:3502
Table_list_adapter< Global_tables_iterator > Global_tables_list
A list interface over the TABLE_LIST::next_global pointer.
Definition: table.h:3632
Definition: table.h:3634
TABLE_LIST * operator*()
Definition: table.h:3588
Per internal schema ACL access rules.
Definition: auth_common.h:135
TABLE_LIST * first_leaf
Definition: table.h:3544
static my_bitmap_map * tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:3640
void add_join_natural(TABLE_LIST *b)
Mark that there is a NATURAL JOIN or JOIN ...
Definition: table.h:3009
void set_readonly()
Set table as readonly, ie it is neither updatable, insertable nor deletable during this statement...
Definition: table.h:2712
void free_blobs(TABLE *table)
Definition: table.cc:3320
Definition: table.h:2266
Definition: table.h:552
Definition: table.h:3315
virtual Field * field()=0
Item * create_item(THD *thd)
Definition: table.cc:5076
bool process_index_hints(const THD *thd, TABLE *table)
Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query, TABLE::keys_in_use_for_grou...
Definition: table.cc:6349
size_t table_name_length
Definition: table.h:3250
bool copy_blobs
Definition: table.h:1499
enum_schema_table_state schema_table_state
Definition: table.h:3381
uint max_key_length
Definition: table.h:785
uint column_bitmap_size
Definition: table.h:827
Definition: table.h:3964
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab)
Definition: table.cc:4995
const char * table_name
Definition: table.h:2203
bool optimized_away
true <=> this table is a const one and was optimized away.
Definition: table.h:3433
Field * field()
Definition: table.h:3484
bool is_simple_order(ORDER *order)
Test if the order list consists of simple field expressions.
Definition: table.cc:7005
This file includes constants used by all storage engines.
Field_translator * field_translator()
Definition: table.h:3505
void clear_column_bitmaps(void)
Definition: table.cc:5406
bool refix_value_generator_items(THD *thd)
Fix table&#39;s generated columns&#39; (GC) and/or default expressions.
Definition: table.cc:4200
uint version
Used for cache invalidation when caching privilege information.
Definition: table.h:357
void set_nullable()
Set table as nullable, ie it is inner wrt some outer join.
Definition: table.h:1704
An abstract class for inspection of a connected subgraph of the wait-for graph.
Definition: mdl.h:899
#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5)
Definition: mdl.h:885
void set_table_cache_key(char *key_buff, const char *key, size_t key_length)
Set share&#39;s table cache key and update its db and table name appropriately.
Definition: table.h:986
Definition: table.h:3966
Definition: table.h:2227
bool is_user_table(TABLE *table)
return true if the table was created explicitly.
Definition: table.h:3825
const TABLE_FIELD_DEF * table_field_def_cache
Cache the checked structure of this table.
Definition: table.h:902
Definition: table.h:2342
bool is_natural_join
Definition: table.h:3087
uint table_open_method
Definition: table.h:3380
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
void use_all_columns()
Definition: table.h:1649
enum enum_table_ref_type get_table_ref_type() const
Convert unrelated members of TABLE_SHARE to one enum representing its type.
Definition: table.h:1012
int64 query_id_t
Definition: table.h:129
char * store(const char *from, size_t length)
Fuction creates duplicate of &#39;from&#39; string in &#39;storage&#39; MEM_ROOT.
Definition: table.h:1198
bool use_default_password_lifetime
Definition: table.h:2309
Key_map visible_indexes
The set of visible and enabled indexes for this table.
Definition: table.h:738
Field * field()
Definition: table.h:3503
TABLE_LIST * m_current
Definition: table.h:3595
View_creation_ctx(THD *thd)
Definition: table.h:262
ulong flags
dupp key and pack flags
Definition: key.h:116
bool is_fqtn
true if the table is referred to in the statement using a fully qualified name (<db_name>.
Definition: table.h:3330
malloc_unordered_map< uint, const histograms::Histogram * > * m_histograms
Definition: table.h:662
structure to define some default "config_option" option settings
Definition: innodb_config.h:180
uint * blob_field
Definition: table.h:699
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:1707
void mark_gcol_in_maps(Field *field)
Adds a generated column and its dependencies to the read_set/write_set bitmaps.
Definition: table.cc:7192
bool use_default_password_reuse_interval
Definition: table.h:2317
Key_map usable_indexes(const THD *thd) const
The set of indexes that the optimizer may use when creating an execution plan.
Definition: table.cc:493
int view_check_option(THD *thd) const
Evaluate the check option of a view.
Definition: table.cc:4712
static const uint MYSQL_SCHEMA_DD_ID
Definition: table.h:3790
const char * name()
Definition: table.cc:5090
uint open_method
Definition: table.h:2199
List< TABLE_LIST > * join_list
The join list immediately containing this table reference.
Definition: table.h:3285
Hook class which via its methods specifies which members of T should be used for participating in a i...
Definition: sql_plist.h:197
bool is_marked_for_partial_update(const Field *field) const
Has this column been marked for partial update?
Definition: table.cc:7428
char * index(const char *, int c)
Definition: mysql.cc:2847
void mark_auto_increment_column(void)
Mark auto-increment fields as used fields in both read and write maps.
Definition: table.cc:5569
LEX_STRING GENERAL_LOG_NAME
Definition: table.cc:136
Definition: table.h:558
Definition: table.h:3981
Struct NESTED_JOIN is used to represent how tables are connected through outer join operations and se...
Definition: nested_join.h:77
Definition: table.h:378
uint db_create_options
Bitmap with flags representing some of table options/attributes.
Definition: table.h:810
Definition: table.h:2149
void next()
Definition: table.h:3498
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:5305
thr_lock_type
Definition: thr_lock.h:50
Definition: table.h:2151
bool create_field_translation(THD *thd)
Create field translation for merged derived table/view.
Definition: table.cc:4495
void destroy()
Release resources and free memory occupied by the table share.
Definition: table.cc:530
const CHARSET_INFO * get_connection_cl()
Definition: table.h:214
Security_context * security_ctx
Definition: table.h:3198
uint leaf_tables_count() const
Return no. of base tables a merged view or derived table is defined over.
Definition: table.cc:6494
Log tables.
Definition: table.h:480
enum_json_diff_operation
Enum that describes what kind of operation a Json_diff object represents.
Definition: json_diff.h:51
handlerton * default_part_db_type
Definition: table.h:3954
void set_updatable()
Set table as updatable. (per default, a table is non-updatable)
Definition: table.h:2700
void set_tableno(uint tableno)
Set table number.
Definition: table.h:3392
Definition: table.h:1285
ulong refresh_version
Definition: mysqld.cc:1162
bool internal_tmp_table
Definition: table.h:3324
#define restore_record(A, B)
Definition: table.h:137
SELECT_LEX * owner_of_possible_tmp_keys
For materialized derived tables;.
Definition: table.h:931
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys...
Definition: map_helpers.h:175
#define MAX_KEY
Definition: sql_const.h:51
bool is_placeholder() const
Definition: table.h:2658
Definition: table.h:2225
void reset_null_row()
Clear "null row" status for the current row.
Definition: table.h:1784
table_map m_map
Table map, derived from m_tableno.
Definition: table.h:3056
TABLE_SHARE_FOREIGN_KEY_INFO * foreign_key
Definition: table.h:939
tmp_table_type
Definition: table.h:374
#define tmp_file_prefix_length
Definition: table.h:143
Class representing the fact that some thread waits for table share to be flushed. ...
Definition: table.h:588
Sql_table_check_constraint_list * table_check_constraint_list
Definition: table.h:1481
key_part_map const_key_parts[MAX_KEY]
Definition: table.h:1459
Mem_root_array_YY< LEX_CSTRING > Create_col_name_list
Definition: table.h:127
bool is_started() const
Definition: table.h:1738
Key_map quick_keys
Definition: table.h:1340
bool contain_auto_increment
Definition: table.h:3294
size_t m_length
The size of the portion that is to be replaced.
Definition: table.h:1216
bool ignore_leaves
preload only non-leaf nodes (IS THIS USED???)
Definition: table.h:3266
Definition: table.h:2226
MEM_ROOT mem_root
Definition: table.h:1592
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, size_t key_length, const char *table_name, const char *path, MEM_ROOT *mem_root)
Initialize share for temporary tables.
Definition: table.cc:454
const char * name()
Definition: table.h:3523
Definition: my_bitmap.h:42
uint stored_fields
Definition: table.h:3956
bool not_exists_optimize
Definition: table.h:1579
Definition: table.h:377
Definition: table.h:2202
Blob_mem_storage * blob_storage
Initialized in Item_func_group_concat::setup for appropriate temporary table if GROUP_CONCAT is used ...
Definition: table.h:1598
~Blob_mem_storage()
Definition: table.cc:4058
TABLE_LIST * last_leaf
Definition: table.h:3544
table_map depend_map
Definition: table.h:299
bool empty_result_table()
Empties internal temporary table (deletes rows, closes scan)
Definition: table.cc:7842
LEX_CSTRING secondary_engine
Secondary storage engine.
Definition: table.h:707
GRANT_INFO * grant()
Definition: table.cc:5065
int(* process_table)(THD *thd, TABLE_LIST *tables, TABLE *table, bool res, LEX_STRING *db_name, LEX_STRING *table_name)
Definition: table.h:2211
enum_table_ref_type m_table_ref_type
See comments for set_metadata_id()
Definition: table.h:3447
bool is_view_or_derived() const
Return true if this represents a named view or a derived table.
Definition: table.h:2622
Definition: table.h:3963
TABLE_LIST * correspondent_table
Definition: table.h:3122
bool materialized
For a materializable derived or SJ table: true if has been materialized.
Definition: table.h:1572
virtual void change_env(THD *thd) const =0
TABLE_SHARE * s
Definition: table.h:1295
size_t length
Definition: mysql_lex_string.h:41
thr_locked_row_action locked_row_action
Definition: table.h:1578
void init_mdl_requests(TABLE_LIST *table_list)
Helper function which allows to allocate metadata lock request objects for all elements of table list...
Definition: table.cc:6467
bool has_columns_marked_for_partial_update() const
Does this table have any columns that were marked with mark_column_for_partial_update()?
Definition: table.cc:7484
uint tableno() const
Return table number.
Definition: table.h:3398
bool is_infoschema_db(const char *name, size_t len)
Definition: table.h:3801
bool setup_materialized_derived(THD *thd)
Setup a derived table to use materialization.
Definition: sql_derived.cc:487
LEX_CSTRING target_tablespace_name
Definition: table.h:3034
TABLE_LIST(const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg)
Definition: table.h:2447
Derived_refs_iterator(TABLE_LIST *start_arg)
Definition: table.h:3913
bool generate_keys()
Generate keys for a materialized derived table/view.
Definition: table.cc:6863
void set_not_started()
Life cycle of the row buffer is as follows:
Definition: table.h:1732
virtual void next()=0
ha_storage_media
Definition: my_base.h:114
uint columns
Definition: table.h:628
void set_null_row()
Set current row as "null row", for use in null-complemented outer join.
Definition: table.h:1777
void next()
Definition: table.cc:5157
Object_creation_ctx * set_n_backup(THD *thd)
Definition: table.cc:170
Item * item_ptr
Definition: table.h:277
void save_null_flags()
Save the NULL flags of the current row into the designated buffer.
Definition: table.h:1814
const histograms::Histogram * find_histogram(uint field_index)
Find the histogram for the given field index.
Definition: table.cc:3930
void set_no_row()
Set status for row buffer: contains no row.
Definition: table.h:1752
bool uses_identified_with_clause
Definition: table.h:2355
Header for compiler-dependent features.
bool force_index_order
Flag set when the statement contains FORCE INDEX FOR ORDER BY See TABLE_LIST::process_index_hints().
Definition: table.h:1512
Context of the owner of metadata locks.
Definition: mdl.h:1390
bool resolve_derived(THD *thd, bool apply_semijoin)
Resolve a derived table or view reference.
Definition: sql_derived.cc:256
LEX_CSTRING current_auth
Definition: table.h:2347
Item * create_item(THD *thd)
Definition: table.cc:5027
#define STATUS_UPDATED
Reserved for use by multi-table update. Means the row has been updated.
Definition: table.h:1275
uint key_block_size
Definition: table.h:771
bool m_secondary_engine
Does this TABLE_SHARE represent a table in a secondary storage engine?
Definition: table.h:1162
static char * path
Definition: mysqldump.cc:123
bool has_deleted_row() const
Definition: table.h:1811
Wait_for_flush_list m_flush_tickets
List of tickets representing threads waiting for the share to be flushed.
Definition: table.h:913
bool is_merged() const
Return true if this is a derived table or view that is merged.
Definition: table.h:2675
Field ** ptr
Definition: table.h:3474
List< Derived_key > derived_key_list
Definition: table.h:3369
Natural_join_column * column_ref()
Definition: table.h:3526
LEX_CSTRING referencing_table_name
Definition: table.h:637
uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n, TABLE_SHARE *share, handler *handler_file, uint *usable_parts)
Generate extended secondary keys by adding primary key parts to the existing secondary key...
Definition: table.cc:796
void set_privileges(ulong privilege)
Set granted privileges for a table.
Definition: table.h:3019
struct Table_share_foreign_key_info TABLE_SHARE_FOREIGN_KEY_INFO
Locks with transaction duration are automatically released at the end of transaction.
Definition: mdl.h:326
~Field_iterator_natural_join()
Definition: table.h:3519
MY_BITMAP * write_set
Definition: table.h:1417
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
ORDER * group
Definition: table.h:1390
Definition: thr_lock.h:98
const Json_diff_vector * get_logical_diffs(const Field_json *field) const
Get the list of JSON diffs that have been collected for a given column in the current row...
Definition: table.cc:7637
bool is_truncated_value() const
Definition: table.h:1204
static uint keys
Definition: hp_test2.cc:43
Opt_hints_qb * opt_hints_qb
Definition: table.h:3041
partition_info * m_part_info
Partition meta data.
Definition: table.h:875
TYPELIB * intervals
Definition: table.h:682
unsigned int len
Definition: dbug_analyze.cc:216
SELECT_LEX_UNIT * derived_unit() const
Return the query expression of a derived table or view.
Definition: table.h:2776
void reset()
Definition: table.h:1184
uint16_t uint16
Definition: my_inttypes.h:60
TABLE_LIST * parent_l
Definition: table.h:3193
Definition: item.h:666
bool uses_materialization() const
Return true if this is a materializable derived table/view.
Definition: table.h:2684
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
Definition: table.h: