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