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