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