MySQL 8.0.31
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_TABLE_INCLUDED
24#define SQL_TABLE_INCLUDED
25
26#include <stddef.h>
27#include <sys/types.h>
28
29#include <map>
30#include <set>
31#include <string>
32#include <utility>
33#include <vector>
34
35#include "my_inttypes.h"
36#include "my_sharedlib.h"
38#include "mysqld_error.h"
39#include "sql/dd/string_type.h"
40#include "sql/handler.h"
41#include "sql/mdl.h"
42
43class Alter_info;
44class Alter_table_ctx;
45class Create_field;
46class FOREIGN_KEY;
47class KEY;
48class THD;
49class handler;
50struct CHARSET_INFO;
51struct MEM_ROOT;
52struct TABLE;
53struct TABLE_LIST;
54struct handlerton;
55
56namespace dd {
57class Foreign_key;
58class Schema;
59class Table;
60} // namespace dd
61
62struct HA_CHECK_OPT;
63struct HA_CREATE_INFO;
64
66template <typename T>
67class List;
68
73};
74
75/* Flags for conversion functions. */
76static const uint FN_FROM_IS_TMP = 1 << 0;
77static const uint FN_TO_IS_TMP = 1 << 1;
79/** Don't check foreign key constraints while renaming table */
80static const uint NO_FK_CHECKS = 1 << 2;
81/**
82 Don't commit transaction after updating data-dictionary while renaming
83 the table.
84*/
85static const uint NO_DD_COMMIT = 1 << 3;
86/** Don't change generated foreign key names while renaming table. */
87static const uint NO_FK_RENAME = 1 << 4;
88/** Don't change generated check constraint names while renaming table. */
89static const uint NO_CC_RENAME = 1 << 5;
90
91// MDL lock types used for ALTER TABLE SECONDARY_LOAD.
92
93/** The MDL type used when initially opening a table for SECONDARY_LOAD */
95
96/**
97 The weaker MDL which the secondary engine plugin may downgrade to after
98 a parallel scan has been started
99*/
101
102/**
103 The MDL which must be acquired before the old table definition
104 can be evicted from the table definition cache.
105*/
107
109 const HA_CREATE_INFO &ci);
110
111size_t filename_to_tablename(const char *from, char *to, size_t to_length,
112 bool stay_quiet = false,
113 bool *has_errors = nullptr);
114size_t tablename_to_filename(const char *from, char *to, size_t to_length);
115size_t build_table_filename(char *buff, size_t bufflen, const char *db,
116 const char *table, const char *ext, uint flags,
117 bool *was_truncated);
118// For caller's who are mostly sure that path do not truncate
119size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
120 const char *table, const char *ext,
121 uint flags) {
122 bool truncated_not_used;
123 return build_table_filename(buff, bufflen, db, table, ext, flags,
124 &truncated_not_used);
125}
126size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
128 HA_CREATE_INFO *create_info, Alter_info *alter_info);
129bool mysql_create_table_no_lock(THD *thd, const char *db,
130 const char *table_name,
131 HA_CREATE_INFO *create_info,
132 Alter_info *alter_info, uint select_field_count,
133 bool find_parent_keys, bool *is_trans,
134 handlerton **post_ddl_ht);
136
137/**
138 Helper class for keeping track for which tables we need to invalidate
139 data-dictionary cache entries and performing such invalidation.
140*/
142 private:
143 typedef std::map<std::pair<dd::String_type, dd::String_type>, handlerton *>
146
147 public:
148 void add(const char *db_name, const char *table_name, handlerton *hton);
149 void invalidate(THD *thd);
150 const Parent_map &parents() const { return m_parent_map; }
151 bool is_empty() const { return m_parent_map.empty(); }
152 void clear() { m_parent_map.clear(); }
153};
154
155/**
156 Auxiliary class implementing RAII principle for getting permission for/
157 notification about finished DDL statements from interested storage engines.
158
159 @see handlerton::ha_notify_table_ddl for details.
160*/
162 public:
164 THD *thd, const MDL_key *key, ha_ddl_type ddl_type,
165 const char *old_db_name = nullptr, const char *old_table_name = nullptr,
166 const char *new_db_name = nullptr,
167 const char *new_table_name = nullptr) noexcept
168 : m_hton_notified(false),
169 m_thd(thd),
170 m_key(*key),
171 m_ddl_type(ddl_type),
172 m_old_db_name(old_db_name),
173 m_old_table_name(old_table_name),
174 m_new_db_name(new_db_name),
175 m_new_table_name(new_table_name) {}
176
177 [[nodiscard]] bool notify() noexcept {
181 m_hton_notified = true;
182 return false;
183 }
184 my_error(ER_LOCK_REFUSED_BY_ENGINE, MYF(0));
185 return true;
186 }
187
189 if (m_hton_notified)
193 }
194
195 private:
200 const char *m_old_db_name;
201 const char *m_old_table_name;
202 const char *m_new_db_name;
203 const char *m_new_table_name;
204};
205
206/*
207 Reload the foreign key parent information of the referenced
208 tables and for the table itself.
209
210 @param thd Thread handle.
211 @param db Table schema name.
212 @param name Table name.
213 @param reload_self Reload FK parent info also for the
214 table itself.
215 @param fk_invalidator Object keeping track of which dd::Table
216 objects to invalidate. If submitted, use this
217 to restrict which FK parents should have their
218 FK parent information reloaded.
219
220 @retval operation outcome, false if no error.
221*/
222bool adjust_fk_parents(THD *thd, const char *db, const char *name,
223 bool reload_self,
224 const Foreign_key_parents_invalidator *fk_invalidator);
225
226/**
227 Check if new definition of parent table is compatible with foreign keys
228 which reference it. Update the unique constraint names and referenced
229 column names for the foreign keys accordingly.
230
231 @param thd Thread handle.
232 @param check_charsets Indicates whether we need to check charsets of
233 columns participating in foreign keys.
234 @param parent_table_db Parent table schema name.
235 @param parent_table_name Parent table name.
236 @param hton Handlerton for table's storage engine.
237 @param parent_table_def Table object representing the referenced table.
238 @param parent_alter_info Alter_info containing information about renames
239 of parent columns. Can be nullptr if there are
240 no such renames.
241 @param invalidate_tdc Indicates whether we need to invalidate TDC for
242 referencing tables after updating their
243 definitions.
244
245 @retval operation outcome, false if no error.
246*/
248 THD *thd, bool check_charsets, const char *parent_table_db,
249 const char *parent_table_name, handlerton *hton,
250 const dd::Table *parent_table_def, Alter_info *parent_alter_info,
251 bool invalidate_tdc);
252
253/**
254 Check if new definition of parent table is compatible with foreign keys
255 which reference it. Update the unique constraint names and referenced
256 column names for the foreign keys accordingly. Do mandatory character
257 set checks and TDC invalidation.
258*/
260 THD *thd, const char *parent_table_db, const char *parent_table_name,
261 handlerton *hton, const dd::Table *parent_table_def,
262 Alter_info *parent_alter_info) {
264 thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
265 parent_alter_info, true);
266}
267
268/**
269 Add MDL requests for specified lock type on all tables referencing the given
270 schema qualified table name to the list.
271
272 @param thd Thread handle.
273 @param schema Schema name.
274 @param table_name Table name.
275 @param hton Handlerton for table's storage engine.
276 @param lock_type Type of MDL requests to add.
277 @param[in,out] mdl_requests List to which MDL requests are to be added.
278
279 @retval operation outcome, false if no error.
280*/
281[[nodiscard]] bool collect_fk_children(THD *thd, const char *schema,
282 const char *table_name, handlerton *hton,
283 enum_mdl_type lock_type,
284 MDL_request_list *mdl_requests);
285
286/**
287 Add MDL requests for lock of specified type on tables referenced by the
288 foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
289 Also add the referenced table names to the foreign key invalidator,
290 to be used at a later stage to invalidate the dd::Table objects.
291
292 @param thd Thread handle.
293 @param db_name Table's database name.
294 @param table_name Table name.
295 @param alter_info Alter_info object with the list of FKs
296 to be added.
297 @param lock_type Type of metadata lock to be requested.
298 @param hton Handlerton for table's storage engine.
299 @param[in,out] mdl_requests List to which MDL requests are to be added.
300 @param[in,out] fk_invalidator Object keeping track of which dd::Table
301 objects to invalidate.
302
303 @retval operation outcome, false if no error.
304*/
305[[nodiscard]] bool collect_fk_parents_for_new_fks(
306 THD *thd, const char *db_name, const char *table_name,
307 const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
308 MDL_request_list *mdl_requests,
309 Foreign_key_parents_invalidator *fk_invalidator);
310
311/**
312 Add MDL requests for exclusive metadata locks on names of foreign keys
313 to be added by the CREATE TABLE or ALTER TABLE operation.
314
315 @param thd Thread context.
316 @param db_name Table's database name.
317 @param table_name Table name.
318 @param alter_info Alter_info object with the
319 list of FKs to be added.
320 @param hton Table's storage engine.
321 @param fk_max_generated_name_number Max value of number component
322 among existing generated foreign
323 key names.
324 @param[in,out] mdl_requests List to which MDL requests
325 are to be added.
326
327 @retval operation outcome, false if no error.
328*/
329bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
330 const char *table_name,
331 const Alter_info *alter_info,
332 handlerton *hton,
333 uint fk_max_generated_name_number,
334 MDL_request_list *mdl_requests);
335
336/**
337 Acquire exclusive metadata locks on tables which definitions need to
338 be updated or invalidated since they are related through foreign keys
339 to the table to be renamed,
340 Also add the referenced table names for the FKs on this table to the
341 foreign key invalidator, to be used at a later stage to invalidate the
342 dd::Table objects.
343
344 @param thd Thread handle.
345 @param db Table's old schema.
346 @param table_name Table's old name.
347 @param table_def Table definition of table being RENAMEd.
348 @param new_db Table's new schema.
349 @param new_table_name Table's new name.
350 @param hton Table's SE.
351 @param[in,out] fk_invalidator Object keeping track of which dd::Table
352 objects to invalidate.
353
354 @retval operation outcome, false if no error.
355*/
357 THD *thd, const char *db, const char *table_name,
358 const dd::Table *table_def, const char *new_db, const char *new_table_name,
359 handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator);
360
361/**
362 As a result of simple rename table operation, orphan non-self-referencing
363 foreign keys may become non-orphan/adopted self-referencing foreign keys.
364 For such transformed foreign key, check that table has compatible referenced
365 column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
366
367 @param thd Thread handle.
368 @param db Table's old schema.
369 @param table_name Table's old name.
370 @param new_db Table's new schema.
371 @param new_table_name Table's new name.
372 @param hton Table's SE.
373
374 @retval operation outcome, false if no error.
375*/
377 THD *thd, const char *db, const char *table_name, const char *new_db,
378 const char *new_table_name, handlerton *hton);
379
380/**
381 Update referenced table names and the unique constraint name for FKs
382 affected by RENAME TABLE operation.
383
384 @param thd Thread handle.
385 @param db Table's old schema.
386 @param table_name Table's old name.
387 @param new_db Table's new schema.
388 @param new_table_name Table's new name.
389 @param hton Table's SE.
390
391 @retval operation outcome, false if no error.
392*/
393[[nodiscard]] bool adjust_fks_for_rename_table(THD *thd, const char *db,
394 const char *table_name,
395 const char *new_db,
396 const char *new_table_name,
397 handlerton *hton);
398
399/*
400 Check if parent key for the foreign key exists, set foreign key's unique
401 constraint name accordingly. Emit error if no parent key found.
402
403 @note Prefer unique key if possible. If parent key is non-unique
404 unique constraint name is set to NULL.
405
406 @note DDL code use this function for non-self-referencing foreign keys.
407
408 @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
409
410 @param hton Handlerton for tables' storage engine.
411 @param parent_table_def Object describing new version of parent table.
412 @param old_child_table_def Object describing old version of child table.
413 Can be nullptr if old_parent_table_def is
414 nullptr. Used for error reporting.
415 @param old_parent_table_def Object describing old version of parent table.
416 nullptr indicates that this is not ALTER TABLE
417 operation. Used for error reporting.
418 @param is_self_referencing_fk If the parent and child is the same table.
419 @param fk[in,out] Object describing the foreign key,
420 its unique_constraint_name member
421 will be updated if matching parent
422 unique constraint is found.
423
424 @retval Operation result. False if success.
425*/
426[[nodiscard]] bool prepare_fk_parent_key(handlerton *hton,
427 const dd::Table *parent_table_def,
428 const dd::Table *old_parent_table_def,
429 const dd::Table *old_child_table_def,
430 bool is_self_referencing_fk,
431 dd::Foreign_key *fk);
432
433/**
434 Prepare Create_field and Key_spec objects for ALTER and upgrade.
435 @param[in,out] thd thread handle. Used as a memory pool
436 and source of environment information.
437 @param[in] src_table DD table object. Will be nullptr for temporary
438 tables and during upgrade.
439 @param[in] table the source table, open and locked
440 Used as an interface to the storage engine
441 to acquire additional information about
442 the original table.
443 @param[in,out] create_info A blob with CREATE/ALTER TABLE
444 parameters
445 @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
446 Originally create_info was used only in
447 CREATE TABLE and alter_info only in ALTER TABLE.
448 But since ALTER might end-up doing CREATE,
449 this distinction is gone and we just carry
450 around two structures.
451 @param[in,out] alter_ctx Runtime context for ALTER TABLE.
452 @param[in] used_fields used_fields from HA_CREATE_INFO.
453
454 @retval true error, out of memory or a semantical error in ALTER
455 TABLE instructions
456 @retval false success
457
458*/
459bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
460 HA_CREATE_INFO *create_info,
461 Alter_info *alter_info, Alter_table_ctx *alter_ctx,
462 const uint &used_fields);
463
464bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
465 TABLE *table, HA_CREATE_INFO *create_info,
466 Alter_info *alter_info,
467 Alter_table_ctx *alter_ctx);
470bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
471 HA_CREATE_INFO *create_info, TABLE_LIST *table_list,
472 Alter_info *alter_info);
473bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info,
474 HA_CREATE_INFO *create_info, bool *metadata_equal);
475bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy);
476bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table,
477 HA_CREATE_INFO *create_info);
478bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
479 const char *old_name, const char *old_fk_db,
480 const char *old_fk_name, const dd::Schema &new_schema,
481 const char *new_db, const char *new_name, uint flags);
482
483bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list,
484 HA_CHECK_OPT *check_opt);
485bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists,
486 bool drop_temporary);
487bool mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
488 bool drop_temporary, bool drop_database,
489 bool *dropped_non_atomic_flag,
490 std::set<handlerton *> *post_ddl_htons,
491 Foreign_key_parents_invalidator *fk_invalidator,
492 std::vector<MDL_ticket *> *safe_to_release_mdl);
493
494/**
495 Discover missing tables in SE and acquire locks on tables which participate
496 in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
497 will have to be updated or invalidated during this operation.
498
499 @param thd Thread context.
500 @param tables Tables to be dropped by DROP TABLES/DATABASE.
501
502 @retval False - Success.
503 @retval True - Failure.
504*/
505[[nodiscard]] bool rm_table_do_discovery_and_lock_fk_tables(THD *thd,
506 TABLE_LIST *tables);
507
508bool quick_rm_table(THD *thd, handlerton *base, const char *db,
509 const char *table_name, uint flags);
510bool prepare_sp_create_field(THD *thd, Create_field *field_def);
511bool prepare_pack_create_field(THD *thd, Create_field *sql_field,
512 longlong table_flags);
513
514const CHARSET_INFO *get_sql_field_charset(const Create_field *sql_field,
515 const HA_CREATE_INFO *create_info);
516bool validate_comment_length(THD *thd, const char *comment_str,
517 size_t *comment_len, uint max_len, uint err_code,
518 const char *comment_name);
519int write_bin_log(THD *thd, bool clear_error, const char *query,
520 size_t query_length, bool is_trans = false);
521void promote_first_timestamp_column(List<Create_field> *column_definitions);
522
523/**
524 Prepares the column definitions for table creation.
525
526 @param thd Thread object.
527 @param error_schema_name Schema name of the table used for error
528 reporting.
529 @param error_table_name Table name used for error reporting.
530 @param create_info Create information.
531 @param[in,out] create_list List of columns to create.
532 @param[in,out] select_field_pos Position where the SELECT columns start
533 for CREATE TABLE ... SELECT.
534 @param file The handler for the new table.
535 @param[in,out] sql_field Create_field to populate.
536 @param field_no Column number.
537
538 @retval false OK
539 @retval true error
540*/
541
542bool prepare_create_field(THD *thd, const char *error_schema_name,
543 const char *error_table_name,
544 HA_CREATE_INFO *create_info,
545 List<Create_field> *create_list,
546 int *select_field_pos, handler *file,
547 Create_field *sql_field, int field_no);
548
549/**
550 Prepares the table and key structures for table creation.
551
552 @param thd Thread object.
553 @param error_schema_name Schema name of the table to create/alter,
554 only error reporting.
555 @param error_table_name Name of table to create/alter, only used for
556 error reporting.
557 @param create_info Create information (like MAX_ROWS).
558 @param alter_info List of columns and indexes to create
559 @param file The handler for the new table.
560 @param is_partitioned Indicates whether table is partitioned.
561 @param[out] key_info_buffer An array of KEY structs for the indexes.
562 @param[out] key_count The number of elements in the array.
563 @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
564 foreign keys.
565 @param[out] fk_key_count The number of elements in the array.
566 @param[in] existing_fks An array of pre-existing FOREIGN KEYS
567 (in case of ALTER).
568 @param[in] existing_fks_count The number of pre-existing foreign keys.
569 @param[in] existing_fks_table dd::Table object for table version from
570 which pre-existing foreign keys come from.
571 Needed for error reporting.
572 @param[in] fk_max_generated_name_number Max value of number component among
573 existing generated foreign key names.
574 @param select_field_count The number of fields coming from a select
575 table.
576 @param find_parent_keys Indicates whether we need to lookup name of
577 unique constraint in parent table for foreign
578 keys.
579
580 @retval false OK
581 @retval true error
582*/
583
585 THD *thd, const char *error_schema_name, const char *error_table_name,
586 HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
587 bool is_partitioned, KEY **key_info_buffer, uint *key_count,
588 FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
589 FOREIGN_KEY *existing_fks, uint existing_fks_count,
590 const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
591 int select_field_count, bool find_parent_keys);
592
593size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
594 enum_explain_filename_mode explain_mode);
595
596extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
597
598/**
599 Acquire metadata lock on triggers associated with a list of tables.
600
601 @param[in] thd Current thread context
602 @param[in] tables Tables for that associated triggers have to locked.
603
604 @return Operation status.
605 @retval false Success
606 @retval true Failure
607*/
608
609bool lock_trigger_names(THD *thd, TABLE_LIST *tables);
610struct TYPELIB;
612
613/**
614 Method to collect check constraint names for the all the tables and acquire
615 MDL lock on them.
616
617 @param[in] thd Thread handle.
618 @param[in] tables Check constraints of tables to be locked.
619
620 @retval false Success.
621 @retval true Failure.
622*/
623bool lock_check_constraint_names(THD *thd, TABLE_LIST *tables);
624
625/**
626 Method to lock check constraint names for rename table operation.
627 Method acquire locks on the constraint names of source table and
628 also on the name of check constraint in the target table.
629
630 @param[in] thd Thread handle.
631 @param[in] db Database name.
632 @param[in] table_name Table name.
633 @param[in] table_def DD table object of source table.
634 @param[in] target_db Target database name.
635 @param[in] target_table_name Target table name.
636
637 @retval false Success.
638 @retval true Failure.
639*/
640bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
641 const char *table_name,
642 const dd::Table *table_def,
643 const char *target_db,
644 const char *target_table_name);
645
646/**
647 Method to prepare check constraints for the CREATE operation. If name of the
648 check constraint is not specified then name is generated, check constraint
649 is pre-validated and MDL on check constraint is acquired.
650
651 @param thd Thread handle.
652 @param db_name Database name.
653 @param table_name Table name.
654 @param alter_info Alter_info object with list of
655 check constraints to be created.
656
657 @retval false Success.
658 @retval true Failure.
659*/
661 const char *table_name,
662 Alter_info *alter_info);
663#endif /* SQL_TABLE_INCLUDED */
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:203
Runtime context for ALTER TABLE.
Definition: sql_alter.h:507
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:50
Definition: key.h:42
Helper class for keeping track for which tables we need to invalidate data-dictionary cache entries a...
Definition: sql_table.h:141
void invalidate(THD *thd)
Definition: sql_table.cc:1486
const Parent_map & parents() const
Definition: sql_table.h:150
std::map< std::pair< dd::String_type, dd::String_type >, handlerton * > Parent_map
Definition: sql_table.h:144
void clear()
Definition: sql_table.h:152
Parent_map m_parent_map
Definition: sql_table.h:145
void add(const char *db_name, const char *table_name, handlerton *hton)
Definition: sql_table.cc:1479
bool is_empty() const
Definition: sql_table.h:151
Intrusive parameterized list.
Definition: sql_plist.h:74
Definition: key.h:112
Definition: sql_list.h:433
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
Auxiliary class implementing RAII principle for getting permission for/ notification about finished D...
Definition: sql_table.h:161
bool m_hton_notified
Definition: sql_table.h:196
const MDL_key m_key
Definition: sql_table.h:198
THD * m_thd
Definition: sql_table.h:197
bool notify() noexcept
Definition: sql_table.h:177
const char * m_old_db_name
Definition: sql_table.h:200
const char * m_new_table_name
Definition: sql_table.h:203
const ha_ddl_type m_ddl_type
Definition: sql_table.h:199
const char * m_old_table_name
Definition: sql_table.h:201
const char * m_new_db_name
Definition: sql_table.h:202
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:163
~Table_ddl_hton_notification_guard()
Definition: sql_table.h:188
Definition: foreign_key.h:46
Definition: schema.h:62
Definition: table.h:46
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4354
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
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:1279
static int flags[50]
Definition: hp_test1.cc:39
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:195
@ MDL_SHARED_UPGRADABLE
Definition: mdl.h:285
@ MDL_SHARED_NO_WRITE
Definition: mdl.h:305
@ MDL_EXCLUSIVE
Definition: mdl.h:325
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:54
#define MYF(v)
Definition: my_inttypes.h:96
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
static char * query
Definition: myisam_ftdump.cc:44
ABI for instrumented mutexes.
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Definition: os0file.h:85
Json_data_extension ext
Definition: backend.cc:50
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
required string key
Definition: replication_asynchronous_connection_failover.proto:59
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:8571
ha_ddl_type
Definition: handler.h:932
@ HA_NOTIFY_POST_EVENT
Definition: handler.h:931
@ HA_NOTIFY_PRE_EVENT
Definition: handler.h:931
static const uint NO_DD_COMMIT
Don't commit transaction after updating data-dictionary while renaming the table.
Definition: sql_table.h:85
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:9885
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:19672
static const uint FN_TO_IS_TMP
Definition: sql_table.h:77
int write_bin_log(THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans=false)
Definition: sql_table.cc:1224
size_t tablename_to_filename(const char *from, char *to, size_t to_length)
Definition: sql_table.cc:819
constexpr enum_mdl_type SECLOAD_SCAN_START_MDL
The MDL type used when initially opening a table for SECONDARY_LOAD.
Definition: sql_table.h:94
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:4189
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:9339
bool rm_table_do_discovery_and_lock_fk_tables(THD *thd, TABLE_LIST *tables)
Discover missing tables in SE and acquire locks on tables which participate in FKs on tables to be dr...
Definition: sql_table.cc:1408
bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary)
Definition: sql_table.cc:1550
bool prepare_fk_parent_key(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:6362
bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table, HA_CREATE_INFO *create_info)
Definition: sql_table.cc:10800
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:3835
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:7906
constexpr enum_mdl_type SECLOAD_TDC_EVICT_MDL
The MDL which must be acquired before the old table definition can be evicted from the table definiti...
Definition: sql_table.h:106
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:9922
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:15590
bool mysql_create_table(THD *thd, TABLE_LIST *create_table, HA_CREATE_INFO *create_info, Alter_info *alter_info)
Implementation of SQLCOM_CREATE_TABLE.
Definition: sql_table.cc:10000
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:414
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:4156
mysql_mutex_t mysql_mutex_t
Definition: sql_table.h:63
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:12462
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:15200
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:4135
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:10557
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:9271
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:14531
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:210
constexpr enum_mdl_type SECLOAD_PAR_SCAN_MDL
The weaker MDL which the secondary engine plugin may downgrade to after a parallel scan has been star...
Definition: sql_table.h:100
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:774
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:3984
static const uint NO_CC_RENAME
Don't change generated check constraint names while renaming table.
Definition: sql_table.h:89
static const uint FN_FROM_IS_TMP
Definition: sql_table.h:76
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
Definition: sql_table.cc:18645
bool lock_check_constraint_names(THD *thd, TABLE_LIST *tables)
Method to collect check constraint names for the all the tables and acquire MDL lock on them.
Definition: sql_table.cc:19732
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:926
static const uint FN_IS_TMP
Definition: sql_table.h:78
static const uint NO_FK_RENAME
Don't change generated foreign key names while renaming table.
Definition: sql_table.h:87
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:619
bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:18671
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:9092
bool mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary, bool drop_database, 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:3109
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:15566
bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, Alter_info *alter_info)
Alter table.
Definition: sql_table.cc:16184
bool lock_trigger_names(THD *thd, TABLE_LIST *tables)
Acquire metadata lock on triggers associated with a list of tables.
Definition: sql_table.cc:1239
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:868
bool mysql_discard_or_import_tablespace(THD *thd, TABLE_LIST *table_list)
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:4501
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table's copy phase.
Definition: sql_table.cc:18287
static const uint NO_FK_CHECKS
Don't check foreign key constraints while renaming table.
Definition: sql_table.h:80
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:15628
enum_explain_filename_mode
Definition: sql_table.h:69
@ EXPLAIN_PARTITIONS_VERBOSE
Definition: sql_table.h:71
@ EXPLAIN_ALL_VERBOSE
Definition: sql_table.h:70
@ EXPLAIN_PARTITIONS_AS_COMMENT
Definition: sql_table.h:72
TYPELIB * create_typelib(MEM_ROOT *mem_root, Create_field *field_def)
Definition: sql_table.cc:4074
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:9638
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:8352
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:18958
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:18307
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:382
Definition: handler.h:3572
Definition: handler.h:2987
Metadata lock object key.
Definition: mdl.h:364
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: table.h:2756
Definition: table.h:1396
Definition: typelib.h:34
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2594
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
unsigned int uint
Definition: uca-dump.cc:29