MySQL 8.0.40
Source Code Documentation
dict0types.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/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/** Alternative partition separator from 8.0.17 and older versions. */
85constexpr char ALT_PART_SEPARATOR[] = "#P#";
86
87/** Alternative sub-partition separator from 8.0.17 and older versions. */
88constexpr char ALT_SUB_PART_SEPARATOR[] = "#SP#";
89
90/** Schema separator is forward slash irrespective of platform. */
91constexpr char SCHEMA_SEPARATOR[] = "/";
92constexpr size_t SCHEMA_SEPARATOR_LEN = sizeof(SCHEMA_SEPARATOR) - 1;
93
94/** The maximum length in bytes that a database name can occupy when
95stored in UTF8MB3, including the terminating null. */
96constexpr size_t MAX_DB_UTF8MB3_LEN = NAME_LEN + 1;
97
98/** The maximum length in characters for database name. */
99constexpr size_t MAX_DB_CHAR_LEN = NAME_CHAR_LEN;
100
101/** The maximum length in bytes that a table name can occupy when stored in
102UTF8MB3, including the terminating null. NAME_LEN is added 3 times to consider
103table name, partition name and sub-partition name for a partitioned table.
104In innodb each partition/sub-partition is a separate table named as below.
105table_name<PART_SEPARATOR>partition_name<SUB_PART_SEPARATOR>subpartition_name
106This macro only applies to table name, without any database name prefixed. */
109 NAME_LEN + 1;
110
111/** The maximum length in characters for table name. */
115
116/** Postfix for a table name which is being altered. Since during
117ALTER TABLE ... PARTITION, new partitions have to be created before
118dropping existing partitions, so a postfix is appended to the name
119to prevent name conflicts. This is also used for EXCHANGE PARTITION */
120constexpr char TMP_POSTFIX[] = "#tmp";
121constexpr size_t TMP_POSTFIX_LEN = sizeof(TMP_POSTFIX) - 1;
122
123/** Maximum space name length. Space name includes schema name, table name
124along with partition and sub-partition name for partitioned table. */
125constexpr size_t MAX_SPACE_NAME_LEN =
128
129/** Name string conversion callback. Used for character set conversion. */
130using Convert_Func = std::function<void(std::string &)>;
131
132/** Conversion function to change for system to file name cs.
133@param[in,out] name identifier name.
134@param[in] quiet true, if we allow error during conversion. */
135void file_to_table(std::string &name, bool quiet);
136
137/** Conversion function to change for file name to system cs.
138@param[in,out] name identifier name. */
139void table_to_file(std::string &name);
140
141/** Check if it is a table partition.
142@param[in] dict_name table name in dictionary
143@return true, iff it is table partition. */
144bool is_partition(const std::string &dict_name);
145
146/** Get schema, table name, partition string and temporary attribute from
147dictionary table name.
148@param[in] dict_name table name in dictionary
149@param[in] convert convert schema & table name to system cs
150@param[out] schema schema name
151@param[out] table table name
152@param[out] partition partition string if table partition
153@param[out] is_tmp true, iff temporary table created by DDL */
154void get_table(const std::string &dict_name, bool convert, std::string &schema,
155 std::string &table, std::string &partition, bool &is_tmp);
156
157/** Get schema and table name from dictionary table name.
158@param[in] dict_name table name in dictionary
159@param[out] schema schema name
160@param[out] table table name */
161void get_table(const std::string &dict_name, std::string &schema,
162 std::string &table);
163
164/** Get schema, table name, partition, subpartition and absolute directory
165from dictionary from filepath.
166@param[in] path path where the ibd file is located
167@return table_name_components struct with parsed out parts of the table name */
168std::optional<table_name_components> parse_tablespace_path(std::string path);
169
170/** Get partition and sub-partition name from partition string
171@param[in] partition partition string from dictionary table name
172@param[in] convert convert partition names to system cs
173@param[out] part partition name
174@param[out] sub_part sub partition name if present */
175void get_partition(const std::string &partition, bool convert,
176 std::string &part, std::string &sub_part);
177
178/* Build dictionary table name. Table name in dictionary is always in filename
179character set.
180@param[in] schema schema name
181@param[in] table table name
182@param[in] partition partition string if table partition
183@param[in] is_tmp true, iff temporary table created by DDL
184@param[in] convert convert all names from system cs
185@param[out] dict_name table name for innodb dictionary */
186void build_table(const std::string &schema, const std::string &table,
187 const std::string &partition, bool is_tmp, bool convert,
188 std::string &dict_name);
189
190/** Build partition string from dd object.
191@param[in] dd_part partition object from DD
192@param[out] partition partition string for dictionary table name */
193void build_partition(const dd::Partition *dd_part, std::string &partition);
194
195/** Build 5.7 style partition string from dd object.
196@param[in] dd_part partition object from DD
197@param[out] partition partition string for dictionary table name */
198void build_57_partition(const dd::Partition *dd_part, std::string &partition);
199
200/** Check if dd partition matches with innodb dictionary table name.
201@param[in] dict_name table name in innodb dictionary
202@param[in] dd_part partition object from DD
203@return true, iff the name matches the partition from DD. */
204bool match_partition(const std::string &dict_name,
205 const dd::Partition *dd_part);
206
207/* Build space name by converting schema, table, partition and sub partition
208names within a dictionary table name.
209@param[in,out] dict_name table name in dictionary */
210void convert_to_space(std::string &dict_name);
211
212/* Rebuild space name by replacing partition string from dictionary table name.
213@param[in] dict_name table name in dictionary
214@param[in,out] space_name space name to be rebuilt */
215void rebuild_space(const std::string &dict_name, std::string &space_name);
216
217/** Rebuild table name to convert from 5.7 format to 8.0.
218@param[in,out] dict_name table name in dictionary */
219void rebuild(std::string &dict_name);
220
221} // namespace dict_name
222
223/* Space id and page no where the dictionary header resides */
224constexpr uint32_t DICT_HDR_SPACE = 0; /* the SYSTEM tablespace */
226
227/* The ibuf table and indexes's ID are assigned as the number
228DICT_IBUF_ID_MIN plus the space id */
229constexpr uint64_t DICT_IBUF_ID_MIN = 0xFFFFFFFF00000000ULL;
230
231/** Table or partition identifier (unique within an InnoDB instance). */
233/** Index identifier (unique within a tablespace). */
235
236/** Globally unique index identifier */
238 public:
239 /** Constructor.
240 @param[in] space_id Tablespace identifier
241 @param[in] index_id Index identifier */
243 : m_space_id(space_id), m_index_id(index_id) {}
244
245 /** Compare this to another index identifier.
246 @param other the other index identifier
247 @return whether this is less than other */
248 bool operator<(const index_id_t &other) const {
249 return (m_space_id < other.m_space_id ||
250 (m_space_id == other.m_space_id && m_index_id < other.m_index_id));
251 }
252 /** Compare this to another index identifier.
253 @param other the other index identifier
254 @return whether the identifiers are equal */
255 bool operator==(const index_id_t &other) const {
256 return (m_space_id == other.m_space_id && m_index_id == other.m_index_id);
257 }
258
259 /** Convert an index_id to a 64 bit integer.
260 @return a 64 bit integer */
261 uint64_t conv_to_int() const {
262 ut_ad((m_index_id & 0xFFFFFFFF00000000ULL) == 0);
263
264 return (static_cast<uint64_t>(m_space_id) << 32 | m_index_id);
265 }
266
267 /** Check if the index belongs to the insert buffer.
268 @return true if the index belongs to the insert buffer */
269 bool is_ibuf() const {
270 return (m_space_id == IBUF_SPACE_ID &&
272 }
273
274 /** Tablespace identifier */
276 /** Index identifier within the tablespace */
278};
279
280/** Display an index identifier.
281@param[in,out] out the output stream
282@param[in] id index identifier
283@return the output stream */
284inline std::ostream &operator<<(std::ostream &out, const index_id_t &id) {
285 return (out << "[space=" << id.m_space_id << ",index=" << id.m_index_id
286 << "]");
287}
288
289/** Error to ignore when we load table dictionary into memory. However,
290the table and index will be marked as "corrupted", and caller will
291be responsible to deal with corrupted table or index.
292Note: please define the IGNORE_ERR_* as bits, so their value can
293be or-ed together */
295 DICT_ERR_IGNORE_NONE = 0, /*!< no error to ignore */
296 DICT_ERR_IGNORE_INDEX_ROOT = 1, /*!< ignore error if index root
297 page is FIL_NULL or incorrect value */
298 DICT_ERR_IGNORE_CORRUPT = 2, /*!< skip corrupted indexes */
299 DICT_ERR_IGNORE_FK_NOKEY = 4, /*!< ignore error if any foreign
300 key is missing */
302 /*!< Used when recovering table locks
303 for resurrected transactions.
304 Silently load a missing
305 tablespace, and do not load
306 incomplete index definitions. */
307 DICT_ERR_IGNORE_ALL = 0xFFFF /*!< ignore all errors */
309
310/** Quiescing states for flushing tables to disk. */
313 QUIESCE_START, /*!< Initialise, prepare to start */
314 QUIESCE_COMPLETE /*!< All done */
316
317#ifndef UNIV_HOTBACKUP
318typedef ib_mutex_t DictSysMutex;
319#endif /* !UNIV_HOTBACKUP */
320
321/** Prefix for tmp tables, adopted from sql/table.h */
322#define TEMP_FILE_PREFIX "#sql"
323#define TEMP_FILE_PREFIX_LENGTH 4
324#define TEMP_FILE_PREFIX_INNODB "#sql-ib"
325
326#define TEMP_TABLE_PREFIX "#sql"
327#define TEMP_TABLE_PATH_PREFIX "/" TEMP_TABLE_PREFIX
328
329#if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
330/** Flag to control insert buffer debugging. */
331extern uint ibuf_debug;
332#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
333
334/** Shift for spatial status */
335constexpr uint32_t SPATIAL_STATUS_SHIFT = 12;
336
337/** Mask to encode/decode spatial status. */
339
341 "SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN");
342
343/** whether a col is used in spatial index or regular index
344Note: the spatial status is part of persistent undo log,
345so we should not modify the values in MySQL 5.7 */
347 /* Unknown status (undo format in 5.7.9) */
349
350 /** Not used in gis index. */
352
353 /** Used in both spatial index and regular index. */
355
356 /** Only used in spatial index. */
357 SPATIAL_ONLY = 3
359
360#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:52
Definition: partition.h:51
Globally unique index identifier.
Definition: dict0types.h:237
space_index_t m_index_id
Index identifier within the tablespace.
Definition: dict0types.h:277
space_id_t m_space_id
Tablespace identifier.
Definition: dict0types.h:275
uint64_t conv_to_int() const
Convert an index_id to a 64 bit integer.
Definition: dict0types.h:261
index_id_t(space_id_t space_id, space_index_t index_id)
Constructor.
Definition: dict0types.h:242
bool is_ibuf() const
Check if the index belongs to the insert buffer.
Definition: dict0types.h:269
bool operator==(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:255
bool operator<(const index_id_t &other) const
Compare this to another index identifier.
Definition: dict0types.h:248
ib_id_t space_index_t
Index identifier (unique within a tablespace).
Definition: dict0types.h:234
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:346
@ SPATIAL_MIXED
Used in both spatial index and regular index.
Definition: dict0types.h:354
@ SPATIAL_NONE
Not used in gis index.
Definition: dict0types.h:351
@ SPATIAL_UNKNOWN
Definition: dict0types.h:348
@ SPATIAL_ONLY
Only used in spatial index.
Definition: dict0types.h:357
uint ibuf_debug
Flag to control insert buffer debugging.
Definition: ibuf0ibuf.cc:208
constexpr uint64_t DICT_IBUF_ID_MIN
Definition: dict0types.h:229
std::ostream & operator<<(std::ostream &out, const index_id_t &id)
Display an index identifier.
Definition: dict0types.h:284
constexpr uint32_t SPATIAL_STATUS_MASK
Mask to encode/decode spatial status.
Definition: dict0types.h:338
constexpr uint32_t DICT_HDR_PAGE_NO
Definition: dict0types.h:225
ib_mutex_t DictSysMutex
Definition: dict0types.h:318
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:294
@ DICT_ERR_IGNORE_INDEX_ROOT
ignore error if index root page is FIL_NULL or incorrect value
Definition: dict0types.h:296
@ DICT_ERR_IGNORE_NONE
no error to ignore
Definition: dict0types.h:295
@ DICT_ERR_IGNORE_CORRUPT
skip corrupted indexes
Definition: dict0types.h:298
@ DICT_ERR_IGNORE_ALL
ignore all errors
Definition: dict0types.h:307
@ DICT_ERR_IGNORE_RECOVER_LOCK
Used when recovering table locks for resurrected transactions.
Definition: dict0types.h:301
@ DICT_ERR_IGNORE_FK_NOKEY
ignore error if any foreign key is missing
Definition: dict0types.h:299
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:232
ib_quiesce_t
Quiescing states for flushing tables to disk.
Definition: dict0types.h:311
@ QUIESCE_NONE
Definition: dict0types.h:312
@ QUIESCE_START
Initialise, prepare to start.
Definition: dict0types.h:313
@ QUIESCE_COMPLETE
All done.
Definition: dict0types.h:314
constexpr uint32_t SPATIAL_STATUS_SHIFT
Shift for spatial status.
Definition: dict0types.h:335
constexpr uint32_t DICT_HDR_SPACE
Definition: dict0types.h:224
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:137
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Innodb data dictionary name.
Definition: dict0dd.cc:7320
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:7619
std::function< void(std::string &)> Convert_Func
Name string conversion callback.
Definition: dict0types.h:130
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:7457
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:7519
bool is_partition(const std::string &dict_name)
Check if it is a table partition.
Definition: dict0dd.cc:7452
constexpr size_t MAX_TABLE_CHAR_LEN
The maximum length in characters for table name.
Definition: dict0types.h:112
constexpr size_t MAX_DB_CHAR_LEN
The maximum length in characters for database name.
Definition: dict0types.h:99
void rebuild_space(const std::string &dict_name, std::string &space_name)
Definition: dict0dd.cc:7870
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:7769
void build_partition(const dd::Partition *dd_part, std::string &partition)
Build partition string from dd object.
Definition: dict0dd.cc:7739
constexpr char ALT_SUB_PART_SEPARATOR[]
Alternative sub-partition separator from 8.0.17 and older versions.
Definition: dict0types.h:88
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:107
constexpr char ALT_PART_SEPARATOR[]
Alternative partition separator from 8.0.17 and older versions.
Definition: dict0types.h:85
void rebuild(std::string &dict_name)
Rebuild table name to convert from 5.7 format to 8.0.
Definition: dict0dd.cc:7899
constexpr size_t MAX_SPACE_NAME_LEN
Maximum space name length.
Definition: dict0types.h:125
constexpr size_t SCHEMA_SEPARATOR_LEN
Definition: dict0types.h:92
constexpr char SCHEMA_SEPARATOR[]
Schema separator is forward slash irrespective of platform.
Definition: dict0types.h:91
void file_to_table(std::string &name, bool quiet)
Conversion function to change for system to file name cs.
Definition: dict0dd.cc:7321
constexpr size_t TMP_POSTFIX_LEN
Definition: dict0types.h:121
void convert_to_space(std::string &dict_name)
Definition: dict0dd.cc:7845
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:7581
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:96
constexpr char TMP_POSTFIX[]
Postfix for a table name which is being altered.
Definition: dict0types.h:120
void build_57_partition(const dd::Partition *dd_part, std::string &partition)
Build 5.7 style partition string from dd object.
Definition: dict0dd.cc:7750
void table_to_file(std::string &name)
Conversion function to change for file name to system cs.
Definition: dict0dd.cc:7330
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:72
case opt name
Definition: sslopt-case.h:33
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:835
Data structure for a column in a table.
Definition: dict0mem.h:489
Data structure for a field in an index.
Definition: dict0mem.h:895
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1666
Data structure for an index.
Definition: dict0mem.h:1046
Definition: dict0dict.h:1009
Data structure for a database table.
Definition: dict0mem.h:1909
Data structure for a virtual column in a table.
Definition: dict0mem.h:815
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
unsigned int uint
Definition: uca9-dump.cc:75
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:69
Policy based mutexes.