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