| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1996, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 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 |
|
| 43 |
struct dict_sys_t; |
| 44 |
struct dict_col_t; |
| 45 |
struct dict_field_t; |
| 46 |
struct dict_index_t; |
| 47 |
struct dict_table_t; |
| 48 |
struct dict_foreign_t; |
| 49 |
struct dict_v_col_t; |
| 50 |
|
| 51 |
struct ind_node_t; |
| 52 |
struct tab_node_t; |
| 53 |
struct dict_add_v_col_t; |
| 54 |
|
| 55 |
struct table_name_components { |
| 56 |
std::string schema_name; |
| 57 |
std::string table_name; |
| 58 |
std::string partition; |
| 59 |
std::string subpartition; |
| 60 |
std::string directory; |
| 61 |
}; |
| 62 |
|
| 63 |
namespace dd { |
| 64 |
class Partition; |
| 65 |
} |
| 66 |
|
| 67 |
/** Innodb data dictionary name. |
| 68 |
NOTE: Innodb dictionary table name is always in my_charset_filename. Hence, |
| 69 |
dictionary name (dict_name) and partition string input parameters in dict_name:: |
| 70 |
interfaces are assumed to be in my_charset_filename. */ |
| 71 |
namespace dict_name { |
| 72 |
/** Partition separator in dictionary table name and file name. */ |
| 73 |
constexpr char PART_SEPARATOR[] = "#p#"; |
| 74 |
|
| 75 |
/** Partition separator length excluding terminating NULL */ |
| 76 |
constexpr size_t PART_SEPARATOR_LEN = sizeof(PART_SEPARATOR) - 1; |
| 77 |
|
| 78 |
/** Sub-Partition separator in dictionary table name and file name. */ |
| 79 |
constexpr char SUB_PART_SEPARATOR[] = "#sp#"; |
| 80 |
|
| 81 |
/** Sub-Partition separator length excluding terminating NULL */ |
| 82 |
constexpr size_t SUB_PART_SEPARATOR_LEN = sizeof(SUB_PART_SEPARATOR) - 1; |
| 83 |
|
| 84 |
/** Alternative partition separator from 8.0.17 and older versions. */ |
| 85 |
constexpr char ALT_PART_SEPARATOR[] = "#P#"; |
| 86 |
|
| 87 |
/** Alternative sub-partition separator from 8.0.17 and older versions. */ |
| 88 |
constexpr char ALT_SUB_PART_SEPARATOR[] = "#SP#"; |
| 89 |
|
| 90 |
/** Schema separator is forward slash irrespective of platform. */ |
| 91 |
constexpr char SCHEMA_SEPARATOR[] = "/"; |
| 92 |
constexpr size_t SCHEMA_SEPARATOR_LEN = sizeof(SCHEMA_SEPARATOR) - 1; |
| 93 |
|
| 94 |
/** The maximum length in bytes that a database name can occupy when |
| 95 |
stored in UTF8MB3, including the terminating null. */ |
| 96 |
constexpr size_t MAX_DB_UTF8MB3_LEN = NAME_LEN + 1; |
| 97 |
|
| 98 |
/** The maximum length in characters for database name. */ |
| 99 |
constexpr 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 |
| 102 |
UTF8MB3, including the terminating null. NAME_LEN is added 3 times to consider |
| 103 |
table name, partition name and sub-partition name for a partitioned table. |
| 104 |
In innodb each partition/sub-partition is a separate table named as below. |
| 105 |
table_name<PART_SEPARATOR>partition_name<SUB_PART_SEPARATOR>subpartition_name |
| 106 |
This macro only applies to table name, without any database name prefixed. */ |
| 107 |
constexpr size_t MAX_TABLE_UTF8MB3_LEN = NAME_LEN + PART_SEPARATOR_LEN + |
| 108 |
NAME_LEN + SUB_PART_SEPARATOR_LEN + |
| 109 |
NAME_LEN + 1; |
| 110 |
|
| 111 |
/** The maximum length in characters for table name. */ |
| 112 |
constexpr size_t MAX_TABLE_CHAR_LEN = NAME_CHAR_LEN + PART_SEPARATOR_LEN + |
| 113 |
NAME_CHAR_LEN + SUB_PART_SEPARATOR_LEN + |
| 114 |
NAME_CHAR_LEN; |
| 115 |
|
| 116 |
/** Postfix for a table name which is being altered. Since during |
| 117 |
ALTER TABLE ... PARTITION, new partitions have to be created before |
| 118 |
dropping existing partitions, so a postfix is appended to the name |
| 119 |
to prevent name conflicts. This is also used for EXCHANGE PARTITION */ |
| 120 |
constexpr char TMP_POSTFIX[] = "#tmp"; |
| 121 |
constexpr size_t TMP_POSTFIX_LEN = sizeof(TMP_POSTFIX) - 1; |
| 122 |
|
| 123 |
/** Maximum space name length. Space name includes schema name, table name |
| 124 |
along with partition and sub-partition name for partitioned table. */ |
| 125 |
constexpr size_t MAX_SPACE_NAME_LEN = |
| 126 |
NAME_LEN + SCHEMA_SEPARATOR_LEN + NAME_LEN + PART_SEPARATOR_LEN + NAME_LEN + |
| 127 |
SUB_PART_SEPARATOR_LEN + NAME_LEN + TMP_POSTFIX_LEN; |
| 128 |
|
| 129 |
/** Name string conversion callback. Used for character set conversion. */ |
| 130 |
using 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. */ |
| 135 |
void 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. */ |
| 139 |
void 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. */ |
| 144 |
bool is_partition(const std::string &dict_name); |
| 145 |
|
| 146 |
/** Get schema, table name, partition string and temporary attribute from |
| 147 |
dictionary 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 */ |
| 154 |
void 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 */ |
| 161 |
void 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 |
| 165 |
from 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 */ |
| 168 |
std::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 */ |
| 175 |
void 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 |
| 179 |
character 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 */ |
| 186 |
void 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 */ |
| 193 |
void 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 */ |
| 198 |
void 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. */ |
| 204 |
bool 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 |
| 208 |
names within a dictionary table name. |
| 209 |
@param[in,out] dict_name table name in dictionary */ |
| 210 |
void 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 */ |
| 215 |
void 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 */ |
| 219 |
void rebuild(std::string &dict_name); |
| 220 |
|
| 221 |
} // namespace dict_name |
| 222 |
|
| 223 |
/* Space id and page no where the dictionary header resides */ |
| 224 |
constexpr uint32_t DICT_HDR_SPACE = 0; /* the SYSTEM tablespace */ |
| 225 |
constexpr uint32_t DICT_HDR_PAGE_NO = FSP_DICT_HDR_PAGE_NO; |
| 226 |
|
| 227 |
/* The ibuf table and indexes's ID are assigned as the number |
| 228 |
DICT_IBUF_ID_MIN plus the space id */ |
| 229 |
constexpr uint64_t DICT_IBUF_ID_MIN = 0xFFFFFFFF00000000ULL; |
| 230 |
|
| 231 |
/** Table or partition identifier (unique within an InnoDB instance). */ |
| 232 |
typedef ib_id_t table_id_t; |
| 233 |
/** Index identifier (unique within a tablespace). */ |
| 234 |
typedef ib_id_t space_index_t; |
| 235 |
|
| 236 |
/** Globally unique index identifier */ |
| 237 |
class index_id_t { |
| 238 |
public: |
| 239 |
/** Constructor. |
| 240 |
@param[in] space_id Tablespace identifier |
| 241 |
@param[in] index_id Index identifier */ |
| 242 |
index_id_t(space_id_t space_id, space_index_t index_id) |
| 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 && |
| 271 |
m_index_id == DICT_IBUF_ID_MIN + IBUF_SPACE_ID); |
| 272 |
} |
| 273 |
|
| 274 |
/** Tablespace identifier */ |
| 275 |
space_id_t m_space_id; |
| 276 |
/** Index identifier within the tablespace */ |
| 277 |
space_index_t m_index_id; |
| 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 */ |
| 284 |
inline 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, |
| 290 |
the table and index will be marked as "corrupted", and caller will |
| 291 |
be responsible to deal with corrupted table or index. |
| 292 |
Note: please define the IGNORE_ERR_* as bits, so their value can |
| 293 |
be or-ed together */ |
| 294 |
enum dict_err_ignore_t { |
| 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 */ |
| 301 |
DICT_ERR_IGNORE_RECOVER_LOCK = 8, |
| 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 */ |
| 308 |
}; |
| 309 |
|
| 310 |
/** Quiescing states for flushing tables to disk. */ |
| 311 |
enum ib_quiesce_t { |
| 312 |
QUIESCE_NONE, |
| 313 |
QUIESCE_START, /*!< Initialise, prepare to start */ |
| 314 |
QUIESCE_COMPLETE /*!< All done */ |
| 315 |
}; |
| 316 |
|
| 317 |
#ifndef UNIV_HOTBACKUP |
| 318 |
typedef 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. */ |
| 331 |
extern uint ibuf_debug; |
| 332 |
#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */ |
| 333 |
|
| 334 |
/** Shift for spatial status */ |
| 335 |
constexpr uint32_t SPATIAL_STATUS_SHIFT = 12; |
| 336 |
|
| 337 |
/** Mask to encode/decode spatial status. */ |
| 338 |
constexpr uint32_t SPATIAL_STATUS_MASK = 3 << SPATIAL_STATUS_SHIFT; |
| 339 |
|
| 340 |
static_assert(SPATIAL_STATUS_MASK >= REC_VERSION_56_MAX_INDEX_COL_LEN, |
| 341 |
"SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN"); |
| 342 |
|
| 343 |
/** whether a col is used in spatial index or regular index |
| 344 |
Note: the spatial status is part of persistent undo log, |
| 345 |
so we should not modify the values in MySQL 5.7 */ |
| 346 |
enum spatial_status_t { |
| 347 |
/* Unknown status (undo format in 5.7.9) */ |
| 348 |
SPATIAL_UNKNOWN = 0, |
| 349 |
|
| 350 |
/** Not used in gis index. */ |
| 351 |
SPATIAL_NONE = 1, |
| 352 |
|
| 353 |
/** Used in both spatial index and regular index. */ |
| 354 |
SPATIAL_MIXED = 2, |
| 355 |
|
| 356 |
/** Only used in spatial index. */ |
| 357 |
SPATIAL_ONLY = 3 |
| 358 |
}; |
| 359 |
|
| 360 |
#endif |