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