MySQL 8.4.2
Source Code Documentation
dict0load.h File Reference

Loads to the memory cache database object definitions from dictionary tables. More...

#include "btr0types.h"
#include "dict0types.h"
#include "fil0fil.h"
#include "mem0mem.h"
#include "trx0types.h"
#include "univ.i"
#include "ut0byte.h"
#include "ut0new.h"
#include <deque>

Go to the source code of this file.

Classes

struct  space_compare
 

Typedefs

typedef std::deque< const char *, ut::allocator< const char * > > dict_names_t
 A stack of table names related through foreign key constraints. More...
 
using missing_sys_tblsp_t = std::set< fil_space_t *, space_compare >
 

Enumerations

enum  dict_system_id_t {
  SYS_TABLES = 0 , SYS_INDEXES , SYS_COLUMNS , SYS_FIELDS ,
  SYS_FOREIGN , SYS_FOREIGN_COLS , SYS_TABLESPACES , SYS_DATAFILES ,
  SYS_VIRTUAL , SYS_NUM_SYSTEM_TABLES
}
 enum that defines all system table IDs. More...
 
enum  dict_table_info_t { DICT_TABLE_LOAD_FROM_RECORD = 0 , DICT_TABLE_LOAD_FROM_CACHE = 1 }
 Status bit for dict_process_sys_tables_rec_and_mtr_commit() More...
 

Functions

char * dict_get_first_table_name_in_db (const char *name)
 Finds the first table name in the given database. More...
 
char * dict_get_first_path (ulint space_id)
 Get the first filepath from SYS_DATAFILES for a given space_id. More...
 
void dict_get_and_save_data_dir_path (dict_table_t *table, bool dict_mutex_own)
 Make sure the data_dir_path is saved in dict_table_t if DATA DIRECTORY was used. More...
 
void dict_get_and_save_space_name (dict_table_t *table)
 Make sure the tablespace name is saved in dict_table_t if the table uses a general tablespace. More...
 
dict_table_tdict_load_table (const char *name, bool cached, dict_err_ignore_t ignore_err, const std::string *prev_table=nullptr)
 Loads a table definition and also all its index definitions, and also the cluster definition if the table is a member in a cluster. More...
 
void dict_load_sys_table (dict_table_t *table)
 This function is called when the database is booted. More...
 
dberr_t dict_load_foreigns (const char *table_name, const char **col_names, bool check_recursive, bool check_charsets, dict_err_ignore_t ignore_err, dict_names_t &fk_tables)
 Loads foreign key constraints where the table is either the foreign key holder or where the table is referenced by a foreign key. More...
 
const rec_tdict_startscan_system (btr_pcur_t *pcur, mtr_t *mtr, dict_system_id_t system_id)
 This function opens a system table, and return the first record. More...
 
const rec_tdict_getnext_system (btr_pcur_t *pcur, mtr_t *mtr)
 This function get the next system table record as we scan the table. More...
 
const char * dict_process_sys_tablespaces (mem_heap_t *heap, const rec_t *rec, space_id_t *space, const char **name, uint32_t *flags)
 This function parses a SYS_TABLESPACES record, extracts necessary information from the record and returns to caller. More...
 
void dict_load_tablespace (dict_table_t *table, dict_err_ignore_t ignore_err)
 Opens a tablespace for dict_load_table_one() More...
 
void dict_save_data_dir_path (dict_table_t *table, char *filepath)
 Using the table->heap, copy the null-terminated filepath into table->data_dir_path. More...
 

Variables

const char * SYSTEM_TABLE_NAME []
 Following are the InnoDB system tables. More...
 
missing_sys_tblsp_t missing_spaces
 
bool has_discarded_tablespaces
 This bool denotes if we found a Table or Partition with discarded Tablespace during load of SYS_TABLES (in dict_check_sys_tables). More...
 

Detailed Description

Loads to the memory cache database object definitions from dictionary tables.

Created 4/24/1996 Heikki Tuuri

Typedef Documentation

◆ dict_names_t

typedef std::deque<const char *, ut::allocator<const char *> > dict_names_t

A stack of table names related through foreign key constraints.

◆ missing_sys_tblsp_t

Enumeration Type Documentation

◆ dict_system_id_t

enum that defines all system table IDs.

See also
SYSTEM_TABLE_NAME[]
Enumerator
SYS_TABLES 
SYS_INDEXES 
SYS_COLUMNS 
SYS_FIELDS 
SYS_FOREIGN 
SYS_FOREIGN_COLS 
SYS_TABLESPACES 
SYS_DATAFILES 
SYS_VIRTUAL 
SYS_NUM_SYSTEM_TABLES 

◆ dict_table_info_t

Status bit for dict_process_sys_tables_rec_and_mtr_commit()

Enumerator
DICT_TABLE_LOAD_FROM_RECORD 

Directly populate a dict_table_t structure with information from a SYS_TABLES record.

DICT_TABLE_LOAD_FROM_CACHE 

Check first whether dict_table_t is in the cache, if so, return it.

Function Documentation

◆ dict_get_and_save_data_dir_path()

void dict_get_and_save_data_dir_path ( dict_table_t table,
bool  dict_mutex_own 
)

Make sure the data_dir_path is saved in dict_table_t if DATA DIRECTORY was used.

Try to read it from the fil_system first, then from SYS_DATAFILES.

Parameters
[in]tableTable object
[in]dict_mutex_owntrue if dict_sys->mutex is owned already

◆ dict_get_and_save_space_name()

void dict_get_and_save_space_name ( dict_table_t table)

Make sure the tablespace name is saved in dict_table_t if the table uses a general tablespace.

Try to read it from the fil_system_t first, then from SYS_TABLESPACES.

Parameters
[in]tableTable object

