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