MySQL  8.0.21
Source Code Documentation
dict0dict.cc File Reference

Data dictionary system. More...

#include "my_config.h"
#include <stdlib.h>
#include <strfunc.h>
#include <sys/types.h>
#include <algorithm>
#include <string>
#include "current_thd.h"
#include "dict0dict.h"
#include "fil0fil.h"
#include "fts0fts.h"
#include "ha_prototypes.h"
#include "my_dbug.h"
#include "clone0api.h"
#include "mysqld.h"
#include "que0types.h"
#include "row0sel.h"
#include <vector>
#include "btr0btr.h"
#include "btr0cur.h"
#include "btr0sea.h"
#include "buf0buf.h"
#include "data0type.h"
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0mem.h"
#include "dict0priv.h"
#include "dict0stats.h"
#include "fsp0sysspace.h"
#include "fts0types.h"
#include "lock0lock.h"
#include "mach0data.h"
#include "mem0mem.h"
#include "os0once.h"
#include "page0page.h"
#include "page0zip.h"
#include "pars0pars.h"
#include "pars0sym.h"
#include "que0que.h"
#include "rem0cmp.h"
#include "row0ins.h"
#include "row0log.h"
#include "row0merge.h"
#include "row0mysql.h"
#include "row0upd.h"
#include "ha_innodb.h"
#include "srv0mon.h"
#include "srv0start.h"
#include "sync0sync.h"
#include "trx0undo.h"
#include "ut0new.h"

Classes

struct  dict_foreign_remove_partial
 Function object to remove a foreign key constraint from the referenced_set of the referenced table. More...
 

Macros

#define DICT_POOL_PER_TABLE_HASH   512
 buffer pool max size per table \ hash table fixed size in bytes More...
 

Functions

static ibool dict_index_find_and_set_cols (const dict_table_t *table, dict_index_t *index, const dict_add_v_col_t *add_v)
 Tries to find column names for the index and sets the col field of the index. More...
 
static dict_index_tdict_index_build_internal_clust (const dict_table_t *table, dict_index_t *index)
 Builds the internal dictionary cache representation for a clustered index, containing also system fields not defined by the user. More...
 
static dict_index_tdict_index_build_internal_non_clust (const dict_table_t *table, dict_index_t *index)
 Builds the internal dictionary cache representation for a non-clustered index, containing also system fields not defined by the user. More...
 
static dict_index_tdict_index_build_internal_fts (dict_table_t *table, dict_index_t *index)
 Builds the internal dictionary cache representation for an FTS index. More...
 
static void dict_index_remove_from_cache_low (dict_table_t *table, dict_index_t *index, ibool lru_evict)
 Removes an index from the dictionary cache. More...
 
static void dict_persist_update_log_margin (void)
 Calculate and update the redo log margin for current tables which have some changed dynamic metadata in memory and have not been written back to mysql.innodb_dynamic_metadata. More...
 
static void dict_table_remove_from_cache_low (dict_table_t *table, ibool lru_evict)
 Removes a table object from the dictionary cache. More...
 
static ibool dict_lru_validate (void)
 Validate the dictionary table LRU list. More...
 
static ibool dict_lru_find_table (const dict_table_t *find_table)
 Check if table is in the dictionary table LRU list. More...
 
static ibool dict_non_lru_find_table (const dict_table_t *find_table)
 Check if a table exists in the dict table non-LRU list. More...
 
ibool dict_tables_have_same_db (const char *name1, const char *name2)
 Checks if the database name in two table names is the same. More...
 
const char * dict_remove_db_name (const char *name)
 Return the end of table name where we have removed dbname and '/'. More...
 
ulint dict_get_db_name_len (const char *name)
 Get the database name length in a table name. More...
 
void dict_mutex_enter_for_mysql (void)
 Reserves the dictionary system mutex for MySQL. More...
 
void dict_mutex_exit_for_mysql (void)
 Releases the dictionary system mutex for MySQL. More...
 
static void dict_table_stats_latch_alloc (void *table_void)
 Allocate and init a dict_table_t's stats latch. More...
 
static void dict_table_stats_latch_free (dict_table_t *table)
 Deinit and free a dict_table_t's stats latch. More...
 
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. More...
 
void dict_table_stats_latch_destroy (dict_table_t *table)
 Destroy a dict_table_t's stats latch. More...
 
void dict_table_stats_lock (dict_table_t *table, ulint latch_mode)
 Lock the appropriate latch to protect a given table's statistics. More...
 
void dict_table_stats_unlock (dict_table_t *table, ulint latch_mode)
 Unlock the latch that has been locked by dict_table_stats_lock(). More...
 
static void dict_table_try_drop_aborted (dict_table_t *table, table_id_t table_id, ulint ref_count)
 Try to drop any indexes after an aborted index creation. More...
 
static void dict_table_try_drop_aborted_and_mutex_exit (dict_table_t *table, ibool try_drop)
 When opening a table, try to drop any indexes after an aborted index creation. More...
 
void dict_table_close (dict_table_t *table, ibool dict_locked, ibool try_drop)
 Decrements the count of open handles to a table. More...
 
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 the whole time. More...
 
ulint dict_table_has_column (const dict_table_t *table, const char *col_name, ulint col_nr)
 Check if the table has a given (non_virtual) column. More...
 
const char * dict_table_get_v_col_name (const dict_table_t *table, ulint col_nr)
 Returns a virtual column's name. More...
 
static ulint dict_table_get_v_col_pos_for_mysql (const dict_table_t *table, ulint col_nr)
 Search virtual column's position in InnoDB according to its position in original table's position. More...
 
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. More...
 
dict_v_col_tdict_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. More...
 
static void dict_table_autoinc_alloc (void *table_void)
 Allocate and init the autoinc latch of a given table. More...
 
static void dict_index_zip_pad_alloc (void *index_void)
 Allocate and init the zip_pad_mutex of a given index. More...
 
void dict_table_autoinc_lock (dict_table_t *table)
 Acquire the autoinc lock. More...
 
static void dict_index_zip_pad_lock (dict_index_t *index)
 Acquire the zip_pad_mutex latch. More...
 
void dict_table_autoinc_initialize (dict_table_t *table, ib_uint64_t value)
 Unconditionally set the autoinc counter. More...
 
void dict_table_autoinc_log (dict_table_t *table, uint64_t value, mtr_t *mtr)
 Write redo logs for autoinc counter that is to be inserted, or to update some existing smaller one to bigger. More...
 
ulint dict_table_get_all_fts_indexes (dict_table_t *table, ib_vector_t *indexes)
 Get all the FTS indexes on a table. More...
 
ib_uint64_t dict_table_autoinc_read (const dict_table_t *table)
 Reads the next autoinc value (== autoinc counter value), 0 if not yet initialized. More...
 
void dict_table_autoinc_update_if_greater (dict_table_t *table, ib_uint64_t value)
 Updates the autoinc counter if the value supplied is greater than the current value. More...
 
void dict_table_autoinc_unlock (dict_table_t *table)
 Release the autoinc lock. More...
 
ibool dict_index_contains_col_or_prefix (const dict_index_t *index, ulint n, bool is_virtual)
 Returns TRUE if the index contains a column or a prefix of that column. More...
 
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. More...
 
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. More...
 
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 position n. More...
 
