| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2015, 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/dict0dd.h |
| 29 |
Data dictionary interface */ |
| 30 |
|
| 31 |
#ifndef dict0dd_h |
| 32 |
#define dict0dd_h |
| 33 |
|
| 34 |
#include "dict0dict.h" |
| 35 |
#include "dict0mem.h" |
| 36 |
#include "dict0types.h" |
| 37 |
#include "my_compiler.h" |
| 38 |
#include "univ.i" |
| 39 |
|
| 40 |
#ifndef UNIV_HOTBACKUP |
| 41 |
#include "dd/cache/dictionary_client.h" |
| 42 |
#include "dd/dd.h" |
| 43 |
#include "dd/dd_schema.h" |
| 44 |
#include "dd/dd_table.h" |
| 45 |
#include "dd/dictionary.h" |
| 46 |
#include "dd/properties.h" |
| 47 |
#include "dd/types/column.h" |
| 48 |
#include "dd/types/foreign_key.h" |
| 49 |
#include "dd/types/foreign_key_element.h" |
| 50 |
#include "dd/types/index.h" |
| 51 |
#include "dd/types/index_element.h" |
| 52 |
#include "dd/types/partition.h" |
| 53 |
#include "dd/types/partition_index.h" |
| 54 |
#include "dd/types/table.h" |
| 55 |
#include "dd/types/tablespace.h" |
| 56 |
#include "dd/types/tablespace_file.h" |
| 57 |
#include "dd_table_share.h" |
| 58 |
#include "sess0sess.h" |
| 59 |
#else |
| 60 |
#include "mysql_com.h" |
| 61 |
#endif /* !UNIV_HOTBACKUP */ |
| 62 |
#include "mysql_version.h" |
| 63 |
|
| 64 |
#ifndef UNIV_HOTBACKUP |
| 65 |
class THD; |
| 66 |
class MDL_ticket; |
| 67 |
|
| 68 |
/** DD functions return false for success and true for failure |
| 69 |
because that is the way the server functions are defined. */ |
| 70 |
constexpr bool DD_SUCCESS = false; |
| 71 |
constexpr bool DD_FAILURE = true; |
| 72 |
|
| 73 |
/** Handler name for InnoDB */ |
| 74 |
static constexpr char handler_name[] = "InnoDB"; |
| 75 |
|
| 76 |
static const char innobase_hton_name[] = "InnoDB"; |
| 77 |
|
| 78 |
/** String constant for AUTOEXTEND_SIZE option string */ |
| 79 |
static constexpr char autoextend_size_str[] = "autoextend_size"; |
| 80 |
|
| 81 |
/** Determine if give version is a valid row version */ |
| 82 |
bool dd_is_valid_row_version(uint32_t version); |
| 83 |
|
| 84 |
/** Determine if column is INSTANT ADD */ |
| 85 |
bool dd_column_is_added(const dd::Column *dd_col); |
| 86 |
|
| 87 |
/** Determine if column is INSTANT DROP */ |
| 88 |
bool dd_column_is_dropped(const dd::Column *dd_col); |
| 89 |
|
| 90 |
/** Get the row version in which column is INSTANT ADD */ |
| 91 |
uint32_t dd_column_get_version_added(const dd::Column *dd_col); |
| 92 |
|
| 93 |
/** Get the row version in which column is INSTANT DROP */ |
| 94 |
uint32_t dd_column_get_version_dropped(const dd::Column *dd_col); |
| 95 |
|
| 96 |
/** Maximum hardcoded data dictionary tables. */ |
| 97 |
constexpr uint32_t DICT_MAX_DD_TABLES = 1024; |
| 98 |
|
| 99 |
/** InnoDB private keys for dd::Table */ |
| 100 |
enum dd_table_keys { |
| 101 |
/** Auto-increment counter */ |
| 102 |
DD_TABLE_AUTOINC, |
| 103 |
/** DATA DIRECTORY (static metadata) */ |
| 104 |
DD_TABLE_DATA_DIRECTORY, |
| 105 |
/** Dynamic metadata version */ |
| 106 |
DD_TABLE_VERSION, |
| 107 |
/** Discard flag. Please don't use it directly, and instead use |
| 108 |
dd_is_discarded and dd_set_discarded functions. Discard flag is defined |
| 109 |
for both dd::Table and dd::Partition and it's easy to confuse. |
| 110 |
The functions will choose right implementation for you, depending on |
| 111 |
whether the argument is dd::Table or dd::Partition. */ |
| 112 |
DD_TABLE_DISCARD, |
| 113 |
/** Columns before first instant ADD COLUMN, used only for V1 */ |
| 114 |
DD_TABLE_INSTANT_COLS, |
| 115 |
/** Sentinel */ |
| 116 |
DD_TABLE__LAST |
| 117 |
}; |
| 118 |
|
| 119 |
/** InnoDB private keys for dd::Column */ |
| 120 |
/** About the DD_INSTANT_COLUMN_DEFAULT*, please note that if it's a |
| 121 |
partitioned table, not every default value is needed for every partition. |
| 122 |
For example, after ALTER TABLE ... PARTITION, maybe some partitions only |
| 123 |
need part or even none of the default values. Let's say there are two |
| 124 |
partitions, p1 and p2. p1 needs 10 default values while p2 needs 2. |
| 125 |
If another ALTER ... PARTITION makes p1 a fresh new partition which |
| 126 |
doesn't need the default values any more, currently, the extra 8(10 - 2) |
| 127 |
default values are not removed form dd::Column::se_private_data. */ |
| 128 |
enum dd_column_keys { |
| 129 |
/** Default value when it was added instantly */ |
| 130 |
DD_INSTANT_COLUMN_DEFAULT, |
| 131 |
/** Default value is null or not */ |
| 132 |
DD_INSTANT_COLUMN_DEFAULT_NULL, |
| 133 |
/** Row version when this column was added instantly */ |
| 134 |
DD_INSTANT_VERSION_ADDED, |
| 135 |
/** Row version when this column was dropped instantly */ |
| 136 |
DD_INSTANT_VERSION_DROPPED, |
| 137 |
/** Column physical position on row when it was created */ |
| 138 |
DD_INSTANT_PHYSICAL_POS, |
| 139 |
/** Sentinel */ |
| 140 |
DD_COLUMN__LAST |
| 141 |
}; |
| 142 |
|
| 143 |
#endif /* !UNIV_HOTBACKUP */ |
| 144 |
|
| 145 |
/** Server version that the tablespace created */ |
| 146 |
const uint32_t DD_SPACE_CURRENT_SRV_VERSION = MYSQL_VERSION_ID; |
| 147 |
|
| 148 |
/** The tablespace version that the tablespace created */ |
| 149 |
const uint32_t DD_SPACE_CURRENT_SPACE_VERSION = 1; |
| 150 |
|
| 151 |
#ifndef UNIV_HOTBACKUP |
| 152 |
/** InnoDB private keys for dd::Partition */ |
| 153 |
enum dd_partition_keys { |
| 154 |
/** Row format for this partition */ |
| 155 |
DD_PARTITION_ROW_FORMAT, |
| 156 |
/** Columns before first instant ADD COLUMN. |
| 157 |
This is necessary for each partition because different partition |
| 158 |
may have different instant column numbers, especially, for a |
| 159 |
newly truncated partition, it can have no instant columns. |
| 160 |
So partition level one should be always >= table level one. */ |
| 161 |
DD_PARTITION_INSTANT_COLS, |
| 162 |
/** Discard flag. Please don't use it directly, and instead use |
| 163 |
dd_is_discarded and dd_set_discarded functions. Discard flag is defined |
| 164 |
for both dd::Table and dd::Partition and it's easy to confuse. |
| 165 |
The functions will choose right implementation for you, depending on |
| 166 |
whether the argument is dd::Table or dd::Partition. */ |
| 167 |
DD_PARTITION_DISCARD, |
| 168 |
/** Sentinel */ |
| 169 |
DD_PARTITION__LAST |
| 170 |
}; |
| 171 |
|
| 172 |
/** InnoDB private keys for dd::Tablespace */ |
| 173 |
enum dd_space_keys { |
| 174 |
/** Tablespace flags */ |
| 175 |
DD_SPACE_FLAGS, |
| 176 |
/** Tablespace identifier */ |
| 177 |
DD_SPACE_ID, |
| 178 |
/** Discard attribute */ |
| 179 |
DD_SPACE_DISCARD, |
| 180 |
/** Server version */ |
| 181 |
DD_SPACE_SERVER_VERSION, |
| 182 |
/** TABLESPACE_VERSION */ |
| 183 |
DD_SPACE_VERSION, |
| 184 |
/** Current state attribute */ |
| 185 |
DD_SPACE_STATE, |
| 186 |
/** Sentinel */ |
| 187 |
DD_SPACE__LAST |
| 188 |
}; |
| 189 |
|
| 190 |
/** Values for InnoDB private key "state" for dd::Tablespace */ |
| 191 |
enum dd_space_states { |
| 192 |
/** Normal IBD tablespace */ |
| 193 |
DD_SPACE_STATE_NORMAL, |
| 194 |
/** Discarded IBD tablespace */ |
| 195 |
DD_SPACE_STATE_DISCARDED, |
| 196 |
/** Corrupted IBD tablespace */ |
| 197 |
DD_SPACE_STATE_CORRUPTED, |
| 198 |
/** Active undo tablespace */ |
| 199 |
DD_SPACE_STATE_ACTIVE, |
| 200 |
/** Inactive undo tablespace being truncated, selected |
| 201 |
explicitly by ALTER UNDO TABLESPACE SET INACTIVE. |
| 202 |
Note: the DD is not updated when an undo space is selected |
| 203 |
for truncation implicitly by the purge thread. */ |
| 204 |
DD_SPACE_STATE_INACTIVE, |
| 205 |
/** Inactive undo tablespace being truncated, selected |
| 206 |
explicitly by ALTER UNDO TABLESPACE SET INACTIVE. */ |
| 207 |
DD_SPACE_STATE_EMPTY, |
| 208 |
/** Sentinel */ |
| 209 |
DD_SPACE_STATE__LAST |
| 210 |
}; |
| 211 |
|
| 212 |
/** InnoDB implicit tablespace name or prefix, which should be same to |
| 213 |
dict_sys_t::s_file_per_table_name */ |
| 214 |
static constexpr char reserved_implicit_name[] = "innodb_file_per_table"; |
| 215 |
|
| 216 |
/** InnoDB private key strings for dd::Tablespace. |
| 217 |
@see dd_space_keys */ |
| 218 |
const char *const dd_space_key_strings[DD_SPACE__LAST] = { |
| 219 |
"flags", "id", "discard", "server_version", "space_version", "state"}; |
| 220 |
|
| 221 |
/** InnoDB private value strings for key string "state" in dd::Tablespace. |
| 222 |
@see dd_space_state_values */ |
| 223 |
const char *const dd_space_state_values[DD_SPACE_STATE__LAST + 1] = { |
| 224 |
"normal", /* for IBD spaces */ |
| 225 |
"discarded", /* for IBD spaces */ |
| 226 |
"corrupted", /* for IBD spaces */ |
| 227 |
"active", /* for undo spaces*/ |
| 228 |
"inactive", /* for undo spaces */ |
| 229 |
"empty", /* for undo spaces */ |
| 230 |
"unknown" /* for non-existing or unknown spaces */ |
| 231 |
}; |
| 232 |
|
| 233 |
/** InnoDB private key strings for dd::Table. @see dd_table_keys */ |
| 234 |
const char *const dd_table_key_strings[DD_TABLE__LAST] = { |
| 235 |
"autoinc", "data_directory", "version", "discard", "instant_col"}; |
| 236 |
|
| 237 |
/** InnoDB private key strings for dd::Column, @see dd_column_keys */ |
| 238 |
const char *const dd_column_key_strings[DD_COLUMN__LAST] = { |
| 239 |
"default", "default_null", "version_added", "version_dropped", |
| 240 |
"physical_pos"}; |
| 241 |
|
| 242 |
/** InnoDB private key strings for dd::Partition. @see dd_partition_keys */ |
| 243 |
const char *const dd_partition_key_strings[DD_PARTITION__LAST] = { |
| 244 |
"format", "instant_col", "discard"}; |
| 245 |
|
| 246 |
/** InnoDB private keys for dd::Index or dd::Partition_index */ |
| 247 |
enum dd_index_keys { |
| 248 |
/** Index identifier */ |
| 249 |
DD_INDEX_ID, |
| 250 |
/** Space id */ |
| 251 |
DD_INDEX_SPACE_ID, |
| 252 |
/** Table id */ |
| 253 |
DD_TABLE_ID, |
| 254 |
/** Root page number */ |
| 255 |
DD_INDEX_ROOT, |
| 256 |
/** Creating transaction ID */ |
| 257 |
DD_INDEX_TRX_ID, |
| 258 |
/** Sentinel */ |
| 259 |
DD_INDEX__LAST |
| 260 |
}; |
| 261 |
|
| 262 |
/** InnoDB private key strings for dd::Index or dd::Partition_index. |
| 263 |
@see dd_index_keys */ |
| 264 |
const char *const dd_index_key_strings[DD_INDEX__LAST] = { |
| 265 |
"id", "space_id", "table_id", "root", "trx_id"}; |
| 266 |
|
| 267 |
/** InnoDB private key strings for dd::Index or dd::Partition_index. |
| 268 |
@see dd_index_keys */ |
| 269 |
extern const char *const dd_index_key_strings[DD_INDEX__LAST]; |
| 270 |
|
| 271 |
/** dd::Partition::options() key for INDEX DIRECTORY */ |
| 272 |
static const dd::String_type index_file_name_key("index_file_name"); |
| 273 |
/** dd::Partition::options() key for DATA DIRECTORY */ |
| 274 |
static const dd::String_type data_file_name_key("data_file_name"); |
| 275 |
|
| 276 |
/** Table names needed to process I_S queries. */ |
| 277 |
static const dd::String_type dd_tables_name("mysql/tables"); |
| 278 |
static const dd::String_type dd_partitions_name("mysql/table_partitions"); |
| 279 |
static const dd::String_type dd_tablespaces_name("mysql/tablespaces"); |
| 280 |
static const dd::String_type dd_indexes_name("mysql/indexes"); |
| 281 |
static const dd::String_type dd_columns_name("mysql/columns"); |
| 282 |
|
| 283 |
#ifdef UNIV_DEBUG |
| 284 |
|
| 285 |
/** Hard-coded data dictionary information */ |
| 286 |
struct innodb_dd_table_t { |
| 287 |
/** Data dictionary table name */ |
| 288 |
const char *name; |
| 289 |
/** Number of indexes */ |
| 290 |
const uint n_indexes; |
| 291 |
}; |
| 292 |
|
| 293 |
/** The hard-coded data dictionary tables. */ |
| 294 |
const innodb_dd_table_t innodb_dd_table[] = { |
| 295 |
INNODB_DD_TABLE("dd_properties", 1), |
| 296 |
|
| 297 |
INNODB_DD_TABLE("innodb_dynamic_metadata", 1), |
| 298 |
INNODB_DD_TABLE("innodb_table_stats", 1), |
| 299 |
INNODB_DD_TABLE("innodb_index_stats", 1), |
| 300 |
INNODB_DD_TABLE("innodb_ddl_log", 2), |
| 301 |
|
| 302 |
INNODB_DD_TABLE("catalogs", 2), |
| 303 |
INNODB_DD_TABLE("character_sets", 3), |
| 304 |
INNODB_DD_TABLE("check_constraints", 3), |
| 305 |
INNODB_DD_TABLE("collations", 3), |
| 306 |
INNODB_DD_TABLE("column_statistics", 3), |
| 307 |
INNODB_DD_TABLE("column_type_elements", 1), |
| 308 |
INNODB_DD_TABLE("columns", 5), |
| 309 |
INNODB_DD_TABLE("events", 6), |
| 310 |
INNODB_DD_TABLE("foreign_key_column_usage", 3), |
| 311 |
INNODB_DD_TABLE("foreign_keys", 4), |
| 312 |
INNODB_DD_TABLE("index_column_usage", 3), |
| 313 |
INNODB_DD_TABLE("index_partitions", 3), |
| 314 |
INNODB_DD_TABLE("index_stats", 1), |
| 315 |
INNODB_DD_TABLE("indexes", 3), |
| 316 |
INNODB_DD_TABLE("parameter_type_elements", 1), |
| 317 |
INNODB_DD_TABLE("parameters", 3), |
| 318 |
INNODB_DD_TABLE("resource_groups", 2), |
| 319 |
INNODB_DD_TABLE("routines", 7), |
| 320 |
INNODB_DD_TABLE("schemata", 3), |
| 321 |
INNODB_DD_TABLE("st_spatial_reference_systems", 3), |
| 322 |
INNODB_DD_TABLE("table_partition_values", 1), |
| 323 |
INNODB_DD_TABLE("table_partitions", 7), |
| 324 |
INNODB_DD_TABLE("table_stats", 1), |
| 325 |
INNODB_DD_TABLE("tables", 10), |
| 326 |
INNODB_DD_TABLE("tablespace_files", 2), |
| 327 |
INNODB_DD_TABLE("tablespaces", 2), |
| 328 |
INNODB_DD_TABLE("triggers", 7), |
| 329 |
INNODB_DD_TABLE("view_routine_usage", 2), |
| 330 |
INNODB_DD_TABLE("view_table_usage", 2)}; |
| 331 |
|
| 332 |
/** Number of hard-coded data dictionary tables */ |
| 333 |
static constexpr size_t innodb_dd_table_size = UT_ARR_SIZE(innodb_dd_table); |
| 334 |
|
| 335 |
/** @return total number of indexes of all DD Tables. */ |
| 336 |
uint32_t dd_get_total_indexes_num(); |
| 337 |
|
| 338 |
#endif /* UNIV_DEBUG */ |
| 339 |
|
| 340 |
#endif /* !UNIV_HOTBACKUP */ |
| 341 |
|
| 342 |
/** Class to decode or encode a stream of default value for instant table. |
| 343 |
The decode/encode are necessary because that the default values would b |
| 344 |
kept as InnoDB format stream, which is in fact byte stream. However, |
| 345 |
to store them in the DD se_private_data, it requires text(char). |
| 346 |
So basically, the encode will change the byte stream into char stream, |
| 347 |
by splitting every byte into two chars, for example, 0xFF, would be split |
| 348 |
into 0x0F and 0x0F. So the final storage space would be double. For the |
| 349 |
decode, it's the converse process, combining two chars into one byte. */ |
| 350 |
class DD_instant_col_val_coder { |
| 351 |
public: |
| 352 |
/** Constructor */ |
| 353 |
DD_instant_col_val_coder() : m_result(nullptr) {} |
| 354 |
|
| 355 |
/** Destructor */ |
| 356 |
~DD_instant_col_val_coder() { cleanup(); } |
| 357 |
|
| 358 |
/** Encode the specified stream in format of bytes into chars |
| 359 |
@param[in] stream stream to encode in bytes |
| 360 |
@param[in] in_len length of the stream |
| 361 |
@param[out] out_len length of the encoded stream |
| 362 |
@return the encoded stream, which would be destroyed if the class |
| 363 |
itself is destroyed */ |
| 364 |
const char *encode(const byte *stream, size_t in_len, size_t *out_len); |
| 365 |
|
| 366 |
/** Decode the specified stream, which is encoded by encode() |
| 367 |
@param[in] stream stream to decode in chars |
| 368 |
@param[in] in_len length of the stream |
| 369 |
@param[out] out_len length of the decoded stream |
| 370 |
@return the decoded stream, which would be destroyed if the class |
| 371 |
itself is destroyed */ |
| 372 |
const byte *decode(const char *stream, size_t in_len, size_t *out_len); |
| 373 |
|
| 374 |
private: |
| 375 |
/** Clean-up last result */ |
| 376 |
void cleanup() { ut::delete_arr(m_result); } |
| 377 |
|
| 378 |
private: |
| 379 |
/** The encoded or decoded stream */ |
| 380 |
byte *m_result; |
| 381 |
}; |
| 382 |
|
| 383 |
#ifndef UNIV_HOTBACKUP |
| 384 |
/** Determine if a dd::Partition is the first leaf partition in the table |
| 385 |
@param[in] dd_part dd::Partition |
| 386 |
@return True If it's the first partition |
| 387 |
@retval False Not the first one */ |
| 388 |
inline bool dd_part_is_first(const dd::Partition *dd_part) { |
| 389 |
return (dd_part == *(dd_part->table().leaf_partitions().begin())); |
| 390 |
} |
| 391 |
|
| 392 |
/** Determine if a dd::Table is partitioned table |
| 393 |
@param[in] table dd::Table |
| 394 |
@return True If partitioned table |
| 395 |
@retval False non-partitioned table */ |
| 396 |
inline bool dd_table_is_partitioned(const dd::Table &table) { |
| 397 |
return (table.partition_type() != dd::Table::PT_NONE); |
| 398 |
} |
| 399 |
|
| 400 |
#ifdef UNIV_DEBUG |
| 401 |
/** Check if the instant columns are consistent with the se_private_data |
| 402 |
in dd::Table |
| 403 |
@param[in] dd_table dd::Table |
| 404 |
@return true if consistent, otherwise false */ |
| 405 |
bool dd_instant_columns_consistent(const dd::Table &dd_table); |
| 406 |
#endif /* UNIV_DEBUG */ |
| 407 |
|
| 408 |
/** Scan through all the keys to identify the key parts which are |
| 409 |
greater than the maximum size supported by the table record format. |
| 410 |
@param table MySQL table definition. |
| 411 |
@param max_part_len Maximum index part length allowed. |
| 412 |
@param visitor Function wrapper to invoke lambda expression. |
| 413 |
*/ |
| 414 |
void dd_visit_keys_with_too_long_parts( |
| 415 |
const TABLE *table, const size_t max_part_len, |
| 416 |
std::function<void(const KEY &)> visitor); |
| 417 |
|
| 418 |
/** Determine if a dd::Table has any INSTANT ADD column(s) in V1 |
| 419 |
@param[in] table dd::Table |
| 420 |
@return true if table has instant column(s) in V1, false otherwise */ |
| 421 |
inline bool dd_table_is_upgraded_instant(const dd::Table &table) { |
| 422 |
if (table.is_temporary()) { |
| 423 |
return false; |
| 424 |
} |
| 425 |
|
| 426 |
return (table.se_private_data().exists( |
| 427 |
dd_table_key_strings[DD_TABLE_INSTANT_COLS])); |
| 428 |
} |
| 429 |
|
| 430 |
/** Determine if dd::Table has INSTANT ADD columns. |
| 431 |
@param[in] table table definition |
| 432 |
@return true if table has INSTANT ADD column(s), false otherwise */ |
| 433 |
inline bool dd_table_has_instant_add_cols(const dd::Table &table) { |
| 434 |
if (table.is_temporary()) { |
| 435 |
return false; |
| 436 |
} |
| 437 |
|
| 438 |
for (const auto column : table.columns()) { |
| 439 |
if (dd_column_is_added(column)) { |
| 440 |
return true; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
return false; |
| 445 |
} |
| 446 |
|
| 447 |
/** Determine if dd::Table has INSTANT DROPPED columns. |
| 448 |
@param[in] table table definition |
| 449 |
@return true if table has INSTANT DROP column(s), false otherwise */ |
| 450 |
inline bool dd_table_has_instant_drop_cols(const dd::Table &table) { |
| 451 |
if (table.is_temporary()) { |
| 452 |
return false; |
| 453 |
} |
| 454 |
|
| 455 |
for (const auto column : table.columns()) { |
| 456 |
if (dd_column_is_dropped(column)) { |
| 457 |
return true; |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
return false; |
| 462 |
} |
| 463 |
|
| 464 |
static inline bool is_system_column(const char *col_name) { |
| 465 |
ut_ad(col_name != nullptr); |
| 466 |
return (strncmp(col_name, "DB_ROW_ID", 9) == 0 || |
| 467 |
strncmp(col_name, "DB_TRX_ID", 9) == 0 || |
| 468 |
strncmp(col_name, "DB_ROLL_PTR", 11) == 0); |
| 469 |
} |
| 470 |
|
| 471 |
/** Set different column counters. |
| 472 |
@param[in] table dd::Table |
| 473 |
@param[out] i_c initial column count |
| 474 |
@param[out] c_c current column count |
| 475 |
@param[out] t_c total column count |
| 476 |
@param[in] current_row_version current row version */ |
| 477 |
inline void dd_table_get_column_counters(const dd::Table &table, uint32_t &i_c, |
| 478 |
uint32_t &c_c, uint32_t &t_c, |
| 479 |
uint32_t ¤t_row_version) { |
| 480 |
size_t n_dropped_cols = 0; |
| 481 |
size_t n_added_cols = 0; |
| 482 |
size_t n_added_and_dropped_cols = 0; |
| 483 |
size_t n_current_cols = 0; |
| 484 |
|
| 485 |
for (const auto column : table.columns()) { |
| 486 |
if (is_system_column(column->name().c_str()) || column->is_virtual()) { |
| 487 |
continue; |
| 488 |
} |
| 489 |
|
| 490 |
if (dd_column_is_dropped(column)) { |
| 491 |
n_dropped_cols++; |
| 492 |
if (dd_column_is_added(column)) { |
| 493 |
n_added_and_dropped_cols++; |
| 494 |
} |
| 495 |
|
| 496 |
uint32_t v_dropped = dd_column_get_version_dropped(column); |
| 497 |
ut_ad(dd_is_valid_row_version(v_dropped)); |
| 498 |
current_row_version = std::max(current_row_version, v_dropped); |
| 499 |
|
| 500 |
continue; |
| 501 |
} |
| 502 |
|
| 503 |
if (dd_column_is_added(column)) { |
| 504 |
n_added_cols++; |
| 505 |
|
| 506 |
uint32_t v_added = dd_column_get_version_added(column); |
| 507 |
ut_ad(dd_is_valid_row_version(v_added)); |
| 508 |
current_row_version = std::max(current_row_version, v_added); |
| 509 |
} |
| 510 |
|
| 511 |
n_current_cols++; |
| 512 |
} |
| 513 |
|
| 514 |
ut_ad(n_dropped_cols >= n_added_and_dropped_cols); |
| 515 |
size_t n_orig_dropped_cols = n_dropped_cols - n_added_and_dropped_cols; |
| 516 |
c_c = n_current_cols; |
| 517 |
i_c = (n_current_cols - n_added_cols) + n_orig_dropped_cols; |
| 518 |
t_c = n_current_cols + n_dropped_cols; |
| 519 |
} |
| 520 |
|
| 521 |
/** Determine if a dd::Table has row versions |
| 522 |
@param[in] table dd::Table |
| 523 |
@return true if table has row versions, false otherwise */ |
| 524 |
inline bool dd_table_has_row_versions(const dd::Table &table) { |
| 525 |
if (table.is_temporary()) { |
| 526 |
return false; |
| 527 |
} |
| 528 |
|
| 529 |
bool has_row_version = false; |
| 530 |
for (const auto column : table.columns()) { |
| 531 |
if (column->is_virtual()) { |
| 532 |
continue; |
| 533 |
} |
| 534 |
|
| 535 |
/* Phy_pos metadata is populated for columns which belongs to table having |
| 536 |
row versions. Check if non virtual column has it. */ |
| 537 |
if (column->se_private_data().exists( |
| 538 |
dd_column_key_strings[DD_INSTANT_PHYSICAL_POS])) { |
| 539 |
has_row_version = true; |
| 540 |
} |
| 541 |
|
| 542 |
/* Checking only for one column is enough. */ |
| 543 |
break; |
| 544 |
} |
| 545 |
|
| 546 |
#ifdef UNIV_DEBUG |
| 547 |
if (has_row_version) { |
| 548 |
bool found_inst_add_or_drop_col = false; |
| 549 |
for (const auto column : table.columns()) { |
| 550 |
if (dd_column_is_dropped(column) || dd_column_is_added(column)) { |
| 551 |
found_inst_add_or_drop_col = true; |
| 552 |
break; |
| 553 |
} |
| 554 |
} |
| 555 |
ut_ad(found_inst_add_or_drop_col); |
| 556 |
} |
| 557 |
#endif |
| 558 |
|
| 559 |
return has_row_version; |
| 560 |
} |
| 561 |
|
| 562 |
/** Determine if a dd::Table has any INSTANTly ADDed/DROPped column |
| 563 |
@param[in] table dd::Table |
| 564 |
@return true if table has instant column(s), false otherwise */ |
| 565 |
inline bool dd_table_has_instant_cols(const dd::Table &table) { |
| 566 |
if (table.is_temporary()) { |
| 567 |
return false; |
| 568 |
} |
| 569 |
|
| 570 |
bool instant_v1 = dd_table_is_upgraded_instant(table); |
| 571 |
bool instant_v2 = dd_table_has_row_versions(table); |
| 572 |
|
| 573 |
bool instant = instant_v1 || instant_v2; |
| 574 |
|
| 575 |
/* If table has instant columns, make sure they are consistent with DD */ |
| 576 |
ut_ad(!instant || dd_instant_columns_consistent(table)); |
| 577 |
|
| 578 |
return (instant); |
| 579 |
} |
| 580 |
|
| 581 |
/** Determine if a dd::Partition has any instant column |
| 582 |
@param[in] part dd::Partition |
| 583 |
@return true If it's a partitioned table with instant columns |
| 584 |
@return false Not a partitioned table with instant columns */ |
| 585 |
inline bool dd_part_has_instant_cols(const dd::Partition &part) { |
| 586 |
bool instant = part.se_private_data().exists( |
| 587 |
dd_partition_key_strings[DD_PARTITION_INSTANT_COLS]); |
| 588 |
ut_ad(!instant || dd_table_has_instant_cols(part.table())); |
| 589 |
|
| 590 |
return (instant); |
| 591 |
} |
| 592 |
|
| 593 |
/** Determine if any partition of the table still has instant columns |
| 594 |
@param[in] table dd::Table of the partitioned table |
| 595 |
@return true If any partition still has instant columns |
| 596 |
@return false No one has instant columns */ |
| 597 |
inline bool dd_table_part_has_instant_cols(const dd::Table &table) { |
| 598 |
ut_ad(dd_table_is_partitioned(table)); |
| 599 |
|
| 600 |
/* For table having INSTANT ADD cols in v1, will have partition specific |
| 601 |
INSTANT Metadata. */ |
| 602 |
if (dd_table_is_upgraded_instant(table)) { |
| 603 |
for (auto part : table.leaf_partitions()) { |
| 604 |
if (dd_part_has_instant_cols(*part)) { |
| 605 |
return (true); |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
return (false); |
| 611 |
} |
| 612 |
|
| 613 |
/** Determine if dd::Table is discarded. Please note that |
| 614 |
in case of partitioned Table, only it's leaf partitions can be marked |
| 615 |
as discarded. However, it's fine to call this function on partitioned |
| 616 |
Table - it will just return false |
| 617 |
|
| 618 |
@param[in] table non-partitioned dd::Table |
| 619 |
@return true if table is marked as discarded |
| 620 |
@return false if table is not marked as discarded */ |
| 621 |
inline bool dd_is_discarded(const dd::Table &table) { |
| 622 |
const dd::Properties &table_private = table.se_private_data(); |
| 623 |
bool is_discarded = false; |
| 624 |
if (table_private.exists(dd_table_key_strings[DD_TABLE_DISCARD])) { |
| 625 |
table_private.get(dd_table_key_strings[DD_TABLE_DISCARD], &is_discarded); |
| 626 |
} |
| 627 |
|
| 628 |
/* In case of partitioned tables, only partitions/subpartitions can ever |
| 629 |
be marked as discarded */ |
| 630 |
ut_ad(!is_discarded || !dd_table_is_partitioned(table)); |
| 631 |
|
| 632 |
return is_discarded; |
| 633 |
} |
| 634 |
|
| 635 |
/** Determine if dd::Partition is discarded. Please note that |
| 636 |
only leaf partitions can be marked as discarded (that is, if partition has |
| 637 |
subpartitions, then only subpartitions can be marked as discarded) |
| 638 |
|
| 639 |
Function can be safely called on a partition, even if it has subpartitions - |
| 640 |
it will just return false. |
| 641 |
|
| 642 |
@param[in] partition dd::Partition |
| 643 |
@return true if partition is marked as discarded |
| 644 |
@return false if partition is not marked as discarded */ |
| 645 |
inline bool dd_is_discarded(const dd::Partition &partition) { |
| 646 |
const dd::Properties &partition_private = partition.se_private_data(); |
| 647 |
bool is_discarded = false; |
| 648 |
if (partition_private.exists( |
| 649 |
dd_partition_key_strings[DD_PARTITION_DISCARD])) { |
| 650 |
partition_private.get(dd_partition_key_strings[DD_PARTITION_DISCARD], |
| 651 |
&is_discarded); |
| 652 |
} |
| 653 |
|
| 654 |
return is_discarded; |
| 655 |
} |
| 656 |
|
| 657 |
/** Sets appropriate discard attribute of dd::Table |
| 658 |
Please note that this function must not be called on partitioned tables |
| 659 |
@param[in] table non-partitioned dd::Table |
| 660 |
@param[in] discard true if Table is discarded, false otherwise */ |
| 661 |
void dd_set_discarded(dd::Table &table, bool discard); |
| 662 |
|
| 663 |
/** Sets appropriate discard attribute of dd::Partition |
| 664 |
Please note that this function can be only called on leaf_partitions. |
| 665 |
@param[in] partition leaf dd::Partition |
| 666 |
@param[in] discard true if Table is discarded, false otherwise */ |
| 667 |
void dd_set_discarded(dd::Partition &partition, bool discard); |
| 668 |
|
| 669 |
/** Get the first index of a table or partition. |
| 670 |
@tparam Table dd::Table or dd::Partition |
| 671 |
@tparam Index dd::Index or dd::Partition_index |
| 672 |
@param[in] table table containing user columns and indexes |
| 673 |
@return the first index |
| 674 |
@retval NULL if there are no indexes */ |
| 675 |
template <typename Table, typename Index> |
| 676 |
inline const Index *dd_first(const Table *table) { |
| 677 |
return (*table->indexes().begin()); |
| 678 |
} |
| 679 |
|
| 680 |
/** Get the first index of a table. |
| 681 |
@param[in] table table containing user columns and indexes |
| 682 |
@return the first index |
| 683 |
@retval NULL if there are no indexes */ |
| 684 |
inline const dd::Index *dd_first_index(const dd::Table *table) { |
| 685 |
return (dd_first<dd::Table, dd::Index>(table)); |
| 686 |
} |
| 687 |
|
| 688 |
/** Get the first index of a partition. |
| 689 |
@param[in] partition partition or subpartition |
| 690 |
@return the first index |
| 691 |
@retval NULL if there are no indexes */ |
| 692 |
inline const dd::Partition_index *dd_first_index( |
| 693 |
const dd::Partition *partition) { |
| 694 |
return (dd_first<dd::Partition, dd::Partition_index>(partition)); |
| 695 |
} |
| 696 |
|
| 697 |
#ifdef UNIV_DEBUG |
| 698 |
/** Determine if a partition is materialized. |
| 699 |
@param[in] part partition |
| 700 |
@return whether the partition is materialized */ |
| 701 |
inline bool dd_part_is_stored(const dd::Partition *part) { |
| 702 |
return (part->table().subpartition_type() == dd::Table::ST_NONE || |
| 703 |
part->parent()); |
| 704 |
} |
| 705 |
#endif /* UNIV_DEBUG */ |
| 706 |
|
| 707 |
/** Get the explicit dd::Tablespace::id of a table. |
| 708 |
@param[in] table non-partitioned table |
| 709 |
@return the explicit dd::Tablespace::id |
| 710 |
@retval dd::INVALID_OBJECT_ID if there is no explicit tablespace */ |
| 711 |
inline dd::Object_id dd_get_space_id(const dd::Table &table) { |
| 712 |
ut_ad(!dd_table_is_partitioned(table)); |
| 713 |
return (table.tablespace_id()); |
| 714 |
} |
| 715 |
|
| 716 |
/** Get the explicit dd::Tablespace::id of a partition. |
| 717 |
@param[in] partition partition or subpartition |
| 718 |
@return the explicit dd::Tablespace::id |
| 719 |
@retval dd::INVALID_OBJECT_ID if there is no explicit tablespace */ |
| 720 |
inline dd::Object_id dd_get_space_id(const dd::Partition &partition); |
| 721 |
|
| 722 |
/** Set the AUTO_INCREMENT attribute. |
| 723 |
@param[in,out] se_private_data dd::Table::se_private_data |
| 724 |
@param[in] autoinc the auto-increment value */ |
| 725 |
void dd_set_autoinc(dd::Properties &se_private_data, uint64_t autoinc); |
| 726 |
|
| 727 |
/** Get the version attribute. |
| 728 |
@param[in] dd_table dd::Table |
| 729 |
@return table dynamic metadata version if exists, otherwise 0 */ |
| 730 |
inline uint64_t dd_get_version(const dd::Table *dd_table); |
| 731 |
|
| 732 |
/** Copy the AUTO_INCREMENT and version attribute if exist. |
| 733 |
@param[in] src dd::Table::se_private_data to copy from |
| 734 |
@param[out] dest dd::Table::se_private_data to copy to */ |
| 735 |
void dd_copy_autoinc(const dd::Properties &src, dd::Properties &dest); |
| 736 |
|
| 737 |
/** Copy the metadata of a table definition if there was an instant |
| 738 |
ADD COLUMN happened. This should be done when it's not an ALTER TABLE |
| 739 |
with rebuild. |
| 740 |
@param[in,out] new_table New table definition |
| 741 |
@param[in] old_table Old table definition */ |
| 742 |
void dd_copy_instant_n_cols(dd::Table &new_table, const dd::Table &old_table); |
| 743 |
|
| 744 |
/** Copy the engine-private parts of a table or partition definition |
| 745 |
when the change does not affect InnoDB. This mainly copies the common |
| 746 |
private data between dd::Table and dd::Partition |
| 747 |
@tparam Table dd::Table or dd::Partition |
| 748 |
@param[in,out] new_table Copy of old table or partition |
| 749 |
definition |
| 750 |
@param[in] old_table Old table or partition definition */ |
| 751 |
template <typename Table> |
| 752 |
void dd_copy_private(Table &new_table, const Table &old_table); |
| 753 |
|
| 754 |
/** Copy the engine-private parts of column definitions of a table |
| 755 |
@param[in] ha_alter_info alter info |
| 756 |
@param[in,out] new_table Copy of old table |
| 757 |
@param[in] old_table Old table |
| 758 |
@param[in] dict_table InnoDB table cache */ |
| 759 |
void dd_copy_table_columns(const Alter_inplace_info *ha_alter_info, |
| 760 |
dd::Table &new_table, const dd::Table &old_table, |
| 761 |
dict_table_t *dict_table); |
| 762 |
|
| 763 |
/** Copy the metadata of a table definition, including the INSTANT |
| 764 |
ADD COLUMN information. This should be done when it's not an ALTER TABLE |
| 765 |
with rebuild. Basically, check dd::Table::se_private_data and |
| 766 |
dd::Column::se_private_data. |
| 767 |
@param[in] ha_alter_info alter info |
| 768 |
@param[in,out] new_table Copy of old table definition |
| 769 |
@param[in] old_table Old table definition */ |
| 770 |
inline void dd_copy_table(const Alter_inplace_info *ha_alter_info, |
| 771 |
dd::Table &new_table, const dd::Table &old_table) { |
| 772 |
/* Copy columns first, to make checking in dd_copy_instant_n_cols pass */ |
| 773 |
dd_copy_table_columns(ha_alter_info, new_table, old_table, nullptr); |
| 774 |
if (dd_table_is_upgraded_instant(old_table)) { |
| 775 |
dd_copy_instant_n_cols(new_table, old_table); |
| 776 |
} |
| 777 |
} |
| 778 |
|
| 779 |
/** Adjust TABLE_ID for partitioned table after ALTER TABLE ... PARTITION. |
| 780 |
This makes sure that the TABLE_ID stored in dd::Column::se_private_data |
| 781 |
is correct if the first partition got changed |
| 782 |
@param[in,out] new_table New dd::Table */ |
| 783 |
void dd_part_adjust_table_id(dd::Table *new_table); |
| 784 |
|
| 785 |
using Columns = std::vector<Field *>; |
| 786 |
|
| 787 |
/** Drop column instantly. It actually updates dropped columns metadata. |
| 788 |
@param[in] old_dd_table Old dd::Table |
| 789 |
@param[in,out] new_dd_table New dd::Table |
| 790 |
@param[in,out] new_table New InnoDB table objecta |
| 791 |
@param[in] cols_to_drop list of columns to be dropped |
| 792 |
@param[in] cols_to_add list of columns to be added |
| 793 |
@param[in] ha_alter_info alter info |
| 794 |
@retval true Failure |
| 795 |
@retval false Success */ |
| 796 |
bool dd_drop_instant_columns(const dd::Table *old_dd_table, |
| 797 |
dd::Table *new_dd_table, dict_table_t *new_table, |
| 798 |
const Columns &cols_to_drop |
| 799 |
IF_DEBUG(, const Columns &cols_to_add, |
| 800 |
Alter_inplace_info *ha_alter_info)); |
| 801 |
|
| 802 |
/** Add column default values for new instantly added columns |
| 803 |
@param[in] old_dd_table Old dd::Table |
| 804 |
@param[in,out] new_dd_table New dd::Table |
| 805 |
@param[in,out] new_table New InnoDB table object |
| 806 |
@param[in] cols_to_add columns to be added INSTANTly |
| 807 |
@retval true Failure |
| 808 |
@retval false Success */ |
| 809 |
bool dd_add_instant_columns(const dd::Table *old_dd_table, |
| 810 |
dd::Table *new_dd_table, dict_table_t *new_table, |
| 811 |
const Columns &cols_to_add); |
| 812 |
|
| 813 |
/** Clear the instant ADD COLUMN information of a table |
| 814 |
@param[in,out] dd_table dd::Table |
| 815 |
@param[in] clear_version true if version metadata is to be cleared |
| 816 |
@return DB_SUCCESS or error code */ |
| 817 |
dberr_t dd_clear_instant_table(dd::Table &dd_table, bool clear_version); |
| 818 |
|
| 819 |
/** Clear the instant ADD COLUMN information of a partition, to make it |
| 820 |
as a normal partition |
| 821 |
@param[in,out] dd_part dd::Partition */ |
| 822 |
void dd_clear_instant_part(dd::Partition &dd_part); |
| 823 |
|
| 824 |
/** Compare the default values between imported column and column defined |
| 825 |
in the server. Note that it's absolutely OK if there is no default value |
| 826 |
in the column defined in server, since it can be filled in later. |
| 827 |
@param[in] dd_col dd::Column |
| 828 |
@param[in] col InnoDB column object |
| 829 |
@return true The default values match |
| 830 |
@retval false Not match */ |
| 831 |
bool dd_match_default_value(const dd::Column *dd_col, const dict_col_t *col); |
| 832 |
|
| 833 |
/** Write default value of a column to dd::Column |
| 834 |
@param[in] col default value of this column to write |
| 835 |
@param[in,out] dd_col where to store the default value */ |
| 836 |
void dd_write_default_value(const dict_col_t *col, dd::Column *dd_col); |
| 837 |
|
| 838 |
/** Import all metadata which is related to instant ADD COLUMN of a table |
| 839 |
to dd::Table. This is used for IMPORT. |
| 840 |
@param[in] table InnoDB table object |
| 841 |
@param[in,out] dd_table dd::Table */ |
| 842 |
void dd_import_instant_add_columns(const dict_table_t *table, |
| 843 |
dd::Table *dd_table); |
| 844 |
|
| 845 |
/** Write metadata of a table to dd::Table |
| 846 |
@tparam Table dd::Table or dd::Partition |
| 847 |
@param[in] dd_space_id Tablespace id, which server allocates |
| 848 |
@param[in,out] dd_table dd::Table or dd::Partition |
| 849 |
@param[in] table InnoDB table object */ |
| 850 |
template <typename Table> |
| 851 |
void dd_write_table(dd::Object_id dd_space_id, Table *dd_table, |
| 852 |
const dict_table_t *table); |
| 853 |
|
| 854 |
/** Set options of dd::Table according to InnoDB table object |
| 855 |
@tparam Table dd::Table or dd::Partition |
| 856 |
@param[in,out] dd_table dd::Table or dd::Partition |
| 857 |
@param[in] table InnoDB table object */ |
| 858 |
template <typename Table> |
| 859 |
void dd_set_table_options(Table *dd_table, const dict_table_t *table); |
| 860 |
|
| 861 |
/** Update virtual columns with new se_private_data, currently, only |
| 862 |
table_id is set |
| 863 |
@param[in,out] dd_table dd::Table |
| 864 |
@param[in] id InnoDB table ID to set */ |
| 865 |
void dd_update_v_cols(dd::Table *dd_table, table_id_t id); |
| 866 |
|
| 867 |
/** Write metadata of a tablespace to dd::Tablespace |
| 868 |
@param[in,out] dd_space dd::Tablespace |
| 869 |
@param[in] space_id InnoDB tablespace ID |
| 870 |
@param[in] fsp_flags InnoDB tablespace flags |
| 871 |
@param[in] state InnoDB tablespace state */ |
| 872 |
void dd_write_tablespace(dd::Tablespace *dd_space, space_id_t space_id, |
| 873 |
uint32_t fsp_flags, dd_space_states state); |
| 874 |
|
| 875 |
/** Add fts doc id column and index to new table |
| 876 |
when old table has hidden fts doc id without fulltext index |
| 877 |
@param[in,out] new_table New dd table |
| 878 |
@param[in] old_table Old dd table */ |
| 879 |
void dd_add_fts_doc_id_index(dd::Table &new_table, const dd::Table &old_table); |
| 880 |
|
| 881 |
MY_COMPILER_DIAGNOSTIC_PUSH() |
| 882 |
MY_COMPILER_CLANG_WORKAROUND_TPARAM_DOCBUG() |
| 883 |
/** Find the specified dd::Index or dd::Partition_index in an InnoDB table |
| 884 |
@tparam Index dd::Index or dd::Partition_index |
| 885 |
@param[in] table InnoDB table object |
| 886 |
@param[in] dd_index Index to search |
| 887 |
@return the dict_index_t object related to the index */ |
| 888 |
template <typename Index> |
| 889 |
const dict_index_t *dd_find_index(const dict_table_t *table, Index *dd_index); |
| 890 |
MY_COMPILER_DIAGNOSTIC_POP() |
| 891 |
|
| 892 |
/** Acquire a shared metadata lock. |
| 893 |
@param[in,out] thd current thread |
| 894 |
@param[out] mdl metadata lock |
| 895 |
@param[in] db schema name |
| 896 |
@param[in] table table name |
| 897 |
@retval false if acquired, or trylock timed out |
| 898 |
@retval true if failed (my_error() will have been called) */ |
| 899 |
[[nodiscard]] static inline bool dd_mdl_acquire(THD *thd, MDL_ticket **mdl, |
| 900 |
const char *db, |
| 901 |
const char *table); |
| 902 |
|
| 903 |
/** Release a metadata lock. |
| 904 |
@param[in,out] thd current thread |
| 905 |
@param[in,out] mdl metadata lock */ |
| 906 |
void dd_mdl_release(THD *thd, MDL_ticket **mdl); |
| 907 |
|
| 908 |
/** Returns thd associated with the trx or current_thd |
| 909 |
@param[in] trx transaction |
| 910 |
@return trx->mysql_thd or current_thd */ |
| 911 |
THD *dd_thd_for_undo(const trx_t *trx); |
| 912 |
|
| 913 |
/** Check if current undo needs a MDL or not |
| 914 |
@param[in] trx transaction |
| 915 |
@return true if MDL is necessary, otherwise false */ |
| 916 |
bool dd_mdl_for_undo(const trx_t *trx); |
| 917 |
|
| 918 |
/** Load foreign key constraint info for the dd::Table object. |
| 919 |
@param[out] m_table InnoDB table handle |
| 920 |
@param[in] dd_table Global DD table |
| 921 |
@param[in] col_names column names, or NULL |
| 922 |
@param[in] ignore_err DICT_ERR_IGNORE_FK_NOKEY or DICT_ERR_IGNORE_NONE |
| 923 |
@param[in] dict_locked True if dict_sys->mutex is already held, |
| 924 |
otherwise false |
| 925 |
@return DB_SUCCESS if successfully load FK constraint */ |
| 926 |
dberr_t dd_table_load_fk_from_dd(dict_table_t *m_table, |
| 927 |
const dd::Table *dd_table, |
| 928 |
const char **col_names, |
| 929 |
dict_err_ignore_t ignore_err, |
| 930 |
bool dict_locked); |
| 931 |
|
| 932 |
/** Set the AUTO_INCREMENT attribute. |
| 933 |
@param[in,out] se_private_data dd::Table::se_private_data |
| 934 |
@param[in] autoinc the auto-increment value */ |
| 935 |
void dd_set_autoinc(dd::Properties &se_private_data, uint64_t autoinc); |
| 936 |
|
| 937 |
/** Scan a new dd system table, like mysql.tables... |
| 938 |
@param[in] thd THD |
| 939 |
@param[in,out] mdl MDL lock |
| 940 |
@param[in,out] pcur Persistent cursor |
| 941 |
@param[in,out] mtr Mini-transaction |
| 942 |
@param[in] system_table_name Which dd system table to open |
| 943 |
@param[in,out] table dict_table_t obj of dd system table |
| 944 |
@retval the first rec of the dd system table */ |
| 945 |
const rec_t *dd_startscan_system(THD *thd, MDL_ticket **mdl, btr_pcur_t *pcur, |
| 946 |
mtr_t *mtr, const char *system_table_name, |
| 947 |
dict_table_t **table); |
| 948 |
|
| 949 |
/** Process one mysql.tables record and get the dict_table_t |
| 950 |
@param[in] heap Temp memory heap |
| 951 |
@param[in,out] rec mysql.tables record |
| 952 |
@param[in,out] table dict_table_t to fill |
| 953 |
@param[in] dd_tables dict_table_t obj of dd system table |
| 954 |
@param[in] mdl MDL on the table |
| 955 |
@param[in] mtr Mini-transaction |
| 956 |
@retval error message, or NULL on success */ |
| 957 |
const char *dd_process_dd_tables_rec_and_mtr_commit( |
| 958 |
mem_heap_t *heap, const rec_t *rec, dict_table_t **table, |
| 959 |
dict_table_t *dd_tables, MDL_ticket **mdl, mtr_t *mtr); |
| 960 |
/** Process one mysql.table_partitions record and get the dict_table_t |
| 961 |
@param[in] heap Temp memory heap |
| 962 |
@param[in,out] rec mysql.table_partitions record |
| 963 |
@param[in,out] table dict_table_t to fill |
| 964 |
@param[in] dd_tables dict_table_t obj of dd partition table |
| 965 |
@param[in] mdl MDL on the table |
| 966 |
@param[in] mtr Mini-transaction |
| 967 |
@retval error message, or NULL on success */ |
| 968 |
const char *dd_process_dd_partitions_rec_and_mtr_commit( |
| 969 |
mem_heap_t *heap, const rec_t *rec, dict_table_t **table, |
| 970 |
dict_table_t *dd_tables, MDL_ticket **mdl, mtr_t *mtr); |
| 971 |
|
| 972 |
/** Process one mysql.columns record and get info to dict_col_t |
| 973 |
@param[in,out] heap Temp memory heap |
| 974 |
@param[in] rec mysql.columns record |
| 975 |
@param[in,out] col dict_col_t to fill |
| 976 |
@param[in,out] table_id Table id |
| 977 |
@param[in,out] col_name Column name |
| 978 |
@param[in,out] nth_v_col Nth v column |
| 979 |
@param[in] dd_columns dict_table_t obj of mysql.columns |
| 980 |
@param[in,out] mtr Mini-transaction |
| 981 |
@retval true if column is filled */ |
| 982 |
bool dd_process_dd_columns_rec(mem_heap_t *heap, const rec_t *rec, |
| 983 |
dict_col_t *col, table_id_t *table_id, |
| 984 |
char **col_name, ulint *nth_v_col, |
| 985 |
const dict_table_t *dd_columns, mtr_t *mtr); |
| 986 |
|
| 987 |
/** Process one mysql.columns record for virtual columns |
| 988 |
@param[in] heap temp memory heap |
| 989 |
@param[in,out] rec mysql.columns record |
| 990 |
@param[in,out] table_id Table id |
| 991 |
@param[in,out] pos Position |
| 992 |
@param[in,out] base_pos Base column position |
| 993 |
@param[in,out] n_row Number of rows |
| 994 |
@param[in] dd_columns dict_table_t obj of mysql.columns |
| 995 |
@param[in] mtr Mini-transaction |
| 996 |
@retval true if virtual info is filled */ |
| 997 |
bool dd_process_dd_virtual_columns_rec(mem_heap_t *heap, const rec_t *rec, |
| 998 |
table_id_t *table_id, ulint **pos, |
| 999 |
ulint **base_pos, ulint *n_row, |
| 1000 |
dict_table_t *dd_columns, mtr_t *mtr); |
| 1001 |
|
| 1002 |
/** Get next record of new DD system tables |
| 1003 |
@param[in,out] pcur Persistent cursor |
| 1004 |
@param[in] mtr Mini-transaction |
| 1005 |
@retval next record */ |
| 1006 |
const rec_t *dd_getnext_system_rec(btr_pcur_t *pcur, mtr_t *mtr); |
| 1007 |
|
| 1008 |
/** Process one mysql.indexes record and get the dict_index_t |
| 1009 |
@param[in] heap Temp memory heap |
| 1010 |
@param[in,out] rec mysql.indexes record |
| 1011 |
@param[in,out] index dict_index_t to fill |
| 1012 |
@param[in] mdl MDL on index->table |
| 1013 |
@param[in,out] parent Parent table if it's fts aux table. |
| 1014 |
@param[in,out] parent_mdl MDL on parent if it's fts aux table. |
| 1015 |
@param[in] dd_indexes dict_table_t obj of mysql.indexes |
| 1016 |
@param[in] mtr Mini-transaction |
| 1017 |
@retval true if index is filled */ |
| 1018 |
bool dd_process_dd_indexes_rec(mem_heap_t *heap, const rec_t *rec, |
| 1019 |
const dict_index_t **index, MDL_ticket **mdl, |
| 1020 |
dict_table_t **parent, MDL_ticket **parent_mdl, |
| 1021 |
dict_table_t *dd_indexes, mtr_t *mtr); |
| 1022 |
|
| 1023 |
/** Process one mysql.indexes record and get brief info to dict_index_t |
| 1024 |
@param[in] heap temp memory heap |
| 1025 |
@param[in,out] rec mysql.indexes record |
| 1026 |
@param[in,out] index_id index id |
| 1027 |
@param[in,out] space_id space id |
| 1028 |
@param[in] dd_indexes dict_table_t obj of mysql.indexes |
| 1029 |
@retval true if index is filled */ |
| 1030 |
bool dd_process_dd_indexes_rec_simple(mem_heap_t *heap, const rec_t *rec, |
| 1031 |
space_index_t *index_id, |
| 1032 |
space_id_t *space_id, |
| 1033 |
dict_table_t *dd_indexes); |
| 1034 |
|
| 1035 |
/** Process one mysql.tablespaces record and get info |
| 1036 |
@param[in] heap temp memory heap |
| 1037 |
@param[in] rec mysql.tablespaces record |
| 1038 |
@param[out] space_id space id |
| 1039 |
@param[out] name space name |
| 1040 |
@param[out] flags space flags |
| 1041 |
@param[out] server_version server version |
| 1042 |
@param[out] space_version space version |
| 1043 |
@param[out] is_encrypted true if tablespace is encrypted |
| 1044 |
@param[out] autoextend_size autoextend_size attribute value |
| 1045 |
@param[out] state space state |
| 1046 |
@param[in] dd_spaces dict_table_t obj of mysql.tablespaces |
| 1047 |
@return true if data is retrieved */ |
| 1048 |
bool dd_process_dd_tablespaces_rec(mem_heap_t *heap, const rec_t *rec, |
| 1049 |
space_id_t *space_id, char **name, |
| 1050 |
uint32_t *flags, uint32_t *server_version, |
| 1051 |
uint32_t *space_version, bool *is_encrypted, |
| 1052 |
uint64_t *autoextend_size, |
| 1053 |
dd::String_type *state, |
| 1054 |
dict_table_t *dd_spaces); |
| 1055 |
|
| 1056 |
/** Make sure the data_dir_path is saved in dict_table_t if DATA DIRECTORY |
| 1057 |
was used. Try to read it from the fil_system first, then from new dd. |
| 1058 |
@tparam Table dd::Table or dd::Partition |
| 1059 |
@param[in,out] table Table object |
| 1060 |
@param[in] dd_table DD table object |
| 1061 |
@param[in] dict_mutex_own true if dict_sys->mutex is owned already */ |
| 1062 |
template <typename Table> |
| 1063 |
void dd_get_and_save_data_dir_path(dict_table_t *table, const Table *dd_table, |
| 1064 |
bool dict_mutex_own); |
| 1065 |
|
| 1066 |
/** Make sure the tablespace name is saved in dict_table_t if the table |
| 1067 |
uses a general tablespace. |
| 1068 |
Try to read it from the fil_system_t first, then from DD. |
| 1069 |
@param[in] table Table object |
| 1070 |
@param[in] dd_table Global DD table or partition object |
| 1071 |
@param[in] dict_mutex_own true if dict_sys->mutex is owned already */ |
| 1072 |
template <typename Table> |
| 1073 |
void dd_get_and_save_space_name(dict_table_t *table, const Table *dd_table, |
| 1074 |
bool dict_mutex_own); |
| 1075 |
|
| 1076 |
/** Get the meta-data filename from the table name for a |
| 1077 |
single-table tablespace. |
| 1078 |
@param[in,out] table table object |
| 1079 |
@param[in] dd_table DD table object |
| 1080 |
@param[out] filename filename |
| 1081 |
@param[in] max_len filename max length */ |
| 1082 |
void dd_get_meta_data_filename(dict_table_t *table, dd::Table *dd_table, |
| 1083 |
char *filename, ulint max_len); |
| 1084 |
|
| 1085 |
/** Load foreign key constraint for the table. Note, it could also open |
| 1086 |
the foreign table, if this table is referenced by the foreign table |
| 1087 |
@param[in,out] client data dictionary client |
| 1088 |
@param[in] tbl_name Table Name |
| 1089 |
@param[in] col_names column names, or NULL |
| 1090 |
@param[out] m_table InnoDB table handle |
| 1091 |
@param[in] dd_table Global DD table |
| 1092 |
@param[in] thd thread THD |
| 1093 |
@param[in] dict_locked True if dict_sys->mutex is already held, |
| 1094 |
otherwise false |
| 1095 |
@param[in] check_charsets whether to check charset compatibility |
| 1096 |
@param[in,out] fk_tables name list for tables that refer to this table |
| 1097 |
@return DB_SUCCESS if successfully load FK constraint */ |
| 1098 |
dberr_t dd_table_load_fk(dd::cache::Dictionary_client *client, |
| 1099 |
const char *tbl_name, const char **col_names, |
| 1100 |
dict_table_t *m_table, const dd::Table *dd_table, |
| 1101 |
THD *thd, bool dict_locked, bool check_charsets, |
| 1102 |
dict_names_t *fk_tables); |
| 1103 |
|
| 1104 |
/** Load foreign key constraint for the table. Note, it could also open |
| 1105 |
the foreign table, if this table is referenced by the foreign table |
| 1106 |
@param[in,out] client data dictionary client |
| 1107 |
@param[in] tbl_name Table Name |
| 1108 |
@param[in] col_names column names, or NULL |
| 1109 |
@param[out] m_table InnoDB table handle |
| 1110 |
@param[in] check_charsets whether to check charset compatibility |
| 1111 |
@param[in] ignore_err DICT_ERR_IGNORE_FK_NOKEY or DICT_ERR_IGNORE_NONE |
| 1112 |
@param[in,out] fk_tables name list for tables that refer to this table |
| 1113 |
@return DB_SUCCESS if successfully load FK constraint */ |
| 1114 |
dberr_t dd_table_check_for_child(dd::cache::Dictionary_client *client, |
| 1115 |
const char *tbl_name, const char **col_names, |
| 1116 |
dict_table_t *m_table, bool check_charsets, |
| 1117 |
dict_err_ignore_t ignore_err, |
| 1118 |
dict_names_t *fk_tables); |
| 1119 |
|
| 1120 |
/** Open uncached table definition based on a Global DD object. |
| 1121 |
@param[in] thd thread THD |
| 1122 |
@param[in] client data dictionary client |
| 1123 |
@param[in] dd_table Global DD table object |
| 1124 |
@param[in] name Table Name |
| 1125 |
@param[out] ts MySQL table share |
| 1126 |
@param[out] td MySQL table definition |
| 1127 |
@retval error number on error |
| 1128 |
@retval 0 on success */ |
| 1129 |
|
| 1130 |
int acquire_uncached_table(THD *thd, dd::cache::Dictionary_client *client, |
| 1131 |
const dd::Table *dd_table, const char *name, |
| 1132 |
TABLE_SHARE *ts, TABLE *td); |
| 1133 |
|
| 1134 |
/** free uncached table definition. |
| 1135 |
@param[in] ts MySQL table share |
| 1136 |
@param[in] td MySQL table definition */ |
| 1137 |
|
| 1138 |
void release_uncached_table(TABLE_SHARE *ts, TABLE *td); |
| 1139 |
|
| 1140 |
/** Instantiate an InnoDB in-memory table metadata (dict_table_t) |
| 1141 |
based on a Global DD object or MYSQL table definition. |
| 1142 |
@param[in] thd thread THD |
| 1143 |
@param[in,out] client data dictionary client |
| 1144 |
@param[in] dd_table Global DD table object |
| 1145 |
@param[in] dd_part Global DD partition or subpartition, or NULL |
| 1146 |
@param[in] tbl_name table name, or NULL if not known |
| 1147 |
@param[out] table InnoDB table (NULL if not found or loadable) |
| 1148 |
@param[in] td MYSQL table definition |
| 1149 |
@return error code |
| 1150 |
@retval 0 on success */ |
| 1151 |
int dd_table_open_on_dd_obj(THD *thd, dd::cache::Dictionary_client *client, |
| 1152 |
const dd::Table &dd_table, |
| 1153 |
const dd::Partition *dd_part, const char *tbl_name, |
| 1154 |
dict_table_t *&table, const TABLE *td); |
| 1155 |
|
| 1156 |
#endif /* !UNIV_HOTBACKUP */ |
| 1157 |
|
| 1158 |
/** Open a persistent InnoDB table based on InnoDB table id, and |
| 1159 |
hold Shared MDL lock on it. |
| 1160 |
@param[in] table_id table identifier |
| 1161 |
@param[in,out] thd current MySQL connection (for mdl) |
| 1162 |
@param[in,out] mdl metadata lock (*mdl set if |
| 1163 |
table_id was found) mdl=NULL if we are resurrecting table IX locks in recovery |
| 1164 |
@param[in] dict_locked dict_sys mutex is held |
| 1165 |
@param[in] check_corruption check if the table is corrupted or not. |
| 1166 |
@return table |
| 1167 |
@retval NULL if the table does not exist or cannot be opened */ |
| 1168 |
dict_table_t *dd_table_open_on_id(table_id_t table_id, THD *thd, |
| 1169 |
MDL_ticket **mdl, bool dict_locked, |
| 1170 |
bool check_corruption); |
| 1171 |
|
| 1172 |
/** Close an internal InnoDB table handle. |
| 1173 |
@param[in,out] table InnoDB table handle |
| 1174 |
@param[in,out] thd current MySQL connection (for mdl) |
| 1175 |
@param[in,out] mdl metadata lock (will be set NULL) |
| 1176 |
@param[in] dict_locked whether we hold dict_sys mutex */ |
| 1177 |
void dd_table_close(dict_table_t *table, THD *thd, MDL_ticket **mdl, |
| 1178 |
bool dict_locked); |
| 1179 |
|
| 1180 |
#ifndef UNIV_HOTBACKUP |
| 1181 |
/** Set the discard flag for a non-partitioned dd table. |
| 1182 |
@param[in,out] thd current thread |
| 1183 |
@param[in] table InnoDB table |
| 1184 |
@param[in,out] table_def MySQL dd::Table to update |
| 1185 |
@param[in] discard discard flag |
| 1186 |
@return true if success |
| 1187 |
@retval false if fail. */ |
| 1188 |
bool dd_table_discard_tablespace(THD *thd, const dict_table_t *table, |
| 1189 |
dd::Table *table_def, bool discard); |
| 1190 |
|
| 1191 |
/** Open an internal handle to a persistent InnoDB table by name. |
| 1192 |
@param[in,out] thd current thread |
| 1193 |
@param[out] mdl metadata lock |
| 1194 |
@param[in] name InnoDB table name |
| 1195 |
@param[in] dict_locked has dict_sys mutex locked |
| 1196 |
@param[in] ignore_err whether to ignore err |
| 1197 |
@param[out] error pointer to error |
| 1198 |
@return handle to non-partitioned table |
| 1199 |
@retval NULL if the table does not exist */ |
| 1200 |
dict_table_t *dd_table_open_on_name(THD *thd, MDL_ticket **mdl, |
| 1201 |
const char *name, bool dict_locked, |
| 1202 |
ulint ignore_err, int *error = nullptr); |
| 1203 |
|
| 1204 |
/** Returns a cached table object based on table id. |
| 1205 |
This function does NOT move the table to the front of MRU, because currently it |
| 1206 |
is called in contexts where we don't really mean to "use" the table, and believe |
| 1207 |
that it would actually hurt performance if we moved it to the front, such as: |
| 1208 |
1. The table would be evicted soon anyway. |
| 1209 |
2. A batch of FTS tables would be opened from background thread, |
| 1210 |
and it is not proper to move these tables to mru. |
| 1211 |
3. All tables in memory will be accessed sequentially, so it is useless to move. |
| 1212 |
@param[in] table_id table id |
| 1213 |
@param[in] dict_locked true=data dictionary locked |
| 1214 |
@return table, NULL if does not exist */ |
| 1215 |
static inline dict_table_t *dd_table_open_on_id_in_mem(table_id_t table_id, |
| 1216 |
bool dict_locked); |
| 1217 |
|
| 1218 |
/** Returns a cached table object based on table name. |
| 1219 |
@param[in] name table name |
| 1220 |
@param[in] dict_locked true=data dictionary locked |
| 1221 |
@return table, NULL if does not exist */ |
| 1222 |
static inline dict_table_t *dd_table_open_on_name_in_mem(const char *name, |
| 1223 |
bool dict_locked); |
| 1224 |
|
| 1225 |
MY_COMPILER_DIAGNOSTIC_PUSH() |
| 1226 |
MY_COMPILER_CLANG_WORKAROUND_TPARAM_DOCBUG() |
| 1227 |
/** Open or load a table definition based on a Global DD object. |
| 1228 |
@tparam Table dd::Table or dd::Partition |
| 1229 |
@param[in,out] client data dictionary client |
| 1230 |
@param[in] table MySQL table definition |
| 1231 |
@param[in] norm_name Table Name |
| 1232 |
@param[in] dd_table Global DD table or partition object |
| 1233 |
@param[in] thd thread THD |
| 1234 |
@return ptr to dict_table_t filled, otherwise, nullptr */ |
| 1235 |
template <typename Table> |
| 1236 |
dict_table_t *dd_open_table(dd::cache::Dictionary_client *client, |
| 1237 |
const TABLE *table, const char *norm_name, |
| 1238 |
const Table *dd_table, THD *thd); |
| 1239 |
MY_COMPILER_DIAGNOSTIC_POP() |
| 1240 |
|
| 1241 |
/** Open foreign tables reference a table. |
| 1242 |
@param[in] fk_list foreign key name list |
| 1243 |
@param[in] dict_locked dict_sys mutex is locked or not |
| 1244 |
@param[in] thd thread THD */ |
| 1245 |
void dd_open_fk_tables(dict_names_t &fk_list, bool dict_locked, THD *thd); |
| 1246 |
|
| 1247 |
/** Update the tablespace name and file name for rename |
| 1248 |
operation. |
| 1249 |
@param[in] dd_space_id dd tablespace id |
| 1250 |
@param[in] is_system_cs true, if space name is in system characters set. |
| 1251 |
While renaming during bootstrap we have it |
| 1252 |
in system cs. Otherwise, in file system cs. |
| 1253 |
@param[in] new_space_name dd_tablespace name |
| 1254 |
@param[in] new_path new data file path |
| 1255 |
@retval DB_SUCCESS on success. */ |
| 1256 |
dberr_t dd_tablespace_rename(dd::Object_id dd_space_id, bool is_system_cs, |
| 1257 |
const char *new_space_name, const char *new_path); |
| 1258 |
|
| 1259 |
/** Update the data directory flag in dd::Table key strings |
| 1260 |
@param[in] object_id dd tablespace object id |
| 1261 |
@param[in] path path where the ibd file is located currently |
| 1262 |
@retval DB_SUCCESS on success. */ |
| 1263 |
dberr_t dd_update_table_and_partitions_after_dir_change(dd::Object_id object_id, |
| 1264 |
std::string path); |
| 1265 |
|
| 1266 |
/** Create metadata for specified tablespace, acquiring exclusive MDL first |
| 1267 |
@param[in,out] dd_client data dictionary client |
| 1268 |
@param[in,out] dd_space_name dd tablespace name |
| 1269 |
@param[in] space_id InnoDB tablespace ID |
| 1270 |
@param[in] flags InnoDB tablespace flags |
| 1271 |
@param[in] filename filename of this tablespace |
| 1272 |
@param[in] discarded true if this tablespace was discarded |
| 1273 |
@param[in,out] dd_space_id dd_space_id |
| 1274 |
@retval false on success |
| 1275 |
@retval true on failure */ |
| 1276 |
bool dd_create_tablespace(dd::cache::Dictionary_client *dd_client, |
| 1277 |
const char *dd_space_name, space_id_t space_id, |
| 1278 |
uint32_t flags, const char *filename, bool discarded, |
| 1279 |
dd::Object_id &dd_space_id); |
| 1280 |
|
| 1281 |
/** Create metadata for implicit tablespace |
| 1282 |
@param[in,out] dd_client data dictionary client |
| 1283 |
@param[in] space_id InnoDB tablespace ID |
| 1284 |
@param[in] space_name tablespace name to be set for the |
| 1285 |
newly created tablespace |
| 1286 |
@param[in] filename tablespace filename |
| 1287 |
@param[in] discarded true if this tablespace was discarded |
| 1288 |
@param[in,out] dd_space_id dd tablespace id |
| 1289 |
@retval false on success |
| 1290 |
@retval true on failure */ |
| 1291 |
bool dd_create_implicit_tablespace(dd::cache::Dictionary_client *dd_client, |
| 1292 |
space_id_t space_id, const char *space_name, |
| 1293 |
const char *filename, bool discarded, |
| 1294 |
dd::Object_id &dd_space_id); |
| 1295 |
|
| 1296 |
/** Get the autoextend_size attribute for a tablespace. |
| 1297 |
@param[in] dd_client Data dictionary client |
| 1298 |
@param[in] dd_space_id Tablespace ID |
| 1299 |
@param[out] autoextend_size Value of autoextend_size attribute |
| 1300 |
@retval false On success |
| 1301 |
@retval true On failure */ |
| 1302 |
bool dd_get_tablespace_size_option(dd::cache::Dictionary_client *dd_client, |
| 1303 |
const dd::Object_id dd_space_id, |
| 1304 |
uint64_t *autoextend_size); |
| 1305 |
|
| 1306 |
/** Drop a tablespace |
| 1307 |
@param[in,out] dd_client data dictionary client |
| 1308 |
@param[in] dd_space_id dd tablespace id |
| 1309 |
@retval false On success |
| 1310 |
@retval true On failure */ |
| 1311 |
bool dd_drop_tablespace(dd::cache::Dictionary_client *dd_client, |
| 1312 |
dd::Object_id dd_space_id); |
| 1313 |
|
| 1314 |
/** Obtain the private handler of InnoDB session specific data. |
| 1315 |
@param[in,out] thd MySQL thread handler. |
| 1316 |
@return reference to private handler */ |
| 1317 |
|
| 1318 |
[[nodiscard]] innodb_session_t *&thd_to_innodb_session(THD *thd); |
| 1319 |
|
| 1320 |
/** Look up a column in a table using the system_charset_info collation. |
| 1321 |
@param[in] dd_table data dictionary table |
| 1322 |
@param[in] name column name |
| 1323 |
@return the column |
| 1324 |
@retval nullptr if not found */ |
| 1325 |
static inline const dd::Column *dd_find_column(const dd::Table *dd_table, |
| 1326 |
const char *name); |
| 1327 |
|
| 1328 |
/** Add a hidden column when creating a table. |
| 1329 |
@param[in,out] dd_table table containing user columns and indexes |
| 1330 |
@param[in] name hidden column name |
| 1331 |
@param[in] length length of the column, in bytes |
| 1332 |
@param[in] type column type |
| 1333 |
@return the added column, or NULL if there already was a column by that name */ |
| 1334 |
static inline dd::Column *dd_add_hidden_column(dd::Table *dd_table, |
| 1335 |
const char *name, uint length, |
| 1336 |
dd::enum_column_types type); |
| 1337 |
|
| 1338 |
/** Add a hidden index element at the end. |
| 1339 |
@param[in,out] index created index metadata |
| 1340 |
@param[in] column column of the index */ |
| 1341 |
static inline void dd_add_hidden_element(dd::Index *index, |
| 1342 |
const dd::Column *column); |
| 1343 |
|
| 1344 |
/** Initialize a hidden unique B-tree index. |
| 1345 |
@param[in,out] index created index metadata |
| 1346 |
@param[in] name name of the index |
| 1347 |
@param[in] column column of the index |
| 1348 |
@return the initialized index */ |
| 1349 |
static inline dd::Index *dd_set_hidden_unique_index(dd::Index *index, |
| 1350 |
const char *name, |
| 1351 |
const dd::Column *column); |
| 1352 |
|
| 1353 |
/** Check whether there exist a column named as "FTS_DOC_ID", which is |
| 1354 |
reserved for InnoDB FTS Doc ID |
| 1355 |
@param[in] thd MySQL thread handle |
| 1356 |
@param[in] form information on table |
| 1357 |
columns and indexes |
| 1358 |
@param[out] doc_id_col Doc ID column number if |
| 1359 |
there exist a FTS_DOC_ID column, |
| 1360 |
ULINT_UNDEFINED if column is of the |
| 1361 |
wrong type/name/size |
| 1362 |
@return true if there exist a "FTS_DOC_ID" column */ |
| 1363 |
static inline bool create_table_check_doc_id_col(THD *thd, const TABLE *form, |
| 1364 |
ulint *doc_id_col); |
| 1365 |
|
| 1366 |
/** Return a display name for the row format |
| 1367 |
@param[in] row_format Row Format |
| 1368 |
@return row format name */ |
| 1369 |
static inline const char *get_row_format_name(enum row_type row_format); |
| 1370 |
|
| 1371 |
/** Get the file name of a tablespace. |
| 1372 |
@param[in] dd_space Tablespace metadata |
| 1373 |
@return file name */ |
| 1374 |
static inline const char *dd_tablespace_get_filename( |
| 1375 |
const dd::Tablespace *dd_space) { |
| 1376 |
ut_ad(dd_space->id() != dd::INVALID_OBJECT_ID); |
| 1377 |
ut_ad(dd_space->files().size() == 1); |
| 1378 |
return ((*dd_space->files().begin())->filename().c_str()); |
| 1379 |
} |
| 1380 |
|
| 1381 |
/** Check if the InnoDB table is consistent with dd::Table |
| 1382 |
@tparam Table dd::Table or dd::Partition |
| 1383 |
@param[in] table InnoDB table |
| 1384 |
@param[in] dd_table dd::Table or dd::Partition |
| 1385 |
@return true if match |
| 1386 |
@retval false if not match */ |
| 1387 |
template <typename Table> |
| 1388 |
bool dd_table_match(const dict_table_t *table, const Table *dd_table); |
| 1389 |
|
| 1390 |
/** Create dd table for fts aux index table |
| 1391 |
@param[in] parent_table parent table of fts table |
| 1392 |
@param[in,out] table fts table |
| 1393 |
@param[in] charset fts index charset |
| 1394 |
@return true on success, false on failure */ |
| 1395 |
bool dd_create_fts_index_table(const dict_table_t *parent_table, |
| 1396 |
dict_table_t *table, |
| 1397 |
const CHARSET_INFO *charset); |
| 1398 |
|
| 1399 |
/** Create dd table for fts aux common table |
| 1400 |
@param[in] parent_table parent table of fts table |
| 1401 |
@param[in,out] table fts table |
| 1402 |
@param[in] is_config flag whether it's fts aux configure table |
| 1403 |
@return true on success, false on failure */ |
| 1404 |
bool dd_create_fts_common_table(const dict_table_t *parent_table, |
| 1405 |
dict_table_t *table, bool is_config); |
| 1406 |
|
| 1407 |
/** Drop dd table & tablespace for fts aux table |
| 1408 |
@param[in] name table name |
| 1409 |
@param[in] file_per_table flag whether use file per table |
| 1410 |
@return true on success, false on failure. */ |
| 1411 |
bool dd_drop_fts_table(const char *name, bool file_per_table); |
| 1412 |
|
| 1413 |
/** Rename dd table & tablespace files for fts aux table |
| 1414 |
@param[in] table dict table |
| 1415 |
@param[in] old_name old innodb table name |
| 1416 |
@return true on success, false on failure. */ |
| 1417 |
bool dd_rename_fts_table(const dict_table_t *table, const char *old_name); |
| 1418 |
|
| 1419 |
/** Open a table from its database and table name, this is currently used by |
| 1420 |
foreign constraint parser to get the referenced table. |
| 1421 |
@param[in] name foreign key table name |
| 1422 |
@param[in] database_name table db name |
| 1423 |
@param[in] database_name_len db name length |
| 1424 |
@param[in] table_name table db name |
| 1425 |
@param[in] table_name_len table name length |
| 1426 |
@param[in,out] table table object or NULL |
| 1427 |
@param[in,out] mdl mdl on table |
| 1428 |
@param[in,out] heap heap memory |
| 1429 |
@return complete table name with database and table name, allocated from |
| 1430 |
heap memory passed in */ |
| 1431 |
char *dd_get_referenced_table(const char *name, const char *database_name, |
| 1432 |
ulint database_name_len, const char *table_name, |
| 1433 |
ulint table_name_len, dict_table_t **table, |
| 1434 |
MDL_ticket **mdl, mem_heap_t *heap); |
| 1435 |
|
| 1436 |
/** Set the 'state' value in dd:tablespace::se_private_data starting with |
| 1437 |
an object id and the space name. Update the transaction when complete. |
| 1438 |
@param[in] thd current thread |
| 1439 |
@param[in] dd_space_id dd::Tablespace |
| 1440 |
@param[in] space_name tablespace name |
| 1441 |
@param[in] state value to set for key 'state'. */ |
| 1442 |
void dd_tablespace_set_state(THD *thd, dd::Object_id dd_space_id, |
| 1443 |
std::string space_name, dd_space_states state); |
| 1444 |
|
| 1445 |
/** Set the 'state' value in dd:tablespace::se_private_data. |
| 1446 |
The caller will update the transaction. |
| 1447 |
@param[in,out] dd_space dd::Tablespace object |
| 1448 |
@param[in] state value to set for key 'state' */ |
| 1449 |
void dd_tablespace_set_state(dd::Tablespace *dd_space, dd_space_states state); |
| 1450 |
|
| 1451 |
/** Set Space ID and state attribute in se_private_data of mysql.tablespaces |
| 1452 |
for the named tablespace. |
| 1453 |
@param[in] space_name tablespace name |
| 1454 |
@param[in] space_id tablespace id |
| 1455 |
@param[in] state value to set for key 'state' |
| 1456 |
@return DB_SUCCESS or DD_FAILURE. */ |
| 1457 |
bool dd_tablespace_set_id_and_state(const char *space_name, space_id_t space_id, |
| 1458 |
dd_space_states state); |
| 1459 |
|
| 1460 |
/** Get state attribute value in dd::Tablespace::se_private_data |
| 1461 |
@param[in] dd_space dd::Tablespace object |
| 1462 |
@param[in,out] state tablespace state attribute |
| 1463 |
@param[in] space_id tablespace ID */ |
| 1464 |
void dd_tablespace_get_state(const dd::Tablespace *dd_space, |
| 1465 |
dd::String_type *state, |
| 1466 |
space_id_t space_id = SPACE_UNKNOWN); |
| 1467 |
|
| 1468 |
/** Get state attribute value in dd::Tablespace::se_private_data |
| 1469 |
@param[in] p dd::Properties for dd::Tablespace::se_private_data |
| 1470 |
@param[in,out] state tablespace state attribute |
| 1471 |
@param[in] space_id tablespace ID */ |
| 1472 |
void dd_tablespace_get_state(const dd::Properties *p, dd::String_type *state, |
| 1473 |
space_id_t space_id = SPACE_UNKNOWN); |
| 1474 |
|
| 1475 |
/** Get the enum for the state of the undo tablespace |
| 1476 |
from either dd::Tablespace::se_private_data or undo::Tablespace |
| 1477 |
@param[in] dd_space dd::Tablespace object |
| 1478 |
@param[in] space_id tablespace ID |
| 1479 |
@return enumerated value associated with the key 'state' */ |
| 1480 |
dd_space_states dd_tablespace_get_state_enum( |
| 1481 |
const dd::Tablespace *dd_space, space_id_t space_id = SPACE_UNKNOWN); |
| 1482 |
|
| 1483 |
/** Get the enum for the state of a tablespace |
| 1484 |
from either dd::Tablespace::se_private_data or undo::Tablespace |
| 1485 |
@param[in] p dd::Properties for dd::Tablespace::se_private_data |
| 1486 |
@param[in] space_id tablespace ID |
| 1487 |
@return enumerated value associated with the key 'state' */ |
| 1488 |
dd_space_states dd_tablespace_get_state_enum( |
| 1489 |
const dd::Properties *p, space_id_t space_id = SPACE_UNKNOWN); |
| 1490 |
|
| 1491 |
/** Get the enum for the state of a tablespace. Try the old 'discarded' |
| 1492 |
key value for IBD spaces or undo::Tablespace. |
| 1493 |
@param[in] p dd::Properties for dd::Tablespace::se_private_data |
| 1494 |
@param[in] space_id tablespace ID |
| 1495 |
@return enumerated value associated with the key 'state' */ |
| 1496 |
dd_space_states dd_tablespace_get_state_enum_legacy( |
| 1497 |
const dd::Properties *p, space_id_t space_id = SPACE_UNKNOWN); |
| 1498 |
|
| 1499 |
/** Get the discarded state from se_private_data of tablespace |
| 1500 |
@param[in] dd_space dd::Tablespace object */ |
| 1501 |
bool dd_tablespace_is_discarded(const dd::Tablespace *dd_space); |
| 1502 |
|
| 1503 |
/** Set the autoextend_size attribute for an implicit tablespace |
| 1504 |
@param[in,out] dd_client Data dictionary client |
| 1505 |
@param[in] dd_space_id DD tablespace id |
| 1506 |
@param[in] create_info HA_CREATE_INFO object |
| 1507 |
@return false On success |
| 1508 |
@return true On failure */ |
| 1509 |
bool dd_implicit_alter_tablespace(dd::cache::Dictionary_client *dd_client, |
| 1510 |
dd::Object_id dd_space_id, |
| 1511 |
HA_CREATE_INFO *create_info); |
| 1512 |
|
| 1513 |
/** Get the MDL for the named tablespace. The mdl_ticket pointer can |
| 1514 |
be provided if it is needed by the caller. If foreground is set to false, |
| 1515 |
then the caller must explicitly release that ticket with dd_release_mdl(). |
| 1516 |
Otherwise, it will ne released with the transaction. |
| 1517 |
@param[in] space_name tablespace name |
| 1518 |
@param[in] mdl_ticket tablespace MDL ticket, default to nullptr |
| 1519 |
@param[in] foreground true, if the caller is foreground thread. Default |
| 1520 |
is true. For foreground, the lock duration is |
| 1521 |
MDL_TRANSACTION. Otherwise, it is MDL_EXPLICIT. |
| 1522 |
@return DD_SUCCESS or DD_FAILURE. */ |
| 1523 |
bool dd_tablespace_get_mdl(const char *space_name, |
| 1524 |
MDL_ticket **mdl_ticket = nullptr, |
| 1525 |
bool foreground = true); |
| 1526 |
/** Set discard attribute value in se_private_dat of tablespace |
| 1527 |
@param[in] dd_space dd::Tablespace object |
| 1528 |
@param[in] discard true if discarded, else false */ |
| 1529 |
void dd_tablespace_set_discard(dd::Tablespace *dd_space, bool discard); |
| 1530 |
|
| 1531 |
/** Get discard attribute value stored in se_private_dat of tablespace |
| 1532 |
@param[in] dd_space dd::Tablespace object |
| 1533 |
@retval true if Tablespace is discarded |
| 1534 |
@retval false if attribute doesn't exist or if the |
| 1535 |
tablespace is not discarded */ |
| 1536 |
bool dd_tablespace_get_discard(const dd::Tablespace *dd_space); |
| 1537 |
|
| 1538 |
/** Release the MDL held by the given ticket. |
| 1539 |
@param[in] mdl_ticket tablespace MDL ticket */ |
| 1540 |
void dd_release_mdl(MDL_ticket *mdl_ticket); |
| 1541 |
|
| 1542 |
/** Copy metadata of already dropped columns from old table def to new |
| 1543 |
table def. |
| 1544 |
param[in] old_dd_table old table definition |
| 1545 |
param[in,out] new_dd_table new table definition |
| 1546 |
@retval true Failure |
| 1547 |
@retval false Success */ |
| 1548 |
bool copy_dropped_columns(const dd::Table *old_dd_table, |
| 1549 |
dd::Table *new_dd_table, |
| 1550 |
uint32_t current_row_version); |
| 1551 |
|
| 1552 |
/** Set Innodb tablespace compression option from DD. |
| 1553 |
@param[in,out] client dictionary client |
| 1554 |
@param[in] algorithm compression algorithm |
| 1555 |
@param[in] dd_space_id DD tablespace ID. |
| 1556 |
@return true, if failed to set compression. */ |
| 1557 |
bool dd_set_tablespace_compression(dd::cache::Dictionary_client *client, |
| 1558 |
const char *algorithm, |
| 1559 |
dd::Object_id dd_space_id); |
| 1560 |
|
| 1561 |
#endif /* !UNIV_HOTBACKUP */ |
| 1562 |
|
| 1563 |
/** Update all InnoDB tablespace cache objects. This step is done post |
| 1564 |
dictionary trx rollback, binlog recovery and DDL_LOG apply. So DD is |
| 1565 |
consistent. Update the cached tablespace objects, if they differ from |
| 1566 |
the dictionary. |
| 1567 |
@param[in,out] thd thread handle |
| 1568 |
@retval true on error |
| 1569 |
@retval false on success */ |
| 1570 |
|
| 1571 |
[[nodiscard]] bool dd_tablespace_update_cache(THD *thd); |
| 1572 |
|
| 1573 |
/* Check if the table belongs to an encrypted tablespace. |
| 1574 |
@return true if it does. */ |
| 1575 |
bool dd_is_table_in_encrypted_tablespace(const dict_table_t *table); |
| 1576 |
|
| 1577 |
/** Parse the default value from dd::Column::se_private to dict_col_t |
| 1578 |
@param[in] se_private_data dd::Column::se_private |
| 1579 |
@param[in,out] col InnoDB column object |
| 1580 |
@param[in,out] heap Heap to store the default value */ |
| 1581 |
void dd_parse_default_value(const dd::Properties &se_private_data, |
| 1582 |
dict_col_t *col, mem_heap_t *heap); |
| 1583 |
|
| 1584 |
#ifndef UNIV_HOTBACKUP |
| 1585 |
/** Add definition of INSTANT dropped column in table cache. |
| 1586 |
@param[in] dd_table Table definition |
| 1587 |
@param[in,out] dict_table Table cache |
| 1588 |
@param[out] current_row_version row_version |
| 1589 |
@param[in] heap heap */ |
| 1590 |
void fill_dict_dropped_columns(const dd::Table *dd_table, |
| 1591 |
dict_table_t *dict_table |
| 1592 |
IF_DEBUG(, uint32_t ¤t_row_version), |
| 1593 |
mem_heap_t *heap); |
| 1594 |
|
| 1595 |
/** Check if given column is renamed during ALTER. |
| 1596 |
@param[in] ha_alter_info alter info |
| 1597 |
@param[in] old_name column old name |
| 1598 |
@param[out] new_name column new name |
| 1599 |
@return true if column is renamed, false otherwise. */ |
| 1600 |
bool is_renamed(const Alter_inplace_info *ha_alter_info, const char *old_name, |
| 1601 |
std::string &new_name); |
| 1602 |
|
| 1603 |
/** Check if given column is dropped during ALTER. |
| 1604 |
@param[in] ha_alter_info alter info |
| 1605 |
@param[in] column_name Column name |
| 1606 |
@return true if column is dropped, false otherwise. */ |
| 1607 |
bool is_dropped(const Alter_inplace_info *ha_alter_info, |
| 1608 |
const char *column_name); |
| 1609 |
|
| 1610 |
/** Get the mtype, prtype and len for a field. |
| 1611 |
@param[in] dd_tab dd table definition |
| 1612 |
@param[in] m_table innodb table cache |
| 1613 |
@param[in] field MySQL field |
| 1614 |
@param[out] col_len length |
| 1615 |
@param[out] mtype mtype |
| 1616 |
@param[out] prtype prtype */ |
| 1617 |
void get_field_types(const dd::Table *dd_tab, const dict_table_t *m_table, |
| 1618 |
const Field *field, unsigned &col_len, ulint &mtype, |
| 1619 |
ulint &prtype); |
| 1620 |
#endif |
| 1621 |
|
| 1622 |
#include "dict0dd.ic" |
| 1623 |
#endif |