MySQL 9.7.0
Source Code Documentation
dict0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2026, 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/dict0types.h
29 Data dictionary global types
30
31 Created 1/8/1996 Heikki Tuuri
32 *******************************************************/
33
34#ifndef dict0types_h
35#define dict0types_h
36
37#include "fsp0types.h"
38#include "ibuf0types.h" /* IBUF_SPACE_ID */
39#include "mysql_com.h"
40#include "rem0types.h"
41#include "ut0mutex.h"
42
43struct dict_sys_t;
44struct dict_col_t;
45struct dict_field_t;
46struct dict_index_t;
47struct dict_table_t;
48struct dict_foreign_t;
49struct dict_v_col_t;
50
51struct ind_node_t;
52struct tab_node_t;
53struct dict_add_v_col_t;
54
56 std::string schema_name;
57 std::string table_name;
58 std::string partition;
59 std::string subpartition;
60 std::string directory;
61};
62
63namespace dd {
64class Partition;
65}
66
67/** Innodb data dictionary name.
68NOTE: Innodb dictionary table name is always in my_charset_filename. Hence,
69dictionary name (dict_name) and partition string input parameters in dict_name::
70interfaces are assumed to be in my_charset_filename. */
71namespace dict_name {
72/** Partition separator in dictionary table name and file name. */
73constexpr char PART_SEPARATOR[] = "#p#";
74
75/** Partition separator length excluding terminating NULL */
76constexpr size_t PART_SEPARATOR_LEN = sizeof(PART_SEPARATOR) - 1;
77
78/** Sub-Partition separator in dictionary table name and file name. */
79constexpr char SUB_PART_SEPARATOR[] = "#sp#";
80
81/** Sub-Partition separator length excluding terminating NULL */
82constexpr size_t SUB_PART_SEPARATOR_LEN = sizeof(SUB_PART_SEPARATOR) - 1;
83
84/** Schema separator is forward slash irrespective of platform. */
85constexpr char SCHEMA_SEPARATOR[] = "/";
86constexpr size_t SCHEMA_SEPARATOR_LEN = sizeof(SCHEMA_SEPARATOR) - 1;
87
88/** The maximum length in bytes that a database name can occupy when
89stored in UTF8MB3, including the terminating null. */
90constexpr size_t MAX_DB_UTF8MB3_LEN = NAME_LEN + 1;
91
92/** The maximum length in characters for database name. */
93constexpr size_t MAX_DB_CHAR_LEN = NAME_CHAR_LEN;
94
95/** The maximum length in bytes that a table name can occupy when stored in
96UTF8MB3, including the terminating null. NAME_LEN is added 3 times to consider
97table name, partition name and sub-partition name for a partitioned table.
98In innodb each partition/sub-partition is a separate table named as below.
99table_name<PART_SEPARATOR>partition_name<SUB_PART_SEPARATOR>subpartition_name
100This macro only applies to table name, without any database name prefixed. */
103 NAME_LEN + 1;
104
105/** The maximum length in characters for table name. */
109
110/** Postfix for a table name which is being altered. Since during
111ALTER TABLE ... PARTITION, new partitions have to be created before
112dropping existing partitions, so a postfix is appended to the name
113to prevent name conflicts. This is also used for EXCHANGE PARTITION */
114constexpr char TMP_POSTFIX[] = "#tmp";
115constexpr size_t TMP_POSTFIX_LEN = sizeof(TMP_POSTFIX) - 1;
116
117/** Maximum space name length. Space name includes schema name, table name
118along with partition and sub-partition name for partitioned table. */
119constexpr size_t MAX_SPACE_NAME_LEN =
122
123/** Name string conversion callback. Used for character set conversion. */
124using Convert_Func = std::function<void(std::string &)>;
125
126/** Conversion function to change for system to file name cs.
127@param[in,out] name identifier name.
128@param[in] quiet true, if we allow error during conversion. */
129void file_to_table(std::string &name, bool quiet);
130
131/** Conversion function to change for file name to system cs.
132@param[in,out] name identifier name. */
133void table_to_file(std::string &name);
134
135/** Check if it is a table partition.
136@param[in] dict_name table name in dictionary
137@return true, iff it is table partition. */
138bool is_partition(const std::string &dict_name);
139
140/** Get schema, table name, partition string and temporary attribute from
141dictionary table name.
142@param[in] dict_name table name in dictionary
143@param[in] convert convert schema & table name to system cs
144@param[out] schema schema name
145@param[out] table table name
146@param[out] partition partition string if table partition
147@param[out] is_tmp true, iff temporary table created by DDL */
148void get_table(const std::string &dict_name, bool convert, std::string &schema,
149 std::string &table, std::string &partition, bool &is_tmp);
150
151/** Get schema and table name from dictionary table name.
152@param[in] dict_name table name in dictionary
153@param[out] schema schema name
154@param[out] table table name */
155void get_table(const std::string &dict_name, std::string &schema,
156 std::string &table);
157
158/** Get schema, table name, partition, subpartition and absolute directory
159from dictionary from filepath.
160@param[in] path path where the ibd file is located
161@return table_name_components struct with parsed out parts of the table name */
162std::optional<table_name_components> parse_tablespace_path(std::string path);
163
164/** Get partition and sub-partition name from partition string
165@param[in] partition partition string from dictionary table name
166@param[in] convert convert partition names to system cs
167@param[out] part partition name
168@param[out] sub_part sub partition name if present */
169void get_partition(const std::string &partition, bool convert,
170 std::string &part, std::string &sub_part);
171
172/* Build dictionary table name. Table name in dictionary is always in filename
173character set.
174@param[in] schema schema name
175@param[in] table table name
176@param[in] partition partition string if table partition
177@param[in] is_tmp true, iff temporary table created by DDL
178@param[in] convert convert all names from system cs
179@param[out] dict_name table name for innodb dictionary */
180void build_table(const std::string &schema, const std::string &table,
181 const std::string &partition, bool is_tmp, bool convert,
182 std::string &dict_name);
183
184/** Build partition string from dd object.
185@param[in] dd_part partition object from DD
186@param[out] partition partition string for dictionary table name */
187void build_partition(const dd::Partition *dd_part, std::string &partition);
188
189/** Check if dd partition matches with innodb dictionary table name.
190@param[in] dict_name table name in innodb dictionary
191@param[in] dd_part partition object from DD
192@return true, iff the name matches the partition from DD. */
193bool match_partition(const std::string &dict_name,
194 const dd::Partition *dd_part);
195
196/* Build space name by converting schema, table, partition and sub partition
197names within a dictionary table name.
198@param[in,out] dict_name table name in dictionary */
199void convert_to_space(std::string &dict_name);
200
201/** Rebuild table name to convert from 5.7 format to 8.0.
202@param[in,out] dict_name table name in dictionary */
203void rebuild(std::string &dict_name);
204
205} // namespace dict_name
206
207/* Space id and page no where the dictionary header resides */
208constexpr uint32_t DICT_HDR_SPACE = 0; /* the SYSTEM tablespace */
210
211/* The ibuf table and indexes's ID are assigned as the number
212DICT_IBUF_ID_MIN plus the space id */
213constexpr uint64_t DICT_IBUF_ID_MIN = 0xFFFFFFFF00000000ULL;
214
215/** Table or partition identifier (unique within an InnoDB instance). */
217/** Index identifier (unique within a tablespace). */
219
220/** Globally unique index identifier */
222 public:
223 /** Constructor.
224 @param[in] space_id Tablespace identifier
225 @param[in] index_id Index identifier */
227 : m_space_id(space_id), m_index_id(index_id) {}
228
229 /** Compare this to another index identifier.
230 @param other the other index identifier
231 @return whether this is less than other */
232 bool operator<(const index_id_t &other) const {
233 return (m_space_id < other.m_space_id ||
234 (m_space_id == other.m_space_id && m_index_id < other.m_index_id));
235 }
236 /** Compare this to another index identifier.
237 @param other the other index identifier
238 @return whether the identifiers are equal */
239 bool operator==(const index_id_t &other) const {
240 return (m_space_id == other.m_space_id && m_index_id == other.m_index_id);
241 }
242
243 /** Convert an index_id to a 64 bit integer.
244 @return a 64 bit integer */
245 uint64_t conv_to_int() const {
246 ut_ad((m_index_id & 0xFFFFFFFF00000000ULL) == 0);
247
248 return (static_cast<uint64_t>(m_space_id) << 32 | m_index_id);
249 }
250
251 /** Check if the index belongs to the insert buffer.
252 @return true if the index belongs to the insert buffer */
253 bool is_ibuf() const {
254 return (m_space_id == IBUF_SPACE_ID &&
256 }
257
258 /** Tablespace identifier */
260 /** Index identifier within the tablespace */
262};
263
264/** Display an index identifier.
265@param[in,out] out the output stream
266@param[in] id index identifier
267@return the output stream */
268inline std::ostream &operator<<(std::ostream &out, const index_id_t &id) {
269 return (out << "[space=" << id.m_space_id << ",index=" << id.m_index_id
270 << "]");
271}
272
273/** Error to ignore when we load table dictionary into memory. However,
274the table and index will be marked as "corrupted", and caller will
275be responsible to deal with corrupted table or index.
276Note: please define the IGNORE_ERR_* as bits, so their value can
277be or-ed together */
279 DICT_ERR_IGNORE_NONE = 0, /*!< no error to ignore */
280 DICT_ERR_IGNORE_INDEX_ROOT = 1, /*!< ignore error if index root
281 page is FIL_NULL or incorrect value */
282 DICT_ERR_IGNORE_CORRUPT = 2, /*!< skip corrupted indexes */
283 DICT_ERR_IGNORE_FK_NOKEY = 4, /*!< ignore error if any foreign
284 key is missing */
286 /*!< Used when recovering table locks
287 for resurrected transactions.
288 Silently load a missing
289 tablespace, and do not load
290 incomplete index definitions. */
291 DICT_ERR_IGNORE_ALL = 0xFFFF /*!< ignore all errors */
293
294/** Quiescing states for flushing tables to disk. */
297 QUIESCE_START, /*!< Initialise, prepare to start */
298 QUIESCE_COMPLETE /*!< All done */
300
301#ifndef UNIV_HOTBACKUP
302typedef ib_mutex_t DictSysMutex;
303#endif /* !UNIV_HOTBACKUP */
304
305/** Prefix for tmp tables, adopted from sql/table.h */
306#define TEMP_FILE_PREFIX "#sql"
307#define TEMP_FILE_PREFIX_LENGTH 4
308#define TEMP_FILE_PREFIX_INNODB "#sql-ib"
309
310#define TEMP_TABLE_PREFIX "#sql"
311#define TEMP_TABLE_PATH_PREFIX "/" TEMP_TABLE_PREFIX
312
313#if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
314/** Flag to control insert buffer debugging. */
315extern uint ibuf_debug;
316#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
317
318/** Shift for spatial status */
319constexpr uint32_t SPATIAL_STATUS_SHIFT = 12;
320
321/** Mask to encode/decode spatial status. */
323
325 "SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN");
326
327/** whether a col is used in spatial index or regular index
328Note: the spatial status is part of persistent undo log,
329so we should not modify the values in MySQL 5.7 */
331 /* Unknown status (undo format in 5.7.9) */
333
334 /** Not used in gis index. */
336
337 /** Used in both spatial index and regular index. */
339
340 /** Only used in spatial index. */
341 SPATIAL_ONLY = 3
343
344#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
Definition: partition.h:51
Globally unique index identifier.
Definition: dict0types.h:221
space_index_t m_index_id
Index identifier within the tablespace.
Definition: dict0types.h:261
space_id_t m_space_id
Tablespace identifier.
Definition: dict0types.h:259
uint64_t conv_to_int() const
Convert an index_id to a 64 bit integer.
Definition: dict0types.h:245
index_id_t(space_id_t space_id, space_index_t index_id)
Constructor.
Definition: dict0types.h:226
bool is_ibuf() const
Check if the index belongs to the insert buffer.
Definition: dict0types.h:253
bool operator==(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:239
bool operator<(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:232
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:218
spatial_status_t
whether a col is used in spatial index or regular index Note: the spatial status is part of persisten...
Definition: dict0types.h:330
@ SPATIAL_MIXED
Used in both spatial index and regular index.
Definition: dict0types.h:338
@ SPATIAL_NONE
Not used in gis index.
Definition: dict0types.h:335
@ SPATIAL_UNKNOWN
Definition: dict0types.h:332
@ SPATIAL_ONLY
Only used in spatial index.
Definition: dict0types.h:341
uint ibuf_debug
Flag to control insert buffer debugging.
Definition: ibuf0ibuf.cc:208
constexpr uint64_t DICT_IBUF_ID_MIN
Definition: dict0types.h:213
std::ostream & operator<<(std::ostream &out, const index_id_t &id)
Display an index identifier.
Definition: dict0types.h:268
constexpr uint32_t SPATIAL_STATUS_MASK
Mask to encode/decode spatial status.
Definition: dict0types.h:322
constexpr uint32_t DICT_HDR_PAGE_NO
Definition: dict0types.h:209
ib_mutex_t DictSysMutex
Definition: dict0types.h:302
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:278
@ DICT_ERR_IGNORE_INDEX_ROOT
ignore error if index root page is FIL_NULL or incorrect value
Definition: dict0types.h:280
@ DICT_ERR_IGNORE_NONE
no error to ignore
Definition: dict0types.h:279
@ DICT_ERR_IGNORE_CORRUPT
skip corrupted indexes
Definition: dict0types.h:282
@ DICT_ERR_IGNORE_ALL
ignore all errors
Definition: dict0types.h:291
@ DICT_ERR_IGNORE_RECOVER_LOCK
Used when recovering table locks for resurrected transactions.
Definition: dict0types.h:285
@ DICT_ERR_IGNORE_FK_NOKEY
ignore error if any foreign key is missing
Definition: dict0types.h:283
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:216
ib_quiesce_t
Quiescing states for flushing tables to disk.
Definition: dict0types.h:295
@ QUIESCE_NONE
Definition: dict0types.h:296
@ QUIESCE_START
Initialise, prepare to start.
Definition: dict0types.h:297
@ QUIESCE_COMPLETE
All done.
Definition: dict0types.h:298
constexpr uint32_t SPATIAL_STATUS_SHIFT
Shift for spatial status.
Definition: dict0types.h:319
constexpr uint32_t DICT_HDR_SPACE
Definition: dict0types.h:208
constexpr uint32_t FSP_DICT_HDR_PAGE_NO
data dictionary header page, in tablespace 0
Definition: fsp0types.h:174
Insert buffer global types.
#define IBUF_SPACE_ID
Definition: ibuf0types.h:38
Common definition between mysql server & client.
#define NAME_LEN
Definition: mysql_com.h:67
#define NAME_CHAR_LEN
Field/table name length.
Definition: mysql_com.h:60
static char * path
Definition: mysqldump.cc:150
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
Innodb data dictionary name.
Definition: dict0dd.cc:7307
void build_table(const std::string &schema, const std::string &table, const std::string &partition, bool is_tmp, bool convert, std::string &dict_name)
Definition: dict0dd.cc:7567
std::function< void(std::string &)> Convert_Func
Name string conversion callback.
Definition: dict0types.h:124
constexpr char PART_SEPARATOR[]
Partition separator in dictionary table name and file name.
Definition: dict0types.h:73
constexpr char SUB_PART_SEPARATOR[]
Sub-Partition separator in dictionary table name and file name.
Definition: dict0types.h:79
constexpr size_t PART_SEPARATOR_LEN
Partition separator length excluding terminating NULL.
Definition: dict0types.h:76
void get_table(const std::string &dict_name, std::string &schema, std::string &table)
Get schema and table name from dictionary table name.
Definition: dict0dd.cc:7405
std::optional< table_name_components > parse_tablespace_path(std::string path)
Get schema, table name, partition, subpartition and absolute directory from dictionary from filepath.
Definition: dict0dd.cc:7467
bool is_partition(const std::string &dict_name)
Check if it is a table partition.
Definition: dict0dd.cc:7400
constexpr size_t MAX_TABLE_CHAR_LEN
The maximum length in characters for table name.
Definition: dict0types.h:106
constexpr size_t MAX_DB_CHAR_LEN
The maximum length in characters for database name.
Definition: dict0types.h:93
bool match_partition(const std::string &dict_name, const dd::Partition *dd_part)
Check if dd partition matches with innodb dictionary table name.
Definition: dict0dd.cc:7685
void build_partition(const dd::Partition *dd_part, std::string &partition)
Build partition string from dd object.
Definition: dict0dd.cc:7674
constexpr size_t SUB_PART_SEPARATOR_LEN
Sub-Partition separator length excluding terminating NULL.
Definition: dict0types.h:82
constexpr size_t MAX_TABLE_UTF8MB3_LEN
The maximum length in bytes that a table name can occupy when stored in UTF8MB3, including the termin...
Definition: dict0types.h:101
void rebuild(std::string &dict_name)
Rebuild table name to convert from 5.7 format to 8.0.
Definition: dict0dd.cc:7779
constexpr size_t MAX_SPACE_NAME_LEN
Maximum space name length.
Definition: dict0types.h:119
constexpr size_t SCHEMA_SEPARATOR_LEN
Definition: dict0types.h:86
constexpr char SCHEMA_SEPARATOR[]
Schema separator is forward slash irrespective of platform.
Definition: dict0types.h:85
void file_to_table(std::string &name, bool quiet)
Conversion function to change for system to file name cs.
Definition: dict0dd.cc:7308
constexpr size_t TMP_POSTFIX_LEN
Definition: dict0types.h:115
void convert_to_space(std::string &dict_name)
Definition: dict0dd.cc:7754
void get_partition(const std::string &partition, bool convert, std::string &part, std::string &sub_part)
Get partition and sub-partition name from partition string.
Definition: dict0dd.cc:7529
constexpr size_t MAX_DB_UTF8MB3_LEN
The maximum length in bytes that a database name can occupy when stored in UTF8MB3,...
Definition: dict0types.h:90
constexpr char TMP_POSTFIX[]
Postfix for a table name which is being altered.
Definition: dict0types.h:114
void table_to_file(std::string &name)
Conversion function to change for file name to system cs.
Definition: dict0dd.cc:7317
Record manager global types.
constexpr uint32_t REC_VERSION_56_MAX_INDEX_COL_LEN
Maximum indexed field length for tables that have atomic BLOBs.
Definition: rem0types.h:87
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:831
Data structure for a column in a table.
Definition: dict0mem.h:485
Data structure for a field in an index.
Definition: dict0mem.h:891
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1673
Data structure for an index.
Definition: dict0mem.h:1067
Definition: dict0dict.h:1019
Data structure for a database table.
Definition: dict0mem.h:1925
Data structure for a virtual column in a table.
Definition: dict0mem.h:811
Definition: dict0crea.h:148
Definition: dict0crea.h:112
Definition: dict0types.h:55
std::string table_name
Definition: dict0types.h:57
std::string directory
Definition: dict0types.h:60
std::string schema_name
Definition: dict0types.h:56
std::string subpartition
Definition: dict0types.h:59
std::string partition
Definition: dict0types.h:58
uint64_t ib_id_t
The generic InnoDB system object identifier data type.
Definition: univ.i:443
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
Policy based mutexes.