MySQL 9.4.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
dict0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2025, 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 space name by replacing partition string from dictionary table name.
202@param[in] dict_name table name in dictionary
203@param[in,out] space_name space name to be rebuilt */
204void rebuild_space(const std::string &dict_name, std::string &space_name);
205
206/** Rebuild table name to convert from 5.7 format to 8.0.
207@param[in,out] dict_name table name in dictionary */
208void rebuild(std::string &dict_name);
209
210} // namespace dict_name
211
212/* Space id and page no where the dictionary header resides */
213constexpr uint32_t DICT_HDR_SPACE = 0; /* the SYSTEM tablespace */
215
216/* The ibuf table and indexes's ID are assigned as the number
217DICT_IBUF_ID_MIN plus the space id */
218constexpr uint64_t DICT_IBUF_ID_MIN = 0xFFFFFFFF00000000ULL;
219
220/** Table or partition identifier (unique within an InnoDB instance). */
222/** Index identifier (unique within a tablespace). */
224
225/** Globally unique index identifier */
227 public:
228 /** Constructor.
229 @param[in] space_id Tablespace identifier
230 @param[in] index_id Index identifier */
232 : m_space_id(space_id), m_index_id(index_id) {}
233
234 /** Compare this to another index identifier.
235 @param other the other index identifier
236 @return whether this is less than other */
237 bool operator<(const index_id_t &other) const {
238 return (m_space_id < other.m_space_id ||
239 (m_space_id == other.m_space_id && m_index_id < other.m_index_id));
240 }
241 /** Compare this to another index identifier.
242 @param other the other index identifier
243 @return whether the identifiers are equal */
244 bool operator==(const index_id_t &other) const {
245 return (m_space_id == other.m_space_id && m_index_id == other.m_index_id);
246 }
247
248 /** Convert an index_id to a 64 bit integer.
249 @return a 64 bit integer */
250 uint64_t conv_to_int() const {
251 ut_ad((m_index_id & 0xFFFFFFFF00000000ULL) == 0);
252
253 return (static_cast<uint64_t>(m_space_id) << 32 | m_index_id);
254 }
255
256 /** Check if the index belongs to the insert buffer.
257 @return true if the index belongs to the insert buffer */
258 bool is_ibuf() const {
259 return (m_space_id == IBUF_SPACE_ID &&
261 }
262
263 /** Tablespace identifier */
265 /** Index identifier within the tablespace */
267};
268
269/** Display an index identifier.
270@param[in,out] out the output stream
271@param[in] id index identifier
272@return the output stream */
273inline std::ostream &operator<<(std::ostream &out, const index_id_t &id) {
274 return (out << "[space=" << id.m_space_id << ",index=" << id.m_index_id
275 << "]");
276}
277
278/** Error to ignore when we load table dictionary into memory. However,
279the table and index will be marked as "corrupted", and caller will
280be responsible to deal with corrupted table or index.
281Note: please define the IGNORE_ERR_* as bits, so their value can
282be or-ed together */
284 DICT_ERR_IGNORE_NONE = 0, /*!< no error to ignore */
285 DICT_ERR_IGNORE_INDEX_ROOT = 1, /*!< ignore error if index root
286 page is FIL_NULL or incorrect value */
287 DICT_ERR_IGNORE_CORRUPT = 2, /*!< skip corrupted indexes */
288 DICT_ERR_IGNORE_FK_NOKEY = 4, /*!< ignore error if any foreign
289 key is missing */
291 /*!< Used when recovering table locks
292 for resurrected transactions.
293 Silently load a missing
294 tablespace, and do not load
295 incomplete index definitions. */
296 DICT_ERR_IGNORE_ALL = 0xFFFF /*!< ignore all errors */
298
299/** Quiescing states for flushing tables to disk. */
302 QUIESCE_START, /*!< Initialise, prepare to start */
303 QUIESCE_COMPLETE /*!< All done */
305
306#ifndef UNIV_HOTBACKUP
307typedef ib_mutex_t DictSysMutex;
308#endif /* !UNIV_HOTBACKUP */
309
310/** Prefix for tmp tables, adopted from sql/table.h */
311#define TEMP_FILE_PREFIX "#sql"
312#define TEMP_FILE_PREFIX_LENGTH 4
313#define TEMP_FILE_PREFIX_INNODB "#sql-ib"
314
315#define TEMP_TABLE_PREFIX "#sql"
316#define TEMP_TABLE_PATH_PREFIX "/" TEMP_TABLE_PREFIX
317
318#if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
319/** Flag to control insert buffer debugging. */
320extern uint ibuf_debug;
321#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
322
323/** Shift for spatial status */
324constexpr uint32_t SPATIAL_STATUS_SHIFT = 12;
325
326/** Mask to encode/decode spatial status. */
328
330 "SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN");
331
332/** whether a col is used in spatial index or regular index
333Note: the spatial status is part of persistent undo log,
334so we should not modify the values in MySQL 5.7 */
336 /* Unknown status (undo format in 5.7.9) */
338
339 /** Not used in gis index. */
341
342 /** Used in both spatial index and regular index. */
344
345 /** Only used in spatial index. */
346 SPATIAL_ONLY = 3
348
349#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:48
Definition: partition.h:51
Globally unique index identifier.
Definition: dict0types.h:226
space_index_t m_index_id
Index identifier within the tablespace.
Definition: dict0types.h:266
space_id_t m_space_id
Tablespace identifier.
Definition: dict0types.h:264
uint64_t conv_to_int() const
Convert an index_id to a 64 bit integer.
Definition: dict0types.h:250
index_id_t(space_id_t space_id, space_index_t index_id)
Constructor.
Definition: dict0types.h:231
bool is_ibuf() const
Check if the index belongs to the insert buffer.
Definition: dict0types.h:258
bool operator==(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:244
bool operator<(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:237
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:223
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:335
@ SPATIAL_MIXED
Used in both spatial index and regular index.
Definition: dict0types.h:343
@ SPATIAL_NONE
Not used in gis index.
Definition: dict0types.h:340
@ SPATIAL_UNKNOWN
Definition: dict0types.h:337
@ SPATIAL_ONLY
Only used in spatial index.
Definition: dict0types.h:346
uint ibuf_debug
Flag to control insert buffer debugging.
Definition: ibuf0ibuf.cc:208
constexpr uint64_t DICT_IBUF_ID_MIN
Definition: dict0types.h:218
std::ostream & operator<<(std::ostream &out, const index_id_t &id)
Display an index identifier.
Definition: dict0types.h:273
constexpr uint32_t SPATIAL_STATUS_MASK
Mask to encode/decode spatial status.
Definition: dict0types.h:327
constexpr uint32_t DICT_HDR_PAGE_NO
Definition: dict0types.h:214
ib_mutex_t DictSysMutex
Definition: dict0types.h:307
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:283
@ DICT_ERR_IGNORE_INDEX_ROOT
ignore error if index root page is FIL_NULL or incorrect value
Definition: dict0types.h:285
@ DICT_ERR_IGNORE_NONE
no error to ignore
Definition: dict0types.h:284
@ DICT_ERR_IGNORE_CORRUPT
skip corrupted indexes
Definition: dict0types.h:287
@ DICT_ERR_IGNORE_ALL
ignore all errors
Definition: dict0types.h:296
@ DICT_ERR_IGNORE_RECOVER_LOCK
Used when recovering table locks for resurrected transactions.
Definition: dict0types.h:290
@ DICT_ERR_IGNORE_FK_NOKEY
ignore error if any foreign key is missing
Definition: dict0types.h:288
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:221
ib_quiesce_t
Quiescing states for flushing tables to disk.
Definition: dict0types.h:300
@ QUIESCE_NONE
Definition: dict0types.h:301
@ QUIESCE_START
Initialise, prepare to start.
Definition: dict0types.h:302
@ QUIESCE_COMPLETE
All done.
Definition: dict0types.h:303
constexpr uint32_t SPATIAL_STATUS_SHIFT
Shift for spatial status.
Definition: dict0types.h:324
constexpr uint32_t DICT_HDR_SPACE
Definition: dict0types.h:213
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:43
Innodb data dictionary name.
Definition: dict0dd.cc:7301
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:7561
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:7399
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:7461
bool is_partition(const std::string &dict_name)
Check if it is a table partition.
Definition: dict0dd.cc:7394
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
void rebuild_space(const std::string &dict_name, std::string &space_name)
Definition: dict0dd.cc:7780
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:7679
void build_partition(const dd::Partition *dd_part, std::string &partition)
Build partition string from dd object.
Definition: dict0dd.cc:7668
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:7809
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:7302
constexpr size_t TMP_POSTFIX_LEN
Definition: dict0types.h:115
void convert_to_space(std::string &dict_name)
Definition: dict0dd.cc:7755
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:7523
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:7311
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:830
Data structure for a column in a table.
Definition: dict0mem.h:484
Data structure for a field in an index.
Definition: dict0mem.h:890
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1661
Data structure for an index.
Definition: dict0mem.h:1041
Definition: dict0dict.h:1009
Data structure for a database table.
Definition: dict0mem.h:1913
Data structure for a virtual column in a table.
Definition: dict0mem.h:810
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.