◆ dict_get_first_path()

char * dict_get_first_path ( ulint  space_id)

Get the first filepath from SYS_DATAFILES for a given space_id.

Parameters
[in]space_idTablespace ID
Returns
First filepath (caller must invoke ut::free() on it)
Return values
NULLif no SYS_DATAFILES entry was found.

◆ dict_get_first_table_name_in_db()

char * dict_get_first_table_name_in_db ( const char *  name)

Finds the first table name in the given database.

Returns
own: table name, NULL if does not exist; the caller must free the memory in the string! in: database name which ends to '/'
own: table name, NULL if does not exist; the caller must free the memory in the string!
Parameters
namein: database name which ends in '/'

◆ dict_getnext_system()

const rec_t * dict_getnext_system ( btr_pcur_t pcur,
mtr_t mtr 
)

This function get the next system table record as we scan the table.

Returns
the record if found, NULL if end of scan. in: the mini-transaction

This function get the next system table record as we scan the table.

Returns
the next record if found, NULL if end of scan
Parameters
pcurin/out: persistent cursor to the record
mtrin: the mini-transaction

◆ dict_load_foreigns()

dberr_t dict_load_foreigns ( const char *  table_name,
const char **  col_names,
bool  check_recursive,
bool  check_charsets,
dict_err_ignore_t  ignore_err,
dict_names_t fk_tables 
)

Loads foreign key constraints where the table is either the foreign key holder or where the table is referenced by a foreign key.

Adds these constraints to the data dictionary.

The foreign key constraint is loaded only if the referenced table is also in the dictionary cache. If the referenced table is not in dictionary cache, then it is added to the output parameter (fk_tables).

Returns
DB_SUCCESS or error code out: stack of table names which must be loaded subsequently to load all the foreign key constraints.

Adds these constraints to the data dictionary.

The foreign key constraint is loaded only if the referenced table is also in the dictionary cache. If the referenced table is not in dictionary cache, then it is added to the output parameter (fk_tables).

Returns
DB_SUCCESS or error code
Parameters
table_namein: table name
col_namesin: column names, or NULL to use table->col_names
check_recursivein: Whether to check recursive load of tables chained by FK
check_charsetsin: whether to check charset compatibility
ignore_errin: error to be ignored
fk_tablesout: stack of table names which must be loaded subsequently to load all the foreign key constraints.

◆ dict_load_sys_table()

void dict_load_sys_table ( dict_table_t table)

This function is called when the database is booted.

Loads system table index definitions except for the clustered index which is added to the dictionary cache at booting before calling this function. in: system table

Loads system table index definitions except for the clustered index which is added to the dictionary cache at booting before calling this function.

Parameters
tablein: system table

◆ dict_load_table()

dict_table_t * dict_load_table ( const char *  name,
bool  cached,
dict_err_ignore_t  ignore_err,
const std::string *  prev_table = nullptr 
)

Loads a table definition and also all its index definitions, and also the cluster definition if the table is a member in a cluster.

Also loads all foreign key constraints where the foreign key is in the table or where a foreign key references columns in this table.

Parameters
[in]nameTable name in the dbname/tablename format
[in]cachedtrue=add to cache, false=do not
[in]ignore_errError to be ignored when loading table and its index definition
[in]prev_tableprevious table name. The current table load is happening because of the load of the previous table name. This parameter is used to check for cyclic calls.
Returns
table, NULL if does not exist; if the table is stored in an .ibd file, but the file does not exist, then we set the ibd_file_missing flag in the table object we return.

◆ dict_load_tablespace()

void dict_load_tablespace ( dict_table_t table,
dict_err_ignore_t  ignore_err 
)

Opens a tablespace for dict_load_table_one()

Parameters
[in,out]tableA table that refers to the tablespace to open
[in]ignore_errWhether to ignore an error.

◆ dict_process_sys_tablespaces()

const char * dict_process_sys_tablespaces ( mem_heap_t heap,
const rec_t rec,
space_id_t space,
const char **  name,
uint32_t *  flags 
)

This function parses a SYS_TABLESPACES record, extracts necessary information from the record and returns to caller.

Returns
error message, or NULL on success out: tablespace flags
error message, or NULL on success
Parameters
heapin/out: heap memory
recin: current SYS_TABLESPACES rec
spaceout: space id
nameout: tablespace name
flagsout: tablespace flags

◆ dict_save_data_dir_path()

void dict_save_data_dir_path ( dict_table_t table,
char *  filepath 
)

Using the table->heap, copy the null-terminated filepath into table->data_dir_path.

The data directory path is derived from the filepath by stripping the the table->name.m_name component suffix. If the filepath is not of the correct form (".../db/table.ibd"), then table->data_dir_path will remain nullptr.

Parameters
[in,out]tabletable instance
[in]filepathfilepath of tablespace

◆ dict_startscan_system()

const rec_t * dict_startscan_system ( btr_pcur_t pcur,
mtr_t mtr,
dict_system_id_t  system_id 
)

This function opens a system table, and return the first record.

Returns
first record of the system table in: which system table to open

This function opens a system table, and return the first record.

Returns
first record of the system table
Parameters
pcurout: persistent cursor to the record
mtrin: the mini-transaction
system_idin: which system table to open

Variable Documentation

◆ has_discarded_tablespaces

bool has_discarded_tablespaces
extern

This bool denotes if we found a Table or Partition with discarded Tablespace during load of SYS_TABLES (in dict_check_sys_tables).

TODO To be removed in WL#16210

◆ missing_spaces

missing_sys_tblsp_t missing_spaces
extern

◆ SYSTEM_TABLE_NAME

const char* SYSTEM_TABLE_NAME[]
extern

Following are the InnoDB system tables.

The positions in this array are referenced by enum dict_system_table_id.