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