MySQL  8.0.22
Source Code Documentation
dict0mem.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2020, Oracle and/or its affiliates.
4 Copyright (c) 2012, Facebook Inc.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License, version 2.0, as published by the
8 Free Software Foundation.
9 
10 This program is also distributed with certain software (including but not
11 limited to OpenSSL) that is licensed under separate terms, as designated in a
12 particular file or component or in included license documentation. The authors
13 of MySQL hereby grant you an additional permission to link the program and
14 your derivative works with the separately licensed software that they have
15 included with MySQL.
16 
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21 
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 
26 *****************************************************************************/
27 
28 /** @file include/dict0mem.h
29  Data dictionary memory object creation
30 
31  Created 1/8/1996 Heikki Tuuri
32  *******************************************************/
33 
34 #ifndef dict0mem_h
35 #define dict0mem_h
36 
37 #include "sql/dd/object_id.h"
38 #include "sql/dd/types/column.h"
39 #include "univ.i"
40 #ifdef UNIV_HOTBACKUP
42 #endif /* UNIV_HOTBACKUP */
43 #include "btr0types.h"
44 #include "data0type.h"
45 #include "dict0types.h"
46 #include "mem0mem.h"
47 #include "rem0types.h"
48 #include "row0types.h"
49 #ifndef UNIV_HOTBACKUP
50 #include "lock0types.h"
51 #include "que0types.h"
52 #endif /* !UNIV_HOTBACKUP */
53 #include "hash0hash.h"
54 #include "sync0rw.h"
55 #include "trx0types.h"
56 #include "ut0byte.h"
57 #include "ut0mem.h"
58 #include "ut0rnd.h"
59 #ifndef UNIV_HOTBACKUP
60 #include "fts0fts.h"
61 #endif /* !UNIV_HOTBACKUP */
62 #include "buf0buf.h"
63 #include "gis0type.h"
64 #ifndef UNIV_HOTBACKUP
65 #include "os0once.h"
66 #endif /* !UNIV_HOTBACKUP */
67 #include "dict/mem.h"
68 #include "ut0new.h"
69 
70 #include "sql/sql_const.h" /* MAX_KEY_LENGTH */
71 
72 #include <algorithm>
73 #include <iterator>
74 #include <memory> /* std::unique_ptr */
75 #include <set>
76 #include <string>
77 #include <vector>
78 
79 /* Forward declaration. */
80 struct ib_rbt_t;
81 
82 /** Type flags of an index: OR'ing of the flags is allowed to define a
83 combination of types */
84 /** @{ */
85 #define DICT_CLUSTERED \
86  1 /*!< clustered index; for other than \
87  auto-generated clustered indexes, \
88  also DICT_UNIQUE will be set */
89 #define DICT_UNIQUE 2 /*!< unique index */
90 #define DICT_IBUF 8 /*!< insert buffer tree */
91 #define DICT_CORRUPT \
92  16 /*!< bit to store the corrupted flag \
93  in SYS_INDEXES.TYPE */
94 #define DICT_FTS \
95  32 /* FTS index; can't be combined with the \
96  other flags */
97 #define DICT_SPATIAL \
98  64 /* SPATIAL index; can't be combined with the \
99  other flags */
100 #define DICT_VIRTUAL 128 /* Index on Virtual column */
101 
102 #define DICT_SDI \
103  256 /* Tablespace dictionary Index. Set only in \
104  in-memory index structure. */
105 #define DICT_MULTI_VALUE 512 /* Multi-value index */
106 
107 #define DICT_IT_BITS \
108  10 /*!< number of bits used for \
109  SYS_INDEXES.TYPE */
110 /** @} */
111 
112 #if 0 /* not implemented, retained for history */
113 /** Types for a table object */
114 #define DICT_TABLE_ORDINARY 1 /*!< ordinary table */
115 #define DICT_TABLE_CLUSTER_MEMBER 2
116 #define DICT_TABLE_CLUSTER \
117  3 /* this means that the table is \
118  really a cluster definition */
119 #endif
120 
121 /* Table and tablespace flags are generally not used for the Antelope file
122 format except for the low order bit, which is used differently depending on
123 where the flags are stored.
124 
125 ==================== Low order flags bit =========================
126  | REDUNDANT | COMPACT | COMPRESSED and DYNAMIC
127 SYS_TABLES.TYPE | 1 | 1 | 1
128 dict_table_t::flags | 0 | 1 | 1
129 FSP_SPACE_FLAGS | 0 | 0 | 1
130 fil_space_t::flags | 0 | 0 | 1
131 
132 Before the 5.1 plugin, SYS_TABLES.TYPE was always DICT_TABLE_ORDINARY (1)
133 and the tablespace flags field was always 0. In the 5.1 plugin, these fields
134 were repurposed to identify compressed and dynamic row formats.
135 
136 The following types and constants describe the flags found in dict_table_t
137 and SYS_TABLES.TYPE. Similar flags found in fil_space_t and FSP_SPACE_FLAGS
138 are described in fsp0fsp.h. */
139 
140 /** @{ */
141 /** dict_table_t::flags bit 0 is equal to 0 if the row format = Redundant */
142 #define DICT_TF_REDUNDANT 0 /*!< Redundant row format. */
143 /** dict_table_t::flags bit 0 is equal to 1 if the row format = Compact */
144 #define DICT_TF_COMPACT 1 /*!< Compact row format. */
145 
146 /** This bitmask is used in SYS_TABLES.N_COLS to set and test whether
147 the Compact page format is used, i.e ROW_FORMAT != REDUNDANT */
148 #define DICT_N_COLS_COMPACT 0x80000000UL
149 
150 /** Width of the COMPACT flag */
151 #define DICT_TF_WIDTH_COMPACT 1
153 /** Width of the ZIP_SSIZE flag */
154 #define DICT_TF_WIDTH_ZIP_SSIZE 4
156 /** Width of the ATOMIC_BLOBS flag. The ROW_FORMAT=REDUNDANT and
157 ROW_FORMAT=COMPACT broke up BLOB and TEXT fields, storing the first 768 bytes
158 in the clustered index. ROW_FORMAT=DYNAMIC and ROW_FORMAT=COMPRESSED
159 store the whole blob or text field off-page atomically.
160 Secondary indexes are created from this external data using row_ext_t
161 to cache the BLOB prefixes. */
162 #define DICT_TF_WIDTH_ATOMIC_BLOBS 1
163 
164 /** If a table is created with the MYSQL option DATA DIRECTORY and
165 innodb-file-per-table, an older engine will not be able to find that table.
166 This flag prevents older engines from attempting to open the table and
167 allows InnoDB to update_create_info() accordingly. */
168 #define DICT_TF_WIDTH_DATA_DIR 1
169 
170 /** Width of the SHARED tablespace flag.
171 It is used to identify tables that exist inside a shared general tablespace.
172 If a table is created with the TABLESPACE=tsname option, an older engine will
173 not be able to find that table. This flag prevents older engines from attempting
174 to open the table and allows InnoDB to quickly find the tablespace. */
175 
176 #define DICT_TF_WIDTH_SHARED_SPACE 1
177 
178 /** Width of all the currently known table flags */
179 #define DICT_TF_BITS \
180  (DICT_TF_WIDTH_COMPACT + DICT_TF_WIDTH_ZIP_SSIZE + \
181  DICT_TF_WIDTH_ATOMIC_BLOBS + DICT_TF_WIDTH_DATA_DIR + \
182  DICT_TF_WIDTH_SHARED_SPACE)
184 /** A mask of all the known/used bits in table flags */
185 #define DICT_TF_BIT_MASK (~(~0 << DICT_TF_BITS))
186 
187 /** Zero relative shift position of the COMPACT field */
188 #define DICT_TF_POS_COMPACT 0
189 /** Zero relative shift position of the ZIP_SSIZE field */
190 #define DICT_TF_POS_ZIP_SSIZE (DICT_TF_POS_COMPACT + DICT_TF_WIDTH_COMPACT)
191 /** Zero relative shift position of the ATOMIC_BLOBS field */
192 #define DICT_TF_POS_ATOMIC_BLOBS \
193  (DICT_TF_POS_ZIP_SSIZE + DICT_TF_WIDTH_ZIP_SSIZE)
194 /** Zero relative shift position of the DATA_DIR field */
195 #define DICT_TF_POS_DATA_DIR \
196  (DICT_TF_POS_ATOMIC_BLOBS + DICT_TF_WIDTH_ATOMIC_BLOBS)
197 /** Zero relative shift position of the SHARED TABLESPACE field */
198 #define DICT_TF_POS_SHARED_SPACE (DICT_TF_POS_DATA_DIR + DICT_TF_WIDTH_DATA_DIR)
199 /** Zero relative shift position of the start of the UNUSED bits */
200 #define DICT_TF_POS_UNUSED \
201  (DICT_TF_POS_SHARED_SPACE + DICT_TF_WIDTH_SHARED_SPACE)
203 /** Bit mask of the COMPACT field */
204 #define DICT_TF_MASK_COMPACT \
205  ((~(~0U << DICT_TF_WIDTH_COMPACT)) << DICT_TF_POS_COMPACT)
206 /** Bit mask of the ZIP_SSIZE field */
207 #define DICT_TF_MASK_ZIP_SSIZE \
208  ((~(~0U << DICT_TF_WIDTH_ZIP_SSIZE)) << DICT_TF_POS_ZIP_SSIZE)
209 /** Bit mask of the ATOMIC_BLOBS field */
210 #define DICT_TF_MASK_ATOMIC_BLOBS \
211  ((~(~0U << DICT_TF_WIDTH_ATOMIC_BLOBS)) << DICT_TF_POS_ATOMIC_BLOBS)
212 /** Bit mask of the DATA_DIR field */
213 #define DICT_TF_MASK_DATA_DIR \
214  ((~(~0U << DICT_TF_WIDTH_DATA_DIR)) << DICT_TF_POS_DATA_DIR)
215 /** Bit mask of the SHARED_SPACE field */
216 #define DICT_TF_MASK_SHARED_SPACE \
217  ((~(~0U << DICT_TF_WIDTH_SHARED_SPACE)) << DICT_TF_POS_SHARED_SPACE)
218 
219 /** Return the value of the COMPACT field */
220 #define DICT_TF_GET_COMPACT(flags) \
221  ((flags & DICT_TF_MASK_COMPACT) >> DICT_TF_POS_COMPACT)
222 /** Return the value of the ZIP_SSIZE field */
223 #define DICT_TF_GET_ZIP_SSIZE(flags) \
224  ((flags & DICT_TF_MASK_ZIP_SSIZE) >> DICT_TF_POS_ZIP_SSIZE)
225 /** Return the value of the ATOMIC_BLOBS field */
226 #define DICT_TF_HAS_ATOMIC_BLOBS(flags) \
227  ((flags & DICT_TF_MASK_ATOMIC_BLOBS) >> DICT_TF_POS_ATOMIC_BLOBS)
228 /** Return the value of the DATA_DIR field */
229 #define DICT_TF_HAS_DATA_DIR(flags) \
230  ((flags & DICT_TF_MASK_DATA_DIR) >> DICT_TF_POS_DATA_DIR)
231 /** Return the value of the SHARED_SPACE field */
232 #define DICT_TF_HAS_SHARED_SPACE(flags) \
233  ((flags & DICT_TF_MASK_SHARED_SPACE) >> DICT_TF_POS_SHARED_SPACE)
234 /** Return the contents of the UNUSED bits */
235 #define DICT_TF_GET_UNUSED(flags) (flags >> DICT_TF_POS_UNUSED)
236 /** @} */
237 
238 /** @brief Table Flags set number 2.
240 These flags will be stored in SYS_TABLES.MIX_LEN. All unused flags
241 will be written as 0. The column may contain garbage for tables
242 created with old versions of InnoDB that only implemented
243 ROW_FORMAT=REDUNDANT. InnoDB engines do not check these flags
244 for unknown bits in order to protect backward incompatibility. */
245 /** @{ */
246 /** Total number of bits in table->flags2. */
247 #define DICT_TF2_BITS 11
248 #define DICT_TF2_UNUSED_BIT_MASK (~0U << DICT_TF2_BITS)
249 #define DICT_TF2_BIT_MASK ~DICT_TF2_UNUSED_BIT_MASK
250 
251 /** TEMPORARY; TRUE for tables from CREATE TEMPORARY TABLE. */
252 #define DICT_TF2_TEMPORARY 1
254 /** The table has an internal defined DOC ID column */
255 #define DICT_TF2_FTS_HAS_DOC_ID 2
257 /** The table has an FTS index */
258 #define DICT_TF2_FTS 4
260 /** Need to add Doc ID column for FTS index build.
261 This is a transient bit for index build */
262 #define DICT_TF2_FTS_ADD_DOC_ID 8
263 
264 /** This bit is used during table creation to indicate that it will
265 use its own tablespace instead of the system tablespace. */
266 #define DICT_TF2_USE_FILE_PER_TABLE 16
267 
268 /** Set when we discard/detach the tablespace */
269 #define DICT_TF2_DISCARDED 32
271 /** Intrinsic table bit
272 Intrinsic table is table created internally by MySQL modules viz. Optimizer,
273 FTS, etc.... Intrinsic table has all the properties of the normal table except
274 it is not created by user and so not visible to end-user. */
275 #define DICT_TF2_INTRINSIC 128
276 
277 /** Encryption table bit for innodb_file-per-table only. */
278 #define DICT_TF2_ENCRYPTION_FILE_PER_TABLE 256
280 /** FTS AUX hidden table bit. */
281 #define DICT_TF2_AUX 512
283 /** Table is opened by resurrected trx during crash recovery. */
284 #define DICT_TF2_RESURRECT_PREPARED 1024
285 /** @} */
286 
287 #define DICT_TF2_FLAG_SET(table, flag) (table->flags2 |= (flag))
289 #define DICT_TF2_FLAG_IS_SET(table, flag) (table->flags2 & (flag))
290 
291 #define DICT_TF2_FLAG_UNSET(table, flag) (table->flags2 &= ~(flag))
292 
293 /** Tables could be chained together with Foreign key constraint. When
294 first load the parent table, we would load all of its descedents.
295 This could result in rescursive calls and out of stack error eventually.
296 DICT_FK_MAX_RECURSIVE_LOAD defines the maximum number of recursive loads,
297 when exceeded, the child table will not be loaded. It will be loaded when
298 the foreign constraint check needs to be run. */
299 #define DICT_FK_MAX_RECURSIVE_LOAD 20
300 
301 /** Similarly, when tables are chained together with foreign key constraints
302 with on cascading delete/update clause, delete from parent table could
303 result in recursive cascading calls. This defines the maximum number of
304 such cascading deletes/updates allowed. When exceeded, the delete from
305 parent table will fail, and user has to drop excessive foreign constraint
306 before proceeds. */
307 #define FK_MAX_CASCADE_DEL 15
308 
309 /** Adds a virtual column definition to a table.
310 @param[in,out] table table
311 @param[in] heap temporary memory heap, or NULL. It is
312  used to store name when we have not finished
313  adding all columns. When all columns are
314  added, the whole name will copy to memory from
315  table->heap
316 @param[in] name column name
317 @param[in] mtype main datatype
318 @param[in] prtype precise type
319 @param[in] len length
320 @param[in] pos position in a table
321 @param[in] num_base number of base columns
322 @param[in] is_visible True if virtual column is visible to user
323 @return the virtual column definition */
325  const char *name, ulint mtype,
326  ulint prtype, ulint len, ulint pos,
327  ulint num_base, bool is_visible);
328 
329 /** Adds a stored column definition to a table.
330 @param[in,out] table table
331 @param[in] num_base number of base columns. */
332 void dict_mem_table_add_s_col(dict_table_t *table, ulint num_base);
333 
334 /** Renames a column of a table in the data dictionary cache.
335 @param[in,out] table Table
336 @param[in] nth_col Column index
337 @param[in] from Old column name
338 @param[in] to New column name
339 @param[in] is_virtual If this is a virtual column */
340 void dict_mem_table_col_rename(dict_table_t *table, ulint nth_col,
341  const char *from, const char *to,
342  bool is_virtual);
343 
344 /** This function poplulates a dict_index_t index memory structure with
345 supplied information.
346 @param[out] index index to be filled
347 @param[in] heap memory heap
348 @param[in] table_name table name
349 @param[in] index_name index name
350 @param[in] space space where the index tree is placed, the
351  clustered type ignored if the index is of
352 the clustered type
353 @param[in] type DICT_UNIQUE, DICT_CLUSTERED, ... ORed
354 @param[in] n_fields number of fields */
355 UNIV_INLINE void dict_mem_fill_index_struct(dict_index_t *index,
356  mem_heap_t *heap,
357  const char *table_name,
358  const char *index_name, ulint space,
359  ulint type, ulint n_fields);
360 
361 /** Frees an index memory object. */
362 void dict_mem_index_free(dict_index_t *index); /*!< in: index */
363 /** Creates and initializes a foreign constraint memory object.
364  @return own: foreign constraint struct */
366 
367 /** Sets the foreign_table_name_lookup pointer based on the value of
368  lower_case_table_names. If that is 0 or 1, foreign_table_name_lookup
369  will point to foreign_table_name. If 2, then another string is
370  allocated from the heap and set to lower case. */
372  dict_foreign_t *foreign, /*!< in/out: foreign struct */
373  ibool do_alloc); /*!< in: is an alloc needed */
374 
375 /** Sets the referenced_table_name_lookup pointer based on the value of
376  lower_case_table_names. If that is 0 or 1, referenced_table_name_lookup
377  will point to referenced_table_name. If 2, then another string is
378  allocated from the heap and set to lower case. */
380  dict_foreign_t *foreign, /*!< in/out: foreign struct */
381  ibool do_alloc); /*!< in: is an alloc needed */
382 
383 /** Fills the dependent virtual columns in a set.
384 Reason for being dependent are
385 1) FK can be present on base column of virtual columns
386 2) FK can be present on column which is a part of virtual index
387 @param[in,out] foreign foreign key information. */
389 
390 /** Fill virtual columns set in each fk constraint present in the table.
391 @param[in,out] table innodb table object. */
393 
394 /** Free the vcol_set from all foreign key constraint on the table.
395 @param[in,out] table innodb table object. */
397 
398 /** Create a temporary tablename like "#sql-ibtid-inc" where
399  tid = the Table ID
400  inc = a randomly initialized number that is incremented for each file
401 The table ID is a 64 bit integer, can use up to 20 digits, and is
402 initialized at bootstrap. The second number is 32 bits, can use up to 10
403 digits, and is initialized at startup to a randomly distributed number.
404 It is hoped that the combination of these two numbers will provide a
405 reasonably unique temporary file name.
406 @param[in] heap A memory heap
407 @param[in] dbtab Table name in the form database/table name
408 @param[in] id Table id
409 @return A unique temporary tablename suitable for InnoDB use */
410 char *dict_mem_create_temporary_tablename(mem_heap_t *heap, const char *dbtab,
411  table_id_t id);
412 
413 /** Initialize dict memory variables */
414 void dict_mem_init(void);
415 
416 /** SQL identifier name wrapper for pretty-printing */
417 class id_name_t {
418  public:
419  /** Default constructor */
420  id_name_t() : m_name() {}
421  /** Constructor
422  @param[in] name identifier to assign */
423  explicit id_name_t(const char *name) : m_name(name) {}
425  /** Assignment operator
426  @param[in] name identifier to assign */
427  id_name_t &operator=(const char *name) {
428  m_name = name;
429  return (*this);
430  }
432  /** Implicit type conversion
433  @return the name */
434  operator const char *() const { return (m_name); }
435 
436  /** Explicit type conversion
437  @return the name */
438  const char *operator()() const { return (m_name); }
439 
440  private:
441  /** The name in internal representation */
442  const char *m_name;
443 };
444 
445 /** Table name wrapper for pretty-printing */
446 struct table_name_t {
447  /** The name in internal representation */
448  char *m_name;
449 };
451 /** Data structure for default value of a column in a table */
453  /** Pointer to the column itself */
454  dict_col_t *col;
455  /** Default value in bytes */
457  /** Length of default value */
458  size_t len;
459 
460  bool operator==(const dict_col_default_t &other);
461  bool operator!=(const dict_col_default_t &other);
462 };
463 
464 /** Data structure for a column in a table */
465 struct dict_col_t {
466  /*----------------------*/
467  /** The following are copied from dtype_t,
468  so that all bit-fields can be packed tightly. */
469  /** @{ */
470 
471  /** Default value when this column was added instantly.
472  If this is not a instantly added column then this is nullptr. */
473  dict_col_default_t *instant_default;
474 
475  unsigned prtype : 32; /*!< precise type; MySQL data
476  type, charset code, flags to
477  indicate nullability,
478  signedness, whether this is a
479  binary string, whether this is
480  a true VARCHAR where MySQL
481  uses 2 bytes to store the length */
482  unsigned mtype : 8; /*!< main data type */
483 
484  /* the remaining fields do not affect alphabetical ordering: */
485 
486  unsigned len : 16; /*!< length; for MySQL data this
487  is field->pack_length(),
488  except that for a >= 5.0.3
489  type true VARCHAR this is the
490  maximum byte length of the
491  string data (in addition to
492  the string, MySQL uses 1 or 2
493  bytes to store the string length) */
494 
495  unsigned mbminmaxlen : 5; /*!< minimum and maximum length of a
496  character, in bytes;
497  DATA_MBMINMAXLEN(mbminlen,mbmaxlen);
498  mbminlen=DATA_MBMINLEN(mbminmaxlen);
499  mbmaxlen=DATA_MBMINLEN(mbminmaxlen) */
500  /*----------------------*/
501  /* End of definitions copied from dtype_t */
502  /** @} */
503 
504  unsigned ind : 10; /*!< table column position
505  (starting from 0) */
506  unsigned ord_part : 1; /*!< nonzero if this column
507  appears in the ordering fields
508  of an index */
509  unsigned max_prefix : 12; /*!< maximum index prefix length on
510  this column. Our current max limit is
511  3072 (REC_VERSION_56_MAX_INDEX_COL_LEN)
512  bytes. */
514  /* True, if the column is visible */
515  bool is_visible;
516 
517  /** Returns the minimum size of the column.
518  @return minimum size */
519  ulint get_min_size() const {
520  return (dtype_get_min_size_low(mtype, prtype, len, mbminmaxlen));
521  }
522 
523  /** Returns the maximum size of the column.
524  @return maximum size */
525  ulint get_max_size() const { return (dtype_get_max_size_low(mtype, len)); }
526 
527  /** Check if a column is a virtual column
528  @return true if it is a virtual column, false otherwise */
529  bool is_virtual() const { return (prtype & DATA_VIRTUAL); }
530 
531  /** Check if a column is a multi-value virtual column
532  @return true if it is a multi-value virtual column, false otherwise */
533  bool is_multi_value() const { return ((prtype & DATA_MULTI_VALUE) != 0); }
534 
535  /** Check if a column is nullable
536  @return true if it is nullable, otherwise false */
537  bool is_nullable() const { return ((prtype & DATA_NOT_NULL) == 0); }
538 
539  /** Gets the column data type.
540  @param[out] type data type */
541  void copy_type(dtype_t *type) const {
542  ut_ad(type != nullptr);
543 
544  type->mtype = mtype;
545  type->prtype = prtype;
546  type->len = len;
547  type->mbminmaxlen = mbminmaxlen;
548  }
549 
550  /** Gets the minimum number of bytes per character.
551  @return minimum multi-byte char size, in bytes */
552  ulint get_mbminlen() const { return (DATA_MBMINLEN(mbminmaxlen)); }
553 
554  /** Gets the maximum number of bytes per character.
555  @return maximum multi-byte char size, in bytes */
556  ulint get_mbmaxlen() const { return (DATA_MBMAXLEN(mbminmaxlen)); }
557 
558  /** Sets the minimum and maximum number of bytes per character.
559  @param[in] mbminlen minimum multi byte character size, in bytes
560  @param[in] mbmaxlen mAXimum multi-byte character size, in bytes */
561  void set_mbminmaxlen(ulint mbminlen, ulint mbmaxlen) {
562  ut_ad(mbminlen < DATA_MBMAX);
563  ut_ad(mbmaxlen < DATA_MBMAX);
564  ut_ad(mbminlen <= mbmaxlen);
566  mbminmaxlen = DATA_MBMINMAXLEN(mbminlen, mbmaxlen);
567  }
568 
569  /** Returns the size of a fixed size column, 0 if not a fixed size column.
570  @param[in] comp nonzero=ROW_FORMAT=COMPACT
571  @return fixed size, or 0 */
572  ulint get_fixed_size(ulint comp) const {
573  return (dtype_get_fixed_size_low(mtype, prtype, len, mbminmaxlen, comp));
574  }
575 
576  /** Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
577  For fixed length types it is the fixed length of the type, otherwise 0.
578  @param[in] comp nonzero=ROW_FORMAT=COMPACT
579  @return SQL null storage size in ROW_FORMAT=REDUNDANT */
580  ulint get_null_size(ulint comp) const { return (get_fixed_size(comp)); }
581 
582  /** Check whether the col is used in spatial index or regular index.
583  @return spatial status */
584  spatial_status_t get_spatial_status() const {
585  spatial_status_t spatial_status = SPATIAL_NONE;
586 
587  /* Column is not a part of any index. */
588  if (!ord_part) {
589  return (spatial_status);
590  }
591 
592  if (DATA_GEOMETRY_MTYPE(mtype)) {
593  if (max_prefix == 0) {
594  spatial_status = SPATIAL_ONLY;
595  } else {
596  /* Any regular index on a geometry column
597  should have a prefix. */
598  spatial_status = SPATIAL_MIXED;
599  }
600  }
601 
602  return (spatial_status);
603  }
604 
605  /** Set default value
606  @param[in] value Default value
607  @param[in] length Default value length
608  @param[in,out] heap Heap to allocate memory */
609  void set_default(const byte *value, size_t length, mem_heap_t *heap);
610 
611 #ifdef UNIV_DEBUG
612  /** Assert that a column and a data type match.
613  param[in] type data type
614  @return true */
615  bool assert_equal(const dtype_t *type) const {
616  ut_ad(type);
617 
618  ut_ad(mtype == type->mtype);
619  ut_ad(prtype == type->prtype);
620  // ut_ad(col->len == type->len);
621 #ifndef UNIV_HOTBACKUP
622  ut_ad(mbminmaxlen == type->mbminmaxlen);
623 #endif /* !UNIV_HOTBACKUP */
624 
625  return true;
626  }
627 #endif /* UNIV_DEBUG */
628 };
629 
630 /** Index information put in a list of virtual column structure. Index
631 id and virtual column position in the index will be logged.
632 There can be multiple entries for a given index, with a different position. */
633 struct dict_v_idx_t {
634  /** active index on the column */
635  dict_index_t *index;
636 
637  /** position in this index */
638  ulint nth_field;
639 };
640 
641 /** Index list to put in dict_v_col_t */
642 typedef std::list<dict_v_idx_t, ut_allocator<dict_v_idx_t>> dict_v_idx_list;
643 
644 /** Data structure for a virtual column in a table */
645 struct dict_v_col_t {
646  /** column structure */
647  dict_col_t m_col;
648 
649  /** array of base column ptr */
650  dict_col_t **base_col;
652  /** number of base columns */
653  ulint num_base;
655  /** column pos in table */
656  ulint v_pos;
658  /** Virtual index list, and column position in the index,
659  the allocated memory is not from table->heap, nor it is
660  tracked by dict_sys->size */
661  dict_v_idx_list *v_indexes;
662 };
663 
664 /** Data structure for newly added virtual column in a table */
666  /** number of new virtual column */
667  ulint n_v_col;
668 
669  /** column structures */
670  const dict_v_col_t *v_col;
672  /** new col names */
673  const char **v_col_name;
674 };
675 
676 /** Data structure for a stored column in a table. */
677 struct dict_s_col_t {
678  /** Stored column ptr */
679  dict_col_t *m_col;
680  /** array of base col ptr */
681  dict_col_t **base_col;
682  /** number of base columns */
683  ulint num_base;
684  /** column pos in table */
685  ulint s_pos;
686 };
688 /** list to put stored column for dict_table_t */
689 typedef std::list<dict_s_col_t, ut_allocator<dict_s_col_t>> dict_s_col_list;
690 
691 /** @brief DICT_ANTELOPE_MAX_INDEX_COL_LEN is measured in bytes and
692 is the maximum indexed column length (or indexed prefix length) in
693 ROW_FORMAT=REDUNDANT and ROW_FORMAT=COMPACT. Also, in any format,
694 any fixed-length field that is longer than this will be encoded as
695 a variable-length field.
696 
697 It is set to 3*256, so that one can create a column prefix index on
698 256 characters of a TEXT or VARCHAR column also in the UTF-8
699 charset. In that charset, a character may take at most 3 bytes. This
700 constant MUST NOT BE CHANGED, or the compatibility of InnoDB data
701 files would be at risk! */
702 #define DICT_ANTELOPE_MAX_INDEX_COL_LEN REC_ANTELOPE_MAX_INDEX_COL_LEN
703 
704 /** Find out maximum indexed column length by its table format.
705 For ROW_FORMAT=REDUNDANT and ROW_FORMAT=COMPACT, the maximum
706 field length is REC_ANTELOPE_MAX_INDEX_COL_LEN - 1 (767). For
707 ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC, the length could
708 be REC_VERSION_56_MAX_INDEX_COL_LEN (3072) bytes */
709 #define DICT_MAX_FIELD_LEN_BY_FORMAT(table) \
710  (dict_table_has_atomic_blobs(table) ? REC_VERSION_56_MAX_INDEX_COL_LEN \
711  : REC_ANTELOPE_MAX_INDEX_COL_LEN - 1)
712 
713 #define DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags) \
714  (DICT_TF_HAS_ATOMIC_BLOBS(flags) ? REC_VERSION_56_MAX_INDEX_COL_LEN \
715  : REC_ANTELOPE_MAX_INDEX_COL_LEN - 1)
716 
717 /** Defines the maximum fixed length column size */
718 #define DICT_MAX_FIXED_COL_LEN DICT_ANTELOPE_MAX_INDEX_COL_LEN
719 
720 /** Data structure for a field in an index */
721 struct dict_field_t {
722  dict_field_t() : col(nullptr), prefix_len(0), fixed_len(0), is_ascending(0) {}
723 
724  dict_col_t *col; /*!< pointer to the table column */
725  id_name_t name; /*!< name of the column */
726  unsigned prefix_len : 12; /*!< 0 or the length of the column
727  prefix in bytes in a MySQL index of
728  type, e.g., INDEX (textcol(25));
729  must be smaller than
730  DICT_MAX_FIELD_LEN_BY_FORMAT;
731  NOTE that in the UTF-8 charset, MySQL
732  sets this to (mbmaxlen * the prefix len)
733  in UTF-8 chars */
734  unsigned fixed_len : 10; /*!< 0 or the fixed length of the
735  column if smaller than
736  DICT_ANTELOPE_MAX_INDEX_COL_LEN */
737  unsigned is_ascending : 1; /*!< 0=DESC, 1=ASC */
738 };
739 
740 /** PADDING HEURISTIC BASED ON LINEAR INCREASE OF PADDING TO AVOID
741  COMPRESSION FAILURES
742  (Note: this is relevant only for compressed indexes)
743  GOAL: Avoid compression failures by maintaining information about the
744  compressibility of data. If data is not very compressible then leave
745  some extra space 'padding' in the uncompressed page making it more
746  likely that compression of less than fully packed uncompressed page will
747  succeed.
748 
749  This padding heuristic works by increasing the pad linearly until the
750  desired failure rate is reached. A "round" is a fixed number of
751  compression operations.
752  After each round, the compression failure rate for that round is
753  computed. If the failure rate is too high, then padding is incremented
754  by a fixed value, otherwise it's left intact.
755  If the compression failure is lower than the desired rate for a fixed
756  number of consecutive rounds, then the padding is decreased by a fixed
757  value. This is done to prevent overshooting the padding value,
758  and to accommodate the possible change in data compressibility. */
759 
760 /** Number of zip ops in one round. */
761 #define ZIP_PAD_ROUND_LEN (128)
762 
763 /** Number of successful rounds after which the padding is decreased */
764 #define ZIP_PAD_SUCCESSFUL_ROUND_LIMIT (5)
766 /** Amount by which padding is increased. */
767 #define ZIP_PAD_INCR (128)
769 /** Percentage of compression failures that are allowed in a single
770 round */
772 
773 /** Maximum percentage of a page that can be allowed as a pad to avoid
774 compression failures */
775 extern ulong zip_pad_max;
776 
777 /** Data structure to hold information about about how much space in
778 an uncompressed page should be left as padding to avoid compression
779 failures. This estimate is based on a self-adapting heuristic. */
780 struct zip_pad_info_t {
781  SysMutex *mutex; /*!< mutex protecting the info */
782  ulint pad; /*!< number of bytes used as pad */
783  ulint success; /*!< successful compression ops during
784  current round */
785  ulint failure; /*!< failed compression ops during
786  current round */
787  ulint n_rounds; /*!< number of currently successful
788  rounds */
789 #ifndef UNIV_HOTBACKUP
790  volatile os_once::state_t mutex_created;
791  /*!< Creation state of mutex member */
792 #endif /* !UNIV_HOTBACKUP */
793 };
795 /** If key is fixed length key then cache the record offsets on first
796 computation. This will help save computation cycle that generate same
797 redundant data. */
798 class rec_cache_t {
799  public:
800  /** Constructor */
801  rec_cache_t()
802  : rec_size(),
803  offsets(),
804  sz_of_offsets(),
805  fixed_len_key(),
806  offsets_cached(),
807  key_has_null_cols() {
808  /* Do Nothing. */
809  }
810 
811  public:
812  /** Record size. (for fixed length key record size is constant) */
813  ulint rec_size;
814 
815  /** Holds reference to cached offsets for record. */
816  ulint *offsets;
818  /** Size of offset array */
819  uint32_t sz_of_offsets;
821  /** If true, then key is fixed length key. */
822  bool fixed_len_key;
824  /** If true, then offset has been cached for re-use. */
825  bool offsets_cached;
827  /** If true, then key part can have columns that can take
828  NULL values. */
829  bool key_has_null_cols;
830 };
831 
832 /** Cache position of last inserted or selected record by caching record
833 and holding reference to the block where record resides.
834 Note: We don't commit mtr and hold it beyond a transaction lifetime as this is
835 a special case (intrinsic table) that are not shared accross connection. */
836 class last_ops_cur_t {
837  public:
838  /** Constructor */
839  last_ops_cur_t() : rec(), block(), mtr(), disable_caching(), invalid() {
840  /* Do Nothing. */
841  }
842 
843  /* Commit mtr and re-initialize cache record and block to NULL. */
844  void release() {
845  if (mtr.is_active()) {
846  mtr_commit(&mtr);
847  }
848  rec = nullptr;
849  block = nullptr;
850  invalid = false;
851  }
852 
853  public:
854  /** last inserted/selected record. */
855  rec_t *rec;
856 
857  /** block where record reside. */
858  buf_block_t *block;
860  /** active mtr that will be re-used for next insert/select. */
861  mtr_t mtr;
863  /** disable caching. (disabled when table involves blob/text.) */
864  bool disable_caching;
866  /** If index structure is undergoing structural change viz.
867  split then invalidate the cached position as it would be no more
868  remain valid. Will be re-cached on post-split insert. */
869  bool invalid;
870 };
871 
872 /** "GEN_CLUST_INDEX" is the name reserved for InnoDB default
873 system clustered index when there is no primary key. */
874 const char innobase_index_reserve_name[] = "GEN_CLUST_INDEX";
875 
876 namespace dd {
877 class Spatial_reference_system;
878 }
879 
880 /** Data structure for an index. Most fields will be
881 initialized to 0, NULL or FALSE in dict_mem_index_create(). */
882 struct dict_index_t {
883  space_index_t id; /*!< id of the index */
884  mem_heap_t *heap; /*!< memory heap */
885  id_name_t name; /*!< index name */
886  const char *table_name; /*!< table name */
887  dict_table_t *table; /*!< back pointer to table */
888  unsigned space : 32;
889  /*!< space where the index tree is placed */
890  unsigned page : 32; /*!< index tree root page number */
891  unsigned merge_threshold : 6;
892  /*!< In the pessimistic delete, if the page
893  data size drops below this limit in percent,
894  merging it to a neighbor is tried */
895 #define DICT_INDEX_MERGE_THRESHOLD_DEFAULT 50
896  unsigned type : DICT_IT_BITS;
897  /*!< index type (DICT_CLUSTERED, DICT_UNIQUE,
898  DICT_IBUF, DICT_CORRUPT) */
899 #define MAX_KEY_LENGTH_BITS 12
900  unsigned trx_id_offset : MAX_KEY_LENGTH_BITS;
901  /*!< position of the trx id column
902  in a clustered index record, if the fields
903  before it are known to be of a fixed size,
904  0 otherwise */
905 #if (1 << MAX_KEY_LENGTH_BITS) < MAX_KEY_LENGTH
906 #error(1<<MAX_KEY_LENGTH_BITS) < MAX_KEY_LENGTH
907 #endif
908  unsigned n_user_defined_cols : 10;
909  /*!< number of columns the user defined to
910  be in the index: in the internal
911  representation we add more columns */
912  unsigned allow_duplicates : 1;
913  /*!< if true, allow duplicate values
914  even if index is created with unique
915  constraint */
916  unsigned nulls_equal : 1;
917  /*!< if true, SQL NULL == SQL NULL */
918  unsigned disable_ahi : 1;
919  /*!< if true, then disable AHI. Currently
920  limited to intrinsic temporary table and SDI
921  table as index id is not unique for such table
922  which is one of the validation criterion for
923  ahi. */
924  unsigned n_uniq : 10; /*!< number of fields from the beginning
925  which are enough to determine an index
926  entry uniquely */
927  unsigned n_def : 10; /*!< number of fields defined so far */
928  unsigned n_fields : 10; /*!< number of fields in the index */
929  unsigned n_nullable : 10; /*!< number of nullable fields */
930  unsigned n_instant_nullable : 10;
931  /*!< number of nullable fields before first
932  instant ADD COLUMN applied to this table.
933  This is valid only when has_instant_cols() is true */
934  unsigned cached : 1; /*!< TRUE if the index object is in the
935  dictionary cache */
936  unsigned to_be_dropped : 1;
937  /*!< TRUE if the index is to be dropped;
938  protected by dict_operation_lock */
939  unsigned online_status : 2;
940  /*!< enum online_index_status.
941  Transitions from ONLINE_INDEX_COMPLETE (to
942  ONLINE_INDEX_CREATION) are protected
943  by dict_operation_lock and
944  dict_sys->mutex. Other changes are
945  protected by index->lock. */
946  unsigned uncommitted : 1;
947  /*!< a flag that is set for secondary indexes
948  that have not been committed to the
949  data dictionary yet */
950  unsigned instant_cols : 1;
951  /*!< TRUE if the index is clustered index and it has some
952  instant columns */
953  uint32_t srid; /* spatial reference id */
954  bool srid_is_valid;
955  /* says whether SRID is valid - it cane be
956  undefined */
957  std::unique_ptr<dd::Spatial_reference_system> rtr_srs;
958  /*!< Cached spatial reference system dictionary
959  entry used by R-tree indexes. */
960 
961 #ifdef UNIV_DEBUG
962  uint32_t magic_n; /*!< magic number */
963 /** Value of dict_index_t::magic_n */
964 #define DICT_INDEX_MAGIC_N 76789786
965 #endif
966  dict_field_t *fields; /*!< array of field descriptions */
967 #ifndef UNIV_HOTBACKUP
968  st_mysql_ftparser *parser; /*!< fulltext parser plugin */
969  bool is_ngram;
970  /*!< true if it's ngram parser */
971  bool has_new_v_col;
972  /*!< whether it has a newly added virtual
973  column in ALTER */
974  bool hidden; /*!< if the index is an hidden index */
975 #endif /* !UNIV_HOTBACKUP */
977  indexes; /*!< list of indexes of the table */
978  btr_search_t *search_info;
979  /*!< info used in optimistic searches */
980 #ifndef UNIV_HOTBACKUP
981  row_log_t *online_log;
982  /*!< the log of modifications
983  during online index creation;
984  valid when online_status is
985  ONLINE_INDEX_CREATION */
986  /*----------------------*/
987  /** Statistics for query optimization */
988  /** @{ */
989  ib_uint64_t *stat_n_diff_key_vals;
990  /*!< approximate number of different
991  key values for this index, for each
992  n-column prefix where 1 <= n <=
993  dict_get_n_unique(index) (the array is
994  indexed from 0 to n_uniq-1); we
995  periodically calculate new
996  estimates */
997  ib_uint64_t *stat_n_sample_sizes;
998  /*!< number of pages that were sampled
999  to calculate each of stat_n_diff_key_vals[],
1000  e.g. stat_n_sample_sizes[3] pages were sampled
1001  to get the number stat_n_diff_key_vals[3]. */
1002  ib_uint64_t *stat_n_non_null_key_vals;
1003  /* approximate number of non-null key values
1004  for this index, for each column where
1005  1 <= n <= dict_get_n_unique(index) (the array
1006  is indexed from 0 to n_uniq-1); This
1007  is used when innodb_stats_method is
1008  "nulls_ignored". */
1009  ulint stat_index_size;
1010  /*!< approximate index size in
1011  database pages */
1012 #endif /* !UNIV_HOTBACKUP */
1013  ulint stat_n_leaf_pages;
1014  /*!< approximate number of leaf pages in the
1015  index tree */
1016  /** @} */
1017  last_ops_cur_t *last_ins_cur;
1018  /*!< cache the last insert position.
1019  Currently limited to auto-generated
1020  clustered index on intrinsic table only. */
1021  last_ops_cur_t *last_sel_cur;
1022  /*!< cache the last selected position
1023  Currently limited to intrinsic table only. */
1024  rec_cache_t rec_cache;
1025  /*!< cache the field that needs to be
1026  re-computed on each insert.
1027  Limited to intrinsic table as this is common
1028  share and can't be used without protection
1029  if table is accessible to multiple-threads. */
1030  rtr_ssn_t rtr_ssn; /*!< Node sequence number for RTree */
1031  rtr_info_track_t *rtr_track; /*!< tracking all R-Tree search cursors */
1032  trx_id_t trx_id; /*!< id of the transaction that created this
1033  index, or 0 if the index existed
1034  when InnoDB was started up */
1035  zip_pad_info_t zip_pad; /*!< Information about state of
1036  compression failures and successes */
1037  rw_lock_t lock; /*!< read-write lock protecting the
1038  upper levels of the index tree */
1039  bool fill_dd; /*!< Flag whether need to fill dd tables
1040  when it's a fulltext index. */
1042  /** Determine if the index has been committed to the
1043  data dictionary.
1044  @return whether the index definition has been committed */
1045  bool is_committed() const {
1046  ut_ad(!uncommitted || !(type & DICT_CLUSTERED));
1047  return (UNIV_LIKELY(!uncommitted));
1048  }
1050  /** Flag an index committed or uncommitted.
1051  @param[in] committed whether the index is committed */
1052  void set_committed(bool committed) {
1053  ut_ad(!to_be_dropped);
1054  ut_ad(committed || !(type & DICT_CLUSTERED));
1055  uncommitted = !committed;
1056  }
1057 
1058  /** Get the next index.
1059  @return next index
1060  @retval NULL if this was the last index */
1061  const dict_index_t *next() const {
1062  const dict_index_t *next = UT_LIST_GET_NEXT(indexes, this);
1063  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1064  return (next);
1065  }
1066  /** Get the next index.
1067  @return next index
1068  @retval NULL if this was the last index */
1069  dict_index_t *next() {
1070  return (const_cast<dict_index_t *>(
1071  const_cast<const dict_index_t *>(this)->next()));
1072  }
1074  /** Check whether the index is corrupted.
1075  @return true if index is corrupted, otherwise false */
1076  bool is_corrupted() const {
1077  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1078 
1079  return (type & DICT_CORRUPT);
1080  }
1081 
1082  /* Check whether the index is the clustered index
1083  @return nonzero for clustered index, zero for other indexes */
1084 
1085  bool is_clustered() const {
1086  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1087 
1088  return (type & DICT_CLUSTERED);
1089  }
1090 
1091  /** Check whether the index is the multi-value index
1092  @return nonzero for multi-value index, zero for other indexes */
1093  bool is_multi_value() const {
1094  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1095 
1096  return (type & DICT_MULTI_VALUE);
1097  }
1098 
1099  /** Returns the minimum data size of an index record.
1100  @return minimum data size in bytes */
1101  ulint get_min_size() const {
1102  ulint size = 0;
1103 
1104  for (unsigned i = 0; i < n_fields; i++) {
1105  size += get_col(i)->get_min_size();
1106  }
1107 
1108  return (size);
1109  }
1110 
1111  /** Check whether index can be used by transaction
1112  @param[in] trx transaction*/
1113  bool is_usable(const trx_t *trx) const;
1114 
1115  /** Check whether index has any instantly added columns
1116  @return true if this is instant affected, otherwise false */
1117  bool has_instant_cols() const { return (instant_cols); }
1118 
1119  /** Check if tuple is having instant format.
1120  @param[in] n_fields_in_tuple number of fields in tuple
1121  @return true if yes, false otherwise. */
1122  bool is_tuple_instant_format(const uint16_t n_fields_in_tuple) const;
1123 
1124  /** Returns the number of nullable fields before specified
1125  nth field
1126  @param[in] nth nth field to check */
1127  uint32_t get_n_nullable_before(uint32_t nth) const {
1128  uint32_t nullable = n_nullable;
1129 
1130  ut_ad(nth <= n_fields);
1132  for (uint32_t i = nth; i < n_fields; ++i) {
1133  if (get_field(i)->col->is_nullable()) {
1134  --nullable;
1135  }
1136  }
1137 
1138  return (nullable);
1139  }
1140 
1141  /** Returns the number of fields before first instant ADD COLUMN */
1142  uint32_t get_instant_fields() const;
1143 
1144  /** Adds a field definition to an index. NOTE: does not take a copy
1145  of the column name if the field is a column. The memory occupied
1146  by the column name may be released only after publishing the index.
1147  @param[in] name_arg column name
1148  @param[in] prefix_len 0 or the column prefix length in a MySQL index
1149  like INDEX (textcol(25))
1150  @param[in] is_ascending true=ASC, false=DESC */
1151  void add_field(const char *name_arg, ulint prefix_len, bool is_ascending) {
1152  dict_field_t *field;
1153 
1154  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1156  n_def++;
1157 
1158  field = get_field(n_def - 1);
1159 
1160  field->name = name_arg;
1161  field->prefix_len = (unsigned int)prefix_len;
1162  field->is_ascending = is_ascending;
1163  }
1164 
1165  /** Gets the nth field of an index.
1166  @param[in] pos position of field
1167  @return pointer to field object */
1168  dict_field_t *get_field(ulint pos) const {
1169  ut_ad(pos < n_def);
1170  ut_ad(magic_n == DICT_INDEX_MAGIC_N);
1171 
1172  return (fields + pos);
1173  }
1174 
1175  /** Gets pointer to the nth column in an index.
1176  @param[in] pos position of the field
1177  @return column */
1178  const dict_col_t *get_col(ulint pos) const { return (get_field(pos)->col); }
1179 
1180  /** Gets the column number the nth field in an index.
1181  @param[in] pos position of the field
1182  @return column number */
1183  ulint get_col_no(ulint pos) const;
1184 
1185  /** Returns the position of a system column in an index.
1186  @param[in] type DATA_ROW_ID, ...
1187  @return position, ULINT_UNDEFINED if not contained */
1188  ulint get_sys_col_pos(ulint type) const;
1189 
1190  /** Looks for column n in an index.
1191  @param[in] n column number
1192  @param[in] inc_prefix true=consider column prefixes too
1193  @param[in] is_virtual true==virtual column
1194  @return position in internal representation of the index;
1195  ULINT_UNDEFINED if not contained */
1196  ulint get_col_pos(ulint n, bool inc_prefix = false,
1197  bool is_virtual = false) const;
1198 
1199  /** Get the default value of nth field and its length if exists.
1200  If not exists, both the return value is nullptr and length is 0.
1201  @param[in] nth nth field to get
1202  @param[in,out] length length of the default value
1203  @return the default value data of nth field */
1204  const byte *get_nth_default(ulint nth, ulint *length) const {
1205  ut_ad(nth < n_fields);
1206  ut_ad(get_instant_fields() <= nth);
1207  const dict_col_t *col = get_col(nth);
1208  if (col->instant_default == nullptr) {
1209  *length = 0;
1210  return (nullptr);
1211  }
1212 
1213  *length = col->instant_default->len;
1214  ut_ad(*length == 0 || *length == UNIV_SQL_NULL ||
1215  col->instant_default->value != nullptr);
1216  return (col->instant_default->value);
1217  }
1218 
1219  /** Sets srid and srid_is_valid values
1220  @param[in] srid_value value of SRID, may be garbage
1221  if srid_is_valid_value = false
1222  @param[in] srid_is_valid_value value of srid_is_valid */
1223  void fill_srid_value(uint32_t srid_value, bool srid_is_valid_value) {
1224  srid_is_valid = srid_is_valid_value;
1225  srid = srid_value;
1226  }
1228  /** Check if the underlying table is compressed.
1229  @return true if compressed, false otherwise. */
1230  bool is_compressed() const;
1231 
1232  /** Check if a multi-value index is built on specified multi-value
1233  virtual column. Please note that there could be only one multi-value
1234  virtual column on the multi-value index, but not necessary the first
1235  field of the index.
1236  @param[in] mv_col multi-value virtual column
1237  @return non-zero means the column is on the index and this is the
1238  nth position of the column, zero means it's not on the index */
1239  uint32_t has_multi_value_col(const dict_v_col_t *mv_col) const {
1240  ut_ad(is_multi_value());
1241  for (uint32_t i = 0; i < n_fields; ++i) {
1242  const dict_col_t *col = get_col(i);
1243  if (mv_col->m_col.ind == col->ind) {
1244  return (i + 1);
1245  }
1246 
1247  /* Only one multi-value field, if not match then no match. */
1248  if (col->is_multi_value()) {
1249  break;
1250  }
1251  }
1252 
1253  return (0);
1254  }
1255 
1256  public:
1257  /** Get the page size of the tablespace to which this index belongs.
1258  @return the page size. */
1259  page_size_t get_page_size() const;
1260 
1261  /** Get the space id of the tablespace to which this index belongs.
1262  @return the space id. */
1263  space_id_t space_id() const { return space; }
1264 };
1265 
1266 /** The status of online index creation */
1268  /** the index is complete and ready for access */
1270  /** the index is being created, online
1271  (allowing concurrent modifications) */
1273  /** secondary index creation was aborted and the index
1274  should be dropped as soon as index->table->n_ref_count reaches 0,
1275  or online table rebuild was aborted and the clustered index
1276  of the original table should soon be restored to
1277  ONLINE_INDEX_COMPLETE */
1279  /** the online index creation was aborted, the index was
1280  dropped from the data dictionary and the tablespace, and it
1281  should be dropped from the data dictionary cache as soon as
1282  index->table->n_ref_count reaches 0. */
1284 };
1285 
1286 /** Set to store the virtual columns which are affected by Foreign
1287 key constraint. */
1288 typedef std::set<dict_v_col_t *, std::less<dict_v_col_t *>,
1290  dict_vcol_set;
1291 
1292 /** Data structure for a foreign key constraint; an example:
1293 FOREIGN KEY (A, B) REFERENCES TABLE2 (C, D). Most fields will be
1294 initialized to 0, NULL or FALSE in dict_mem_foreign_create(). */
1295 struct dict_foreign_t {
1296  mem_heap_t *heap; /*!< this object is allocated from
1297  this memory heap */
1298  char *id; /*!< id of the constraint as a
1299  null-terminated string */
1300  unsigned n_fields : 10; /*!< number of indexes' first fields
1301  for which the foreign key
1302  constraint is defined: we allow the
1303  indexes to contain more fields than
1304  mentioned in the constraint, as long
1305  as the first fields are as mentioned */
1306  unsigned type : 6; /*!< 0 or DICT_FOREIGN_ON_DELETE_CASCADE
1307  or DICT_FOREIGN_ON_DELETE_SET_NULL */
1308  char *foreign_table_name; /*!< foreign table name */
1309  char *foreign_table_name_lookup;
1310  /*!< foreign table name used for dict lookup */
1311  dict_table_t *foreign_table; /*!< table where the foreign key is */
1312  const char **foreign_col_names; /*!< names of the columns in the
1313  foreign key */
1314  char *referenced_table_name; /*!< referenced table name */
1315  char *referenced_table_name_lookup;
1316  /*!< referenced table name for dict lookup*/
1317  dict_table_t *referenced_table; /*!< table where the referenced key
1318  is */
1319  const char **referenced_col_names; /*!< names of the referenced
1320  columns in the referenced table */
1321  dict_index_t *foreign_index; /*!< foreign index; we require that
1322  both tables contain explicitly defined
1323  indexes for the constraint: InnoDB
1324  does not generate new indexes
1325  implicitly */
1326  dict_index_t *referenced_index; /*!< referenced index */
1327 
1328  dict_vcol_set *v_cols; /*!< set of virtual columns affected
1329  by foreign key constraint. */
1330 };
1331 
1332 std::ostream &operator<<(std::ostream &out, const dict_foreign_t &foreign);
1333 
1334 struct dict_foreign_print {
1335  dict_foreign_print(std::ostream &out) : m_out(out) {}
1336 
1337  void operator()(const dict_foreign_t *foreign) { m_out << *foreign; }
1339  private:
1340  std::ostream &m_out;
1341 };
1342 
1343 /** Compare two dict_foreign_t objects using their ids. Used in the ordering
1344 of dict_table_t::foreign_set and dict_table_t::referenced_set. It returns
1345 true if the first argument is considered to go before the second in the
1346 strict weak ordering it defines, and false otherwise. */
1347 struct dict_foreign_compare {
1348  bool operator()(const dict_foreign_t *lhs, const dict_foreign_t *rhs) const {
1349  return (ut_strcmp(lhs->id, rhs->id) < 0);
1350  }
1351 };
1353 /** A function object to find a foreign key with the given index as the
1354 referenced index. Return the foreign key with matching criteria or NULL */
1355 struct dict_foreign_with_index {
1356  dict_foreign_with_index(const dict_index_t *index) : m_index(index) {}
1357 
1358  bool operator()(const dict_foreign_t *foreign) const {
1359  return (foreign->referenced_index == m_index);
1360  }
1361 
1362  const dict_index_t *m_index;
1363 };
1364 
1365 /* A function object to check if the foreign constraint is between different
1366 tables. Returns true if foreign key constraint is between different tables,
1367 false otherwise. */
1369  bool operator()(const dict_foreign_t *foreign) const {
1370  return (foreign->foreign_table != foreign->referenced_table);
1371  }
1372 };
1377 
1378 std::ostream &operator<<(std::ostream &out, const dict_foreign_set &fk_set);
1379 
1380 /** Function object to check if a foreign key object is there
1381 in the given foreign key set or not. It returns true if the
1382 foreign key is not found, false otherwise */
1383 struct dict_foreign_not_exists {
1384  dict_foreign_not_exists(const dict_foreign_set &obj_) : m_foreigns(obj_) {}
1385 
1386  /* Return true if the given foreign key is not found */
1387  bool operator()(dict_foreign_t *const &foreign) const {
1388  return (m_foreigns.find(foreign) == m_foreigns.end());
1389  }
1390 
1391  private:
1392  const dict_foreign_set &m_foreigns;
1393 };
1394 
1395 /** Validate the search order in the foreign key set.
1396 @param[in] fk_set the foreign key set to be validated
1397 @return true if search order is fine in the set, false otherwise. */
1398 bool dict_foreign_set_validate(const dict_foreign_set &fk_set);
1399 
1400 /** Validate the search order in the foreign key sets of the table
1401 (foreign_set and referenced_set).
1402 @param[in] table table whose foreign key sets are to be validated
1403 @return true if foreign key sets are fine, false otherwise. */
1404 bool dict_foreign_set_validate(const dict_table_t &table);
1405 
1406 /** Frees a foreign key struct. */
1407 inline void dict_foreign_free(
1408  dict_foreign_t *foreign) /*!< in, own: foreign key struct */
1409 {
1410  if (foreign->v_cols != nullptr) {
1411  UT_DELETE(foreign->v_cols);
1412  }
1413 
1414  mem_heap_free(foreign->heap);
1415 }
1416 
1417 /** The destructor will free all the foreign key constraints in the set
1418 by calling dict_foreign_free() on each of the foreign key constraints.
1419 This is used to free the allocated memory when a local set goes out
1420 of scope. */
1421 struct dict_foreign_set_free {
1422  dict_foreign_set_free(const dict_foreign_set &foreign_set)
1423  : m_foreign_set(foreign_set) {}
1424 
1426  std::for_each(m_foreign_set.begin(), m_foreign_set.end(),
1428  }
1430  const dict_foreign_set &m_foreign_set;
1431 };
1432 
1433 /** The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that
1434 a foreign key constraint is enforced, therefore RESTRICT just means no flag */
1435 /** @{ */
1436 #define DICT_FOREIGN_ON_DELETE_CASCADE 1 /*!< ON DELETE CASCADE */
1437 #define DICT_FOREIGN_ON_DELETE_SET_NULL 2 /*!< ON DELETE SET NULL */
1438 #define DICT_FOREIGN_ON_UPDATE_CASCADE 4 /*!< ON UPDATE CASCADE */
1439 #define DICT_FOREIGN_ON_UPDATE_SET_NULL 8 /*!< ON UPDATE SET NULL */
1440 #define DICT_FOREIGN_ON_DELETE_NO_ACTION 16 /*!< ON DELETE NO ACTION */
1441 #define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32 /*!< ON UPDATE NO ACTION */
1442 /** @} */
1444 /** Display an identifier.
1445 @param[in,out] s output stream
1446 @param[in] id_name SQL identifier (other than table name)
1447 @return the output stream */
1448 std::ostream &operator<<(std::ostream &s, const id_name_t &id_name);
1449 
1450 /** Display a table name.
1451 @param[in,out] s output stream
1452 @param[in] table_name table name
1453 @return the output stream */
1454 std::ostream &operator<<(std::ostream &s, const table_name_t &table_name);
1455 
1456 #ifndef UNIV_HOTBACKUP
1457 /** List of locks that different transactions have acquired on a table. This
1458 list has a list node that is embedded in a nested union/structure. We have to
1459 generate a specific template for it. */
1460 
1463 #endif /* !UNIV_HOTBACKUP */
1464 
1465 /** mysql template structure defined in row0mysql.cc */
1467 
1468 /** Structure defines template related to virtual columns and
1469 their base columns */
1470 struct dict_vcol_templ_t {
1471  /** number of regular columns */
1472  ulint n_col;
1473 
1474  /** number of virtual columns */
1475  ulint n_v_col;
1477  /** array of templates for virtual col and their base columns */
1478  mysql_row_templ_t **vtempl;
1480  /** table's database name */
1481  std::string db_name;
1483  /** table name */
1484  std::string tb_name;
1486  /** share->table_name */
1487  std::string share_name;
1489  /** MySQL record length */
1490  ulint rec_len;
1492  /** default column value if any */
1493  byte *default_rec;
1494 };
1495 
1496 /** The dirty status of tables, used to indicate if a table has some
1497 dynamic metadata changed to be written back */
1498 enum table_dirty_status {
1499  /** Some persistent metadata is now dirty in memory, need to be
1500  written back to DDTableBuffer table and(or directly to) DD table.
1501  There could be some exceptions, when it's marked as dirty, but
1502  the metadata has already been written back to DDTableBuffer.
1503  For example, if a corrupted index is found and marked as corrupted,
1504  then it gets dropped. At this time, the dirty_status is still of
1505  this dirty value. Also a concurrent checkpoint make this bit
1506  out-of-date for other working threads, which still think the
1507  status is dirty and write-back is necessary.
1508  There could be either one row or no row for this table in
1509  DDTableBuffer table */
1510  METADATA_DIRTY = 0,
1511  /** Some persistent metadata is buffered in DDTableBuffer table,
1512  need to be written back to DD table. There is must be one row in
1513  DDTableBuffer table for this table */
1515  /** All persistent metadata are up to date. There is no row
1516  for this table in DDTableBuffer table */
1518 };
1519 
1520 #ifndef UNIV_HOTBACKUP
1521 /** A vector to collect prebuilt from different readers working on the same
1522 temp table */
1523 typedef std::vector<row_prebuilt_t *> temp_prebuilt_vec;
1524 #endif /* !UNIV_HOTBACKUP */
1525 
1526 /** Data structure for a database table. Most fields will be
1527 initialized to 0, NULL or FALSE in dict_mem_table_create(). */
1528 struct dict_table_t {
1529  /** Check if the table is compressed.
1530  @return true if compressed, false otherwise. */
1531  bool is_compressed() const { return (DICT_TF_GET_ZIP_SSIZE(flags) != 0); }
1533  /** Get reference count.
1534  @return current value of n_ref_count */
1535  inline uint64_t get_ref_count() const;
1536 
1537  /** Acquire the table handle. */
1538  inline void acquire();
1539 
1540  /** Acquire the table handle, with lock() and unlock() the table.
1541  This function needs to be called for opening table when the table
1542  is in memory and later the stats information would be initialized */
1543  inline void acquire_with_lock();
1544 
1545  /** Release the table handle. */
1546  inline void release();
1547 
1548  /** Lock the table handle. */
1549  inline void lock();
1550 
1551  /** Unlock the table handle. */
1552  inline void unlock();
1553 
1554 #ifndef UNIV_HOTBACKUP
1555  /** Get schema and table name in system character set.
1556  @param[out] schema schema name
1557  @param[out] table table name */
1558  void get_table_name(std::string &schema, std::string &table);
1559 
1560  /** Mutex of the table for concurrency access. */
1561  ib_mutex_t *mutex;
1562 
1563  /** Creation state of mutex. */
1564  volatile os_once::state_t mutex_created;
1565 #endif /* !UNIV_HOTBACKUP */
1566 
1567  /** Id of the table. */
1569 
1570  /** Memory heap. If you allocate from this heap after the table has
1571  been created then be sure to account the allocation into
1572  dict_sys->size. When closing the table we do something like
1573  dict_sys->size -= mem_heap_get_size(table->heap) and if that is going
1574  to become negative then we would assert. Something like this should do:
1575  old_size = mem_heap_get_size()
1576  mem_heap_alloc()
1577  new_size = mem_heap_get_size()
1578  dict_sys->size += new_size - old_size. */
1579  mem_heap_t *heap;
1580 
1581  /** Table name. */
1584  /** Truncate name. */
1585  table_name_t trunc_name;
1587  /** NULL or the directory path specified by DATA DIRECTORY. */
1588  char *data_dir_path;
1590  /** NULL or the tablespace name that this table is assigned to,
1591  specified by the TABLESPACE option.*/
1592  id_name_t tablespace;
1593 
1594  /** Space where the clustered index of the table is placed. */
1595  space_id_t space;
1597  /** dd::Tablespace::id of the table */
1598  dd::Object_id dd_space_id;
1600  /** Stores information about:
1601  1 row format (redundant or compact),
1602  2 compressed page size (zip shift size),
1603  3 whether using atomic blobs,
1604  4 whether the table has been created with the option DATA DIRECTORY.
1605  Use DICT_TF_GET_COMPACT(), DICT_TF_GET_ZIP_SSIZE(),
1606  DICT_TF_HAS_ATOMIC_BLOBS() and DICT_TF_HAS_DATA_DIR() to parse this
1607  flag. */
1608  unsigned flags : DICT_TF_BITS;
1609 
1610  /** Stores information about:
1611  1 whether the table has been created using CREATE TEMPORARY TABLE,
1612  2 whether the table has an internally defined DOC ID column,
1613  3 whether the table has a FTS index,
1614  4 whether DOC ID column need to be added to the FTS index,
1615  5 whether the table is being created its own tablespace,
1616  6 whether the table has been DISCARDed,
1617  7 whether the aux FTS tables names are in hex.
1618  8 whether the table is instinc table.
1619  9 whether the table has encryption setting.
1620  Use DICT_TF2_FLAG_IS_SET() to parse this flag. */
1621  unsigned flags2 : DICT_TF2_BITS;
1622 
1623  /** TRUE if the table is an intermediate table during copy alter
1624  operation or a partition/subpartition which is required for copying
1625  data and skip the undo log for insertion of row in the table.
1626  This variable will be set and unset during extra(), or during the
1627  process of altering partitions */
1628  unsigned skip_alter_undo : 1;
1629 
1630  /** TRUE if this is in a single-table tablespace and the .ibd file is
1631  missing. Then we must return in ha_innodb.cc an error if the user
1632  tries to query such an orphaned table. */
1633  unsigned ibd_file_missing : 1;
1634 
1635  /** TRUE if the table object has been added to the dictionary cache. */
1636  unsigned cached : 1;
1638  /** TRUE if the table is to be dropped, but not yet actually dropped
1639  (could in the background drop list). It is turned on at the beginning
1640  of row_drop_table_for_mysql() and turned off just before we start to
1641  update system tables for the drop. It is protected by
1642  dict_operation_lock. */
1643  unsigned to_be_dropped : 1;
1644 
1645  /** Number of non-virtual columns defined so far. */
1646  unsigned n_def : 10;
1648  /** Number of non-virtual columns. */
1649  unsigned n_cols : 10;
1651  /** Number of non-virtual columns before first instant ADD COLUMN,
1652  including the system columns like n_cols. */
1653  unsigned n_instant_cols : 10;
1654 
1655  /** Number of total columns (inlcude virtual and non-virtual) */
1656  unsigned n_t_cols : 10;
1658  /** Number of total columns defined so far. */
1659  unsigned n_t_def : 10;
1661  /** Number of virtual columns defined so far. */
1662  unsigned n_v_def : 10;
1664  /** Number of virtual columns. */
1665  unsigned n_v_cols : 10;
1667  /** Number of multi-value virtual columns. */
1668  unsigned n_m_v_cols : 10;
1670  /** TRUE if this table is expected to be kept in memory. This table
1671  could be a table that has FK relationships or is undergoing DDL */
1672  unsigned can_be_evicted : 1;
1673 
1674  /** TRUE if this table is not evictable(can_be_evicted) and this is
1675  because of DDL operation */
1676  unsigned ddl_not_evictable : 1;
1677 
1678  /** TRUE if some indexes should be dropped after ONLINE_INDEX_ABORTED
1679  or ONLINE_INDEX_ABORTED_DROPPED. */
1680  unsigned drop_aborted : 1;
1681 
1682  /** Array of column descriptions. */
1683  dict_col_t *cols;
1685  /** Array of virtual column descriptions. */
1686  dict_v_col_t *v_cols;
1688  /** List of stored column descriptions. It is used only for foreign key
1689  check during create table and copy alter operations.
1690  During copy alter, s_cols list is filled during create table operation
1691  and need to preserve till rename table operation. That is the
1692  reason s_cols is a part of dict_table_t */
1693  dict_s_col_list *s_cols;
1694 
1695  /** Column names packed in a character string
1696  "name1\0name2\0...nameN\0". Until the string contains n_cols, it will
1697  be allocated from a temporary heap. The final string will be allocated
1698  from table->heap. */
1699  const char *col_names;
1700 
1701  /** Virtual column names */
1702  const char *v_col_names;
1704  /** True if the table belongs to a system database (mysql, information_schema
1705  or performance_schema) */
1706  bool is_system_table;
1707 
1708  /** Hash chain node. */
1709  hash_node_t name_hash;
1711  /** Hash chain node. */
1712  hash_node_t id_hash;
1714  /** The FTS_DOC_ID_INDEX, or NULL if no fulltext indexes exist */
1715  dict_index_t *fts_doc_id_index;
1717  /** List of indexes of the table. */
1720  /** List of foreign key constraints in the table. These refer to
1721  columns in other tables. */
1722  UT_LIST_BASE_NODE_T(dict_foreign_t) foreign_list;
1723 
1724  /** List of foreign key constraints which refer to this table. */
1725  UT_LIST_BASE_NODE_T(dict_foreign_t) referenced_list;
1726 
1727  /** Node of the LRU list of tables. */
1728  UT_LIST_NODE_T(dict_table_t) table_LRU;
1729 
1730  /** metadata version number of dd::Table::se_private_data() */
1731  uint64_t version;
1732 
1733  /** table dynamic metadata status, protected by dict_persist->mutex */
1734  std::atomic<table_dirty_status> dirty_status;
1736 #ifndef UNIV_HOTBACKUP
1737  /** Node of the dirty table list of tables, which is protected
1738  by dict_persist->mutex */
1739  UT_LIST_NODE_T(dict_table_t) dirty_dict_tables;
1740 #endif /* !UNIV_HOTBACKUP */
1741 
1742 #ifdef UNIV_DEBUG
1743  /** This field is used to mark if a table is in the
1744  dirty_dict_tables_list. if the dirty_status is not of
1745  METADATA_CLEAN, the table should be in the list, otherwise not.
1746  This field should be protected by dict_persist->mutex too. */
1747  bool in_dirty_dict_tables_list;
1748 #endif /* UNIV_DEBUG */
1749 
1750  /** Maximum recursive level we support when loading tables chained
1751  together with FK constraints. If exceeds this level, we will stop
1752  loading child table into memory along with its parent table. */
1753  unsigned fk_max_recusive_level : 8;
1754 
1755  /** Count of how many foreign key check operations are currently being
1756  performed on the table. We cannot drop the table while there are
1757  foreign key checks running on it. */
1758  ulint n_foreign_key_checks_running;
1759 
1760  /** Transaction id that last touched the table definition. Either when
1761  loading the definition or CREATE TABLE, or ALTER TABLE (prepare,
1762  commit, and rollback phases). */
1763  trx_id_t def_trx_id;
1764 
1765  /*!< set of foreign key constraints in the table; these refer to
1766  columns in other tables */
1767  dict_foreign_set foreign_set;
1768 
1769  /*!< set of foreign key constraints which refer to this table */
1770  dict_foreign_set referenced_set;
1772 #ifdef UNIV_DEBUG
1773  /** This field is used to specify in simulations tables which are so
1774  big that disk should be accessed. Disk access is simulated by putting
1775  the thread to sleep for a while. NOTE that this flag is not stored to
1776  the data dictionary on disk, and the database will forget about value
1777  TRUE if it has to reload the table definition from disk. */
1778  ibool does_not_fit_in_memory;
1779 #endif /* UNIV_DEBUG */
1780 
1781  /** TRUE if the maximum length of a single row exceeds BIG_ROW_SIZE.
1782  Initialized in dict_table_add_to_cache(). */
1783  unsigned big_rows : 1;
1784 
1785 #ifndef UNIV_HOTBACKUP
1786  /** Statistics for query optimization. @{ */
1788  /** Creation state of 'stats_latch'. */
1789  volatile os_once::state_t stats_latch_created;
1790 
1791  /** This latch protects:
1792  "dict_table_t::stat_initialized",
1793  "dict_table_t::stat_n_rows (*)",
1794  "dict_table_t::stat_clustered_index_size",
1795  "dict_table_t::stat_sum_of_other_index_sizes",
1796  "dict_table_t::stat_modified_counter (*)",
1797  "dict_table_t::indexes*::stat_n_diff_key_vals[]",
1798  "dict_table_t::indexes*::stat_index_size",
1799  "dict_table_t::indexes*::stat_n_leaf_pages".
1800  (*) Those are not always protected for
1801  performance reasons. */
1802  rw_lock_t *stats_latch;
1803 
1804  /** TRUE if statistics have been calculated the first time after
1805  database startup or table creation. */
1806  unsigned stat_initialized : 1;
1807 
1808  /** Timestamp of last recalc of the stats. */
1809  ib_time_monotonic_t stats_last_recalc;
1811 /** The two bits below are set in the 'stat_persistent' member. They
1812 have the following meaning:
1813 1. _ON=0, _OFF=0, no explicit persistent stats setting for this table,
1814 the value of the global srv_stats_persistent is used to determine
1815 whether the table has persistent stats enabled or not
1816 2. _ON=0, _OFF=1, persistent stats are explicitly disabled for this
1817 table, regardless of the value of the global srv_stats_persistent
1818 3. _ON=1, _OFF=0, persistent stats are explicitly enabled for this
1819 table, regardless of the value of the global srv_stats_persistent
1820 4. _ON=1, _OFF=1, not allowed, we assert if this ever happens. */
1821 #define DICT_STATS_PERSISTENT_ON (1 << 1)
1822 #define DICT_STATS_PERSISTENT_OFF (1 << 2)
1823 
1824  /** Indicates whether the table uses persistent stats or not. See
1825  DICT_STATS_PERSISTENT_ON and DICT_STATS_PERSISTENT_OFF. */
1826  ib_uint32_t stat_persistent;
1827 
1828 /** The two bits below are set in the 'stats_auto_recalc' member. They
1829 have the following meaning:
1830 1. _ON=0, _OFF=0, no explicit auto recalc setting for this table, the
1831 value of the global srv_stats_persistent_auto_recalc is used to
1832 determine whether the table has auto recalc enabled or not
1833 2. _ON=0, _OFF=1, auto recalc is explicitly disabled for this table,
1834 regardless of the value of the global srv_stats_persistent_auto_recalc
1835 3. _ON=1, _OFF=0, auto recalc is explicitly enabled for this table,
1836 regardless of the value of the global srv_stats_persistent_auto_recalc
1837 4. _ON=1, _OFF=1, not allowed, we assert if this ever happens. */
1838 #define DICT_STATS_AUTO_RECALC_ON (1 << 1)
1839 #define DICT_STATS_AUTO_RECALC_OFF (1 << 2)
1840 
1841  /** Indicates whether the table uses automatic recalc for persistent
1842  stats or not. See DICT_STATS_AUTO_RECALC_ON and
1843  DICT_STATS_AUTO_RECALC_OFF. */
1844  ib_uint32_t stats_auto_recalc;
1845 
1846  /** The number of pages to sample for this table during persistent
1847  stats estimation. If this is 0, then the value of the global
1848  srv_stats_persistent_sample_pages will be used instead. */
1849  ulint stats_sample_pages;
1850 
1851  /** Approximate number of rows in the table. We periodically calculate
1852  new estimates. */
1853  ib_uint64_t stat_n_rows;
1854 
1855  /** Approximate clustered index size in database pages. */
1856  ulint stat_clustered_index_size;
1858  /** Approximate size of other indexes in database pages. */
1859  ulint stat_sum_of_other_index_sizes;
1861  /** If FTS AUX table, parent table id */
1862  table_id_t parent_id;
1864  /** How many rows are modified since last stats recalc. When a row is
1865  inserted, updated, or deleted, we add 1 to this number; we calculate
1866  new estimates for the table and the indexes if the table has changed
1867  too much, see row_update_statistics_if_needed(). The counter is reset
1868  to zero at statistics calculation. This counter is not protected by
1869  any latch, because this is only used for heuristics. */
1870  ib_uint64_t stat_modified_counter;
1871 
1872 /** Background stats thread is not working on this table. */
1873 #define BG_STAT_NONE 0
1875 /** Set in 'stats_bg_flag' when the background stats code is working
1876 on this table. The DROP TABLE code waits for this to be cleared before
1877 proceeding. */
1878 #define BG_STAT_IN_PROGRESS (1 << 0)
1879 
1880 /** Set in 'stats_bg_flag' when DROP TABLE starts waiting on
1881 BG_STAT_IN_PROGRESS to be cleared. The background stats thread will
1882 detect this and will eventually quit sooner. */
1883 #define BG_STAT_SHOULD_QUIT (1 << 1)
1884 
1885  /** The state of the background stats thread wrt this table.
1886  See BG_STAT_NONE, BG_STAT_IN_PROGRESS and BG_STAT_SHOULD_QUIT.
1887  Writes are covered by dict_sys->mutex. Dirty reads are possible. */
1888  byte stats_bg_flag;
1889 
1890  /** @} */
1891 #endif /* !UNIV_HOTBACKUP */
1893  /** AUTOINC related members. @{ */
1894 
1895  /* The actual collection of tables locked during AUTOINC read/write is
1896  kept in trx_t. In order to quickly determine whether a transaction has
1897  locked the AUTOINC lock we keep a pointer to the transaction here in
1898  the 'autoinc_trx' member. This is to avoid acquiring lock_sys latches and
1899  scanning the vector in trx_t.
1900  When an AUTOINC lock has to wait, the corresponding lock instance is
1901  created on the trx lock heap rather than use the pre-allocated instance
1902  in autoinc_lock below. */
1903 
1904  /** A buffer for an AUTOINC lock for this table. We allocate the
1905  memory here so that individual transactions can get it and release it
1906  without a need to allocate space from the lock heap of the trx:
1907  otherwise the lock heap would grow rapidly if we do a large insert
1908  from a select. */
1909 #ifndef UNIV_HOTBACKUP
1910  lock_t *autoinc_lock;
1911 
1912  /** Creation state of autoinc_mutex member */
1913  volatile os_once::state_t autoinc_mutex_created;
1914 #endif /* !UNIV_HOTBACKUP */
1915 
1916  /** Mutex protecting the autoincrement counter. */
1917  ib_mutex_t *autoinc_mutex;
1918 
1919  /** Autoinc counter value to give to the next inserted row. */
1920  ib_uint64_t autoinc;
1922  /** Mutex protecting the persisted autoincrement counter. */
1923  ib_mutex_t *autoinc_persisted_mutex;
1925  /** Autoinc counter value that has been persisted in redo logs or
1926  DDTableBuffer. It's mainly used when we want to write counter back
1927  to DDTableBuffer.
1928  This is different from the 'autoinc' above, which could be bigger
1929  than this one, because 'autoinc' will get updated right after
1930  some counters are allocated, but we will write the counter to redo
1931  logs and update this counter later. Once all allocated counters
1932  have been written to redo logs, 'autoinc' should be exact the next
1933  counter of this persisted one.
1934  We want this counter because when we need to write the counter back
1935  to DDTableBuffer, we had better keep it consistency with the counter
1936  that has been written to redo logs. Besides, we can't read the 'autoinc'
1937  directly easily, because the autoinc_lock is required and there could
1938  be a deadlock.
1939  This variable is protected by autoinc_persisted_mutex. */
1940  ib_uint64_t autoinc_persisted;
1941 
1942  /** The position of autoinc counter field in clustered index. This would
1943  be set when CREATE/ALTER/OPEN TABLE and IMPORT TABLESPACE, and used in
1944  modifications to clustered index, such as INSERT/UPDATE. There should
1945  be no conflict to access it, so no protection is needed. */
1946  ulint autoinc_field_no;
1947 
1948  /** The transaction that currently holds the the AUTOINC lock on this table.
1949  Protected by lock_sys table shard latch. To "peek" the current value one
1950  can read it without any latch, understanding that in general it may change.
1951  Such access pattern is correct if trx thread wants to check if it has the lock
1952  granted, as the field can only change to other value when lock is released,
1953  which can not happen concurrently to thread executing the trx. */
1954  std::atomic<const trx_t *> autoinc_trx;
1955 
1956  /** @} */
1957 
1958 #ifndef UNIV_HOTBACKUP
1959  /** FTS specific state variables. */
1960  fts_t *fts;
1961 #endif /* !UNIV_HOTBACKUP */
1962 
1963  /** Quiescing states, protected by the dict_index_t::lock. ie. we can
1964  only change the state if we acquire all the latches (dict_index_t::lock)
1965  in X mode of this table's indexes. */
1966  ib_quiesce_t quiesce;
1967 
1968  /** Count of the number of record locks on this table. We use this to
1969  determine whether we can evict the table from the dictionary cache.
1970  Writes (atomic increments and decrements) are performed when holding a shared
1971  latch on lock_sys. (Note that this the table's shard latch is NOT required,
1972  as this is field counts *record* locks, so a page shard is latched instead)
1973  Reads should be performed when holding exclusive lock_sys latch, however:
1974  - Some places assert this field is zero without holding any latch.
1975  - Some places assert this field is positive holding only shared latch. */
1976  std::atomic<size_t> n_rec_locks;
1977 
1978 #ifndef UNIV_DEBUG
1979  private:
1980 #endif
1981  /** Count of how many handles are opened to this table. Dropping of the
1982  table is NOT allowed until this count gets to zero. MySQL does NOT
1983  itself check the number of open handles at DROP. */
1984  std::atomic<uint64_t> n_ref_count;
1985 
1986  public:
1987 #ifndef UNIV_HOTBACKUP
1988  /** List of locks on the table. Protected by lock_sys shard latch. */
1989  table_lock_list_t locks;
1990  /** count_by_mode[M] = number of locks in this->locks with
1991  lock->type_mode&LOCK_MODE_MASK == M.
1992  Used to quickly verify that there are no LOCK_S or LOCK_X, which are the only
1993  modes incompatible with LOCK_IS and LOCK_IX, to avoid costly iteration over
1994  this->locks when adding LOCK_IS or LOCK_IX.
1995  We use count_by_mode[LOCK_AUTO_INC] to track the number of granted and pending
1996  autoinc locks on this table. This value is set after acquiring the lock_sys
1997  table shard latch, but we peek the contents to determine whether other
1998  transactions have acquired the AUTOINC lock or not. Of course only one
1999  transaction can be granted the lock but there can be multiple
2000  waiters.
2001  Protected by lock_sys table shard latch. */
2002  ulong count_by_mode[LOCK_NUM];
2003 #endif /* !UNIV_HOTBACKUP */
2004 
2005  /** Timestamp of the last modification of this table. */
2006  time_t update_time;
2007 
2008  /** row-id counter for use by intrinsic table for getting row-id.
2009  Given intrinsic table semantics, row-id can be locally maintained
2010  instead of getting it from central generator which involves mutex
2011  locking. */
2012  ib_uint64_t sess_row_id;
2013 
2014  /** trx_id counter for use by intrinsic table for getting trx-id.
2015  Intrinsic table are not shared so don't need a central trx-id
2016  but just need a increased counter to track consistent view while
2017  proceeding SELECT as part of UPDATE. */
2018  ib_uint64_t sess_trx_id;
2019 
2020 #ifdef UNIV_DEBUG
2021 /** Value of 'magic_n'. */
2022 #define DICT_TABLE_MAGIC_N 76333786
2023 
2024  /** Magic number. */
2025  ulint magic_n;
2026 #endif /* UNIV_DEBUG */
2027  /** mysql_row_templ_t for base columns used for compute the virtual
2028  columns */
2030 
2031  /** encryption key, it's only for export/import */
2032  byte *encryption_key;
2034  /** encryption iv, it's only for export/import */
2035  byte *encryption_iv;
2037  /** remove the dict_table_t from cache after DDL operation */
2038  bool discard_after_ddl;
2040  /** refresh/reload FK info */
2041  bool refresh_fk;
2043 #ifndef UNIV_HOTBACKUP
2044  /** multiple cursors can be active on this temporary table */
2045  temp_prebuilt_vec *temp_prebuilt;
2046 #endif /* !UNIV_HOTBACKUP */
2047 
2048  /** TRUE only for dictionary tables like mysql/tables,
2049  mysql/columns, mysql/tablespaces, etc. This flag is used
2050  to do non-locking reads on DD tables. */
2051  bool is_dd_table;
2052 
2053  /** true if this table is explicitly put to non-LRU list
2054  during table creation */
2055  bool explicitly_non_lru;
2056 
2057  /** @return the clustered index */
2058  const dict_index_t *first_index() const {
2060  const dict_index_t *first = UT_LIST_GET_FIRST(indexes);
2061  return (first);
2062  }
2063  /** @return the clustered index */
2064  dict_index_t *first_index() {
2065  return (const_cast<dict_index_t *>(
2066  const_cast<const dict_table_t *>(this)->first_index()));
2067  }
2069  /** @return if there was any instantly added column.
2070  This will be true after one or more instant ADD COLUMN, however,
2071  it would become false after ALTER TABLE which rebuilds or copies
2072  the old table.
2073  If this is true, all instantly added columns should have default
2074  values, and records in the table may have REC_INFO_INSTANT_FLAG set. */
2075  bool has_instant_cols() const {
2076  ut_ad(n_instant_cols <= n_cols);
2077 
2078  return (n_instant_cols < n_cols);
2079  }
2080 
2081  /** Set the number of columns when the first instant ADD COLUMN happens.
2082  @param[in] instant_cols number of fields when first instant
2083  ADD COLUMN happens, without system
2084  columns */
2085  void set_instant_cols(uint16_t instant_cols) {
2086  n_instant_cols = static_cast<unsigned>(instant_cols) + get_n_sys_cols();
2087  }
2088 
2089  /** Get the number of user columns when the first instant ADD COLUMN
2090  happens.
2091  @return the number of user columns as described above */
2092  uint16_t get_instant_cols() const {
2093  return static_cast<uint16_t>(n_instant_cols - get_n_sys_cols());
2094  }
2095 
2096  /** Check whether the table is corrupted.
2097  @return true if the table is corrupted, otherwise false */
2098  bool is_corrupted() const {
2099  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2100 
2101  const dict_index_t *index = first_index();
2103  /* It is possible that this table is only half created, in which case
2104  the clustered index may be NULL. If the clustered index is corrupted,
2105  the table is corrupt. We do not consider the table corrupt if only
2106  a secondary index is corrupt. */
2107  ut_ad(index == nullptr || index->is_clustered());
2108 
2109  return (index != nullptr && index->type & DICT_CORRUPT);
2110  }
2111 
2112  /** Returns a column's name.
2113  @param[in] col_nr column number
2114  @return column name. NOTE: not guaranteed to stay valid if table is
2115  modified in any way (columns added, etc.). */
2116  const char *get_col_name(ulint col_nr) const {
2117  ut_ad(col_nr < n_def);
2118  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2119 
2120  const char *s = col_names;
2121  if (s) {
2122  for (ulint i = 0; i < col_nr; i++) {
2123  s += strlen(s) + 1;
2124  }
2125  }
2126 
2127  return (s);
2128  }
2129 
2130  /**Gets the nth column of a table.
2131  @param[in] pos position of column
2132  @return pointer to column object */
2133  dict_col_t *get_col(ulint pos) const {
2134  ut_ad(pos < n_def);
2135  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2136 
2137  return (cols + pos);
2138  }
2139 
2140  /** Gets the number of user-defined non-virtual columns in a table
2141  in the dictionary cache.
2142  @return number of user-defined (e.g., not ROW_ID) non-virtual columns
2143  of a table */
2144  uint16_t get_n_user_cols() const {
2145  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2146 
2147  return (static_cast<uint16_t>(n_cols) - get_n_sys_cols());
2148  }
2149 
2150  /** Gets the number of system columns in a table.
2151  For intrinsic table on ROW_ID column is added for all other
2152  tables TRX_ID and ROLL_PTR are all also appeneded.
2153  @return number of system (e.g., ROW_ID) columns of a table */
2154  uint16_t get_n_sys_cols() const {
2155  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2156 
2157  return (is_intrinsic() ? DATA_ITT_N_SYS_COLS : DATA_N_SYS_COLS);
2158  }
2159 
2160  /** Gets the number of all non-virtual columns (also system) in a table
2161  in the dictionary cache.
2162  @return number of non-virtual columns of a table */
2163  ulint get_n_cols() const {
2164  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2165 
2166  return (n_cols);
2167  }
2168 
2169  /** Gets the given system column of a table.
2170  @param[in] sys DATA_ROW_ID, ...
2171  @return pointer to column object */
2172  dict_col_t *get_sys_col(ulint sys) const {
2173  dict_col_t *col;
2174 
2175  ut_ad(sys < get_n_sys_cols());
2177 
2178  col = get_col(n_cols - get_n_sys_cols() + sys);
2179  ut_ad(col->mtype == DATA_SYS);
2180  ut_ad(col->prtype == (sys | DATA_NOT_NULL));
2181 
2182  return (col);
2183  }
2184 
2185  /** Determine if this is a temporary table. */
2186  bool is_temporary() const {
2187  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2188  return (flags2 & DICT_TF2_TEMPORARY);
2189  }
2191  /** Determine if this is a FTS AUX table. */
2192  bool is_fts_aux() const {
2193  ut_ad(magic_n == DICT_TABLE_MAGIC_N);
2194  return (flags2 & DICT_TF2_AUX);
2195  }
2197  /** Determine whether the table is intrinsic.
2198  An intrinsic table is a special kind of temporary table that
2199  is invisible to the end user. It can be created internally by InnoDB,
2200  the MySQL server layer or other modules connected to InnoDB in order
2201  to gather and use data as part of a larger task. Since access to it
2202  must be as fast as possible, it does not need UNDO semantics, system
2203  fields DB_TRX_ID & DB_ROLL_PTR, doublewrite, checksum, insert buffer,
2204  use of the shared data dictionary, locking, or even a transaction.
2205  In short, these are not ACID tables at all, just temporary data stored
2206  and manipulated during a larger process.*/
2207  bool is_intrinsic() const {
2208  if (flags2 & DICT_TF2_INTRINSIC) {
2209  ut_ad(is_temporary());
2210  return (true);
2211  }
2212 
2213  return (false);
2214  }
2215 
2216  /* GAP locks are skipped for DD tables and SDI tables
2217  @return true if table is DD table or SDI table, else false */
2218  inline bool skip_gap_locks() const;
2219 
2220  /** Determine if the table can support instant ADD COLUMN */
2221  inline bool support_instant_add() const;
2222 };
2223 
2224 inline bool dict_index_t::is_compressed() const {
2225  return (table->is_compressed());
2226 }
2227 
2228 /** Persistent dynamic metadata type, there should be 1 to 1
2229 relationship between the metadata and the type. Please keep them in order
2230 so that we can iterate over it */
2231 enum persistent_type_t {
2232  /** The smallest type, which should be 1 less than the first
2233  true type */
2234  PM_SMALLEST_TYPE = 0,
2236  /** Persistent Metadata type for corrupted indexes */
2237  PM_INDEX_CORRUPTED = 1,
2239  /** Persistent Metadata type for autoinc counter */
2240  PM_TABLE_AUTO_INC = 2,
2242  /* TODO: Will add following types
2243  PM_TABLE_UPDATE_TIME = 3,
2244  Maybe something tablespace related
2245  PM_TABLESPACE_SIZE = 4,
2246  PM_TABLESPACE_MAX_TRX_ID = 5, */
2247 
2248  /** The biggest type, which should be 1 bigger than the last
2249  true type */
2250  PM_BIGGEST_TYPE = 3
2251 };
2252 
2253 typedef std::vector<index_id_t, ut_allocator<index_id_t>> corrupted_ids_t;
2255 /** Persistent dynamic metadata for a table */
2257  public:
2258  /** Constructor
2259  @param[in] id table id
2260  @param[in] version table dynamic metadata version */
2262  : m_id(id), m_version(version), m_corrupted_ids(), m_autoinc(0) {}
2263 
2264  /** Get the corrupted indexes' IDs
2265  @return the vector of indexes' IDs */
2266  const corrupted_ids_t &get_corrupted_indexes() const {
2267  return (m_corrupted_ids);
2268  }
2269 
2270  /** Add a corrupted index id and space id
2271  @param[in] id corrupted index id */
2272  void add_corrupted_index(const index_id_t id) {
2273  m_corrupted_ids.push_back(id);
2274  }
2275 
2276  /** Set the dynamic metadata version.
2277  @param[in] version dynamic metadata version */
2278  void set_version(uint64_t version) { m_version = version; }
2279 
2280  /** Get the dynamic metadata version */
2281  uint64_t get_version() const { return (m_version); }
2283  /** Get the table id of the metadata
2284  @return table id */
2285  table_id_t get_table_id() const { return (m_id); }
2286 
2287  /** Set the autoinc counter of the table if it's bigger
2288  @param[in] autoinc autoinc counter */
2289  void set_autoinc_if_bigger(uint64_t autoinc) {
2290  /* We only set the biggest autoinc counter. Callers don't
2291  guarantee passing a bigger number in. */
2292  if (autoinc > m_autoinc) {
2293  m_autoinc = autoinc;
2294  }
2295  }
2296 
2297  /** Set the autoinc counter of the table
2298  @param[in] autoinc autoinc counter */
2299  void set_autoinc(uint64_t autoinc) { m_autoinc = autoinc; }
2300 
2301  /** Get the autoinc counter of the table
2302  @return the autoinc counter */
2303  uint64_t get_autoinc() const { return (m_autoinc); }
2304 
2305  private:
2306  /** Table ID which this metadata belongs to */
2308 
2309  /** Table dynamic metadata version of the change */
2310  uint64_t m_version;
2312  /** Storing the corrupted indexes' ID if exist, or else empty */
2313  corrupted_ids_t m_corrupted_ids;
2315  /** Autoinc counter of the table */
2316  uint64_t m_autoinc;
2318  /* TODO: We will add update_time, etc. here and APIs accordingly */
2319 };
2321 /** Interface for persistent dynamic table metadata. */
2322 class Persister {
2323  public:
2324  /** Virtual desctructor */
2325  virtual ~Persister() {}
2327  /** Write the dynamic metadata of a table, we can pre-calculate
2328  the size by calling get_write_size()
2329  @param[in] metadata persistent data
2330  @param[out] buffer write buffer
2331  @param[in] size size of write buffer, should be
2332  at least get_write_size()
2333  @return the length of bytes written */
2334  virtual ulint write(const PersistentTableMetadata &metadata, byte *buffer,
2335  ulint size) const = 0;
2336 
2337  /** Pre-calculate the size of metadata to be written
2338  @param[in] metadata metadata to be written
2339  @return the size of metadata */
2340  virtual ulint get_write_size(
2341  const PersistentTableMetadata &metadata) const = 0;
2342 
2343  /** Read the dynamic metadata from buffer, and store them to
2344  metadata object
2345  @param[out] metadata metadata where we store the read data
2346  @param[in] buffer buffer to read
2347  @param[in] size size of buffer
2348  @param[out] corrupt true if we found something wrong in
2349  the buffer except incomplete buffer,
2350  otherwise false
2351  @return the bytes we read from the buffer if the buffer data
2352  is complete and we get everything, 0 if the buffer is incompleted */
2353  virtual ulint read(PersistentTableMetadata &metadata, const byte *buffer,
2354  ulint size, bool *corrupt) const = 0;
2355 
2356  /** Write MLOG_TABLE_DYNAMIC_META for persistent dynamic
2357  metadata of table
2358  @param[in] id Table id
2359  @param[in] metadata Metadata used to write the log
2360  @param[in,out] mtr Mini-transaction */
2361  void write_log(table_id_t id, const PersistentTableMetadata &metadata,
2362  mtr_t *mtr) const;
2363 };
2364 
2365 /** Persister used for corrupted indexes */
2366 class CorruptedIndexPersister : public Persister {
2367  public:
2368  /** Write the corrupted indexes of a table, we can pre-calculate the size
2369  by calling get_write_size()
2370  @param[in] metadata persistent data
2371  @param[out] buffer write buffer
2372  @param[in] size size of write buffer, should be at least
2373  get_write_size()
2374  @return the length of bytes written */
2376  ulint size) const override;
2377 
2378  /** Pre-calculate the size of metadata to be written
2379  @param[in] metadata metadata to be written
2380  @return the size of metadata */
2381  ulint get_write_size(const PersistentTableMetadata &metadata) const override;
2382 
2383  /** Read the corrupted indexes from buffer, and store them to
2384  metadata object
2385  @param[out] metadata metadata where we store the read data
2386  @param[in] buffer buffer to read
2387  @param[in] size size of buffer
2388  @param[out] corrupt true if we found something wrong in
2389  the buffer except incomplete buffer,
2390  otherwise false
2391  @return the bytes we read from the buffer if the buffer data
2392  is complete and we get everything, 0 if the buffer is incompleted */
2393  ulint read(PersistentTableMetadata &metadata, const byte *buffer, ulint size,
2394  bool *corrupt) const override;
2395 
2396  private:
2397  /** The length of index_id_t we will write */
2398  static const size_t INDEX_ID_LENGTH = 12;
2399 };
2400 
2401 /** Persister used for autoinc counters */
2402 class AutoIncPersister : public Persister {
2403  public:
2404  /** Write the autoinc counter of a table, we can pre-calculate
2405  the size by calling get_write_size()
2406  @param[in] metadata persistent metadata
2407  @param[out] buffer write buffer
2408  @param[in] size size of write buffer, should be
2409  at least get_write_size()
2410  @return the length of bytes written */
2412  ulint size) const override;
2413 
2414  /** Pre-calculate the size of metadata to be written
2415  @param[in] metadata metadata to be written
2416  @return the size of metadata */
2417  inline ulint get_write_size(
2418  const PersistentTableMetadata &metadata) const override {
2419  /* We just return the max possible size that would be used
2420  if the counter exists, so we don't calculate every time.
2421  Here we need 1 byte for dynamic metadata type and 11 bytes
2422  for the max possible size of counter. */
2423  return (12);
2424  }
2425 
2426  /** Read the autoinc counter from buffer, and store them to
2427  metadata object
2428  @param[out] metadata metadata where we store the read data
2429  @param[in] buffer buffer to read
2430  @param[in] size size of buffer
2431  @param[out] corrupt true if we found something wrong in
2432  the buffer except incomplete buffer,
2433  otherwise false
2434  @return the bytes we read from the buffer if the buffer data
2435  is complete and we get everything, 0 if the buffer is incomplete */
2436  ulint read(PersistentTableMetadata &metadata, const byte *buffer, ulint size,
2437  bool *corrupt) const override;
2438 };
2439 
2440 /** Container of persisters used in the system. Currently we don't need
2441 to protect this object since we only initialize it at very beginning and
2442 destroy it in the end. During the server running, we only get the persisters */
2443 class Persisters {
2444  typedef std::map<
2445  persistent_type_t, Persister *, std::less<persistent_type_t>,
2448 
2449  public:
2450  /** Constructor */
2451  Persisters() : m_persisters() {}
2452 
2453  /** Destructor */
2454  ~Persisters();
2456  /** Get the persister object with specified type
2457  @param[in] type persister type
2458  @return Persister object required or NULL if not found */
2459  Persister *get(persistent_type_t type) const;
2460 
2461  /** Add a specified persister of type, we will allocate the Persister
2462  if there is no such persister exist, otherwise do nothing and return
2463  the existing one
2464  @param[in] type persister type
2465  @return the persister of type */
2466  Persister *add(persistent_type_t type);
2467 
2468  /** Remove a specified persister of type, we will free the Persister
2469  @param[in] type persister type */
2470  void remove(persistent_type_t type);
2471 
2472  /** Serialize the metadata to a buffer
2473  @param[in] metadata metadata to serialize
2474  @param[out] buffer buffer to store the serialized metadata
2475  @return the length of serialized metadata */
2477 
2478  private:
2479  /** A map to store all persisters needed */
2480  persisters_t m_persisters;
2481 };
2482 
2483 #ifndef UNIV_HOTBACKUP
2485 /** Initialise the table lock list.
2486 @param[out] lock_list List to initialise */
2488 
2489 /** A function object to add the foreign key constraint to the referenced set
2490 of the referenced table, if it exists in the dictionary cache. */
2492  void operator()(dict_foreign_t *foreign) const {
2493  if (dict_table_t *table = foreign->referenced_table) {
2494  std::pair<dict_foreign_set::iterator, bool> ret =
2495  table->referenced_set.insert(foreign);
2496  ut_a(ret.second);
2497  }
2498  }
2499 };
2500 
2501 /** Request for lazy creation of the mutex of a given table.
2502 This function is only called from either single threaded environment
2503 or from a thread that has not shared the table object with other threads.
2504 @param[in,out] table table whose mutex is to be created */
2505 inline void dict_table_mutex_create_lazy(dict_table_t *table) {
2506  table->mutex = nullptr;
2508 }
2510 /** Destroy the mutex of a given table.
2511 This function is only called from either single threaded environment
2512 or from a thread that has not shared the table object with other threads.
2513 @param[in,out] table table whose mutex is to be created */
2514 inline void dict_table_mutex_destroy(dict_table_t *table) {
2515  if (table->mutex_created == os_once::DONE) {
2516  if (table->mutex != nullptr) {
2517  mutex_free(table->mutex);
2518  UT_DELETE(table->mutex);
2519  }
2520  }
2521 }
2522 
2523 /** Destroy the autoinc latch of the given table.
2524 This function is only called from either single threaded environment
2525 or from a thread that has not shared the table object with other threads.
2526 @param[in,out] table table whose stats latch to destroy */
2527 inline void dict_table_autoinc_destroy(dict_table_t *table) {
2528  if (table->autoinc_mutex_created == os_once::DONE) {
2529  if (table->autoinc_mutex != nullptr) {
2530  mutex_free(table->autoinc_mutex);
2532  }
2533 
2534  if (table->autoinc_persisted_mutex != nullptr) {
2537  }
2538  }
2539 }
2540 
2541 /** Request for lazy creation of the autoinc latch of a given table.
2542 This function is only called from either single threaded environment
2543 or from a thread that has not shared the table object with other threads.
2544 @param[in,out] table table whose autoinc latch is to be created. */
2545 inline void dict_table_autoinc_create_lazy(dict_table_t *table) {
2546  table->autoinc_mutex = nullptr;
2547  table->autoinc_persisted_mutex = nullptr;
2550 
2551 /** Request a lazy creation of dict_index_t::zip_pad::mutex.
2552 This function is only called from either single threaded environment
2553 or from a thread that has not shared the table object with other threads.
2554 @param[in,out] index index whose zip_pad mutex is to be created */
2556  index->zip_pad.mutex = nullptr;
2558 }
2560 /** Destroy the zip_pad_mutex of the given index.
2561 This function is only called from either single threaded environment
2562 or from a thread that has not shared the table object with other threads.
2563 @param[in,out] index index whose stats latch to destroy */
2564 inline void dict_index_zip_pad_mutex_destroy(dict_index_t *index) {
2565  if (index->zip_pad.mutex_created == os_once::DONE &&
2566  index->zip_pad.mutex != nullptr) {
2567  mutex_free(index->zip_pad.mutex);
2569  }
2570 }
2571 #endif /* !UNIV_HOTBACKUP */
2572 
2573 /** Release the zip_pad_mutex of a given index.
2574 @param[in,out] index index whose zip_pad_mutex is to be released */
2575 inline void dict_index_zip_pad_unlock(dict_index_t *index) {
2576 #ifndef UNIV_HOTBACKUP
2577  mutex_exit(index->zip_pad.mutex);
2578 #endif /* !UNIV_HOTBACKUP */
2580 
2581 #ifdef UNIV_DEBUG
2582 /** Check if the current thread owns the autoinc_mutex of a given table.
2583 @param[in] table the autoinc_mutex belongs to this table
2584 @return true, if the current thread owns the autoinc_mutex, false otherwise.*/
2585 inline bool dict_table_autoinc_own(const dict_table_t *table) {
2586  return (mutex_own(table->autoinc_mutex));
2587 }
2588 #endif /* UNIV_DEBUG */
2590 #include "dict0mem.ic"
2591 
2592 #endif /* dict0mem_h */
Allocator class for allocating memory from inside std::* containers.
Definition: ut0new.h:572
ib_mutex_t * mutex
Mutex of the table for concurrency access.
Definition: dict0mem.h:1565
Record manager global types.
unsigned mtype
main data type
Definition: dict0mem.h:486
bool read(T *ap, const GV &gv, const char *key)
Definition: sdi_impl.h:339
void dict_index_zip_pad_mutex_destroy(dict_index_t *index)
Destroy the zip_pad_mutex of the given index.
Definition: dict0mem.h:2568
Definition: lock0types.h:59
unsigned len
length; for MySQL data this is field->pack_length(), except that for a >= 5.0.3 type true VARCHAR thi...
Definition: data0type.h:509
void dict_mem_foreign_table_name_lookup_set(dict_foreign_t *foreign, ibool do_alloc)
Sets the foreign_table_name_lookup pointer based on the value of lower_case_table_names.
Definition: dict0mem.cc:362
Data types.
ib_uint32_t state_t
Control variables&#39; state type.
Definition: os0once.h:66
void set(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:105
ulong zip_pad_max
Maximum percentage of a page that can be allowed as a pad to avoid compression failures.
Definition: dict0dict.cc:181
unsigned is_ascending
0=DESC, 1=ASC
Definition: dict0mem.h:741
UNIV_INLINE ulint dtype_get_min_size_low(ulint mtype, ulint prtype, ulint len, ulint mbminmaxlen)
Returns the minimum size of a data type.
Not used in gis index.
Definition: dict0types.h:335
Persistent dynamic metadata for a table.
Definition: dict0mem.h:2260
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:564
size_t len
Length of default value.
Definition: dict0mem.h:462
const char * db_name
Definition: rules_table_service.cc:54
void add(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:69
dict_col_t m_col
column structure
Definition: dict0mem.h:651
R-tree header file.
Data dictionary memory object creation.
SysMutex * mutex
mutex protecting the info
Definition: dict0mem.h:785
volatile os_once::state_t mutex_created
Creation state of mutex member.
Definition: dict0mem.h:794
static double cached
Definition: xcom_statistics.cc:97
void lock_table_lock_list_init(table_lock_list_t *lock_list)
Initialise the table lock list.
Buffer for logging modifications during online index creation.
Definition: row0log.cc:176
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
unsigned prefix_len
0 or the length of the column prefix in bytes in a MySQL index of type, e.g., INDEX (textcol(25)); mu...
Definition: dict0mem.h:730
#define MAX_KEY_LENGTH_BITS
Definition: dict0mem.h:903
File containing constants that can be used throughout the server.
persistent_type_t
Persistent dynamic metadata type, there should be 1 to 1 relationship between the metadata and the ty...
Definition: dict0mem.h:2235
Lock struct; protected by lock_sys latches.
Definition: lock0priv.h:131
Definition: trx0trx.h:833
volatile os_once::state_t autoinc_mutex_created
Creation state of autoinc_mutex member.
Definition: dict0mem.h:1917
unsigned prtype
precise type; MySQL data type, charset code, flags to indicate nullability, signedness, whether this is a binary string, whether this is a true VARCHAR where MySQL uses 2 bytes to store the length
Definition: data0type.h:498
bool dict_table_autoinc_own(const dict_table_t *table)
Check if the current thread owns the autoinc_mutex of a given table.
Definition: dict0mem.h:2589
Definition: gis0type.h:159
UNIV_INLINE void dict_mem_fill_index_struct(dict_index_t *index, mem_heap_t *heap, const char *table_name, const char *index_name, ulint space, ulint type, ulint n_fields)
This function poplulates a dict_index_t index memory structure with supplied information.
pthread_mutex_t mutex
Definition: memcached.c:384
The buffer control block structure.
Definition: buf0buf.h:1324
static const state_t NEVER_DONE
Not yet executed.
Definition: os0once.h:69
#define UT_LIST_GET_FIRST(BASE)
Definition: innodb_utility.h:115
The transaction lock system global types.
#define DATA_NOT_NULL
Definition: data0type.h:199
bool operator==(const Uuid &a, const Uuid &b)
Definition: uuid.h:169
void dict_mem_foreign_fill_vcol_set(dict_foreign_t *foreign)
Fills the dependent virtual columns in a set.
Definition: dict0mem.cc:495
#define DICT_TF_GET_ZIP_SSIZE(flags)
Return the value of the ZIP_SSIZE field.
Definition: dict0mem.h:227
#define DICT_TF2_AUX
FTS AUX hidden table bit.
Definition: dict0mem.h:285
char * dict_mem_create_temporary_tablename(mem_heap_t *heap, const char *dbtab, table_id_t id)
Create a temporary tablename like "#sql-ibtid-inc" where tid = the Table ID inc = a randomly initiali...
Definition: dict0mem.cc:750
std::list< dict_s_col_t, ut_allocator< dict_s_col_t > > dict_s_col_list
list to put stored column for dict_table_t
Definition: dict0mem.h:693
Index information put in a list of virtual column structure.
Definition: dict0mem.h:637
std::set< dict_foreign_t *, dict_foreign_compare, ut_allocator< dict_foreign_t * > > dict_foreign_set
Definition: dict0mem.h:1380
#define UT_LIST_GET_NEXT(NAME, N)
Definition: innodb_utility.h:111
bool operator!=(const system_executor &, const system_executor &)
Definition: executor.h:569
std::ostream & operator<<(std::ostream &out, const dict_foreign_t &foreign)
Definition: dict0mem.cc:814
Some persistent metadata is buffered in DDTableBuffer table, need to be written back to DD table...
Definition: dict0mem.h:1518
Data structure for a database table.
Definition: dict0mem.h:1532
ut_list_base< lock_t, ut_list_node< lock_t > lock_table_t::* > table_lock_list_t
List of locks that different transactions have acquired on a table.
Definition: dict0mem.h:1466
unsigned mbminmaxlen
minimum and maximum length of a character, in bytes; DATA_MBMINMAXLEN(mbminlen,mbmaxlen); mbminlen=DA...
Definition: data0type.h:517
void dict_index_zip_pad_mutex_create_lazy(dict_index_t *index)
Request a lazy creation of dict_index_t::zip_pad::mutex.
Definition: dict0mem.h:2559
std::vector< row_prebuilt_t * > temp_prebuilt_vec
A vector to collect prebuilt from different readers working on the same temp table.
Definition: dict0mem.h:1527
id_name_t name
name of the column
Definition: dict0mem.h:729
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:443
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:669
int64_t ib_time_monotonic_t
Time stamp read from the monotonic clock (returned by ut_time_monotonic()).
Definition: ut0ut.h:89
dict_index_t * referenced_index
referenced index
Definition: dict0mem.h:1330
Used in both spatial index and regular index.
Definition: dict0types.h:338
#define DATA_GEOMETRY_MTYPE(mtype)
Definition: data0type.h:262
bool dict_foreign_set_validate(const dict_foreign_set &fk_set)
Validate the search order in the foreign key set.
Definition: dict0mem.cc:787
void dict_table_mutex_destroy(dict_table_t *table)
Destroy the mutex of a given table.
Definition: dict0mem.h:2518
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C...
Definition: dict0mem.h:1299
The search info struct in an index.
Definition: btr0sea.h:233
unsigned ind
table column position (starting from 0)
Definition: dict0mem.h:508
the index is complete and ready for access
Definition: dict0mem.h:1273
byte * value
Default value in bytes.
Definition: dict0mem.h:460
Some persistent metadata is now dirty in memory, need to be written back to DDTableBuffer table and(o...
Definition: dict0mem.h:1514
dict_v_col_t * dict_mem_table_add_v_col(dict_table_t *table, mem_heap_t *heap, const char *name, ulint mtype, ulint prtype, ulint len, ulint pos, ulint num_base, bool is_visible)
Adds a virtual column definition to a table.
Definition: dict0mem.cc:91
ib_quiesce_t
Quiescing states for flushing tables to disk.
Definition: dict0types.h:294
#define DICT_TF_BITS
Width of all the currently known table flags.
Definition: dict0mem.h:183
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:349
ulong zip_failure_threshold_pct
Percentage of compression failures that are allowed in a single round.
Definition: dict0dict.cc:177
void write(W *w, const T &t, const char *key, size_t key_sz)
Definition: sdi_impl.h:333
void dict_mem_table_col_rename(dict_table_t *table, ulint nth_col, const char *from, const char *to, bool is_virtual)
Renames a column of a table in the data dictionary cache.
Definition: dict0mem.cc:315
Container of persisters used in the system.
Definition: dict0mem.h:2447
unsigned prtype
precise type; MySQL data type, charset code, flags to indicate nullability, signedness, whether this is a binary string, whether this is a true VARCHAR where MySQL uses 2 bytes to store the length
Definition: dict0mem.h:479
#define DICT_CORRUPT
bit to store the corrupted flag \ in SYS_INDEXES.TYPE
Definition: dict0mem.h:93
Data structure for a column in a table.
Definition: dict0mem.h:469
#define DATA_MBMAXLEN(mbminmaxlen)
Definition: data0type.h:255
Definition: row0mysql.h:490
All persistent metadata are up to date.
Definition: dict0mem.h:1521
Query graph global types.
Full text search header file.
The two-way list base node.
Definition: ut0lst.h:71
SQL identifier name wrapper for pretty-printing.
Definition: dict0mem.h:421
bool is_clustered() const
Definition: dict0mem.h:1089
secondary index creation was aborted and the index should be dropped as soon as index->table->n_ref_c...
Definition: dict0mem.h:1282
Persistent Metadata type for corrupted indexes.
Definition: dict0mem.h:2241
void dict_mem_table_free_foreign_vcol_set(dict_table_t *table)
Free the vcol_set from all foreign key constraint on the table.
Definition: dict0mem.cc:531
unsigned mtype
main data type
Definition: data0type.h:505
void dict_mem_table_fill_foreign_vcol_set(dict_table_t *table)
Fill virtual columns set in each fk constraint present in the table.
Definition: dict0mem.cc:518
#define DICT_INDEX_MAGIC_N
Value of dict_index_t::magic_n.
Definition: dict0mem.h:968
Only used in spatial index.
Definition: dict0types.h:341
#define DICT_MULTI_VALUE
Definition: dict0mem.h:108
Globally unique index identifier.
Definition: dict0types.h:220
#define DATA_MBMAX
Definition: data0type.h:236
The index tree general types.
int page
Definition: ctype-mb.cc:1234
Data dictionary global types.
dict_vcol_set * v_cols
set of virtual columns affected by foreign key constraint.
Definition: dict0mem.h:1332
char * pos
Definition: do_ctype.cc:76
Memory primitives.
unsigned type
index type (DICT_CLUSTERED, DICT_UNIQUE, DICT_IBUF, DICT_CORRUPT)
Definition: dict0mem.h:900
Compare two dict_foreign_t objects using their ids.
Definition: dict0mem.h:1351
UNIV_INLINE ulint dtype_get_max_size_low(ulint mtype, ulint len)
Returns the maximum size of a data type.
#define UT_DELETE(ptr)
Destroy, deallocate and trace the deallocation of an object created by UT_NEW() or UT_NEW_NOKEY()...
Definition: ut0new.h:1022
Table name wrapper for pretty-printing.
Definition: dict0mem.h:450
static std::mutex lock
Definition: net_ns.cc:55
bool is_multi_value() const
Check if a column is a multi-value virtual column.
Definition: dict0mem.h:537
#define mutex_free(M)
Definition: ut0mutex.h:124
byte rec_t
Definition: rem0types.h:39
void for_each(const Shards< COUNT > &shards, Function &&f) noexcept
Iterate over the shards.
Definition: ut0counter.h:322
void dict_table_mutex_create_lazy(dict_table_t *table)
Request for lazy creation of the mutex of a given table.
Definition: dict0mem.h:2509
The destructor will free all the foreign key constraints in the set by calling dict_foreign_free() on...
Definition: dict0mem.h:1425
ib_mutex_t * autoinc_mutex
Mutex protecting the autoincrement counter.
Definition: dict0mem.h:1921
The read-write lock (for threads, not for database transactions)
#define DATA_MULTI_VALUE
Definition: data0type.h:223
#define DICT_CLUSTERED
Type flags of an index: OR&#39;ing of the flags is allowed to define a combination of types...
Definition: dict0mem.h:85
void * hash_node_t
Definition: innodb_config.h:42
dict_foreign_t * dict_mem_foreign_create(void)
Creates and initializes a foreign constraint memory object.
Definition: dict0mem.cc:339
A class that aids executing a given function exactly once in a multi-threaded environment.
A table lock.
Definition: lock0priv.h:51
Row operation global types.
const char innobase_index_reserve_name[]
"GEN_CLUST_INDEX" is the name reserved for InnoDB default system clustered index when there is no pri...
Definition: dict0mem.h:878
Data structure for a field in an index.
Definition: dict0mem.h:725
Instrumented memory allocator.
id_name_t()
Default constructor.
Definition: dict0mem.h:424
#define DICT_TABLE_MAGIC_N
Value of &#39;magic_n&#39;.
Definition: dict0mem.h:2026
void dict_table_autoinc_destroy(dict_table_t *table)
Destroy the autoinc latch of the given table.
Definition: dict0mem.h:2531
struct Parser parser
case opt name
Definition: sslopt-case.h:32
char * id
id of the constraint as a null-terminated string
Definition: dict0mem.h:1302
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:54
unsigned long long Object_id
Definition: object_id.h:30
The biggest type, which should be 1 bigger than the last true type.
Definition: dict0mem.h:2254
UNIV_INLINE ulint dtype_get_fixed_size_low(ulint mtype, ulint prtype, ulint len, ulint mbminmaxlen, ulint comp)
Returns the size of a fixed size data type, 0 if not a fixed size type.
Definition: gis0type.h:151
Utilities for byte operations.
#define DICT_TF2_INTRINSIC
Intrinsic table bit Intrinsic table is table created internally by MySQL modules viz.
Definition: dict0mem.h:279
Transaction system global type definitions.
The smallest type, which should be 1 less than the first true type.
Definition: dict0mem.h:2238
const string version("\ersion\)
dict_col_default_t * instant_default
The following are copied from dtype_t, so that all bit-fields can be packed tightly.
Definition: dict0mem.h:477
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:215
Definition: data0type.h:497
Persistent Metadata type for autoinc counter.
Definition: dict0mem.h:2244
#define DICT_TF2_BITS
Table Flags set number 2.
Definition: dict0mem.h:251
void dict_table_autoinc_create_lazy(dict_table_t *table)
Request for lazy creation of the autoinc latch of a given table.
Definition: dict0mem.h:2549
dict_table_t * referenced_table
table where the referenced key is
Definition: dict0mem.h:1321
Function object to check if a foreign key object is there in the given foreign key set or not...
Definition: dict0mem.h:1387
Definition: plugin_ftparser.h:211
A function object to find a foreign key with the given index as the referenced index.
Definition: dict0mem.h:1359
dict_foreign_set referenced_set
Definition: dict0mem.h:1774
dict_table_t * foreign_table
table where the foreign key is
Definition: dict0mem.h:1315
#define DICT_IT_BITS
number of bits used for \ SYS_INDEXES.TYPE
Definition: dict0mem.h:110
The memory management.
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
Structure defines template related to virtual columns and their base columns.
Definition: dict0mem.h:1474
const string metadata("\etadata\)
#define DATA_VIRTUAL
Definition: data0type.h:222
#define DATA_MBMINMAXLEN(mbminlen, mbmaxlen)
Definition: data0type.h:248
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:66
Persister used for autoinc counters.
Definition: dict0mem.h:2406
Page size descriptor.
Definition: page0size.h:49
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:144
#define UT_LIST_BASE_NODE_T(TYPE)
Definition: innodb_utility.h:47
#define mtr_commit(m)
Commit a mini-transaction.
Definition: mtr0mtr.h:59
Definition: dict0mem.h:1338
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:217
#define DATA_MBMINLEN(mbminmaxlen)
Definition: data0type.h:252
UNIV_INLINE void mem_heap_free(mem_heap_t *heap)
Frees the space occupied by a memory heap.
#define DATA_SYS
Definition: data0type.h:74
ib_mutex_t * autoinc_persisted_mutex
Mutex protecting the persisted autoincrement counter.
Definition: dict0mem.h:1927
void dict_foreign_free(dict_foreign_t *foreign)
Frees a foreign key struct.
Definition: dict0mem.h:1411
Data structure for a virtual column in a table.
Definition: dict0mem.h:649
Cache position of last inserted or selected record by caching record and holding reference to the blo...
Definition: dict0mem.h:840
int n
Definition: xcom_base.cc:442
Data structure for a stored column in a table.
Definition: dict0mem.h:681
void dict_mem_referenced_table_name_lookup_set(dict_foreign_t *foreign, ibool do_alloc)
Sets the referenced_table_name_lookup pointer based on the value of lower_case_table_names.
Definition: dict0mem.cc:386
#define mutex_exit(M)
Definition: ut0mutex.h:122
Persister used for corrupted indexes.
Definition: dict0mem.h:2370
zip_pad_info_t zip_pad
Information about state of compression failures and successes.
Definition: dict0mem.h:1039
Interface for persistent dynamic table metadata.
Definition: dict0mem.h:2326
Random numbers and hashing.
std::list< dict_v_idx_t, ut_allocator< dict_v_idx_t > > dict_v_idx_list
Index list to put in dict_v_col_t.
Definition: dict0mem.h:646
const char * m_name
The name in internal representation.
Definition: dict0mem.h:446
volatile os_once::state_t mutex_created
Creation state of mutex.
Definition: dict0mem.h:1568
table_dirty_status
The dirty status of tables, used to indicate if a table has some dynamic metadata changed to be writt...
Definition: dict0mem.h:1502
mem_heap_t * heap
this object is allocated from this memory heap
Definition: dict0mem.h:1300
#define DATA_ITT_N_SYS_COLS
Definition: data0type.h:190
void dict_mem_init(void)
Initialize dict memory variables.
Definition: dict0mem.cc:772
The state of the FTS sub system.
Definition: fts0fts.h:364
const string value("\alue\)
If key is fixed length key then cache the record offsets on first computation.
Definition: dict0mem.h:802
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:40
const char * operator()() const
Explicit type conversion.
Definition: dict0mem.h:442
Red black tree instance.
Definition: ut0rbt.h:74
std::map< persistent_type_t, Persister *, std::less< persistent_type_t >, ut_allocator< std::pair< const persistent_type_t, Persister * > > > persisters_t
Definition: dict0mem.h:2451
std::set< dict_v_col_t *, std::less< dict_v_col_t * >, ut_allocator< dict_v_col_t * > > dict_vcol_set
Set to store the virtual columns which are affected by Foreign key constraint.
Definition: dict0mem.h:1294
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:156
A function object to add the foreign key constraint to the referenced set of the referenced table...
Definition: dict0mem.h:2495
static int flags[50]
Definition: hp_test1.cc:39
The simple hash table utility.
unsigned char byte
Blob class.
Definition: common.h:159
static const state_t DONE
Finished execution.
Definition: os0once.h:75
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
Definition: dict0mem.h:1372
The database buffer pool high-level routines.
#define DICT_TF2_TEMPORARY
TEMPORARY; TRUE for tables from CREATE TEMPORARY TABLE.
Definition: dict0mem.h:256
bool get_field(MEM_ROOT *mem, Field *field, String *res)
Allocate string field in MEM_ROOT and return it as String.
Definition: table.cc:3530
Data structure for default value of a column in a table.
Definition: dict0mem.h:456
bool is_compressed() const
Check if the underlying table is compressed.
Definition: dict0mem.h:2228
#define DATA_N_SYS_COLS
Definition: data0type.h:188
#define UT_LIST_NODE_T(TYPE)
Definition: innodb_utility.h:40
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
uint64_t uint64
Definition: my_inttypes.h:68
bool is_compressed() const
Check if the table is compressed.
Definition: dict0mem.h:1535
Data structure to hold information about about how much space in an uncompressed page should be left ...
Definition: dict0mem.h:784
void dict_index_zip_pad_unlock(dict_index_t *index)
Release the zip_pad_mutex of a given index.
Definition: dict0mem.h:2579
void dict_mem_table_add_s_col(dict_table_t *table, ulint num_base)
Adds a stored column definition to a table.
Definition: dict0mem.cc:147
void dict_mem_index_free(dict_index_t *index)
Frees an index memory object.
Definition: dict0mem.cc:706
UNIV_INLINE int ut_strcmp(const char *str1, const char *str2)
Wrapper for strcmp(3).
id_name_t & operator=(const char *name)
Assignment operator.
Definition: dict0mem.h:431
Dialog Client Authentication nullptr
Definition: dialog.cc:353
std::vector< index_id_t, ut_allocator< index_id_t > > corrupted_ids_t
Definition: dict0mem.h:2257
the online index creation was aborted, the index was dropped from the data dictionary and the tablesp...
Definition: dict0mem.h:1287
the index is being created, online (allowing concurrent modifications)
Definition: dict0mem.h:1276
spatial_status_t
whether a col is used in spatial index or regular index Note: the spatial status is part of persisten...
Definition: dict0types.h:330
const char * table_name
Definition: rules_table_service.cc:55
online_index_status
The status of online index creation.
Definition: dict0mem.h:1271
Data structure for an index.
Definition: dict0mem.h:886