MySQL  8.0.16
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_STRING db{nullptr, 0}; /* Pointer to db */
725  LEX_STRING 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 occured.
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  /*
1343  possible_quick_keys is a superset of quick_keys to use with EXPLAIN of
1344  JOIN-less commands (single-table UPDATE and DELETE).
1345 
1346  When explaining regular JOINs, we use JOIN_TAB::keys to output the
1347  "possible_keys" column value. However, it is not available for
1348  single-table UPDATE and DELETE commands, since they don't use JOIN
1349  optimizer at the top level. OTOH they directly use the range optimizer,
1350  that collects all keys usable for range access here.
1351  */
1353 
1354  /*
1355  A set of keys that can be used in the query that references this
1356  table.
1357 
1358  All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be
1359  subtracted from this set upon instantiation. Thus for any TABLE t it holds
1360  that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
1361  must not introduce any new keys here (see setup_tables).
1362 
1363  The set is implemented as a bitmap.
1364  */
1366  /* Map of keys that can be used to calculate GROUP BY without sorting */
1368  /* Map of keys that can be used to calculate ORDER BY without sorting */
1370  KEY *key_info{nullptr}; /* data of keys defined for the table */
1371 
1372  Field *next_number_field{nullptr}; /* Set if next_number is activated */
1373  Field *found_next_number_field{nullptr}; /* Set on open */
1374  /// Pointer to generated columns
1375  Field **vfield{nullptr};
1376  /// Pointer to fields having the default value generated
1378  /// Field used by unique constraint
1379  Field *hash_field{nullptr};
1380  Field *fts_doc_id_field{nullptr}; /* Set if FTS_DOC_ID field is present */
1381 
1382  /* Table's triggers, 0 if there are no of them */
1384  TABLE_LIST *pos_in_table_list{nullptr}; /* Element referring to this table */
1385  /* Position in thd->locked_table_list under LOCK TABLES */
1387  ORDER *group{nullptr};
1388  const char *alias{nullptr}; ///< alias or table name
1389  uchar *null_flags{nullptr}; ///< Pointer to the null flags of record[0]
1391  nullptr}; ///< Saved null_flags while null_row is true
1392 
1393  /* containers */
1395  /*
1396  Bitmap of fields that one or more query condition refers to. Only
1397  used if optimizer_condition_fanout_filter is turned 'on'.
1398  Currently, only the WHERE clause and ON clause of inner joins is
1399  taken into account but not ON conditions of outer joins.
1400  Furthermore, HAVING conditions apply to groups and are therefore
1401  not useful as table condition filters.
1402  */
1404 
1405  /**
1406  Bitmap of table fields (columns), which are explicitly set in the
1407  INSERT INTO statement. It is declared here to avoid memory allocation
1408  on MEM_ROOT).
1409 
1410  @sa fields_set_during_insert.
1411  */
1413 
1414  MY_BITMAP *read_set{nullptr}, *write_set{nullptr}; /* Active column sets */
1415 
1416  /**
1417  A pointer to the bitmap of table fields (columns), which are explicitly set
1418  in the INSERT INTO statement.
1419 
1420  fields_set_during_insert points to def_fields_set_during_insert
1421  for base (non-temporary) tables. In other cases, it is NULL.
1422  Triggers can not be defined for temporary tables, so this bitmap does not
1423  matter for temporary tables.
1424 
1425  @sa def_fields_set_during_insert.
1426  */
1428 
1429  /*
1430  The ID of the query that opened and is using this table. Has different
1431  meanings depending on the table type.
1432 
1433  Temporary tables:
1434 
1435  table->query_id is set to thd->query_id for the duration of a statement
1436  and is reset to 0 once it is closed by the same statement. A non-zero
1437  table->query_id means that a statement is using the table even if it's
1438  not the current statement (table is in use by some outer statement).
1439 
1440  Non-temporary tables:
1441 
1442  Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
1443  for the duration of a statement and is reset to 0 once it is closed by
1444  the same statement. A non-zero query_id is used to control which tables
1445  in the list of pre-opened and locked tables are actually being used.
1446  */
1448 
1449  /*
1450  For each key that has quick_keys.is_set(key) == true: estimate of #records
1451  and max #key parts that range access would use.
1452  */
1454 
1455  /* Bitmaps of key parts that =const for the entire join. */
1457 
1460 
1461  /*
1462  Estimate of number of records that satisfy SARGable part of the table
1463  condition, or table->file->records if no SARGable condition could be
1464  constructed.
1465  This value is used by join optimizer as an estimate of number of records
1466  that will pass the table condition (condition that depends on fields of
1467  this table and constants)
1468  */
1470 
1471  uint lock_position{0}; /* Position in MYSQL_LOCK.table */
1472  uint lock_data_start{0}; /* Start pos. in MYSQL_LOCK.locks */
1473  uint lock_count{0}; /* Number of locks */
1474  uint db_stat{0}; /* mode of file as in handler.h */
1475  int current_lock{0}; /* Type of lock on table */
1476 
1477  // List of table check constraints.
1479 
1480  private:
1481  /**
1482  If true, this table is inner w.r.t. some outer join operation, all columns
1483  are nullable (in the query), and null_row may be true.
1484  */
1485  bool nullable{false};
1486 
1487  uint8 m_status{0}; /* What's in record[0] */
1488  public:
1489  /*
1490  If true, the current table row is considered to have all columns set to
1491  NULL, including columns declared as "not null" (see nullable).
1492  @todo make it private, currently join buffering changes it through a pointer
1493  */
1494  bool null_row{false};
1495 
1496  bool copy_blobs{false}; /* copy_blobs when storing */
1497 
1498  /*
1499  TODO: Each of the following flags take up 8 bits. They can just as easily
1500  be put into one single unsigned long and instead of taking up 18
1501  bytes, it would take up 4.
1502  */
1503  bool force_index{false};
1504 
1505  /**
1506  Flag set when the statement contains FORCE INDEX FOR ORDER BY
1507  See TABLE_LIST::process_index_hints().
1508  */
1509  bool force_index_order{false};
1510 
1511  /**
1512  Flag set when the statement contains FORCE INDEX FOR GROUP BY
1513  See TABLE_LIST::process_index_hints().
1514  */
1515  bool force_index_group{false};
1516  /**
1517  Whether this is a temporary table that already has a UNIQUE index (removing
1518  duplicate rows on insert), so that the optimizer does not need to run
1519  DISTINCT itself.
1520  */
1521  bool is_distinct{false};
1522  bool const_table{false};
1523  /// True if writes to this table should not write rows and just write keys.
1524  bool no_rows{false};
1525 
1526  /**
1527  If set, the optimizer has found that row retrieval should access index
1528  tree only.
1529  */
1530  bool key_read{false};
1531  /**
1532  Certain statements which need the full row, set this to ban index-only
1533  access.
1534  */
1535  bool no_keyread{false};
1536  /**
1537  If set, indicate that the table is not replicated by the server.
1538  */
1539  bool no_replicate{false};
1540  bool fulltext_searched{false};
1541  bool no_cache{false};
1542  /* To signal that the table is associated with a HANDLER statement */
1543  bool open_by_handler{false};
1544  /*
1545  To indicate that a non-null value of the auto_increment field
1546  was provided by the user or retrieved from the current record.
1547  Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
1548  */
1550  bool alias_name_used{false}; /* true if table_name is alias */
1551  bool get_fields_in_item_tree{false}; /* Signal to fix_field */
1552  /**
1553  This table must be reopened and is not to be reused.
1554  NOTE: The TABLE will not be reopened during LOCK TABLES in
1555  close_thread_tables!!!
1556  */
1557  bool m_needs_reopen{false};
1558 
1559  private:
1560  /**
1561  For tmp tables. true <=> tmp table has been instantiated.
1562  Also indicates that table was successfully opened since
1563  we immediately delete tmp tables which we fail to open.
1564  */
1565  bool created{false};
1566 
1567  public:
1568  /// For a materializable derived or SJ table: true if has been materialized
1569  bool materialized{false};
1570  struct /* field connections */
1571  {
1572  class JOIN_TAB *join_tab{nullptr};
1573  class QEP_TAB *qep_tab{nullptr};
1574  thr_lock_type lock_type{TL_UNLOCK}; /* How table is used */
1576  bool not_exists_optimize{false};
1577  /*
1578  true <=> range optimizer found that there is no rows satisfying
1579  table conditions.
1580  */
1581  bool impossible_range{false};
1582  } reginfo;
1583 
1584  /**
1585  @todo This member should not be declared in-line. That makes it
1586  impossible for any function that does memory allocation to take a const
1587  reference to a TABLE object.
1588  */
1590  /**
1591  Initialized in Item_func_group_concat::setup for appropriate
1592  temporary table if GROUP_CONCAT is used with ORDER BY | DISTINCT
1593  and BLOB field count > 0.
1594  */
1597  /**
1598  The result of applying a unique opertion (by row ID) to the table, if done.
1599  In particular, this is done in some forms of index merge.
1600  */
1602  partition_info *part_info{nullptr}; /* Partition related information */
1603  /* If true, all partitions have been pruned away */
1606 
1607  private:
1608  /// Cost model object for operations on this table
1610 #ifndef DBUG_OFF
1611  /**
1612  Internal tmp table sequential number. Increased in the order of
1613  creation. Used for debugging purposes when many tmp tables are used
1614  during execution (e.g several windows with window functions)
1615  */
1617 #endif
1618  public:
1619  void init(THD *thd, TABLE_LIST *tl);
1620  bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root,
1621  CHARSET_INFO *charset, const char *alias, Field **fld,
1622  uint *blob_fld, bool is_virtual);
1623  bool fill_item_list(List<Item> *item_list) const;
1624  void reset_item_list(List<Item> *item_list) const;
1625  void clear_column_bitmaps(void);
1626  void prepare_for_position(void);
1627 
1628  void mark_column_used(Field *field, enum enum_mark_columns mark);
1630  uint key_parts = 0);
1632  void mark_auto_increment_column(void);
1633  void mark_columns_needed_for_update(THD *thd, bool mark_binlog_columns);
1637  void mark_generated_columns(bool is_update);
1638  bool is_field_used_by_generated_columns(uint field_index, int *error_no);
1639  void mark_gcol_in_maps(Field *field);
1640  void column_bitmaps_set(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg);
1641  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
1642  MY_BITMAP *write_set_arg) {
1643  read_set = read_set_arg;
1644  write_set = write_set_arg;
1645  }
1646  inline void use_all_columns() {
1648  }
1649  inline void default_column_bitmaps() {
1652  }
1653  /** Should this instance of the table be reopened? */
1654  inline bool needs_reopen() { return !db_stat || m_needs_reopen; }
1655  /// @returns first non-hidden column
1657  /// @returns count of visible fields
1659  bool alloc_tmp_keys(uint key_count, bool modify_share);
1660  bool add_tmp_key(Field_map *key_parts, char *key_name, bool invisible,
1661  bool modify_share);
1662  void copy_tmp_key(int old_idx, bool modify_share);
1663  void drop_unused_tmp_keys(bool modify_share);
1664 
1665  void set_keyread(bool flag);
1666 
1667  /**
1668  Check whether the given index has a virtual generated columns.
1669 
1670  @param index_no the given index to check
1671 
1672  @returns true if if index is defined over at least one virtual generated
1673  column
1674  */
1675  inline bool index_contains_some_virtual_gcol(uint index_no) {
1676  DBUG_ASSERT(index_no < s->keys);
1677  return key_info[index_no].flags & HA_VIRTUAL_GEN_KEY;
1678  }
1679  bool update_const_key_parts(Item *conds);
1680 
1682 
1684  return (my_ptrdiff_t)(s->default_values - record[0]);
1685  }
1686 
1687  /// Return true if table is instantiated, and false otherwise.
1688  bool is_created() const { return created; }
1689 
1690  /**
1691  Set the table as "created", and enable flags in storage engine
1692  that could not be enabled without an instantiated table.
1693  */
1694  void set_created();
1695  /**
1696  Set the contents of table to be "deleted", ie "not created", after having
1697  deleted the contents.
1698  */
1699  void set_deleted() { created = materialized = false; }
1700  /// Set table as nullable, ie it is inner wrt some outer join
1701  void set_nullable() { nullable = true; }
1702 
1703  /// Return whether table is nullable
1704  bool is_nullable() const { return nullable; }
1705 
1706  /// @return true if table contains one or more generated columns
1707  bool has_gcol() const { return vfield; }
1708 
1709  /**
1710  Life cycle of the row buffer is as follows:
1711  - The initial state is "not started".
1712  - When reading a row through the storage engine handler, the status is set
1713  as "has row" or "no row", depending on whether a row was found or not.
1714  The "not started" state is cleared, as well as the "null row" state,
1715  the updated state and the deleted state.
1716  - When making a row available in record[0], make sure to update row status
1717  similarly to how the storage engine handler does it.
1718  - If a NULL-extended row is needed in join execution, the "null row" state
1719  is set. Note that this can be combined with "has row" if a row was read
1720  but condition on it was evaluated to false (happens for single-row
1721  lookup), or "no row" if no more rows could be read.
1722  Note also that for the "null row" state, the NULL bits inside the
1723  row are set to one, so the row inside the row buffer is no longer usable,
1724  unless the NULL bits are saved in a separate buffer.
1725  - The "is updated" and "is deleted" states are set when row is updated or
1726  deleted, respectively.
1727  */
1728  /// Set status for row buffer as "not started"
1731  null_row = false;
1732  }
1733 
1734  /// @return true if a row operation has been done
1735  bool is_started() const { return !(m_status & STATUS_NOT_STARTED); }
1736 
1737  /// Set status for row buffer: contains row
1738  void set_found_row() {
1739  m_status = 0;
1740  null_row = false;
1741  }
1742 
1743  /**
1744  Set status for row buffer: contains no row. This is set when
1745  - A lookup operation finds no row
1746  - A scan operation scans past the last row of the range.
1747  - An error in generating key values before calling storage engine.
1748  */
1749  void set_no_row() {
1751  null_row = false;
1752  }
1753 
1754  /**
1755  Set "row found" status from handler result
1756 
1757  @param status 0 if row was found, <> 0 if row was not found
1758  */
1761  null_row = false;
1762  }
1763 
1764  /**
1765  Set current row as "null row", for use in null-complemented outer join.
1766  The row buffer may or may not contain a valid row.
1767  set_null_row() and reset_null_row() are used by the join executor to
1768  signal the presence or absence of a NULL-extended row for an outer joined
1769  table. Null rows may also be used to specify rows that are all NULL in
1770  grouing operations.
1771  @note this is a destructive operation since the NULL value bit vector
1772  is overwritten. Caching operations must be aware of this.
1773  */
1774  void set_null_row() {
1775  null_row = true;
1777  if (s->null_bytes > 0) memset(null_flags, 255, s->null_bytes);
1778  }
1779 
1780  /// Clear "null row" status for the current row
1782  null_row = false;
1784  }
1785 
1786  /// Set "updated" property for the current row
1788  DBUG_ASSERT(is_started() && has_row());
1790  }
1791 
1792  /// Set "deleted" property for the current row
1794  DBUG_ASSERT(is_started() && has_row());
1796  }
1797 
1798  /// @return true if there is a row in row buffer
1799  bool has_row() const { return !(m_status & STATUS_NOT_FOUND); }
1800 
1801  /// @return true if current row is null-extended
1802  bool has_null_row() const { return null_row; }
1803 
1804  /// @return true if current row has been updated (multi-table update)
1805  bool has_updated_row() const { return m_status & STATUS_UPDATED; }
1806 
1807  /// @return true if current row has been deleted (multi-table delete)
1808  bool has_deleted_row() const { return m_status & STATUS_DELETED; }
1809 
1810  /// Save the NULL flags of the current row into the designated buffer
1812  if (s->null_bytes > 0) memcpy(null_flags_saved, null_flags, s->null_bytes);
1813  }
1814 
1815  /// Restore the NULL flags of the current row from the designated buffer
1817  if (s->null_bytes > 0) memcpy(null_flags, null_flags_saved, s->null_bytes);
1818  }
1819 
1820  /// Empties internal temporary table (deletes rows, closes scan)
1821  bool empty_result_table();
1822 
1823  /**
1824  Initialize the optimizer cost model.
1825 
1826  This function should be called each time a new query is started.
1827 
1828  @param cost_model_server the main cost model object for the query
1829  */
1830  void init_cost_model(const Cost_model_server *cost_model_server) {
1831  m_cost_model.init(cost_model_server, this);
1832  }
1833 
1834  /**
1835  Return the cost model object for this table.
1836  */
1837  const Cost_model_table *cost_model() const { return &m_cost_model; }
1838 
1839  /**
1840  Fix table's generated columns' (GC) and/or default expressions
1841 
1842  @details When a table is opened from the dictionary, the Value Generator
1843  expressions are fixed during opening (see fix_value_generators_fields()).
1844  After query execution, Item::cleanup() is called on them
1845  (see cleanup_value_generator_items()). When the table is opened from the
1846  table cache, the Value Generetor(s) need to be fixed again and this
1847  function does that.
1848 
1849  @param[in] thd the current thread
1850  @return true if error, else false
1851  */
1852  bool refix_value_generator_items(THD *thd);
1853 
1854  /**
1855  Helper function for refix_value_generator_items() that fixes one column's
1856  expression (be it GC or default expression) and check constraint expression.
1857 
1858  @param[in] thd current thread
1859  @param[in,out] g_expr the expression who's items needs to be fixed
1860  @param[in] table the table it blongs to
1861  @param[in] field the column it blongs to (for GC and Default
1862  expression).
1863  @param[in] source Source of value generator(a generated column, a
1864  regular column with generated default value or
1865  a check constraint).
1866  @param[in] source_name Name of the source (generated column, a reguler
1867  column with generated default value or a check
1868  constraint).
1869 
1870  @return true if error, else false
1871  */
1873  Field *field, TABLE *table,
1874  Value_generator_source source,
1875  const char *source_name);
1876 
1877  /**
1878  Clean any state in items associated with generated columns to be ready for
1879  the next statement.
1880  */
1882 
1883 #ifndef DBUG_OFF
1885 #endif
1886  /**
1887  Update covering keys depending on max read key length.
1888 
1889  Update available covering keys for the table, based on a constrained field
1890  and the identified covering prefix keys: If the matched part of field is
1891  longer than the index prefix,
1892  the prefix index cannot be used as a covering index.
1893 
1894  @param[in] field Pointer to field object
1895  @param[in] key_read_length Max read key length
1896  @param[in] covering_prefix_keys Covering prefix keys
1897  */
1898  void update_covering_prefix_keys(Field *field, uint16 key_read_length,
1899  Key_map *covering_prefix_keys);
1900 
1901  private:
1902  /**
1903  Bitmap that tells which columns are eligible for partial update in an
1904  update statement.
1905 
1906  The bitmap is lazily allocated in the TABLE's mem_root when
1907  #mark_column_for_partial_update() is called.
1908  */
1910 
1911  /**
1912  Object which contains execution time state used for partial update
1913  of JSON columns.
1914 
1915  It is allocated in the execution mem_root by #setup_partial_update() if
1916  there are columns that have been marked as eligible for partial update.
1917  */
1919 
1920  /**
1921  This flag decides whether or not we should log the drop temporary table
1922  command.
1923  */
1925 
1926  public:
1927  /**
1928  Does this table have any columns that can be updated using partial update
1929  in the current row?
1930 
1931  @return whether any columns in the current row can be updated using partial
1932  update
1933  */
1934  bool has_binary_diff_columns() const;
1935 
1936  /**
1937  Get the list of binary diffs that have been collected for a given column in
1938  the current row, or `nullptr` if partial update cannot be used for that
1939  column.
1940 
1941  @param field the column to get binary diffs for
1942  @return the list of binary diffs for the column, or `nullptr` if the column
1943  cannot be updated using partial update
1944  */
1945  const Binary_diff_vector *get_binary_diffs(const Field *field) const;
1946 
1947  /**
1948  Mark a given column as one that can potentially be updated using
1949  partial update during execution of an update statement.
1950 
1951  Whether it is actually updated using partial update, is not
1952  determined until execution time, since that depends both on the
1953  data that is in the column and the new data that is written to the
1954  column.
1955 
1956  This function should be called during preparation of an update
1957  statement.
1958 
1959  @param field a column which is eligible for partial update
1960  @retval false on success
1961  @retval true on out-of-memory
1962  */
1964 
1965  /**
1966  Has this column been marked for partial update?
1967 
1968  Note that this only tells if the column satisfies the syntactical
1969  requirements for being partially updated. Use #is_binary_diff_enabled() or
1970  #is_logical_diff_enabled() instead to see if partial update should be used
1971  on the column.
1972 
1973  @param field the column to check
1974  @return whether the column has been marked for partial update
1975  */
1976  bool is_marked_for_partial_update(const Field *field) const;
1977 
1978  /**
1979  Does this table have any columns that were marked with
1980  #mark_column_for_partial_update()?
1981 
1982  Note that this only tells if any of the columns satisfy the syntactical
1983  requirements for being partially updated. Use
1984  #has_binary_diff_columns(), #is_binary_diff_enabled() or
1985  #is_logical_diff_enabled() instead to see if partial update should be used
1986  on a column.
1987  */
1989 
1990  /**
1991  Enable partial update of JSON columns in this table. It is only
1992  enabled for the columns that have previously been marked for
1993  partial update using #mark_column_for_partial_update().
1994 
1995  @param logical_diffs should logical JSON diffs be collected in addition
1996  to the physical binary diffs?
1997 
1998  This function should be called once per statement execution, when
1999  the update statement is optimized.
2000 
2001  @retval false on success
2002  @retval true on out-of-memory
2003  */
2004  bool setup_partial_update(bool logical_diffs);
2005 
2006  /**
2007  @see setup_partial_update(bool)
2008 
2009  This is a wrapper that auto-computes the value of the parameter
2010  logical_diffs.
2011 
2012  @retval false on success
2013  @retval true on out-of-memory
2014  */
2015  bool setup_partial_update();
2016 
2017  /**
2018  Add a binary diff for a column that is updated using partial update.
2019 
2020  @param field the column that is being updated
2021  @param offset the offset of the changed portion
2022  @param length the length of the changed portion
2023 
2024  @retval false on success
2025  @retval true on out-of-memory
2026  */
2027  bool add_binary_diff(const Field *field, size_t offset, size_t length);
2028 
2029  /**
2030  Clear the diffs that have been collected for partial update of
2031  JSON columns, and re-enable partial update for any columns where
2032  partial update was temporarily disabled for the current row.
2033  Should be called between each row that is updated.
2034  */
2036 
2037  /**
2038  Clean up state used for partial update of JSON columns.
2039 
2040  This function should be called at the end of each statement
2041  execution.
2042  */
2043  void cleanup_partial_update();
2044 
2045  /**
2046  Temporarily disable collection of binary diffs for a column in the current
2047  row.
2048 
2049  This function is called during execution to disable partial update of a
2050  column that was previously marked as eligible for partial update with
2051  #mark_column_for_partial_update() during preparation.
2052 
2053  Partial update of this column will be re-enabled when we go to the next
2054  row.
2055 
2056  @param field the column to stop collecting binary diffs for
2057  */
2059 
2060  /**
2061  Temporarily disable collection of Json_diff objects describing the
2062  logical changes of a JSON column in the current row.
2063 
2064  Collection of logical JSON diffs is re-enabled when we go to the next row.
2065 
2066  @param field the column to stop collecting logical JSON diffs for
2067  */
2069 
2070  /**
2071  Get a buffer that can be used to hold the partially updated column value
2072  while performing partial update.
2073  */
2075 
2076  /**
2077  Add a logical JSON diff describing a logical change to a JSON column in
2078  partial update.
2079 
2080  @param field the column that is updated
2081  @param path the JSON path that is changed
2082  @param operation the operation to perform
2083  @param new_value the new value in the path
2084 
2085  @throws std::bad_alloc if memory cannot be allocated
2086  */
2088  enum_json_diff_operation operation,
2089  const Json_wrapper *new_value);
2090 
2091  /**
2092  Get the list of JSON diffs that have been collected for a given column in
2093  the current row, or `nullptr` if partial update cannot be used for that
2094  column.
2095 
2096  @param field the column to get JSON diffs for
2097  @return the list of JSON diffs for the column, or `nullptr` if the column
2098  cannot be updated using partial update
2099  */
2100  const Json_diff_vector *get_logical_diffs(const Field_json *field) const;
2101 
2102  /**
2103  Is partial update using binary diffs enabled on this JSON column?
2104 
2105  @param field the column to check
2106  @return whether the column can be updated with binary diffs
2107  */
2108  bool is_binary_diff_enabled(const Field *field) const;
2109 
2110  /**
2111  Is partial update using logical diffs enabled on this JSON column?
2112 
2113  @param field the column to check
2114  @return whether the column can be updated with JSON diffs
2115  */
2116  bool is_logical_diff_enabled(const Field *field) const;
2117 
2118  /**
2119  Virtual fields of type BLOB have a flag m_keep_old_value. This flag is set
2120  to false for all such fields in this table.
2121  */
2123 
2124  /**
2125  Set the variable should_binlog_drop_if_temp_flag, so that
2126  the logging of temporary tables can be decided.
2127 
2128  @param should_binlog the value to set flag should_binlog_drop_if_temp_flag
2129  */
2130  void set_binlog_drop_if_temp(bool should_binlog);
2131 
2132  /**
2133  @return whether should_binlog_drop_if_temp_flag flag is
2134  set or not
2135  */
2136  bool should_binlog_drop_if_temp(void) const;
2137 };
2138 
2139 static inline void empty_record(TABLE *table) {
2140  restore_record(table, s->default_values);
2141  if (table->s->null_bytes > 0)
2142  memset(table->null_flags, 255, table->s->null_bytes);
2143 }
2144 
2149 };
2150 
2162 };
2163 
2164 #define MY_I_S_MAYBE_NULL 1
2165 #define MY_I_S_UNSIGNED 2
2166 
2168  /**
2169  This is used as column name.
2170  */
2171  const char *field_name;
2172  /**
2173  For string-type columns, this is the maximum number of
2174  characters. Otherwise, it is the 'display-length' for the column.
2175  For the data type MYSQL_TYPE_DATETIME this field specifies the
2176  number of digits in the fractional part of time value.
2177  */
2179  /**
2180  This denotes data type for the column. For the most part, there seems to
2181  be one entry in the enum for each SQL data type, although there seem to
2182  be a number of additional entries in the enum.
2183  */
2185  int value;
2186  /**
2187  This is used to set column attributes. By default, columns are @c NOT
2188  @c NULL and @c SIGNED, and you can deviate from the default
2189  by setting the appropriate flags. You can use either one of the flags
2190  @c MY_I_S_MAYBE_NULL and @c MY_I_S_UNSIGNED or
2191  combine them using the bitwise or operator @c |. Both flags are
2192  defined in table.h.
2193  */
2194  uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.)
2195  const char *old_name;
2196  uint open_method; // Not used
2197 };
2198 
2200  const char *table_name;
2202  /* Create information_schema table */
2203  TABLE *(*create_table)(THD *thd, TABLE_LIST *table_list);
2204  /* Fill table with data */
2205  int (*fill_table)(THD *thd, TABLE_LIST *tables, Item *cond);
2206  /* Handle fileds for old SHOW */
2207  int (*old_format)(THD *thd, ST_SCHEMA_TABLE *schema_table);
2208  int (*process_table)(THD *thd, TABLE_LIST *tables, TABLE *table, bool res,
2211  bool hidden;
2213 };
2214 
2215 #define JOIN_TYPE_LEFT 1
2216 #define JOIN_TYPE_RIGHT 2
2217 
2218 /**
2219  Strategy for how to process a view or derived table (merge or materialization)
2220 */
2225 };
2226 
2227 #define VIEW_SUID_INVOKER 0
2228 #define VIEW_SUID_DEFINER 1
2229 #define VIEW_SUID_DEFAULT 2
2230 
2231 /* view WITH CHECK OPTION parameter options */
2232 #define VIEW_CHECK_NONE 0
2233 #define VIEW_CHECK_LOCAL 1
2234 #define VIEW_CHECK_CASCADED 2
2235 
2236 /* result of view WITH CHECK OPTION parameter check */
2237 #define VIEW_CHECK_OK 0
2238 #define VIEW_CHECK_ERROR 1
2239 #define VIEW_CHECK_SKIP 2
2240 
2241 /** The threshold size a blob field buffer before it is freed */
2242 #define MAX_TDC_BLOB_SIZE 65536
2243 
2244 /**
2245  Struct that describes an expression selected from a derived table or view.
2246 */
2248  /**
2249  Points to an item that represents the expression.
2250  If the item is determined to be unused, the pointer is set to NULL.
2251  */
2253  /// Name of selected expression
2254  const char *name;
2255 };
2256 
2257 /*
2258  Column reference of a NATURAL/USING join. Since column references in
2259  joins can be both from views and stored tables, may point to either a
2260  Field (for tables), or a Field_translator (for views).
2261 */
2262 
2264  public:
2265  Field_translator *view_field; /* Column reference of merge view. */
2266  Item_field *table_field; /* Column reference of table or temp view. */
2267  TABLE_LIST *table_ref; /* Original base table/view reference. */
2268  /*
2269  True if a common join column of two NATURAL/USING join operands. Notice
2270  that when we have a hierarchy of nested NATURAL/USING joins, a column can
2271  be common at some level of nesting but it may not be common at higher
2272  levels of nesting. Thus this flag may change depending on at which level
2273  we are looking at some column.
2274  */
2276 
2277  public:
2278  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
2279  Natural_join_column(Item_field *field_param, TABLE_LIST *tab);
2280  const char *name();
2281  Item *create_item(THD *thd);
2282  Field *field();
2283  const char *table_name();
2284  const char *db_name();
2285  GRANT_INFO *grant();
2286 };
2287 
2288 /**
2289  This is generic enum. It may be reused in the ACL statements
2290  for clauses that can map to the values defined in this enum.
2291 */
2293  UNCHANGED, /* The clause is not specified */
2294  DEFAULT, /* Default value of clause is specified */
2295  YES, /* Value that maps to True is specified */
2296  NO /* Value that maps to False is specified */
2297 };
2298 
2299 /*
2300  This structure holds the specifications relating to
2301  ALTER user ... PASSWORD EXPIRE ...
2302 */
2303 struct LEX_ALTER {
2316  /* Holds the specification of 'PASSWORD REQUIRE CURRENT' clause. */
2318  void cleanup() {
2322  expire_after_days = 0;
2324  account_locked = false;
2326  update_password_history = false;
2332  }
2333 };
2334 
2335 /*
2336  This structure holds the specifications related to
2337  mysql user and the associated auth details.
2338 */
2339 struct LEX_USER {
2345  /*
2346  The following flags are indicators for the SQL syntax used while
2347  parsing CREATE/ALTER user. While other members are self-explanatory,
2348  'uses_authentication_string_clause' signifies if the password is in
2349  hash form (if the var was set to true) or not.
2350  */
2358  /*
2359  Allocates the memory in the THD mem pool and initialize the members of
2360  this struct. It is prefererable to use this method to create a LEX_USER
2361  rather allocating the memory in the THD and initilizing the members
2362  explicitiyly.
2363  */
2364  static LEX_USER *alloc(THD *thd, LEX_STRING *user, LEX_STRING *host);
2365 };
2366 
2367 /**
2368  Derive type of metadata lock to be requested for table used by a DML
2369  statement from the type of THR_LOCK lock requested for this table.
2370 */
2371 
2372 inline enum enum_mdl_type mdl_type_for_dml(enum thr_lock_type lock_type) {
2373  return lock_type >= TL_WRITE_ALLOW_WRITE
2375  : MDL_SHARED_WRITE)
2376  : MDL_SHARED_READ;
2377 }
2378 
2379 /**
2380  Type of table which can be open for an element of table list.
2381 */
2382 
2387 };
2388 
2389 /**
2390  This structure is used to keep info about possible key for the result table
2391  of a derived table/view.
2392  The 'referenced_by' is the table map of tables to which this possible
2393  key corresponds.
2394  The 'used_field' is a map of fields of which this key consists of.
2395  See also the comment for the TABLE_LIST::update_derived_keys function.
2396 */
2397 
2399  public:
2402 };
2403 
2404 class Table_function;
2405 /*
2406  Table reference in the FROM clause.
2407 
2408  These table references can be of several types that correspond to
2409  different SQL elements. Below we list all types of TABLE_LISTs with
2410  the necessary conditions to determine when a TABLE_LIST instance
2411  belongs to a certain type.
2412 
2413  1) table (TABLE_LIST::view == NULL)
2414  - base table
2415  (TABLE_LIST::derived == NULL)
2416  - subquery - TABLE_LIST::table is a temp table
2417  (TABLE_LIST::derived != NULL)
2418  - information schema table
2419  (TABLE_LIST::schema_table != NULL)
2420  NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
2421  2) view (TABLE_LIST::view != NULL)
2422  - merge (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
2423  also (TABLE_LIST::field_translation != NULL)
2424  - temptable(TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TEMPTABLE)
2425  also (TABLE_LIST::field_translation == NULL)
2426  3) nested table reference (TABLE_LIST::nested_join != NULL)
2427  - table sequence - e.g. (t1, t2, t3)
2428  TODO: how to distinguish from a JOIN?
2429  - general JOIN
2430  TODO: how to distinguish from a table sequence?
2431  - NATURAL JOIN
2432  (TABLE_LIST::natural_join != NULL)
2433  - JOIN ... USING
2434  (TABLE_LIST::join_using_fields != NULL)
2435  - semi-join
2436  ;
2437 */
2438 
2439 struct TABLE_LIST {
2440  TABLE_LIST() = default;
2441 
2442  explicit TABLE_LIST(TABLE *table_arg) : table(table_arg) {}
2443 
2444  TABLE_LIST(const char *db_name_arg, size_t db_length_arg,
2445  const char *table_name_arg, size_t table_name_length_arg,
2446  const char *alias_arg, enum thr_lock_type lock_type_arg)
2447  : TABLE_LIST(nullptr, db_name_arg, db_length_arg, table_name_arg,
2448  table_name_length_arg, alias_arg, lock_type_arg) {}
2449 
2450  TABLE_LIST(const char *db_name_arg, size_t db_length_arg,
2451  const char *table_name_arg, size_t table_name_length_arg,
2452  const char *alias_arg, enum thr_lock_type lock_type_arg,
2453  enum enum_mdl_type mdl_request_type)
2454  : TABLE_LIST(nullptr, db_name_arg, db_length_arg, table_name_arg,
2455  table_name_length_arg, alias_arg, lock_type_arg) {
2456  mdl_request.set_type(mdl_request_type);
2457  }
2458 
2459  TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2460  const char *table_name_arg, size_t table_name_length_arg,
2461  const char *alias_arg, enum thr_lock_type lock_type_arg)
2462  : db(db_name_arg),
2463  table_name(table_name_arg),
2464  alias(alias_arg),
2465  m_map(1),
2466  table(table_arg),
2467  m_lock_descriptor{lock_type_arg},
2468  db_length(db_length_arg),
2469  table_name_length(table_name_length_arg) {
2472  }
2473 
2474  /**
2475  Sets an explicit enum_mdl_type value, without initializing
2476  m_lock_descriptor.
2477  */
2478  TABLE_LIST(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2479  const char *table_name_arg, size_t table_name_length_arg,
2480  const char *alias_arg, enum_mdl_type mdl_type)
2481  : db(db_name_arg),
2482  table_name(table_name_arg),
2483  alias(alias_arg),
2484  m_map(1),
2485  table(table_arg),
2486  db_length(db_length_arg),
2487  table_name_length(table_name_length_arg) {
2489  MDL_TRANSACTION);
2490  }
2491 
2492  /**
2493  Do not use this function in new code. It exists only for legacy code.
2494  Prepare TABLE_LIST that consists of one table instance to use in
2495  simple_open_and_lock_tables
2496  */
2497  inline void init_one_table(const char *db_name_arg, size_t db_length_arg,
2498  const char *table_name_arg,
2499  size_t table_name_length_arg,
2500  const char *alias_arg,
2501  enum thr_lock_type lock_type_arg) {
2502  *this = TABLE_LIST();
2503  m_map = 1;
2504  db = db_name_arg;
2505  db_length = db_length_arg;
2506  table_name = table_name_arg;
2507  table_name_length = table_name_length_arg;
2508  alias = alias_arg;
2509  m_lock_descriptor.type = lock_type_arg;
2512  }
2513 
2514  /**
2515  Do not use this function in new code. It exists only for legacy code.
2516  Auxiliary method which prepares TABLE_LIST consisting of one table instance
2517  to be used in simple open_and_lock_tables and takes type of MDL lock on the
2518  table as explicit parameter.
2519  */
2520 
2521  inline void init_one_table(const char *db_name_arg, size_t db_length_arg,
2522  const char *table_name_arg,
2523  size_t table_name_length_arg,
2524  const char *alias_arg,
2525  enum thr_lock_type lock_type_arg,
2526  enum enum_mdl_type mdl_request_type) {
2527  init_one_table(db_name_arg, db_length_arg, table_name_arg,
2528  table_name_length_arg, alias_arg, lock_type_arg);
2529  mdl_request.set_type(mdl_request_type);
2530  }
2531 
2532  /// Create a TABLE_LIST object representing a nested join
2533  static TABLE_LIST *new_nested_join(MEM_ROOT *allocator, const char *alias,
2535  List<TABLE_LIST> *belongs_to,
2536  SELECT_LEX *select);
2537 
2538  Item **join_cond_ref() { return &m_join_cond; }
2539  Item *join_cond() const { return m_join_cond; }
2540  void set_join_cond(Item *val) {
2541  // If optimization has started, it's too late to change m_join_cond.
2543  m_join_cond = val;
2544  }
2547  /*
2548  Either we are setting to "empty", or there must pre-exist a
2549  permanent condition.
2550  */
2551  DBUG_ASSERT(cond == NULL || cond == (Item *)1 || m_join_cond != NULL);
2552  m_join_cond_optim = cond;
2553  }
2555 
2556  /// Get the semi-join condition for a semi-join nest, NULL otherwise
2557  Item *sj_cond() const { return m_sj_cond; }
2558 
2559  /// Set the semi-join condition for a semi-join nest
2560  void set_sj_cond(Item *cond) {
2562  m_sj_cond = cond;
2563  }
2564 
2565  /// Merge tables from a query block into a nested join structure
2566  bool merge_underlying_tables(SELECT_LEX *select);
2567 
2568  /// Reset table
2569  void reset();
2570 
2571  /// Evaluate the check option of a view
2572  int view_check_option(THD *thd) const;
2573 
2574  /// Cleanup field translations for a view
2575  void cleanup_items();
2576 
2577  /// Produce a textual identification of this object
2578  void print(const THD *thd, String *str, enum_query_type query_type) const;
2579 
2580  /// Check which single table inside a view that matches a table map
2581  bool check_single_table(TABLE_LIST **table_ref, table_map map);
2582 
2583  /// Allocate a buffer for inserted column values
2585 
2588  bool is_leaf_for_name_resolution() const;
2589 
2590  /// Return the outermost view this table belongs to, or itself
2591  inline const TABLE_LIST *top_table() const {
2592  return belong_to_view ? belong_to_view : this;
2593  }
2594 
2595  inline TABLE_LIST *top_table() {
2596  return const_cast<TABLE_LIST *>(
2597  const_cast<const TABLE_LIST *>(this)->top_table());
2598  }
2599 
2600  /// Prepare check option for a view
2601  bool prepare_check_option(THD *thd, bool is_cascaded = false);
2602 
2603  /// Merge WHERE condition of view or derived table into outer query
2604  bool merge_where(THD *thd);
2605 
2606  /// Prepare replace filter for a view (used for REPLACE command)
2607  bool prepare_replace_filter(THD *thd);
2608 
2609  /// Return true if this represents a named view
2610  bool is_view() const { return view != NULL; }
2611 
2612  /// Return true if this represents a derived table (an unnamed view)
2613  bool is_derived() const { return derived != NULL && view == NULL; }
2614 
2615  /// Return true if this represents a named view or a derived table
2616  bool is_view_or_derived() const { return derived != NULL; }
2617 
2618  /// Return true if this represents a table function
2619  bool is_table_function() const { return table_function != NULL; }
2620  /**
2621  @returns true if this is a recursive reference inside the definition of a
2622  recursive CTE.
2623  @note that it starts its existence as a dummy derived table, until the
2624  end of resolution when it's not a derived table anymore, just a reference
2625  to the materialized temporary table. Whereas a non-recursive
2626  reference to the recursive CTE is a derived table.
2627  */
2629 
2630  /**
2631  @see is_recursive_reference().
2632  @returns true if error
2633  */
2634  bool set_recursive_reference();
2635 
2636  /**
2637  @returns true for a table that represents an optimizer internal table,
2638  is a derived table, a recursive reference, a table function.
2639  Internal tables are only visible inside a query expression, and is hence
2640  not visible in any schema, or need any kind of privilege checking.
2641  */
2642  bool is_internal() const {
2644  }
2645 
2646  /**
2647  @returns true for a table that is a placeholder, ie a derived table,
2648  a view, a recursive reference, a table function or a schema table.
2649  A table is also considered to be a placeholder if it does not have a
2650  TABLE object for some other reason.
2651  */
2652  bool is_placeholder() const {
2654  is_table_function() || schema_table || table == nullptr;
2655  }
2656 
2657  /// Return true if view or derived table and can be merged
2658  bool is_mergeable() const;
2659 
2660  /**
2661  @returns true if materializable table contains one or zero rows.
2662 
2663  Returning true implies that the table is materialized during optimization,
2664  so it need not be optimized during execution.
2665  */
2666  bool materializable_is_const() const;
2667 
2668  /// Return true if this is a derived table or view that is merged
2670 
2671  /// Set table to be merged
2672  void set_merged() {
2675  }
2676 
2677  /// Return true if this is a materializable derived table/view
2678  bool uses_materialization() const {
2680  }
2681 
2682  /// Set table to be materialized
2684  // @todo We should do this only once, but currently we cannot:
2685  // DBUG_ASSERT(effective_algorithm == VIEW_ALGORITHM_UNDEFINED);
2688  }
2689 
2690  /// Return true if table is updatable
2691  bool is_updatable() const { return m_updatable; }
2692 
2693  /// Set table as updatable. (per default, a table is non-updatable)
2694  void set_updatable() { m_updatable = true; }
2695 
2696  /// Return true if table is insertable-into
2697  bool is_insertable() const { return m_insertable; }
2698 
2699  /// Set table as insertable-into. (per default, a table is not insertable)
2700  void set_insertable() { m_insertable = true; }
2701 
2702  /**
2703  Set table as readonly, ie it is neither updatable, insertable nor
2704  deletable during this statement.
2705  */
2706  void set_readonly() {
2707  m_updatable = false;
2708  m_insertable = false;
2709  }
2710 
2711  /**
2712  Return true if this is a view or derived table that is defined over
2713  more than one base table, and false otherwise.
2714  */
2715  bool is_multiple_tables() const {
2716  if (is_view_or_derived()) {
2717  DBUG_ASSERT(is_merged()); // Cannot be a materialized view
2718  return leaf_tables_count() > 1;
2719  } else {
2720  DBUG_ASSERT(nested_join == NULL); // Must be a base table
2721  return false;
2722  }
2723  }
2724 
2725  /// Return no. of base tables a merged view or derived table is defined over.
2726  uint leaf_tables_count() const;
2727 
2728  /// Return first leaf table of a base table or a view/derived table
2730  TABLE_LIST *tr = this;
2731  while (tr->merge_underlying_list) tr = tr->merge_underlying_list;
2732  return tr;
2733  }
2734 
2735  /// Return any leaf table that is not an inner table of an outer join
2736  /// @todo when WL#6570 is implemented, replace with first_leaf_table()
2738  TABLE_LIST *tr = this;
2739  while (tr->merge_underlying_list) {
2740  tr = tr->merge_underlying_list;
2741  /*
2742  "while" is used, however, an "if" might be sufficient since there is
2743  no more than one inner table in a join nest (with outer_join true).
2744  */
2745  while (tr->outer_join) tr = tr->next_local;
2746  }
2747  return tr;
2748  }
2749  /**
2750  Set the LEX object of a view (will also define this as a view).
2751  @note: The value 1 is used to indicate a view but without a valid
2752  query object. Use only if the LEX object is not going to
2753  be used in later processing.
2754  */
2755  void set_view_query(LEX *lex) { view = lex; }
2756 
2757  /// Return the valid LEX object for a view.
2758  LEX *view_query() const {
2759  DBUG_ASSERT(view != NULL && view != (LEX *)1);
2760  return view;
2761  }
2762 
2763  /**
2764  Set the query expression of a derived table or view.
2765  (Will also define this as a derived table, unless it is a named view.)
2766  */
2767  void set_derived_unit(SELECT_LEX_UNIT *query_expr) { derived = query_expr; }
2768 
2769  /// Return the query expression of a derived table or view.
2772  return derived;
2773  }
2774 
2775  /// Save names of materialized table @see reset_name_temporary
2777  view_db.str = db;
2781  }
2782 
2783  /// Set temporary name from underlying temporary table:
2788  db = (char *)"";
2789  db_length = 0;
2790  }
2791 
2792  /// Reset original name for temporary table.
2796  /*
2797  When printing a query using a view or CTE, we need the table's name and
2798  the alias; the name has been destroyed if the table was materialized,
2799  so we restore it:
2800  */
2804  if (is_view()) // restore database's name too
2805  {
2806  DBUG_ASSERT(db != view_db.str);
2807  db = view_db.str;
2809  }
2810  }
2811 
2812  /// Resolve a derived table or view reference
2813  bool resolve_derived(THD *thd, bool apply_semijoin);
2814 
2815  /// Optimize the query expression representing a derived table/view
2816  bool optimize_derived(THD *thd);
2817 
2818  /// Create result table for a materialized derived table/view
2819  bool create_materialized_table(THD *thd);
2820 
2821  /// Materialize derived table
2822  bool materialize_derived(THD *thd);
2823 
2824  /// Clean up the query expression for a materialized derived table
2825  bool cleanup_derived(THD *thd);
2826 
2827  /// Prepare security context for a view
2828  bool prepare_security(THD *thd);
2829 
2832 
2833  /// Cleanup for re-execution in a prepared statement or a stored procedure.
2834  void reinit_before_use(THD *thd);
2835 
2836  /**
2837  Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query,
2838  TABLE::keys_in_use_for_group_by, TABLE::keys_in_use_for_order_by,
2839  TABLE::force_index and TABLE::covering_keys.
2840  */
2841  bool process_index_hints(const THD *thd, TABLE *table);
2842 
2843  /**
2844  Compare the version of metadata from the previous execution
2845  (if any) with values obtained from the current table
2846  definition cache element.
2847 
2848  @sa check_and_update_table_version()
2849  */
2851  return (m_table_ref_type == s->get_table_ref_type() &&
2853  }
2854 
2855  /**
2856  Record the value of metadata version of the corresponding
2857  table definition cache element in this parse tree node.
2858 
2859  @sa check_and_update_table_version()
2860  */
2863  }
2864 
2865  void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
2866  ulonglong table_ref_version_arg) {
2867  m_table_ref_type = table_ref_type_arg;
2868  m_table_ref_version = table_ref_version_arg;
2869  }
2870 
2871  /**
2872  If a derived table, returns query block id of first underlying query block.
2873  Zero if not derived.
2874  */
2875  uint query_block_id() const;
2876 
2877  /**
2878  This is for showing in EXPLAIN.
2879  If a derived table, returns query block id of first underlying query block
2880  of first materialized TABLE_LIST instance. Zero if not derived.
2881  */
2883 
2884  /**
2885  @brief Returns the name of the database that the referenced table belongs
2886  to.
2887  */
2888  const char *get_db_name() const { return view != NULL ? view_db.str : db; }
2889 
2890  /**
2891  @brief Returns the name of the table that this TABLE_LIST represents.
2892 
2893  @details The unqualified table name or view name for a table or view,
2894  respectively.
2895  */
2896  const char *get_table_name() const {
2897  return view != NULL ? view_name.str : table_name;
2898  }
2899  int fetch_number_of_rows();
2900  bool update_derived_keys(Field *, Item **, uint);
2901  bool generate_keys();
2902 
2903  /// Setup a derived table to use materialization
2904  bool setup_materialized_derived(THD *thd);
2906 
2907  /// Setup a table function to use materialization
2908  bool setup_table_function(THD *thd);
2909 
2910  bool create_field_translation(THD *thd);
2911 
2912  /**
2913  @brief Returns the outer join nest that this TABLE_LIST belongs to, if any.
2914 
2915  @details There are two kinds of join nests, outer-join nests and semi-join
2916  nests. This function returns non-NULL in the following cases:
2917  @li 1. If this table/nest is embedded in a nest and this nest IS NOT a
2918  semi-join nest. (In other words, it is an outer-join nest.)
2919  @li 2. If this table/nest is embedded in a nest and this nest IS a
2920  semi-join nest, but this semi-join nest is embedded in another
2921  nest. (This other nest will be an outer-join nest, since all inner
2922  joined nested semi-join nests have been merged in
2923  @c simplify_joins() ).
2924  Note: This function assumes that @c simplify_joins() has been performed.
2925  Before that, join nests will be present for all types of join.
2926 
2927  @return outer join nest, or NULL if none.
2928  */
2929 
2931  if (!embedding) return NULL;
2932  if (embedding->sj_cond()) return embedding->embedding;
2933  return embedding;
2934  }
2935  /**
2936  Return true if this table is an inner table of some outer join.
2937 
2938  Examine all the embedding join nests of the table.
2939  @note This function works also before redundant join nests have been
2940  eliminated.
2941 
2942  @return true if table is an inner table of some outer join, false otherwise.
2943  */
2944 
2946  if (outer_join) return true;
2947  for (TABLE_LIST *emb = embedding; emb; emb = emb->embedding) {
2948  if (emb->outer_join) return true;
2949  }
2950  return false;
2951  }
2952 
2953  /**
2954  Return the base table entry of an updatable table.
2955  In DELETE and UPDATE, a view used as a target table must be mergeable,
2956  updatable and defined over a single table.
2957  */
2959  TABLE_LIST *tbl = this;
2960  DBUG_ASSERT(tbl->is_updatable() && !tbl->is_multiple_tables());
2961  while (tbl->is_view_or_derived()) {
2962  tbl = tbl->merge_underlying_list;
2963  DBUG_ASSERT(tbl->is_updatable() && !tbl->is_multiple_tables());
2964  }
2965  return tbl;
2966  }
2967 
2968  /**
2969  Mark that there is a NATURAL JOIN or JOIN ... USING between two tables.
2970 
2971  This function marks that table b should be joined with a either via
2972  a NATURAL JOIN or via JOIN ... USING. Both join types are special
2973  cases of each other, so we treat them together. The function
2974  setup_conds() creates a list of equal condition between all fields
2975  of the same name for NATURAL JOIN or the fields in
2976  TABLE_LIST::join_using_fields for JOIN ... USING.
2977  The list of equality conditions is stored
2978  either in b->join_cond(), or in JOIN::conds, depending on whether there
2979  was an outer join.
2980 
2981  EXAMPLE
2982  @verbatim
2983  SELECT * FROM t1 NATURAL LEFT JOIN t2
2984  <=>
2985  SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
2986 
2987  SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
2988  <=>
2989  SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
2990 
2991  SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
2992  <=>
2993  SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
2994  @endverbatim
2995 
2996  @param b Right join argument.
2997  */
2998  void add_join_natural(TABLE_LIST *b) { b->natural_join = this; }
2999 
3000  /**
3001  Set granted privileges for a table.
3002 
3003  Can be used when generating temporary tables that are also used in
3004  resolver process, such as when generating a UNION table
3005 
3006  @param privilege Privileges granted for this table.
3007  */
3008  void set_privileges(ulong privilege) { grant.privilege |= privilege; }
3009  /*
3010  List of tables local to a subquery or the top-level SELECT (used by
3011  SQL_I_List). Considers views as leaves (unlike 'next_leaf' below).
3012  Created at parse time in SELECT_LEX::add_table_to_list() ->
3013  table_list.link_in_list().
3014  */
3016  /* link in a global list of all queries tables */
3017  TABLE_LIST *next_global{nullptr}, **prev_global{nullptr};
3018  const char *db{nullptr}, *table_name{nullptr}, *alias{nullptr};
3019  /*
3020  Target tablespace name: When creating or altering tables, this
3021  member points to the tablespace_name in the HA_CREATE_INFO struct.
3022  */
3024  char *schema_table_name{nullptr};
3025  char *option{nullptr}; /* Used by cache index */
3026 
3027  /** Table level optimizer hints for this table. */
3029  /* Hints for query block of this table. */
3031 
3034  }
3035 
3037 
3038  private:
3039  /**
3040  The members below must be kept aligned so that (1 << m_tableno) == m_map.
3041  A table that takes part in a join operation must be assigned a unique
3042  table number.
3043  */
3044  uint m_tableno{0}; ///< Table number within query block
3045  table_map m_map{0}; ///< Table map, derived from m_tableno
3046  /**
3047  If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this
3048  member points to C. May also be generated from JOIN ... USING clause.
3049  It may be modified only by permanent transformations (permanent = done
3050  once for all executions of a prepared statement).
3051  */
3052  Item *m_join_cond{nullptr};
3053  Item *m_sj_cond{nullptr}; ///< Synthesized semijoin condition
3054  public:
3055  /*
3056  (Valid only for semi-join nests) Bitmap of tables that are within the
3057  semi-join (this is different from bitmap of all nest's children because
3058  tables that were pulled out of the semi-join nest remain listed as
3059  nest's children).
3060  */
3062 
3063  /*
3064  During parsing - left operand of NATURAL/USING join where 'this' is
3065  the right operand. After parsing (this->natural_join == this) iff
3066  'this' represents a NATURAL or USING join operation. Thus after
3067  parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
3068  */
3070  /*
3071  True if 'this' represents a nested join that is a NATURAL JOIN.
3072  For one of the operands of 'this', the member 'natural_join' points
3073  to the other operand of 'this'.
3074  */
3075  bool is_natural_join{false};
3076  /* Field names in a USING clause for JOIN ... USING. */
3078  /*
3079  Explicitly store the result columns of either a NATURAL/USING join or
3080  an operand of such a join.
3081  */
3083  /* true if join_columns contains all columns of this table reference. */
3085 
3086  /*
3087  List of nodes in a nested join tree, that should be considered as
3088  leaves with respect to name resolution. The leaves are: views,
3089  top-most nodes representing NATURAL/USING joins, subqueries, and
3090  base tables. All of these TABLE_LIST instances contain a
3091  materialized list of columns. The list is local to a subquery.
3092  */
3094  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
3096  TABLE *table{nullptr}; /* opened table */
3097  Table_id table_id{}; /* table id (from binlog) for opened table */
3098  /*
3099  Query_result for derived table to pass it from table creation to table
3100  filling procedure
3101  */
3103  /*
3104  Reference from aux_tables to local list entry of main select of
3105  multi-delete statement:
3106  delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
3107  here it will be reference of first occurrence of t1 to second (as you
3108  can see this lists can't be merged)
3109  */
3111 
3112  /*
3113  Holds the function used as the table function
3114  */
3116 
3117  private:
3118  /**
3119  This field is set to non-null for derived tables and views. It points
3120  to the SELECT_LEX_UNIT representing the derived table/view.
3121  E.g. for a query
3122  @verbatim SELECT * FROM (SELECT a FROM t1) b @endverbatim
3123  */
3124  SELECT_LEX_UNIT *derived{nullptr}; /* SELECT_LEX_UNIT of derived table */
3125 
3126  /// If non-NULL, the CTE which this table is derived from.
3128  /**
3129  If the user has specified column names with the syntaxes "table name
3130  parenthesis column names":
3131  WITH qn(column names) AS (select...)
3132  or
3133  FROM (select...) dt(column names)
3134  or
3135  CREATE VIEW v(column_names) AS ...
3136  then this points to the list of column names. NULL otherwise.
3137  */
3139 
3140  public:
3141  ST_SCHEMA_TABLE *schema_table{nullptr}; /* Information_schema table */
3143  /*
3144  True when the view field translation table is used to convert
3145  schema table fields for backwards compatibility with SHOW command.
3146  */
3149  /* link to select_lex where this table was used */
3151 
3152  private:
3153  LEX *view{nullptr}; /* link on VIEW lex for merging */
3154 
3155  public:
3156  /// Array of selected expressions from a derived table or view.
3158 
3159  /// pointer to element after last one in translation table above
3161  /*
3162  List (based on next_local) of underlying tables of this view. I.e. it
3163  does not include the tables of subqueries used in the view. Is set only
3164  for merged views.
3165  */
3167  /*
3168  - 0 for base tables
3169  - in case of the view it is the list of all (not only underlying
3170  tables but also used in subquery ones) tables of the view.
3171  */
3173  /* most upper view this table belongs to */
3175  /*
3176  The view directly referencing this table
3177  (non-zero only for merged underlying tables of a view).
3178  */
3180  /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
3182  /*
3183  Security context (non-zero only for tables which belong
3184  to view with SQL SECURITY DEFINER)
3185  */
3187  /*
3188  This view security context (non-zero only for views with
3189  SQL SECURITY DEFINER)
3190  */
3192  /*
3193  List of all base tables local to a subquery including all view
3194  tables. Unlike 'next_local', this in this list views are *not*
3195  leaves. Created in setup_tables() -> make_leaf_tables().
3196  */
3198  Item *derived_where_cond{nullptr}; ///< WHERE condition from derived table
3199  Item *check_option{nullptr}; ///< WITH CHECK OPTION condition
3200  Item *replace_filter{nullptr}; ///< Filter for REPLACE command
3201  LEX_STRING select_stmt{nullptr, 0}; ///< text of (CREATE/SELECT) statement
3202  LEX_STRING source{nullptr, 0}; ///< source of CREATE VIEW
3203  LEX_CSTRING view_db{nullptr, 0}; ///< saved view database
3204  LEX_CSTRING view_name{nullptr, 0}; ///< saved view name
3205  LEX_STRING timestamp{nullptr, 0}; ///< GMT time stamp of last operation
3206  LEX_USER definer; ///< definer of view
3207  /**
3208  @note: This field is currently not reliable when read from dictionary:
3209  If an underlying view is changed, updatable_view is not changed,
3210  due to lack of dependency checking in dictionary implementation.
3211  Prefer to use is_updatable() during preparation and optimization.
3212  */
3213  ulonglong updatable_view{0}; ///< VIEW can be updated
3214  /**
3215  @brief The declared algorithm, if this is a view.
3216  @details One of
3217  - VIEW_ALGORITHM_UNDEFINED
3218  - VIEW_ALGORITHM_TEMPTABLE
3219  - VIEW_ALGORITHM_MERGE
3220  @todo Replace with an enum
3221  */
3223  ulonglong view_suid{0}; ///< view is suid (true by default)
3224  ulonglong with_check{0}; ///< WITH CHECK OPTION
3225 
3226  private:
3227  /// The view algorithm that is actually used, if this is a view.
3230 
3231  public:
3233 
3234  public:
3235  uint outer_join{0}; /* Which join type */
3236  uint shared{0}; /* Used in multi-upd */
3237  size_t db_length{0};
3239 
3240  private:
3241  bool m_updatable{false}; /* VIEW/TABLE can be updated */
3242  bool m_insertable{false}; /* VIEW/TABLE can be inserted into */
3243  public:
3244  bool straight{false}; /* optimize with prev table */
3245  /**
3246  True for tables and views being changed in a data change statement.
3247  Also used by replication to filter out statements that can be ignored,
3248  especially important for multi-table UPDATE and DELETE.
3249  */
3250  bool updating{false};
3251  bool force_index{false}; /* prefer index over table scan */
3252  bool ignore_leaves{false}; /* preload only non-leaf nodes */
3253  table_map dep_tables{0}; /* tables the table depends on */
3254  table_map on_expr_dep_tables{0}; /* tables on expression depends on */
3255  NESTED_JOIN *nested_join{nullptr}; /* if the element is a nested join */
3256  TABLE_LIST *embedding{nullptr}; /* nested join containing the table */
3257  List<TABLE_LIST> *join_list{nullptr}; /* join list the table belongs to */
3258  bool cacheable_table{false}; /* stop PS caching */
3259  /**
3260  Specifies which kind of table should be open for this element
3261  of table list.
3262  */
3264  /* true if this merged view contain auto_increment field */
3266  /// true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
3268  /// true <=> Filter condition is processed
3270 
3272  char timestamp_buffer[20]{0}; /* buffer for timestamp (19+1) */
3273  /*
3274  This TABLE_LIST object is just placeholder for prelocking, it will be
3275  used for implicit LOCK TABLES only and won't be used in real statement.
3276  */
3278  /**
3279  Indicates that if TABLE_LIST object corresponds to the table/view
3280  which requires special handling.
3281  */
3282  enum {
3283  /* Normal open. */
3285  /* Associate a table share only if the the table exists. */
3287  /*
3288  Associate a table share only if the the table exists.
3289  Also upgrade metadata lock to exclusive if table doesn't exist.
3290  */
3292  /* Don't associate a table share. */
3294  } open_strategy{OPEN_NORMAL};
3295  bool internal_tmp_table{false};
3296  /** true if an alias for this table was specified in the SQL. */
3297  bool is_alias{false};
3298  /** true if the table is referred to in the statement using a fully
3299  qualified name (@<db_name@>.@<table_name@>).
3300  */
3301  bool is_fqtn{false};
3302 
3303  /* View creation context. */
3304 
3306 
3307  /*
3308  Attributes to save/load view creation context in/from frm-file.
3309 
3310  They are required only to be able to use existing parser to load
3311  view-definition file. As soon as the parser parsed the file, view
3312  creation context is initialized and the attributes become redundant.
3313 
3314  These attributes MUST NOT be used for any purposes but the parsing.
3315  */
3316 
3319 
3320  /*
3321  View definition (SELECT-statement) in the UTF-form.
3322  */
3323 
3325 
3326  // True, If this is a system view
3327  bool is_system_view{false};
3328 
3329  /*
3330  Set to 'true' if this is a DD table being opened in the context of a
3331  dictionary operation. Note that when 'false', this may still be a DD
3332  table when opened in a non-DD context, e.g. as part of an I_S view
3333  query.
3334  */
3335  bool is_dd_ctx_table{false};
3336 
3337  /* End of view definition context. */
3338 
3339  /* List of possible keys. Valid only for materialized derived tables/views. */
3341 
3342  /**
3343  Indicates what triggers we need to pre-load for this TABLE_LIST
3344  when opening an associated TABLE. This is filled after
3345  the parsed tree is created.
3346  */
3349  bool has_db_lookup_value{false};
3353 
3355 
3356  /// if true, EXPLAIN can't explain view due to insufficient rights.
3357  bool view_no_explain{false};
3358 
3359  /* List to carry partition names from PARTITION (...) clause in statement */
3361 
3362  /// Set table number
3365  m_tableno = tableno;
3366  m_map = (table_map)1 << tableno;
3367  }
3368  /// Return table number
3369  uint tableno() const { return m_tableno; }
3370 
3371  /// Return table map derived from table number
3372  table_map map() const {
3373  DBUG_ASSERT(((table_map)1 << m_tableno) == m_map);
3374  return m_map;
3375  }
3376 
3377  /// If non-NULL, the CTE which this table is derived from.
3380  /// @see m_derived_column_names
3382  return m_derived_column_names;
3383  }
3386  }
3387  void propagate_table_maps(table_map map_arg);
3388 
3389  private:
3390  /*
3391  A group of members set and used only during JOIN::optimize().
3392  */
3393  /**
3394  Optimized copy of m_join_cond (valid for one single
3395  execution). Initialized by SELECT_LEX::get_optimizable_conditions().
3396  @todo it would be goo dto reset it in reinit_before_use(), if
3397  reinit_stmt_before_use() had a loop including join nests.
3398  */
3400 
3401  public:
3402  COND_EQUAL *cond_equal{nullptr}; ///< Used with outer join
3403  /// true <=> this table is a const one and was optimized away.
3404  bool optimized_away{false};
3405  /**
3406  true <=> all possible keys for a derived table were collected and
3407  could be re-used while statement re-execution.
3408  */
3409  bool derived_keys_ready{false};
3410 
3411  private:
3412  /// If a recursive reference inside the definition of a CTE.
3414  // End of group for optimization
3415 
3416  private:
3417  /** See comments for set_metadata_id() */
3419  /** See comments for TABLE_SHARE::get_table_ref_version() */
3421 };
3422 
3423 /*
3424  Iterator over the fields of a generic table reference.
3425 */
3426 
3428  public:
3429  Field_iterator() {} /* Remove gcc warning */
3430  virtual ~Field_iterator() {}
3431  virtual void set(TABLE_LIST *) = 0;
3432  virtual void next() = 0;
3433  virtual bool end_of_fields() = 0; /* Return 1 at end of list */
3434  virtual const char *name() = 0;
3435  virtual Item *create_item(THD *) = 0;
3436  virtual Field *field() = 0;
3437 };
3438 
3439 /*
3440  Iterator over the fields of a base table, view with temporary
3441  table, or subquery.
3442 */
3443 
3446 
3447  public:
3449  void set(TABLE_LIST *table) { ptr = table->table->field; }
3450  void set_table(TABLE *table) { ptr = table->field; }
3451  void next() { ptr++; }
3452  bool end_of_fields() { return *ptr == 0; }
3453  const char *name();
3454  Item *create_item(THD *thd);
3455  Field *field() { return *ptr; }
3456 };
3457 
3458 /**
3459  Iterator over the fields of a merged derived table or view.
3460 */
3461 
3465 
3466  public:
3468  void set(TABLE_LIST *table);
3469  void next() { ptr++; }
3470  bool end_of_fields() { return ptr == array_end; }
3471  const char *name();
3472  Item *create_item(THD *thd);
3473  Item **item_ptr() { return &ptr->item; }
3474  Field *field() { return 0; }
3475  inline Item *item() { return ptr->item; }
3477 };
3478 
3479 /*
3480  Field_iterator interface to the list of materialized fields of a
3481  NATURAL/USING join.
3482 */
3483 
3487 
3488  public:
3491  void set(TABLE_LIST *table);
3492  void next();
3493  bool end_of_fields() { return !cur_column_ref; }
3494  const char *name() { return cur_column_ref->name(); }
3495  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
3496  Field *field() { return cur_column_ref->field(); }
3498 };
3499 
3500 /**
3501  Generic iterator over the fields of an arbitrary table reference.
3502 
3503  This class unifies the various ways of iterating over the columns
3504  of a table reference depending on the type of SQL entity it
3505  represents. If such an entity represents a nested table reference,
3506  this iterator encapsulates the iteration over the columns of the
3507  members of the table reference.
3508 
3509  The implementation assumes that all underlying NATURAL/USING table
3510  references already contain their result columns and are linked into
3511  the list TABLE_LIST::next_name_resolution_table.
3512 */
3513 
3520  void set_field_iterator();
3521 
3522  public:
3524  void set(TABLE_LIST *table);
3525  void next();
3526  bool end_of_fields() {
3527  return (table_ref == last_leaf && field_it->end_of_fields());
3528  }
3529  const char *name() { return field_it->name(); }
3530  const char *get_table_name();
3531  const char *get_db_name();
3532  GRANT_INFO *grant();
3533  Item *create_item(THD *thd) { return field_it->create_item(thd); }
3534  Field *field() { return field_it->field(); }
3536  TABLE_LIST *parent_table_ref);
3538 };
3539 
3540 /**
3541  An iterator over an intrusive list in TABLE_LIST objects. Can be used for
3542  iterating an intrusive list in e.g. range-based for loops.
3543 
3544  @tparam Next_pointer The intrusive list's "next" member.
3545 */
3546 template <TABLE_LIST *TABLE_LIST::*Next_pointer>
3548  public:
3549  /**
3550  Constructs an iterator.
3551 
3552  @param start The TABLE_LIST where that the iterator will start iterating
3553  from.
3554  */
3556 
3557  TABLE_LIST *operator++() { return m_current = m_current->*Next_pointer; }
3558 
3560 
3561  bool operator!=(const Table_list_iterator &other) const {
3562  return m_current != other.m_current;
3563  }
3564 
3565  private:
3567 };
3568 
3571 
3572 /**
3573  Provides a list interface on TABLE_LIST objects. The interface is similar to
3574  std::vector, but has only the bare minimum to allow for iteration.
3575 
3576  @tparam Iterator_type Must have an implicit constructor from a TABLE_LIST
3577  pointer, and support pre-increment, non-equality and dereference operators.
3578 */
3579 template <typename Iterator_type>
3581  public:
3582  /**
3583  Constructs the list adapter.
3584 
3585  @param first The TABLE_LIST that is considered first in the list.
3586  */
3588 
3589  /// An iterator pointing to the first TABLE_LIST.
3590  Iterator_type begin() { return m_first; }
3591 
3592  /// A past-the-end iterator.
3593  Iterator_type end() { return nullptr; }
3594 
3595  private:
3597 };
3598 
3599 /// A list interface over the TABLE_LIST::next_local pointer.
3601 
3602 /// A list interface over the TABLE_LIST::next_global pointer.
3604 
3607  char *db, *table;
3608  uint32 in_use, locked;
3609 };
3610 
3612  MY_BITMAP *bitmap) {
3613  my_bitmap_map *old = bitmap->bitmap;
3614  bitmap->bitmap = table->s->all_set.bitmap; // does not repoint last_word_ptr
3615  return old;
3616 }
3617 
3618 static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
3619  my_bitmap_map *old) {
3620  bitmap->bitmap = old;
3621 }
3622 
3623 /* The following is only needed for debugging */
3624 
3626  TABLE *table MY_ATTRIBUTE((unused)),
3627  MY_BITMAP *bitmap MY_ATTRIBUTE((unused))) {
3628 #ifndef DBUG_OFF
3629  return tmp_use_all_columns(table, bitmap);
3630 #else
3631  return 0;
3632 #endif
3633 }
3634 
3635 static inline void dbug_tmp_restore_column_map(
3636  MY_BITMAP *bitmap MY_ATTRIBUTE((unused)),
3637  my_bitmap_map *old MY_ATTRIBUTE((unused))) {
3638 #ifndef DBUG_OFF
3639  tmp_restore_column_map(bitmap, old);
3640 #endif
3641 }
3642 
3643 /*
3644  Variant of the above : handle both read and write sets.
3645  Provide for the possiblity of the read set being the same as the write set
3646 */
3647 static inline void dbug_tmp_use_all_columns(
3648  TABLE *table MY_ATTRIBUTE((unused)),
3649  my_bitmap_map **save MY_ATTRIBUTE((unused)),
3650  MY_BITMAP *read_set MY_ATTRIBUTE((unused)),
3651  MY_BITMAP *write_set MY_ATTRIBUTE((unused))) {
3652 #ifndef DBUG_OFF
3653  save[0] = read_set->bitmap;
3654  save[1] = write_set->bitmap;
3655  (void)tmp_use_all_columns(table, read_set);
3656  (void)tmp_use_all_columns(table, write_set);
3657 #endif
3658 }
3659 
3660 static inline void dbug_tmp_restore_column_maps(
3661  MY_BITMAP *read_set MY_ATTRIBUTE((unused)),
3662  MY_BITMAP *write_set MY_ATTRIBUTE((unused)),
3663  my_bitmap_map **old MY_ATTRIBUTE((unused))) {
3664 #ifndef DBUG_OFF
3665  tmp_restore_column_map(read_set, old[0]);
3666  tmp_restore_column_map(write_set, old[1]);
3667 #endif
3668 }
3669 
3670 void init_mdl_requests(TABLE_LIST *table_list);
3671 
3672 /**
3673  Unpacks the definition of a generated column, default expression or check
3674  constraint expression passed as argument. Parses the text obtained from
3675  TABLE_SHARE and produces an Item.
3676 
3677  @param thd Thread handler
3678  @param table Table with the checked field
3679  @param val_generator The expression to unpack.
3680  @param source Source of value generator(a generated column,
3681  a regular column with generated default value or
3682  a check constraint).
3683  @param source_name Name of the source (generated column, a reguler
3684  column with generated default value or a check
3685  constraint).
3686  @param field Pointer to Field object
3687  @param is_create_table Indicates that table is opened as part
3688  of CREATE or ALTER and does not yet exist in SE
3689  @param error_reported updated flag for the caller that no other error
3690  messages are to be generated.
3691 
3692  @retval true Failure.
3693  @retval false Success.
3694 */
3695 
3696 bool unpack_value_generator(THD *thd, TABLE *table,
3697  Value_generator **val_generator,
3698  Value_generator_source source,
3699  const char *source_name, Field *field,
3700  bool is_create_table, bool *error_reported);
3701 
3702 /**
3703  Unpack the partition expression. Parse the partition expression
3704  to produce an Item.
3705 
3706  @param[in] thd Thread handler
3707  @param[in] outparam Table object
3708  @param[in] share TABLE_SHARE object
3709  @param[in] engine_type Engine type of the partitions.
3710  @param[in] is_create_table Indicates that table is opened as part of
3711  CREATE or ALTER and does not yet exist in SE
3712 
3713  @retval true Failure.
3714  @retval false Success.
3715 */
3716 
3717 bool unpack_partition_info(THD *thd, TABLE *outparam, TABLE_SHARE *share,
3718  handlerton *engine_type, bool is_create_table);
3719 
3720 int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
3721  uint db_stat, uint prgflag, uint ha_open_flags,
3722  TABLE *outparam, bool is_create_table,
3723  const dd::Table *table_def_param);
3724 TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
3725  const char *key, size_t key_length,
3726  bool open_secondary);
3727 void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
3728  size_t key_length, const char *table_name,
3729  const char *path, MEM_ROOT *mem_root);
3730 void free_table_share(TABLE_SHARE *share);
3732 Ident_name_check check_db_name(const char *name, size_t length);
3734  bool preserve_lettercase);
3735 bool check_column_name(const char *name);
3736 Ident_name_check check_table_name(const char *name, size_t length);
3737 int rename_file_ext(const char *from, const char *to, const char *ext);
3738 char *get_field(MEM_ROOT *mem, Field *field);
3739 bool get_field(MEM_ROOT *mem, Field *field, class String *res);
3740 
3741 int closefrm(TABLE *table, bool free_share);
3742 void free_blobs(TABLE *table);
3743 void free_blob_buffers_and_reset(TABLE *table, uint32 size);
3744 int set_zone(int nr, int min_zone, int max_zone);
3745 void append_unescaped(String *res, const char *pos, size_t length);
3746 char *fn_rext(char *name);
3748 
3749 /* performance schema */
3751 
3753 extern LEX_STRING SLOW_LOG_NAME;
3754 
3755 /* information schema */
3757 
3758 /* mysql schema name and DD ID */
3760 static const uint MYSQL_SCHEMA_DD_ID = 1;
3761 
3762 /* mysql tablespace name and DD ID */
3764 static const uint MYSQL_TABLESPACE_DD_ID = 1;
3765 
3766 /* replication's tables */
3767 extern LEX_STRING RLI_INFO_NAME;
3768 extern LEX_STRING MI_INFO_NAME;
3770 
3771 inline bool is_infoschema_db(const char *name, size_t len) {
3772  return (
3775 }
3776 
3777 inline bool is_infoschema_db(const char *name) {
3779 }
3780 
3781 inline bool is_perfschema_db(const char *name, size_t len) {
3782  return (PERFORMANCE_SCHEMA_DB_NAME.length == len &&
3784  name));
3785 }
3786 
3787 inline bool is_perfschema_db(const char *name) {
3789  name);
3790 }
3791 
3792 /**
3793  return true if the table was created explicitly.
3794 */
3795 inline bool is_user_table(TABLE *table) {
3796  const char *name = table->s->table_name.str;
3797  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
3798 }
3799 
3800 bool is_simple_order(ORDER *order);
3801 
3802 uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n,
3803  TABLE_SHARE *share, handler *handler_file,
3804  uint *usable_parts);
3805 void setup_key_part_field(TABLE_SHARE *share, handler *handler_file,
3806  uint primary_key_n, KEY *keyinfo, uint key_n,
3807  uint key_part_n, uint *usable_parts,
3808  bool part_of_key_not_extended);
3809 
3810 const uchar *get_field_name(const uchar *arg, size_t *length);
3811 
3812 void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec);
3813 bool update_generated_write_fields(const MY_BITMAP *bitmap, TABLE *table);
3814 bool update_generated_read_fields(uchar *buf, TABLE *table,
3815  uint active_index = MAX_KEY);
3816 
3817 /**
3818  Check if a TABLE_LIST instance represents a pre-opened temporary table.
3819 */
3820 
3821 inline bool is_temporary_table(TABLE_LIST *tl) {
3822  if (tl->is_view() || tl->schema_table) return false;
3823 
3824  if (!tl->table) return false;
3825 
3826  /*
3827  NOTE: 'table->s' might be NULL for specially constructed TABLE
3828  instances. See SHOW TRIGGERS for example.
3829  */
3830 
3831  if (!tl->table->s) return false;
3832 
3833  return tl->table->s->tmp_table != NO_TMP_TABLE;
3834 }
3835 
3836 /**
3837  After parsing, a Common Table Expression is accessed through a
3838  TABLE_LIST. This class contains all information about the CTE which the
3839  TABLE_LIST needs.
3840 
3841  @note that before and during parsing, the CTE is described by a
3842  PT_common_table_expr.
3843 */
3845  public:
3848  TABLE *clone_tmp_table(THD *thd, TABLE_LIST *tl);
3850  /**
3851  All references to this CTE in the statement, except those inside the
3852  query expression defining this CTE.
3853  In other words, all non-recursive references.
3854  */
3856  /// True if it's a recursive CTE
3858  /**
3859  List of all TABLE_LISTSs reading/writing to the tmp table created to
3860  materialize this CTE. Due to shared materialization, only the first one
3861  has a TABLE generated by create_tmp_table(); other ones have a TABLE
3862  generated by open_table_from_share().
3863  */
3865  /// Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
3867 };
3868 
3869 /**
3870  This iterates on those references to a derived table / view / CTE which are
3871  materialized. If a recursive CTE, this includes recursive references.
3872  Upon construction it is passed a non-recursive materialized reference
3873  to the derived table (TABLE_LIST*).
3874  For a CTE it may return more than one reference; for a derived table or a
3875  view, there is only one (as references to a same view are treated as
3876  independent objects).
3877  References are returned as TABLE*.
3878 */
3880  TABLE_LIST *const start; ///< The reference provided in construction.
3881  int ref_idx; ///< Current index in cte->tmp_tables
3882  public:
3883  explicit Derived_refs_iterator(TABLE_LIST *start_arg)
3884  : start(start_arg), ref_idx(-1) {}
3886  ref_idx++;
3887  const Common_table_expr *cte = start->common_table_expr();
3888  if (!cte) return (ref_idx < 1) ? start->table : nullptr;
3889  return ((uint)ref_idx < cte->tmp_tables.size())
3890  ? cte->tmp_tables[ref_idx]->table
3891  : nullptr;
3892  }
3893  void rewind() { ref_idx = -1; }
3894  /// @returns true if the last get_next() returned the first element.
3895  bool is_first() const { return ref_idx == 0; }
3896 };
3897 
3898 //////////////////////////////////////////////////////////////////////////
3899 
3900 /*
3901  NOTE:
3902  These structures are added to read .frm file in upgrade scenario.
3903 
3904  They should not be used any where else in the code.
3905  They will be removed in future release.
3906  Any new code should not be added in this section.
3907 */
3908 
3909 /**
3910  These members were removed from TABLE_SHARE as they are not used in
3911  in the code. open_binary_frm() uses these members while reading
3912  .frm files.
3913 */
3915  public:
3919  stored_fields(0),
3920  view_def(NULL),
3921  frm_version(0),
3922  fieldnames() {}
3923 
3926  uint stored_fields; /* Number of stored fields
3927  (i.e. without generated-only ones) */
3928 
3929  enum utype {
3942  EMPTY_VAL, // EMPTY_VAL rather than EMPTY since EMPTY can conflict with
3943  // system headers.
3956  };
3957 
3958  /**
3959  For shares representing views File_parser object with view
3960  definition read from .FRM file.
3961  */
3964  TYPELIB fieldnames; /* Pointer to fieldnames */
3965 };
3966 
3967 /**
3968  Create TABLE_SHARE from .frm file.
3969 
3970  FRM_context object is used to store the value removed from
3971  TABLE_SHARE. These values are used only for .frm file parsing.
3972 
3973  @param[in] thd Thread handle.
3974  @param[in] path Path of the frm file.
3975  @param[out] share TABLE_SHARE to be populated.
3976  @param[out] frm_context FRM_context object.
3977  @param[in] db Database name.
3978  @param[in] table Table name.
3979  @param[in] is_fix_view_cols_and_deps Fix view column data, table
3980  and routine dependency.
3981 
3982  @retval TABLE_SHARE ON SUCCESS
3983  @retval NULL ON FAILURE
3984 */
3985 bool create_table_share_for_upgrade(THD *thd, const char *path,
3986  TABLE_SHARE *share,
3987  FRM_context *frm_context, const char *db,
3988  const char *table,
3989  bool is_fix_view_cols_and_deps);
3990 //////////////////////////////////////////////////////////////////////////
3991 
3992 #endif /* TABLE_INCLUDED */
static my_bitmap_map * dbug_tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:3625
LEX_STRING * update_method
Definition: table.h:2157
LEX_STRING * foreign_table
Definition: table.h:2154
uint fields
Definition: table.h:779
my_ptrdiff_t default_values_offset() const
Definition: table.h:1683
ulong avg_row_length
Definition: table.h:741
Key_map keys_in_use_for_group_by
Definition: table.h:1367
Definition: table.h:3953
bool end_of_fields()
Definition: table.h:3452
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1118
bool no_cache
Definition: table.h:1541
Definition: table.h:3427
Definition: sql_plugin_ref.h:44
After parsing, a Common Table Expression is accessed through a TABLE_LIST.
Definition: table.h:3844
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:2351
void restore_null_flags()
Restore the NULL flags of the current row from the designated buffer.
Definition: table.h:1816
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:7403
Definition: item.h:3287
void set_common_table_expr(Common_table_expr *c)
Definition: table.h:3379
uint field_length
For string-type columns, this is the maximum number of characters.
Definition: table.h:2178
unsigned long long int ulonglong
Definition: my_inttypes.h:69
Definition: mdl.h:251
bool open_by_handler
Definition: table.h:1543
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:1699
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
A granted metadata lock.
Definition: mdl.h:962
void cleanup_partial_update()
Clean up state used for partial update of JSON columns.
Definition: table.cc:7462
Filesort_info sort
Definition: table.h:1596
bool is_mergeable() const
Return true if view or derived table and can be merged.
Definition: table.cc:6464
This file contains the field type.
bool replace_filter_processed
true <=> Filter condition is processed
Definition: table.h:3269
Item * item()
Definition: table.h:3475
uint i_s_requested_object
Definition: table.h:3348
Field * next_number_field
Definition: table.h:1372
const char * get_table_name() const
Returns the name of the table that this TABLE_LIST represents.
Definition: table.h:2896
This iterates on those references to a derived table / view / CTE which are materialized.
Definition: table.h:3879
#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:1390
Definition: table.h:3444
unsigned char uchar
Definition: my_inttypes.h:49
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:6996
const Lock_descriptor & lock_descriptor() const
Definition: table.h:3036
Definition: table.h:3932
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:792
MY_BITMAP pack_row_tmp_set
Definition: table.h:1394
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:2804
Table_list_adapter< Local_tables_iterator > Local_tables_list
A list interface over the TABLE_LIST::next_local pointer.
Definition: table.h:3600
LEX * view_query() const
Return the valid LEX object for a view.
Definition: table.h:2758
enum_open_type
Type of table which can be open for an element of table list.
Definition: table.h:2383
TABLE_LIST * referencing_view
Definition: table.h:3179
bool use_default_password_history
Definition: table.h:2311
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:7576
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:3222
Item * create_item(THD *thd)
Definition: table.cc:5085
Field_iterator_table()
Definition: table.h:3448
void rewind()
Definition: table.h:3893
ulonglong get_table_ref_version() const
Return a table metadata version.
Definition: table.cc:4037
const char * db_name
Definition: rules_table_service.cc:54
Definition: table.h:2385
uint next_number_keypart
Definition: table.h:825
bool operator!=(const Table_list_iterator &other) const
Definition: table.h:3561
List< LEX_STRING > referenced_fields
Definition: table.h:2161
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:3267
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:1469
uint primary_key
Definition: table.h:822
Provides a list interface on TABLE_LIST objects.
Definition: table.h:3580
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:236
bool force_index
Definition: table.h:3251
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:4147
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:6274
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:2450
TABLE_LIST * next_global
Definition: table.h:3017
TABLE_LIST * embedding
Definition: table.h:3256
TABLE * table
Definition: field.h:797
uint lock_data_start
Definition: table.h:1472
bool check_read_removal(uint index)
Read removal is possible if the selected quick read method is using full unique index.
Definition: table.cc:6950
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:3438
Definition: sql_lex.h:3635
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:7469
Lock_descriptor m_lock_descriptor
Definition: table.h:3229
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:5999
partition_info * part_info
Definition: table.h:1602
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1274
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:2888
void set_found_row()
Set status for row buffer: contains row.
Definition: table.h:1738
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:2591
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:1394
SELECT_LEX_UNIT * derived
This field is set to non-null for derived tables and views.
Definition: table.h:3124
void next()
Definition: table.cc:5210
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:2540
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:3250
Definition: mi_test3.cc:54
int ref_idx
Current index in cte->tmp_tables.
Definition: table.h:3881
bool uses_authentication_string_clause
Definition: table.h:2353
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:1535
bool uses_replace_clause
Definition: table.h:2354
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:1375
Definition: table.h:3952
uint next_number_key_offset
Definition: table.h:824
longlong int64
Definition: my_inttypes.h:71
static void tmp_restore_column_map(MY_BITMAP *bitmap, my_bitmap_map *old)
Definition: table.h:3618
bool should_binlog_drop_if_temp_flag
This flag decides whether or not we should log the drop temporary table command.
Definition: table.h:1924
uint partition_info_str_len
Definition: table.h:890
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:934
KEY * key_info
Definition: table.h:698
GRANT_INFO * grant()
Definition: table.cc:5257
Field ** visible_field_ptr() const
Definition: table.h:1656
Table_id table_id
Definition: table.h:3097
Some integer typedefs for easier portability.
ulonglong with_check
WITH CHECK OPTION.
Definition: table.h:3224
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:3115
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:4453
Natural_join_column * get_natural_column_ref()
Return an existing reference to a column of a natural/using join.
Definition: table.cc:5377
LEX_STRING INFORMATION_SCHEMA_NAME
Definition: table.cc:123
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:3764
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:7640
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:3349
enum_schema_table_state
Definition: table.h:2145
Field * hash_field
Field used by unique constraint.
Definition: table.h:1379
uint keys
Definition: table.h:781
Definition: table.h:2167
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form)
Definition: table.cc:3475
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:210
Definition: sql_bitmap.h:134
Key_map keys_in_use_for_order_by
Definition: table.h:1369
const char * db
Definition: table.h:3018
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:6031
bool force_index_group
Flag set when the statement contains FORCE INDEX FOR GROUP BY See TABLE_LIST::process_index_hints().
Definition: table.h:1515
const char * new_data(Field *field) const
Get a pointer to the start of the replacement data.
Definition: table.cc:7559
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:4729
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:2307
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
Item * sj_cond() const
Get the semi-join condition for a semi-join nest, NULL otherwise.
Definition: table.h:2557
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:922
TABLE_LIST * table_ref
Definition: table.h:2267
bool m_updatable
Definition: table.h:3241
const CHARSET_INFO * table_charset
Definition: table.h:709
Definition: field.h:707
void print(const THD *thd, String *str, enum_query_type query_type) const
Produce a textual identification of this object.
Definition: sql_lex.cc:2767
bool update_const_key_parts(Item *conds)
Update TABLE::const_key_parts for single table UPDATE/DELETE query.
Definition: table.cc:6914
Definition: table.h:3947
LEX_CSTRING user
Definition: table.h:2340
TABLE_LIST * updatable_base_table()
Return the base table entry of an updatable table.
Definition: table.h:2958
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:7494
bool has_row() const
Definition: table.h:1799
unsigned char uint8
Definition: my_inttypes.h:51
PSI_table_share * m_psi
Instrumentation for this table share.
Definition: table.h:908
bool prelocking_placeholder
Definition: table.h:3277
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:178
signed char int8
Definition: my_inttypes.h:50
Definition: table.h:166
int(* fill_table)(THD *thd, TABLE_LIST *tables, Item *cond)
Definition: table.h:2205
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:2715
Item ** join_cond_ref()
Definition: table.h:2538
LEX_STRING * referenced_db
Definition: table.h:2155
Item * item
Points to an item that represents the expression.
Definition: table.h:2252
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:2672
List< Index_hint > * index_hints
Definition: table.h:3095
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
Definition: table.h:2147
enum enum_table_category TABLE_CATEGORY
Definition: table.h:548
bool all_partitions_pruned_away
Definition: table.h:1604
void mark_columns_needed_for_delete(THD *thd)
Definition: table.cc:5594
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:5429
Field_iterator()
Definition: table.h:3429
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:3413
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:3138
bool has_null_row() const
Definition: table.h:1802
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:3605
This class represents a buffer that can be used for multi-row reads.
Definition: record_buffer.h:46
TYPELIB fieldnames
Definition: table.h:3964
bool created
For tmp tables.
Definition: table.h:1565
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:7385
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:3939
Lex_acl_attrib_udyn
This is generic enum.
Definition: table.h:2292
const uchar * get_field_name(const uchar *arg, size_t *length)
TABLE * get_next()
Definition: table.h:3885
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:1414
const char * table_name
Definition: table.h:3018
TABLE_LIST * view
Definition: table.h:3464
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:3335
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:51
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:5741
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:2304
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:2478
query_id_t query_id
Definition: table.h:1447
const Create_col_name_list * derived_column_names() const
Definition: table.h:3381
Definition: thr_lock.h:72
bool cacheable_table
Definition: table.h:3258
enum_mark_columns
Definition: sql_const.h:378
Contains the class Table_id, mainly used for row based replication.
SELECT_LEX * select_lex
Definition: table.h:3150
void default_column_bitmaps()
Definition: table.h:1649
LEX_STRING name
Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
Definition: table.h:3866
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:5986
const char * alias
alias or table name
Definition: table.h:1388
Performance schema instrumentation interface.
class JOIN_TAB * join_tab
Definition: table.h:1572
virtual ~Field_iterator()
Definition: table.h:3430
ST_SCHEMA_TABLE * schema_table
Definition: table.h:3141
bool impossible_range
Definition: table.h:1581
uint quick_key_parts[MAX_KEY]
Definition: table.h:1458
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
LEX_STRING cset
Definition: table.h:555
#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:5030
Item ** join_cond_optim_ref()
Definition: table.h:2554
LEX_STRING * referenced_table
Definition: table.h:2156
TABLE_LIST ** prev_global
Definition: table.h:3017
uint db_stat
Definition: table.h:1474
List_iterator_fast< Natural_join_column > column_ref_it
Definition: table.h:3485
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:1377
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:2521
Definition: table.h:3945
bool is_system_view
Definition: table.h:3327
bool end_of_fields()
Definition: table.h:3493
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3913
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:3821
bool is_recursive_reference() const
Definition: table.h:2628
User table.
Definition: table.h:424
TABLE * table
Definition: table.h:3096
void set_keyread(bool flag)
Definition: table.cc:6059
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:3855
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:7803
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:3069
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:2697
Item * join_cond() const
Definition: table.h:2539
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:2160
plugin_ref db_plugin
Definition: table.h:747
bool end_of_fields()
Definition: table.h:3470
uchar * null_flags
Pointer to the null flags of record[0].
Definition: table.h:1389
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:4800
Definition: thr_lock.h:52
ha_rows max_rows
Definition: table.h:740
static MEM_ROOT mem
Definition: sql_servers.cc:97
const ACL_internal_schema_access * m_schema_access
Cached internal schema access.
Definition: table.h:314
const char * name()
Definition: table.cc:5067
LEX_STRING * foreign_id
Definition: table.h:2152
Definition: table.h:3954
bool m_insertable
Definition: table.h:3242
Field_translator * ptr
Definition: table.h:3463
bool is_distinct
Whether this is a temporary table that already has a UNIQUE index (removing duplicate rows on insert)...
Definition: table.h:1521
Definition: table.h:3949
Definition: table.h:168
bool check_column_name(const char *name)
Definition: table.cc:3671
ulonglong updatable_view
Definition: table.h:3213
int rename_file_ext(const char *from, const char *to, const char *ext)
Definition: table.cc:3496
Abstract class representing an edge in the waiters graph to be traversed by deadlock detection algori...
Definition: mdl.h:924
Definition: table.h:1294
LEX_STRING db
Definition: table.h:724
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:1707
virtual Object_creation_ctx * create_backup_ctx(THD *thd) const
Definition: table.cc:200
TABLE ** cache_prev
Definition: table.h:1307
const char * get_table_name()
Definition: table.cc:5224
void cleanup()
Definition: table.h:2318
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:2613
LEX_STRING * foreign_db
Definition: table.h:2153
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:3420
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:3845
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:1609
Item * m_sj_cond
Synthesized semijoin condition.
Definition: table.h:3053
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:2945
Definition: table.h:3948
const char * alias
Definition: table.h:3018
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:4369
void set_lock(const Lock_descriptor &descriptor)
Definition: table.h:3032
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:7110
Key_map possible_quick_keys
Definition: table.h:1352
KEY * key_info
Definition: table.h:1370
bool fulltext_searched
Definition: table.h:1540
TABLE_LIST * next_name_resolution_table
Definition: table.h:3093
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:3962
void append_unescaped(String *res, const char *pos, size_t length)
Store an SQL quoted string.
Definition: table.cc:3438
Item ** item_ptr()
Definition: table.h:3473
Table_list_adapter< Global_tables_iterator > Global_tables_list
A list interface over the TABLE_LIST::next_global pointer.
Definition: table.h:3603
Definition: table.h:3605
TABLE_LIST * operator*()
Definition: table.h:3559
Per internal schema ACL access rules.
Definition: auth_common.h:133
TABLE_LIST * first_leaf
Definition: table.h:3515
static my_bitmap_map * tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:3611
void add_join_natural(TABLE_LIST *b)
Mark that there is a NATURAL JOIN or JOIN ...
Definition: table.h:2998
void set_readonly()
Set table as readonly, ie it is neither updatable, insertable nor deletable during this statement...
Definition: table.h:2706
void free_blobs(TABLE *table)
Definition: table.cc:3314
Definition: table.h:2263
Definition: table.h:552
virtual Field * field()=0
Item * create_item(THD *thd)
Definition: table.cc:5069
LEX_STRING table_cache_key
Definition: table.h:723
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:6334
size_t table_name_length
Definition: table.h:3238
bool copy_blobs
Definition: table.h:1496
enum_schema_table_state schema_table_state
Definition: table.h:3352
uint max_key_length
Definition: table.h:785
uint column_bitmap_size
Definition: table.h:827
Definition: table.h:3293
Definition: table.h:3934
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab)
Definition: table.cc:4988
const char * table_name
Definition: table.h:2200
bool optimized_away
true <=> this table is a const one and was optimized away.
Definition: table.h:3404
Field * field()
Definition: table.h:3455
bool is_simple_order(ORDER *order)
Test if the order list consists of simple field expressions.
Definition: table.cc:6981
This file includes constants used by all storage engines.
Field_translator * field_translator()
Definition: table.h:3476
void clear_column_bitmaps(void)
Definition: table.cc:5399
bool refix_value_generator_items(THD *thd)
Fix table&#39;s generated columns&#39; (GC) and/or default expressions.
Definition: table.cc:4194
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:1701
An abstract class for inspection of a connected subgraph of the wait-for graph.
Definition: mdl.h:898
#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5)
Definition: mdl.h:884
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:3936
Definition: table.h:2224
bool is_user_table(TABLE *table)
return true if the table was created explicitly.
Definition: table.h:3795
const TABLE_FIELD_DEF * table_field_def_cache
Cache the checked structure of this table.
Definition: table.h:902
Definition: table.h:2339
bool is_natural_join
Definition: table.h:3075
uint table_open_method
Definition: table.h:3351
#define DBUG_ASSERT(A)
Definition: my_dbug.h:128
void use_all_columns()
Definition: table.h:1646
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:2306
Key_map visible_indexes
The set of visible and enabled indexes for this table.
Definition: table.h:738
Field * field()
Definition: table.h:3474
TABLE_LIST * m_current
Definition: table.h:3566
View_creation_ctx(THD *thd)
Definition: table.h:262
ulong flags
dupp key and pack flags
Definition: key.h:116
LEX_STRING table_name
Definition: table.h:725
bool is_fqtn
true if the table is referred to in the statement using a fully qualified name (<db_name>.
Definition: table.h:3301
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:1704
void mark_gcol_in_maps(Field *field)
Adds a generated column and its dependencies to the read_set/write_set bitmaps.
Definition: table.cc:7167
bool use_default_password_reuse_interval
Definition: table.h:2314
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:4706
static const uint MYSQL_SCHEMA_DD_ID
Definition: table.h:3760
const char * name()
Definition: table.cc:5083
uint open_method
Definition: table.h:2196
List< TABLE_LIST > * join_list
Definition: table.h:3257
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:7397
char * index(const char *, int c)
Definition: mysql.cc:2840
void mark_auto_increment_column(void)
Mark auto-increment fields as used fields in both read and write maps.
Definition: table.cc:5563
LEX_STRING GENERAL_LOG_NAME
Definition: table.cc:136
Definition: table.h:558
bool is_field_used_by_generated_columns(uint field_index, int *error_no)
Definition: table.cc:6194
Definition: table.h:3951
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:2146
void next()
Definition: table.h:3469
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:5298
thr_lock_type
Definition: thr_lock.h:50
Definition: table.h:2148
bool create_field_translation(THD *thd)
Create field translation for merged derived table/view.
Definition: table.cc:4489
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:3186
uint leaf_tables_count() const
Return no. of base tables a merged view or derived table is defined over.
Definition: table.cc:6479
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:3924
void set_updatable()
Set table as updatable. (per default, a table is non-updatable)
Definition: table.h:2694
void set_tableno(uint tableno)
Set table number.
Definition: table.h:3363
Definition: table.h:1285
ulong refresh_version
Definition: mysqld.cc:1119
bool internal_tmp_table
Definition: table.h:3295
#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:2652
Definition: table.h:2222
void reset_null_row()
Clear "null row" status for the current row.
Definition: table.h:1781
table_map m_map
Table map, derived from m_tableno.
Definition: table.h:3045
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:1478
key_part_map const_key_parts[MAX_KEY]
Definition: table.h:1456
Mem_root_array_YY< LEX_CSTRING > Create_col_name_list
Definition: table.h:127
bool is_started() const
Definition: table.h:1735
Key_map quick_keys
Definition: table.h:1340
bool contain_auto_increment
Definition: table.h:3265
size_t m_length
The size of the portion that is to be replaced.
Definition: table.h:1216
bool ignore_leaves
Definition: table.h:3252
Definition: table.h:2223
MEM_ROOT mem_root
Definition: table.h:1589
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:3494
Definition: my_bitmap.h:42
uint stored_fields
Definition: table.h:3926
bool not_exists_optimize
Definition: table.h:1576
Definition: table.h:377
Definition: table.h:2199
Blob_mem_storage * blob_storage
Initialized in Item_func_group_concat::setup for appropriate temporary table if GROUP_CONCAT is used ...
Definition: table.h:1595
~Blob_mem_storage()
Definition: table.cc:4052
TABLE_LIST * last_leaf
Definition: table.h:3515
table_map depend_map
Definition: table.h:299
bool empty_result_table()
Empties internal temporary table (deletes rows, closes scan)
Definition: table.cc:7811
GRANT_INFO * grant()
Definition: table.cc:5058
int(* process_table)(THD *thd, TABLE_LIST *tables, TABLE *table, bool res, LEX_STRING *db_name, LEX_STRING *table_name)
Definition: table.h:2208
enum_table_ref_type m_table_ref_type
See comments for set_metadata_id()
Definition: table.h:3418
bool is_view_or_derived() const
Return true if this represents a named view or a derived table.
Definition: table.h:2616
Definition: table.h:3933
TABLE_LIST * correspondent_table
Definition: table.h:3110
bool materialized
For a materializable derived or SJ table: true if has been materialized.
Definition: table.h:1569
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:1575
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:6452
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:7453
uint tableno() const
Return table number.
Definition: table.h:3369
bool is_infoschema_db(const char *name, size_t len)
Definition: table.h:3771
LEX_STRING type
Definition: table.h:554
bool setup_materialized_derived(THD *thd)
Setup a derived table to use materialization.
Definition: sql_derived.cc:488
LEX_CSTRING target_tablespace_name
Definition: table.h:3023
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:2444
Derived_refs_iterator(TABLE_LIST *start_arg)
Definition: table.h:3883
bool generate_keys()
Generate keys for a materialized derived table/view.
Definition: table.cc:6839
void set_not_started()
Life cycle of the row buffer is as follows:
Definition: table.h:1729
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:1774
void next()
Definition: table.cc:5150
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:1811
const histograms::Histogram * find_histogram(uint field_index)
Find the histogram for the given field index.
Definition: table.cc:3924
void set_no_row()
Set status for row buffer: contains no row.
Definition: table.h:1749
bool uses_identified_with_clause
Definition: table.h:2352
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:1509
Context of the owner of metadata locks.
Definition: mdl.h:1389
bool resolve_derived(THD *thd, bool apply_semijoin)
Resolve a derived table or view reference.
Definition: sql_derived.cc:257
LEX_CSTRING current_auth
Definition: table.h:2344
Item * create_item(THD *thd)
Definition: table.cc:5020
#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:122
bool has_deleted_row() const
Definition: table.h:1808
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:2669
Field ** ptr
Definition: table.h:3445
List< Derived_key > derived_key_list
Definition: table.h:3340
Natural_join_column * column_ref()
Definition: table.h:3497
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:795
void set_privileges(ulong privilege)
Set granted privileges for a table.
Definition: table.h:3008
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:325
~Field_iterator_natural_join()
Definition: table.h:3490
MY_BITMAP * write_set
Definition: table.h:1414
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
ORDER * group
Definition: table.h:1387
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:7606
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:3030
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:2770
void reset()
Definition: table.h:1184
TABLE_LIST * parent_l
Definition: table.h:3181
Definition: item.h:666
bool uses_materialization() const
Return true if this is a materializable derived table/view.
Definition: table.h:2678
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
Definition: table.h:3950
bool create_table_share_for_upgrade(THD *thd, const char *path, TABLE_SHARE *share, FRM_context *frm_context, const char *db, const char *table, bool is_fix_view_cols_and_deps)
Create TABLE_SHARE from .frm file.
Definition: table.cc:7769
Field * field()
Definition: table.h:3534
ulong privilege
The set of privileges that the current user has fulfilled for a certain host, database, and object.
Definition: table.h:369
bool force_index
Definition: table.h:1503
bool is_position
Definition: table.h:300
Key_map keys_in_use_for_query
Definition: table.h:1365
OPEN_TABLE_LIST * next
Definition: table.h:3606
uint shared
Definition: table.h:3236
bool retain_current_password
Definition: table.h:2355
TABLE_LIST * last_leaf_for_name_resolution()
Retrieve the last (right-most) leaf in a nested join tree with respect to name resolution.
Definition: table.cc:4844
char * get_field(MEM_ROOT *mem, Field *field)
Allocate string field in MEM_ROOT and return it as NULL-terminated string.
Definition: table.cc:3539
table_map used
Definition: table.h:299
uint32 password_reuse_interval
Definition: table.h:2313
MY_BITMAP cond_set
Definition: table.h:1403
void cleanup_value_generator_items()
Clean any state in items associated with generated columns to be ready for the next statement...
Definition: table.cc:4291
LEX_STRING select_stmt
text of (CREATE/SELECT) statement
Definition: table.h:3201
This structure is used to keep info about possible key for the result table of a d