ibool dict_table_col_in_clustered_key (const dict_table_t *table, ulint n)
 Checks if a column is in the ordering columns of the clustered index of a table. More...
 
void dict_init (void)
 Inits the data dictionary module. More...
 
void dict_move_to_mru (dict_table_t *table)
 Move to the most recently used segment of the LRU list. More...
 
dict_table_tdict_table_open_on_name (const char *table_name, ibool dict_locked, ibool try_drop, dict_err_ignore_t ignore_err)
 Returns a table object and increment its open handle count. More...
 
void dict_table_add_system_columns (dict_table_t *table, mem_heap_t *heap)
 Adds system columns to a table object. More...
 
void dict_table_set_big_rows (dict_table_t *table)
 Mark if table has big rows. More...
 
void dict_table_add_to_cache (dict_table_t *table, ibool can_be_evicted, mem_heap_t *heap)
 Adds a table object to the dictionary cache. More...
 
static ibool dict_table_can_be_evicted (dict_table_t *table)
 Test whether a table can be evicted from the LRU cache. More...
 
ulint dict_make_room_in_cache (ulint max_tables, ulint pct_check)
 Make room in the table cache by evicting an unused table. More...
 
void dict_table_move_from_lru_to_non_lru (dict_table_t *table)
 Move a table to the non-LRU list from the LRU list. More...
 
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. More...
 
static const dict_index_tdict_table_find_index_on_id (const dict_table_t *table, const index_id_t &id)
 Look up an index in a table. More...
 
const dict_index_tdict_index_find (const index_id_t &id)
 Look up an index. More...
 
dberr_t dict_table_rename_in_cache (dict_table_t *table, const char *new_name, ibool rename_also_foreigns)
 Renames a table object. More...
 
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. More...
 
void dict_table_remove_from_cache (dict_table_t *table)
 Removes a table object from the dictionary cache. More...
 
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. More...
 
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. More...
 
ibool dict_col_name_is_reserved (const char *name)
 If the given column name is reserved for InnoDB system columns, return TRUE. More...
 
ulint dict_index_node_ptr_max_size (const dict_index_t *index)
 Return maximum size of the node pointer record. More...
 
static bool dict_index_too_big_for_tree (const dict_table_t *table, const dict_index_t *new_index, bool strict)
 If a record of this index might not fit on a single B-tree page, return TRUE. More...
 
dberr_t dict_index_add_to_cache (dict_table_t *table, dict_index_t *index, page_no_t page_no, ibool strict)
 Adds an index to the dictionary cache. More...
 
void dict_index_remove_from_v_col_list (dict_index_t *index)
 Clears the virtual column's index list before index is being freed. More...
 
dberr_t dict_index_add_to_cache_w_vcol (dict_table_t *table, dict_index_t *index, const dict_add_v_col_t *add_v, page_no_t page_no, ibool strict)
 Adds an index to the dictionary cache, with possible indexing newly added column. More...
 
void dict_index_remove_from_cache (dict_table_t *table, dict_index_t *index)
 Removes an index from the dictionary cache. More...
 
static dict_v_col_tdict_duplicate_v_col (const dict_v_col_t *v_col, mem_heap_t *heap)
 Duplicate a virtual column information. More...
 
static void dict_index_copy (dict_index_t *index1, dict_index_t *index2, const dict_table_t *table, ulint start, ulint end)
 Copies fields contained in index2 to index1. More...
 
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. More...
 
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 SQL NULL value. More...
 
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 value. More...
 
void dict_table_wait_for_bg_threads_to_exit (dict_table_t *table, ulint delay)
 
ibool dict_table_is_referenced_by_foreign_key (const dict_table_t *table)
 Checks if a table is referenced by foreign keys. More...
 
void dict_foreign_remove_from_cache (dict_foreign_t *foreign)
 Removes a foreign constraint struct from the dictionary cache. More...
 
static dict_foreign_tdict_foreign_find (dict_table_t *table, dict_foreign_t *foreign)
 Looks for the foreign constraint from the foreign and referenced lists of a table. More...
 
dict_index_tdict_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 marked for deletion and is not the same as types_idx. More...
 
static void dict_foreign_error_report_low (FILE *file, const char *name)
 Report an error in a foreign key definition. More...
 
static void dict_foreign_error_report (FILE *file, dict_foreign_t *fk, const char *msg)
 Report an error in a foreign key definition. More...
 
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. More...
 
ulint dict_table_get_highest_foreign_id (dict_table_t *table)
 Finds the highest [number] for foreign key constraints of the table. More...
 
ibool dict_index_check_search_tuple (const dict_index_t *index, const dtuple_t *tuple)
 Checks that a tuple has n_fields_cmp value in a sensible range, so that no comparison can occur with the page number field in a node pointer. More...
 
dtuple_tdict_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. More...
 
rec_tdict_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. More...
 
dtuple_tdict_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. More...
 
ulint dict_index_calc_min_rec_len (const dict_index_t *index)
 Calculates the minimum record length in an index. More...
 
void dict_print_info_on_foreign_key_in_create_format (FILE *file, trx_t *trx, dict_foreign_t *foreign, ibool add_newline)
 Outputs info on a foreign key of a table in a format suitable for CREATE TABLE. More...
 
void dict_persist_init (void)
 Inits the structure for persisting dynamic metadata. More...
 
void dict_persist_close (void)
 Clear the structure. More...
 
static void dict_init_dynamic_metadata (dict_table_t *table, PersistentTableMetadata *metadata)
 Initialize the dynamic metadata according to the table object. More...
 
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 during recovery. More...
 
void dict_table_read_dynamic_metadata (const byte *buffer, ulint size, PersistentTableMetadata *metadata)
 Read persistent dynamic metadata stored in a buffer. More...
 
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 specific table. More...
 
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 necessary. More...
 
void dict_set_corrupted (dict_index_t *index)
 Flags an index corrupted in the data dictionary cache only. More...
 
static void dict_table_persist_to_dd_table_buffer_low (dict_table_t *table)
 Write the dirty persistent dynamic metadata for a table to DD TABLE BUFFER table. More...
 
void dict_table_persist_to_dd_table_buffer (dict_table_t *table)
 Write back the dirty persistent dynamic metadata of the table to DDTableBuffer. More...
 
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.innodb_dynamic_metadata accordingly. More...
 
void dict_set_merge_threshold_list_debug (UT_LIST_BASE_NODE_T(dict_table_t) *list, uint merge_threshold_all)
 Sets merge_threshold for all indexes in the list of tables. More...
 
void dict_set_merge_threshold_all_debug (uint merge_threshold_all)
 Sets merge_threshold for all indexes in dictionary cache for debug. More...
 
void dict_ind_init (void)
 Inits dict_ind_redundant. More...
 
void dict_ind_free (void)
 Frees dict_ind_redundant. More...
 
dict_index_tdict_table_get_index_on_name (dict_table_t *table, const char *name, bool committed)
 Get an index by name. More...
 
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. More...
 
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]. More...
 
