MySQL 26.10.0
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_TABLE_INCLUDED
25#define SQL_TABLE_INCLUDED
26
27#include <stddef.h>
28#include <sys/types.h>
29
30#include <map>
31#include <set>
32#include <string>
33#include <utility>
34#include <vector>
35
36#include "my_inttypes.h"
37#include "my_sharedlib.h"
39#include "mysqld_error.h"
40#include "sql/dd/string_type.h"
41#include "sql/handler.h"
42#include "sql/mdl.h"
43
44class Alter_info;
45class Alter_table_ctx;
46class Create_field;
47class Field;
48class FOREIGN_KEY;
49class KEY;
50class THD;
51class handler;
52struct CHARSET_INFO;
53struct MEM_ROOT;
54struct TABLE;
55class Table_ref;
56struct handlerton;
57
58namespace dd {
59class Foreign_key;
60class Schema;
61class Table;
62class View;
63} // namespace dd
64
65struct HA_CHECK_OPT;
66struct HA_CREATE_INFO;
67
69template <typename T>
70class List;
71
76};
77
78/* Flags for conversion functions. */
79static const uint FN_FROM_IS_TMP = 1 << 0;
80static const uint FN_TO_IS_TMP = 1 << 1;
82/** Don't check foreign key constraints while renaming table */
83static const uint NO_FK_CHECKS = 1 << 2;
84/**
85 Don't commit transaction after updating data-dictionary while renaming
86 the table.
87*/
88static const uint NO_DD_COMMIT = 1 << 3;
89/** Don't change generated foreign key names while renaming table. */
90static const uint NO_FK_RENAME = 1 << 4;
91/** Don't change generated check constraint names while renaming table. */
92static const uint NO_CC_RENAME = 1 << 5;
93
95 const HA_CREATE_INFO &ci);
96
97size_t filename_to_tablename(const char *from, char *to, size_t to_length,
98 bool stay_quiet = false,
99 bool *has_errors = nullptr);
100size_t tablename_to_filename(const char *from, char *to, size_t to_length);
101size_t build_table_filename(char *buff, size_t bufflen, const char *db,
102 const char *table, const char *ext, uint flags,
103 bool *was_truncated);
104// For caller's who are mostly sure that path do not truncate
105size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
106 const char *table, const char *ext,
107 uint flags) {
108 bool truncated_not_used;
109 return build_table_filename(buff, bufflen, db, table, ext, flags,
110 &truncated_not_used);
111}
112size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
114 HA_CREATE_INFO *create_info, Alter_info *alter_info);
115bool mysql_create_table_no_lock(THD *thd, const char *db,
116 const char *table_name,
117 HA_CREATE_INFO *create_info,
118 Alter_info *alter_info, uint select_field_count,
119 bool find_parent_keys, bool *is_trans,
120 handlerton **post_ddl_ht);
122
123/**
124 Helper class for keeping track for which tables we need to invalidate
125 data-dictionary cache entries and performing such invalidation.
126*/
128 public:
132 };
133
134 private:
135 typedef std::map<std::pair<dd::String_type, dd::String_type>,
136 std::pair<handlerton *, enum_invalidation_type>>
139
140 public:
141 void add(
142 const char *db_name, const char *table_name, handlerton *hton,
144 // Usually tables added to a Foreign_key_parents_invalidator instance are
145 // closed by the invalidate member function. However, occasionally tables
146 // are added that we subsequently discover should only be invalidated and
147 // not closed by the invalidate member function as they will be closed
148 // elsewhere.
149 // See bool Query_result_create::send_eof(THD *thd) for an example.
150 // The mark_for_reopen_if_added member function updates the
151 // corresponding Parent_map entry if necessary in this situation.
152 void mark_for_reopen_if_added(const char *db_name, const char *table_name);
153 void invalidate(THD *thd);
154 const Parent_map &parents() const { return m_parent_map; }
155 bool is_empty() const { return m_parent_map.empty(); }
156 void clear() { m_parent_map.clear(); }
157};
158
159/**
160 Auxiliary class implementing RAII principle for getting permission for/
161 notification about finished DDL statements from interested storage engines.
162
163 @see handlerton::ha_notify_table_ddl for details.
164*/
166 public:
168 THD *thd, const MDL_key *key, ha_ddl_type ddl_type,
169 const char *old_db_name = nullptr, const char *old_table_name = nullptr,
170 const char *new_db_name = nullptr,
171 const char *new_table_name = nullptr) noexcept
172 : m_hton_notified(false),
173 m_thd(thd),
174 m_key(*key),
175 m_ddl_type(ddl_type),
176 m_old_db_name(old_db_name),
177 m_old_table_name(old_table_name),
178 m_new_db_name(new_db_name),
179 m_new_table_name(new_table_name) {}
180
181 [[nodiscard]] bool notify() noexcept {
185 m_hton_notified = true;
186 return false;
187 }
188 my_error(ER_LOCK_REFUSED_BY_ENGINE, MYF(0));
189 return true;
190 }
191
193 if (m_hton_notified)
197 }
198
199 private:
204 const char *m_old_db_name;
205 const char *m_old_table_name;
206 const char *m_new_db_name;
207 const char *m_new_table_name;
208};
209
210/*
211 Reload the foreign key parent information of the referenced
212 tables and for the table itself.
213
214 @param thd Thread handle.
215 @param db Table schema name.
216 @param name Table name.
217 @param reload_self Reload FK parent info also for the
218 table itself.
219 @param fk_invalidator Object keeping track of which dd::Table
220 objects to invalidate. If submitted, use this
221 to restrict which FK parents should have their
222 FK parent information reloaded.
223
224 @retval operation outcome, false if no error.
225*/
226bool adjust_fk_parents(THD *thd, const char *db, const char *name,
227 bool reload_self,
228 const Foreign_key_parents_invalidator *fk_invalidator);
229
230/**
231 Check if new definition of parent table is compatible with foreign keys
232 which reference it. Update the unique constraint names and referenced
233 column names for the foreign keys accordingly.
234
235 @param thd Thread handle.
236 @param check_charsets Indicates whether we need to check charsets of
237 columns participating in foreign keys.
238 @param parent_table_db Parent table schema name.
239 @param parent_table_name Parent table name.
240 @param hton Handlerton for table's storage engine.
241 @param parent_table_def Table object representing the referenced table.
242 @param parent_alter_info Alter_info containing information about renames
243 of parent columns. Can be nullptr if there are
244 no such renames.
245 @param invalidate_tdc Indicates whether we need to invalidate TDC for
246 referencing tables after updating their
247 definitions.
248
249 @retval operation outcome, false if no error.
250*/
252 THD *thd, bool check_charsets, const char *parent_table_db,
253 const char *parent_table_name, handlerton *hton,
254 const dd::Table *parent_table_def, Alter_info *parent_alter_info,
255 bool invalidate_tdc);
256
257/**
258 Check if new definition of parent table is compatible with foreign keys
259 which reference it. Update the unique constraint names and referenced
260 column names for the foreign keys accordingly. Do mandatory character
261 set checks and TDC invalidation.
262*/
264 THD *thd, const char *parent_table_db, const char *parent_table_name,
265 handlerton *hton, const dd::Table *parent_table_def,
266 Alter_info *parent_alter_info) {
268 thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
269 parent_alter_info, true);
270}
271
272/**
273 Add MDL requests for specified lock type on all tables referencing the given
274 schema qualified table name to the list.
275
276 @param thd Thread handle.
277 @param schema Schema name.
278 @param table_name Table name.
279 @param hton Handlerton for table's storage engine.
280 @param lock_type Type of MDL requests to add.
281 @param[in,out] mdl_requests List to which MDL requests are to be added.
282
283 @retval operation outcome, false if no error.
284*/
285[[nodiscard]] bool collect_fk_children(THD *thd, const char *schema,
286 const char *table_name, handlerton *hton,
287 enum_mdl_type lock_type,
288 MDL_request_list *mdl_requests);
289
290/**
291 Add MDL requests for lock of specified type on tables referenced by the
292 foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
293 Also add the referenced table names to the foreign key invalidator,
294 to be used at a later stage to invalidate the dd::Table objects.
295
296 @param thd Thread handle.
297 @param db_name Table's database name.
298 @param table_name Table name.
299 @param alter_info Alter_info object with the list of FKs
300 to be added.
301 @param lock_type Type of metadata lock to be requested.
302 @param hton Handlerton for table's storage engine.
303 @param[in,out] mdl_requests List to which MDL requests are to be added.
304 @param[in,out] fk_invalidator Object keeping track of which dd::Table
305 objects to invalidate.
306
307 @retval operation outcome, false if no error.
308*/
309[[nodiscard]] bool collect_fk_parents_for_new_fks(
310 THD *thd, const char *db_name, const char *table_name,
311 const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
312 MDL_request_list *mdl_requests,
313 Foreign_key_parents_invalidator *fk_invalidator);
314
315/**
316 Add MDL requests for exclusive metadata locks on names of foreign keys
317 to be added by the CREATE TABLE or ALTER TABLE operation.
318
319 @param thd Thread context.
320 @param db_name Table's database name.
321 @param table_name Table name.
322 @param alter_info Alter_info object with the
323 list of FKs to be added.
324 @param hton Table's storage engine.
325 @param fk_max_generated_name_number Max value of number component
326 among existing generated foreign
327 key names.
328 @param[in,out] mdl_requests List to which MDL requests
329 are to be added.
330
331 @retval operation outcome, false if no error.
332*/
333bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
334 const char *table_name,
335 const Alter_info *alter_info,
336 handlerton *hton,
337 uint fk_max_generated_name_number,
338 MDL_request_list *mdl_requests);
339
340/**
341 Acquire exclusive metadata locks on tables which definitions need to
342 be updated or invalidated since they are related through foreign keys
343 to the table to be renamed,
344 Also add the referenced table names for the FKs on this table to the
345 foreign key invalidator, to be used at a later stage to invalidate the
346 dd::Table objects.
347
348 @param thd Thread handle.
349 @param db Table's old schema.
350 @param table_name Table's old name.
351 @param table_def Table definition of table being RENAMEd.
352 @param new_db Table's new schema.
353 @param new_table_name Table's new name.
354 @param hton Table's SE.
355 @param[in,out] fk_invalidator Object keeping track of which dd::Table
356 objects to invalidate.
357
358 @retval operation outcome, false if no error.
359*/
361 THD *thd, const char *db, const char *table_name,
362 const dd::Table *table_def, const char *new_db, const char *new_table_name,
363 handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator);
364
365/**
366 As a result of simple rename table operation, orphan non-self-referencing
367 foreign keys may become non-orphan/adopted self-referencing foreign keys.
368 For such transformed foreign key, check that table has compatible referenced
369 column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
370
371 @param thd Thread handle.
372 @param db Table's old schema.
373 @param table_name Table's old name.
374 @param new_db Table's new schema.
375 @param new_table_name Table's new name.
376 @param hton Table's SE.
377
378 @retval operation outcome, false if no error.
379*/
381 THD *thd, const char *db, const char *table_name, const char *new_db,
382 const char *new_table_name, handlerton *hton);
383
384/**
385 Update referenced table names and the unique constraint name for FKs
386 affected by RENAME TABLE operation.
387
388 @param thd Thread handle.
389 @param db Table's old schema.
390 @param table_name Table's old name.
391 @param new_db Table's new schema.
392 @param new_table_name Table's new name.
393 @param hton Table's SE.
394
395 @retval operation outcome, false if no error.
396*/
397[[nodiscard]] bool adjust_fks_for_rename_table(THD *thd, const char *db,
398 const char *table_name,
399 const char *new_db,
400 const char *new_table_name,
401 handlerton *hton);
402
403/*
404 Check if parent key for the foreign key exists, set foreign key's unique
405 constraint name accordingly. Emit error if no parent key found.
406
407 @note Prefer unique key if possible. If parent key is non-unique
408 unique constraint name is set to NULL.
409
410 @note DDL code use this function for non-self-referencing foreign keys.
411
412 @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
413
414 @param thd Thread handle.
415 @param hton Handlerton for tables' storage engine.
416 @param parent_table_def Object describing new version of parent table.
417 @param old_child_table_def Object describing old version of child table.
418 Can be nullptr if old_parent_table_def is
419 nullptr. Used for error reporting.
420 @param old_parent_table_def Object describing old version of parent table.
421 nullptr indicates that this is not ALTER TABLE
422 operation. Used for error reporting.
423 @param is_self_referencing_fk If the parent and child is the same table.
424 @param fk[in,out] Object describing the foreign key,
425 its unique_constraint_name member
426 will be updated if matching parent
427 unique constraint is found.
428
429 @retval Operation result. False if success.
430*/
431[[nodiscard]] bool prepare_fk_parent_key(THD *thd, handlerton *hton,
432 const dd::Table *parent_table_def,
433 const dd::Table *old_parent_table_def,
434 const dd::Table *old_child_table_def,
435 bool is_self_referencing_fk,
436 dd::Foreign_key *fk);
437
438/**
439 Prepare Create_field and Key_spec objects for ALTER and upgrade.
440 @param[in,out] thd thread handle. Used as a memory pool
441 and source of environment information.
442 @param[in] src_table DD table object. Will be nullptr for temporary
443 tables and during upgrade.
444 @param[in] table the source table, open and locked
445 Used as an interface to the storage engine
446 to acquire additional information about
447 the original table.
448 @param[in,out] create_info A blob with CREATE/ALTER TABLE
449 parameters
450 @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
451 Originally create_info was used only in
452 CREATE TABLE and alter_info only in ALTER TABLE.
453 But since ALTER might end-up doing CREATE,
454 this distinction is gone and we just carry
455 around two structures.
456 @param[in,out] alter_ctx Runtime context for ALTER TABLE.
457 @param[in] used_fields used_fields from HA_CREATE_INFO.
458
459 @retval true error, out of memory or a semantical error in ALTER
460 TABLE instructions
461 @retval false success
462
463*/
464bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
465 HA_CREATE_INFO *create_info,
466 Alter_info *alter_info, Alter_table_ctx *alter_ctx,
467 const uint &used_fields);
468
469bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
470 TABLE *table, HA_CREATE_INFO *create_info,
471 Alter_info *alter_info,
472 Alter_table_ctx *alter_ctx);
475bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
476 HA_CREATE_INFO *create_info, Table_ref *table_list,
477 Alter_info *alter_info);
478bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info,
479 HA_CREATE_INFO *create_info, bool *metadata_equal);
480void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
482bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy);
483bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table,
484 HA_CREATE_INFO *create_info, uint open_flags = 0,
485 bool skip_post_ddl_operations = false);
486bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
487 const char *old_name, const char *old_fk_db,
488 const char *old_fk_name, const dd::Schema &new_schema,
489 const char *new_db, const char *new_name, uint flags);
490
491bool mysql_checksum_table(THD *thd, Table_ref *table_list,
492 HA_CHECK_OPT *check_opt);
493bool mysql_rm_table(THD *thd, Table_ref *tables, bool if_exists,
494 bool drop_temporary);
495bool mysql_rm_table_no_locks(THD *thd, Table_ref *tables, bool if_exists,
496 bool drop_temporary, bool drop_database,
497 const char *database_name,
498 const bool should_drop_schema_ddl_log,
499 bool *dropped_non_atomic_flag,
500 std::set<handlerton *> *post_ddl_htons,
501 Foreign_key_parents_invalidator *fk_invalidator,
502 std::vector<MDL_ticket *> *safe_to_release_mdl);
503
504/**
505 Discover missing tables in SE and acquire locks on tables which participate
506 in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
507 will have to be updated or invalidated during this operation.
508
509 @param thd Thread context.
510 @param tables Tables to be dropped by DROP TABLES/DATABASE.
511
512 @retval False - Success.
513 @retval True - Failure.
514*/
515[[nodiscard]] bool rm_table_do_discovery_and_lock_fk_tables(THD *thd,
516 Table_ref *tables);
517
518bool quick_rm_table(THD *thd, handlerton *base, const char *db,
519 const char *table_name, uint flags);
520bool prepare_sp_create_field(THD *thd, Create_field *field_def);
521bool prepare_pack_create_field(THD *thd, Create_field *sql_field,
522 longlong table_flags);
523
524const CHARSET_INFO *get_sql_field_charset(const Create_field *sql_field,
525 const HA_CREATE_INFO *create_info);
526bool validate_comment_length(THD *thd, const char *comment_str,
527 size_t *comment_len, uint max_len, uint err_code,
528 const char *comment_name);
529int write_bin_log(THD *thd, bool clear_error, const char *query,
530 size_t query_length, bool is_trans = false);
531void promote_first_timestamp_column(List<Create_field> *column_definitions);
532
533/**
534 Prepares the column definitions for table creation.
535
536 @param thd Thread object.
537 @param error_schema_name Schema name of the table used for error
538 reporting.
539 @param error_table_name Table name used for error reporting.
540 @param create_info Create information.
541 @param[in,out] create_list List of columns to create.
542 @param[in,out] select_field_pos Position where the SELECT columns start
543 for CREATE TABLE ... SELECT.
544 @param file The handler for the new table.
545 @param[in,out] sql_field Create_field to populate.
546 @param field_no Column number.
547
548 @retval false OK
549 @retval true error
550*/
551
552bool prepare_create_field(THD *thd, const char *error_schema_name,
553 const char *error_table_name,
554 HA_CREATE_INFO *create_info,
555 List<Create_field> *create_list,
556 int *select_field_pos, handler *file,
557 Create_field *sql_field, int field_no);
558
559/**
560 Prepares the table and key structures for table creation.
561
562 @param thd Thread object.
563 @param error_schema_name Schema name of the table to create/alter,
564 only error reporting.
565 @param error_table_name Name of table to create/alter, only used for
566 error reporting.
567 @param create_info Create information (like MAX_ROWS).
568 @param alter_info List of columns and indexes to create
569 @param file The handler for the new table.
570 @param is_partitioned Indicates whether table is partitioned.
571 @param[out] key_info_buffer An array of KEY structs for the indexes.
572 @param[out] key_count The number of elements in the array.
573 @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
574 foreign keys.
575 @param[out] fk_key_count The number of elements in the array.
576 @param[in] existing_fks An array of pre-existing FOREIGN KEYS
577 (in case of ALTER).
578 @param[in] existing_fks_count The number of pre-existing foreign keys.
579 @param[in] existing_fks_table dd::Table object for table version from
580 which pre-existing foreign keys come from.
581 Needed for error reporting.
582 @param[in] fk_max_generated_name_number Max value of number component among
583 existing generated foreign key names.
584 @param select_field_count The number of fields coming from a select
585 table.
586 @param find_parent_keys Indicates whether we need to lookup name of
587 unique constraint in parent table for foreign
588 keys.
589
590 @retval false OK
591 @retval true error
592*/
593
595 THD *thd, const char *error_schema_name, const char *error_table_name,
596 HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
597 bool is_partitioned, KEY **key_info_buffer, uint *key_count,
598 FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
599 FOREIGN_KEY *existing_fks, uint existing_fks_count,
600 const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
601 int select_field_count, bool find_parent_keys);
602
603size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
604 enum_explain_filename_mode explain_mode);
605
606extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
607
608/**
609 Acquire metadata lock on triggers associated with a list of tables.
610
611 @param[in] thd Current thread context
612 @param[in] tables Tables for that associated triggers have to locked.
613
614 @return Operation status.
615 @retval false Success
616 @retval true Failure
617*/
618
619bool lock_trigger_names(THD *thd, Table_ref *tables);
620struct TYPELIB;
622
623/**
624 Method to collect check constraint names for the all the tables and acquire
625 MDL lock on them.
626
627 @param[in] thd Thread handle.
628 @param[in] tables Check constraints of tables to be locked.
629
630 @retval false Success.
631 @retval true Failure.
632*/
633bool lock_check_constraint_names(THD *thd, Table_ref *tables);
634
635/**
636 Method to lock check constraint names for rename table operation.
637 Method acquire locks on the constraint names of source table and
638 also on the name of check constraint in the target table.
639
640 @param[in] thd Thread handle.
641 @param[in] db Database name.
642 @param[in] table_name Table name.
643 @param[in] table_def DD table object of source table.
644 @param[in] target_db Target database name.
645 @param[in] target_table_name Target table name.
646
647 @retval false Success.
648 @retval true Failure.
649*/
650bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
651 const char *table_name,
652 const dd::Table *table_def,
653 const char *target_db,
654 const char *target_table_name);
655
656/**
657 Method to prepare check constraints for the CREATE operation. If name of the
658 check constraint is not specified then name is generated, check constraint
659 is pre-validated and MDL on check constraint is acquired.
660
661 @param thd Thread handle.
662 @param db_name Database name.
663 @param table_name Table name.
664 @param alter_info Alter_info object with list of
665 check constraints to be created.
666
667 @retval false Success.
668 @retval true Failure.
669*/
671 const char *table_name,
672 Alter_info *alter_info);
673
674extern std::atomic_ulong deprecated_use_fk_on_non_standard_key_count;
676
677/**
678 Unloads the materialized view from a secondary engine, where it might be
679 materialized.
680 */
682 const dd::View *view_def);
683
684/**
685 Resolves the secondary engine handled via its name and calls the unload
686 table function
687*/
688bool secondary_engine_unload_table_inner(THD *thd, const char *db_name,
689 const char *table_name,
691 bool is_partitioned,
692 bool error_if_not_loaded);
693
694/**
695 Validation on create temporary table statements with secondary engine defined:
696 1. Check that the create table statement contains a query.
697 2. Set the lex state indicating that the query can execute only
698 on the secondary engine.
699*/
701 HA_CREATE_INFO *create_info);
702
703#endif /* SQL_TABLE_INCLUDED */
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:210
Runtime context for ALTER TABLE.
Definition: sql_alter.h:531
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Definition: key.h:43
Definition: field.h:573
Helper class for keeping track for which tables we need to invalidate data-dictionary cache entries a...
Definition: sql_table.h:127
void invalidate(THD *thd)
Definition: sql_table.cc:1540
void mark_for_reopen_if_added(const char *db_name, const char *table_name)
Definition: sql_table.cc:1530
const Parent_map & parents() const
Definition: sql_table.h:154
enum_invalidation_type
Definition: sql_table.h:129
@ INVALIDATE_AND_MARK_FOR_REOPEN
Definition: sql_table.h:131
@ INVALIDATE_AND_CLOSE_TABLE
Definition: sql_table.h:130
std::map< std::pair< dd::String_type, dd::String_type >, std::pair< handlerton *, enum_invalidation_type > > Parent_map
Definition: sql_table.h:137
void clear()
Definition: sql_table.h:156
void add(const char *db_name, const char *table_name, handlerton *hton, enum_invalidation_type invalidation_type=INVALIDATE_AND_CLOSE_TABLE)
Definition: sql_table.cc:1522
Parent_map m_parent_map
Definition: sql_table.h:138
bool is_empty() const
Definition: sql_table.h:155
Intrusive parameterized list.
Definition: sql_plist.h:75
Definition: key.h:113
Definition: sql_list.h:494
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Auxiliary class implementing RAII principle for getting permission for/ notification about finished D...
Definition: sql_table.h:165
bool m_hton_notified
Definition: sql_table.h:200
const MDL_key m_key
Definition: sql_table.h:202
THD * m_thd
Definition: sql_table.h:201
bool notify() noexcept
Definition: sql_table.h:181
const char * m_old_db_name
Definition: sql_table.h:204
const char * m_new_table_name
Definition: sql_table.h:207
const ha_ddl_type m_ddl_type
Definition: sql_table.h:203
const char * m_old_table_name
Definition: sql_table.h:205
const char * m_new_db_name
Definition: sql_table.h:206
Table_ddl_hton_notification_guard(THD *thd, const MDL_key *key, ha_ddl_type ddl_type, const char *old_db_name=nullptr, const char *old_table_name=nullptr, const char *new_db_name=nullptr, const char *new_table_name=nullptr) noexcept
Definition: sql_table.h:167
~Table_ddl_hton_notification_guard()
Definition: sql_table.h:192
Definition: table.h:2958
Definition: foreign_key.h:47
Definition: schema.h:64
Definition: table.h:47
Definition: view.h:39
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4753
A table definition from the master.
Definition: rpl_utility.h:251
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:217
PFS_table * create_table(PFS_table_share *share, PFS_thread *opening_thread, const void *)
Create instrumentation for a table instance.
Definition: pfs_instr.cc:1308
static int flags[50]
Definition: hp_test1.cc:40
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
#define MYF(v)
Definition: my_inttypes.h:97
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:71
static char * query
Definition: myisam_ftdump.cc:47
ABI for instrumented mutexes.
static Secondary_engine * secondary_engine
Definition: mysqltest.cc:260
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:288
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
Definition: os0file.h:89
Json_data_extension ext
Definition: backend.cc:50
entry::Table Table
Definition: select.h:51
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
required string key
Definition: replication_asynchronous_connection_failover.proto:60
bool ha_notify_table_ddl(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type, ha_ddl_type ddl_type, const char *old_db_name, const char *old_table_name, const char *new_db_name, const char *new_table_name)
Notify/get permission from all interested storage engines before or after executed DDL (ALTER TABLE,...
Definition: handler.cc:8939
ha_ddl_type
Definition: handler.h:965
@ HA_NOTIFY_POST_EVENT
Definition: handler.h:964
@ HA_NOTIFY_PRE_EVENT
Definition: handler.h:964
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:106
static const uint NO_DD_COMMIT
Don't commit transaction after updating data-dictionary while renaming the table.
Definition: sql_table.h:88
bool collect_fk_parents_for_new_fks(THD *thd, const char *db_name, const char *table_name, const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton, MDL_request_list *mdl_requests, Foreign_key_parents_invalidator *fk_invalidator)
Add MDL requests for lock of specified type on tables referenced by the foreign keys to be added by t...
Definition: sql_table.cc:10822
bool lock_check_constraint_names_for_rename(THD *thd, const char *db, const char *table_name, const dd::Table *table_def, const char *target_db, const char *target_table_name)
Method to lock check constraint names for rename table operation.
Definition: sql_table.cc:20962
static const uint FN_TO_IS_TMP
Definition: sql_table.h:80
int write_bin_log(THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans=false)
Definition: sql_table.cc:1265
size_t tablename_to_filename(const char *from, char *to, size_t to_length)
Definition: sql_table.cc:845
void promote_first_timestamp_column(List< Create_field > *column_definitions)
Modifies the first column definition whose SQL type is TIMESTAMP by adding the features DEFAULT CURRE...
Definition: sql_table.cc:4384
bool adjust_fk_parents(THD *thd, const char *db, const char *name, bool reload_self, const Foreign_key_parents_invalidator *fk_invalidator)
Definition: sql_table.cc:10275
bool lock_trigger_names(THD *thd, Table_ref *tables)
Acquire metadata lock on triggers associated with a list of tables.
Definition: sql_table.cc:1280
bool lock_check_constraint_names(THD *thd, Table_ref *tables)
Method to collect check constraint names for the all the tables and acquire MDL lock on them.
Definition: sql_table.cc:21022
bool quick_rm_table(THD *thd, handlerton *base, const char *db, const char *table_name, uint flags)
Quickly remove a table.
Definition: sql_table.cc:4021
bool rm_table_do_discovery_and_lock_fk_tables(THD *thd, Table_ref *tables)
Discover missing tables in SE and acquire locks on tables which participate in FKs on tables to be dr...
Definition: sql_table.cc:1450
bool mysql_prepare_create_table(THD *thd, const char *error_schema_name, const char *error_table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file, bool is_partitioned, KEY **key_info_buffer, uint *key_count, FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count, FOREIGN_KEY *existing_fks, uint existing_fks_count, const dd::Table *existing_fks_table, uint fk_max_generated_name_number, int select_field_count, bool find_parent_keys)
Prepares the table and key structures for table creation.
Definition: sql_table.cc:8306
bool collect_fk_names_for_new_fks(THD *thd, const char *db_name, const char *table_name, const Alter_info *alter_info, handlerton *hton, uint fk_max_generated_name_number, MDL_request_list *mdl_requests)
Add MDL requests for exclusive metadata locks on names of foreign keys to be added by the CREATE TABL...
Definition: sql_table.cc:10859
bool adjust_adopted_self_ref_fk_for_simple_rename_table(THD *thd, const char *db, const char *table_name, const char *new_db, const char *new_table_name, handlerton *hton)
As a result of simple rename table operation, orphan non-self-referencing foreign keys may become non...
Definition: sql_table.cc:16850
std::atomic_ullong deprecated_use_fk_on_non_standard_key_last_timestamp
Last time fk is created on non standard index key, as usec since epoch.
Definition: sql_table.cc:225
handlerton * get_viable_handlerton_for_create(THD *thd, const char *table_name, const HA_CREATE_INFO &ci)
Checks if the handlerton for the specified ENGINE is enabled AND NOT explicitly disabled (listed in t...
Definition: sql_table.cc:439
const CHARSET_INFO * get_sql_field_charset(const Create_field *sql_field, const HA_CREATE_INFO *create_info)
Get the character set from field object generated by the parser, using default values when not set.
Definition: sql_table.cc:4345
mysql_mutex_t mysql_mutex_t
Definition: sql_table.h:66
bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, bool *metadata_equal)
Compare two tables to see if their metadata are compatible.
Definition: sql_table.cc:13771
bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table, TABLE *table, HA_CREATE_INFO *create_info, Alter_info *alter_info, Alter_table_ctx *alter_ctx)
Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
Definition: sql_table.cc:16452
bool prepare_sp_create_field(THD *thd, Create_field *field_def)
Prepare an instance of Create_field for field creation (fill all necessary attributes).
Definition: sql_table.cc:4324
bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db, const char *old_name, const char *old_fk_db, const char *old_fk_name, const dd::Schema &new_schema, const char *new_db, const char *new_name, uint flags)
Rename a table.
Definition: sql_table.cc:11511
bool mysql_rm_table_no_locks(THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary, bool drop_database, const char *database_name, const bool should_drop_schema_ddl_log, bool *dropped_non_atomic_flag, std::set< handlerton * > *post_ddl_htons, Foreign_key_parents_invalidator *fk_invalidator, std::vector< MDL_ticket * > *safe_to_release_mdl)
Execute the drop of a normal or temporary table.
Definition: sql_table.cc:3286
bool collect_fk_children(THD *thd, const char *schema, const char *table_name, handlerton *hton, enum_mdl_type lock_type, MDL_request_list *mdl_requests)
Add MDL requests for specified lock type on all tables referencing the given schema qualified table n...
Definition: sql_table.cc:10207
bool prepare_fk_parent_key(THD *thd, handlerton *hton, const dd::Table *parent_table_def, const dd::Table *old_parent_table_def, const dd::Table *old_child_table_def, bool is_self_referencing_fk, dd::Foreign_key *fk)
Definition: sql_table.cc:6717
bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table, HA_CREATE_INFO *create_info, Alter_info *alter_info, Alter_table_ctx *alter_ctx, const uint &used_fields)
Prepare Create_field and Key_spec objects for ALTER and upgrade.
Definition: sql_table.cc:15768
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:235
size_t filename_to_tablename(const char *from, char *to, size_t to_length, bool stay_quiet=false, bool *has_errors=nullptr)
Definition: sql_table.cc:800
bool prepare_pack_create_field(THD *thd, Create_field *sql_field, longlong table_flags)
Prepare a create_table instance for packing.
Definition: sql_table.cc:4172
static const uint NO_CC_RENAME
Don't change generated check constraint names while renaming table.
Definition: sql_table.h:92
static const uint FN_FROM_IS_TMP
Definition: sql_table.h:79
bool mysql_rm_table(THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary)
Definition: sql_table.cc:1613
size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen)
Create path to a temporary table, like mysql_tmpdir/#sql1234_12_1 (i.e.
Definition: sql_table.cc:952
static const uint FN_IS_TMP
Definition: sql_table.h:81
static const uint NO_FK_RENAME
Don't change generated foreign key names while renaming table.
Definition: sql_table.h:90
size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length, enum_explain_filename_mode explain_mode)
Explain a path name by split it to database, table etc.
Definition: sql_table.cc:646
bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table, HA_CREATE_INFO *create_info, uint open_flags=0, bool skip_post_ddl_operations=false)
Definition: sql_table.cc:11754
bool mysql_create_table_no_lock(THD *thd, const char *db, const char *table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, uint select_field_count, bool find_parent_keys, bool *is_trans, handlerton **post_ddl_ht)
Simple wrapper around create_table_impl() to be used in various version of CREATE TABLE statement.
Definition: sql_table.cc:10032
bool mysql_create_table(THD *thd, Table_ref *create_table, HA_CREATE_INFO *create_info, Alter_info *alter_info)
Implementation of SQLCOM_CREATE_TABLE.
Definition: sql_table.cc:10937
bool collect_and_lock_fk_tables_for_rename_table(THD *thd, const char *db, const char *table_name, const dd::Table *table_def, const char *new_db, const char *new_table_name, handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator)
Acquire exclusive metadata locks on tables which definitions need to be updated or invalidated since ...
Definition: sql_table.cc:16826
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf)
Set the fields in an array to point to a new record buffer.
Definition: sql_table.cc:13660
std::atomic_ulong deprecated_use_fk_on_non_standard_key_count
Count number of times foreign key is created on non standard index keys.
Definition: sql_table.cc:222
bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, HA_CREATE_INFO *create_info, Table_ref *table_list, Alter_info *alter_info)
Alter table.
Definition: sql_table.cc:17445
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table, const char *ext, uint flags, bool *was_truncated)
Definition: sql_table.cc:894
bool secondary_engine_unload_table_inner(THD *thd, const char *db_name, const char *table_name, LEX_CSTRING secondary_engine, bool is_partitioned, bool error_if_not_loaded)
Resolves the secondary engine handled via its name and calls the unload table function.
Definition: sql_table.cc:2868
bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy)
Definition: sql_table.cc:19921
bool secondary_engine_unload_materialized_view(THD *thd, const Table_ref *view, const dd::View *view_def)
Unloads the materialized view from a secondary engine, where it might be materialized.
Definition: sql_table.cc:2852
bool prepare_create_field(THD *thd, const char *error_schema_name, const char *error_table_name, HA_CREATE_INFO *create_info, List< Create_field > *create_list, int *select_field_pos, handler *file, Create_field *sql_field, int field_no)
Prepares the column definitions for table creation.
Definition: sql_table.cc:4706
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table's copy phase.
Definition: sql_table.cc:19557
static const uint NO_FK_CHECKS
Don't check foreign key constraints while renaming table.
Definition: sql_table.h:83
bool adjust_fks_for_rename_table(THD *thd, const char *db, const char *table_name, const char *new_db, const char *new_table_name, handlerton *hton)
Update referenced table names and the unique constraint name for FKs affected by RENAME TABLE operati...
Definition: sql_table.cc:16889
enum_explain_filename_mode
Definition: sql_table.h:72
@ EXPLAIN_PARTITIONS_VERBOSE
Definition: sql_table.h:74
@ EXPLAIN_ALL_VERBOSE
Definition: sql_table.h:73
@ EXPLAIN_PARTITIONS_AS_COMMENT
Definition: sql_table.h:75
TYPELIB * create_typelib(MEM_ROOT *mem_root, Create_field *field_def)
Definition: sql_table.cc:4263
bool adjust_fk_children_after_parent_def_change(THD *thd, bool check_charsets, const char *parent_table_db, const char *parent_table_name, handlerton *hton, const dd::Table *parent_table_def, Alter_info *parent_alter_info, bool invalidate_tdc)
Check if new definition of parent table is compatible with foreign keys which reference it.
Definition: sql_table.cc:10575
bool validate_comment_length(THD *thd, const char *comment_str, size_t *comment_len, uint max_len, uint err_code, const char *comment_name)
check comment length of table, column, index and partition
Definition: sql_table.cc:8777
bool prepare_check_constraints_for_create(THD *thd, const char *db_name, const char *table_name, Alter_info *alter_info)
Method to prepare check constraints for the CREATE operation.
Definition: sql_table.cc:20236
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:19577
bool mysql_checksum_table(THD *thd, Table_ref *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:19947
bool mysql_discard_or_import_tablespace(THD *thd, Table_ref *table_list)
bool verify_data_with_check_constraints(TABLE *table, TABLE *check_table)
Verify that all rows in a table satisfy another table's CHECK constraints.
Definition: sql_table.cc:13679
bool validate_secondary_engine_temporary_table(THD *thd, HA_CREATE_INFO *create_info)
Validation on create temporary table statements with secondary engine defined:
Definition: sql_table.cc:9042
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: handler.h:3966
Struct to hold information about the table that should be created.
Definition: handler.h:3356
Metadata lock object key.
Definition: mdl.h:366
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: table.h:1456
Definition: typelib.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2852
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50