MySQL 8.0.32
Source Code Documentation
dict0dict.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2022, Oracle and/or its affiliates.
4Copyright (c) 2012, Facebook Inc.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License, version 2.0, as published by the
8Free Software Foundation.
9
10This program is also distributed with certain software (including but not
11limited to OpenSSL) that is licensed under separate terms, as designated in a
12particular file or component or in included license documentation. The authors
13of MySQL hereby grant you an additional permission to link the program and
14your derivative works with the separately licensed software that they have
15included with MySQL.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 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 "srv0mon.h" /* for dict0dict.ic */
53#include "sync0rw.h"
54#include "trx0types.h"
55#include "univ.i"
56#include "ut0byte.h"
57#include "ut0mem.h"
58#include "ut0new.h"
59#include "ut0rnd.h"
60
61#define dict_sys_mutex_enter() mutex_enter(&dict_sys->mutex)
62
63#define dict_sys_mutex_exit() mutex_exit(&dict_sys->mutex)
64
65#define dict_sys_mutex_own() mutex_own(&dict_sys->mutex)
66
67#define dict_sys_mutex_free() mutex_free(&dict_sys->mutex)
68/** initial memory heap size when creating a table or index object */
69constexpr uint32_t DICT_HEAP_SIZE = 100;
70
71/** SDI version. Written on Page 1 & 2 at FIL_PAGE_FILE_FLUSH_LSN offset. */
72const uint32_t SDI_VERSION = 1;
73
74/** Space id of system tablespace */
76
77/** Get the database name length in a table name.
78 @return database name length */
79[[nodiscard]] ulint dict_get_db_name_len(
80 const char *name); /*!< in: table name in the form
81 dbname '/' tablename */
82#ifndef UNIV_HOTBACKUP
83/** Frees a foreign key struct. */
85 dict_foreign_t *foreign); /*!< in, own: foreign key struct */
86/** Finds the highest [number] for foreign key constraints of the table. Looks
87 only at the >= 4.0.18-format id's, which are of the form
88 databasename/tablename_ibfk_[number].
89 @return highest number, 0 if table has no new format foreign key constraints */
91 dict_table_t *table); /*!< in: table in the dictionary
92 memory cache */
93#endif /* !UNIV_HOTBACKUP */
94/** Return the end of table name where we have removed dbname and '/'.
95 @return table name */
96[[nodiscard]] const char *dict_remove_db_name(
97 const char *name); /*!< in: table name in the
98 form dbname '/' tablename */
99
100/** Operation to perform when opening a table */
102 /** Expect the tablespace to exist. */
104 /** Drop any orphan indexes after an aborted online index creation */
106 /** Silently load the tablespace if it does not exist,
107 and do not load the definitions of incomplete indexes. */
110
111/** Decrements the count of open handles to a table.
112@param[in,out] table Table
113@param[in] dict_locked True=data dictionary locked
114@param[in] try_drop True=try to drop any orphan indexes after an aborted online
115index creation */
116void dict_table_close(dict_table_t *table, bool dict_locked, bool try_drop);
117
118/** Closes the only open handle to a table and drops a table while assuring
119 that dict_sys->mutex is held the whole time. This assures that the table
120 is not evicted after the close when the count of open handles goes to zero.
121 Because dict_sys->mutex is held, we do not need to call
122 dict_table_prevent_eviction(). */
124 trx_t *trx, /*!< in: data dictionary transaction */
125 dict_table_t *table); /*!< in/out: table */
126/** Inits the data dictionary module. */
127void dict_init(void);
128
129/** Closes the data dictionary module. */
130void dict_close(void);
131
132/** Inits the structure for persisting dynamic metadata */
133void dict_persist_init(void);
134
135/** Clear the structure */
136void dict_persist_close(void);
137
138#ifndef UNIV_HOTBACKUP
139/** Write back the dirty persistent dynamic metadata of the table
140to DDTableBuffer.
141@param[in,out] table table object */
143
144/** Read persistent dynamic metadata stored in a buffer
145@param[in] buffer buffer to read
146@param[in] size size of data in buffer
147@param[in] metadata where we store the metadata from buffer */
148void dict_table_read_dynamic_metadata(const byte *buffer, ulint size,
149 PersistentTableMetadata *metadata);
150
151/** Determine bytes of column prefix to be stored in the undo log. Please
152note that if !dict_table_has_atomic_blobs(table), no prefix
153needs to be stored in the undo log.
154@param[in] table Table.
155@param[in] col Column which index prefix is based on.
156@return bytes of column prefix to be stored in the undo log */
157[[nodiscard]] static inline ulint dict_max_field_len_store_undo(
158 dict_table_t *table, const dict_col_t *col);
159
160/** Determine maximum bytes of a virtual column need to be stored
161in the undo log.
162@param[in] table dict_table_t for the table
163@param[in] col_no virtual column number
164@return maximum bytes of virtual column to be stored in the undo log */
166 ulint col_no);
167
168#endif /* !UNIV_HOTBACKUP */
169/** Gets the column number.
170 @return col->ind, table column position (starting from 0) */
171[[nodiscard]] static inline ulint dict_col_get_no(
172 const dict_col_t *col); /*!< in: column */
173/** Gets the column position in the clustered index.
174@param[in] col Table column.
175@param[in] clust_index Clustered index. */
176[[nodiscard]] static inline ulint dict_col_get_clust_pos(
177 const dict_col_t *col, const dict_index_t *clust_index);
178
179#ifndef UNIV_HOTBACKUP
180/** Gets the column position in the given index.
181@param[in] col table column
182@param[in] index index to be searched for column
183@return position of column in the given index. */
184[[nodiscard]] static inline ulint dict_col_get_index_pos(
185 const dict_col_t *col, const dict_index_t *index) MY_ATTRIBUTE((nonnull));
186
187/** If the given column name is reserved for InnoDB system columns, return
188 true.
189 @return true if name is reserved */
190[[nodiscard]] bool dict_col_name_is_reserved(
191 const char *name); /*!< in: column name */
192/** Acquire the autoinc lock. */
193void dict_table_autoinc_lock(dict_table_t *table); /*!< in/out: table */
194
195/** Unconditionally set the autoinc counter.
196@param[in,out] table Table
197@param[in] value Next value to assign to a row */
198void dict_table_autoinc_initialize(dict_table_t *table, uint64_t value);
199
200/** Reads the next autoinc value (== autoinc counter value), 0 if not yet
201 initialized.
202 @return value for a new row, or 0 */
203[[nodiscard]] uint64_t dict_table_autoinc_read(
204 const dict_table_t *table); /*!< in: table */
205
206/** Updates the autoinc counter if the value supplied is greater than the
207 current value.
208@param[in,out] table Table
209@param[in] value Value which was assigned to a row */
210void dict_table_autoinc_update_if_greater(dict_table_t *table, uint64_t value);
211
212/** Release the autoinc lock. */
213void dict_table_autoinc_unlock(dict_table_t *table); /*!< in/out: table */
214
215/** Update the persisted autoinc counter to specified one, we should hold
216autoinc_persisted_mutex.
217@param[in,out] table table
218@param[in] autoinc set autoinc_persisted to this value */
220 uint64_t autoinc);
221
222/** Set the column position of autoinc column in clustered index for a table.
223@param[in] table table
224@param[in] pos column position in table definition */
226 ulint pos);
227
228/** Write redo logs for autoinc counter that is to be inserted, or to
229update some existing smaller one to bigger.
230@param[in,out] table InnoDB table object
231@param[in] value AUTOINC counter to log
232@param[in,out] mtr Mini-transaction
233@return true if auto increment needs to be persisted to DD table buffer. */
234bool dict_table_autoinc_log(dict_table_t *table, uint64_t value, mtr_t *mtr);
235
236/** Check if a table has an autoinc counter column.
237@param[in] table table
238@return true if there is an autoinc column in the table, otherwise false. */
239static inline bool dict_table_has_autoinc_col(const dict_table_t *table);
240
241#endif /* !UNIV_HOTBACKUP */
242
243/** Adds system columns to a table object.
244@param[in,out] table Table
245@param[in] heap Temporary heap */
247
248#ifndef UNIV_HOTBACKUP
249/** Mark if table has big rows.
250@param[in,out] table table handler */
251void dict_table_set_big_rows(dict_table_t *table) MY_ATTRIBUTE((nonnull));
252
253/** Adds a table object to the dictionary cache.
254@param[in,out] table table
255@param[in] can_be_evicted true if can be evicted */
256void dict_table_add_to_cache(dict_table_t *table, bool can_be_evicted);
257
258/** Removes a table object from the dictionary cache. */
259void dict_table_remove_from_cache(dict_table_t *table); /*!< in, own: table */
260
261/** Try to invalidate an entry from the dict cache, for a partitioned table,
262if any table found.
263@param[in] name Table name */
265
266#ifdef UNIV_DEBUG
267/** Removes a table object from the dictionary cache, for debug purpose
268@param[in,out] table table object
269@param[in] lru_evict true if table being evicted to make room
270 in the table LRU list */
271void dict_table_remove_from_cache_debug(dict_table_t *table, bool lru_evict);
272#endif /* UNIV_DEBUG */
273
274/** Renames a table object.
275 @return true if success */
277 dict_table_t *table, /*!< in/out: table */
278 const char *new_name, /*!< in: new name */
279 bool rename_also_foreigns);
280/*!< in: in ALTER TABLE we want
281to preserve the original table name
282in constraints which reference it */
283
284/** Removes an index from the dictionary cache.
285@param[in,out] table table whose index to remove
286@param[in,out] index index to remove, this object is destroyed and must not
287be accessed by the caller afterwards */
289
290/** Change the id of a table object in the dictionary cache. This is used in
291 DISCARD TABLESPACE. */
293 dict_table_t *table, /*!< in/out: table object already in cache */
294 table_id_t new_id); /*!< in: new id to set */
295/** Removes a foreign constraint struct from the dictionary cache. */
297 dict_foreign_t *foreign); /*!< in, own: foreign constraint */
298/** Adds a foreign key constraint object to the dictionary cache. May free
299 the object if there already is an object with the same identifier in.
300 At least one of foreign table or referenced table must already be in
301 the dictionary cache!
302 @return DB_SUCCESS or error code */
304 dict_foreign_t *foreign,
305 /*!< in, own: foreign key constraint */
306 const char **col_names,
307 /*!< in: column names, or NULL to use
308 foreign->foreign_table->col_names */
309 bool check_charsets,
310 /*!< in: whether to check charset
311 compatibility */
312 bool can_free_fk,
313 /*!< in: whether free existing FK */
314 dict_err_ignore_t ignore_err);
315/*!< in: error to be ignored */
316/** Checks if a table is referenced by foreign keys.
317 @return true if table is referenced by a foreign key */
319 const dict_table_t *table); /*!< in: InnoDB table */
320/** Replace the index passed in with another equivalent index in the
321 foreign key lists of the table.
322 @return whether all replacements were found */
323[[nodiscard]] bool dict_foreign_replace_index(
324 dict_table_t *table, /*!< in/out: table */
325 const char **col_names,
326 /*!< in: column names, or NULL
327 to use table->col_names */
328 const dict_index_t *index); /*!< in: index to be replaced */
329#endif /* !UNIV_HOTBACKUP */
330/** Returns a table object and increments its open handle count.
331 NOTE! This is a high-level function to be used mainly from outside the
332 'dict' directory. Inside this directory dict_table_get_low
333 is usually the appropriate function.
334 @param[in] table_name Table name
335 @param[in] dict_locked true=data dictionary locked
336 @param[in] try_drop true=try to drop any orphan indexes after
337 an aborted online index creation
338 @param[in] ignore_err error to be ignored when loading the table
339 @return table, NULL if does not exist */
341 const char *table_name, bool dict_locked, bool try_drop,
342 dict_err_ignore_t ignore_err);
343
344/** Tries to find an index whose first fields are the columns in the array,
345 in the same order and is not marked for deletion and is not the same
346 as types_idx.
347 @return matching index, NULL if not found */
349 const dict_table_t *table, /*!< in: table */
350 const char **col_names,
351 /*!< in: column names, or NULL
352 to use table->col_names */
353 const char **columns, /*!< in: array of column names */
354 ulint n_cols, /*!< in: number of columns */
355 const dict_index_t *types_idx,
356 /*!< in: NULL or an index
357 whose types the column types
358 must match */
359 bool check_charsets,
360 /*!< in: whether to check
361 charsets. only has an effect
362 if types_idx != NULL */
363 ulint check_null);
364/*!< in: nonzero if none of
365the columns must be declared
366NOT NULL */
367
368/** Returns a virtual column's name.
369@param[in] table target table
370@param[in] col_nr virtual column number (nth virtual column)
371@return column name or NULL if column number out of range. */
372const char *dict_table_get_v_col_name(const dict_table_t *table, ulint col_nr);
373
374/** Check if the table has a given (non_virtual) column.
375@param[in] table table object
376@param[in] col_name column name
377@param[in] col_nr column number guessed, 0 as default
378@return column number if the table has the specified column,
379otherwise table->n_def */
380ulint dict_table_has_column(const dict_table_t *table, const char *col_name,
381 ulint col_nr = 0);
382
383/** Outputs info on a foreign key of a table in a format suitable for
384 CREATE TABLE.
385@param[in] file File where to print
386@param[in] trx Transaction
387@param[in] foreign Foreign key constraint
388@param[in] add_newline Whether to add a newline */
390 dict_foreign_t *foreign,
391 bool add_newline);
392
393/** Tries to find an index whose first fields are the columns in the array,
394 in the same order and is not marked for deletion and is not the same
395 as types_idx.
396 @return matching index, NULL if not found */
397[[nodiscard]] bool dict_foreign_qualify_index(
398 const dict_table_t *table, /*!< in: table */
399 const char **col_names,
400 /*!< in: column names, or NULL
401 to use table->col_names */
402 const char **columns, /*!< in: array of column names */
403 ulint n_cols, /*!< in: number of columns */
404 const dict_index_t *index, /*!< in: index to check */
405 const dict_index_t *types_idx,
406 /*!< in: NULL or an index
407 whose types the column types
408 must match */
409 bool check_charsets,
410 /*!< in: whether to check
411 charsets. only has an effect
412 if types_idx != NULL */
413 ulint check_null);
414/*!< in: nonzero if none of
415the columns must be declared
416NOT NULL */
417
418/* Skip corrupted index */
419static inline void dict_table_skip_corrupt_index(dict_index_t *&index) {
420 while (index && index->is_corrupted()) {
421 index = index->next();
422 }
423}
424
425/* Get the next non-corrupt index */
427 index = index->next();
429}
430
431/** Check if index is auto-generated clustered index.
432@param[in] index index
433
434@return true if index is auto-generated clustered index. */
435static inline bool dict_index_is_auto_gen_clust(const dict_index_t *index);
436
437/** Check whether the index is unique.
438 @return nonzero for unique index, zero for other indexes */
439[[nodiscard]] static inline ulint dict_index_is_unique(
440 const dict_index_t *index); /*!< in: index */
441/** Check whether the index is a Spatial Index.
442 @return nonzero for Spatial Index, zero for other indexes */
443[[nodiscard]] static inline ulint dict_index_is_spatial(
444 const dict_index_t *index); /*!< in: index */
445/** Check whether the index contains a virtual column.
446@param[in] index index
447@return nonzero for index on virtual column, zero for other indexes */
448static inline ulint dict_index_has_virtual(const dict_index_t *index);
449/** Check whether the index is the insert buffer tree.
450 @return nonzero for insert buffer, zero for other indexes */
451[[nodiscard]] static inline ulint dict_index_is_ibuf(
452 const dict_index_t *index); /*!< in: index */
453
454/** Check whether the index consists of descending columns only.
455@param[in] index index tree
456@retval true if index has any descending column
457@retval false if index has only ascending columns */
458[[nodiscard]] static inline bool dict_index_has_desc(const dict_index_t *index);
459/** Check whether the index is a secondary index or the insert buffer tree.
460 @return nonzero for insert buffer, zero for other indexes */
461[[nodiscard]] static inline ulint dict_index_is_sec_or_ibuf(
462 const dict_index_t *index); /*!< in: index */
463
464/** Get all the FTS indexes on a table.
465@param[in] table table
466@param[out] indexes all FTS indexes on this table
467@return number of FTS indexes */
469
471
472/** Gets the number of virtual columns in a table in the dictionary cache.
473@param[in] table the table to check
474@return number of virtual columns of a table */
475static inline ulint dict_table_get_n_v_cols(const dict_table_t *table);
476
477/** Check if a table has indexed virtual columns
478@param[in] table the table to check
479@return true is the table has indexed virtual columns */
480static inline bool dict_table_has_indexed_v_cols(const dict_table_t *table);
481
482#ifndef UNIV_HOTBACKUP
483/** Gets the approximately estimated number of rows in the table.
484 @return estimated number of rows */
485[[nodiscard]] static inline uint64_t dict_table_get_n_rows(
486 const dict_table_t *table); /*!< in: table */
487/** Increment the number of rows in the table by one.
488 Notice that this operation is not protected by any latch, the number is
489 approximate. */
490static inline void dict_table_n_rows_inc(
491 dict_table_t *table); /*!< in/out: table */
492/** Decrement the number of rows in the table by one.
493 Notice that this operation is not protected by any latch, the number is
494 approximate. */
495static inline void dict_table_n_rows_dec(
496 dict_table_t *table); /*!< in/out: table */
497#endif /* !UNIV_HOTBACKUP */
498
499/** Get nth virtual column according to its original MySQL table position
500@param[in] table target table
501@param[in] col_nr column number in MySQL Table definition
502@return dict_v_col_t ptr */
504 ulint col_nr);
505
506#ifdef UNIV_DEBUG
507/** Gets the nth virtual column of a table.
508@param[in] table table
509@param[in] pos position of virtual column
510@return pointer to virtual column object */
512 ulint pos);
513
514#else /* UNIV_DEBUG */
515/* Get nth virtual columns */
516#define dict_table_get_nth_v_col(table, pos) ((table)->v_cols + (pos))
517#endif /* UNIV_DEBUG */
518/** Gets the given system column number of a table.
519@param[in] table Table.
520@param[in] sys DATA_ROW_ID, ...
521@return column number */
522[[nodiscard]] static inline ulint dict_table_get_sys_col_no(
523 const dict_table_t *table, ulint sys);
524/** Check whether the table uses the compact page format.
525 @return true if table uses the compact page format */
526[[nodiscard]] static inline bool dict_table_is_comp(
527 const dict_table_t *table); /*!< in: table */
528
529/** Determine if a table uses atomic BLOBs (no locally stored prefix).
530@param[in] table InnoDB table
531@return whether BLOBs are atomic */
532[[nodiscard]] static inline bool dict_table_has_atomic_blobs(
533 const dict_table_t *table);
534
535#ifndef UNIV_HOTBACKUP
536/** Set the various values in a dict_table_t::flags pointer.
537@param[in,out] flags Pointer to a 4 byte Table Flags
538@param[in] format File Format
539@param[in] zip_ssize Zip Shift Size
540@param[in] use_data_dir Table uses DATA DIRECTORY
541@param[in] shared_space Table uses a General Shared Tablespace */
542static inline void dict_tf_set(uint32_t *flags, rec_format_t format,
543 uint32_t zip_ssize, bool use_data_dir,
544 bool shared_space);
545
546/** Initialize a dict_table_t::flags pointer.
547@param[in] compact Table uses Compact or greater
548@param[in] zip_ssize Zip Shift Size (log 2 minus 9)
549@param[in] atomic_blobs Table uses Compressed or Dynamic
550@param[in] data_dir Table uses DATA DIRECTORY
551@param[in] shared_space Table uses a General Shared Tablespace */
552static inline uint32_t dict_tf_init(bool compact, ulint zip_ssize,
553 bool atomic_blobs, bool data_dir,
554 bool shared_space);
555
556/** Convert a 32 bit integer table flags to the 32 bit FSP Flags.
557Fsp Flags are written into the tablespace header at the offset
558FSP_SPACE_FLAGS and are also stored in the fil_space_t::flags field.
559The following chart shows the translation of the low order bit.
560Other bits are the same.
561========================= Low order bit ==========================
562 | REDUNDANT | COMPACT | COMPRESSED | DYNAMIC
563dict_table_t::flags | 0 | 1 | 1 | 1
564fil_space_t::flags | 0 | 0 | 1 | 1
565==================================================================
566@param[in] table_flags dict_table_t::flags
567@return tablespace flags (fil_space_t::flags) */
568uint32_t dict_tf_to_fsp_flags(uint32_t table_flags);
569
570/** Extract the page size info from table flags.
571@param[in] flags flags
572@return a structure containing the compressed and uncompressed
573page sizes and a boolean indicating if the page is compressed. */
574static inline const page_size_t dict_tf_get_page_size(uint32_t flags);
575
576#endif /* !UNIV_HOTBACKUP */
577
578/** Determine the extent size (in pages) for the given table
579@param[in] table the table whose extent size is being
580 calculated.
581@return extent size in pages (256, 128 or 64) */
583
584/** Get the table page size.
585@param[in] table table
586@return compressed page size, or 0 if not compressed */
587[[nodiscard]] static inline const page_size_t dict_table_page_size(
588 const dict_table_t *table);
589
590#ifndef UNIV_HOTBACKUP
591/** Obtain exclusive locks on all index trees of the table. This is to prevent
592 accessing index trees while InnoDB is updating internal metadata for
593 operations such as FLUSH TABLES. */
594static inline void dict_table_x_lock_indexes(
595 dict_table_t *table); /*!< in: table */
596/** Release the exclusive locks on all index tree. */
598 dict_table_t *table); /*!< in: table */
599/** Check if the table has an FTS index.
600 @return true if table has an FTS index */
601[[nodiscard]] static inline bool dict_table_has_fts_index(
602 dict_table_t *table); /*!< in: table */
603#ifdef UNIV_DEBUG
604/** Validate no active background threads to cause purge or rollback
605 operations. */
607#endif /* UNIV_DEBUG */
608#endif /* !UNIV_HOTBACKUP */
609/** Checks if a column is in the ordering columns of the clustered index of a
610 table. Column prefixes are treated like whole columns.
611 @return true if the column, or its prefix, is in the clustered key */
612[[nodiscard]] bool dict_table_col_in_clustered_key(
613 const dict_table_t *table, /*!< in: table */
614 ulint n); /*!< in: column number */
615/** Copies types of virtual columns contained in table to tuple and sets all
616fields of the tuple to the SQL NULL value. This function should
617be called right after dtuple_create().
618@param[in,out] tuple data tuple
619@param[in] table table */
620void dict_table_copy_v_types(dtuple_t *tuple, const dict_table_t *table);
621/** Copies types of columns contained in table to tuple and sets all
622 fields of the tuple to the SQL NULL value. This function should
623 be called right after dtuple_create(). */
624void dict_table_copy_types(dtuple_t *tuple, /*!< in/out: data tuple */
625 const dict_table_t *table); /*!< in: table */
626#ifndef UNIV_HOTBACKUP
627/********************************************************************
628Wait until all the background threads of the given table have exited, i.e.,
629bg_threads == 0. Note: bg_threads_mutex must be reserved when
630calling this. */
632 dict_table_t *table, /* in: table */
633 std::chrono::microseconds delay); /* in: time to wait between
634 checks of bg_threads. */
635
636/** Look up an index among already opened tables. Does not attempt to open
637tables that are not available in the dictionary cache. This behaviour is fine
638for information schema's scenarios - use dd_table_open_on_id() if you need
639to access index meta-data reliably.
640@param[in] id index identifier
641@return index or NULL if not found */
642[[nodiscard]] const dict_index_t *dict_index_find(const index_id_t &id);
643
644/** Make room in the table cache by evicting an unused table. The unused table
645 should not be part of FK relationship and currently not used in any user
646 transaction. There is no guarantee that it will remove a table.
647 @return number of tables evicted. */
649 ulint max_tables, /*!< in: max tables allowed in cache */
650 ulint pct_check); /*!< in: max percent to check */
651
652constexpr uint32_t BIG_ROW_SIZE = 1024;
653
654/** Adds an index to the dictionary cache.
655@param[in,out] table table on which the index is
656@param[in,out] index index; NOTE! The index memory
657 object is freed in this function!
658@param[in] page_no root page number of the index
659@param[in] strict true=refuse to create the index
660 if records could be too big to fit in
661 an B-tree page
662@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
663[[nodiscard]] dberr_t dict_index_add_to_cache(dict_table_t *table,
664 dict_index_t *index,
665 page_no_t page_no, bool strict);
666
667/** Clears the virtual column's index list before index is being freed.
668@param[in] index Index being freed */
670
671/** Adds an index to the dictionary cache, with possible indexing newly
672added column.
673@param[in,out] table table on which the index is
674@param[in,out] index index; NOTE! The index memory
675 object is freed in this function!
676@param[in] add_v new virtual column that being added along with
677 an add index call
678@param[in] page_no root page number of the index
679@param[in] strict true=refuse to create the index
680 if records could be too big to fit in
681 an B-tree page
682@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
684 dict_table_t *table, dict_index_t *index, const dict_add_v_col_t *add_v,
685 page_no_t page_no, bool strict);
686#endif /* !UNIV_HOTBACKUP */
687/** Gets the number of fields in the internal representation of an index,
688 including fields added by the dictionary system.
689 @return number of fields */
690[[nodiscard]] static inline ulint dict_index_get_n_fields(
691 const dict_index_t *index); /*!< in: an internal
692 representation of index (in
693 the dictionary cache) */
694/** Gets the number of fields in the internal representation of an index
695 that uniquely determine the position of an index entry in the index, if
696 we do not take multiversioning into account: in the B-tree use the value
697 returned by dict_index_get_n_unique_in_tree.
698 @return number of fields */
699[[nodiscard]] static inline ulint dict_index_get_n_unique(
700 const dict_index_t *index); /*!< in: an internal representation
701 of index (in the dictionary cache) */
702/** Gets the number of fields in the internal representation of an index
703 which uniquely determine the position of an index entry in the index, if
704 we also take multiversioning into account.
705 @return number of fields */
706[[nodiscard]] static inline ulint dict_index_get_n_unique_in_tree(
707 const dict_index_t *index); /*!< in: an internal representation
708 of index (in the dictionary cache) */
709
710/** The number of fields in the nonleaf page of spatial index, except
711the page no field. */
712constexpr uint32_t DICT_INDEX_SPATIAL_NODEPTR_SIZE = 1;
713/**
714Gets the number of fields on nonleaf page level in the internal representation
715of an index which uniquely determine the position of an index entry in the
716index, if we also take multiversioning into account. Note, it doesn't
717include page no field.
718@param[in] index index
719@return number of fields */
720[[nodiscard]] static inline uint16_t dict_index_get_n_unique_in_tree_nonleaf(
721 const dict_index_t *index);
722/** Gets the number of user-defined ordering fields in the index. In the
723 internal representation we add the row id to the ordering fields to make all
724 indexes unique, but this function returns the number of fields the user defined
725 in the index as ordering fields.
726 @return number of fields */
728 const dict_index_t *index); /*!< in: an internal representation
729 of index (in the dictionary cache) */
730/** Returns true if the index contains a column or a prefix of that column.
731@param[in] index index
732@param[in] n column number
733@param[in] is_virtual whether it is a virtual col
734@return true if contains the column or its prefix */
735[[nodiscard]] bool dict_index_contains_col_or_prefix(const dict_index_t *index,
736 ulint n, bool is_virtual);
737/** Looks for a matching field in an index. The column has to be the same. The
738 column in index must be complete, or must contain a prefix longer than the
739 column in index2. That is, we must be able to construct the prefix in index2
740 from the prefix in index.
741 @return position in internal representation of the index;
742 ULINT_UNDEFINED if not contained */
744 const dict_index_t *index, /*!< in: index from which to search */
745 const dict_index_t *index2, /*!< in: index */
746 ulint n); /*!< in: field number in index2 */
747/** Looks for non-virtual column n position in the clustered index.
748 @return position in internal representation of the clustered index */
750 const dict_table_t *table, /*!< in: table */
751 ulint n); /*!< in: column number */
752
753/** Get the innodb column position for a non-virtual column according to
754its original MySQL table position n
755@param[in] table table
756@param[in] n MySQL column position
757@return column position in InnoDB */
759
760/** Copies types of fields contained in index to tuple.
761@param[in,out] tuple Data tuple
762@param[in] index Index
763@param[in] n_fields Number of field types to copy */
764void dict_index_copy_types(dtuple_t *tuple, const dict_index_t *index,
765 ulint n_fields);
766
767#ifdef UNIV_DEBUG
768/** Checks that a tuple has n_fields_cmp value in a sensible range, so that
769 no comparison can occur with the page number field in a node pointer.
770 @return true if ok */
771[[nodiscard]] bool dict_index_check_search_tuple(
772 const dict_index_t *index, /*!< in: index tree */
773 const dtuple_t *tuple); /*!< in: tuple used in a search */
774/** Whether and when to allow temporary index names */
776 /** Require all indexes to be complete. */
778 /** Allow aborted online index creation. */
780 /** Allow partial indexes to exist. */
783
784/** Check for duplicate index entries in a table [using the index name]
785@param[in] table Check for dup indexes in this table
786@param[in] check Whether and when to allow temporary index names */
788 enum check_name check);
789
790/** Check if a table is a temporary table with compressed row format,
791we should always expect false.
792@param[in] table table
793@return true if it's a compressed temporary table, false otherwise */
794inline bool dict_table_is_compressed_temporary(const dict_table_t *table);
795#endif /* UNIV_DEBUG */
796/** Builds a node pointer out of a physical record and a page number.
797 @return own: node pointer */
799 const dict_index_t *index, /*!< in: index */
800 const rec_t *rec, /*!< in: record for which
801 to build node pointer */
802 page_no_t page_no, /*!< in: page number to
803 put in node pointer */
804 mem_heap_t *heap, /*!< in: memory heap where
805 pointer created */
806 ulint level); /*!< in: level of rec in tree:
807 0 means leaf level */
808/** Copies an initial segment of a physical record, long enough to specify an
809index entry uniquely. In case buf is nullptr or the buf_size is not enough to
810store the prefix, the new buffer will be allocated.
811@param[in] index index
812@param[in] rec record for which to copy prefix
813@param[out] n_fields number of fields copied
814@param[in,out] buf memory buffer for the copied prefix, or nullptr
815@param[in,out] buf_size buffer size, size of allocated buffer
816@return pointer to the prefix record */
817[[nodiscard]] rec_t *dict_index_copy_rec_order_prefix(const dict_index_t *index,
818 const rec_t *rec,
819 ulint *n_fields,
820 byte **buf,
821 size_t *buf_size);
822/** Builds a typed data tuple out of a physical record.
823 @return own: data tuple */
825 dict_index_t *index, /*!< in: index */
826 rec_t *rec, /*!< in: record for which to build data tuple */
827 ulint n_fields, /*!< in: number of data fields */
828 mem_heap_t *heap); /*!< in: memory heap where tuple created */
829/** Gets the space id of the root of the index tree.
830 @return space id */
831[[nodiscard]] static inline space_id_t dict_index_get_space(
832 const dict_index_t *index); /*!< in: index */
833
834/** Sets the space id of the root of the index tree.
835@param[in,out] index index
836@param[in] space space id */
837static inline void dict_index_set_space(dict_index_t *index, space_id_t space);
838
839/** Gets the page number of the root of the index tree.
840 @return page number */
841[[nodiscard]] static inline page_no_t dict_index_get_page(
842 const dict_index_t *tree); /*!< in: index */
843/** Gets the read-write lock of the index tree.
844 @return read-write lock */
845[[nodiscard]] static inline rw_lock_t *dict_index_get_lock(
846 dict_index_t *index); /*!< in: index */
847/** Returns free space reserved for future updates of records. This is
848 relevant only in the case of many consecutive inserts, as updates
849 which make the records bigger might fragment the index.
850 @return number of free bytes on page, reserved for updates */
852
853/* Online index creation @{ */
854/** Gets the status of online index creation.
855 @return the status */
856[[nodiscard]] static inline enum online_index_status
858 const dict_index_t *index); /*!< in: secondary index */
859
860/** Sets the status of online index creation.
861@param[in,out] index index
862@param[in] status status */
865
866/** Determines if a secondary index is being or has been created online,
867 or if the table is being rebuilt online, allowing concurrent modifications
868 to the table.
869 @retval true if the index is being or has been built online, or
870 if this is a clustered index and the table is being or has been rebuilt online
871 @retval false if the index has been created or the table has been
872 rebuilt completely */
873[[nodiscard]] static inline bool dict_index_is_online_ddl(
874 const dict_index_t *index); /*!< in: index */
875/** Calculates the minimum record length in an index. */
877 const dict_index_t *index); /*!< in: index */
878/** Reserves the dictionary system mutex for MySQL. */
880/** Releases the dictionary system mutex for MySQL. */
882
883#ifndef UNIV_HOTBACKUP
884/** Create a dict_table_t's stats latch or delay for lazy creation.
885This function is only called from either single threaded environment
886or from a thread that has not shared the table object with other threads.
887@param[in,out] table table whose stats latch to create
888@param[in] enabled if false then the latch is disabled
889and dict_table_stats_lock()/unlock() become noop on this table. */
891
892/** Destroy a dict_table_t's stats latch.
893This function is only called from either single threaded environment
894or from a thread that has not shared the table object with other threads.
895@param[in,out] table table whose stats latch to destroy */
897
898/** Lock the appropriate latch to protect a given table's statistics.
899@param[in] table table whose stats to lock
900@param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
901void dict_table_stats_lock(dict_table_t *table, ulint latch_mode);
902
903/** Unlock the latch that has been locked by dict_table_stats_lock().
904@param[in] table table whose stats to unlock
905@param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
906void dict_table_stats_unlock(dict_table_t *table, ulint latch_mode);
907
908/** Checks if the database name in two table names is the same.
909 @return true if same db name */
910[[nodiscard]] bool dict_tables_have_same_db(
911 const char *name1, /*!< in: table name in the
912 form dbname '/' tablename */
913 const char *name2); /*!< in: table name in the
914 form dbname '/' tablename */
915/** Get an index by name.
916@param[in] table the table where to look for the index
917@param[in] name the index name to look for
918@param[in] committed true=search for committed,
919false=search for uncommitted
920@return index, NULL if does not exist */
922 const char *name,
923 bool committed = true);
924/** Get an index by name.
925@param[in] table the table where to look for the index
926@param[in] name the index name to look for
927@param[in] committed true=search for committed,
928false=search for uncommitted
929@return index, NULL if does not exist */
931 const dict_table_t *table, const char *name, bool committed = true) {
932 return (dict_table_get_index_on_name(const_cast<dict_table_t *>(table), name,
933 committed));
934}
935
936/** Check whether a column exists in an FTS index.
937@param[in] indexes Vector containing only FTS indexes
938@param[in] col_no Column number to search for.
939@param[in] is_virtual Whether it is a virtual column.
940@return ULINT_UNDEFINED if no match else the offset within the vector. */
941[[nodiscard]] static inline ulint dict_table_is_fts_column(ib_vector_t *indexes,
942 ulint col_no,
943 bool is_virtual);
944/** Prevent table eviction by moving a table to the non-LRU list from the
945 LRU list if it is not already there. */
947 dict_table_t *table); /*!< in: table to prevent eviction */
948
949/** Allow the table to be evicted by moving a table to the LRU list from
950the non-LRU list if it is not already there.
951@param[in] table InnoDB table object can be evicted */
952static inline void dict_table_allow_eviction(dict_table_t *table);
953
954/** Move this table to non-LRU list for DDL operations if it's
955currently not there. This also prevents later opening table via DD objects,
956when the table name in InnoDB doesn't match with DD object.
957@param[in,out] table Table to put in non-LRU list */
958static inline void dict_table_ddl_acquire(dict_table_t *table);
959
960/** Move this table to LRU list after DDL operations if it was moved
961to non-LRU list
962@param[in,out] table Table to put in LRU list */
963static inline void dict_table_ddl_release(dict_table_t *table);
964
965/** Move a table to the non LRU end of the LRU list. */
967 dict_table_t *table); /*!< in: table to move from LRU to non-LRU */
968
969/** Move a table to the LRU end from the non LRU list.
970@param[in] table InnoDB table object */
972
973/** Move to the most recently used segment of the LRU list. */
974void dict_move_to_mru(dict_table_t *table); /*!< in: table to move to MRU */
975
976/** Maximum number of columns in a foreign key constraint. Please Note MySQL
977has a much lower limit on the number of columns allowed in a foreign key
978constraint */
979constexpr uint32_t MAX_NUM_FK_COLUMNS = 500;
980
981/* Buffers for storing detailed information about the latest foreign key
982and unique key errors */
984extern ib_mutex_t dict_foreign_err_mutex; /* mutex protecting the
985 foreign key error messages */
986#endif /* !UNIV_HOTBACKUP */
987
988/** the dictionary system */
989extern dict_sys_t *dict_sys;
990#ifndef UNIV_HOTBACKUP
991/** the data dictionary rw-latch protecting dict_sys */
993
994/** Forward declaration */
995class DDTableBuffer;
996#endif /* !UNIV_HOTBACKUP */
997struct dict_persist_t;
998
999/** the dictionary persisting structure */
1001
1002/* Dictionary system struct */
1004#ifndef UNIV_HOTBACKUP
1005 DictSysMutex mutex; /*!< mutex protecting the data
1006 dictionary; protects also the
1007 disk-based dictionary system tables;
1008 this mutex serializes CREATE TABLE
1009 and DROP TABLE, as well as reading
1010 the dictionary data for a table from
1011 system tables */
1012#endif /* !UNIV_HOTBACKUP */
1013 row_id_t row_id; /*!< the next row id to assign;
1014 NOTE that at a checkpoint this
1015 must be written to the dict system
1016 header and flushed to a file; in
1017 recovery this must be derived from
1018 the log records */
1019 hash_table_t *table_hash; /*!< hash table of the tables, based
1020 on name */
1021 hash_table_t *table_id_hash; /*!< hash table of the tables, based
1022 on id */
1023 size_t size; /*!< varying space in bytes occupied
1024 by the data dictionary table and
1025 index objects */
1026 /** Handler to sys_* tables, they're only for upgrade */
1027 dict_table_t *sys_tables; /*!< SYS_TABLES table */
1028 dict_table_t *sys_columns; /*!< SYS_COLUMNS table */
1029 dict_table_t *sys_indexes; /*!< SYS_INDEXES table */
1030 dict_table_t *sys_fields; /*!< SYS_FIELDS table */
1031 dict_table_t *sys_virtual; /*!< SYS_VIRTUAL table */
1032
1033 /** Permanent handle to mysql.innodb_table_stats */
1035 /** Permanent handle to mysql.innodb_index_stats */
1037 /** Permanent handle to mysql.innodb_ddl_log */
1039 /** Permanent handle to mysql.innodb_dynamic_metadata */
1042
1043 /** List of tables that can be evicted from the cache */
1045 /** List of tables that can't be evicted from the cache */
1047
1048 /** Iterate each table.
1049 @tparam Functor visitor
1050 @param[in,out] functor to be invoked on each table */
1051 template <typename Functor>
1052 void for_each_table(Functor &functor) {
1054
1056 const auto n_cells = hash->get_n_cells();
1057 for (ulint i = 0; i < n_cells; i++) {
1058 for (dict_table_t *table =
1059 static_cast<dict_table_t *>(hash_get_first(hash, i));
1060 table;
1061 table = static_cast<dict_table_t *>(HASH_GET_NEXT(id_hash, table))) {
1062 functor(table);
1063 }
1064 }
1065
1066 mutex_exit(&mutex);
1067 }
1068
1069 /** Check if a tablespace id is a reserved tablespace ID
1070 @param[in] space tablespace id to check
1071 @return true if a reserved tablespace id, otherwise false */
1072 static bool is_reserved(space_id_t space) {
1073 return (space >= dict_sys_t::s_reserved_space_id);
1074 }
1075
1076 /** Set of ids of DD tables */
1077 static std::set<dd::Object_id> s_dd_table_ids;
1078
1079 /** Check if a table is hardcoded. it only includes the dd tables
1080 @param[in] id table ID
1081 @retval true if the table is a persistent hard-coded table
1082 (dict_table_t::is_temporary() will not hold)
1083 @retval false if the table is not hard-coded
1084 (it can be persistent or temporary) */
1085 static bool is_dd_table_id(table_id_t id) {
1086 return (s_dd_table_ids.find(id) != s_dd_table_ids.end());
1087 }
1088
1089 /** The first ID of the redo log pseudo-tablespace */
1090 static constexpr space_id_t s_log_space_id = 0xFFFFFFF0UL;
1091
1092 /** Use maximum UINT value to indicate invalid space ID. */
1093 static constexpr space_id_t s_invalid_space_id = 0xFFFFFFFF;
1094
1095 /** The data dictionary tablespace ID. */
1096 static constexpr space_id_t s_dict_space_id = 0xFFFFFFFE;
1097
1098 /** The innodb_temporary tablespace ID. */
1099 static constexpr space_id_t s_temp_space_id = 0xFFFFFFFD;
1100
1101 /** The number of space IDs dedicated to each undo tablespace */
1102 static constexpr space_id_t s_undo_space_id_range = 400000;
1103
1104 /** The lowest undo tablespace ID. */
1107
1108 /** The highest undo tablespace ID. */
1110
1111 /** Start space_ids for temporary tablespaces. */
1113
1114 /** The number of space IDs dedicated to temporary tablespaces */
1115 static constexpr space_id_t s_temp_space_id_range = 400000;
1116
1117 /** Lowest temporary general space id */
1120
1121 /** The first reserved tablespace ID */
1123
1124 /** The dd::Tablespace::id of the dictionary tablespace. */
1125 static constexpr dd::Object_id s_dd_dict_space_id = 1;
1126
1127 /** The dd::Tablespace::id of innodb_system. */
1128 static constexpr dd::Object_id s_dd_sys_space_id = 2;
1129
1130 /** The dd::Tablespace::id of innodb_temporary. */
1131 static constexpr dd::Object_id s_dd_temp_space_id = 3;
1132
1133 /** The name of the data dictionary tablespace. */
1134 static const char *s_dd_space_name;
1135
1136 /** The file name of the data dictionary tablespace. */
1137 static const char *s_dd_space_file_name;
1138
1139 /** The name of the hard-coded system tablespace. */
1140 static const char *s_sys_space_name;
1141
1142 /** The name of the predefined temporary tablespace. */
1143 static const char *s_temp_space_name;
1144
1145 /** The file name of the predefined temporary tablespace. */
1146 static const char *s_temp_space_file_name;
1147
1148 /** The hard-coded tablespace name innodb_file_per_table. */
1149 static const char *s_file_per_table_name;
1150
1151 /** These two undo tablespaces cannot be dropped. */
1154
1155 /** The table ID of mysql.innodb_dynamic_metadata */
1157
1158 /** The clustered index ID of mysql.innodb_dynamic_metadata */
1160};
1161
1162/** Structure for persisting dynamic metadata of data dictionary */
1164#ifndef UNIV_HOTBACKUP
1165 /** Write dynamic metadata to DD buffer table immediately when such data is
1166 generated. By default, the metadata is first written to redo log and then to
1167 the DD buffer table during checkpoint. This is going to hurt auto increment
1168 performance and Currently enabled by clone for short time to eliminate
1169 dependency with dynamic metadata recovered from redo log. */
1171 public:
1172 /** Constructor to immediate persisting mode.
1173 @param[in,out] persister dictionary persister */
1174 Enable_immediate(dict_persist_t *persister);
1175
1176 /** Destructor to switch back to default mode. */
1178
1179 /** Disable copy construction */
1181
1182 /** Disable assignment */
1184
1185 private:
1186 /** Dictionary persister */
1188 };
1189
1190 /** @return true if need to write dynamic metadata to DD buffer table
1191 immediately after logging. */
1193 return m_persist_immediately.load();
1194 }
1195
1196 /** List of tables whose dirty_status are marked as METADATA_DIRTY,
1197 or METADATA_BUFFERED. It's protected by the mutex */
1200#endif
1201
1202 /** Mutex to protect data in this structure, also the
1203 dict_table_t::dirty_status and
1204 dict_table_t::in_dirty_dict_tables_list
1205 This mutex should be low-level one so that it can be used widely
1206 when necessary, so its level had to be above SYNC_LOG. However,
1207 after this mutex, persister may have to access B-tree and require
1208 tree latch, the latch level of this mutex then has to be right
1209 before the SYNC_INDEX_TREE. */
1210 ib_mutex_t mutex;
1211
1212 /** Number of the tables which are of status METADATA_DIRTY.
1213 It's protected by the mutex */
1214 std::atomic<uint32_t> num_dirty_tables;
1215
1216 /** If set, dynamic metadata is saved to DD buffer table immediately.
1217 Currently we consider only auto increment PM_TABLE_AUTO_INC. Corrupt
1218 index PM_INDEX_CORRUPTED is not needed to be saved immediately. */
1219 std::atomic<bool> m_persist_immediately;
1220
1221#ifndef UNIV_HOTBACKUP
1222 /** DDTableBuffer table for persistent dynamic metadata */
1224#endif /* !UNIV_HOTBACKUP */
1225
1226 /** Collection of instances to persist dynamic metadata */
1228};
1229
1230#ifndef UNIV_HOTBACKUP
1231/** dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records */
1233
1234/** Inits dict_ind_redundant. */
1235void dict_ind_init(void);
1236
1237/** Converts a database and table name from filesystem encoding (e.g.
1238"@code d@i1b/a@q1b@1Kc @endcode", same format as used in dict_table_t::name)
1239in two strings in UTF8MB3 encoding (e.g. dцb and aюbØc). The output buffers must
1240be at least MAX_DB_UTF8MB3_LEN and MAX_TABLE_UTF8MB3_LEN bytes.
1241@param[in] db_and_table database and table names,
1242 e.g. "@code d@i1b/a@q1b@1Kc @endcode"
1243@param[out] db_utf8mb3 database name, e.g. dцb
1244@param[in] db_utf8mb3_size db_utf8mb3 size
1245@param[out] table_utf8mb3 table name, e.g. aюbØc
1246@param[in] table_utf8mb3_size table_utf8mb3 size */
1247void dict_fs2utf8(const char *db_and_table, char *db_utf8mb3,
1248 size_t db_utf8mb3_size, char *table_utf8mb3,
1249 size_t table_utf8mb3_size);
1250
1251/** Resize the hash tables based on the current buffer pool size. */
1252void dict_resize();
1253
1254/** Wrapper for the mysql.innodb_dynamic_metadata used to buffer the persistent
1255dynamic metadata.
1256This should be a table with only clustered index, no delete-marked records,
1257no locking, no undo logging, no purge, no adaptive hash index.
1258We should always use low level btr functions to access and modify the table.
1259Accessing this table should be protected by dict_sys->mutex */
1261 public:
1262 /** Default constructor */
1263 DDTableBuffer();
1264
1265 /** Destructor */
1267
1268 /** Replace the dynamic metadata for a specific table
1269 @param[in] id table id
1270 @param[in] version table dynamic metadata version
1271 @param[in] metadata the metadata we want to replace
1272 @param[in] len the metadata length
1273 @return DB_SUCCESS or error code */
1274 dberr_t replace(table_id_t id, uint64_t version, const byte *metadata,
1275 size_t len);
1276
1277 /** Remove the whole row for a specific table
1278 @param[in] id table id
1279 @return DB_SUCCESS or error code */
1281
1282 /** Truncate the table. We can call it after all the dynamic
1283 metadata has been written back to DD table */
1284 void truncate(void);
1285
1286 /** Get the buffered metadata for a specific table, the caller
1287 has to delete the returned std::string object by ut::delete_
1288 @param[in] id table id
1289 @param[out] version table dynamic metadata version
1290 @return the metadata saved in a string object, if nothing, the
1291 string would be of length 0 */
1292 std::string *get(table_id_t id, uint64_t *version);
1293
1294 private:
1295 /** Initialize m_index, the in-memory clustered index of the table
1296 and two tuples used in this class */
1297 void init();
1298
1299 /** Open the mysql.innodb_dynamic_metadata when DD is not fully up */
1300 void open();
1301
1302 /** Create the search and replace tuples */
1303 void create_tuples();
1304
1305 /** Initialize the id field of tuple
1306 @param[out] tuple the tuple to be initialized
1307 @param[in] id table id */
1308 void init_tuple_with_id(dtuple_t *tuple, table_id_t id);
1309
1310 /** Free the things initialized in init() */
1311 void close();
1312
1313 /** Prepare for a update on METADATA field
1314 @param[in] entry clustered index entry to replace rec
1315 @param[in] rec clustered index record
1316 @return update vector of differing fields without system columns,
1317 or NULL if there isn't any different field */
1318 upd_t *update_set_metadata(const dtuple_t *entry, const rec_t *rec);
1319
1320 private:
1321 /** The clustered index of this system table */
1323
1324 /** The heap used for dynamic allocations, which should always
1325 be freed before return */
1327
1328 /** The heap used during replace() operation, which should always
1329 be freed before return */
1331
1332 /** The heap used to create the search tuple and replace tuple */
1334
1335 /** The tuple used to search for specified table, it's protected
1336 by dict_persist->mutex */
1338
1339 /** The tuple used to replace for specified table, it's protected
1340 by dict_persist->mutex */
1342
1343 private:
1344 /** Column number of mysql.innodb_dynamic_metadata.table_id */
1345 static constexpr unsigned TABLE_ID_COL_NO = 0;
1346
1347 /** Column number of mysql.innodb_dynamic_metadata.version */
1348 static constexpr unsigned VERSION_COL_NO = 1;
1349
1350 /** Column number of mysql.innodb_dynamic_metadata.metadata */
1351 static constexpr unsigned METADATA_COL_NO = 2;
1352
1353 /** Number of user columns */
1354 static constexpr unsigned N_USER_COLS = METADATA_COL_NO + 1;
1355
1356 /** Number of columns */
1357 static constexpr unsigned N_COLS = N_USER_COLS + DATA_N_SYS_COLS;
1358
1359 /** Clustered index field number of
1360 mysql.innodb_dynamic_metadata.table_id */
1361 static constexpr unsigned TABLE_ID_FIELD_NO = TABLE_ID_COL_NO;
1362
1363 /** Clustered index field number of
1364 mysql.innodb_dynamic_metadata.version */
1365 static constexpr unsigned VERSION_FIELD_NO = VERSION_COL_NO + 2;
1366
1367 /** Clustered index field number of
1368 mysql.innodb_dynamic_metadata.metadata
1369 Plusing 2 here skips the DATA_TRX_ID and DATA_ROLL_PTR fields */
1370 static constexpr unsigned METADATA_FIELD_NO = METADATA_COL_NO + 2;
1371
1372 /** Number of fields in the clustered index */
1373 static constexpr unsigned N_FIELDS = METADATA_FIELD_NO + 1;
1374};
1375
1376/** Mark the dirty_status of a table as METADATA_DIRTY, and add it to the
1377dirty_dict_tables list if necessary.
1378@param[in,out] table table */
1380#endif /* !UNIV_HOTBACKUP */
1381
1382/** Flags an index corrupted in the data dictionary cache only. This
1383is used to mark a corrupted index when index's own dictionary
1384is corrupted, and we would force to load such index for repair purpose.
1385Besides, we have to write a redo log.
1386We don't want to hold dict_sys->mutex here, so that we can set index as
1387corrupted in some low-level functions. We would only set the flags from
1388not corrupted to corrupted when server is running, so it should be safe
1389to set it directly.
1390@param[in,out] index index, must not be NULL */
1392
1393#ifndef UNIV_HOTBACKUP
1394
1395/** Check if there is any latest persistent dynamic metadata recorded
1396in DDTableBuffer table of the specific table. If so, read the metadata and
1397update the table object accordingly. It's used when loading table.
1398@param[in] table table object */
1400
1401/** Check if any table has any dirty persistent data, if so
1402write dirty persistent data of table to mysql.innodb_dynamic_metadata
1403accordingly. */
1405#endif /* !UNIV_HOTBACKUP */
1406
1407/** Apply the persistent dynamic metadata read from redo logs or
1408DDTableBuffer to corresponding table during recovery.
1409@param[in,out] table table
1410@param[in] metadata structure of persistent metadata
1411@return true if we do apply something to the in-memory table object,
1412otherwise false */
1414 const PersistentTableMetadata *metadata);
1415
1416#ifndef UNIV_HOTBACKUP
1417/** Sets merge_threshold in the SYS_INDEXES
1418@param[in,out] index index
1419@param[in] merge_threshold value to set */
1421
1422#ifdef UNIV_DEBUG
1423/** Sets merge_threshold for all indexes in dictionary cache for debug.
1424@param[in] merge_threshold_all value to set for all indexes */
1425void dict_set_merge_threshold_all_debug(uint merge_threshold_all);
1426#endif /* UNIV_DEBUG */
1427
1428/** Validate the table flags.
1429@param[in] flags Table flags
1430@return true if valid. */
1431static inline bool dict_tf_is_valid(uint32_t flags);
1432
1433/** Validate both table flags and table flags2 and make sure they
1434are compatible.
1435@param[in] flags Table flags
1436@param[in] flags2 Table flags2
1437@return true if valid. */
1438static inline bool dict_tf2_is_valid(uint32_t flags, uint32_t flags2);
1439
1440/** Check if the tablespace for the table has been discarded.
1441 @return true if the tablespace has been discarded. */
1442[[nodiscard]] static inline bool dict_table_is_discarded(
1443 const dict_table_t *table); /*!< in: table to check */
1444
1445/** Check whether the table is DDTableBuffer. See class DDTableBuffer
1446@param[in] table table to check
1447@return true if this is a DDTableBuffer table. */
1448static inline bool dict_table_is_table_buffer(const dict_table_t *table);
1449
1450/** Check if the table is in a shared tablespace (System or General).
1451@param[in] table table to check
1452@return true if table is a shared tablespace, false if not. */
1453[[nodiscard]] static inline bool dict_table_in_shared_tablespace(
1454 const dict_table_t *table);
1455
1456/** Check whether locking is disabled for this table.
1457Currently this is done for intrinsic table as their visibility is limited
1458to the connection and the DDTableBuffer as it's protected by
1459dict_persist->mutex.
1460
1461@param[in] table table to check
1462@return true if locking is disabled. */
1463[[nodiscard]] static inline bool dict_table_is_locking_disabled(
1464 const dict_table_t *table);
1465
1466/** Turn-off redo-logging if temporary table.
1467@param[in] table Table to check
1468@param[out] mtr Mini-transaction */
1469static inline void dict_disable_redo_if_temporary(const dict_table_t *table,
1470 mtr_t *mtr);
1471
1472/** Get table session row-id and increment the row-id counter for next use.
1473@param[in,out] table table handler
1474@return next table local row-id. */
1476 dict_table_t *table);
1477
1478/** Get table session trx-id and increment the trx-id counter for next use.
1479@param[in,out] table table handler
1480@return next table local trx-id. */
1482 dict_table_t *table);
1483
1484/** Get current session trx-id.
1485@param[in] table table handler
1486@return table local trx-id. */
1488 const dict_table_t *table);
1489
1490/** This function should be called whenever a page is successfully
1491 compressed. Updates the compression padding information. */
1493 dict_index_t *index); /*!< in/out: index to be updated. */
1494/** This function should be called whenever a page compression attempt
1495 fails. Updates the compression padding information. */
1497 dict_index_t *index); /*!< in/out: index to be updated. */
1498/** Return the optimal page size, for which page will likely compress.
1499 @return page size beyond which page may not compress*/
1501 dict_index_t *index); /*!< in: index for which page size
1502 is requested */
1503/** Convert table flag to row format string.
1504 @return row format name */
1506 uint32_t table_flag); /*!< in: row format setting */
1507/** Return maximum size of the node pointer record.
1508 @return maximum size of the record in bytes */
1510 const dict_index_t *index); /*!< in: index */
1511
1512/** Get index by first field of the index.
1513@param[in] table table
1514@param[in] col_index position of column in table
1515@return index which is having first field matches with the field present in
1516field_index position of table */
1518 dict_table_t *table, ulint col_index);
1519#endif /* !UNIV_HOTBACKUP */
1520
1521/** encode number of columns and number of virtual columns in one
15224 bytes value. We could do this because the number of columns in
1523InnoDB is limited to 1017
1524@param[in] n_col number of non-virtual column
1525@param[in] n_v_col number of virtual column
1526@return encoded value */
1527static inline ulint dict_table_encode_n_col(ulint n_col, ulint n_v_col);
1528
1529/** Decode number of virtual and non-virtual columns in one 4 bytes value.
1530@param[in] encoded encoded value
1531@param[in,out] n_col number of non-virtual column
1532@param[in,out] n_v_col number of virtual column */
1533static inline void dict_table_decode_n_col(uint32_t encoded, uint32_t *n_col,
1534 uint32_t *n_v_col);
1535
1536/** Free the virtual column template
1537@param[in,out] vc_templ virtual column template */
1538static inline void dict_free_vc_templ(dict_vcol_templ_t *vc_templ);
1539
1540/** Returns a virtual column's name according to its original
1541MySQL table position.
1542@param[in] table target table
1543@param[in] col_nr column number (nth column in the table)
1544@return column name. */
1545const char *dict_table_get_v_col_name_mysql(const dict_table_t *table,
1546 ulint col_nr);
1547
1548/** Check whether the table have virtual index.
1549@param[in] table InnoDB table
1550@return true if the table have virtual index, false otherwise. */
1552
1553/** Retrieve in-memory index for SDI table.
1554@param[in] tablespace_id innodb tablespace ID
1555@return dict_index_t structure or NULL*/
1557
1558/** Retrieve in-memory table object for SDI table.
1559@param[in] tablespace_id innodb tablespace ID
1560@param[in] dict_locked true if dict_sys mutex is acquired
1561@param[in] is_create true when creating SDI Index
1562@return dict_table_t structure */
1563dict_table_t *dict_sdi_get_table(space_id_t tablespace_id, bool dict_locked,
1564 bool is_create);
1565
1566/** Remove the SDI table from table cache.
1567@param[in] space_id InnoDB tablespace ID
1568@param[in] sdi_table SDI table
1569@param[in] dict_locked true if dict_sys mutex acquired */
1570void dict_sdi_remove_from_cache(space_id_t space_id, dict_table_t *sdi_table,
1571 bool dict_locked);
1572
1573/** Check if the index is SDI index
1574@param[in] index in-memory index structure
1575@return true if index is SDI index else false */
1576static inline bool dict_index_is_sdi(const dict_index_t *index);
1577
1578/** Check if an table id belongs SDI table
1579@param[in] table_id dict_table_t id
1580@return true if table_id is SDI table_id else false */
1581static inline bool dict_table_is_sdi(uint64_t table_id);
1582
1583/** Close SDI table.
1584@param[in] table the in-memory SDI table object */
1586
1587/** Acquire exclusive MDL on SDI tables. This is acquired to
1588prevent concurrent DROP table/tablespace when there is purge
1589happening on SDI table records. Purge will acquire shared
1590MDL on SDI table.
1591
1592Exclusive MDL is transactional(released on trx commit). So
1593for successful acquisition, there should be a valid thd associated
1594with a trx.
1595
1596Acquisition order of SDI MDL and SDI table has to be in the same
1597order:
1598
15991. dd_sdi_acquire_exclusive_mdl
16002. row_drop_table_from_cache()/innodb_drop_tablespace()
1601 ->dict_sdi_remove_from_cache()->dd_table_open_on_id()
1602
1603In purge:
1604
16051. dd_sdi_acquire_shared_mdl
16062. dd_table_open_on_id()
1607
1608@param[in] thd server thread instance
1609@param[in] space_id InnoDB tablespace id
1610@param[in,out] sdi_mdl MDL ticket on SDI table
1611@retval DB_SUCESS on success
1612@retval DB_LOCK_WAIT_TIMEOUT on error */
1614 MDL_ticket **sdi_mdl);
1615
1616/** Acquire shared MDL on SDI tables. This is acquired by purge to
1617prevent concurrent DROP table/tablespace.
1618DROP table/tablespace will acquire exclusive MDL on SDI table
1619
1620Acquisition order of SDI MDL and SDI table has to be in same
1621order:
1622
16231. dd_sdi_acquire_exclusive_mdl
16242. row_drop_table_from_cache()/innodb_drop_tablespace()
1625 ->dict_sdi_remove_from_cache()->dd_table_open_on_id()
1626
1627In purge:
1628
16291. dd_sdi_acquire_shared_mdl
16302. dd_table_open_on_id()
1631
1632MDL should be released by caller
1633@param[in] thd server thread instance
1634@param[in] space_id InnoDB tablespace id
1635@param[in,out] sdi_mdl MDL ticket on SDI table
1636@retval DB_SUCESS on success
1637@retval DB_LOCK_WAIT_TIMEOUT on error */
1639 MDL_ticket **sdi_mdl);
1640
1641/** Check whether the dict_table_t is a partition.
1642A partitioned table on the SQL level is composed of InnoDB tables,
1643where each InnoDB table is a [sub]partition including its secondary indexes
1644which belongs to the partition.
1645@param[in] table Table to check.
1646@return true if the dict_table_t is a partition else false. */
1647static inline bool dict_table_is_partition(const dict_table_t *table);
1648
1649/** Allocate memory for intrinsic cache elements in the index
1650@param[in] index index object */
1652
1653/** Evict all tables that are loaded for applying purge.
1654Since we move the offset of all table ids during upgrade,
1655these tables cannot exist in cache. Also change table_ids
1656of SYS_* tables if they are upgraded from earlier versions */
1658
1659/** @return true if table is InnoDB SYS_* table
1660@param[in] table_id table id */
1661bool dict_table_is_system(table_id_t table_id);
1662
1663/** Build the table_id array of SYS_* tables. This
1664array is used to determine if a table is InnoDB SYSTEM
1665table or not.
1666@return true if successful, false otherwise */
1668
1669/** Change the table_id of SYS_* tables if they have been created after
1670an earlier upgrade. This will update the table_id by adding DICT_MAX_DD_TABLES
1671*/
1673
1674/** Get the tablespace data directory if set, otherwise empty string.
1675@return the data directory */
1676[[nodiscard]] std::string dict_table_get_datadir(const dict_table_t *table);
1677
1678/** Set the compression type for the tablespace of a table
1679@param[in] table The table that should be compressed
1680@param[in] algorithm Text representation of the algorithm
1681@param[in] is_import_op True if it's being set during import operation
1682@return DB_SUCCESS or error code */
1683[[nodiscard]] dberr_t dict_set_compression(dict_table_t *table,
1684 const char *algorithm,
1685 bool is_import_op);
1686
1687/** @return true if all base column of virtual column is foreign key column
1688@param[in] vcol in-memory virtual column
1689@param[in] foreign in-memory Foreign key constraint */
1691 dict_foreign_t *foreign);
1692
1693/** Get maximum possible size needed for a field.
1694@param[in] table innodb table definition cache
1695@param[in] index index
1696@param[in] field field
1697@param[out] rec_max_size max record size needed */
1698void get_field_max_size(const dict_table_t *table, const dict_index_t *index,
1699 const dict_field_t *field, size_t &rec_max_size);
1700
1701/** Get the maximum size of a record permissible on an index page.
1702@param[in] table innodb table definition cache
1703@param[in] index index
1704@param[out] page_rec_max maximum size of record on a leaf page
1705@param[out] page_ptr_max maximum size of record on non-leaf page */
1706void get_permissible_max_size(const dict_table_t *table,
1707 const dict_index_t *index, size_t &page_rec_max,
1708 size_t &page_ptr_max);
1709
1710/** validate that maximum possible size of a row is within permissible limit.
1711@param[in] table innodb table definition cache
1712@param[in] index index
1713@param[in] strict true if error is to be reported
1714@param[in] page_rec_max maximum size of possible record on leaf page
1715@param[in] page_ptr_max maximum size of possible record on non-leaf page
1716@param[out] rec_max_size maximum size of record on page
1717@return true if max record size is within limit, false otherwise. */
1719 const dict_index_t *index, bool strict,
1720 const size_t page_rec_max,
1721 const size_t page_ptr_max,
1722 size_t &rec_max_size);
1723
1724#include "dict0dict.ic"
1725
1726#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:50
uint32_t page_no_t
Page number.
Definition: api0api.h:48
Wrapper for the mysql.innodb_dynamic_metadata used to buffer the persistent dynamic metadata.
Definition: dict0dict.h:1260
~DDTableBuffer()
Destructor.
Definition: dict0dict.cc:5070
static constexpr unsigned N_USER_COLS
Number of user columns.
Definition: dict0dict.h:1354
void init_tuple_with_id(dtuple_t *tuple, table_id_t id)
Initialize the id field of tuple.
Definition: dict0dict.cc:5225
std::string * get(table_id_t id, uint64_t *version)
Get the buffered metadata for a specific table, the caller has to delete the returned std::string obj...
Definition: dict0dict.cc:5420
static constexpr unsigned TABLE_ID_COL_NO
Column number of mysql.innodb_dynamic_metadata.table_id.
Definition: dict0dict.h:1345
mem_heap_t * m_replace_heap
The heap used during replace() operation, which should always be freed before return.
Definition: dict0dict.h:1330
void create_tuples()
Create the search and replace tuples.
Definition: dict0dict.cc:5073
dict_index_t * m_index
The clustered index of this system table.
Definition: dict0dict.h:1322
void init()
Initialize m_index, the in-memory clustered index of the table and two tuples used in this class.
Definition: dict0dict.cc:5116
static constexpr unsigned METADATA_COL_NO
Column number of mysql.innodb_dynamic_metadata.metadata.
Definition: dict0dict.h:1351
static constexpr unsigned VERSION_FIELD_NO
Clustered index field number of mysql.innodb_dynamic_metadata.version.
Definition: dict0dict.h:1365
DDTableBuffer()
Default constructor.
Definition: dict0dict.cc:5062
dtuple_t * m_replace_tuple
The tuple used to replace for specified table, it's protected by dict_persist->mutex.
Definition: dict0dict.h:1341
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:1370
void close()
Free the things initialized in init()
Definition: dict0dict.cc:5234
upd_t * update_set_metadata(const dtuple_t *entry, const rec_t *rec)
Prepare for a update on METADATA field.
Definition: dict0dict.cc:5248
void open()
Open the mysql.innodb_dynamic_metadata when DD is not fully up.
Definition: dict0dict.cc:5142
static constexpr unsigned TABLE_ID_FIELD_NO
Clustered index field number of mysql.innodb_dynamic_metadata.table_id.
Definition: dict0dict.h:1361
static constexpr unsigned N_COLS
Number of columns.
Definition: dict0dict.h:1357
static constexpr unsigned N_FIELDS
Number of fields in the clustered index.
Definition: dict0dict.h:1373
dtuple_t * m_search_tuple
The tuple used to search for specified table, it's protected by dict_persist->mutex.
Definition: dict0dict.h:1337
void truncate(void)
Truncate the table.
Definition: dict0dict.cc:5408
dberr_t remove(table_id_t id)
Remove the whole row for a specific table.
Definition: dict0dict.cc:5377
mem_heap_t * m_dynamic_heap
The heap used for dynamic allocations, which should always be freed before return.
Definition: dict0dict.h:1326
mem_heap_t * m_heap
The heap used to create the search tuple and replace tuple.
Definition: dict0dict.h:1333
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:5297
static constexpr unsigned VERSION_COL_NO
Column number of mysql.innodb_dynamic_metadata.version.
Definition: dict0dict.h:1348
A granted metadata lock.
Definition: mdl.h:983
Persistent dynamic metadata for a table.
Definition: dict0mem.h:2753
Container of persisters used in the system.
Definition: dict0mem.h:2940
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Write dynamic metadata to DD buffer table immediately when such data is generated.
Definition: dict0dict.h:1170
~Enable_immediate()
Destructor to switch back to default mode.
Definition: dict0dict.cc:6086
Enable_immediate(dict_persist_t *persister)
Constructor to immediate persisting mode.
Definition: dict0dict.cc:6076
Enable_immediate & operator=(Enable_immediate const &)=delete
Disable assignment.
Enable_immediate(Enable_immediate const &)=delete
Disable copy construction.
dict_persist_t * m_persister
Dictionary persister.
Definition: dict0dict.h:1187
Definition: hash0hash.h:373
size_t get_n_cells()
Returns number of cells in cells[] array.
Definition: hash0hash.h:391
Globally unique index identifier.
Definition: dict0types.h:222
Page size descriptor.
Definition: page0size.h:49
constexpr DWORD buf_size
Definition: create_def.cc:227
SQL data field and tuple.
Data types.
constexpr uint32_t DATA_N_SYS_COLS
number of system columns defined above
Definition: data0type.h:193
dberr_t
Definition: db0err.h:38
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:5020
static void dict_free_vc_templ(dict_vcol_templ_t *vc_templ)
Free the virtual column template.
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:1838
bool 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:757
void dict_init(void)
Inits the data dictionary module.
Definition: dict0dict.cc:1008
constexpr uint32_t BIG_ROW_SIZE
Definition: dict0dict.h:652
static 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.
constexpr uint32_t DICT_INDEX_SPATIAL_NODEPTR_SIZE
The number of fields in the nonleaf page of spatial index, except the page no field.
Definition: dict0dict.h:712
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:5977
ulint dict_get_db_name_len(const char *name)
Get the database name length in a table name.
Definition: dict0dict.cc:294
void dict_print_info_on_foreign_key_in_create_format(FILE *file, trx_t *trx, dict_foreign_t *foreign, bool add_newline)
Outputs info on a foreign key of a table in a format suitable for CREATE TABLE.
Definition: dict0dict.cc:3799
static 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.
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:3566
static bool dict_index_has_desc(const dict_index_t *index)
Check whether the index consists of descending columns only.
static void dict_index_set_space(dict_index_t *index, space_id_t space)
Sets the space id of the root of the index tree.
static ulint dict_table_get_sys_col_no(const dict_table_t *table, ulint sys)
Gets the given system column number of a table.
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:950
static void dict_table_next_uncorrupted_index(dict_index_t *&index)
Definition: dict0dict.h:426
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:1975
const char * dict_remove_db_name(const char *name)
Return the end of table name where we have removed dbname and '/'.
Definition: dict0dict.cc:282
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:4758
static 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 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...
dberr_t dict_table_rename_in_cache(dict_table_t *table, const char *new_name, bool rename_also_foreigns)
Renames a table object.
Definition: dict0dict.cc:1461
void dict_mutex_exit_for_mysql(void)
Releases the dictionary system mutex for MySQL.
Definition: dict0dict.cc:310
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:4975
bool 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:266
static bool dict_table_in_shared_tablespace(const dict_table_t *table)
Check if the table is in a shared tablespace (System or General).
void dict_close(void)
Closes the data dictionary module.
Definition: dict0dict.cc:4631
static bool dict_table_is_discarded(const dict_table_t *table)
Check if the tablespace for the table has been discarded.
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:3696
static ulint dict_table_get_n_tot_u_cols(const dict_table_t *table)
static trx_id_t dict_table_get_curr_table_sess_trx_id(const dict_table_t *table)
Get current session trx-id.
static bool dict_table_has_indexed_v_cols(const dict_table_t *table)
Check if a table has indexed virtual columns.
static 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_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:4113
void dict_persist_close(void)
Clear the structure.
Definition: dict0dict.cc:3915
static bool dict_tf2_is_valid(uint32_t flags, uint32_t flags2)
Validate both table flags and table flags2 and make sure they are compatible.
static void dict_table_n_rows_dec(dict_table_t *table)
Decrement the number of rows in the table by one.
static 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_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, bool strict)
Adds an index to the dictionary cache, with possible indexing newly added column.
Definition: dict0dict.cc:2440
static ulint dict_index_is_ibuf(const dict_index_t *index)
Check whether the index is the insert buffer tree.
static void dict_table_x_unlock_indexes(dict_table_t *table)
Release the exclusive locks on all index tree.
static void dict_disable_redo_if_temporary(const dict_table_t *table, mtr_t *mtr)
Turn-off redo-logging if temporary table.
static 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.
const char * dict_table_get_v_col_name(const dict_table_t *table, ulint col_nr)
Returns a virtual column's name.
Definition: dict0dict.cc:624
constexpr uint32_t MAX_NUM_FK_COLUMNS
Maximum number of columns in a foreign key constraint.
Definition: dict0dict.h:979
void dict_table_wait_for_bg_threads_to_exit(dict_table_t *table, std::chrono::microseconds delay)
Definition: dict0dict.cc:2929
rw_lock_t * dict_operation_lock
the data dictionary rw-latch protecting dict_sys
Definition: dict0dict.cc:176
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:1393
void dict_validate_no_purge_rollback_threads()
Validate no active background threads to cause purge or rollback operations.
Definition: dict0dict.cc:6111
void dict_table_stats_latch_destroy(dict_table_t *table)
Destroy a dict_table_t's stats latch.
Definition: dict0dict.cc:359
void dict_foreign_free(dict_foreign_t *foreign)
Frees a foreign key struct.
Definition: dict0mem.h:1777
dict_persist_t * dict_persist
the dictionary persisting structure
Definition: dict0dict.cc:166
static 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.
void dict_table_autoinc_lock(dict_table_t *table)
Acquire the autoinc lock.
Definition: dict0dict.cc:731
static page_no_t dict_index_get_page(const dict_index_t *tree)
Gets the page number of the root of the index tree.
ib_mutex_t dict_foreign_err_mutex
Definition: dict0dict.cc:262
void dict_table_add_to_cache(dict_table_t *table, bool can_be_evicted)
Adds a table object to the dictionary cache.
Definition: dict0dict.cc:1190
static 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 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:1375
void dict_index_remove_from_cache(dict_table_t *table, dict_index_t *index)
Removes an index from the dictionary cache.
Definition: dict0dict.cc:2714
void dict_ind_init(void)
Inits dict_ind_redundant.
Definition: dict0dict.cc:4366
dict_index_t * dict_sdi_get_index(space_id_t tablespace_id)
Retrieve in-memory index for SDI table.
Definition: dict0dict.cc:5789
void dict_table_close(dict_table_t *table, bool dict_locked, bool try_drop)
Decrements the count of open handles to a table.
Definition: dict0dict.cc:494
void dict_persist_init(void)
Inits the structure for persisting dynamic metadata.
Definition: dict0dict.cc:3890
void dict_index_set_merge_threshold(dict_index_t *index, ulint merge_threshold)
Sets merge_threshold in the SYS_INDEXES.
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:570
const dict_index_t * dict_index_find(const index_id_t &id)
Look up an index among already opened tables.
Definition: dict0dict.cc:1424
static 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 uniq...
void dict_move_to_mru(dict_table_t *table)
Move to the most recently used segment of the LRU list.
Definition: dict0dict.cc:1041
static bool dict_table_have_virtual_index(dict_table_t *table)
Check whether the table have virtual index.
void dict_upgrade_evict_tables_cache()
Evict all tables that are loaded for applying purge.
Definition: dict0dict.cc:5896
ulint dict_index_node_ptr_max_size(const dict_index_t *index)
Return maximum size of the node pointer record.
Definition: dict0dict.cc:2040
static 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...
const uint32_t SDI_VERSION
SDI version.
Definition: dict0dict.h:72
void dict_table_autoinc_unlock(dict_table_t *table)
Release the autoinc lock.
Definition: dict0dict.cc:850
bool dict_sys_table_id_build()
Build the table_id array of SYS_* tables.
Definition: dict0dict.cc:5948
static bool dict_table_is_partition(const dict_table_t *table)
Check whether the dict_table_t is a partition.
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:812
void dict_index_remove_from_v_col_list(dict_index_t *index)
Clears the virtual column's index list before index is being freed.
Definition: dict0dict.cc:2332
void dict_resize()
Resize the hash tables based on the current buffer pool size.
Definition: dict0dict.cc:4585
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:4353
static bool dict_index_is_sdi(const dict_index_t *index)
Check if the index is SDI index.
static ulint dict_index_is_unique(const dict_index_t *index)
Check whether the index is unique.
static bool dict_table_is_table_buffer(const dict_table_t *table)
Check whether the table is DDTableBuffer.
static 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.
FILE * dict_foreign_err_file
Definition: dict0dict.cc:260
bool dict_table_is_system(table_id_t table_id)
Definition: dict0dict.cc:5968
static bool dict_table_is_comp(const dict_table_t *table)
Check whether the table uses the compact page format.
static ulint dict_index_get_space_reserve(void)
Returns free space reserved for future updates of records.
static void dict_table_skip_corrupt_index(dict_index_t *&index)
Definition: dict0dict.h:419
static void dict_table_autoinc_persisted_update(dict_table_t *table, uint64_t autoinc)
Update the persisted autoinc counter to specified one, we should hold autoinc_persisted_mutex.
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:3634
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:4218
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:894
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:5829
void dict_table_read_dynamic_metadata(const byte *buffer, ulint size, PersistentTableMetadata *metadata)
Read persistent dynamic metadata stored in a buffer.
Definition: dict0dict.cc:4033
void dict_table_stats_latch_create(dict_table_t *table, bool enabled)
Create a dict_table_t's stats latch or delay for lazy creation.
Definition: dict0dict.cc:343
uint32_t dict_vcol_base_is_foreign_key(dict_v_col_t *vcol, dict_foreign_t *foreign)
Definition: dict0dict.cc:6091
static bool dict_tf_is_valid(uint32_t flags)
Validate the table flags.
static 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.
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:3958
static 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...
const char * dict_tf_to_row_format_string(uint32_t table_flag)
Convert table flag to row format string.
Definition: dict0dict.cc:4999
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:4398
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 (non_virtual) column.
Definition: dict0dict.cc:596
void dict_set_corrupted(dict_index_t *index) UNIV_COLD
Flags an index corrupted in the data dictionary cache only.
Definition: dict0dict.cc:4151
void dict_sdi_close_table(dict_table_t *table)
Close SDI table.
Definition: dict0dict.cc:5781
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:400
dict_index_t * dict_ind_redundant
dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records
Definition: dict0dict.cc:70
static 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.
static void dict_tf_set(uint32_t *flags, rec_format_t format, uint32_t zip_ssize, bool use_data_dir, bool shared_space)
Set the various values in a dict_table_t::flags pointer.
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:2010
static const page_size_t dict_tf_get_page_size(uint32_t flags)
Extract the page size info from table flags.
void dict_table_stats_lock(dict_table_t *table, ulint latch_mode)
Lock the appropriate latch to protect a given table's statistics.
Definition: dict0dict.cc:369
static void dict_table_n_rows_inc(dict_table_t *table)
Increment the number of rows in the table by one.
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:2861
static ulint dict_table_is_fts_column(ib_vector_t *indexes, ulint col_no, bool is_virtual)
Check whether a column exists in an FTS index.
check_name
Whether and when to allow temporary index names.
Definition: dict0dict.h:775
@ CHECK_ABORTED_OK
Allow aborted online index creation.
Definition: dict0dict.h:779
@ CHECK_ALL_COMPLETE
Require all indexes to be complete.
Definition: dict0dict.h:777
@ CHECK_PARTIAL_OK
Allow partial indexes to exist.
Definition: dict0dict.h:781
const space_id_t SYSTEM_TABLE_SPACE
Space id of system tablespace.
Definition: dict0dict.h:75
static bool dict_index_is_auto_gen_clust(const dict_index_t *index)
Check if index is auto-generated clustered index.
static void dict_allocate_mem_intrinsic_cache(dict_index_t *index)
Allocate memory for intrinsic cache elements in the index.
bool dict_table_is_referenced_by_foreign_key(const dict_table_t *table)
Checks if a table is referenced by foreign keys.
Definition: dict0dict.cc:3288
static bool dict_table_is_locking_disabled(const dict_table_t *table)
Check whether locking is disabled for this table.
static const page_size_t dict_table_page_size(const dict_table_t *table)
Get the table page size.
void dict_mutex_enter_for_mysql(void)
Reserves the dictionary system mutex for MySQL.
Definition: dict0dict.cc:307
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:3422
dberr_t dict_set_compression(dict_table_t *table, const char *algorithm, bool is_import_op)
Set the compression type for the tablespace of a table.
Definition: dict0dict.cc:6052
void dict_index_zip_failure(dict_index_t *index)
This function should be called whenever a page compression attempt fails.
Definition: dict0dict.cc:4914
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:2895
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:5860
constexpr uint32_t DICT_HEAP_SIZE
initial memory heap size when creating a table or index object
Definition: dict0dict.h:69
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:1315
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:2913
static ulint dict_col_get_no(const dict_col_t *col)
Gets the column number.
static 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.
bool dict_col_name_is_reserved(const char *name)
If the given column name is reserved for InnoDB system columns, return true.
Definition: dict0dict.cc:2018
static void dict_table_ddl_acquire(dict_table_t *table)
Move this table to non-LRU list for DDL operations if it's currently not there.
void dict_foreign_remove_from_cache(dict_foreign_t *foreign)
Removes a foreign constraint struct from the dictionary cache.
Definition: dict0dict.cc:3295
static uint64_t dict_table_get_n_rows(const dict_table_t *table)
Gets the approximately estimated number of rows in the table.
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:4419
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:830
void dict_fs2utf8(const char *db_and_table, char *db_utf8mb3, size_t db_utf8mb3_size, char *table_utf8mb3, size_t table_utf8mb3_size)
Converts a database and table name from filesystem encoding (e.g.
Definition: dict0dict.cc:4537
bool 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:3617
dberr_t dict_index_add_to_cache(dict_table_t *table, dict_index_t *index, page_no_t page_no, bool strict)
Adds an index to the dictionary cache.
Definition: dict0dict.cc:2323
std::string dict_table_get_datadir(const dict_table_t *table)
Get the tablespace data directory if set, otherwise empty string.
Definition: dict0dict.cc:6042
void dict_table_autoinc_update_if_greater(dict_table_t *table, uint64_t value)
Updates the autoinc counter if the value supplied is greater than the current value.
Definition: dict0dict.cc:841
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:4933
static ulint dict_index_has_virtual(const dict_index_t *index)
Check whether the index contains a virtual column.
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:3343
void dict_index_zip_success(dict_index_t *index)
This function should be called whenever a page is successfully compressed.
Definition: dict0dict.cc:4895
void dict_table_add_system_columns(dict_table_t *table, mem_heap_t *heap)
Adds system columns to a table object.
Definition: dict0dict.cc:1130
void get_permissible_max_size(const dict_table_t *table, const dict_index_t *index, size_t &page_rec_max, size_t &page_ptr_max)
Get the maximum size of a record permissible on an index page.
Definition: dict0dict.cc:2116
void dict_table_set_big_rows(dict_table_t *table)
Mark if table has big rows.
Definition: dict0dict.cc:1171
void dict_table_autoinc_initialize(dict_table_t *table, uint64_t value)
Unconditionally set the autoinc counter.
Definition: dict0dict.cc:751
static 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...
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:939
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:4483
dict_table_op_t
Operation to perform when opening a table.
Definition: dict0dict.h:101
@ DICT_TABLE_OP_NORMAL
Expect the tablespace to exist.
Definition: dict0dict.h:103
@ DICT_TABLE_OP_LOAD_TABLESPACE
Silently load the tablespace if it does not exist, and do not load the definitions of incomplete inde...
Definition: dict0dict.h:108
@ DICT_TABLE_OP_DROP_ORPHAN
Drop any orphan indexes after an aborted online index creation.
Definition: dict0dict.h:105
static bool dict_table_is_sdi(uint64_t table_id)
Check if an table id belongs SDI table.
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:5805
static rw_lock_t * dict_index_get_lock(dict_index_t *index)
Gets the read-write lock of the index tree.
static bool dict_table_has_fts_index(dict_table_t *table)
Check if the table has an FTS index.
bool 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:977
static 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.
ulint dict_index_calc_min_rec_len(const dict_index_t *index)
Calculates the minimum record length in an index.
Definition: dict0dict.cc:3750
static void dict_index_set_online_status(dict_index_t *index, enum online_index_status status)
Sets the status of online index creation.
static 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.
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:4064
static 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.
bool dict_index_validate_max_rec_size(const dict_table_t *table, const dict_index_t *index, bool strict, const size_t page_rec_max, const size_t page_ptr_max, size_t &rec_max_size)
validate that maximum possible size of a row is within permissible limit.
Definition: dict0dict.cc:2249
dict_v_col_t * dict_table_get_nth_v_col_mysql(const dict_table_t *table, ulint col_nr)
Get nth virtual column according to its original MySQL table position.
Definition: dict0dict.cc:693
static enum online_index_status dict_index_get_online_status(const dict_index_t *index)
Gets the status of online index creation.
bool 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:855
static 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.
void dict_table_remove_from_cache(dict_table_t *table)
Removes a table object from the dictionary cache.
Definition: dict0dict.cc:1967
static ulint dict_index_is_spatial(const dict_index_t *index)
Check whether the index is a Spatial Index.
const char * dict_table_get_v_col_name_mysql(const dict_table_t *table, ulint col_nr)
Returns a virtual column's name according to its original MySQL table position.
Definition: dict0dict.cc:678
static space_id_t dict_index_get_space(const dict_index_t *index)
Gets the space id of the root of the index tree.
void get_field_max_size(const dict_table_t *table, const dict_index_t *index, const dict_field_t *field, size_t &rec_max_size)
Get maximum possible size needed for a field.
Definition: dict0dict.cc:2150
static bool dict_table_has_autoinc_col(const dict_table_t *table)
Check if a table has an autoinc counter column.
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.
Definition: dict0dict.ic:756
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:3727
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:6015
static 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...
dict_sys_t * dict_sys
the dictionary system
Definition: dict0dict.cc:136
static 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...
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:4238
static void dict_table_x_lock_indexes(dict_table_t *table)
Obtain exclusive locks on all index trees of the table.
dict_table_t * dict_table_open_on_name(const char *table_name, bool dict_locked, bool try_drop, dict_err_ignore_t ignore_err)
Returns a table object and increments its open handle count.
Definition: dict0dict.cc:1061
static bool dict_table_has_atomic_blobs(const dict_table_t *table)
Determine if a table uses atomic BLOBs (no locally stored prefix).
Data dictionary system.
Data dictionary memory object creation.
online_index_status
The status of online index creation.
Definition: dict0mem.h:1637
Data dictionary global types.
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:219
ib_mutex_t DictSysMutex
Definition: dict0types.h:303
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:279
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:217
Data dictionary system.
File space management.
Multi file, shared, system tablespace implementation.
constexpr size_t FSP_MAX_UNDO_TABLESPACES
Definition: fsp0types.h:402
The simple hash table utility.
static void *& hash_get_first(hash_table_t *table, size_t cell_id)
Gets the first struct in a hash chain, NULL if none.
Definition: hash0hash.h:158
#define HASH_GET_NEXT(NAME, DATA)
Gets the next struct in a hash chain, NULL if none.
Definition: hash0hash.h:164
static int flags[50]
Definition: hp_test1.cc:39
The memory management.
Definition: buf0block_hint.cc:29
const std::string FILE("FILE")
unsigned long long Object_id
Definition: object_id.h:30
Definition: os0file.h:85
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
const char * table_name
Definition: rules_table_service.cc:55
Record manager global types.
byte rec_t
Definition: rem0types.h:40
enum rec_format_enum rec_format_t
Definition: rem0types.h:82
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:60
required uint64 version
Definition: replication_group_member_actions.proto:40
required bool enabled
Definition: replication_group_member_actions.proto:32
Row operation global types.
Server monitor counter related defines.
case opt name
Definition: sslopt-case.h:32
Definition: completion_hash.h:34
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:834
Data structure for a column in a table.
Definition: dict0mem.h:488
Data structure for a field in an index.
Definition: dict0mem.h:894
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1665
Data structure for an index.
Definition: dict0mem.h:1045
const dict_index_t * next() const
Get the next index.
Definition: dict0mem.h:1286
bool is_corrupted() const
Check whether the index is corrupted.
Definition: dict0mem.h:1301
Structure for persisting dynamic metadata of data dictionary.
Definition: dict0dict.h:1163
Persisters * persisters
Collection of instances to persist dynamic metadata.
Definition: dict0dict.h:1227
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:1210
std::atomic< uint32_t > num_dirty_tables
Number of the tables which are of status METADATA_DIRTY.
Definition: dict0dict.h:1214
std::atomic< bool > m_persist_immediately
If set, dynamic metadata is saved to DD buffer table immediately.
Definition: dict0dict.h:1219
DDTableBuffer * table_buffer
DDTableBuffer table for persistent dynamic metadata.
Definition: dict0dict.h:1223
bool check_persist_immediately() const
Definition: dict0dict.h:1192
dirty_dict_tables
List of tables whose dirty_status are marked as METADATA_DIRTY, or METADATA_BUFFERED.
Definition: dict0dict.h:1199
Definition: dict0dict.h:1003
void for_each_table(Functor &functor)
Iterate each table.
Definition: dict0dict.h:1052
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:1013
static constexpr space_id_t s_undo_space_id_range
The number of space IDs dedicated to each undo tablespace.
Definition: dict0dict.h:1102
static constexpr space_id_t s_max_undo_space_id
The highest undo tablespace ID.
Definition: dict0dict.h:1109
dict_table_t * ddl_log
Permanent handle to mysql.innodb_ddl_log.
Definition: dict0dict.h:1038
static bool is_reserved(space_id_t space)
Check if a tablespace id is a reserved tablespace ID.
Definition: dict0dict.h:1072
static constexpr space_id_t s_reserved_space_id
The first reserved tablespace ID.
Definition: dict0dict.h:1122
static std::set< dd::Object_id > s_dd_table_ids
Set of ids of DD tables.
Definition: dict0dict.h:1077
static constexpr table_id_t s_dynamic_meta_table_id
The table ID of mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1156
static constexpr space_id_t s_min_temp_space_id
Lowest temporary general space id.
Definition: dict0dict.h:1118
static constexpr dd::Object_id s_dd_sys_space_id
The dd::Tablespace::id of innodb_system.
Definition: dict0dict.h:1128
static const char * s_default_undo_space_name_2
Definition: dict0dict.h:1153
UT_LIST_BASE_NODE_T(dict_table_t, table_LRU) Table_LRU_list_base
Definition: dict0dict.h:1041
dict_table_t * sys_fields
SYS_FIELDS table.
Definition: dict0dict.h:1030
static const char * s_file_per_table_name
The hard-coded tablespace name innodb_file_per_table.
Definition: dict0dict.h:1149
static constexpr space_id_t s_log_space_id
The first ID of the redo log pseudo-tablespace.
Definition: dict0dict.h:1090
Table_LRU_list_base table_LRU
List of tables that can be evicted from the cache.
Definition: dict0dict.h:1044
static const char * s_dd_space_name
The name of the data dictionary tablespace.
Definition: dict0dict.h:1134
DictSysMutex mutex
mutex protecting the data dictionary; protects also the disk-based dictionary system tables; this mut...
Definition: dict0dict.h:1005
static constexpr space_id_t s_min_undo_space_id
The lowest undo tablespace ID.
Definition: dict0dict.h:1105
static const char * s_temp_space_file_name
The file name of the predefined temporary tablespace.
Definition: dict0dict.h:1146
static bool is_dd_table_id(table_id_t id)
Check if a table is hardcoded.
Definition: dict0dict.h:1085
static const char * s_default_undo_space_name_1
These two undo tablespaces cannot be dropped.
Definition: dict0dict.h:1152
size_t size
varying space in bytes occupied by the data dictionary table and index objects
Definition: dict0dict.h:1023
static const char * s_dd_space_file_name
The file name of the data dictionary tablespace.
Definition: dict0dict.h:1137
dict_table_t * sys_tables
Handler to sys_* tables, they're only for upgrade.
Definition: dict0dict.h:1027
Table_LRU_list_base table_non_LRU
List of tables that can't be evicted from the cache.
Definition: dict0dict.h:1046
static constexpr dd::Object_id s_dd_dict_space_id
The dd::Tablespace::id of the dictionary tablespace.
Definition: dict0dict.h:1125
static const char * s_sys_space_name
The name of the hard-coded system tablespace.
Definition: dict0dict.h:1140
static constexpr space_id_t s_temp_space_id
The innodb_temporary tablespace ID.
Definition: dict0dict.h:1099
dict_table_t * index_stats
Permanent handle to mysql.innodb_index_stats.
Definition: dict0dict.h:1036
static constexpr space_id_t s_dict_space_id
The data dictionary tablespace ID.
Definition: dict0dict.h:1096
dict_table_t * table_stats
Permanent handle to mysql.innodb_table_stats.
Definition: dict0dict.h:1034
static constexpr space_index_t s_dynamic_meta_index_id
The clustered index ID of mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1159
static constexpr space_id_t s_max_temp_space_id
Start space_ids for temporary tablespaces.
Definition: dict0dict.h:1112
dict_table_t * sys_indexes
SYS_INDEXES table.
Definition: dict0dict.h:1029
static constexpr dd::Object_id s_dd_temp_space_id
The dd::Tablespace::id of innodb_temporary.
Definition: dict0dict.h:1131
static const char * s_temp_space_name
The name of the predefined temporary tablespace.
Definition: dict0dict.h:1143
static constexpr space_id_t s_invalid_space_id
Use maximum UINT value to indicate invalid space ID.
Definition: dict0dict.h:1093
dict_table_t * dynamic_metadata
Permanent handle to mysql.innodb_dynamic_metadata.
Definition: dict0dict.h:1040
dict_table_t * sys_columns
SYS_COLUMNS table.
Definition: dict0dict.h:1028
static constexpr space_id_t s_temp_space_id_range
The number of space IDs dedicated to temporary tablespaces.
Definition: dict0dict.h:1115
hash_table_t * table_id_hash
hash table of the tables, based on id
Definition: dict0dict.h:1021
dict_table_t * sys_virtual
SYS_VIRTUAL table.
Definition: dict0dict.h:1031
hash_table_t * table_hash
hash table of the tables, based on name
Definition: dict0dict.h:1019
Data structure for a database table.
Definition: dict0mem.h:1908
Data structure for a virtual column in a table.
Definition: dict0mem.h:814
Structure defines template related to virtual columns and their base columns.
Definition: dict0mem.h:1845
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:681
Definition: ut0vec.h:212
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:181
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:359
Definition: trx0trx.h:680
Definition: row0upd.h:564
The read-write lock (for threads, not for database transactions)
typedef UT_LIST_BASE_NODE_T(rw_lock_t, list) rw_lock_list_t
Transaction system global type definitions.
ib_id_t row_id_t
Row identifier (DB_ROW_ID, DATA_ROW_ID)
Definition: trx0types.h:131
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
static const space_id_t TRX_SYS_SPACE
Space id of the transaction system page (the system tablespace)
Definition: trx0types.h:51
unsigned int uint
Definition: uca-dump.cc:29
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:268
unsigned long int ulint
Definition: univ.i:407
Utilities for byte operations.
Memory primitives.
#define mutex_exit(M)
Definition: ut0mutex.h:122
#define mutex_enter(M)
Definition: ut0mutex.h:116
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
Random numbers and hashing.
uint32_t new_id()
Create a new (hopefully unique) ID.
Definition: xcom_base.cc:1781
int n
Definition: xcom_base.cc:508