void dict_fs2utf8 (const char *db_and_table, char *db_utf8, size_t db_utf8_size, char *table_utf8, size_t table_utf8_size)
 Converts a database and table name from filesystem encoding (e.g. More...
 
void dict_resize ()
 Resize the hash tables besed on the current buffer pool size. More...
 
void dict_close (void)
 Closes the data dictionary module. More...
 
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)
 Check an index to see whether its first fields are the columns in the array, in the same order and is not marked for deletion and is not the same as types_idx. More...
 
static void dict_index_zip_pad_update (zip_pad_info_t *info, ulint zip_threshold)
 Update the state of compression failure padding heuristics. More...
 
void dict_index_zip_success (dict_index_t *index)
 This function should be called whenever a page is successfully compressed. More...
 
void dict_index_zip_failure (dict_index_t *index)
 This function should be called whenever a page compression attempt fails. More...
 
ulint dict_index_zip_pad_optimal_page_size (dict_index_t *index)
 Return the optimal page size, for which page will likely compress. More...
 
uint32_t dict_tf_to_fsp_flags (uint32_t table_flags)
 Convert a 32 bit integer table flags to the 32 bit FSP Flags. More...
 
const char * dict_tf_to_row_format_string (uint32_t table_flag)
 Convert table flag to row format string. More...
 
page_no_t dict_table_extent_size (const dict_table_t *table)
 Determine the extent size (in pages) for the given table. More...
 
void dict_sdi_close_table (dict_table_t *table)
 Close SDI table. More...
 
dict_index_tdict_sdi_get_index (space_id_t tablespace_id)
 Retrieve in-memory index for SDI table. More...
 
dict_table_tdict_sdi_get_table (space_id_t tablespace_id, bool dict_locked, bool is_create)
 Retrieve in-memory table object for SDI table. More...
 
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. More...
 
void dict_table_change_id_sys_tables ()
 Change the table_id of SYS_* tables if they have been created after an earlier upgrade. More...
 
void dict_upgrade_evict_tables_cache ()
 Evict all tables that are loaded for applying purge. More...
 
bool dict_sys_table_id_build ()
 Build the table_id array of SYS_* tables. More...
 
bool dict_table_is_system (table_id_t table_id)
 
dberr_t dd_sdi_acquire_exclusive_mdl (THD *thd, space_id_t space_id, MDL_ticket **sdi_mdl)
 Acquire exclusive MDL on SDI tables. More...
 
dberr_t dd_sdi_acquire_shared_mdl (THD *thd, space_id_t space_id, MDL_ticket **sdi_mdl)
 Acquire shared MDL on SDI tables. More...
 
std::string dict_table_get_datadir (const dict_table_t *table)
 Get the tablespace data directory if set, otherwise empty string. More...
 

Variables

dict_index_tdict_ind_redundant
 dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records More...
 
uint ibuf_debug
 Flag to control insert buffer debugging. More...
 
dict_sys_tdict_sys = nullptr
 the dictionary system More...
 
dict_persist_tdict_persist = nullptr
 the dictionary persisting structure More...
 
rw_lock_tdict_operation_lock
 the data dictionary rw-latch protecting dict_sys More...
 
ulong zip_failure_threshold_pct = 5
 Percentage of compression failures that are allowed in a single round. More...
 
ulong zip_pad_max = 50
 Maximum percentage of a page that can be allowed as a pad to avoid compression failures. More...
 
static char dict_ibfk [] = "_ibfk_"
 Identifies generated InnoDB foreign key names. More...
 
static table_id_t dict_sys_table_id [SYS_NUM_SYSTEM_TABLES]
 Array to store table_ids of INNODB_SYS_* TABLES. More...
 
FILE * dict_foreign_err_file = nullptr
 
ib_mutex_t dict_foreign_err_mutex
 

Detailed Description

Data dictionary system.

Created 1/8/1996 Heikki Tuuri

Macro Definition Documentation

◆ DICT_POOL_PER_TABLE_HASH

#define DICT_POOL_PER_TABLE_HASH   512

buffer pool max size per table \ hash table fixed size in bytes

Function Documentation

◆ dd_sdi_acquire_exclusive_mdl()

dberr_t dd_sdi_acquire_exclusive_mdl ( THD thd,
space_id_t  space_id,
MDL_ticket **  sdi_mdl 
)

Acquire exclusive MDL on SDI tables.

This is acquired to prevent concurrent DROP table/tablespace when there is purge happening on SDI table records. Purge will acquired shared MDL on SDI table.

Exclusive MDL is transactional(released on trx commit). So for successful acquistion, there should be valid thd with trx associated.

Acquistion order of SDI MDL and SDI table has to be in same order:

  1. dd_sdi_acquire_exclusive_mdl
  2. row_drop_table_from_cache()/innodb_drop_tablespace() ->dict_sdi_remove_from_cache()->dd_table_open_on_id()

In purge:

  1. dd_sdi_acquire_shared_mdl
  2. dd_table_open_on_id()
Parameters
[in]thdserver thread instance
[in]space_idInnoDB tablespace id
[in,out]sdi_mdlMDL ticket on SDI table
Return values
DB_SUCESSon success
DB_LOCK_WAIT_TIMEOUTon error

◆ dd_sdi_acquire_shared_mdl()

dberr_t dd_sdi_acquire_shared_mdl ( THD thd,
space_id_t  space_id,
MDL_ticket **  sdi_mdl 
)

Acquire shared MDL on SDI tables.

This is acquired by purge to prevent concurrent DROP table/tablespace. DROP table/tablespace will acquire exclusive MDL on SDI table

Acquistion order of SDI MDL and SDI table has to be in same order:

  1. dd_sdi_acquire_exclusive_mdl
  2. row_drop_table_from_cache()/innodb_drop_tablespace() ->dict_sdi_remove_from_cache()->dd_table_open_on_id()

In purge:

  1. dd_sdi_acquire_shared_mdl
  2. dd_table_open_on_id()

MDL should be released by caller

Parameters
[in]thdserver thread instance
[in]space_idInnoDB tablespace id
[in,out]sdi_mdlMDL ticket on SDI table
Return values
DB_SUCESSon success
DB_LOCK_WAIT_TIMEOUTon error

◆ dict_close()

void dict_close ( void  )

Closes the data dictionary module.

◆ dict_col_name_is_reserved()

ibool dict_col_name_is_reserved ( const char *  name)

If the given column name is reserved for InnoDB system columns, return TRUE.

Returns
true if name is reserved
Parameters
namein: column name

◆ dict_duplicate_v_col()

static dict_v_col_t* dict_duplicate_v_col ( const dict_v_col_t v_col,
mem_heap_t heap 
)
static

Duplicate a virtual column information.

Parameters
[in]v_colvirtual column information to duplicate
[in,out]heapmemory heap
Returns
the duplicated virtual column

◆ dict_foreign_add_to_cache()

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.

May free the object if there already is an object with the same identifier in. At least one of the foreign table and the referenced table must already be in the dictionary cache!

Returns
DB_SUCCESS or error code
Parameters
foreignin, own: foreign key constraint
col_namesin: column names, or NULL to use foreign->foreign_table->col_names
check_charsetsin: whether to check charset compatibility
can_free_fkin: whether free existing FK
ignore_errin: error to be ignored

◆ dict_foreign_error_report()

static void dict_foreign_error_report ( FILE *  file,
dict_foreign_t fk,
const char *  msg 
)
static

