MySQL 9.5.0
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2025, 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 FOREIGN_KEY;
48class KEY;
49class THD;
50class handler;
51struct CHARSET_INFO;
52struct MEM_ROOT;
53struct TABLE;
54class Table_ref;
55struct handlerton;
56
57namespace dd {
58class Foreign_key;
59class Schema;
60class Table;
61class View;
62} // namespace dd
63
64struct HA_CHECK_OPT;
65struct HA_CREATE_INFO;
66
68template <typename T>
69class List;
70
75};
76
77/* Flags for conversion functions. */
78static const uint FN_FROM_IS_TMP = 1 << 0;
79static const uint FN_TO_IS_TMP = 1 << 1;
81/** Don't check foreign key constraints while renaming table */
82static const uint NO_FK_CHECKS = 1 << 2;
83/**
84 Don't commit transaction after updating data-dictionary while renaming
85 the table.
86*/
87static const uint NO_DD_COMMIT = 1 << 3;
88/** Don't change generated foreign key names while renaming table. */
89static const uint NO_FK_RENAME = 1 << 4;
90/** Don't change generated check constraint names while renaming table. */
91static const uint NO_CC_RENAME = 1 << 5;
92
94 const HA_CREATE_INFO &ci);
95
96size_t filename_to_tablename(const char *from, char *to, size_t to_length,
97 bool stay_quiet = false,
98 bool *has_errors = nullptr);
99size_t tablename_to_filename(const char *from, char *to, size_t to_length);
100size_t build_table_filename(char *buff, size_t bufflen, const char *db,
101 const char *table, const char *ext, uint flags,
102 bool *was_truncated);
103// For caller's who are mostly sure that path do not truncate
104size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
105 const char *table, const char *ext,
106 uint flags) {
107 bool truncated_not_used;
108 return build_table_filename(buff, bufflen, db, table, ext, flags,
109 &truncated_not_used);
110}
111size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
113 HA_CREATE_INFO *create_info, Alter_info *alter_info);
114bool mysql_create_table_no_lock(THD *thd, const char *db,
115 const char *table_name,
116 HA_CREATE_INFO *create_info,
117 Alter_info *alter_info, uint select_field_count,
118 bool find_parent_keys, bool *is_trans,
119 handlerton **post_ddl_ht);
121
122/**
123 Helper class for keeping track for which tables we need to invalidate
124 data-dictionary cache entries and performing such invalidation.
125*/
127 private:
131 };
132 typedef std::map<std::pair<dd::String_type, dd::String_type>,
133 std::pair<handlerton *, enum_invalidation_type>>
136
137 public:
138 void add(
139 const char *db_name, const char *table_name, handlerton *hton,
141 // Usually tables added to a Foreign_key_parents_invalidator instance are
142 // closed by the invalidate member function. However, occasionally tables
143 // are added that we subsequently discover should only be invalidated and
144 // not closed by the invalidate member function as they will be closed
145 // elsewhere.
146 // See bool Query_result_create::send_eof(THD *thd) for an example.
147 // The mark_for_reopen_if_added member function updates the
148 // corresponding Parent_map entry if necessary in this situation.
149 void mark_for_reopen_if_added(const char *db_name, const char *table_name);
150 void invalidate(THD *thd);
151 const Parent_map &parents() const { return m_parent_map; }
152 bool is_empty() const { return m_parent_map.empty(); }
153 void clear() { m_parent_map.clear(); }
154};
155
156/**
157 Auxiliary class implementing RAII principle for getting permission for/
158 notification about finished DDL statements from interested storage engines.
159
160 @see handlerton::ha_notify_table_ddl for details.
161*/
163 public:
165 THD *thd, const MDL_key *key, ha_ddl_type ddl_type,
166 const char *old_db_name = nullptr, const char *old_table_name = nullptr,
167 const char *new_db_name = nullptr,
168 const char *new_table_name = nullptr) noexcept
169 : m_hton_notified(false),
170 m_thd(thd),
171 m_key(*key),
172 m_ddl_type(ddl_type),
173 m_old_db_name(old_db_name),
174 m_old_table_name(old_table_name),
175 m_new_db_name(new_db_name),
176 m_new_table_name(new_table_name) {}
177
178 [[nodiscard]] bool notify() noexcept {
182 m_hton_notified = true;
183 return false;
184 }
185 my_error(ER_LOCK_REFUSED_BY_ENGINE, MYF(0));
186 return true;
187 }
188
190 if (m_hton_notified)
194 }
195
196 private:
201 const char *m_old_db_name;
202 const char *m_old_table_name;
203 const char *m_new_db_name;
204 const char *m_new_table_name;
205};
206
207/*
208 Reload the foreign key parent information of the referenced
209 tables and for the table itself.
210
211 @param thd Thread handle.
212 @param db Table schema name.
213 @param name Table name.
214 @param reload_self Reload FK parent info also for the
215 table itself.
216 @param fk_invalidator Object keeping track of which dd::Table
217 objects to invalidate. If submitted, use this
218 to restrict which FK parents should have their
219 FK parent information reloaded.
220
221 @retval operation outcome, false if no error.
222*/
223bool adjust_fk_parents(THD *thd, const char *db, const char *name,
224 bool reload_self,
225 const Foreign_key_parents_invalidator *fk_invalidator);
226
227/**
228 Check if new definition of parent table is compatible with foreign keys
229 which reference it. Update the unique constraint names and referenced
230 column names for the foreign keys accordingly.
231
232 @param thd Thread handle.
233 @param check_charsets Indicates whether we need to check charsets of
234 columns participating in foreign keys.
235 @param parent_table_db Parent table schema name.
236 @param parent_table_name Parent table name.
237 @param hton Handlerton for table's storage engine.
238 @param parent_table_def Table object representing the referenced table.
239 @param parent_alter_info Alter_info containing information about renames
240 of parent columns. Can be nullptr if there are
241 no such renames.
242 @param invalidate_tdc Indicates whether we need to invalidate TDC for
243 referencing tables after updating their
244 definitions.
245
246 @retval operation outcome, false if no error.
247*/
249 THD *thd, bool check_charsets, const char *parent_table_db,
250 const char *parent_table_name, handlerton *hton,
251 const dd::Table *parent_table_def, Alter_info *parent_alter_info,
252 bool invalidate_tdc);
253
254/**
255 Check if new definition of parent table is compatible with foreign keys
256 which reference it. Update the unique constraint names and referenced
257 column names for the foreign keys accordingly. Do mandatory character
258 set checks and TDC invalidation.
259*/
261 THD *thd, const char *parent_table_db, const char *parent_table_name,
262 handlerton *hton, const dd::Table *parent_table_def,
263 Alter_info *parent_alter_info) {
265 thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
266 parent_alter_info, true);
267}
268
269/**
270 Add MDL requests for specified lock type on all tables referencing the given
271 schema qualified table name to the list.
272
273 @param thd Thread handle.
274 @param schema Schema name.
275 @param table_name Table name.
276 @param hton Handlerton for table's storage engine.
277 @param lock_type Type of MDL requests to add.
278 @param[in,out] mdl_requests List to which MDL requests are to be added.
279
280 @retval operation outcome, false if no error.
281*/
282[[nodiscard]] bool collect_fk_children(THD *thd, const char *schema,
283 const char *table_name, handlerton *hton,
284 enum_mdl_type lock_type,
285 MDL_request_list *mdl_requests);
286
287/**
288 Add MDL requests for lock of specified type on tables referenced by the
289 foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
290 Also add the referenced table names to the foreign key invalidator,
291 to be used at a later stage to invalidate the dd::Table objects.
292
293 @param thd Thread handle.
294 @param db_name Table's database name.
295 @param table_name Table name.
296 @param alter_info Alter_info object with the list of FKs
297 to be added.
298 @param lock_type Type of metadata lock to be requested.
299 @param hton Handlerton for table's storage engine.
300 @param[in,out] mdl_requests List to which MDL requests are to be added.
301 @param[in,out] fk_invalidator Object keeping track of which dd::Table
302 objects to invalidate.
303
304 @retval operation outcome, false if no error.
305*/
306[[nodiscard]] bool collect_fk_parents_for_new_fks(
307 THD *thd, const char *db_name, const char *table_name,
308 const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
309 MDL_request_list *mdl_requests,
310 Foreign_key_parents_invalidator *fk_invalidator);
311
312/**
313 Add MDL requests for exclusive metadata locks on names of foreign keys
314 to be added by the CREATE TABLE or ALTER TABLE operation.
315
316 @param thd Thread context.
317 @param db_name Table's database name.
318 @param table_name Table name.
319 @param alter_info Alter_info object with the
320 list of FKs to be added.
321 @param hton Table's storage engine.
322 @param fk_max_generated_name_number Max value of number component
323 among existing generated foreign
324 key names.
325 @param[in,out] mdl_requests List to which MDL requests
326 are to be added.
327
328 @retval operation outcome, false if no error.
329*/
330bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
331 const char *table_name,
332 const Alter_info *alter_info,
333 handlerton *hton,
334 uint fk_max_generated_name_number,
335 MDL_request_list *mdl_requests);
336
337/**
338 Acquire exclusive metadata locks on tables which definitions need to
339 be updated or invalidated since they are related through foreign keys
340 to the table to be renamed,
341 Also add the referenced table names for the FKs on this table to the
342 foreign key invalidator, to be used at a later stage to invalidate the
343 dd::Table objects.
344
345 @param thd Thread handle.
346 @param db Table's old schema.
347 @param table_name Table's old name.
348 @param table_def Table definition of table being RENAMEd.
349 @param new_db Table's new schema.
350 @param new_table_name Table's new name.
351 @param hton Table's SE.
352 @param[in,out] fk_invalidator Object keeping track of which dd::Table
353 objects to invalidate.
354
355 @retval operation outcome, false if no error.
356*/
358 THD *thd, const char *db, const char *table_name,
359 const dd::Table *table_def, const char *new_db, const char *new_table_name,
360 handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator);
361
362/**
363 As a result of simple rename table operation, orphan non-self-referencing
364 foreign keys may become non-orphan/adopted self-referencing foreign keys.
365 For such transformed foreign key, check that table has compatible referenced
366 column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
367
368 @param thd Thread handle.
369 @param db Table's old schema.
370 @param table_name Table's old name.
371 @param new_db Table's new schema.
372 @param new_table_name Table's new name.
373 @param hton Table's SE.
374
375 @retval operation outcome, false if no error.
376*/
378 THD *thd, const char *db, const char *table_name, const char *new_db,
379 const char *new_table_name, handlerton *hton);
380
381/**
382 Update referenced table names and the unique constraint name for FKs
383 affected by RENAME TABLE operation.
384
385 @param thd Thread handle.
386 @param db Table's old schema.
387 @param table_name Table's old name.
388 @param new_db Table's new schema.
389 @param new_table_name Table's new name.
390 @param hton Table's SE.
391
392 @retval operation outcome, false if no error.
393*/
394[[nodiscard]] bool adjust_fks_for_rename_table(THD *thd, const char *db,
395 const char *table_name,
396 const char *new_db,
397 const char *new_table_name,
398 handlerton *hton);
399
400/*
401 Check if parent key for the foreign key exists, set foreign key's unique
402 constraint name accordingly. Emit error if no parent key found.
403
404 @note Prefer unique key if possible. If parent key is non-unique
405 unique constraint name is set to NULL.
406
407 @note DDL code use this function for non-self-referencing foreign keys.
408
409 @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
410
411 @param thd Thread handle.
412 @param hton Handlerton for tables' storage engine.
413 @param parent_table_def Object describing new version of parent table.
414 @param old_child_table_def Object describing old version of child table.
415 Can be nullptr if old_parent_table_def is
416 nullptr. Used for error reporting.
417 @param old_parent_table_def Object describing old version of parent table.
418 nullptr indicates that this is not ALTER TABLE
419 operation. Used for error reporting.
420 @param is_self_referencing_fk If the parent and child is the same table.
421 @param fk[in,out] Object describing the foreign key,
422 its unique_constraint_name member
423 will be updated if matching parent
424 unique constraint is found.
425
426 @retval Operation result. False if success.
427*/
428[[nodiscard]] bool prepare_fk_parent_key(THD *thd, handlerton *hton,
429 const dd::Table *parent_table_def,
430 const dd::Table *old_parent_table_def,
431 const dd::Table *old_child_table_def,
432 bool is_self_referencing_fk,
433 dd::Foreign_key *fk);
434
435/**
436 Prepare Create_field and Key_spec objects for ALTER and upgrade.
437 @param[in,out] thd thread handle. Used as a memory pool
438 and source of environment information.
439 @param[in] src_table DD table object. Will be nullptr for temporary
440 tables and during upgrade.
441 @param[in] table the source table, open and locked
442 Used as an interface to the storage engine
443 to acquire additional information about
444 the original table.
445 @param[in,out] create_info A blob with CREATE/ALTER TABLE
446 parameters
447 @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
448 Originally create_info was used only in
449 CREATE TABLE and alter_info only in ALTER TABLE.
450 But since ALTER might end-up doing CREATE,
451 this distinction is gone and we just carry
452 around two structures.
453 @param[in,out] alter_ctx Runtime context for ALTER TABLE.
454 @param[in] used_fields used_fields from HA_CREATE_INFO.
455
456 @retval true error, out of memory or a semantical error in ALTER
457 TABLE instructions
458 @retval false success
459
460*/
461bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
462 HA_CREATE_INFO *create_info,
463 Alter_info *alter_info, Alter_table_ctx *alter_ctx,
464 const uint &used_fields);
465
466bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
467 TABLE *table, HA_CREATE_INFO *create_info,
468 Alter_info *alter_info,
469 Alter_table_ctx *alter_ctx);
472bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
473 HA_CREATE_INFO *create_info, Table_ref *table_list,
474 Alter_info *alter_info);
475bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info,
476 HA_CREATE_INFO *create_info, bool *metadata_equal);
477bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy);
478bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table,
479 HA_CREATE_INFO *create_info);
480bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
481 const char *old_name, const char *old_fk_db,
482 const char *old_fk_name, const dd::Schema &new_schema,
483 const char *new_db, const char *new_name, uint flags);
484
485bool mysql_checksum_table(THD *thd, Table_ref *table_list,
486 HA_CHECK_OPT *check_opt);
487bool mysql_rm_table(THD *thd, Table_ref *tables, bool if_exists,
488 bool drop_temporary);
489bool mysql_rm_table_no_locks(THD *thd, Table_ref *tables, bool if_exists,
490 bool drop_temporary, bool drop_database,
491 const char *database_name,
492 const bool should_drop_schema_ddl_log,
493 bool *dropped_non_atomic_flag,
494 std::set<handlerton *> *post_ddl_htons,
495 Foreign_key_parents_invalidator *fk_invalidator,
496 std::vector<MDL_ticket *> *safe_to_release_mdl);
497
498/**
499 Discover missing tables in SE and acquire locks on tables which participate
500 in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
501 will have to be updated or invalidated during this operation.
502
503 @param thd Thread context.
504 @param tables Tables to be dropped by DROP TABLES/DATABASE.
505
506 @retval False - Success.
507 @retval True - Failure.
508*/
509[[nodiscard]] bool rm_table_do_discovery_and_lock_fk_tables(THD *thd,
510 Table_ref *tables);
511
512bool quick_rm_table(THD *thd, handlerton *base, const char *db,
513 const char *table_name, uint flags);
514bool prepare_sp_create_field(THD *thd, Create_field *field_def);
515bool prepare_pack_create_field(THD *thd, Create_field *sql_field,
516 longlong table_flags);
517
518const CHARSET_INFO *get_sql_field_charset(const Create_field *sql_field,
519 const HA_CREATE_INFO *create_info);
520bool validate_comment_length(THD *thd, const char *comment_str,
521 size_t *comment_len, uint max_len, uint err_code,
522 const char *comment_name);
523int write_bin_log(THD *thd, bool clear_error, const char *query,
524 size_t query_length, bool is_trans = false);
525void promote_first_timestamp_column(List<Create_field> *column_definitions);
526
527/**
528 Prepares the column definitions for table creation.
529
530 @param thd Thread object.
531 @param error_schema_name Schema name of the table used for error
532 reporting.
533 @param error_table_name Table name used for error reporting.
534 @param create_info Create information.
535 @param[in,out] create_list List of columns to create.
536 @param[in,out] select_field_pos Position where the SELECT columns start
537 for CREATE TABLE ... SELECT.
538 @param file The handler for the new table.
539 @param[in,out] sql_field Create_field to populate.
540 @param field_no Column number.
541
542 @retval false OK
543 @retval true error
544*/
545
546bool prepare_create_field(THD *thd, const char *error_schema_name,
547 const char *error_table_name,
548 HA_CREATE_INFO *create_info,
549 List<Create_field> *create_list,
550 int *select_field_pos, handler *file,
551 Create_field *sql_field, int field_no);
552
553/**
554 Prepares the table and key structures for table creation.
555
556 @param thd Thread object.
557 @param error_schema_name Schema name of the table to create/alter,
558 only error reporting.
559 @param error_table_name Name of table to create/alter, only used for
560 error reporting.
561 @param create_info Create information (like MAX_ROWS).
562 @param alter_info List of columns and indexes to create
563 @param file The handler for the new table.
564 @param is_partitioned Indicates whether table is partitioned.
565 @param[out] key_info_buffer An array of KEY structs for the indexes.
566 @param[out] key_count The number of elements in the array.
567 @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
568 foreign keys.
569 @param[out] fk_key_count The number of elements in the array.
570 @param[in] existing_fks An array of pre-existing FOREIGN KEYS
571 (in case of ALTER).
572 @param[in] existing_fks_count The number of pre-existing foreign keys.
573 @param[in] existing_fks_table dd::Table object for table version from
574 which pre-existing foreign keys come from.
575 Needed for error reporting.
576 @param[in] fk_max_generated_name_number Max value of number component among
577 existing generated foreign key names.
578 @param select_field_count The number of fields coming from a select
579 table.
580 @param find_parent_keys Indicates whether we need to lookup name of
581 unique constraint in parent table for foreign
582 keys.
583
584 @retval false OK
585 @retval true error
586*/
587
589 THD *thd, const char *error_schema_name, const char *error_table_name,
590 HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
591 bool is_partitioned, KEY **key_info_buffer, uint *key_count,
592 FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
593 FOREIGN_KEY *existing_fks, uint existing_fks_count,
594 const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
595 int select_field_count, bool find_parent_keys);
596
597size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
598 enum_explain_filename_mode explain_mode);
599
600extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
601
602/**
603 Acquire metadata lock on triggers associated with a list of tables.
604
605 @param[in] thd Current thread context
606 @param[in] tables Tables for that associated triggers have to locked.
607
608 @return Operation status.
609 @retval false Success
610 @retval true Failure
611*/
612
613bool lock_trigger_names(THD *thd, Table_ref *tables);
614struct TYPELIB;
616
617/**
618 Method to collect check constraint names for the all the tables and acquire
619 MDL lock on them.
620
621 @param[in] thd Thread handle.
622 @param[in] tables Check constraints of tables to be locked.
623
624 @retval false Success.
625 @retval true Failure.
626*/
627bool lock_check_constraint_names(THD *thd, Table_ref *tables);
628
629/**
630 Method to lock check constraint names for rename table operation.
631 Method acquire locks on the constraint names of source table and
632 also on the name of check constraint in the target table.
633
634 @param[in] thd Thread handle.
635 @param[in] db Database name.
636 @param[in] table_name Table name.
637 @param[in] table_def DD table object of source table.
638 @param[in] target_db Target database name.
639 @param[in] target_table_name Target table name.
640
641 @retval false Success.
642 @retval true Failure.
643*/
644bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
645 const char *table_name,
646 const dd::Table *table_def,
647 const char *target_db,
648 const char *target_table_name);
649
650/**
651 Method to prepare check constraints for the CREATE operation. If name of the
652 check constraint is not specified then name is generated, check constraint
653 is pre-validated and MDL on check constraint is acquired.
654
655 @param thd Thread handle.
656 @param db_name Database name.
657 @param table_name Table name.
658 @param alter_info Alter_info object with list of
659 check constraints to be created.
660
661 @retval false Success.
662 @retval true Failure.
663*/
665 const char *table_name,
666 Alter_info *alter_info);
667
668extern std::atomic_ulong deprecated_use_fk_on_non_standard_key_count;
670
671/**
672 Unloads the materialized view from a secondary engine, where it might be
673 materialized.
674 */
676 const dd::View *view_def);
677
678/**
679 Resolves the secondary engine handled via its name and calls the unload
680 table function
681*/
682bool secondary_engine_unload_table_inner(THD *thd, const char *db_name,
683 const char *table_name,
685 bool is_partitioned,
686 bool error_if_not_loaded);
687
688/**
689 Validation on create temporary table statements with secondary engine defined:
690 1. Check that the create table statement contains a query.
691 2. Set the lex state indicating that the query can execute only
692 on the secondary engine.
693*/
695 HA_CREATE_INFO *create_info);
696
697#endif /* SQL_TABLE_INCLUDED */
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:205
Runtime context for ALTER TABLE.
Definition: sql_alter.h:516
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
Helper class for keeping track for which tables we need to invalidate data-dictionary cache entries a...
Definition: sql_table.h:126
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:151
enum_invalidation_type
Definition: sql_table.h:128
@ INVALIDATE_AND_MARK_FOR_REOPEN
Definition: sql_table.h:130
@ INVALIDATE_AND_CLOSE_TABLE
Definition: sql_table.h:129
std::map< std::pair< dd::String_type, dd::String_type >, std::pair< handlerton *, enum_invalidation_type > > Parent_map
Definition: sql_table.h:134
void clear()
Definition: sql_table.h:153
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:135
bool is_empty() const
Definition: sql_table.h:152
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:162
bool m_hton_notified
Definition: sql_table.h:197
const MDL_key m_key
Definition: sql_table.h:199
THD * m_thd
Definition: sql_table.h:198
bool notify() noexcept
Definition: sql_table.h:178
const char * m_old_db_name
Definition: sql_table.h:201
const char * m_new_table_name
Definition: sql_table.h:204
const ha_ddl_type m_ddl_type
Definition: sql_table.h:200
const char * m_old_table_name
Definition: sql_table.h:202
const char * m_new_db_name
Definition: sql_table.h:203
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:164
~Table_ddl_hton_notification_guard()
Definition: sql_table.h:189
Definition: table.h:2933
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:4741
A table definition from the master.
Definition: rpl_utility.h:249
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 *identity)
Create instrumentation for a table instance.
Definition: pfs_instr.cc:1307
static int flags[50]
Definition: hp_test1.cc:40
Some integer typedefs for easier portability.
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:43
Definition: os0file.h:89
Json_data_extension ext
Definition: backend.cc:50
entry::Table Table
Definition: select.h:51
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:8926
ha_ddl_type
Definition: handler.h:964
@ HA_NOTIFY_POST_EVENT
Definition: handler.h:963
@ HA_NOTIFY_PRE_EVENT
Definition: handler.h:963
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:87
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:10774
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:20721
static const uint FN_TO_IS_TMP
Definition: sql_table.h:79
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:4364
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:10227
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:20781
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:4007
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:8263
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:10811
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:16623
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:224
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:438
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:4331
mysql_mutex_t mysql_mutex_t
Definition: sql_table.h:65
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:13587
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:16225
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:4310
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:11460
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:3276
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:10159
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:6690
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:15558
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:234
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:4158
static const uint NO_CC_RENAME
Don't change generated check constraint names while renaming table.
Definition: sql_table.h:91
static const uint FN_FROM_IS_TMP
Definition: sql_table.h:78
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:80
static const uint NO_FK_RENAME
Don't change generated foreign key names while renaming table.
Definition: sql_table.h:89
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:645
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:9984
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:10889
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:16599
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:221
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:17218
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:2858
bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy)
Definition: sql_table.cc:19688
bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table, HA_CREATE_INFO *create_info)
Definition: sql_table.cc:11703
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:2842
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:4686
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table's copy phase.
Definition: sql_table.cc:19330
static const uint NO_FK_CHECKS
Don't check foreign key constraints while renaming table.
Definition: sql_table.h:82
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:16662
enum_explain_filename_mode
Definition: sql_table.h:71
@ EXPLAIN_PARTITIONS_VERBOSE
Definition: sql_table.h:73
@ EXPLAIN_ALL_VERBOSE
Definition: sql_table.h:72
@ EXPLAIN_PARTITIONS_AS_COMMENT
Definition: sql_table.h:74
TYPELIB * create_typelib(MEM_ROOT *mem_root, Create_field *field_def)
Definition: sql_table.cc:4249
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:10527
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:8729
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:20003
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:19350
bool mysql_checksum_table(THD *thd, Table_ref *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:19714
bool mysql_discard_or_import_tablespace(THD *thd, Table_ref *table_list)
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:8994
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: handler.h:3954
Struct to hold information about the table that should be created.
Definition: handler.h:3347
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:1435
Definition: typelib.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2851
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50