MySQL  8.0.18
Source Code Documentation
dict0dict.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved.
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/dict0dict.h
29  Data dictionary system
30 
31  Created 1/8/1996 Heikki Tuuri
32  *******************************************************/
33 
34 #ifndef dict0dict_h
35 #define dict0dict_h
36 
37 #include <set>
38 
39 #include <deque>
40 #include "data0data.h"
41 #include "data0type.h"
42 #include "dict/dict.h"
43 #include "dict0mem.h"
44 #include "dict0types.h"
45 #include "fsp0fsp.h"
46 #include "fsp0sysspace.h"
47 #include "hash0hash.h"
48 #include "mem0mem.h"
49 #include "rem0types.h"
50 #include "row0types.h"
51 #include "sql/dd/object_id.h"
52 #include "sync0rw.h"
53 #include "trx0types.h"
54 #include "univ.i"
55 #include "ut0byte.h"
56 #include "ut0mem.h"
57 #include "ut0new.h"
58 #include "ut0rnd.h"
59 
60 #define DICT_HEAP_SIZE \
61  100 /*!< initial memory heap size when \
62  creating a table or index object */
63 
64 /** SDI version. Written on Page 1 & 2 at FIL_PAGE_FILE_FLUSH_LSN offset. */
65 const uint32_t SDI_VERSION = 1;
66 
67 /** Space id of system tablespace */
69 
70 /** Get the database name length in a table name.
71  @return database name length */
72 ulint dict_get_db_name_len(const char *name) /*!< in: table name in the form
73  dbname '/' tablename */
74  MY_ATTRIBUTE((warn_unused_result));
75 #ifndef UNIV_HOTBACKUP
76 /** Open a table from its database and table name, this is currently used by
77  foreign constraint parser to get the referenced table.
78  @return complete table name with database and table name, allocated from
79  heap memory passed in */
81  const char *name, /*!< in: foreign key table name */
82  const char *database_name, /*!< in: table db name */
83  ulint database_name_len, /*!< in: db name length */
84  const char *table_name, /*!< in: table name */
85  ulint table_name_len, /*!< in: table name length */
86  dict_table_t **table, /*!< out: table object or NULL */
87  mem_heap_t *heap); /*!< in: heap memory */
88 /** Frees a foreign key struct. */
90  dict_foreign_t *foreign); /*!< in, own: foreign key struct */
91 /** Finds the highest [number] for foreign key constraints of the table. Looks
92  only at the >= 4.0.18-format id's, which are of the form
93  databasename/tablename_ibfk_[number].
94  @return highest number, 0 if table has no new format foreign key constraints */
96  dict_table_t *table); /*!< in: table in the dictionary
97  memory cache */
98 #endif /* !UNIV_HOTBACKUP */
99 /** Return the end of table name where we have removed dbname and '/'.
100  @return table name */
101 const char *dict_remove_db_name(const char *name) /*!< in: table name in the
102  form dbname '/' tablename */
103  MY_ATTRIBUTE((warn_unused_result));
104 
105 /** Operation to perform when opening a table */
106 enum dict_table_op_t {
107  /** Expect the tablespace to exist. */
109  /** Drop any orphan indexes after an aborted online index creation */
111  /** Silently load the tablespace if it does not exist,
112  and do not load the definitions of incomplete indexes. */
114 };
115 
116 /** Decrements the count of open handles to a table. */
117 void dict_table_close(dict_table_t *table, /*!< in/out: table */
118  ibool dict_locked, /*!< in: TRUE=data dictionary locked */
119  ibool try_drop); /*!< in: TRUE=try to drop any orphan
120  indexes after an aborted online
121  index creation */
122 /** Closes the only open handle to a table and drops a table while assuring
123  that dict_sys->mutex is held the whole time. This assures that the table
124  is not evicted after the close when the count of open handles goes to zero.
125  Because dict_sys->mutex is held, we do not need to call
126  dict_table_prevent_eviction(). */
128  trx_t *trx, /*!< in: data dictionary transaction */
129  dict_table_t *table); /*!< in/out: table */
130 /** Inits the data dictionary module. */
131 void dict_init(void);
132 
133 /** Closes the data dictionary module. */
134 void dict_close(void);
135 
136 /** Inits the structure for persisting dynamic metadata */
137 void dict_persist_init(void);
138 
139 /** Clear the structure */
140 void dict_persist_close(void);
141 
142 #ifndef UNIV_HOTBACKUP
143 /** Write back the dirty persistent dynamic metadata of the table
144 to DDTableBuffer.
145 @param[in,out] table table object */
147 
148 /** Read persistent dynamic metadata stored in a buffer
149 @param[in] buffer buffer to read
150 @param[in] size size of data in buffer
151 @param[in] metadata where we store the metadata from buffer */
152 void dict_table_read_dynamic_metadata(const byte *buffer, ulint size,
154 
155 /** Determine bytes of column prefix to be stored in the undo log. Please
156  note that if !dict_table_has_atomic_blobs(table), no prefix
157  needs to be stored in the undo log.
158  @return bytes of column prefix to be stored in the undo log */
159 UNIV_INLINE
161  dict_table_t *table, /*!< in: table */
162  const dict_col_t *col) /*!< in: column which index prefix
163  is based on */
164  MY_ATTRIBUTE((warn_unused_result));
165 
166 /** Determine maximum bytes of a virtual column need to be stored
167 in the undo log.
168 @param[in] table dict_table_t for the table
169 @param[in] col_no virtual column number
170 @return maximum bytes of virtual column to be stored in the undo log */
171 UNIV_INLINE
172 ulint dict_max_v_field_len_store_undo(dict_table_t *table, ulint col_no);
173 
174 #endif /* !UNIV_HOTBACKUP */
175 /** Gets the column number.
176  @return col->ind, table column position (starting from 0) */
177 UNIV_INLINE
178 ulint dict_col_get_no(const dict_col_t *col) /*!< in: column */
179  MY_ATTRIBUTE((warn_unused_result));
180 /** Gets the column position in the clustered index. */
181 UNIV_INLINE
183  const dict_col_t *col, /*!< in: table column */
184  const dict_index_t *clust_index) /*!< in: clustered index */
185  MY_ATTRIBUTE((warn_unused_result));
186 
187 #ifndef UNIV_HOTBACKUP
188 /** Gets the column position in the given index.
189 @param[in] col table column
190 @param[in] index index to be searched for column
191 @return position of column in the given index. */
192 UNIV_INLINE
193 ulint dict_col_get_index_pos(const dict_col_t *col, const dict_index_t *index)
194  MY_ATTRIBUTE((nonnull, warn_unused_result));
195 
196 /** If the given column name is reserved for InnoDB system columns, return
197  TRUE.
198  @return true if name is reserved */
199 ibool dict_col_name_is_reserved(const char *name) /*!< in: column name */
200  MY_ATTRIBUTE((warn_unused_result));
201 /** Acquire the autoinc lock. */
202 void dict_table_autoinc_lock(dict_table_t *table); /*!< in/out: table */
203 
204 /** Unconditionally set the autoinc counter. */
206  dict_table_t *table, /*!< in/out: table */
207  ib_uint64_t value); /*!< in: next value to assign to a row */
208 /** Reads the next autoinc value (== autoinc counter value), 0 if not yet
209  initialized.
210  @return value for a new row, or 0 */
211 ib_uint64_t dict_table_autoinc_read(const dict_table_t *table) /*!< in: table */
212  MY_ATTRIBUTE((warn_unused_result));
213 /** Updates the autoinc counter if the value supplied is greater than the
214  current value. */
216 
217  dict_table_t *table, /*!< in/out: table */
218  ib_uint64_t value); /*!< in: value which was assigned to a row */
219 /** Release the autoinc lock. */
220 void dict_table_autoinc_unlock(dict_table_t *table); /*!< in/out: table */
221 
222 /** Update the persisted autoinc counter to specified one, we should hold
223 autoinc_persisted_mutex.
224 @param[in,out] table table
225 @param[in] autoinc set autoinc_persisted to this value */
226 UNIV_INLINE
228  ib_uint64_t autoinc);
229 
230 /** Set the column position of autoinc column in clustered index for a table.
231 @param[in] table table
232 @param[in] pos column position in table definition */
233 UNIV_INLINE
235 
236 /** Write redo logs for autoinc counter that is to be inserted, or to
237 update some existing smaller one to bigger.
238 @param[in,out] table InnoDB table object
239 @param[in] value AUTOINC counter to log
240 @param[in,out] mtr mini-transaction */
241 void dict_table_autoinc_log(dict_table_t *table, uint64_t value, mtr_t *mtr);
242 
243 /** Check if a table has an autoinc counter column.
244 @param[in] table table
245 @return true if there is an autoinc column in the table, otherwise false. */
246 UNIV_INLINE
247 bool dict_table_has_autoinc_col(const dict_table_t *table);
248 
249 #endif /* !UNIV_HOTBACKUP */
250 /** Adds system columns to a table object. */
251 void dict_table_add_system_columns(dict_table_t *table, /*!< in/out: table */
252  mem_heap_t *heap); /*!< in: temporary heap */
253 #ifndef UNIV_HOTBACKUP
254 /** Mark if table has big rows.
255 @param[in,out] table table handler */
256 void dict_table_set_big_rows(dict_table_t *table) MY_ATTRIBUTE((nonnull));
257 /** Adds a table object to the dictionary cache.
258 @param[in] table table
259 @param[in] can_be_evicted true if can be evicted
260 @param[in] heap temporary heap
261 */
262 void dict_table_add_to_cache(dict_table_t *table, ibool can_be_evicted,
263  mem_heap_t *heap);
264 
265 /** Removes a table object from the dictionary cache. */
266 void dict_table_remove_from_cache(dict_table_t *table); /*!< in, own: table */
267 
268 /** Try to invalidate an entry from the dict cache, for a partitioned table,
269 if any table found.
270 @param[in] name Table name */
272 
273 #ifdef UNIV_DEBUG
274 /** Removes a table object from the dictionary cache, for debug purpose
275 @param[in,out] table table object
276 @param[in] lru_evict true if table being evicted to make room
277  in the table LRU list */
278 void dict_table_remove_from_cache_debug(dict_table_t *table, bool lru_evict);
279 #endif /* UNIV_DEBUG */
280 
281 /** Renames a table object.
282  @return true if success */
283 dberr_t dict_table_rename_in_cache(dict_table_t *table, /*!< in/out: table */
284  const char *new_name, /*!< in: new name */
285  ibool rename_also_foreigns)
286  /*!< in: in ALTER TABLE we want
287  to preserve the original table name
288  in constraints which reference it */
289  MY_ATTRIBUTE((warn_unused_result));
290 
291 /** Removes an index from the dictionary cache.
292 @param[in,out] table table whose index to remove
293 @param[in,out] index index to remove, this object is destroyed and must not
294 be accessed by the caller afterwards */
296 
297 /** Change the id of a table object in the dictionary cache. This is used in
298  DISCARD TABLESPACE. */
300  dict_table_t *table, /*!< in/out: table object already in cache */
301  table_id_t new_id); /*!< in: new id to set */
302 /** Removes a foreign constraint struct from the dictionary cache. */
304  dict_foreign_t *foreign); /*!< in, own: foreign constraint */
305 /** Adds a foreign key constraint object to the dictionary cache. May free
306  the object if there already is an object with the same identifier in.
307  At least one of foreign table or referenced table must already be in
308  the dictionary cache!
309  @return DB_SUCCESS or error code */
311  /*!< in, own: foreign key constraint */
312  const char **col_names,
313  /*!< in: column names, or NULL to use
314  foreign->foreign_table->col_names */
315  bool check_charsets,
316  /*!< in: whether to check charset
317  compatibility */
318  bool can_free_fk,
319  /*!< in: whether free existing FK */
320  dict_err_ignore_t ignore_err)
321  /*!< in: error to be ignored */
322  MY_ATTRIBUTE((warn_unused_result));
323 /** Checks if a table is referenced by foreign keys.
324  @return true if table is referenced by a foreign key */
326  const dict_table_t *table) /*!< in: InnoDB table */
327  MY_ATTRIBUTE((warn_unused_result));
328 /** Replace the index passed in with another equivalent index in the
329  foreign key lists of the table.
330  @return whether all replacements were found */
332  dict_table_t *table, /*!< in/out: table */
333  const char **col_names,
334  /*!< in: column names, or NULL
335  to use table->col_names */
336  const dict_index_t *index) /*!< in: index to be replaced */
337  MY_ATTRIBUTE((warn_unused_result));
338 /** Scans a table create SQL string and adds to the data dictionary
339 the foreign key constraints declared in the string. This function
340 should be called after the indexes for a table have been created.
341 Each foreign key constraint must be accompanied with indexes in
342 bot participating tables. The indexes are allowed to contain more
343 fields than mentioned in the constraint.
344 
345 @param[in] trx transaction
346 @param[in] sql_string table create statement where
347  foreign keys are declared like:
348  FOREIGN KEY (a, b) REFERENCES table2(c, d),
349  table2 can be written also with the database
350  name before it: test.table2; the default
351  database id the database of parameter name
352 @param[in] sql_length length of sql_string
353 @param[in] name table full name in normalized form
354 @param[in] reject_fks if TRUE, fail with error code
355  DB_CANNOT_ADD_CONSTRAINT if any
356  foreign keys are found.
357 @return error code or DB_SUCCESS */
358 dberr_t dict_create_foreign_constraints(trx_t *trx, const char *sql_string,
359  size_t sql_length, const char *name,
360  ibool reject_fks)
361  MY_ATTRIBUTE((warn_unused_result));
362 /** Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement.
363  @return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the
364  constraint id does not match */
366  mem_heap_t *heap, /*!< in: heap from which we can
367  allocate memory */
368  trx_t *trx, /*!< in: transaction */
369  dict_table_t *table, /*!< in: table */
370  ulint *n, /*!< out: number of constraints
371  to drop */
372  const char ***constraints_to_drop) /*!< out: id's of the
373  constraints to drop */
374  MY_ATTRIBUTE((warn_unused_result));
375 #endif /* !UNIV_HOTBACKUP */
376 /** Returns a table object and increments its open handle count.
377  NOTE! This is a high-level function to be used mainly from outside the
378  'dict' directory. Inside this directory dict_table_get_low
379  is usually the appropriate function.
380  @param[in] table_name Table name
381  @param[in] dict_locked TRUE=data dictionary locked
382  @param[in] try_drop TRUE=try to drop any orphan indexes after
383  an aborted online index creation
384  @param[in] ignore_err error to be ignored when loading the table
385  @return table, NULL if does not exist */
386 dict_table_t *dict_table_open_on_name(const char *table_name, ibool dict_locked,
387  ibool try_drop,
388  dict_err_ignore_t ignore_err)
389  MY_ATTRIBUTE((warn_unused_result));
390 
391 /** Tries to find an index whose first fields are the columns in the array,
392  in the same order and is not marked for deletion and is not the same
393  as types_idx.
394  @return matching index, NULL if not found */
396  const dict_table_t *table, /*!< in: table */
397  const char **col_names,
398  /*!< in: column names, or NULL
399  to use table->col_names */
400  const char **columns, /*!< in: array of column names */
401  ulint n_cols, /*!< in: number of columns */
402  const dict_index_t *types_idx,
403  /*!< in: NULL or an index
404  whose types the column types
405  must match */
406  bool check_charsets,
407  /*!< in: whether to check
408  charsets. only has an effect
409  if types_idx != NULL */
410  ulint check_null)
411  /*!< in: nonzero if none of
412  the columns must be declared
413  NOT NULL */
414  MY_ATTRIBUTE((warn_unused_result));
415 
416 /** Returns a virtual column's name.
417 @param[in] table table object
418 @param[in] col_nr virtual column number(nth virtual column)
419 @return column name. */
420 const char *dict_table_get_v_col_name(const dict_table_t *table, ulint col_nr);
421 
422 /** Check if the table has a given column.
423 @param[in] table table object
424 @param[in] col_name column name
425 @param[in] col_nr column number guessed, 0 as default
426 @return column number if the table has the specified column,
427 otherwise table->n_def */
428 ulint dict_table_has_column(const dict_table_t *table, const char *col_name,
429  ulint col_nr = 0);
430 
431 /** Outputs info on foreign keys of a table. */
433  ibool create_table_format, /*!< in: if TRUE then print in
434  a format suitable to be inserted into
435  a CREATE TABLE, otherwise in the format
436  of SHOW TABLE STATUS */
437  FILE *file, /*!< in: file where to print */
438  trx_t *trx, /*!< in: transaction */
439  dict_table_t *table); /*!< in: table */
440 /** Outputs info on a foreign key of a table in a format suitable for
441  CREATE TABLE. */
443  FILE *file, /*!< in: file where to print */
444  trx_t *trx, /*!< in: transaction */
445  dict_foreign_t *foreign, /*!< in: foreign key constraint */
446  ibool add_newline); /*!< in: whether to add a newline */
447 /** Tries to find an index whose first fields are the columns in the array,
448  in the same order and is not marked for deletion and is not the same
449  as types_idx.
450  @return matching index, NULL if not found */
452  const dict_table_t *table, /*!< in: table */
453  const char **col_names,
454  /*!< in: column names, or NULL
455  to use table->col_names */
456  const char **columns, /*!< in: array of column names */
457  ulint n_cols, /*!< in: number of columns */
458  const dict_index_t *index, /*!< in: index to check */
459  const dict_index_t *types_idx,
460  /*!< in: NULL or an index
461  whose types the column types
462  must match */
463  bool check_charsets,
464  /*!< in: whether to check
465  charsets. only has an effect
466  if types_idx != NULL */
467  ulint check_null)
468  /*!< in: nonzero if none of
469  the columns must be declared
470  NOT NULL */
471  MY_ATTRIBUTE((warn_unused_result));
472 
473 /* Skip corrupted index */
474 #define dict_table_skip_corrupt_index(index) \
475  while (index && index->is_corrupted()) { \
476  index = index->next(); \
477  }
478 
479 /* Get the next non-corrupt index */
480 #define dict_table_next_uncorrupted_index(index) \
481  do { \
482  index = index->next(); \
483  dict_table_skip_corrupt_index(index); \
484  } while (0)
485 
486 /** Check if index is auto-generated clustered index.
487 @param[in] index index
488 
489 @return true if index is auto-generated clustered index. */
490 UNIV_INLINE
492 
493 /** Check whether the index is unique.
494  @return nonzero for unique index, zero for other indexes */
495 UNIV_INLINE
496 ulint dict_index_is_unique(const dict_index_t *index) /*!< in: index */
497  MY_ATTRIBUTE((warn_unused_result));
498 /** Check whether the index is a Spatial Index.
499  @return nonzero for Spatial Index, zero for other indexes */
500 UNIV_INLINE
501 ulint dict_index_is_spatial(const dict_index_t *index) /*!< in: index */
502  MY_ATTRIBUTE((warn_unused_result));
503 /** Check whether the index contains a virtual column.
504 @param[in] index index
505 @return nonzero for index on virtual column, zero for other indexes */
506 UNIV_INLINE
508 /** Check whether the index is the insert buffer tree.
509  @return nonzero for insert buffer, zero for other indexes */
510 UNIV_INLINE
511 ulint dict_index_is_ibuf(const dict_index_t *index) /*!< in: index */
512  MY_ATTRIBUTE((warn_unused_result));
513 
514 /** Check whether the index consists of descending columns only.
515 @param[in] index index tree
516 @retval true if index has any descending column
517 @retval false if index has only ascending columns */
518 UNIV_INLINE
520  MY_ATTRIBUTE((warn_unused_result));
521 /** Check whether the index is a secondary index or the insert buffer tree.
522  @return nonzero for insert buffer, zero for other indexes */
523 UNIV_INLINE
524 ulint dict_index_is_sec_or_ibuf(const dict_index_t *index) /*!< in: index */
525  MY_ATTRIBUTE((warn_unused_result));
526 
527 /** Get all the FTS indexes on a table.
528 @param[in] table table
529 @param[out] indexes all FTS indexes on this table
530 @return number of FTS indexes */
532 
533 UNIV_INLINE
534 ulint dict_table_get_n_tot_u_cols(const dict_table_t *table);
535 
536 /** Gets the number of virtual columns in a table in the dictionary cache.
537 @param[in] table the table to check
538 @return number of virtual columns of a table */
539 UNIV_INLINE
540 ulint dict_table_get_n_v_cols(const dict_table_t *table);
541 
542 /** Check if a table has indexed virtual columns
543 @param[in] table the table to check
544 @return true is the table has indexed virtual columns */
545 UNIV_INLINE
547 
548 /** Gets the approximately estimated number of rows in the table.
549  @return estimated number of rows */
550 UNIV_INLINE
551 ib_uint64_t dict_table_get_n_rows(const dict_table_t *table) /*!< in: table */
552  MY_ATTRIBUTE((warn_unused_result));
553 /** Increment the number of rows in the table by one.
554  Notice that this operation is not protected by any latch, the number is
555  approximate. */
556 UNIV_INLINE
557 void dict_table_n_rows_inc(dict_table_t *table); /*!< in/out: table */
558 /** Decrement the number of rows in the table by one.
559  Notice that this operation is not protected by any latch, the number is
560  approximate. */
561 UNIV_INLINE
562 void dict_table_n_rows_dec(dict_table_t *table); /*!< in/out: table */
563 
564 /** Get nth virtual column
565 @param[in] table target table
566 @param[in] col_nr column number in MySQL Table definition
567 @return dict_v_col_t ptr */
569  ulint col_nr);
570 
571 #ifdef UNIV_DEBUG
572 /** Gets the nth virtual column of a table.
573 @param[in] table table
574 @param[in] pos position of virtual column
575 @return pointer to virtual column object */
576 UNIV_INLINE
578 
579 #else /* UNIV_DEBUG */
580 /* Get nth virtual columns */
581 #define dict_table_get_nth_v_col(table, pos) ((table)->v_cols + (pos))
582 #endif /* UNIV_DEBUG */
583 /** Gets the given system column number of a table.
584  @return column number */
585 UNIV_INLINE
586 ulint dict_table_get_sys_col_no(const dict_table_t *table, /*!< in: table */
587  ulint sys) /*!< in: DATA_ROW_ID, ... */
588  MY_ATTRIBUTE((warn_unused_result));
589 /** Check whether the table uses the compact page format.
590  @return true if table uses the compact page format */
591 UNIV_INLINE
592 ibool dict_table_is_comp(const dict_table_t *table) /*!< in: table */
593  MY_ATTRIBUTE((warn_unused_result));
594 
595 /** Determine if a table uses atomic BLOBs (no locally stored prefix).
596 @param[in] table InnoDB table
597 @return whether BLOBs are atomic */
598 UNIV_INLINE
599 bool dict_table_has_atomic_blobs(const dict_table_t *table)
600  MY_ATTRIBUTE((warn_unused_result));
601 
602 #ifndef UNIV_HOTBACKUP
603 /** Set the various values in a dict_table_t::flags pointer.
604 @param[in,out] flags Pointer to a 4 byte Table Flags
605 @param[in] format File Format
606 @param[in] zip_ssize Zip Shift Size
607 @param[in] use_data_dir Table uses DATA DIRECTORY
608 @param[in] shared_space Table uses a General Shared Tablespace */
609 UNIV_INLINE
610 void dict_tf_set(uint32_t *flags, rec_format_t format, ulint zip_ssize,
611  bool use_data_dir, bool shared_space);
612 
613 /** Initialize a dict_table_t::flags pointer.
614 @param[in] compact Table uses Compact or greater
615 @param[in] zip_ssize Zip Shift Size (log 2 minus 9)
616 @param[in] atomic_blobs Table uses Compressed or Dynamic
617 @param[in] data_dir Table uses DATA DIRECTORY
618 @param[in] shared_space Table uses a General Shared Tablespace */
619 UNIV_INLINE
620 uint32_t dict_tf_init(bool compact, ulint zip_ssize, bool atomic_blobs,
621  bool data_dir, bool shared_space);
622 
623 /** Convert a 32 bit integer table flags to the 32 bit FSP Flags.
624 Fsp Flags are written into the tablespace header at the offset
625 FSP_SPACE_FLAGS and are also stored in the fil_space_t::flags field.
626 The following chart shows the translation of the low order bit.
627 Other bits are the same.
628 ========================= Low order bit ==========================
629  | REDUNDANT | COMPACT | COMPRESSED | DYNAMIC
630 dict_table_t::flags | 0 | 1 | 1 | 1
631 fil_space_t::flags | 0 | 0 | 1 | 1
632 ==================================================================
633 @param[in] table_flags dict_table_t::flags
634 @return tablespace flags (fil_space_t::flags) */
635 uint32_t dict_tf_to_fsp_flags(uint32_t table_flags) MY_ATTRIBUTE((const));
636 
637 /** Extract the page size from table flags.
638 @param[in] flags flags
639 @return compressed page size, or 0 if not compressed */
640 UNIV_INLINE
641 const page_size_t dict_tf_get_page_size(uint32_t flags) MY_ATTRIBUTE((const));
642 #endif /* !UNIV_HOTBACKUP */
643 
644 /** Determine the extent size (in pages) for the given table
645 @param[in] table the table whose extent size is being
646  calculated.
647 @return extent size in pages (256, 128 or 64) */
649 
650 /** Get the table page size.
651 @param[in] table table
652 @return compressed page size, or 0 if not compressed */
653 UNIV_INLINE
655  MY_ATTRIBUTE((warn_unused_result));
656 
657 #ifndef UNIV_HOTBACKUP
658 /** Obtain exclusive locks on all index trees of the table. This is to prevent
659  accessing index trees while InnoDB is updating internal metadata for
660  operations such as FLUSH TABLES. */
661 UNIV_INLINE
662 void dict_table_x_lock_indexes(dict_table_t *table); /*!< in: table */
663 /** Release the exclusive locks on all index tree. */
664 UNIV_INLINE
665 void dict_table_x_unlock_indexes(dict_table_t *table); /*!< in: table */
666 #endif /* !UNIV_HOTBACKUP */
667 /** Checks if a column is in the ordering columns of the clustered index of a
668  table. Column prefixes are treated like whole columns.
669  @return true if the column, or its prefix, is in the clustered key */
671  const dict_table_t *table, /*!< in: table */
672  ulint n) /*!< in: column number */
673  MY_ATTRIBUTE((warn_unused_result));
674 /** Check if the table has an FTS index.
675  @return true if table has an FTS index */
676 UNIV_INLINE
677 ibool dict_table_has_fts_index(dict_table_t *table) /*!< in: table */
678  MY_ATTRIBUTE((warn_unused_result));
679 /** Copies types of virtual columns contained in table to tuple and sets all
680 fields of the tuple to the SQL NULL value. This function should
681 be called right after dtuple_create().
682 @param[in,out] tuple data tuple
683 @param[in] table table */
684 void dict_table_copy_v_types(dtuple_t *tuple, const dict_table_t *table);
685 /** Copies types of columns contained in table to tuple and sets all
686  fields of the tuple to the SQL NULL value. This function should
687  be called right after dtuple_create(). */
688 void dict_table_copy_types(dtuple_t *tuple, /*!< in/out: data tuple */
689  const dict_table_t *table); /*!< in: table */
690 #ifndef UNIV_HOTBACKUP
691 /********************************************************************
692 Wait until all the background threads of the given table have exited, i.e.,
693 bg_threads == 0. Note: bg_threads_mutex must be reserved when
694 calling this. */
696  dict_table_t *table, /* in: table */
697  ulint delay); /* in: time in microseconds to wait between
698  checks of bg_threads. */
699 /** Look up an index.
700 @param[in] id index identifier
701 @return index or NULL if not found */
702 const dict_index_t *dict_index_find(const index_id_t &id)
703  MY_ATTRIBUTE((warn_unused_result));
704 /** Make room in the table cache by evicting an unused table. The unused table
705  should not be part of FK relationship and currently not used in any user
706  transaction. There is no guarantee that it will remove a table.
707  @return number of tables evicted. */
709  ulint max_tables, /*!< in: max tables allowed in cache */
710  ulint pct_check); /*!< in: max percent to check */
711 
712 #define BIG_ROW_SIZE 1024
714 /** Adds an index to the dictionary cache.
715 @param[in] table table on which the index is
716 @param[in] index index; NOTE! The index memory
717  object is freed in this function!
718 @param[in] page_no root page number of the index
719 @param[in] strict TRUE=refuse to create the index
720  if records could be too big to fit in
721  an B-tree page
722 @return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
724  dict_table_t *table, /*!< in: table on which the index is */
725  dict_index_t *index, /*!< in, own: index; NOTE! The index memory
726  object is freed in this function! */
727  page_no_t page_no, /*!< in: root page number of the index */
728  ibool strict) /*!< in: TRUE=refuse to create the index
729  if records could be too big to fit in
730  an B-tree page */
731  MY_ATTRIBUTE((warn_unused_result));
732 
733 /** Clears the virtual column's index list before index is being freed.
734 @param[in] index Index being freed */
736 
737 /** Adds an index to the dictionary cache, with possible indexing newly
738 added column.
739 @param[in] table table on which the index is
740 @param[in] index index; NOTE! The index memory
741  object is freed in this function!
742 @param[in] add_v new virtual column that being added along with
743  an add index call
744 @param[in] page_no root page number of the index
745 @param[in] strict TRUE=refuse to create the index
746  if records could be too big to fit in
747  an B-tree page
748 @return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
750  const dict_add_v_col_t *add_v,
751  page_no_t page_no, ibool strict)
752  MY_ATTRIBUTE((warn_unused_result));
753 #endif /* !UNIV_HOTBACKUP */
754 /** Gets the number of fields in the internal representation of an index,
755  including fields added by the dictionary system.
756  @return number of fields */
757 UNIV_INLINE
759  const dict_index_t *index) /*!< in: an internal
760  representation of index (in
761  the dictionary cache) */
762  MY_ATTRIBUTE((warn_unused_result));
763 /** Gets the number of fields in the internal representation of an index
764  that uniquely determine the position of an index entry in the index, if
765  we do not take multiversioning into account: in the B-tree use the value
766  returned by dict_index_get_n_unique_in_tree.
767  @return number of fields */
768 UNIV_INLINE
770  const dict_index_t *index) /*!< in: an internal representation
771  of index (in the dictionary cache) */
772  MY_ATTRIBUTE((warn_unused_result));
773 /** Gets the number of fields in the internal representation of an index
774  which uniquely determine the position of an index entry in the index, if
775  we also take multiversioning into account.
776  @return number of fields */
777 UNIV_INLINE
779  const dict_index_t *index) /*!< in: an internal representation
780  of index (in the dictionary cache) */
781  MY_ATTRIBUTE((warn_unused_result));
782 
783 /** The number of fields in the nonleaf page of spatial index, except
784 the page no field. */
785 #define DICT_INDEX_SPATIAL_NODEPTR_SIZE 1
786 /**
787 Gets the number of fields on nonleaf page level in the internal representation
788 of an index which uniquely determine the position of an index entry in the
789 index, if we also take multiversioning into account. Note, it doesn't
790 include page no field.
791 @param[in] index index
792 @return number of fields */
793 UNIV_INLINE
795  MY_ATTRIBUTE((warn_unused_result));
796 /** Gets the number of user-defined ordering fields in the index. In the
797  internal representation we add the row id to the ordering fields to make all
798  indexes unique, but this function returns the number of fields the user defined
799  in the index as ordering fields.
800  @return number of fields */
801 UNIV_INLINE
803  const dict_index_t *index) /*!< in: an internal representation
804  of index (in the dictionary cache) */
805  MY_ATTRIBUTE((warn_unused_result));
806 /** Returns TRUE if the index contains a column or a prefix of that column.
807  @return true if contains the column or its prefix */
809  const dict_index_t *index, /*!< in: index */
810  ulint n, /*!< in: column number */
811  bool is_virtual)
812  /*!< in: whether it is a virtual col */
813  MY_ATTRIBUTE((warn_unused_result));
814 /** Looks for a matching field in an index. The column has to be the same. The
815  column in index must be complete, or must contain a prefix longer than the
816  column in index2. That is, we must be able to construct the prefix in index2
817  from the prefix in index.
818  @return position in internal representation of the index;
819  ULINT_UNDEFINED if not contained */
821  const dict_index_t *index, /*!< in: index from which to search */
822  const dict_index_t *index2, /*!< in: index */
823  ulint n) /*!< in: field number in index2 */
824  MY_ATTRIBUTE((warn_unused_result));
825 /** Looks for non-virtual column n position in the clustered index.
826  @return position in internal representation of the clustered index */
827 ulint dict_table_get_nth_col_pos(const dict_table_t *table, /*!< in: table */
828  ulint n) /*!< in: column number */
829  MY_ATTRIBUTE((warn_unused_result));
830 
831 /** Get the innodb column position for a non-virtual column according to
832 its original MySQL table position n
833 @param[in] table table
834 @param[in] n MySQL column position
835 @return column position in InnoDB */
836 ulint dict_table_mysql_pos_to_innodb(const dict_table_t *table, ulint n);
837 
838 /** Copies types of fields contained in index to tuple. */
839 void dict_index_copy_types(dtuple_t *tuple, /*!< in/out: data tuple */
840  const dict_index_t *index, /*!< in: index */
841  ulint n_fields); /*!< in: number of
842  field types to copy */
843 #ifdef UNIV_DEBUG
844 /** Checks that a tuple has n_fields_cmp value in a sensible range, so that
845  no comparison can occur with the page number field in a node pointer.
846  @return true if ok */
848  const dict_index_t *index, /*!< in: index tree */
849  const dtuple_t *tuple) /*!< in: tuple used in a search */
850  MY_ATTRIBUTE((warn_unused_result));
851 /** Whether and when to allow temporary index names */
852 enum check_name {
853  /** Require all indexes to be complete. */
855  /** Allow aborted online index creation. */
857  /** Allow partial indexes to exist. */
859 };
860 /** Check for duplicate index entries in a table [using the index name] */
862  const dict_table_t *table, /*!< in: Check for dup indexes
863  in this table */
864  enum check_name check); /*!< in: whether and when to allow
865  temporary index names */
866 /** Check if a table is a temporary table with compressed row format,
867 we should always expect false.
868 @param[in] table table
869 @return true if it's a compressed temporary table, false otherwise */
870 inline bool dict_table_is_compressed_temporary(const dict_table_t *table);
871 #endif /* UNIV_DEBUG */
872 /** Builds a node pointer out of a physical record and a page number.
873  @return own: node pointer */
874 dtuple_t *dict_index_build_node_ptr(const dict_index_t *index, /*!< in: index */
875  const rec_t *rec, /*!< in: record for which
876  to build node pointer */
877  page_no_t page_no, /*!< in: page number to
878  put in node pointer */
879  mem_heap_t *heap, /*!< in: memory heap where
880  pointer created */
881  ulint level) /*!< in: level of rec in tree:
882  0 means leaf level */
883  MY_ATTRIBUTE((warn_unused_result));
884 /** Copies an initial segment of a physical record, long enough to specify an
885  index entry uniquely.
886  @return pointer to the prefix record */
888  const dict_index_t *index, /*!< in: index */
889  const rec_t *rec, /*!< in: record for which to
890  copy prefix */
891  ulint *n_fields, /*!< out: number of fields copied */
892  byte **buf, /*!< in/out: memory buffer for the
893  copied prefix, or NULL */
894  size_t *buf_size) /*!< in/out: buffer size */
895  MY_ATTRIBUTE((warn_unused_result));
896 /** Builds a typed data tuple out of a physical record.
897  @return own: data tuple */
899  dict_index_t *index, /*!< in: index */
900  rec_t *rec, /*!< in: record for which to build data tuple */
901  ulint n_fields, /*!< in: number of data fields */
902  mem_heap_t *heap) /*!< in: memory heap where tuple created */
903  MY_ATTRIBUTE((warn_unused_result));
904 /** Gets the space id of the root of the index tree.
905  @return space id */
906 UNIV_INLINE
907 space_id_t dict_index_get_space(const dict_index_t *index) /*!< in: index */
908  MY_ATTRIBUTE((warn_unused_result));
909 
910 /** Sets the space id of the root of the index tree.
911 @param[in,out] index index
912 @param[in] space space id */
913 UNIV_INLINE
915 
916 /** Gets the page number of the root of the index tree.
917  @return page number */
918 UNIV_INLINE
919 page_no_t dict_index_get_page(const dict_index_t *tree) /*!< in: index */
920  MY_ATTRIBUTE((warn_unused_result));
921 /** Gets the read-write lock of the index tree.
922  @return read-write lock */
923 UNIV_INLINE
924 rw_lock_t *dict_index_get_lock(dict_index_t *index) /*!< in: index */
925  MY_ATTRIBUTE((warn_unused_result));
926 /** Returns free space reserved for future updates of records. This is
927  relevant only in the case of many consecutive inserts, as updates
928  which make the records bigger might fragment the index.
929  @return number of free bytes on page, reserved for updates */
930 UNIV_INLINE
931 ulint dict_index_get_space_reserve(void);
932 
933 /* Online index creation @{ */
934 /** Gets the status of online index creation.
935  @return the status */
936 UNIV_INLINE
938  const dict_index_t *index) /*!< in: secondary index */
939  MY_ATTRIBUTE((warn_unused_result));
940 
941 /** Sets the status of online index creation.
942 @param[in,out] index index
943 @param[in] status status */
944 UNIV_INLINE
947 
948 /** Determines if a secondary index is being or has been created online,
949  or if the table is being rebuilt online, allowing concurrent modifications
950  to the table.
951  @retval true if the index is being or has been built online, or
952  if this is a clustered index and the table is being or has been rebuilt online
953  @retval false if the index has been created or the table has been
954  rebuilt completely */
955 UNIV_INLINE
956 bool dict_index_is_online_ddl(const dict_index_t *index) /*!< in: index */
957  MY_ATTRIBUTE((warn_unused_result));
958 /** Calculates the minimum record length in an index. */
959 ulint dict_index_calc_min_rec_len(const dict_index_t *index) /*!< in: index */
960  MY_ATTRIBUTE((warn_unused_result));
961 /** Reserves the dictionary system mutex for MySQL. */
962 void dict_mutex_enter_for_mysql(void);
963 /** Releases the dictionary system mutex for MySQL. */
964 void dict_mutex_exit_for_mysql(void);
965 
966 #ifndef UNIV_HOTBACKUP
967 /** Create a dict_table_t's stats latch or delay for lazy creation.
968 This function is only called from either single threaded environment
969 or from a thread that has not shared the table object with other threads.
970 @param[in,out] table table whose stats latch to create
971 @param[in] enabled if false then the latch is disabled
972 and dict_table_stats_lock()/unlock() become noop on this table. */
973 void dict_table_stats_latch_create(dict_table_t *table, bool enabled);
974 
975 /** Destroy a dict_table_t's stats latch.
976 This function is only called from either single threaded environment
977 or from a thread that has not shared the table object with other threads.
978 @param[in,out] table table whose stats latch to destroy */
980 
981 /** Lock the appropriate latch to protect a given table's statistics.
982 @param[in] table table whose stats to lock
983 @param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
984 void dict_table_stats_lock(dict_table_t *table, ulint latch_mode);
985 
986 /** Unlock the latch that has been locked by dict_table_stats_lock().
987 @param[in] table table whose stats to unlock
988 @param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
989 void dict_table_stats_unlock(dict_table_t *table, ulint latch_mode);
990 
991 /** Checks if the database name in two table names is the same.
992  @return true if same db name */
993 ibool dict_tables_have_same_db(const char *name1, /*!< in: table name in the
994  form dbname '/' tablename */
995  const char *name2) /*!< in: table name in the
996  form dbname '/' tablename */
997  MY_ATTRIBUTE((warn_unused_result));
998 /** Get an index by name.
999 @param[in] table the table where to look for the index
1000 @param[in] name the index name to look for
1001 @param[in] committed true=search for committed,
1002 false=search for uncommitted
1003 @return index, NULL if does not exist */
1005  const char *name,
1006  bool committed = true)
1007  MY_ATTRIBUTE((warn_unused_result));
1008 /** Get an index by name.
1009 @param[in] table the table where to look for the index
1010 @param[in] name the index name to look for
1011 @param[in] committed true=search for committed,
1012 false=search for uncommitted
1013 @return index, NULL if does not exist */
1015  const dict_table_t *table, const char *name, bool committed = true) {
1016  return (dict_table_get_index_on_name(const_cast<dict_table_t *>(table), name,
1017  committed));
1018 }
1019 
1020 /***************************************************************
1021 Check whether a column exists in an FTS index. */
1022 UNIV_INLINE
1024  /*!< out: ULINT_UNDEFINED if no match else
1025  the offset within the vector */
1026  ib_vector_t *indexes, /*!< in: vector containing only FTS indexes */
1027  ulint col_no, /*!< in: col number to search for */
1028  bool is_virtual) /*!< in: whether it is a virtual column */
1029  MY_ATTRIBUTE((warn_unused_result));
1030 /** Prevent table eviction by moving a table to the non-LRU list from the
1031  LRU list if it is not already there. */
1032 UNIV_INLINE
1034  dict_table_t *table); /*!< in: table to prevent eviction */
1035 
1036 /** Allow the table to be evicted by moving a table to the LRU list from
1037 the non-LRU list if it is not already there.
1038 @param[in] table InnoDB table object can be evicted */
1039 UNIV_INLINE
1041 
1042 /** Move this table to non-LRU list for DDL operations if it's
1043 currently not there. This also prevents later opening table via DD objects,
1044 when the table name in InnoDB doesn't match with DD object.
1045 @param[in,out] table Table to put in non-LRU list */
1046 UNIV_INLINE
1048 
1049 /** Move this table to LRU list after DDL operations if it was moved
1050 to non-LRU list
1051 @param[in,out] table Table to put in LRU list */
1052 UNIV_INLINE
1054 
1055 /** Move a table to the non LRU end of the LRU list. */
1057  dict_table_t *table); /*!< in: table to move from LRU to non-LRU */
1058 
1059 /** Move a table to the LRU end from the non LRU list.
1060 @param[in] table InnoDB table object */
1062 
1063 /** Move to the most recently used segment of the LRU list. */
1064 void dict_move_to_mru(dict_table_t *table); /*!< in: table to move to MRU */
1065 
1066 /** Maximum number of columns in a foreign key constraint. Please Note MySQL
1067 has a much lower limit on the number of columns allowed in a foreign key
1068 constraint */
1069 #define MAX_NUM_FK_COLUMNS 500
1071 /* Buffers for storing detailed information about the latest foreign key
1072 and unique key errors */
1073 extern FILE *dict_foreign_err_file;
1074 extern ib_mutex_t dict_foreign_err_mutex; /* mutex protecting the
1075  foreign key error messages */
1076 #endif /* !UNIV_HOTBACKUP */
1077 
1078 /** the dictionary system */
1079 extern dict_sys_t *dict_sys;
1080 #ifndef UNIV_HOTBACKUP
1081 /** the data dictionary rw-latch protecting dict_sys */
1083 
1084 /** Forward declaration */
1085 class DDTableBuffer;
1086 #endif /* !UNIV_HOTBACKUP */
1087 struct dict_persist_t;
1088 
1089 /** the dictionary persisting structure */
1091 
1092 /* Dictionary system struct */
1093 struct dict_sys_t {
1094 #ifndef UNIV_HOTBACKUP
1095  DictSysMutex mutex; /*!< mutex protecting the data
1096  dictionary; protects also the
1097  disk-based dictionary system tables;
1098  this mutex serializes CREATE TABLE
1099  and DROP TABLE, as well as reading
1100  the dictionary data for a table from
1101  system tables */
1102 #endif /* !UNIV_HOTBACKUP */
1103  row_id_t row_id; /*!< the next row id to assign;
1104  NOTE that at a checkpoint this
1105  must be written to the dict system
1106  header and flushed to a file; in
1107  recovery this must be derived from
1108  the log records */
1109  hash_table_t *table_hash; /*!< hash table of the tables, based
1110  on name */
1111  hash_table_t *table_id_hash; /*!< hash table of the tables, based
1112  on id */
1113  lint size; /*!< varying space in bytes occupied
1114  by the data dictionary table and
1115  index objects */
1116  /** Handler to sys_* tables, they're only for upgrade */
1117  dict_table_t *sys_tables; /*!< SYS_TABLES table */
1118  dict_table_t *sys_columns; /*!< SYS_COLUMNS table */
1119  dict_table_t *sys_indexes; /*!< SYS_INDEXES table */
1120  dict_table_t *sys_fields; /*!< SYS_FIELDS table */
1121  dict_table_t *sys_virtual; /*!< SYS_VIRTUAL table */
1123  /** Permanent handle to mysql.innodb_table_stats */
1125  /** Permanent handle to mysql.innodb_index_stats */
1127  /** Permanent handle to mysql.innodb_ddl_log */
1129  /** Permanent handle to mysql.innodb_dynamic_metadata */
1133  table_LRU; /*!< List of tables that can be evicted
1134  from the cache */
1136  table_non_LRU; /*!< List of tables that can't be
1137  evicted from the cache */
1138 
1139  /** Iterate each table.
1140  @tparam Functor visitor
1141  @param[in,out] functor to be invoked on each table */
1142  template <typename Functor>
1143  void for_each_table(Functor &functor) {
1145 
1147 
1148  for (ulint i = 0; i < hash->n_cells; i++) {
1149  for (dict_table_t *table =
1150  static_cast<dict_table_t *>(HASH_GET_FIRST(hash, i));
1151  table;
1152  table = static_cast<dict_table_t *>(HASH_GET_NEXT(id_hash, table))) {
1153  functor(table);
1154  }
1155  }
1156 
1157  mutex_exit(&mutex);
1158  }
1159 
1160  /** Check if a tablespace id is a reserved one
1161  @param[in] space tablespace id to check
1162  @return true if a reserved tablespace id, otherwise false */
1163  static bool is_reserved(space_id_t space) {
1165  fsp_is_session_temporary(space));
1166  }
1167 
1168  /** Set of ids of DD tables */
1169  static std::set<dd::Object_id> s_dd_table_ids;
1171  /** Check if a table is hardcoded. it only includes the dd tables
1172  @param[in] id table ID
1173  @retval true if the table is a persistent hard-coded table
1174  (dict_table_t::is_temporary() will not hold)
1175  @retval false if the table is not hard-coded
1176  (it can be persistent or temporary) */
1177  static bool is_dd_table_id(table_id_t id) {
1178  return (s_dd_table_ids.find(id) != s_dd_table_ids.end());
1179  }
1180 
1181  /** The first ID of the redo log pseudo-tablespace */
1182  static constexpr space_id_t s_log_space_first_id = 0xFFFFFFF0UL;
1184  /** Use maximum UINT value to indicate invalid space ID. */
1185  static constexpr space_id_t s_invalid_space_id = 0xFFFFFFFF;
1187  /** The data dictionary tablespace ID. */
1188  static constexpr space_id_t s_space_id = 0xFFFFFFFE;
1190  /** The innodb_temporary tablespace ID. */
1191  static constexpr space_id_t s_temp_space_id = 0xFFFFFFFD;
1193  /** The number of space IDs dedicated to each undo tablespace */
1194  static constexpr space_id_t undo_space_id_range = 512;
1196  /** The lowest undo tablespace ID. */
1197  static constexpr space_id_t s_min_undo_space_id =
1199 
1200  /** The highest undo tablespace ID. */
1201  static constexpr space_id_t s_max_undo_space_id = s_log_space_first_id - 1;
1203  /** The first reserved tablespace ID */
1206  /** Leave 1K space_ids and start space_ids for temporary
1207  general tablespaces (total 400K space_ids)*/
1208  static constexpr space_id_t s_max_temp_space_id = s_reserved_space_id - 1000;
1210  /** Lowest temporary general space id */
1211  static constexpr space_id_t s_min_temp_space_id =
1212  s_reserved_space_id - 1000 - 400000;
1213 
1214  /** The dd::Tablespace::id of the dictionary tablespace. */
1215  static constexpr dd::Object_id s_dd_space_id = 1;
1217  /** The dd::Tablespace::id of innodb_system. */
1218  static constexpr dd::Object_id s_dd_sys_space_id = 2;
1220  /** The dd::Tablespace::id of innodb_temporary. */
1221  static constexpr dd::Object_id s_dd_temp_space_id = 3;
1223  /** The name of the data dictionary tablespace. */
1224  static const char *s_dd_space_name;
1226  /** The file name of the data dictionary tablespace. */
1227  static const char *s_dd_space_file_name;
1229  /** The name of the hard-coded system tablespace. */
1230  static const char *s_sys_space_name;
1232  /** The name of the predefined temporary tablespace. */
1233  static const char *s_temp_space_name;
1235  /** The file name of the predefined temporary tablespace. */
1236  static const char *s_temp_space_file_name;
1238  /** The hard-coded tablespace name innodb_file_per_table. */
1239  static const char *s_file_per_table_name;
1241  /** These two undo tablespaces cannot be dropped. */
1242  static const char *s_default_undo_space_name_1;
1243  static const char *s_default_undo_space_name_2;
1245  /** The table ID of mysql.innodb_dynamic_metadata */
1246  static constexpr table_id_t s_dynamic_meta_table_id = 2;
1248  /** The clustered index ID of mysql.innodb_dynamic_metadata */
1249  static constexpr space_index_t s_dynamic_meta_index_id = 2;
1250 };
1251 
1252 /** Structure for persisting dynamic metadata of data dictionary */
1253 struct dict_persist_t {
1254  /** Mutex to protect data in this structure, also the
1255  dict_table_t::dirty_status and
1256  dict_table_t::in_dirty_dict_tables_list
1257  This mutex should be low-level one so that it can be used widely
1258  when necessary, so its level had to be above SYNC_LOG. However,
1259  after this mutex, persister may have to access B-tree and require
1260  tree latch, the latch level of this mutex then has to be right
1261  before the SYNC_INDEX_TREE. */
1262  ib_mutex_t mutex;
1264  /** List of tables whose dirty_status are marked as METADATA_DIRTY,
1265  or METADATA_BUFFERED. It's protected by the mutex */
1269  /** Number of the tables which are of status METADATA_DIRTY.
1270  It's protected by the mutex */
1271  std::atomic<uint32_t> num_dirty_tables;
1273 #ifndef UNIV_HOTBACKUP
1274  /** DDTableBuffer table for persistent dynamic metadata */
1276 #endif /* !UNIV_HOTBACKUP */
1277 
1278  /** Collection of instances to persist dynamic metadata */
1280 };
1281 
1282 #ifndef UNIV_HOTBACKUP
1283 /** dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records */
1285 
1286 /** Inits dict_ind_redundant. */
1287 void dict_ind_init(void);
1288 
1289 /** Converts a database and table name from filesystem encoding (e.g.
1290 "@code d@i1b/a@q1b@1Kc @endcode", same format as used in dict_table_t::name)
1291 in two strings in UTF8 encoding (e.g. dцb and aюbØc). The output buffers must
1292 be at least MAX_DB_UTF8_LEN and MAX_TABLE_UTF8_LEN bytes.
1293 @param[in] db_and_table database and table names,
1294  e.g. "@code d@i1b/a@q1b@1Kc @endcode"
1295 @param[out] db_utf8 database name, e.g. dцb
1296 @param[in] db_utf8_size dbname_utf8 size
1297 @param[out] table_utf8 table name, e.g. aюbØc
1298 @param[in] table_utf8_size table_utf8 size */
1299 void dict_fs2utf8(const char *db_and_table, char *db_utf8, size_t db_utf8_size,
1300  char *table_utf8, size_t table_utf8_size);
1301 
1302 /** Resize the hash tables besed on the current buffer pool size. */
1303 void dict_resize();
1304 
1305 /** Wrapper for the mysql.innodb_dynamic_metadata used to buffer the persistent
1306 dynamic metadata.
1307 This should be a table with only clustered index, no delete-marked records,
1308 no locking, no undo logging, no purge, no adaptive hash index.
1309 We should always use low level btr functions to access and modify the table.
1310 Accessing this table should be protected by dict_sys->mutex */
1311 class DDTableBuffer {
1312  public:
1313  /** Default constructor */
1314  DDTableBuffer();
1315 
1316  /** Destructor */
1317  ~DDTableBuffer();
1318 
1319  /** Replace the dynamic metadata for a specific table
1320  @param[in] id table id
1321  @param[in] version table dynamic metadata version
1322  @param[in] metadata the metadata we want to replace
1323  @param[in] len the metadata length
1324  @return DB_SUCCESS or error code */
1325  dberr_t replace(table_id_t id, uint64_t version, const byte *metadata,
1326  size_t len);
1327 
1328  /** Remove the whole row for a specific table
1329  @param[in] id table id
1330  @return DB_SUCCESS or error code */
1331  dberr_t remove(table_id_t id);
1332 
1333  /** Truncate the table. We can call it after all the dynamic
1334  metadata has been written back to DD table */
1335  void truncate(void);
1336 
1337  /** Get the buffered metadata for a specific table, the caller
1338  has to delete the returned std::string object by UT_DELETE
1339  @param[in] id table id
1340  @param[out] version table dynamic metadata version
1341  @return the metadata saved in a string object, if nothing, the
1342  string would be of length 0 */
1343  std::string *get(table_id_t id, uint64 *version);
1344 
1345  private:
1346  /** Initialize m_index, the in-memory clustered index of the table
1347  and two tuples used in this class */
1348  void init();
1349 
1350  /** Open the mysql.innodb_dynamic_metadata when DD is not fully up */
1351  void open();
1352 
1353  /** Create the search and replace tuples */
1354  void create_tuples();
1355 
1356  /** Initialize the id field of tuple
1357  @param[out] tuple the tuple to be initialized
1358  @param[in] id table id */
1359  void init_tuple_with_id(dtuple_t *tuple, table_id_t id);
1360 
1361  /** Free the things initialized in init() */
1362  void close();
1363 
1364  /** Prepare for a update on METADATA field
1365  @param[in] entry clustered index entry to replace rec
1366  @param[in] rec clustered index record
1367  @return update vector of differing fields without system columns,
1368  or NULL if there isn't any different field */
1369  upd_t *update_set_metadata(const dtuple_t *entry, const rec_t *rec);
1370 
1371  private:
1372  /** The clustered index of this system table */
1375  /** The heap used for dynamic allocations, which should always
1376  be freed before return */
1379  /** The heap used during replace() operation, which should always
1380  be freed before return */
1383  /** The heap used to create the search tuple and replace tuple */
1384  mem_heap_t *m_heap;
1386  /** The tuple used to search for specified table, it's protected
1387  by dict_persist->mutex */
1390  /** The tuple used to replace for specified table, it's protected
1391  by dict_persist->mutex */
1394  private:
1395  /** Column number of mysql.innodb_dynamic_metadata.table_id */
1396  static constexpr unsigned TABLE_ID_COL_NO = 0;
1398  /** Column number of mysql.innodb_dynamic_metadata.version */
1399  static constexpr unsigned VERSION_COL_NO = 1;
1401  /** Column number of mysql.innodb_dynamic_metadata.metadata */
1402  static constexpr unsigned METADATA_COL_NO = 2;
1404  /** Number of user columns */
1405  static constexpr unsigned N_USER_COLS = METADATA_COL_NO + 1;
1407  /** Number of columns */
1408  static constexpr unsigned N_COLS = N_USER_COLS + DATA_N_SYS_COLS;
1410  /** Clustered index field number of
1411  mysql.innodb_dynamic_metadata.table_id */
1412  static constexpr unsigned TABLE_ID_FIELD_NO = TABLE_ID_COL_NO;
1414  /** Clustered index field number of
1415  mysql.innodb_dynamic_metadata.version */
1416  static constexpr unsigned VERSION_FIELD_NO = VERSION_COL_NO + 2;
1418  /** Clustered index field number of
1419  mysql.innodb_dynamic_metadata.metadata
1420  Plusing 2 here skips the DATA_TRX_ID and DATA_ROLL_PTR fields */
1421  static constexpr unsigned METADATA_FIELD_NO = METADATA_COL_NO + 2;
1423  /** Number of fields in the clustered index */
1424  static constexpr unsigned N_FIELDS = METADATA_FIELD_NO + 1;
1425 };
1426 
1427 /** Mark the dirty_status of a table as METADATA_DIRTY, and add it to the
1428 dirty_dict_tables list if necessary.
1429 @param[in,out] table table */
1430 void dict_table_mark_dirty(dict_table_t *table);
1431 #endif /* !UNIV_HOTBACKUP */
1432 
1433 /** Flags an index corrupted in the data dictionary cache only. This
1434 is used to mark a corrupted index when index's own dictionary
1435 is corrupted, and we would force to load such index for repair purpose.
1436 Besides, we have to write a redo log.
1437 We don't want to hold dict_sys->mutex here, so that we can set index as
1438 corrupted in some low-level functions. We would only set the flags from
1439 not corrupted to corrupted when server is running, so it should be safe
1440 to set it directly.
1441 @param[in,out] index index, must not be NULL */
1442 void dict_set_corrupted(dict_index_t *index) UNIV_COLD;
1443 
1444 #ifndef UNIV_HOTBACKUP
1445 /** Check if there is any latest persistent dynamic metadata recorded
1446 in DDTableBuffer table of the specific table. If so, read the metadata and
1447 update the table object accordingly
1448 @param[in] table table object */
1450 
1451 /** Check if any table has any dirty persistent data, if so
1452 write dirty persistent data of table to mysql.innodb_dynamic_metadata
1453 accordingly. */
1455 #endif /* !UNIV_HOTBACKUP */
1456 
1457 /** Apply the persistent dynamic metadata read from redo logs or
1458 DDTableBuffer to corresponding table during recovery.
1459 @param[in,out] table table
1460 @param[in] metadata structure of persistent metadata
1461 @return true if we do apply something to the in-memory table object,
1462 otherwise false */
1465 
1466 #ifndef UNIV_HOTBACKUP
1467 /** Sets merge_threshold in the SYS_INDEXES
1468 @param[in,out] index index
1469 @param[in] merge_threshold value to set */
1470 void dict_index_set_merge_threshold(dict_index_t *index, ulint merge_threshold);
1471 
1472 #ifdef UNIV_DEBUG
1473 /** Sets merge_threshold for all indexes in dictionary cache for debug.
1474 @param[in] merge_threshold_all value to set for all indexes */
1475 void dict_set_merge_threshold_all_debug(uint merge_threshold_all);
1476 #endif /* UNIV_DEBUG */
1477 
1478 /** Validate the table flags.
1479 @param[in] flags Table flags
1480 @return true if valid. */
1481 UNIV_INLINE
1482 bool dict_tf_is_valid(uint32_t flags);
1483 
1484 /** Validate both table flags and table flags2 and make sure they
1485 are compatible.
1486 @param[in] flags Table flags
1487 @param[in] flags2 Table flags2
1488 @return true if valid. */
1489 UNIV_INLINE
1490 bool dict_tf2_is_valid(uint32_t flags, uint32_t flags2);
1491 
1492 /** Check if the tablespace for the table has been discarded.
1493  @return true if the tablespace has been discarded. */
1494 UNIV_INLINE
1496  const dict_table_t *table) /*!< in: table to check */
1497  MY_ATTRIBUTE((warn_unused_result));
1498 
1499 /** Check whether the table is DDTableBuffer. See class DDTableBuffer
1500 @param[in] table table to check
1501 @return true if this is a DDTableBuffer table. */
1502 UNIV_INLINE
1503 bool dict_table_is_table_buffer(const dict_table_t *table);
1504 
1505 /** Check if the table is in a shared tablespace (System or General).
1506 @param[in] table table to check
1507 @return true if table is a shared tablespace, false if not. */
1508 UNIV_INLINE
1510  MY_ATTRIBUTE((warn_unused_result));
1511 
1512 /** Check whether locking is disabled for this table.
1513 Currently this is done for intrinsic table as their visibility is limited
1514 to the connection and the DDTableBuffer as it's protected by
1515 dict_persist->mutex.
1516 
1517 @param[in] table table to check
1518 @return true if locking is disabled. */
1519 UNIV_INLINE
1521  MY_ATTRIBUTE((warn_unused_result));
1522 
1523 /** Turn-off redo-logging if temporary table.
1524 @param[in] table table to check
1525 @param[out] mtr mini-transaction */
1526 UNIV_INLINE
1527 void dict_disable_redo_if_temporary(const dict_table_t *table, mtr_t *mtr);
1528 
1529 /** Get table session row-id and increment the row-id counter for next use.
1530 @param[in,out] table table handler
1531 @return next table local row-id. */
1532 UNIV_INLINE
1534 
1535 /** Get table session trx-id and increment the trx-id counter for next use.
1536 @param[in,out] table table handler
1537 @return next table local trx-id. */
1538 UNIV_INLINE
1540 
1541 /** Get current session trx-id.
1542 @param[in] table table handler
1543 @return table local trx-id. */
1544 UNIV_INLINE
1546 
1547 /** This function should be called whenever a page is successfully
1548  compressed. Updates the compression padding information. */
1550  dict_index_t *index); /*!< in/out: index to be updated. */
1551 /** This function should be called whenever a page compression attempt
1552  fails. Updates the compression padding information. */
1554  dict_index_t *index); /*!< in/out: index to be updated. */
1555 /** Return the optimal page size, for which page will likely compress.
1556  @return page size beyond which page may not compress*/
1558  dict_index_t *index) /*!< in: index for which page size
1559  is requested */
1560  MY_ATTRIBUTE((warn_unused_result));
1561 /** Convert table flag to row format string.
1562  @return row format name */
1563 const char *dict_tf_to_row_format_string(
1564  ulint table_flag); /*!< in: row format setting */
1565 /** Return maximum size of the node pointer record.
1566  @return maximum size of the record in bytes */
1567 ulint dict_index_node_ptr_max_size(const dict_index_t *index) /*!< in: index */
1568  MY_ATTRIBUTE((warn_unused_result));
1569 
1570 /** Get index by first field of the index.
1571 @param[in] table table
1572 @param[in] col_index position of column in table
1573 @return index which is having first field matches with the field present in
1574 field_index position of table */
1575 UNIV_INLINE
1577  ulint col_index);
1578 #endif /* !UNIV_HOTBACKUP */
1579 
1580 /** encode number of columns and number of virtual columns in one
1581 4 bytes value. We could do this because the number of columns in
1582 InnoDB is limited to 1017
1583 @param[in] n_col number of non-virtual column
1584 @param[in] n_v_col number of virtual column
1585 @return encoded value */
1586 UNIV_INLINE
1587 ulint dict_table_encode_n_col(ulint n_col, ulint n_v_col);
1588 
1589 /** Decode number of virtual and non-virtual columns in one 4 bytes value.
1590 @param[in] encoded encoded value
1591 @param[in,out] n_col number of non-virtual column
1592 @param[in,out] n_v_col number of virtual column */
1593 UNIV_INLINE
1594 void dict_table_decode_n_col(uint32_t encoded, uint32_t *n_col,
1595  uint32_t *n_v_col);
1596 
1597 /** Free the virtual column template
1598 @param[in,out] vc_templ virtual column template */
1599 UNIV_INLINE
1600 void dict_free_vc_templ(dict_vcol_templ_t *vc_templ);
1601 
1602 /** Returns a virtual column's name according to its original
1603 MySQL table position.
1604 @param[in] table target table
1605 @param[in] col_nr column number (nth column in the table)
1606 @return column name. */
1607 const char *dict_table_get_v_col_name_mysql(const dict_table_t *table,
1608  ulint col_nr);
1609 
1610 /** Check whether the table have virtual index.
1611 @param[in] table InnoDB table
1612 @return true if the table have virtual index, false otherwise. */
1613 UNIV_INLINE
1615 
1616 /** Retrieve in-memory index for SDI table.
1617 @param[in] tablespace_id innodb tablespace ID
1618 @return dict_index_t structure or NULL*/
1620 
1621 /** Retrieve in-memory table object for SDI table.
1622 @param[in] tablespace_id innodb tablespace ID
1623 @param[in] dict_locked true if dict_sys mutex is acquired
1624 @param[in] is_create true when creating SDI Index
1625 @return dict_table_t structure */
1626 dict_table_t *dict_sdi_get_table(space_id_t tablespace_id, bool dict_locked,
1627  bool is_create);
1628 
1629 /** Remove the SDI table from table cache.
1630 @param[in] space_id InnoDB tablespace ID
1631 @param[in] sdi_table SDI table
1632 @param[in] dict_locked true if dict_sys mutex acquired */
1633 void dict_sdi_remove_from_cache(space_id_t space_id, dict_table_t *sdi_table,
1634  bool dict_locked);
1635 
1636 /** Check if the index is SDI index
1637 @param[in] index in-memory index structure
1638 @return true if index is SDI index else false */
1639 UNIV_INLINE
1640 bool dict_index_is_sdi(const dict_index_t *index);
1641 
1642 /** Check if an table id belongs SDI table
1643 @param[in] table_id dict_table_t id
1644 @return true if table_id is SDI table_id else false */
1645 UNIV_INLINE
1646 bool dict_table_is_sdi(uint64_t table_id);
1647 
1648 /** Close SDI table.
1649 @param[in] table the in-meory SDI table object */
1650 void dict_sdi_close_table(dict_table_t *table);
1651 
1652 /** Acquire exclusive MDL on SDI tables. This is acquired to
1653 prevent concurrent DROP table/tablespace when there is purge
1654 happening on SDI table records. Purge will acquired shared
1655 MDL on SDI table.
1656 
1657 Exclusive MDL is transactional(released on trx commit). So
1658 for successful acquistion, there should be valid thd with
1659 trx associated.
1660 
1661 Acquistion order of SDI MDL and SDI table has to be in same
1662 order:
1663 
1664 1. dd_sdi_acquire_exclusive_mdl
1665 2. row_drop_table_from_cache()/innodb_drop_tablespace()
1666  ->dd_sdi_remove_from_cache()->dd_table_open_on_id()
1667 
1668 In purge:
1669 
1670 1. dd_sdi_acquire_shared_mdl
1671 2. dd_table_open_on_id()
1672 
1673 @param[in] thd server thread instance
1674 @param[in] space_id InnoDB tablespace id
1675 @param[in,out] sdi_mdl MDL ticket on SDI table
1676 @retval DB_SUCESS on success
1677 @retval DB_LOCK_WAIT_TIMEOUT on error */
1679  MDL_ticket **sdi_mdl);
1680 
1681 /** Acquire shared MDL on SDI tables. This is acquired by purge to
1682 prevent concurrent DROP table/tablespace.
1683 DROP table/tablespace will acquire exclusive MDL on SDI table
1684 
1685 Acquistion order of SDI MDL and SDI table has to be in same
1686 order:
1687 
1688 1. dd_sdi_acquire_exclusive_mdl
1689 2. row_drop_table_from_cache()/innodb_drop_tablespace()
1690  ->dict_sdi_remove_from_cache()->dd_table_open_on_id()
1691 
1692 In purge:
1693 
1694 1. dd_sdi_acquire_shared_mdl
1695 2. dd_table_open_on_id()
1696 
1697 MDL should be released by caller
1698 @param[in] thd server thread instance
1699 @param[in] space_id InnoDB tablespace id
1700 @param[in,out] sdi_mdl MDL ticket on SDI table
1701 @retval DB_SUCESS on success
1702 @retval DB_LOCK_WAIT_TIMEOUT on error */
1704  MDL_ticket **sdi_mdl);
1705 
1706 /** Check whether the dict_table_t is a partition.
1707 A partitioned table on the SQL level is composed of InnoDB tables,
1708 where each InnoDB table is a [sub]partition including its secondary indexes
1709 which belongs to the partition.
1710 @param[in] table Table to check.
1711 @return true if the dict_table_t is a partition else false. */
1712 UNIV_INLINE
1713 bool dict_table_is_partition(const dict_table_t *table);
1714 
1715 /** Allocate memory for intrinsic cache elements in the index
1716  * @param[in] index index object */
1717 UNIV_INLINE
1719 
1720 /** Evict all tables that are loaded for applying purge.
1721 Since we move the offset of all table ids during upgrade,
1722 these tables cannot exist in cache. Also change table_ids
1723 of SYS_* tables if they are upgraded from earlier versions */
1725 
1726 /** @return true if table is InnoDB SYS_* table
1727 @param[in] table_id table id */
1728 bool dict_table_is_system(table_id_t table_id);
1729 
1730 /** Build the table_id array of SYS_* tables. This
1731 array is used to determine if a table is InnoDB SYSTEM
1732 table or not.
1733 @return true if successful, false otherwise */
1735 
1736 /** Change the table_id of SYS_* tables if they have been created after
1737 an earlier upgrade. This will update the table_id by adding DICT_MAX_DD_TABLES
1738 */
1740 
1741 /** Get the tablespace data directory if set, otherwise empty string.
1742 @return the data directory */
1743 std::string dict_table_get_datadir(const dict_table_t *table)
1744  MY_ATTRIBUTE((warn_unused_result));
1745 
1746 #include "dict0dict.ic"
1747 
1748 #endif
uint32_t new_id()
Create a new (hopefully unique) ID.
Definition: xcom_base.c:1600
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:123
UNIV_INLINE void dict_table_decode_n_col(uint32_t encoded, uint32_t *n_col, uint32_t *n_v_col)
Decode number of virtual and non-virtual columns in one 4 bytes value.
dberr_t replace(table_id_t id, uint64_t version, const byte *metadata, size_t len)
Replace the dynamic metadata for a specific table.
Definition: dict0dict.cc:6561
Multi file, shared, system tablespace implementation.
Record manager global types.
Persisters * persisters
Collection of instances to persist dynamic metadata.
Definition: dict0dict.h:1280
A granted metadata lock.
Definition: mdl.h:963
Data dictionary memory object creation.
ulint dict_table_get_highest_foreign_id(dict_table_t *table)
Finds the highest [number] for foreign key constraints of the table.
Definition: dict0dict.cc:3937
UNIV_INLINE ulint dict_table_encode_n_col(ulint n_col, ulint n_v_col)
encode number of columns and number of virtual columns in one 4 bytes value.
Data types.
ulint dict_table_has_column(const dict_table_t *table, const char *col_name, ulint col_nr=0)
Check if the table has a given column.
Definition: dict0dict.cc:598
void dict_table_change_id_sys_tables()
Change the table_id of SYS_* tables if they have been created after an earlier upgrade.
Definition: dict0dict.cc:7118
UNIV_INLINE void dict_table_autoinc_persisted_update(dict_table_t *table, ib_uint64_t autoinc)
Update the persisted autoinc counter to specified one, we should hold autoinc_persisted_mutex.
UNIV_INLINE void dict_tf_set(uint32_t *flags, rec_format_t format, ulint zip_ssize, bool use_data_dir, bool shared_space)
Set the various values in a dict_table_t::flags pointer.
void dict_partitioned_table_remove_from_cache(const char *name)
Try to invalidate an entry from the dict cache, for a partitioned table, if any table found...
Definition: dict0dict.cc:1970
Structure for persisting dynamic metadata of data dictionary.
Definition: dict0dict.h:1254
ibool dict_tables_have_same_db(const char *name1, const char *name2)
Checks if the database name in two table names is the same.
Definition: dict0dict.cc:265
const uint32_t SDI_VERSION
SDI version.
Definition: dict0dict.h:66
static const char * s_temp_space_file_name
The file name of the predefined temporary tablespace.
Definition: dict0dict.h:1237
Persistent dynamic metadata for a table.
Definition: dict0mem.h:2239
static constexpr space_id_t s_max_temp_space_id
Leave 1K space_ids and start space_ids for temporary general tablespaces (total 400K space_ids) ...
Definition: dict0dict.h:1209
uint32 page_no_t
Page number.
Definition: api0api.h:57
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:555
void dict_table_add_to_cache(dict_table_t *table, ibool can_be_evicted, mem_heap_t *heap)
Adds a table object to the dictionary cache.
Definition: dict0dict.cc:1189
UNIV_INLINE bool dict_table_is_sdi(uint64_t table_id)
Check if an table id belongs SDI table.
void dict_print_info_on_foreign_key_in_create_format(FILE *file, trx_t *trx, dict_foreign_t *foreign, ibool add_newline)
Outputs info on a foreign key of a table in a format suitable for CREATE TABLE.
Definition: dict0dict.cc:4965
void dict_foreign_free(dict_foreign_t *foreign)
Frees a foreign key struct.
Definition: dict0mem.h:1408
UNIV_INLINE void dict_table_x_unlock_indexes(dict_table_t *table)
Release the exclusive locks on all index tree.
bool dict_foreign_replace_index(dict_table_t *table, const char **col_names, const dict_index_t *index)
Replace the index passed in with another equivalent index in the foreign key lists of the table...
Definition: dict0dict.cc:5668
bool fsp_is_session_temporary(space_id_t space_id)
Check if the tablespace is session temporary.
Definition: fsp0fsp.cc:275
UNIV_INLINE ib_uint64_t dict_table_get_n_rows(const dict_table_t *table)
Gets the approximately estimated number of rows in the table.
static constexpr unsigned VERSION_FIELD_NO
Clustered index field number of mysql.innodb_dynamic_metadata.version.
Definition: dict0dict.h:1417
static const char * s_default_undo_space_name_1
These two undo tablespaces cannot be dropped.
Definition: dict0dict.h:1243
void dict_table_mark_dirty(dict_table_t *table)
Mark the dirty_status of a table as METADATA_DIRTY, and add it to the dirty_dict_tables list if neces...
Definition: dict0dict.cc:5355
dict_index_t * dict_foreign_find_index(const dict_table_t *table, const char **col_names, const char **columns, ulint n_cols, const dict_index_t *types_idx, bool check_charsets, ulint check_null)
Tries to find an index whose first fields are the columns in the array, in the same order and is not ...
Definition: dict0dict.cc:3225
const string name("\ame\)
dict_index_t * dict_sdi_get_index(space_id_t tablespace_id)
Retrieve in-memory index for SDI table.
Definition: dict0dict.cc:7048
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
static constexpr space_id_t undo_space_id_range
The number of space IDs dedicated to each undo tablespace.
Definition: dict0dict.h:1195
table_non_LRU
List of tables that can&#39;t be evicted from the cache.
Definition: dict0dict.h:1137
dberr_t dict_index_add_to_cache_w_vcol(dict_table_t *table, dict_index_t *index, const dict_add_v_col_t *add_v, page_no_t page_no, ibool strict)
Adds an index to the dictionary cache, with possible indexing newly added column. ...
Definition: dict0dict.cc:2338
UNIV_INLINE ulint dict_index_get_n_fields(const dict_index_t *index)
Gets the number of fields in the internal representation of an index, including fields added by the d...
Allow partial indexes to exist.
Definition: dict0dict.h:859
void dict_index_zip_failure(dict_index_t *index)
This function should be called whenever a page compression attempt fails.
Definition: dict0dict.cc:6181
Definition: trx0trx.h:780
void dict_table_stats_latch_create(dict_table_t *table, bool enabled)
Create a dict_table_t&#39;s stats latch or delay for lazy creation.
Definition: dict0dict.cc:341
dtuple_t * dict_index_build_node_ptr(const dict_index_t *index, const rec_t *rec, page_no_t page_no, mem_heap_t *heap, ulint level)
Builds a node pointer out of a physical record and a page number.
Definition: dict0dict.cc:4804
Wrapper for the mysql.innodb_dynamic_metadata used to buffer the persistent dynamic metadata...
Definition: dict0dict.h:1312
UNIV_INLINE void dict_table_prevent_eviction(dict_table_t *table)
Prevent table eviction by moving a table to the non-LRU list from the LRU list if it is not already t...
void dict_mutex_enter_for_mysql(void)
Reserves the dictionary system mutex for MySQL.
Definition: dict0dict.cc:306
ulint dict_table_get_nth_col_pos(const dict_table_t *table, ulint n)
Looks for non-virtual column n position in the clustered index.
Definition: dict0dict.cc:949
UNIV_INLINE ulint dict_index_is_unique(const dict_index_t *index)
Check whether the index is unique.
void dict_index_remove_from_cache(dict_table_t *table, dict_index_t *index)
Removes an index from the dictionary cache.
Definition: dict0dict.cc:2655
static constexpr unsigned METADATA_FIELD_NO
Clustered index field number of mysql.innodb_dynamic_metadata.metadata Plusing 2 here skips the DATA_...
Definition: dict0dict.h:1422
rw_lock_t * dict_operation_lock
the data dictionary rw-latch protecting dict_sys
Definition: dict0dict.cc:173
mem_heap_t * m_dynamic_heap
The heap used for dynamic allocations, which should always be freed before return.
Definition: dict0dict.h:1378
dict_table_t * sys_columns
SYS_COLUMNS table.
Definition: dict0dict.h:1119
const char * dict_tf_to_row_format_string(ulint table_flag)
Convert table flag to row format string.
Definition: dict0dict.cc:6265
static constexpr unsigned N_FIELDS
Number of fields in the clustered index.
Definition: dict0dict.h:1425
const space_id_t SYSTEM_TABLE_SPACE
Space id of system tablespace.
Definition: dict0dict.h:69
static constexpr dd::Object_id s_dd_sys_space_id
The dd::Tablespace::id of innodb_system.
Definition: dict0dict.h:1219
UNIV_INLINE space_id_t dict_index_get_space(const dict_index_t *index)
Gets the space id of the root of the index tree.
dict_persist_t * dict_persist
the dictionary persisting structure
Definition: dict0dict.cc:163
static constexpr space_id_t s_reserved_space_id
The first reserved tablespace ID.
Definition: dict0dict.h:1205
#define FSP_MAX_UNDO_TABLESPACES
Definition: fsp0types.h:401
const char * dict_table_get_v_col_name_mysql(const dict_table_t *table, ulint col_nr)
Returns a virtual column&#39;s name according to its original MySQL table position.
Definition: dict0dict.cc:679
void dict_persist_to_dd_table_buffer()
Check if any table has any dirty persistent data, if so write dirty persistent data of table to mysql...
Definition: dict0dict.cc:5483
dberr_t dd_sdi_acquire_shared_mdl(THD *thd, space_id_t space_id, MDL_ticket **sdi_mdl)
Acquire shared MDL on SDI tables.
Definition: dict0dict.cc:7308
uint32_t dict_tf_to_fsp_flags(uint32_t table_flags)
Convert a 32 bit integer table flags to the 32 bit FSP Flags.
Definition: dict0dict.cc:6241
UNIV_INLINE void dict_index_set_online_status(dict_index_t *index, enum online_index_status status)
Sets the status of online index creation.
bool dict_table_apply_dynamic_metadata(dict_table_t *table, const PersistentTableMetadata *metadata)
Apply the persistent dynamic metadata read from redo logs or DDTableBuffer to corresponding table dur...
Definition: dict0dict.cc:5199
dict_table_t * sys_fields
SYS_FIELDS table.
Definition: dict0dict.h:1121
void dict_persist_close(void)
Clear the structure.
Definition: dict0dict.cc:5156
UNIV_INLINE enum online_index_status dict_index_get_online_status(const dict_index_t *index)
Gets the status of online index creation.
ibool dict_col_name_is_reserved(const char *name)
If the given column name is reserved for InnoDB system columns, return TRUE.
Definition: dict0dict.cc:2014
bool dict_sys_table_id_build()
Build the table_id array of SYS_* tables.
Definition: dict0dict.cc:7195
Data dictionary system.
static constexpr unsigned N_USER_COLS
Number of user columns.
Definition: dict0dict.h:1406
unsigned long id[MAX_DEAD]
Definition: xcom_base.c:426
UNIV_INLINE bool dict_table_has_indexed_v_cols(const dict_table_t *table)
Check if a table has indexed virtual columns.
UNIV_INLINE ibool dict_table_is_comp(const dict_table_t *table)
Check whether the table uses the compact page format.
Data structure for a database table.
Definition: dict0mem.h:1529
static constexpr space_id_t s_max_undo_space_id
The highest undo tablespace ID.
Definition: dict0dict.h:1202
hash_table_t * table_hash
hash table of the tables, based on name
Definition: dict0dict.h:1110
void dict_foreign_remove_from_cache(dict_foreign_t *foreign)
Removes a foreign constraint struct from the dictionary cache.
Definition: dict0dict.cc:3177
static constexpr unsigned VERSION_COL_NO
Column number of mysql.innodb_dynamic_metadata.version.
Definition: dict0dict.h:1400
void dict_set_merge_threshold_all_debug(uint merge_threshold_all)
Sets merge_threshold for all indexes in dictionary cache for debug.
Definition: dict0dict.cc:5602
void dict_table_move_from_lru_to_non_lru(dict_table_t *table)
Move a table to the non LRU end of the LRU list.
Definition: dict0dict.cc:1376
UNIV_INLINE ulint dict_col_get_clust_pos(const dict_col_t *col, const dict_index_t *clust_index)
Gets the column position in the clustered index.
void dict_init(void)
Inits the data dictionary module.
Definition: dict0dict.cc:1018
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:658
ibool dict_table_is_referenced_by_foreign_key(const dict_table_t *table)
Checks if a table is referenced by foreign keys.
Definition: dict0dict.cc:3170
static const char * s_file_per_table_name
The hard-coded tablespace name innodb_file_per_table.
Definition: dict0dict.h:1240
UNIV_INLINE ulint dict_col_get_index_pos(const dict_col_t *col, const dict_index_t *index)
Gets the column position in the given index.
static constexpr space_id_t s_log_space_first_id
The first ID of the redo log pseudo-tablespace.
Definition: dict0dict.h:1183
File space management.
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C...
Definition: dict0mem.h:1274
void init()
Initialize m_index, the in-memory clustered index of the table and two tuples used in this class...
Definition: dict0dict.cc:6382
const std::string FILE("FILE")
UNIV_INLINE const page_size_t dict_tf_get_page_size(uint32_t flags)
Extract the page size from table flags.
void dict_index_remove_from_v_col_list(dict_index_t *index)
Clears the virtual column&#39;s index list before index is being freed.
Definition: dict0dict.cc:2293
ulint dict_index_node_ptr_max_size(const dict_index_t *index)
Return maximum size of the node pointer record.
Definition: dict0dict.cc:2038
ulint dict_table_mysql_pos_to_innodb(const dict_table_t *table, ulint n)
Get the innodb column position for a non-virtual column according to its original MySQL table positio...
Definition: dict0dict.cc:960
ulint dict_index_calc_min_rec_len(const dict_index_t *index)
Calculates the minimum record length in an index.
Definition: dict0dict.cc:4920
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:343
Container of persisters used in the system.
Definition: dict0mem.h:2425
static constexpr space_id_t s_min_undo_space_id
The lowest undo tablespace ID.
Definition: dict0dict.h:1198
UNIV_INLINE bool dict_table_in_shared_tablespace(const dict_table_t *table)
Check if the table is in a shared tablespace (System or General).
ib_id_t row_id_t
Row identifier (DB_ROW_ID, DATA_ROW_ID)
Definition: trx0types.h:142
UNIV_INLINE const page_size_t dict_table_page_size(const dict_table_t *table)
Get the table page size.
ibool dict_index_contains_col_or_prefix(const dict_index_t *index, ulint n, bool is_virtual)
Returns TRUE if the index contains a column or a prefix of that column.
Definition: dict0dict.cc:865
SQL data field and tuple.
Data structure for a column in a table.
Definition: dict0mem.h:461
UNIV_INLINE trx_id_t dict_table_get_curr_table_sess_trx_id(const dict_table_t *table)
Get current session trx-id.
void dict_table_stats_lock(dict_table_t *table, ulint latch_mode)
Lock the appropriate latch to protect a given table&#39;s statistics.
Definition: dict0dict.cc:367
DDTableBuffer * table_buffer
DDTableBuffer table for persistent dynamic metadata.
Definition: dict0dict.h:1276
UNIV_INLINE ulint dict_max_field_len_store_undo(dict_table_t *table, const dict_col_t *col)
Determine bytes of column prefix to be stored in the undo log.
UNIV_INLINE ulint dict_table_get_n_tot_u_cols(const dict_table_t *table)
UNIV_INLINE ulint dict_table_get_n_v_cols(const dict_table_t *table)
Gets the number of virtual columns in a table in the dictionary cache.
UNIV_INLINE uint16_t dict_index_get_n_unique_in_tree_nonleaf(const dict_index_t *index)
Gets the number of fields on nonleaf page level in the internal representation of an index which uni...
bool dict_table_is_system(table_id_t table_id)
Definition: dict0dict.cc:7215
UNIV_INLINE bool dict_table_is_discarded(const dict_table_t *table)
Check if the tablespace for the table has been discarded.
ib_mutex_t dict_foreign_err_mutex
Definition: dict0dict.cc:261
UNIV_INLINE ulint dict_index_has_virtual(const dict_index_t *index)
Check whether the index contains a virtual column.
static const char * s_default_undo_space_name_2
Definition: dict0dict.h:1244
UNIV_INLINE void dict_table_ddl_acquire(dict_table_t *table)
Move this table to non-LRU list for DDL operations if it&#39;s currently not there.
void dict_table_wait_for_bg_threads_to_exit(dict_table_t *table, ulint delay)
Definition: dict0dict.cc:2870
ib_uint64_t dict_table_autoinc_read(const dict_table_t *table)
Reads the next autoinc value (== autoinc counter value), 0 if not yet initialized.
Definition: dict0dict.cc:833
void dict_fs2utf8(const char *db_and_table, char *db_utf8, size_t db_utf8_size, char *table_utf8, size_t table_utf8_size)
Converts a database and table name from filesystem encoding (e.g.
Definition: dict0dict.cc:5793
void dict_table_persist_to_dd_table_buffer(dict_table_t *table)
Write back the dirty persistent dynamic metadata of the table to DDTableBuffer.
Definition: dict0dict.cc:5460
Globally unique index identifier.
Definition: dict0types.h:66
Definition: hash0hash.h:401
void dict_table_stats_latch_destroy(dict_table_t *table)
Destroy a dict_table_t&#39;s stats latch.
Definition: dict0dict.cc:357
static constexpr space_id_t s_space_id
The data dictionary tablespace ID.
Definition: dict0dict.h:1189
UNIV_INLINE ulint dict_index_get_n_unique_in_tree(const dict_index_t *index)
Gets the number of fields in the internal representation of an index which uniquely determine the pos...
DDTableBuffer()
Default constructor.
Definition: dict0dict.cc:6328
char * index(const char *, int c)
Definition: mysql.cc:2862
dirty_dict_tables
List of tables whose dirty_status are marked as METADATA_DIRTY, or METADATA_BUFFERED.
Definition: dict0dict.h:1268
UNIV_INLINE dict_index_t * dict_table_get_index_on_first_col(dict_table_t *table, ulint col_index)
Get index by first field of the index.
static constexpr unsigned METADATA_COL_NO
Column number of mysql.innodb_dynamic_metadata.metadata.
Definition: dict0dict.h:1403
const char * dict_remove_db_name(const char *name)
Return the end of table name where we have removed dbname and &#39;/&#39;.
Definition: dict0dict.cc:281
Data dictionary global types.
char * pos
Definition: do_ctype.cc:76
Memory primitives.
static const char * s_temp_space_name
The name of the predefined temporary tablespace.
Definition: dict0dict.h:1234
UNIV_INLINE ulint dict_index_is_ibuf(const dict_index_t *index)
Check whether the index is the insert buffer tree.
void dict_resize()
Resize the hash tables besed on the current buffer pool size.
Definition: dict0dict.cc:5840
UNIV_INLINE bool dict_tf_is_valid(uint32_t flags)
Validate the table flags.
UNIV_INLINE page_no_t dict_index_get_page(const dict_index_t *tree)
Gets the page number of the root of the index tree.
byte rec_t
Definition: rem0types.h:39
hash_table_t * table_id_hash
hash table of the tables, based on id
Definition: dict0dict.h:1112
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:714
std::string dict_table_get_datadir(const dict_table_t *table)
Get the tablespace data directory if set, otherwise empty string.
Definition: dict0dict.cc:7335
UNIV_INLINE void dict_free_vc_templ(dict_vcol_templ_t *vc_templ)
Free the virtual column template.
The read-write lock (for threads, not for database transactions)
UNIV_INLINE void dict_table_n_rows_inc(dict_table_t *table)
Increment the number of rows in the table by one.
UNIV_INLINE bool dict_index_has_desc(const dict_index_t *index)
Check whether the index consists of descending columns only.
void create_tuples()
Create the search and replace tuples.
Definition: dict0dict.cc:6339
page_no_t dict_table_extent_size(const dict_table_t *table)
Determine the extent size (in pages) for the given table.
Definition: dict0dict.cc:6286
dict_index_t * dict_table_get_index_on_name(dict_table_t *table, const char *name, bool committed=true)
Get an index by name.
Definition: dict0dict.cc:5647
row_id_t row_id
the next row id to assign; NOTE that at a checkpoint this must be written to the dict system header a...
Definition: dict0dict.h:1104
ulint dict_index_zip_pad_optimal_page_size(dict_index_t *index)
Return the optimal page size, for which page will likely compress.
Definition: dict0dict.cc:6200
void dict_index_zip_success(dict_index_t *index)
This function should be called whenever a page is successfully compressed.
Definition: dict0dict.cc:6162
void dict_table_autoinc_unlock(dict_table_t *table)
Release the autoinc lock.
Definition: dict0dict.cc:855
dberr_t
Definition: db0err.h:38
void dict_persist_init(void)
Inits the structure for persisting dynamic metadata.
Definition: dict0dict.cc:5133
static constexpr unsigned TABLE_ID_FIELD_NO
Clustered index field number of mysql.innodb_dynamic_metadata.table_id.
Definition: dict0dict.h:1413
ulint dict_index_get_nth_field_pos(const dict_index_t *index, const dict_index_t *index2, ulint n)
Looks for a matching field in an index.
Definition: dict0dict.cc:904
ulint dict_get_db_name_len(const char *name)
Get the database name length in a table name.
Definition: dict0dict.cc:293
Row operation global types.
dict_table_t * sys_virtual
SYS_VIRTUAL table.
Definition: dict0dict.h:1122
dtuple_t * m_replace_tuple
The tuple used to replace for specified table, it&#39;s protected by dict_persist->mutex.
Definition: dict0dict.h:1393
Instrumented memory allocator.
UNIV_INLINE ulint dict_col_get_no(const dict_col_t *col)
Gets the column number.
const dict_index_t * dict_index_find(const index_id_t &id)
Look up an index.
Definition: dict0dict.cc:1428
UNIV_INLINE row_id_t dict_table_get_next_table_sess_row_id(dict_table_t *table)
Get table session row-id and increment the row-id counter for next use.
dberr_t dict_foreign_parse_drop_constraints(mem_heap_t *heap, trx_t *trx, dict_table_t *table, ulint *n, const char ***constraints_to_drop)
Parses the CONSTRAINT id&#39;s to be dropped in an ALTER TABLE statement.
Definition: dict0dict.cc:4658
Definition: ut0vec.h:229
unsigned int uint
Definition: uca-dump.cc:29
lint size
varying space in bytes occupied by the data dictionary table and index objects
Definition: dict0dict.h:1114
void dict_table_read_dynamic_metadata(const byte *buffer, ulint size, PersistentTableMetadata *metadata)
Read persistent dynamic metadata stored in a buffer.
Definition: dict0dict.cc:5274
#define true
Definition: config_static.h:44
UNIV_INLINE rw_lock_t * dict_index_get_lock(dict_index_t *index)
Gets the read-write lock of the index tree.
dict_table_t * sys_tables
Handler to sys_* tables, they&#39;re only for upgrade.
Definition: dict0dict.h:1118
static bool is_dd_table_id(table_id_t id)
Check if a table is hardcoded.
Definition: dict0dict.h:1178
void dict_set_corrupted(dict_index_t *index) UNIV_COLD
Flags an index corrupted in the data dictionary cache only.
Definition: dict0dict.cc:5390
UNIV_INLINE bool dict_table_have_virtual_index(dict_table_t *table)
Check whether the table have virtual index.
#define HASH_GET_NEXT(NAME, DATA)
Gets the next struct in a hash chain, NULL if none.
Definition: innodb_utility.h:166
Require all indexes to be complete.
Definition: dict0dict.h:855
dberr_t dict_table_rename_in_cache(dict_table_t *table, const char *new_name, ibool rename_also_foreigns)
Renames a table object.
Definition: dict0dict.cc:1469
unsigned long long Object_id
Definition: object_id.h:30
UNIV_INLINE ulint dict_index_get_n_ordering_defined_by_user(const dict_index_t *index)
Gets the number of user-defined ordering fields in the index.
static const char * s_dd_space_name
The name of the data dictionary tablespace.
Definition: dict0dict.h:1225
void delay(int amt)
Definition: suite_stubs.c:27
mem_heap_t * m_replace_heap
The heap used during replace() operation, which should always be freed before return.
Definition: dict0dict.h:1382
Utilities for byte operations.
static constexpr dd::Object_id s_dd_temp_space_id
The dd::Tablespace::id of innodb_temporary.
Definition: dict0dict.h:1222
void dict_table_remove_from_cache(dict_table_t *table)
Removes a table object from the dictionary cache.
Definition: dict0dict.cc:1962
ibool dict_index_check_search_tuple(const dict_index_t *index, const dtuple_t *tuple)
Checks that a tuple has n_fields_cmp value in a sensible range, so that no comparison can occur with ...
Definition: dict0dict.cc:4787
mem_heap_t * m_heap
The heap used to create the search tuple and replace tuple.
Definition: dict0dict.h:1385
void dict_sdi_remove_from_cache(space_id_t space_id, dict_table_t *sdi_table, bool dict_locked)
Remove the SDI table from table cache.
Definition: dict0dict.cc:7087
void dict_table_remove_from_cache_debug(dict_table_t *table, bool lru_evict)
Removes a table object from the dictionary cache, for debug purpose.
Definition: dict0dict.cc:2006
Drop any orphan indexes after an aborted online index creation.
Definition: dict0dict.h:111
Transaction system global type definitions.
UNIV_INLINE void dict_table_n_rows_dec(dict_table_t *table)
Decrement the number of rows in the table by one.
Silently load the tablespace if it does not exist, and do not load the definitions of incomplete inde...
Definition: dict0dict.h:114
void dict_table_autoinc_update_if_greater(dict_table_t *table, ib_uint64_t value)
Updates the autoinc counter if the value supplied is greater than the current value.
Definition: dict0dict.cc:842
dict_v_col_t * dict_table_get_nth_v_col_mysql(const dict_table_t *table, ulint col_nr)
Get nth virtual column.
Definition: dict0dict.cc:694
void dict_mutex_exit_for_mysql(void)
Releases the dictionary system mutex for MySQL.
Definition: dict0dict.cc:309
UNIV_INLINE ibool dict_table_has_fts_index(dict_table_t *table)
Check if the table has an FTS index.
UNIV_INLINE bool dict_index_is_online_ddl(const dict_index_t *index)
Determines if a secondary index is being or has been created online, or if the table is being rebuilt...
dict_table_t * dict_sdi_get_table(space_id_t tablespace_id, bool dict_locked, bool is_create)
Retrieve in-memory table object for SDI table.
Definition: dict0dict.cc:7064
const string version("\ersion\)
dberr_t dict_index_add_to_cache(dict_table_t *table, dict_index_t *index, page_no_t page_no, ibool strict)
Adds an index to the dictionary cache.
Definition: dict0dict.cc:2285
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:61
void init_tuple_with_id(dtuple_t *tuple, table_id_t id)
Initialize the id field of tuple.
Definition: dict0dict.cc:6489
static constexpr space_id_t s_temp_space_id
The innodb_temporary tablespace ID.
Definition: dict0dict.h:1192
UNIV_INLINE bool dict_table_has_autoinc_col(const dict_table_t *table)
Check if a table has an autoinc counter column.
uint32_t hash(const void *key, size_t length, const uint32_t initval)
Definition: hash.c:121
check_name
Whether and when to allow temporary index names.
Definition: dict0dict.h:853
void dict_table_autoinc_log(dict_table_t *table, uint64_t value, mtr_t *mtr)
Write redo logs for autoinc counter that is to be inserted, or to update some existing smaller one to...
Definition: dict0dict.cc:763
UNIV_INLINE void dict_table_allow_eviction(dict_table_t *table)
Allow the table to be evicted by moving a table to the LRU list from the non-LRU list if it is not al...
dberr_t dict_create_foreign_constraints(trx_t *trx, const char *sql_string, size_t sql_length, const char *name, ibool reject_fks)
Scans a table create SQL string and adds to the data dictionary the foreign key constraints declared ...
Definition: dict0dict.cc:4633
int n
Definition: xcom_base.c:425
FILE * dict_foreign_err_file
Definition: dict0dict.cc:259
The memory management.
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
UNIV_INLINE bool dict_index_is_auto_gen_clust(const dict_index_t *index)
Check if index is auto-generated clustered index.
Structure defines template related to virtual columns and their base columns.
Definition: dict0mem.h:1471
dberr_t dict_foreign_add_to_cache(dict_foreign_t *foreign, const char **col_names, bool check_charsets, bool can_free_fk, dict_err_ignore_t ignore_err)
Adds a foreign key constraint object to the dictionary cache.
Definition: dict0dict.cc:3304
Definition: dict0dict.h:1094
dict_sys_t * dict_sys
the dictionary system
Definition: dict0dict.cc:133
const string metadata("\etadata\)
enum rec_format_enum rec_format_t
Definition: rem0types.h:80
static const char * s_sys_space_name
The name of the hard-coded system tablespace.
Definition: dict0dict.h:1231
dict_table_t * dict_table_open_on_name(const char *table_name, ibool dict_locked, ibool try_drop, dict_err_ignore_t ignore_err)
Returns a table object and increments its open handle count.
Definition: dict0dict.cc:1070
Page size descriptor.
Definition: page0size.h:50
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
void dict_table_set_big_rows(dict_table_t *table)
Mark if table has big rows.
Definition: dict0dict.cc:1165
void dict_move_to_mru(dict_table_t *table)
Move to the most recently used segment of the LRU list.
Definition: dict0dict.cc:1050
#define UT_LIST_BASE_NODE_T(TYPE)
Definition: innodb_utility.h:47
UNIV_INLINE trx_id_t dict_table_get_next_table_sess_trx_id(dict_table_t *table)
Get table session trx-id and increment the trx-id counter for next use.
dict_table_op_t
Operation to perform when opening a table.
Definition: dict0dict.h:107
void dict_table_copy_types(dtuple_t *tuple, const dict_table_t *table)
Copies types of columns contained in table to tuple and sets all fields of the tuple to the SQL NULL ...
Definition: dict0dict.cc:2850
void dict_table_add_system_columns(dict_table_t *table, mem_heap_t *heap)
Adds system columns to a table object.
Definition: dict0dict.cc:1131
upd_t * update_set_metadata(const dtuple_t *entry, const rec_t *rec)
Prepare for a update on METADATA field.
Definition: dict0dict.cc:6512
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:63
void dict_table_move_from_non_lru_to_lru(dict_table_t *table)
Move a table to the LRU end from the non LRU list.
Definition: dict0dict.cc:1394
#define mutex_enter(M)
Definition: ut0mutex.h:115
UNIV_INLINE ulint dict_index_get_n_unique(const dict_index_t *index)
Gets the number of fields in the internal representation of an index that uniquely determine the posi...
UNIV_INLINE ulint dict_index_is_spatial(const dict_index_t *index)
Check whether the index is a Spatial Index.
static constexpr space_id_t s_min_temp_space_id
Lowest temporary general space id.
Definition: dict0dict.h:1212
char * dict_get_referenced_table(const char *name, const char *database_name, ulint database_name_len, const char *table_name, ulint table_name_len, dict_table_t **table, mem_heap_t *heap)
Open a table from its database and table name, this is currently used by foreign constraint parser to...
Definition: dict0dict.cc:3677
UNIV_INLINE ulint dict_table_is_fts_column(ib_vector_t *indexes, ulint col_no, bool is_virtual)
void dict_table_change_id_in_cache(dict_table_t *table, table_id_t new_id)
Change the id of a table object in the dictionary cache.
Definition: dict0dict.cc:1850
UNIV_INLINE bool dict_table_is_table_buffer(const dict_table_t *table)
Check whether the table is DDTableBuffer.
bool dict_table_is_compressed_temporary(const dict_table_t *table)
Check if a table is a temporary table with compressed row format, we should always expect false...
ulint dict_table_get_all_fts_indexes(dict_table_t *table, ib_vector_t *indexes)
Get all the FTS indexes on a table.
Definition: dict0dict.cc:815
dtuple_t * dict_index_build_data_tuple(dict_index_t *index, rec_t *rec, ulint n_fields, mem_heap_t *heap)
Builds a typed data tuple out of a physical record.
Definition: dict0dict.cc:4897
UNIV_INLINE void dict_table_autoinc_set_col_pos(dict_table_t *table, ulint pos)
Set the column position of autoinc column in clustered index for a table.
UNIV_INLINE ulint dict_max_v_field_len_store_undo(dict_table_t *table, ulint col_no)
Determine maximum bytes of a virtual column need to be stored in the undo log.
void close()
Free the things initialized in init()
Definition: dict0dict.cc:6498
void dict_index_set_merge_threshold(dict_index_t *index, ulint merge_threshold)
Sets merge_threshold in the SYS_INDEXES.
ib_mutex_t mutex
Mutex to protect data in this structure, also the dict_table_t::dirty_status and dict_table_t::in_dir...
Definition: dict0dict.h:1263
Data structure for a virtual column in a table.
Definition: dict0mem.h:638
void dict_table_copy_v_types(dtuple_t *tuple, const dict_table_t *table)
Copies types of virtual columns contained in table to tuple and sets all fields of the tuple to the S...
Definition: dict0dict.cc:2832
static constexpr table_id_t s_dynamic_meta_table_id
The table ID of mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1247
#define mutex_exit(M)
Definition: ut0mutex.h:122
UNIV_INLINE ulint dict_index_get_space_reserve(void)
Returns free space reserved for future updates of records.
void dict_table_close(dict_table_t *table, ibool dict_locked, ibool try_drop)
Decrements the count of open handles to a table.
Definition: dict0dict.cc:488
static const char * s_dd_space_file_name
The file name of the data dictionary tablespace.
Definition: dict0dict.h:1228
dict_table_t * ddl_log
Permanent handle to mysql.innodb_ddl_log.
Definition: dict0dict.h:1129
void dict_table_close_and_drop(trx_t *trx, dict_table_t *table)
Closes the only open handle to a table and drops a table while assuring that dict_sys->mutex is held ...
Definition: dict0dict.cc:572
UNIV_INLINE void dict_table_ddl_release(dict_table_t *table)
Move this table to LRU list after DDL operations if it was moved to non-LRU list. ...
ib_mutex_t DictSysMutex
Definition: dict0types.h:147
DictSysMutex mutex
mutex protecting the data dictionary; protects also the disk-based dictionary system tables; this mut...
Definition: dict0dict.h:1096
void dict_table_stats_unlock(dict_table_t *table, ulint latch_mode)
Unlock the latch that has been locked by dict_table_stats_lock().
Definition: dict0dict.cc:398
UNIV_INLINE bool dict_index_is_sdi(const dict_index_t *index)
Check if the index is SDI index.
ulint dict_make_room_in_cache(ulint max_tables, ulint pct_check)
Make room in the table cache by evicting an unused table.
Definition: dict0dict.cc:1316
rec_t * dict_index_copy_rec_order_prefix(const dict_index_t *index, const rec_t *rec, ulint *n_fields, byte **buf, size_t *buf_size)
Copies an initial segment of a physical record, long enough to specify an index entry uniquely...
Definition: dict0dict.cc:4866
Random numbers and hashing.
static constexpr dd::Object_id s_dd_space_id
The dd::Tablespace::id of the dictionary tablespace.
Definition: dict0dict.h:1216
static bool is_reserved(space_id_t space)
Check if a tablespace id is a reserved one.
Definition: dict0dict.h:1164
UNIV_INLINE void dict_allocate_mem_intrinsic_cache(dict_index_t *index)
Allocate memory for intrinsic cache elements in the index.
UNIV_INLINE bool dict_table_is_locking_disabled(const dict_table_t *table)
Check whether locking is disabled for this table.
dberr_t dd_sdi_acquire_exclusive_mdl(THD *thd, space_id_t space_id, MDL_ticket **sdi_mdl)
Acquire exclusive MDL on SDI tables.
Definition: dict0dict.cc:7250
void dict_table_autoinc_initialize(dict_table_t *table, ib_uint64_t value)
Unconditionally set the autoinc counter.
Definition: dict0dict.cc:749
void dict_table_autoinc_lock(dict_table_t *table)
Acquire the autoinc lock.
Definition: dict0dict.cc:731
const string value("\alue\)
UNIV_INLINE ulint dict_index_is_sec_or_ibuf(const dict_index_t *index)
Check whether the index is a secondary index or the insert buffer tree.
UNIV_INLINE ulint dict_table_get_sys_col_no(const dict_table_t *table, ulint sys)
Gets the given system column number of a table.
static STATUS status
Definition: mysql.cc:193
UNIV_INLINE dict_v_col_t * dict_table_get_nth_v_col(const dict_table_t *table, ulint pos)
Gets the nth virtual column of a table.
void dict_ind_init(void)
Inits dict_ind_redundant.
Definition: dict0dict.cc:5615
static std::set< dd::Object_id > s_dd_table_ids
Set of ids of DD tables.
Definition: dict0dict.h:1170
void dict_index_copy_types(dtuple_t *tuple, const dict_index_t *index, ulint n_fields)
Copies types of fields contained in index to tuple.
Definition: dict0dict.cc:2799
UNIV_INLINE bool dict_table_is_partition(const dict_table_t *table)
Check whether the dict_table_t is a partition.
UNIV_INLINE void dict_index_set_space(dict_index_t *index, space_id_t space)
Sets the space id of the root of the index tree.
UNIV_INLINE uint32_t dict_tf_init(bool compact, ulint zip_ssize, bool atomic_blobs, bool data_dir, bool shared_space)
Initialize a dict_table_t::flags pointer.
static int flags[50]
Definition: hp_test1.cc:39
The simple hash table utility.
unsigned char byte
Blob class.
Definition: common.h:159
void dict_sdi_close_table(dict_table_t *table)
Close SDI table.
Definition: dict0dict.cc:7040
static constexpr unsigned TABLE_ID_COL_NO
Column number of mysql.innodb_dynamic_metadata.table_id.
Definition: dict0dict.h:1397
static constexpr space_id_t s_invalid_space_id
Use maximum UINT value to indicate invalid space ID.
Definition: dict0dict.h:1186
void dict_upgrade_evict_tables_cache()
Evict all tables that are loaded for applying purge.
Definition: dict0dict.cc:7143
table_LRU
List of tables that can be evicted from the cache.
Definition: dict0dict.h:1134
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
UNIV_INLINE void dict_disable_redo_if_temporary(const dict_table_t *table, mtr_t *mtr)
Turn-off redo-logging if temporary table.
dtuple_t * m_search_tuple
The tuple used to search for specified table, it&#39;s protected by dict_persist->mutex.
Definition: dict0dict.h:1389
void dict_print_info_on_foreign_keys(ibool create_table_format, FILE *file, trx_t *trx, dict_table_t *table)
Outputs info on foreign keys of a table.
Definition: dict0dict.cc:5058
dict_index_t * m_index
The clustered index of this system table.
Definition: dict0dict.h:1374
static const space_id_t TRX_SYS_SPACE
Space id of the transaction system page (the system tablespace)
Definition: trx0types.h:57
bool dict_foreign_qualify_index(const dict_table_t *table, const char **col_names, const char **columns, ulint n_cols, const dict_index_t *index, const dict_index_t *types_idx, bool check_charsets, ulint check_null)
Tries to find an index whose first fields are the columns in the array, in the same order and is not ...
Definition: dict0dict.cc:6025
dict_table_t * sys_indexes
SYS_INDEXES table.
Definition: dict0dict.h:1120
void dict_table_check_for_dup_indexes(const dict_table_t *table, enum check_name check)
Check for duplicate index entries in a table [using the index name].
Definition: dict0dict.cc:5730
static constexpr unsigned N_COLS
Number of columns.
Definition: dict0dict.h:1409
#define HASH_GET_FIRST(TABLE, HASH_VAL)
Gets the first struct in a hash chain, NULL if none.
Definition: innodb_utility.h:160
dict_table_t * dynamic_metadata
Permanent handle to mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1131
UNIV_INLINE void dict_table_x_lock_indexes(dict_table_t *table)
Obtain exclusive locks on all index trees of the table.
void open()
Open the mysql.innodb_dynamic_metadata when DD is not fully up.
Definition: dict0dict.cc:6408
#define DATA_N_SYS_COLS
Definition: data0type.h:188
Definition: completion_hash.h:34
void dict_table_load_dynamic_metadata(dict_table_t *table)
Check if there is any latest persistent dynamic metadata recorded in DDTableBuffer table of the speci...
Definition: dict0dict.cc:5305
uint64_t uint64
Definition: my_inttypes.h:68
void truncate(void)
Truncate the table.
Definition: dict0dict.cc:6670
static constexpr space_index_t s_dynamic_meta_index_id
The clustered index ID of mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1250
UNIV_INLINE bool dict_table_has_atomic_blobs(const dict_table_t *table)
Determine if a table uses atomic BLOBs (no locally stored prefix).
dict_table_t * table_stats
Permanent handle to mysql.innodb_table_stats.
Definition: dict0dict.h:1125
dict_table_t * index_stats
Permanent handle to mysql.innodb_index_stats.
Definition: dict0dict.h:1127
ibool dict_table_col_in_clustered_key(const dict_table_t *table, ulint n)
Checks if a column is in the ordering columns of the clustered index of a table.
Definition: dict0dict.cc:987
const char * dict_table_get_v_col_name(const dict_table_t *table, ulint col_nr)
Returns a virtual column&#39;s name.
Definition: dict0dict.cc:626
dict_index_t * dict_ind_redundant
dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records
Definition: dict0dict.cc:67
~DDTableBuffer()
Destructor.
Definition: dict0dict.cc:6336
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
Definition: row0upd.h:554
void dict_close(void)
Closes the data dictionary module.
Definition: dict0dict.cc:5880
Allow aborted online index creation.
Definition: dict0dict.h:857
std::atomic< uint32_t > num_dirty_tables
Number of the tables which are of status METADATA_DIRTY.
Definition: dict0dict.h:1272
const char * table_name
Definition: rules_table_service.cc:55
online_index_status
The status of online index creation.
Definition: dict0mem.h:1246
Data structure for an index.
Definition: dict0mem.h:875
void for_each_table(Functor &functor)
Iterate each table.
Definition: dict0dict.h:1144
Expect the tablespace to exist.
Definition: dict0dict.h:109
UNIV_INLINE bool dict_tf2_is_valid(uint32_t flags, uint32_t flags2)
Validate both table flags and table flags2 and make sure they are compatible.