Report an error in a foreign key definition.

Parameters
filein: output stream
fkin: foreign key constraint
msgin: the error message

◆ dict_foreign_error_report_low()

static void dict_foreign_error_report_low ( FILE *  file,
const char *  name 
)
static

Report an error in a foreign key definition.

Parameters
filein: output stream
namein: table name

◆ dict_foreign_find()

static dict_foreign_t* dict_foreign_find ( dict_table_t table,
dict_foreign_t foreign 
)
static

Looks for the foreign constraint from the foreign and referenced lists of a table.

Returns
foreign constraint
Parameters
tablein: table object
foreignin: foreign constraint

◆ dict_foreign_find_index()

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 marked for deletion and is not the same as types_idx.

Returns
matching index, NULL if not found
Parameters
tablein: table
col_namesin: column names, or NULL to use table->col_names
columnsin: array of column names
n_colsin: number of columns
types_idxin: NULL or an index whose types the column types must match
check_charsetsin: whether to check charsets. only has an effect if types_idx != NULL
check_nullin: nonzero if none of the columns must be declared NOT NULL

◆ dict_foreign_qualify_index()

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 
)

Check an index to see whether its first fields are the columns in the array, in the same order and is not marked for deletion and is not the same as types_idx.

Tries to find an index whose first fields are the columns in the array, in the same order and is not marked for deletion and is not the same as types_idx.

Returns
true if the index qualifies, otherwise false
Parameters
tablein: table
col_namesin: column names, or NULL to use table->col_names
columnsin: array of column names
n_colsin: number of columns
indexin: index to check
types_idxin: NULL or an index whose types the column types must match
check_charsetsin: whether to check charsets. only has an effect if types_idx != NULL
check_nullin: nonzero if none of the columns must be declared NOT NULL

◆ dict_foreign_remove_from_cache()

void dict_foreign_remove_from_cache ( dict_foreign_t foreign)

Removes a foreign constraint struct from the dictionary cache.

Parameters
foreignin, own: foreign constraint

◆ dict_foreign_replace_index()

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.

Returns
whether all replacements were found
Parameters
tablein/out: table
col_namesin: column names, or NULL to use table->col_names
indexin: index to be replaced

◆ dict_fs2utf8()

void dict_fs2utf8 ( const char *  db_and_table,
char *  db_utf8,
size_t  db_utf8_size,
char *  table_utf8,
size_t  table_utf8_size 
)

Converts a database and table name from filesystem encoding (e.g.

"@code d@i1b/a@q1b@1Kc @endcode", same format as used in dict_table_t::name) in two strings in UTF8 encoding (e.g. dцb and aюbØc). The output buffers must be at least MAX_DB_UTF8_LEN and MAX_TABLE_UTF8_LEN bytes.

Parameters
[in]db_and_tabledatabase and table names, e.g. "@code d@i1b/a@q1b@1Kc @endcode"
[out]db_utf8database name, e.g. dцb
[in]db_utf8_sizedbname_utf8 size
[out]table_utf8table name, e.g. aюbØc
[in]table_utf8_sizetable_utf8 size

◆ dict_get_db_name_len()

ulint dict_get_db_name_len ( const char *  name)

Get the database name length in a table name.

Returns
database name length
Parameters
namein: table name in the form dbname '/' tablename

◆ dict_ind_free()

void dict_ind_free ( void  )

Frees dict_ind_redundant.

◆ dict_ind_init()

void dict_ind_init ( void  )

Inits dict_ind_redundant.

◆ dict_index_add_to_cache()

dberr_t dict_index_add_to_cache ( dict_table_t table,
dict_index_t index,
page_no_t  page_no,
ibool  strict 
)

Adds an index to the dictionary cache.

Parameters
[in,out]tabletable on which the index is
[in,out]indexindex; NOTE! The index memory object is freed in this function!
[in]page_noroot page number of the index
[in]strictTRUE=refuse to create the index if records could be too big to fit in an B-tree page
Returns
DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION
Parameters
tablein: table on which the index is
indexin, own: index; NOTE! The index memory object is freed in this function!
page_noin: root page number of the index
strictin: TRUE=refuse to create the index if records could be too big to fit in an B-tree page

◆ dict_index_add_to_cache_w_vcol()

dberr_t dict_index_add_to_cache_w_vcol ( dict_table_t table,
dict_index_t index,
const dict_add_v_col_t add_v,
page_no_t  page_no,
ibool  strict 
)

Adds an index to the dictionary cache, with possible indexing newly added column.

Parameters
[in,out]tabletable on which the index is
[in,out]indexindex; NOTE! The index memory object is freed in this function!
[in]add_vnew virtual column that being added along with an add index call
[in]page_noroot page number of the index
[in]strictTRUE=refuse to create the index if records could be too big to fit in an B-tree page
Returns
DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION

◆ dict_index_build_data_tuple()

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.

Returns
own: data tuple
Parameters
indexin: index tree
recin: record for which to build data tuple
n_fieldsin: number of data fields
heapin: memory heap where tuple created

◆ dict_index_build_internal_clust()

static dict_index_t * dict_index_build_internal_clust ( const dict_table_t table,
dict_index_t index 
)
static

Builds the internal dictionary cache representation for a clustered index, containing also system fields not defined by the user.

Returns
own: the internal representation of the clustered index in: user representation of a clustered index
own: the internal representation of the clustered index
Parameters
tablein: table
indexin: user representation of a clustered index

◆ dict_index_build_internal_fts()

static dict_index_t * dict_index_build_internal_fts ( dict_table_t table,
dict_index_t index 
)
static

Builds the internal dictionary cache representation for an FTS index.

Returns
own: the internal representation of the FTS index in: user representation of an FTS index
Parameters
tablein: table
indexin: user representation of an FTS index

◆ dict_index_build_internal_non_clust()

static dict_index_t * dict_index_build_internal_non_clust ( const dict_table_t table,
dict_index_t index 
)
static

Builds the internal dictionary cache representation for a non-clustered index, containing also system fields not defined by the user.

Returns
own: the internal representation of the non-clustered index in: user representation of a non-clustered index
own: the internal representation of the non-clustered index
Parameters
tablein: table
indexin: user representation of a non-clustered index

◆ dict_index_build_node_ptr()

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.

Returns
own: node pointer
Parameters
indexin: index
recin: record for which to build node pointer
page_noin: page number to put in node pointer
heapin: memory heap where pointer created
levelin: level of rec in tree: 0 means leaf level

◆ dict_index_calc_min_rec_len()

ulint dict_index_calc_min_rec_len ( const dict_index_t index)

Calculates the minimum record length in an index.

Parameters
indexin: index

◆ dict_index_check_search_tuple()

ibool dict_index_check_search_tuple ( const dict_index_t index,
const dtuple_t tuple 
)

Checks that a tuple has n_fields_cmp value in a sensible range, so that no comparison can occur with the page number field in a node pointer.

Returns
true if ok
Parameters
indexin: index tree
tuplein: tuple used in a search

◆ dict_index_contains_col_or_prefix()

ibool dict_index_contains_col_or_prefix ( const dict_index_t index,
ulint  n,
bool  is_virtual 
)

Returns TRUE if the index contains a column or a prefix of that column.

