MySQL 8.3.0
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2023, 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;
53class Table_ref;
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
92 const HA_CREATE_INFO &ci);
93
94size_t filename_to_tablename(const char *from, char *to, size_t to_length,
95 bool stay_quiet = false,
96 bool *has_errors = nullptr);
97size_t tablename_to_filename(const char *from, char *to, size_t to_length);
98size_t build_table_filename(char *buff, size_t bufflen, const char *db,
99 const char *table, const char *ext, uint flags,
100 bool *was_truncated);
101// For caller's who are mostly sure that path do not truncate
102size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
103 const char *table, const char *ext,
104 uint flags) {
105 bool truncated_not_used;
106 return build_table_filename(buff, bufflen, db, table, ext, flags,
107 &truncated_not_used);
108}
109size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
111 HA_CREATE_INFO *create_info, Alter_info *alter_info);
112bool mysql_create_table_no_lock(THD *thd, const char *db,
113 const char *table_name,
114 HA_CREATE_INFO *create_info,
115 Alter_info *alter_info, uint select_field_count,
116 bool find_parent_keys, bool *is_trans,
117 handlerton **post_ddl_ht);
119
120/**
121 Helper class for keeping track for which tables we need to invalidate
122 data-dictionary cache entries and performing such invalidation.
123*/
125 private:
126 typedef std::map<std::pair<dd::String_type, dd::String_type>, handlerton *>
129
130 public:
131 void add(const char *db_name, const char *table_name, handlerton *hton);
132 void invalidate(THD *thd);
133 const Parent_map &parents() const { return m_parent_map; }
134 bool is_empty() const { return m_parent_map.empty(); }
135 void clear() { m_parent_map.clear(); }
136};
137
138/**
139 Auxiliary class implementing RAII principle for getting permission for/
140 notification about finished DDL statements from interested storage engines.
141
142 @see handlerton::ha_notify_table_ddl for details.
143*/
145 public:
147 THD *thd, const MDL_key *key, ha_ddl_type ddl_type,
148 const char *old_db_name = nullptr, const char *old_table_name = nullptr,
149 const char *new_db_name = nullptr,
150 const char *new_table_name = nullptr) noexcept
151 : m_hton_notified(false),
152 m_thd(thd),
153 m_key(*key),
154 m_ddl_type(ddl_type),
155 m_old_db_name(old_db_name),
156 m_old_table_name(old_table_name),
157 m_new_db_name(new_db_name),
158 m_new_table_name(new_table_name) {}
159
160 [[nodiscard]] bool notify() noexcept {
164 m_hton_notified = true;
165 return false;
166 }
167 my_error(ER_LOCK_REFUSED_BY_ENGINE, MYF(0));
168 return true;
169 }
170
172 if (m_hton_notified)
176 }
177
178 private:
183 const char *m_old_db_name;
184 const char *m_old_table_name;
185 const char *m_new_db_name;
186 const char *m_new_table_name;
187};
188
189/*
190 Reload the foreign key parent information of the referenced
191 tables and for the table itself.
192
193 @param thd Thread handle.
194 @param db Table schema name.
195 @param name Table name.
196 @param reload_self Reload FK parent info also for the
197 table itself.
198 @param fk_invalidator Object keeping track of which dd::Table
199 objects to invalidate. If submitted, use this
200 to restrict which FK parents should have their
201 FK parent information reloaded.
202
203 @retval operation outcome, false if no error.
204*/
205bool adjust_fk_parents(THD *thd, const char *db, const char *name,
206 bool reload_self,
207 const Foreign_key_parents_invalidator *fk_invalidator);
208
209/**
210 Check if new definition of parent table is compatible with foreign keys
211 which reference it. Update the unique constraint names and referenced
212 column names for the foreign keys accordingly.
213
214 @param thd Thread handle.
215 @param check_charsets Indicates whether we need to check charsets of
216 columns participating in foreign keys.
217 @param parent_table_db Parent table schema name.
218 @param parent_table_name Parent table name.
219 @param hton Handlerton for table's storage engine.
220 @param parent_table_def Table object representing the referenced table.
221 @param parent_alter_info Alter_info containing information about renames
222 of parent columns. Can be nullptr if there are
223 no such renames.
224 @param invalidate_tdc Indicates whether we need to invalidate TDC for
225 referencing tables after updating their
226 definitions.
227
228 @retval operation outcome, false if no error.
229*/
231 THD *thd, bool check_charsets, const char *parent_table_db,
232 const char *parent_table_name, handlerton *hton,
233 const dd::Table *parent_table_def, Alter_info *parent_alter_info,
234 bool invalidate_tdc);
235
236/**
237 Check if new definition of parent table is compatible with foreign keys
238 which reference it. Update the unique constraint names and referenced
239 column names for the foreign keys accordingly. Do mandatory character
240 set checks and TDC invalidation.
241*/
243 THD *thd, const char *parent_table_db, const char *parent_table_name,
244 handlerton *hton, const dd::Table *parent_table_def,
245 Alter_info *parent_alter_info) {
247 thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
248 parent_alter_info, true);
249}
250
251/**
252 Add MDL requests for specified lock type on all tables referencing the given
253 schema qualified table name to the list.
254
255 @param thd Thread handle.
256 @param schema Schema name.
257 @param table_name Table name.
258 @param hton Handlerton for table's storage engine.
259 @param lock_type Type of MDL requests to add.
260 @param[in,out] mdl_requests List to which MDL requests are to be added.
261
262 @retval operation outcome, false if no error.
263*/
264[[nodiscard]] bool collect_fk_children(THD *thd, const char *schema,
265 const char *table_name, handlerton *hton,
266 enum_mdl_type lock_type,
267 MDL_request_list *mdl_requests);
268
269/**
270 Add MDL requests for lock of specified type on tables referenced by the
271 foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
272 Also add the referenced table names to the foreign key invalidator,
273 to be used at a later stage to invalidate the dd::Table objects.
274
275 @param thd Thread handle.
276 @param db_name Table's database name.
277 @param table_name Table name.
278 @param alter_info Alter_info object with the list of FKs
279 to be added.
280 @param lock_type Type of metadata lock to be requested.
281 @param hton Handlerton for table's storage engine.
282 @param[in,out] mdl_requests List to which MDL requests are to be added.
283 @param[in,out] fk_invalidator Object keeping track of which dd::Table
284 objects to invalidate.
285
286 @retval operation outcome, false if no error.
287*/
288[[nodiscard]] bool collect_fk_parents_for_new_fks(
289 THD *thd, const char *db_name, const char *table_name,
290 const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
291 MDL_request_list *mdl_requests,
292 Foreign_key_parents_invalidator *fk_invalidator);
293
294/**
295 Add MDL requests for exclusive metadata locks on names of foreign keys
296 to be added by the CREATE TABLE or ALTER TABLE operation.
297
298 @param thd Thread context.
299 @param db_name Table's database name.
300 @param table_name Table name.
301 @param alter_info Alter_info object with the
302 list of FKs to be added.
303 @param hton Table's storage engine.
304 @param fk_max_generated_name_number Max value of number component
305 among existing generated foreign
306 key names.
307 @param[in,out] mdl_requests List to which MDL requests
308 are to be added.
309
310 @retval operation outcome, false if no error.
311*/
312bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
313 const char *table_name,
314 const Alter_info *alter_info,
315 handlerton *hton,
316 uint fk_max_generated_name_number,
317 MDL_request_list *mdl_requests);
318
319/**
320 Acquire exclusive metadata locks on tables which definitions need to
321 be updated or invalidated since they are related through foreign keys
322 to the table to be renamed,
323 Also add the referenced table names for the FKs on this table to the
324 foreign key invalidator, to be used at a later stage to invalidate the
325 dd::Table objects.
326
327 @param thd Thread handle.
328 @param db Table's old schema.
329 @param table_name Table's old name.
330 @param table_def Table definition of table being RENAMEd.
331 @param new_db Table's new schema.
332 @param new_table_name Table's new name.
333 @param hton Table's SE.
334 @param[in,out] fk_invalidator Object keeping track of which dd::Table
335 objects to invalidate.
336
337 @retval operation outcome, false if no error.
338*/
340 THD *thd, const char *db, const char *table_name,
341 const dd::Table *table_def, const char *new_db, const char *new_table_name,
342 handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator);
343
344/**
345 As a result of simple rename table operation, orphan non-self-referencing
346 foreign keys may become non-orphan/adopted self-referencing foreign keys.
347 For such transformed foreign key, check that table has compatible referenced
348 column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
349
350 @param thd Thread handle.
351 @param db Table's old schema.
352 @param table_name Table's old name.
353 @param new_db Table's new schema.
354 @param new_table_name Table's new name.
355 @param hton Table's SE.
356
357 @retval operation outcome, false if no error.
358*/
360 THD *thd, const char *db, const char *table_name, const char *new_db,
361 const char *new_table_name, handlerton *hton);
362
363/**
364 Update referenced table names and the unique constraint name for FKs
365 affected by RENAME TABLE operation.
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*/
376[[nodiscard]] bool adjust_fks_for_rename_table(THD *thd, const char *db,
377 const char *table_name,
378 const char *new_db,
379 const char *new_table_name,
380 handlerton *hton);
381
382/*
383 Check if parent key for the foreign key exists, set foreign key's unique
384 constraint name accordingly. Emit error if no parent key found.
385
386 @note Prefer unique key if possible. If parent key is non-unique
387 unique constraint name is set to NULL.
388
389 @note DDL code use this function for non-self-referencing foreign keys.
390
391 @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
392
393 @param hton Handlerton for tables' storage engine.
394 @param parent_table_def Object describing new version of parent table.
395 @param old_child_table_def Object describing old version of child table.
396 Can be nullptr if old_parent_table_def is
397 nullptr. Used for error reporting.
398 @param old_parent_table_def Object describing old version of parent table.
399 nullptr indicates that this is not ALTER TABLE
400 operation. Used for error reporting.
401 @param is_self_referencing_fk If the parent and child is the same table.
402 @param fk[in,out] Object describing the foreign key,
403 its unique_constraint_name member
404 will be updated if matching parent
405 unique constraint is found.
406
407 @retval Operation result. False if success.
408*/
409[[nodiscard]] bool prepare_fk_parent_key(handlerton *hton,
410 const dd::Table *parent_table_def,
411 const dd::Table *old_parent_table_def,
412 const dd::Table *old_child_table_def,
413 bool is_self_referencing_fk,
414 dd::Foreign_key *fk);
415
416/**
417 Prepare Create_field and Key_spec objects for ALTER and upgrade.
418 @param[in,out] thd thread handle. Used as a memory pool
419 and source of environment information.
420 @param[in] src_table DD table object. Will be nullptr for temporary
421 tables and during upgrade.
422 @param[in] table the source table, open and locked
423 Used as an interface to the storage engine
424 to acquire additional information about
425 the original table.
426 @param[in,out] create_info A blob with CREATE/ALTER TABLE
427 parameters
428 @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
429 Originally create_info was used only in
430 CREATE TABLE and alter_info only in ALTER TABLE.
431 But since ALTER might end-up doing CREATE,
432 this distinction is gone and we just carry
433 around two structures.
434 @param[in,out] alter_ctx Runtime context for ALTER TABLE.
435 @param[in] used_fields used_fields from HA_CREATE_INFO.
436
437 @retval true error, out of memory or a semantical error in ALTER
438 TABLE instructions
439 @retval false success
440
441*/
442bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
443 HA_CREATE_INFO *create_info,
444 Alter_info *alter_info, Alter_table_ctx *alter_ctx,
445 const uint &used_fields);
446
447bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
448 TABLE *table, HA_CREATE_INFO *create_info,
449 Alter_info *alter_info,
450 Alter_table_ctx *alter_ctx);
453bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
454 HA_CREATE_INFO *create_info, Table_ref *table_list,
455 Alter_info *alter_info);
456bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info,
457 HA_CREATE_INFO *create_info, bool *metadata_equal);
458bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy);
459bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table,
460 HA_CREATE_INFO *create_info);
461bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
462 const char *old_name, const char *old_fk_db,
463 const char *old_fk_name, const dd::Schema &new_schema,
464 const char *new_db, const char *new_name, uint flags);
465
466bool mysql_checksum_table(THD *thd, Table_ref *table_list,
467 HA_CHECK_OPT *check_opt);
468bool mysql_rm_table(THD *thd, Table_ref *tables, bool if_exists,
469 bool drop_temporary);
470bool mysql_rm_table_no_locks(THD *thd, Table_ref *tables, bool if_exists,
471 bool drop_temporary, bool drop_database,
472 bool *dropped_non_atomic_flag,
473 std::set<handlerton *> *post_ddl_htons,
474 Foreign_key_parents_invalidator *fk_invalidator,
475 std::vector<MDL_ticket *> *safe_to_release_mdl);
476
477/**
478 Discover missing tables in SE and acquire locks on tables which participate
479 in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
480 will have to be updated or invalidated during this operation.
481
482 @param thd Thread context.
483 @param tables Tables to be dropped by DROP TABLES/DATABASE.
484
485 @retval False - Success.
486 @retval True - Failure.
487*/
488[[nodiscard]] bool rm_table_do_discovery_and_lock_fk_tables(THD *thd,
489 Table_ref *tables);
490
491bool quick_rm_table(THD *thd, handlerton *base, const char *db,
492 const char *table_name, uint flags);
493bool prepare_sp_create_field(THD *thd, Create_field *field_def);
494bool prepare_pack_create_field(THD *thd, Create_field *sql_field,
495 longlong table_flags);
496
497const CHARSET_INFO *get_sql_field_charset(const Create_field *sql_field,
498 const HA_CREATE_INFO *create_info);
499bool validate_comment_length(THD *thd, const char *comment_str,
500 size_t *comment_len, uint max_len, uint err_code,
501 const char *comment_name);
502int write_bin_log(THD *thd, bool clear_error, const char *query,
503 size_t query_length, bool is_trans = false);
504void promote_first_timestamp_column(List<Create_field> *column_definitions);
505
506/**
507 Prepares the column definitions for table creation.
508
509 @param thd Thread object.
510 @param error_schema_name Schema name of the table used for error
511 reporting.
512 @param error_table_name Table name used for error reporting.
513 @param create_info Create information.
514 @param[in,out] create_list List of columns to create.
515 @param[in,out] select_field_pos Position where the SELECT columns start
516 for CREATE TABLE ... SELECT.
517 @param file The handler for the new table.
518 @param[in,out] sql_field Create_field to populate.
519 @param field_no Column number.
520
521 @retval false OK
522 @retval true error
523*/
524
525bool prepare_create_field(THD *thd, const char *error_schema_name,
526 const char *error_table_name,
527 HA_CREATE_INFO *create_info,
528 List<Create_field> *create_list,
529 int *select_field_pos, handler *file,
530 Create_field *sql_field, int field_no);
531
532/**
533 Prepares the table and key structures for table creation.
534
535 @param thd Thread object.
536 @param error_schema_name Schema name of the table to create/alter,
537 only error reporting.
538 @param error_table_name Name of table to create/alter, only used for
539 error reporting.
540 @param create_info Create information (like MAX_ROWS).
541 @param alter_info List of columns and indexes to create
542 @param file The handler for the new table.
543 @param is_partitioned Indicates whether table is partitioned.
544 @param[out] key_info_buffer An array of KEY structs for the indexes.
545 @param[out] key_count The number of elements in the array.
546 @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
547 foreign keys.
548 @param[out] fk_key_count The number of elements in the array.
549 @param[in] existing_fks An array of pre-existing FOREIGN KEYS
550 (in case of ALTER).
551 @param[in] existing_fks_count The number of pre-existing foreign keys.
552 @param[in] existing_fks_table dd::Table object for table version from
553 which pre-existing foreign keys come from.
554 Needed for error reporting.
555 @param[in] fk_max_generated_name_number Max value of number component among
556 existing generated foreign key names.
557 @param select_field_count The number of fields coming from a select
558 table.
559 @param find_parent_keys Indicates whether we need to lookup name of
560 unique constraint in parent table for foreign
561 keys.
562
563 @retval false OK
564 @retval true error
565*/
566
568 THD *thd, const char *error_schema_name, const char *error_table_name,
569 HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
570 bool is_partitioned, KEY **key_info_buffer, uint *key_count,
571 FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
572 FOREIGN_KEY *existing_fks, uint existing_fks_count,
573 const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
574 int select_field_count, bool find_parent_keys);
575
576size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
577 enum_explain_filename_mode explain_mode);
578
579extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
580
581/**
582 Acquire metadata lock on triggers associated with a list of tables.
583
584 @param[in] thd Current thread context
585 @param[in] tables Tables for that associated triggers have to locked.
586
587 @return Operation status.
588 @retval false Success
589 @retval true Failure
590*/
591
592bool lock_trigger_names(THD *thd, Table_ref *tables);
593struct TYPELIB;
595
596/**
597 Method to collect check constraint names for the all the tables and acquire
598 MDL lock on them.
599
600 @param[in] thd Thread handle.
601 @param[in] tables Check constraints of tables to be locked.
602
603 @retval false Success.
604 @retval true Failure.
605*/
606bool lock_check_constraint_names(THD *thd, Table_ref *tables);
607
608/**
609 Method to lock check constraint names for rename table operation.
610 Method acquire locks on the constraint names of source table and
611 also on the name of check constraint in the target table.
612
613 @param[in] thd Thread handle.
614 @param[in] db Database name.
615 @param[in] table_name Table name.
616 @param[in] table_def DD table object of source table.
617 @param[in] target_db Target database name.
618 @param[in] target_table_name Target table name.
619
620 @retval false Success.
621 @retval true Failure.
622*/
623bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
624 const char *table_name,
625 const dd::Table *table_def,
626 const char *target_db,
627 const char *target_table_name);
628
629/**
630 Method to prepare check constraints for the CREATE operation. If name of the
631 check constraint is not specified then name is generated, check constraint
632 is pre-validated and MDL on check constraint is acquired.
633
634 @param thd Thread handle.
635 @param db_name Database name.
636 @param table_name Table name.
637 @param alter_info Alter_info object with list of
638 check constraints to be created.
639
640 @retval false Success.
641 @retval true Failure.
642*/
644 const char *table_name,
645 Alter_info *alter_info);
646#endif /* SQL_TABLE_INCLUDED */
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:204
Runtime context for ALTER TABLE.
Definition: sql_alter.h:508
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:124
void invalidate(THD *thd)
Definition: sql_table.cc:1511
const Parent_map & parents() const
Definition: sql_table.h:133
std::map< std::pair< dd::String_type, dd::String_type >, handlerton * > Parent_map
Definition: sql_table.h:127
void clear()
Definition: sql_table.h:135
Parent_map m_parent_map
Definition: sql_table.h:128
void add(const char *db_name, const char *table_name, handlerton *hton)
Definition: sql_table.cc:1504
bool is_empty() const
Definition: sql_table.h:134
Intrusive parameterized list.
Definition: sql_plist.h:74
Definition: key.h:112
Definition: sql_list.h:434
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Auxiliary class implementing RAII principle for getting permission for/ notification about finished D...
Definition: sql_table.h:144
bool m_hton_notified
Definition: sql_table.h:179
const MDL_key m_key
Definition: sql_table.h:181
THD * m_thd
Definition: sql_table.h:180
bool notify() noexcept
Definition: sql_table.h:160
const char * m_old_db_name
Definition: sql_table.h:183
const char * m_new_table_name
Definition: sql_table.h:186
const ha_ddl_type m_ddl_type
Definition: sql_table.h:182
const char * m_old_table_name
Definition: sql_table.h:184
const char * m_new_db_name
Definition: sql_table.h:185
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:146
~Table_ddl_hton_notification_guard()
Definition: sql_table.h:171
Definition: table.h:2853
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:4548
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
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:1307
static int flags[50]
Definition: hp_test1.cc:39
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:46
ABI for instrumented mutexes.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
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:42
Definition: os0file.h:88
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:8759
ha_ddl_type
Definition: handler.h:940
@ HA_NOTIFY_POST_EVENT
Definition: handler.h:939
@ HA_NOTIFY_PRE_EVENT
Definition: handler.h:939
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:105
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:9939
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:19817
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:1247
size_t tablename_to_filename(const char *from, char *to, size_t to_length)
Definition: sql_table.cc:827
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:4243
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:9393
bool lock_trigger_names(THD *thd, Table_ref *tables)
Acquire metadata lock on triggers associated with a list of tables.
Definition: sql_table.cc:1262
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:19877
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:6416
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:3889
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:1432
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:7960
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:9976
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:15731
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:422
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:4210
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:12602
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:15341
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:4189
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:10611
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:9325
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:14672
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:218
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:782
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:4038
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_rm_table(THD *thd, Table_ref *tables, bool if_exists, bool drop_temporary)
Definition: sql_table.cc:1575
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:934
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:627
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:9146
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:10054
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:15707
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:16325
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:876
bool mysql_recreate_table(THD *thd, Table_ref *table_list, bool table_copy)
Definition: sql_table.cc:18788
bool mysql_create_like_table(THD *thd, Table_ref *table, Table_ref *src_table, HA_CREATE_INFO *create_info)
Definition: sql_table.cc:10854
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:4555
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table's copy phase.
Definition: sql_table.cc:18430
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:15769
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:4128
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:9692
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:8406
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:19101
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:18450
bool mysql_checksum_table(THD *thd, Table_ref *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:18814
bool mysql_rm_table_no_locks(THD *thd, Table_ref *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:3163
bool mysql_discard_or_import_tablespace(THD *thd, Table_ref *table_list)
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422
Definition: handler.h:3766
Struct to hold information about the table that should be created.
Definition: handler.h:3177
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:1403
Definition: typelib.h:34
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2718
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49