MySQL 8.4.2
Source Code Documentation
dict0load.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/dict0load.h
29 Loads to the memory cache database object definitions
30 from dictionary tables
31
32 Created 4/24/1996 Heikki Tuuri
33 *******************************************************/
34
35#ifndef dict0load_h
36#define dict0load_h
37
38#include "btr0types.h"
39#include "dict0types.h"
40#include "fil0fil.h"
41#include "mem0mem.h"
42#include "trx0types.h"
43#include "univ.i"
44#include "ut0byte.h"
45#include "ut0new.h"
46
47#include <deque>
48
49/** A stack of table names related through foreign key constraints */
50typedef std::deque<const char *, ut::allocator<const char *>> dict_names_t;
51
52/** enum that defines all system table IDs. @see SYSTEM_TABLE_NAME[] */
63
64 /* This must be last item. Defines the number of system tables. */
66};
67
68/** Status bit for dict_process_sys_tables_rec_and_mtr_commit() */
70 DICT_TABLE_LOAD_FROM_RECORD = 0, /*!< Directly populate a dict_table_t
71 structure with information from
72 a SYS_TABLES record */
73 DICT_TABLE_LOAD_FROM_CACHE = 1 /*!< Check first whether dict_table_t
74 is in the cache, if so, return it */
75};
76
77extern const char *SYSTEM_TABLE_NAME[];
78
79/** Finds the first table name in the given database.
80 @return own: table name, NULL if does not exist; the caller must free
81 the memory in the string! */
83 const char *name); /*!< in: database name which ends to '/' */
84
85/** Get the first filepath from SYS_DATAFILES for a given space_id.
86@param[in] space_id Tablespace ID
87@return First filepath (caller must invoke ut::free() on it)
88@retval NULL if no SYS_DATAFILES entry was found. */
89char *dict_get_first_path(ulint space_id);
90
91/** Make sure the data_dir_path is saved in dict_table_t if DATA DIRECTORY
92was used. Try to read it from the fil_system first, then from SYS_DATAFILES.
93@param[in] table Table object
94@param[in] dict_mutex_own true if dict_sys->mutex is owned already */
95void dict_get_and_save_data_dir_path(dict_table_t *table, bool dict_mutex_own);
96
97/** Make sure the tablespace name is saved in dict_table_t if the table
98uses a general tablespace.
99Try to read it from the fil_system_t first, then from SYS_TABLESPACES.
100@param[in] table Table object */
102
103/** Loads a table definition and also all its index definitions, and also
104the cluster definition if the table is a member in a cluster. Also loads
105all foreign key constraints where the foreign key is in the table or where
106a foreign key references columns in this table.
107@param[in] name Table name in the dbname/tablename format
108@param[in] cached true=add to cache, false=do not
109@param[in] ignore_err Error to be ignored when loading
110 table and its index definition
111@param[in] prev_table previous table name. The current table load
112 is happening because of the load of the
113 previous table name. This parameter is used
114 to check for cyclic calls.
115@return table, NULL if does not exist; if the table is stored in an
116.ibd file, but the file does not exist, then we set the ibd_file_missing
117flag in the table object we return. */
118dict_table_t *dict_load_table(const char *name, bool cached,
119 dict_err_ignore_t ignore_err,
120 const std::string *prev_table = nullptr);
121
122/** This function is called when the database is booted.
123 Loads system table index definitions except for the clustered index which
124 is added to the dictionary cache at booting before calling this function. */
125void dict_load_sys_table(dict_table_t *table); /*!< in: system table */
126/** Loads foreign key constraints where the table is either the foreign key
127 holder or where the table is referenced by a foreign key. Adds these
128 constraints to the data dictionary.
129
130 The foreign key constraint is loaded only if the referenced table is also
131 in the dictionary cache. If the referenced table is not in dictionary
132 cache, then it is added to the output parameter (fk_tables).
133
134 @return DB_SUCCESS or error code */
135[[nodiscard]] dberr_t dict_load_foreigns(
136 const char *table_name, /*!< in: table name */
137 const char **col_names, /*!< in: column names, or NULL
138 to use table->col_names */
139 bool check_recursive, /*!< in: Whether to check
140 recursive load of tables
141 chained by FK */
142 bool check_charsets, /*!< in: whether to check
143 charset compatibility */
144 dict_err_ignore_t ignore_err, /*!< in: error to be ignored */
145 dict_names_t &fk_tables); /*!< out: stack of table names
146 which must be loaded
147 subsequently to load all the
148 foreign key constraints. */
149
150/** This function opens a system table, and return the first record.
151 @return first record of the system table */
153 btr_pcur_t *pcur, /*!< out: persistent cursor to
154 the record */
155 mtr_t *mtr, /*!< in: the mini-transaction */
156 dict_system_id_t system_id); /*!< in: which system table to open */
157/** This function get the next system table record as we scan the table.
158 @return the record if found, NULL if end of scan. */
159const rec_t *dict_getnext_system(btr_pcur_t *pcur, /*!< in/out: persistent
160 cursor to the record */
161 mtr_t *mtr); /*!< in: the mini-transaction */
162
163/** This function parses a SYS_TABLESPACES record, extracts necessary
164 information from the record and returns to caller.
165 @return error message, or NULL on success */
167 mem_heap_t *heap, /*!< in/out: heap memory */
168 const rec_t *rec, /*!< in: current SYS_TABLESPACES rec */
169 space_id_t *space, /*!< out: space id */
170 const char **name, /*!< out: tablespace name */
171 uint32_t *flags); /*!< out: tablespace flags */
172
173/** Opens a tablespace for dict_load_table_one()
174@param[in,out] table A table that refers to the tablespace to open
175@param[in] ignore_err Whether to ignore an error. */
177
178/** Using the table->heap, copy the null-terminated filepath into
179table->data_dir_path. The data directory path is derived from the
180filepath by stripping the the table->name.m_name component suffix.
181If the filepath is not of the correct form (".../db/table.ibd"),
182then table->data_dir_path will remain nullptr.
183@param[in,out] table table instance
184@param[in] filepath filepath of tablespace */
186
187/* Comparator for missing_spaces. */
189 bool operator()(const fil_space_t *lhs, const fil_space_t *rhs) const {
190 return (lhs->id < rhs->id);
191 }
192};
193
194/* This is set of tablespaces that are not found in SYS_TABLESPACES.
195InnoDB tablespaces before 5.6 are not registered in SYS_TABLESPACES.
196So we maintain a std::set, which is later used to register the
197tablespaces to dictionary table mysql.tablespaces */
198using missing_sys_tblsp_t = std::set<fil_space_t *, space_compare>;
200
201/** This bool denotes if we found a Table or Partition with discarded Tablespace
202during load of SYS_TABLES (in dict_check_sys_tables).
203*/
204extern bool has_discarded_tablespaces;
205
206#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
The index tree general types.
dberr_t
Definition: db0err.h:39
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.
Definition: dict0load.cc:261
std::deque< const char *, ut::allocator< const char * > > dict_names_t
A stack of table names related through foreign key constraints.
Definition: dict0load.h:50
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 ...
Definition: dict0load.cc:2917
std::set< fil_space_t *, space_compare > missing_sys_tblsp_t
Definition: dict0load.h:198
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.
Definition: dict0load.cc:2144
dict_table_info_t
Status bit for dict_process_sys_tables_rec_and_mtr_commit()
Definition: dict0load.h:69
@ DICT_TABLE_LOAD_FROM_RECORD
Directly populate a dict_table_t structure with information from a SYS_TABLES record.
Definition: dict0load.h:70
@ DICT_TABLE_LOAD_FROM_CACHE
Check first whether dict_table_t is in the cache, if so, return it.
Definition: dict0load.h:73
void dict_load_tablespace(dict_table_t *table, dict_err_ignore_t ignore_err)
Opens a tablespace for dict_load_table_one()
Definition: dict0load.cc:2225
char * dict_get_first_table_name_in_db(const char *name)
Finds the first table name in the given database.
Definition: dict0load.cc:157
dict_system_id_t
enum that defines all system table IDs.
Definition: dict0load.h:53
@ SYS_VIRTUAL
Definition: dict0load.h:62
@ SYS_INDEXES
Definition: dict0load.h:55
@ SYS_FOREIGN_COLS
Definition: dict0load.h:59
@ SYS_NUM_SYSTEM_TABLES
Definition: dict0load.h:65
@ SYS_FOREIGN
Definition: dict0load.h:58
@ SYS_TABLESPACES
Definition: dict0load.h:60
@ SYS_FIELDS
Definition: dict0load.h:57
@ SYS_DATAFILES
Definition: dict0load.h:61
@ SYS_TABLES
Definition: dict0load.h:54
@ SYS_COLUMNS
Definition: dict0load.h:56
void dict_load_sys_table(dict_table_t *table)
This function is called when the database is booted.
Definition: dict0load.cc:2599
missing_sys_tblsp_t missing_spaces
Definition: dict0load.cc:93
bool has_discarded_tablespaces
This bool denotes if we found a Table or Partition with discarded Tablespace during load of SYS_TABLE...
Definition: dict0load.cc:98
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.
Definition: dict0load.cc:2080
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.
Definition: dict0load.cc:286
char * dict_get_first_path(ulint space_id)
Get the first filepath from SYS_DATAFILES for a given space_id.
Definition: dict0load.cc:991
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.
Definition: dict0load.cc:2116
const char * SYSTEM_TABLE_NAME[]
Following are the InnoDB system tables.
Definition: dict0load.cc:70
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 ret...
Definition: dict0load.cc:927
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 t...
Definition: dict0load.cc:2182
Data dictionary global types.
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:294
The low-level file system.
static int flags[50]
Definition: hp_test1.cc:40
The memory management.
static const char * filepath
Definition: myisamlog.cc:97
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
const char * table_name
Definition: rules_table_service.cc:56
byte rec_t
Definition: rem0types.h:41
case opt name
Definition: sslopt-case.h:29
Definition: btr0pcur.h:99
Data structure for a database table.
Definition: dict0mem.h:1909
Tablespace or log data space.
Definition: fil0fil.h:238
space_id_t id
Tablespace ID.
Definition: fil0fil.h:334
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Definition: dict0load.h:188
bool operator()(const fil_space_t *lhs, const fil_space_t *rhs) const
Definition: dict0load.h:189
Transaction system global type definitions.
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406
Utilities for byte operations.
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
static double cached
Definition: xcom_statistics.cc:101