Parameters
[in]indexindex
[in]ncolumn number
[in]is_virtualwhether it is a virtual col
Returns
true if contains the column or its prefix
Parameters
indexin: index
nin: column number
is_virtualin: whether it is a virtual col

◆ dict_index_copy()

static void dict_index_copy ( dict_index_t index1,
dict_index_t index2,
const dict_table_t table,
ulint  start,
ulint  end 
)
static

Copies fields contained in index2 to index1.

Parameters
index1in: index to copy to
index2in: index to copy from
tablein: table
startin: first position to copy
endin: last position to copy

◆ dict_index_copy_rec_order_prefix()

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.

Returns
pointer to the prefix record
Parameters
indexin: index
recin: record for which to copy prefix
n_fieldsout: number of fields copied
bufin/out: memory buffer for the copied prefix, or NULL
buf_sizein/out: buffer size

◆ dict_index_copy_types()

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.

Parameters
tuplein/out: data tuple
indexin: index
n_fieldsin: number of field types to copy

◆ dict_index_find()

const dict_index_t* dict_index_find ( const index_id_t id)

Look up an index.

Parameters
[in]idindex identifier
Returns
index or NULL if not found

◆ dict_index_find_and_set_cols()

static ibool dict_index_find_and_set_cols ( const dict_table_t table,
dict_index_t index,
const dict_add_v_col_t add_v 
)
static

Tries to find column names for the index and sets the col field of the index.

Parameters
[in]tabletable
[in]indexindex
[in]add_vnew virtual columns added along with an add index call
Returns
true if the column names were found
Parameters
[in]tabletable
[in,out]indexindex
[in]add_vnew virtual columns added along with an add index call
Returns
true if the column names were found

◆ dict_index_get_nth_field_pos()

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.

The column has to be the same. The column in index must be complete, or must contain a prefix longer than the column in index2. That is, we must be able to construct the prefix in index2 from the prefix in index.

Returns
position in internal representation of the index; ULINT_UNDEFINED if not contained
Parameters
indexin: index from which to search
index2in: index
nin: field number in index2

◆ dict_index_node_ptr_max_size()

ulint dict_index_node_ptr_max_size ( const dict_index_t index)

Return maximum size of the node pointer record.

Returns
maximum size of the record in bytes
Parameters
indexin: index

◆ dict_index_remove_from_cache()

void dict_index_remove_from_cache ( dict_table_t table,
dict_index_t index 
)

Removes an index from the dictionary cache.

Parameters
tablein/out: table
indexin, own: index

◆ dict_index_remove_from_cache_low()

static void dict_index_remove_from_cache_low ( dict_table_t table,
dict_index_t index,
ibool  lru_evict 
)
static

Removes an index from the dictionary cache.

in: TRUE if page being evicted to make room in the table LRU list

Parameters
tablein/out: table
indexin, own: index
lru_evictin: TRUE if index being evicted to make room in the table LRU list

◆ dict_index_remove_from_v_col_list()

void dict_index_remove_from_v_col_list ( dict_index_t index)

Clears the virtual column's index list before index is being freed.

Parameters
[in]indexIndex being freed

◆ dict_index_too_big_for_tree()

static bool dict_index_too_big_for_tree ( const dict_table_t table,
const dict_index_t new_index,
bool  strict 
)
static

If a record of this index might not fit on a single B-tree page, return TRUE.

Returns
true if the index record could become too big
Parameters
tablein: table
new_indexin: index
strictin: TRUE=report error if records could be too big to fit in an B-tree page

◆ dict_index_zip_failure()

void dict_index_zip_failure ( dict_index_t index)

This function should be called whenever a page compression attempt fails.

Updates the compression padding information.

Parameters
indexin/out: index to be updated.

◆ dict_index_zip_pad_alloc()

static void dict_index_zip_pad_alloc ( void *  index_void)
static

Allocate and init the zip_pad_mutex of a given index.

This function must not be called concurrently on the same index object.

Parameters
[in,out]index_voidindex whose zip_pad_mutex to create

◆ dict_index_zip_pad_lock()

static void dict_index_zip_pad_lock ( dict_index_t index)
static

Acquire the zip_pad_mutex latch.

Parameters
[in,out]indexthe index whose zip_pad_mutex to acquire.

◆ dict_index_zip_pad_optimal_page_size()

ulint dict_index_zip_pad_optimal_page_size ( dict_index_t index)

Return the optimal page size, for which page will likely compress.

Returns
page size beyond which page might not compress
Parameters
indexin: index for which page size is requested

◆ dict_index_zip_pad_update()

static void dict_index_zip_pad_update ( zip_pad_info_t info,
ulint  zip_threshold 
)
static

Update the state of compression failure padding heuristics.

This is called whenever a compression operation succeeds or fails. The caller must be holding info->mutex

Parameters
infoin/out: info to be updated
zip_thresholdin: zip threshold value

◆ dict_index_zip_success()

void dict_index_zip_success ( dict_index_t index)

This function should be called whenever a page is successfully compressed.

Updates the compression padding information.

Parameters
indexin/out: index to be updated.

◆ dict_init()

void dict_init ( void  )

Inits the data dictionary module.

◆ dict_init_dynamic_metadata()

static void dict_init_dynamic_metadata ( dict_table_t table,
PersistentTableMetadata metadata 
)
static

Initialize the dynamic metadata according to the table object.

Parameters
[in]tabletable object
[in,out]metadatametadata to be initialized

◆ dict_lru_find_table()

static ibool dict_lru_find_table ( const dict_table_t find_table)
static

Check if table is in the dictionary table LRU list.

Check if a table exists in the dict table LRU list.

Returns
true if table found in: table to find
true if table found in LRU list
Parameters
find_tablein: table to find

◆ dict_lru_validate()

static ibool dict_lru_validate ( void  )
static

Validate the dictionary table LRU list.

Returns
true if validate OK
true if valid

◆ dict_make_room_in_cache()

ulint dict_make_room_in_cache ( ulint  max_tables,
ulint  pct_check 
)

Make room in the table cache by evicting an unused table.

The unused table should not be part of FK relationship and currently not used in any user transaction. There is no guarantee that it will remove a table.

Returns
number of tables evicted. If the number of tables in the dict_LRU is less than max_tables it will not do anything.
Parameters
max_tablesin: max tables allowed in cache
pct_checkin: max percent to check

◆ dict_move_to_mru()

void dict_move_to_mru ( dict_table_t table)

Move to the most recently used segment of the LRU list.

Parameters
tablein: table to move to MRU

◆ dict_mutex_enter_for_mysql()

void dict_mutex_enter_for_mysql ( void  )

Reserves the dictionary system mutex for MySQL.

◆ dict_mutex_exit_for_mysql()

void dict_mutex_exit_for_mysql ( void  )

Releases the dictionary system mutex for MySQL.

◆ dict_non_lru_find_table()

static ibool dict_non_lru_find_table ( const dict_table_t find_table)
static

Check if a table exists in the dict table non-LRU list.

Returns
true if table found in: table to find
true if table found in non-LRU list
Parameters
find_tablein: table to find

◆ dict_partitioned_table_remove_from_cache()

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.

Parameters
[in]nameTable name

◆ dict_persist_close()

void dict_persist_close ( void  )

