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