MySQL 8.0.39
Source Code Documentation
|
Loads to the memory cache database object definitions from dictionary tables. More...
#include "current_thd.h"
#include "ha_prototypes.h"
#include <set>
#include <stack>
#include "dict0load.h"
#include "btr0btr.h"
#include "btr0pcur.h"
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "dict0mem.h"
#include "dict0priv.h"
#include "dict0stats.h"
#include "fsp0file.h"
#include "fsp0sysspace.h"
#include "fts0priv.h"
#include "mach0data.h"
#include "my_dbug.h"
#include "fil0fil.h"
#include "fts0fts.h"
#include "mysql_version.h"
#include "page0page.h"
#include "rem0cmp.h"
#include "srv0srv.h"
#include "srv0start.h"
Functions | |
static bool | dict_load_is_system_table (const char *name) |
This variant is based on name comparison and is used because system table id array is not built yet. More... | |
static dict_table_t * | dict_load_table_one (table_name_t &name, bool cached, dict_err_ignore_t ignore_err, dict_names_t &fk_tables, const std::string *prev_table) |
Loads a table definition and also all its index definitions. More... | |
static const char * | dict_load_table_low (table_name_t &name, const rec_t *rec, dict_table_t **table) |
Loads a table definition from a SYS_TABLES record to dict_table_t. More... | |
static bool | name_of_col_is (const dict_table_t *table, const dict_index_t *index, ulint i, const char *name) |
Compare the name of an index column. More... | |
char * | dict_get_first_table_name_in_db (const char *name) |
Finds the first table name in the given database. More... | |
static const rec_t * | dict_getnext_system_low (btr_pcur_t *pcur, mtr_t *mtr) |
This function gets the next system table record as it scans the table. More... | |
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 returns the first record. More... | |
const rec_t * | dict_getnext_system (btr_pcur_t *pcur, mtr_t *mtr) |
This function gets the next system table record as it scans the table. More... | |
static const char * | dict_load_index_low (byte *table_id, const char *table_name, mem_heap_t *heap, const rec_t *rec, bool allocate, dict_index_t **index) |
Load an index definition from a SYS_INDEXES record to dict_index_t. More... | |
static const char * | dict_load_column_low (dict_table_t *table, mem_heap_t *heap, dict_col_t *column, table_id_t *table_id, const char **col_name, const rec_t *rec, ulint *nth_v_col) |
Load a table column definition from a SYS_COLUMNS record to dict_table_t. More... | |
static const char * | dict_load_virtual_low (dict_table_t *table, dict_col_t **column, table_id_t *table_id, ulint *pos, ulint *base_pos, const rec_t *rec) |
Loads a virtual column "mapping" (to base columns) information from a SYS_VIRTUAL record. More... | |
static void | dict_load_virtual_one_col (dict_table_t *table, ulint nth_v_col, dict_v_col_t *v_col, mem_heap_t *heap) |
Loads SYS_VIRTUAL info for one virtual column. More... | |
static void | dict_load_virtual (dict_table_t *table, mem_heap_t *heap) |
Loads info from SYS_VIRTUAL for virtual columns. More... | |
static const char * | dict_load_field_low (byte *index_id, dict_index_t *index, mem_heap_t *heap, const rec_t *rec) |
Loads an index field definition from a SYS_FIELDS record to dict_index_t. 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... | |
char * | dict_get_first_path (ulint space_id) |
Get the first filepath from SYS_DATAFILES for a given space_id. More... | |
static char * | dict_space_get_name (space_id_t space_id, mem_heap_t *callers_heap) |
Gets the space name from SYS_TABLESPACES for a given space ID. More... | |
static const char * | dict_sys_tables_rec_check (const rec_t *rec) |
Check the validity of a SYS_TABLES record Make sure the fields are the right length and that they do not contain invalid contents. More... | |
static bool | dict_sys_tablespaces_rec_read (const rec_t *rec, space_id_t *id, char *name, uint32_t *flags) |
Read and return the contents of a SYS_TABLESPACES record. More... | |
static space_id_t | dict_check_sys_tablespaces (bool validate) |
Load and check each general tablespace mentioned in the SYS_TABLESPACES. More... | |
static bool | dict_sys_tables_rec_read (const rec_t *rec, const table_name_t &table_name, table_id_t *table_id, space_id_t *space_id, uint32_t *n_cols, uint32_t *flags, uint32_t *flags2) |
Read and return 5 integer fields from a SYS_TABLES record. More... | |
static space_id_t | dict_check_sys_tables (bool validate) |
Load and check each non-predefined tablespace mentioned in SYS_TABLES. More... | |
static void | dict_load_columns (dict_table_t *table, mem_heap_t *heap) |
Load columns in an innodb cached table object from SYS_COLUMNS table. More... | |
static ulint | dict_load_fields (dict_index_t *index, mem_heap_t *heap) |
Loads definitions for index fields. More... | |
static dberr_t | dict_load_indexes (dict_table_t *table, mem_heap_t *heap, dict_err_ignore_t ignore_err) |
Loads definitions for table indexes. 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... | |
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_t * | dict_load_table (const char *name, bool cached, dict_err_ignore_t ignore_err, const std::string *prev_table) |
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_tablespace (dict_table_t *table, dict_err_ignore_t ignore_err) |
Opens a tablespace for dict_load_table_one() More... | |
void | dict_load_sys_table (dict_table_t *table) |
This function is called when the database is booted. More... | |
static void | dict_load_foreign_cols (dict_foreign_t *foreign) |
Loads foreign key constraint col names (also for the referenced table). More... | |
static dberr_t | dict_load_foreign (const char *id, const char **col_names, bool check_recursive, bool check_charsets, dict_err_ignore_t ignore_err, dict_names_t &fk_tables) |
Loads a foreign key constraint to the dictionary cache. 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... | |
void | dict_load_tablespaces_for_upgrade () |
Load all tablespaces during upgrade. More... | |
Variables | |
const char * | SYSTEM_TABLE_NAME [] |
Following are the InnoDB system tables. More... | |
missing_sys_tblsp_t | missing_spaces |
bool | has_discarded_tablespaces = false |
This bool denotes if we found a Table or Partition with discarded Tablespace during load of SYS_TABLES (in dict_check_sys_tables). More... | |
bool | srv_load_corrupted = false |
static const char * | dict_load_index_del = "delete-marked record in SYS_INDEXES" |
Error message for a delete-marked record in dict_load_index_low() More... | |
static const char * | dict_load_index_id_err = "SYS_INDEXES.TABLE_ID mismatch" |
Error message for table->id mismatch in dict_load_index_low() More... | |
static const char * | dict_load_column_del = "delete-marked record in SYS_COLUMN" |
Error message for a delete-marked record in dict_load_column_low() More... | |
static const char * | dict_load_virtual_del |
Error message for a delete-marked record in dict_load_virtual_low() More... | |
static const char * | dict_load_field_del = "delete-marked record in SYS_FIELDS" |
Error message for a delete-marked record in dict_load_field_low() More... | |
Loads to the memory cache database object definitions from dictionary tables.
Created 4/24/1996 Heikki Tuuri
|
inlinestatic |
Load and check each non-predefined tablespace mentioned in SYS_TABLES.
Search SYS_TABLES and check each tablespace mentioned that has not already been added to the fil_system. If it is valid, add it to the file_system list. Perform extra validation on the table if recovery from the REDO log occurred.
[in] | validate | Whether to do validation on the table. |
|
inlinestatic |
Load and check each general tablespace mentioned in the SYS_TABLESPACES.
Ignore system and file-per-table tablespaces. If it is valid, add it to the file_system list.
[in] | validate | true when the previous shutdown was not clean |
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.
[in] | table | Table object |
[in] | dict_mutex_own | true if dict_sys->mutex is owned already |
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.
[in] | table | Table object |
char * dict_get_first_path | ( | ulint | space_id | ) |
Get the first filepath from SYS_DATAFILES for a given space_id.
[in] | space_id | Tablespace ID |
NULL | if no SYS_DATAFILES entry was found. |
char * dict_get_first_table_name_in_db | ( | const char * | name | ) |
Finds the first table name in the given database.
name | in: database name which ends in '/' |
const rec_t * dict_getnext_system | ( | btr_pcur_t * | pcur, |
mtr_t * | mtr | ||
) |
This function gets the next system table record as it scans the table.
This function get the next system table record as we scan the table.
pcur | in/out: persistent cursor to the record |
mtr | in: the mini-transaction |
|
static |
This function gets the next system table record as it scans the table.
pcur | in/out: persistent cursor to the record |
mtr | in: the mini-transaction |
|
static |
Load a table column definition from a SYS_COLUMNS record to dict_table_t.
table | in/out: table, could be NULL if we just populate a dict_column_t struct with information from a SYS_COLUMNS record |
heap | in/out: memory heap for temporary storage |
column | out: dict_column_t to fill, or NULL if table != NULL |
table_id | out: table id |
col_name | out: column name |
rec | in: SYS_COLUMNS record |
nth_v_col | out: if not NULL, this records the "n" of "nth" virtual column |
|
static |
Load columns in an innodb cached table object from SYS_COLUMNS table.
[in,out] | table | Table cache object |
[in,out] | heap | memory heap for temporary storage |
|
static |
Loads an index field definition from a SYS_FIELDS record to dict_index_t.
NULL | on success |
index_id | in/out: index id (8 bytes) an "in" value if index != NULL and "out" if index == NULL |
index | in/out: index, could be NULL if we just populate a dict_field_t struct with information from a SYS_FIELDS record |
heap | in/out: memory heap for temporary storage |
rec | in: SYS_FIELDS record |
|
static |
Loads definitions for index fields.
index | in/out: index whose fields to load |
heap | in: memory heap for temporary storage |
|
static |
Loads a foreign key constraint to the dictionary cache.
If the referenced table is not yet loaded, it is added in the output parameter (fk_tables).
id | in: foreign constraint id, must be '\0'-terminated |
col_names | in: column names, or NULL to use foreign->foreign_table->col_names |
check_recursive | in: whether to record the foreign table parent count to avoid unlimited recursive load of chained foreign tables |
check_charsets | in: whether to check charset compatibility |
ignore_err | in: error to be ignored |
fk_tables | out: the foreign key constraint is added to the dictionary cache only if the referenced table is already in cache. Otherwise, the foreign key constraint is not added to cache, and the referenced table is added to this stack. |
|
static |
Loads foreign key constraint col names (also for the referenced table).
Members that must be set (and valid) in foreign: foreign->heap foreign->n_fields foreign->id ('\0'-terminated) Members that will be created and set by this function: foreign->foreign_col_names[i] foreign->referenced_col_namesi
foreign | in/out: foreign constraint object |
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).
table_name | in: table name |
col_names | in: column names, or NULL to use table->col_names |
check_recursive | in: Whether to check recursive load of tables chained by FK |
check_charsets | in: whether to check charset compatibility |
ignore_err | in: error to be ignored |
fk_tables | out: stack of table names which must be loaded subsequently to load all the foreign key constraints. |
|
static |
Load an index definition from a SYS_INDEXES record to dict_index_t.
If allocate=true, we will create a dict_index_t structure and fill it accordingly. If allocated=false, the dict_index_t will be supplied by the caller and filled with information read from the record.
table_id | in/out: table id (8 bytes), an "in" value if allocate=true and "out" when allocate=false |
table_name | in: table name |
heap | in/out: temporary memory heap |
rec | in: SYS_INDEXES record |
allocate | in: true=allocate *index, false=fill in a pre-allocated *index |
index | out,own: index, or NULL |
|
static |
Loads definitions for table indexes.
Adds them to the data dictionary cache.
table | in/out: table |
heap | in: memory heap for temporary storage |
ignore_err | in: error to be ignored when loading the index definition |
|
static |
This variant is based on name comparison and is used because system table id array is not built yet.
[in] | name | InnoDB table name |
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.
table | in: system 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.
[in] | name | Table name in the dbname/tablename format |
[in] | cached | true=add to cache, false=do not |
[in] | ignore_err | Error to be ignored when loading table and its index definition |
[in] | prev_table | previous 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. |
|
static |
Loads a table definition from a SYS_TABLES record to dict_table_t.
Does not load any columns or indexes.
[in] | name | Table name |
[in] | rec | SYS_TABLES record |
[out] | table | Table, or NULL |
|
static |
Loads a table definition and also all its index definitions.
Loads those foreign key constraints whose referenced table is already in dictionary cache. If a foreign key constraint is not loaded, then the referenced table is pushed into the output stack (fk_tables), if it is not NULL. These tables must be subsequently loaded so that all the foreign key constraints are loaded into memory.
[in] | name | Table name in the db/tablename format |
[in] | cached | true=add to cache, false=do not |
[in] | ignore_err | Error to be ignored when loading table and its index definition |
[out] | fk_tables | Related table names that must also be loaded to ensure that all foreign key constraints are loaded. |
[in] | prev_table | previous 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. |
void dict_load_tablespace | ( | dict_table_t * | table, |
dict_err_ignore_t | ignore_err | ||
) |
Opens a tablespace for dict_load_table_one()
[in,out] | table | A table that refers to the tablespace to open |
[in] | ignore_err | Whether to ignore an error. |
void dict_load_tablespaces_for_upgrade | ( | ) |
Load all tablespaces during upgrade.
|
static |
Loads info from SYS_VIRTUAL for virtual columns.
[in,out] | table | table |
[in] | heap | memory heap |
|
static |
Loads a virtual column "mapping" (to base columns) information from a SYS_VIRTUAL record.
[in,out] | table | table |
[in,out] | column | mapped base column's dict_column_t |
[in,out] | table_id | table id |
[in,out] | pos | virtual column position |
[in,out] | base_pos | base column position |
[in] | rec | SYS_VIRTUAL record |
|
static |
Loads SYS_VIRTUAL info for one virtual column.
[in,out] | table | table |
[in] | nth_v_col | virtual column sequence num |
[in,out] | v_col | virtual column |
[in,out] | heap | memory heap |
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.
heap | in/out: heap memory |
rec | in: current SYS_TABLESPACES rec |
space | out: space id |
name | out: tablespace name |
flags | out: tablespace flags |
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.
[in,out] | table | table instance |
[in] | filepath | filepath of tablespace |
|
static |
Gets the space name from SYS_TABLESPACES for a given space ID.
[in] | space_id | Tablespace ID |
[in] | callers_heap | A heap to allocate from, may be NULL |
NULL | if no dictionary entry was found. |
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 returns the first record.
This function opens a system table, and return the first record.
pcur | out: persistent cursor to the record |
mtr | in: the mini-transaction |
system_id | in: which system table to open |
|
static |
Check the validity of a SYS_TABLES record Make sure the fields are the right length and that they do not contain invalid contents.
[in] | rec | SYS_TABLES record |
|
static |
Read and return 5 integer fields from a SYS_TABLES record.
[in] | rec | A record of SYS_TABLES |
[in] | table_name | Table Name, the same as SYS_TABLES.NAME |
[out] | table_id | Pointer to the table_id for this table |
[out] | space_id | Pointer to the space_id for this table |
[out] | n_cols | Pointer to number of columns for this table. |
[out] | flags | Pointer to table flags |
[out] | flags2 | Pointer to table flags2 |
|
static |
Read and return the contents of a SYS_TABLESPACES record.
[in] | rec | A record of SYS_TABLESPACES |
[out] | id | Pointer to the space_id for this table |
[in,out] | name | Buffer for Tablespace Name of length NAME_LEN |
[out] | flags | Pointer to tablespace flags |
|
static |
Compare the name of an index column.
table | in: table |
index | in: index |
i | in: index field offset |
name | in: name to compare to |
|
static |
Error message for a delete-marked record in dict_load_column_low()
|
static |
Error message for a delete-marked record in dict_load_field_low()
|
static |
Error message for a delete-marked record in dict_load_index_low()
|
static |
Error message for table->id mismatch in dict_load_index_low()
|
static |
Error message for a delete-marked record in dict_load_virtual_low()
bool has_discarded_tablespaces = false |
This bool denotes if we found a Table or Partition with discarded Tablespace during load of SYS_TABLES (in dict_check_sys_tables).
We use it to stop upgrade from 5.7 to 8.0 if there are discarded Tablespaces.
missing_sys_tblsp_t missing_spaces |
bool srv_load_corrupted = false |
const char* SYSTEM_TABLE_NAME[] |
Following are the InnoDB system tables.
The positions in this array are referenced by enum dict_system_table_id.