Clear the structure.

◆ dict_persist_init()

void dict_persist_init ( void  )

Inits the structure for persisting dynamic metadata.

◆ dict_persist_to_dd_table_buffer()

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.innodb_dynamic_metadata accordingly.

◆ dict_persist_update_log_margin()

static void dict_persist_update_log_margin ( void  )
static

Calculate and update the redo log margin for current tables which have some changed dynamic metadata in memory and have not been written back to mysql.innodb_dynamic_metadata.

Update LSN limit, which is used to stop user threads when redo log is running out of space and they do not hold latches (log.free_check_limit_sn).

◆ dict_print_info_on_foreign_key_in_create_format()

void dict_print_info_on_foreign_key_in_create_format ( FILE *  file,
trx_t trx,
dict_foreign_t foreign,
ibool  add_newline 
)

Outputs info on a foreign key of a table in a format suitable for CREATE TABLE.

Parameters
filein: file where to print
trxin: transaction
foreignin: foreign key constraint
add_newlinein: whether to add a newline

◆ dict_remove_db_name()

const char* dict_remove_db_name ( const char *  name)

Return the end of table name where we have removed dbname and '/'.

Returns
table name
Parameters
namein: table name in the form dbname '/' tablename

◆ dict_resize()

void dict_resize ( )

Resize the hash tables besed on the current buffer pool size.

◆ dict_sdi_close_table()

void dict_sdi_close_table ( dict_table_t table)

Close SDI table.

Parameters
[in]tablethe in-meory SDI table object

◆ dict_sdi_get_index()

dict_index_t* dict_sdi_get_index ( space_id_t  tablespace_id)

Retrieve in-memory index for SDI table.

Parameters
[in]tablespace_idinnodb tablespace id
Returns
dict_index_t structure or NULL

◆ dict_sdi_get_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.

Parameters
[in]tablespace_idinnodb tablespace id
[in]dict_lockedtrue if dict_sys mutex is acquired
[in]is_createtrue if we are creating index
Returns
dict_table_t structure

◆ dict_sdi_remove_from_cache()

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.

Parameters
[in]space_idInnoDB tablespace ID
[in]sdi_tablesdi table
[in]dict_lockedtrue if dict_sys mutex acquired

◆ dict_set_corrupted()

void dict_set_corrupted ( dict_index_t index)

Flags an index corrupted in the data dictionary cache only.

This is used to mark a corrupted index when index's own dictionary is corrupted, and we would force to load such index for repair purpose. Besides, we have to write a redo log. We don't want to hold dict_sys->mutex here, so that we can set index as corrupted in some low-level functions. We would only set the flags from not corrupted to corrupted when server is running, so it should be safe to set it directly.

Parameters
[in,out]indexindex, must not be NULL

◆ dict_set_merge_threshold_all_debug()

void dict_set_merge_threshold_all_debug ( uint  merge_threshold_all)

Sets merge_threshold for all indexes in dictionary cache for debug.

Parameters
[in]merge_threshold_allvalue to set for all indexes

◆ dict_set_merge_threshold_list_debug()

void dict_set_merge_threshold_list_debug ( UT_LIST_BASE_NODE_T(dict_table_t) *  list,
uint  merge_threshold_all 
)
inline

Sets merge_threshold for all indexes in the list of tables.

Parameters
[in]listpointer to the list of tables
[in]merge_threshold_allvalue to set for all indexes

◆ dict_sys_table_id_build()

bool dict_sys_table_id_build ( )

Build the table_id array of SYS_* tables.

This array is used to determine if a table is InnoDB SYSTEM table or not.

Returns
true if successful, false otherwise

◆ dict_table_add_system_columns()

void dict_table_add_system_columns ( dict_table_t table,
mem_heap_t heap 
)

Adds system columns to a table object.

Parameters
tablein/out: table
heapin: temporary heap

◆ dict_table_add_to_cache()

void dict_table_add_to_cache ( dict_table_t table,
ibool  can_be_evicted,
mem_heap_t heap 
)

Adds a table object to the dictionary cache.

Parameters
[in,out]tabletable
[in]can_be_evictedtrue if can be evicted
[in,out]heaptemporary heap

◆ dict_table_apply_dynamic_metadata()

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 during recovery.

Parameters
[in,out]tabletable
[in]metadatastructure of persistent metadata
Returns
true if we do apply something to the in-memory table object, otherwise false

◆ dict_table_autoinc_alloc()

static void dict_table_autoinc_alloc ( void *  table_void)
static

Allocate and init the autoinc latch of a given table.

This function must not be called concurrently on the same table object.

Parameters
[in,out]table_voidtable whose autoinc latch to create

◆ dict_table_autoinc_initialize()

void dict_table_autoinc_initialize ( dict_table_t table,
ib_uint64_t  value 
)

Unconditionally set the autoinc counter.

Parameters
tablein/out: table
valuein: next value to assign to a row

◆ dict_table_autoinc_lock()

void dict_table_autoinc_lock ( dict_table_t table)

Acquire the autoinc lock.

Parameters
tablein/out: table

◆ dict_table_autoinc_log()

void dict_table_autoinc_log ( dict_table_t table,
uint64_t  value,
mtr_t mtr 
)

Write redo logs for autoinc counter that is to be inserted, or to update some existing smaller one to bigger.

Parameters
[in,out]tableInnoDB table object
[in]valueAUTOINC counter to log
[in,out]mtrmini-transaction

◆ dict_table_autoinc_read()

ib_uint64_t dict_table_autoinc_read ( const dict_table_t table)

Reads the next autoinc value (== autoinc counter value), 0 if not yet initialized.

Returns
value for a new row, or 0
Parameters
tablein: table

◆ dict_table_autoinc_unlock()

void dict_table_autoinc_unlock ( dict_table_t table)

Release the autoinc lock.

Parameters
tablein/out: table

◆ dict_table_autoinc_update_if_greater()

void dict_table_autoinc_update_if_greater ( dict_table_t table,
ib_uint64_t  value 
)

Updates the autoinc counter if the value supplied is greater than the current value.

Parameters
tablein/out: table
valuein: value which was assigned to a row

◆ dict_table_can_be_evicted()

static ibool dict_table_can_be_evicted ( dict_table_t table)
static

Test whether a table can be evicted from the LRU cache.

Returns
true if table can be evicted.
Parameters
tablein: table to test

◆ dict_table_change_id_in_cache()

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.

This is used in DISCARD TABLESPACE.

Parameters
tablein/out: table object already in cache
new_idin: new id to set

◆ dict_table_change_id_sys_tables()

void dict_table_change_id_sys_tables ( )

Change the table_id of SYS_* tables if they have been created after an earlier upgrade.

This will update the table_id by adding DICT_MAX_DD_TABLES

◆ dict_table_check_for_dup_indexes()

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].

in: whether and when to allow temporary index names

Parameters
tablein: Check for dup indexes in this table
checkin: whether and when to allow temporary index names

◆ dict_table_close()

void dict_table_close ( dict_table_t table,
ibool  dict_locked,
ibool  try_drop 
)

Decrements the count of open handles to a table.

Parameters
tablein/out: table
dict_lockedin: TRUE=data dictionary locked
try_dropin: TRUE=try to drop any orphan indexes after an aborted online index creation

◆ dict_table_close_and_drop()

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 the whole time.

This assures that the table is not evicted after the close when the count of open handles goes to zero. Because dict_sys->mutex is held, we do not need to call dict_table_prevent_eviction().

Parameters
trxin: data dictionary transaction
tablein/out: table

◆ dict_table_col_in_clustered_key()

ibool dict_table_col_in_clustered_key ( const dict_table_t table,
ulint  n 
)

Checks if a column is in the ordering columns of the clustered index of a table.

Column prefixes are treated like whole columns.

Returns
true if the column, or its prefix, is in the clustered key
Parameters
tablein: table
nin: column number

◆ dict_table_copy_types()

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 value.

This function should be called right after dtuple_create().

Parameters
tuplein/out: data tuple
tablein: table

◆ dict_table_copy_v_types()

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 SQL NULL value.

This function should be called right after dtuple_create().

Parameters
[in,out]tupledata tuple
[in]tabletable

◆ dict_table_extent_size()

page_no_t dict_table_extent_size ( const dict_table_t table)

Determine the extent size (in pages) for the given table.

Parameters
[in]tablethe table whose extent size is being calculated.
Returns
extent size in pages (256, 128 or 64)

◆ dict_table_find_index_on_id()

static const dict_index_t* dict_table_find_index_on_id ( const dict_table_t table,
const index_id_t id 
)
static

Look up an index in a table.

Parameters
[in]tabletable
[in]idindex identifier
Returns
index
Return values
NULLif not found

◆ dict_table_get_all_fts_indexes()

ulint dict_table_get_all_fts_indexes ( dict_table_t table,
ib_vector_t indexes 
)

Get all the FTS indexes on a table.

Parameters
[in]tabletable
[out]indexesall FTS indexes on this table
Returns
number of FTS indexes

◆ dict_table_get_datadir()

std::string dict_table_get_datadir ( const dict_table_t table)

Get the tablespace data directory if set, otherwise empty string.

Returns
the data directory

◆ dict_table_get_highest_foreign_id()

ulint dict_table_get_highest_foreign_id ( dict_table_t table)

Finds the highest [number] for foreign key constraints of the table.

Looks only at the >= 4.0.18-format id's, which are of the form databasename/tablename_ibfk_[number]. TODO: Remove this function once in-place ALTER TABLE code is updated to avoid its use.

Returns
highest number, 0 if table has no new format foreign key constraints
Parameters
tablein: table in the dictionary memory cache

◆ dict_table_get_index_on_name()

dict_index_t* dict_table_get_index_on_name ( dict_table_t table,
const char *  name,
bool  committed 
)

Get an index by name.

Parameters
[in]tablethe table where to look for the index
[in]namethe index name to look for
[in]committedtrue=search for committed, false=search for uncommitted
Returns
index, NULL if does not exist

◆ dict_table_get_nth_col_pos()

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.

Returns
position in internal representation of the clustered index
Parameters
tablein: table
nin: column number

◆ dict_table_get_nth_v_col_mysql()

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.

Get nth virtual column.

Parameters
[in]tabletarget table
[in]col_nrcolumn number in MySQL Table definition
Returns
dict_v_col_t ptr

◆ dict_table_get_v_col_name()

const char* dict_table_get_v_col_name ( const dict_table_t table,
ulint  col_nr 
)

Returns a virtual column's name.

Parameters
[in]tabletarget table
[in]col_nrvirtual column number (nth virtual column)
Returns
column name or NULL if column number out of range.

◆ dict_table_get_v_col_name_mysql()

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.

Parameters
[in]tabletarget table
[in]col_nrcolumn number (nth column in the table)
Returns
column name.

◆ dict_table_get_v_col_pos_for_mysql()

static ulint dict_table_get_v_col_pos_for_mysql ( const dict_table_t table,
ulint  col_nr 
)
static

Search virtual column's position in InnoDB according to its position in original table's position.

Parameters
[in]tabletarget table
[in]col_nrcolumn number (nth column in the MySQL table)
Returns
virtual column's position in InnoDB, ULINT_UNDEFINED if not find

◆ dict_table_has_column()

ulint dict_table_has_column ( const dict_table_t table,
const char *  col_name,
ulint  col_nr 
)

Check if the table has a given (non_virtual) column.

Check if the table has a given column.

Parameters
[in]tabletable object
[in]col_namecolumn name
[in]col_nrcolumn number guessed, 0 as default
Returns
column number if the table has the specified column, otherwise table->n_def

The order of column may changed, check it with other columns

◆ dict_table_is_referenced_by_foreign_key()

ibool dict_table_is_referenced_by_foreign_key ( const dict_table_t table)

Checks if a table is referenced by foreign keys.

Returns
true if table is referenced by a foreign key
Parameters
tablein: InnoDB table

◆ dict_table_is_system()

bool dict_table_is_system ( table_id_t  table_id)
Returns
true if table is InnoDB SYS_* table
Parameters
[in]table_idtable id

◆ dict_table_load_dynamic_metadata()

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 specific table.

If so, read the metadata and update the table object accordingly. It's used when loading table.

Parameters
[in]tabletable object

◆ dict_table_mark_dirty()

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 necessary.

Parameters
[in,out]tabletable

◆ dict_table_move_from_lru_to_non_lru()

void dict_table_move_from_lru_to_non_lru ( dict_table_t table)

Move a table to the non-LRU list from the LRU list.

Move a table to the non LRU end of the LRU list.

Parameters
tablein: table to move from LRU to non-LRU

◆ dict_table_move_from_non_lru_to_lru()

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.

Parameters
[in]tableInnoDB table object

◆ dict_table_mysql_pos_to_innodb()

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 position n.

Parameters
[in]tabletable
[in]nMySQL column position
Returns
column position in InnoDB

◆ dict_table_open_on_name()

dict_table_t* dict_table_open_on_name ( const char *  table_name,
ibool  dict_locked,
ibool  try_drop,
dict_err_ignore_t  ignore_err 
)

Returns a table object and increment its open handle count.

Returns a table object and increments its open handle count.

NOTE! This is a high-level function to be used mainly from outside the 'dict' module. Inside this directory dict_table_get_low is usually the appropriate function.

Returns
table, NULL if does not exist
Parameters
table_namein: table name
dict_lockedin: TRUE=data dictionary locked
try_dropin: TRUE=try to drop any orphan indexes after an aborted online index creation
ignore_errin: error to be ignored when loading a table definition

◆ dict_table_persist_to_dd_table_buffer()

void dict_table_persist_to_dd_table_buffer ( dict_table_t table)

Write back the dirty persistent dynamic metadata of the table to DDTableBuffer.

Parameters
[in,out]tabletable object

◆ dict_table_persist_to_dd_table_buffer_low()

static void dict_table_persist_to_dd_table_buffer_low ( dict_table_t table)
static

Write the dirty persistent dynamic metadata for a table to DD TABLE BUFFER table.

This is the low level function to write back.

Parameters
[in,out]tabletable to write

◆ dict_table_read_dynamic_metadata()

void dict_table_read_dynamic_metadata ( const byte buffer,
ulint  size,
PersistentTableMetadata metadata 
)

Read persistent dynamic metadata stored in a buffer.

Parameters
[in]bufferbuffer to read
[in]sizesize of data in buffer
[in]metadatawhere we store the metadata from buffer

◆ dict_table_remove_from_cache()

void dict_table_remove_from_cache ( dict_table_t table)

Removes a table object from the dictionary cache.

Parameters
tablein, own: table

◆ dict_table_remove_from_cache_debug()

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.

Parameters
[in,out]tabletable object
[in]lru_evicttrue if table being evicted to make room in the table LRU list

◆ dict_table_remove_from_cache_low()

static void dict_table_remove_from_cache_low ( dict_table_t table,
ibool  lru_evict 
)
static

Removes a table object from the dictionary cache.

in: TRUE if evicting from LRU

Parameters
tablein, own: table
lru_evictin: TRUE if table being evicted to make room in the table LRU list

◆ dict_table_rename_in_cache()

dberr_t dict_table_rename_in_cache ( dict_table_t table,
const char *  new_name,
ibool  rename_also_foreigns 
)

Renames a table object.

Returns
true if success
Parameters
tablein/out: table
new_namein: new name
rename_also_foreignsin: in ALTER TABLE we want to preserve the original table name in constraints which reference it

◆ dict_table_set_big_rows()

void dict_table_set_big_rows ( dict_table_t table)

Mark if table has big rows.

Parameters
[in,out]tabletable handler

◆ dict_table_stats_latch_alloc()

static void dict_table_stats_latch_alloc ( void *  table_void)
static

Allocate and init a dict_table_t's stats latch.

This function must not be called concurrently on the same table object.

Parameters
[in,out]table_voidtable whose stats latch to create

◆ dict_table_stats_latch_create()

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.

This function is only called from either single threaded environment or from a thread that has not shared the table object with other threads.

Parameters
[in,out]tabletable whose stats latch to create
[in]enabledif false then the latch is disabled and dict_table_stats_lock()/unlock() become noop on this table.

◆ dict_table_stats_latch_destroy()

void dict_table_stats_latch_destroy ( dict_table_t table)

Destroy a dict_table_t's stats latch.

This function is only called from either single threaded environment or from a thread that has not shared the table object with other threads.

Parameters
[in,out]tabletable whose stats latch to destroy

◆ dict_table_stats_latch_free()

static void dict_table_stats_latch_free ( dict_table_t table)
static

Deinit and free a dict_table_t's stats latch.

This function must not be called concurrently on the same table object.

Parameters
[in,out]tabletable whose stats latch to free

◆ dict_table_stats_lock()

void dict_table_stats_lock ( dict_table_t table,
ulint  latch_mode 
)

Lock the appropriate latch to protect a given table's statistics.

Parameters
[in]tabletable whose stats to lock
[in]latch_modeRW_S_LATCH or RW_X_LATCH

◆ dict_table_stats_unlock()

void dict_table_stats_unlock ( dict_table_t table,
ulint  latch_mode 
)

Unlock the latch that has been locked by dict_table_stats_lock().

Parameters
[in]tabletable whose stats to unlock
[in]latch_modeRW_S_LATCH or RW_X_LATCH

◆ dict_table_try_drop_aborted()

static void dict_table_try_drop_aborted ( dict_table_t table,
table_id_t  table_id,
ulint  ref_count 
)
static

Try to drop any indexes after an aborted index creation.

This can also be after a server kill during DROP INDEX.

Parameters
tablein: table, or NULL if it needs to be looked up again
table_idin: table identifier
ref_countin: expected table->n_ref_count

◆ dict_table_try_drop_aborted_and_mutex_exit()

static void dict_table_try_drop_aborted_and_mutex_exit ( dict_table_t table,
ibool  try_drop 
)
static

When opening a table, try to drop any indexes after an aborted index creation.

Release the dict_sys->mutex.

Parameters
tablein: table (may be NULL)
try_dropin: FALSE if should try to drop indexes whose online creation was aborted

◆ dict_table_wait_for_bg_threads_to_exit()

void dict_table_wait_for_bg_threads_to_exit ( dict_table_t table,
ulint  delay 
)
Parameters
tablein: table
delayin: time in microseconds to wait between checks of bg_threads.

◆ dict_tables_have_same_db()

ibool dict_tables_have_same_db ( const char *  name1,
const char *  name2 
)

Checks if the database name in two table names is the same.

Returns
true if same db name
Parameters
name1in: table name in the form dbname '/' tablename
name2in: table name in the form dbname '/' tablename

◆ dict_tf_to_fsp_flags()

uint32_t dict_tf_to_fsp_flags ( uint32_t  table_flags)

Convert a 32 bit integer table flags to the 32 bit FSP Flags.

Fsp Flags are written into the tablespace header at the offset FSP_SPACE_FLAGS and are also stored in the fil_space_t::flags field. The following chart shows the translation of the low order bit. Other bits are the same. Low order bit | REDUNDANT | COMPACT | COMPRESSED | DYNAMIC dict_table_t::flags | 0 | 1 | 1 | 1 fil_space_t::flags | 0 | 0 | 1 | 1

Parameters
[in]table_flagsdict_table_t::flags
Returns
tablespace flags (fil_space_t::flags)

◆ dict_tf_to_row_format_string()

const char* dict_tf_to_row_format_string ( uint32_t  table_flag)

Convert table flag to row format string.

Returns
row format name.
Parameters
table_flagin: row format setting

◆ dict_upgrade_evict_tables_cache()

void dict_upgrade_evict_tables_cache ( )

Evict all tables that are loaded for applying purge.

Since we move the offset of all table ids during upgrade, these tables cannot exist in cache. Also change table_ids of SYS_* tables if they are upgraded from earlier versions

Variable Documentation

◆ dict_foreign_err_file

FILE* dict_foreign_err_file = nullptr

◆ dict_foreign_err_mutex

ib_mutex_t dict_foreign_err_mutex

◆ dict_ibfk

char dict_ibfk[] = "_ibfk_"
static

Identifies generated InnoDB foreign key names.

◆ dict_ind_redundant

dict_index_t* dict_ind_redundant

dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records

◆ dict_operation_lock

rw_lock_t* dict_operation_lock

the data dictionary rw-latch protecting dict_sys

table create, drop, etc. reserve this in X-mode; implicit or backround operations purge, rollback, foreign key checks reserve this in S-mode; we cannot trust that MySQL protects implicit or background operations a table drop since MySQL does not know of them; therefore we need this; NOTE: a transaction which reserves this must keep book on the mode in trx_t::dict_operation_lock_mode

◆ dict_persist

dict_persist_t* dict_persist = nullptr

the dictionary persisting structure

◆ dict_sys

dict_sys_t* dict_sys = nullptr

the dictionary system

◆ dict_sys_table_id

table_id_t dict_sys_table_id[SYS_NUM_SYSTEM_TABLES]
static

Array to store table_ids of INNODB_SYS_* TABLES.

◆ ibuf_debug

uint ibuf_debug

Flag to control insert buffer debugging.

◆ zip_failure_threshold_pct

ulong zip_failure_threshold_pct = 5

Percentage of compression failures that are allowed in a single round.

◆ zip_pad_max

ulong zip_pad_max = 50

Maximum percentage of a page that can be allowed as a pad to avoid compression failures.