MySQL 8.0.29
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2021, 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 "sql/dd/string_type.h"
39#include "sql/mdl.h"
40
41class Alter_info;
42class Alter_table_ctx;
43class Create_field;
44class FOREIGN_KEY;
45class KEY;
46class THD;
47class handler;
48struct CHARSET_INFO;
49struct MEM_ROOT;
50struct TABLE;
51struct TABLE_LIST;
52struct handlerton;
53
54namespace dd {
55class Foreign_key;
56class Schema;
57class Table;
58} // namespace dd
59
60struct HA_CHECK_OPT;
61struct HA_CREATE_INFO;
62
64template <typename T>
65class List;
66
71};
72
73/* Flags for conversion functions. */
74static const uint FN_FROM_IS_TMP = 1 << 0;
75static const uint FN_TO_IS_TMP = 1 << 1;
77/** Don't check foreign key constraints while renaming table */
78static const uint NO_FK_CHECKS = 1 << 2;
79/**
80 Don't commit transaction after updating data-dictionary while renaming
81 the table.
82*/
83static const uint NO_DD_COMMIT = 1 << 3;
84/** Don't change generated foreign key names while renaming table. */
85static const uint NO_FK_RENAME = 1 << 4;
86/** Don't change generated check constraint names while renaming table. */
87static const uint NO_CC_RENAME = 1 << 5;
88
89// MDL lock types used for ALTER TABLE SECONDARY_LOAD.
90
91/** The MDL type used when initially opening a table for SECONDARY_LOAD */
93
94/**
95 The weaker MDL which the secondary engine plugin may downgrade to after
96 a parallel scan has been started
97*/
99
100/**
101 The MDL which must be acquired before the old table definition
102 can be evicted from the table definition cache.
103*/
105
107 const HA_CREATE_INFO &ci);
108
109size_t filename_to_tablename(const char *from, char *to, size_t to_length,
110 bool stay_quiet = false);
111size_t tablename_to_filename(const char *from, char *to, size_t to_length);
112size_t build_table_filename(char *buff, size_t bufflen, const char *db,
113 const char *table, const char *ext, uint flags,
114 bool *was_truncated);
115// For caller's who are mostly sure that path do not truncate
116size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
117 const char *table, const char *ext,
118 uint flags) {
119 bool truncated_not_used;
120 return build_table_filename(buff, bufflen, db, table, ext, flags,
121 &truncated_not_used);
122}
123size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
125 HA_CREATE_INFO *create_info, Alter_info *alter_info);
126bool mysql_create_table_no_lock(THD *thd, const char *db,
127 const char *table_name,
128 HA_CREATE_INFO *create_info,
129 Alter_info *alter_info, uint select_field_count,
130 bool find_parent_keys, bool *is_trans,
131 handlerton **post_ddl_ht);
133
134/**
135 Helper class for keeping track for which tables we need to invalidate
136 data-dictionary cache entries and performing such invalidation.
137*/
139 private:
140 typedef std::map<std::pair<dd::String_type, dd::String_type>, handlerton *>
143
144 public:
145 void add(const char *db_name, const char *table_name, handlerton *hton);
146 void invalidate(THD *thd);
147 const Parent_map &parents() const { return m_parent_map; }
148 bool is_empty() const { return m_parent_map.empty(); }
149 void clear() { m_parent_map.clear(); }
150};
151
152/*
153 Reload the foreign key parent information of the referenced
154 tables and for the table itself.
155
156 @param thd Thread handle.
157 @param db Table schema name.
158 @param name Table name.
159 @param reload_self Reload FK parent info also for the
160 table itself.
161 @param fk_invalidator Object keeping track of which dd::Table
162 objects to invalidate. If submitted, use this
163 to restrict which FK parents should have their
164 FK parent information reloaded.
165
166 @retval operation outcome, false if no error.
167*/
168bool adjust_fk_parents(THD *thd, const char *db, const char *name,
169 bool reload_self,
170 const Foreign_key_parents_invalidator *fk_invalidator);
171
172/**
173 Check if new definition of parent table is compatible with foreign keys
174 which reference it. Update the unique constraint names and referenced
175 column names for the foreign keys accordingly.
176
177 @param thd Thread handle.
178 @param check_charsets Indicates whether we need to check charsets of
179 columns participating in foreign keys.
180 @param parent_table_db Parent table schema name.
181 @param parent_table_name Parent table name.
182 @param hton Handlerton for table's storage engine.
183 @param parent_table_def Table object representing the referenced table.
184 @param parent_alter_info Alter_info containing information about renames
185 of parent columns. Can be nullptr if there are
186 no such renames.
187 @param invalidate_tdc Indicates whether we need to invalidate TDC for
188 referencing tables after updating their
189 definitions.
190
191 @retval operation outcome, false if no error.
192*/
194 THD *thd, bool check_charsets, const char *parent_table_db,
195 const char *parent_table_name, handlerton *hton,
196 const dd::Table *parent_table_def, Alter_info *parent_alter_info,
197 bool invalidate_tdc);
198
199/**
200 Check if new definition of parent table is compatible with foreign keys
201 which reference it. Update the unique constraint names and referenced
202 column names for the foreign keys accordingly. Do mandatory character
203 set checks and TDC invalidation.
204*/
206 THD *thd, const char *parent_table_db, const char *parent_table_name,
207 handlerton *hton, const dd::Table *parent_table_def,
208 Alter_info *parent_alter_info) {
210 thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
211 parent_alter_info, true);
212}
213
214/**
215 Add MDL requests for specified lock type on all tables referencing the given
216 schema qualified table name to the list.
217
218 @param thd Thread handle.
219 @param schema Schema name.
220 @param table_name Table name.
221 @param hton Handlerton for table's storage engine.
222 @param lock_type Type of MDL requests to add.
223 @param[in,out] mdl_requests List to which MDL requests are to be added.
224
225 @retval operation outcome, false if no error.
226*/
227[[nodiscard]] bool collect_fk_children(THD *thd, const char *schema,
228 const char *table_name, handlerton *hton,
229 enum_mdl_type lock_type,
230 MDL_request_list *mdl_requests);
231
232/**
233 Add MDL requests for lock of specified type on tables referenced by the
234 foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
235 Also add the referenced table names to the foreign key invalidator,
236 to be used at a later stage to invalidate the dd::Table objects.
237
238 @param thd Thread handle.
239 @param db_name Table's database name.
240 @param table_name Table name.
241 @param alter_info Alter_info object with the list of FKs
242 to be added.
243 @param lock_type Type of metadata lock to be requested.
244 @param hton Handlerton for table's storage engine.
245 @param[in,out] mdl_requests List to which MDL requests are to be added.
246 @param[in,out] fk_invalidator Object keeping track of which dd::Table
247 objects to invalidate.
248
249 @retval operation outcome, false if no error.
250*/
251[[nodiscard]] bool collect_fk_parents_for_new_fks(
252 THD *thd, const char *db_name, const char *table_name,
253 const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
254 MDL_request_list *mdl_requests,
255 Foreign_key_parents_invalidator *fk_invalidator);
256
257/**
258 Add MDL requests for exclusive metadata locks on names of foreign keys
259 to be added by the CREATE TABLE or ALTER TABLE operation.
260
261 @param thd Thread context.
262 @param db_name Table's database name.
263 @param table_name Table name.
264 @param alter_info Alter_info object with the
265 list of FKs to be added.
266 @param hton Table's storage engine.
267 @param fk_max_generated_name_number Max value of number component
268 among existing generated foreign
269 key names.
270 @param[in,out] mdl_requests List to which MDL requests
271 are to be added.
272
273 @retval operation outcome, false if no error.
274*/
275bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
276 const char *table_name,
277 const Alter_info *alter_info,
278 handlerton *hton,
279 uint fk_max_generated_name_number,
280 MDL_request_list *mdl_requests);
281
282/**
283 Acquire exclusive metadata locks on tables which definitions need to
284 be updated or invalidated since they are related through foreign keys
285 to the table to be renamed,
286 Also add the referenced table names for the FKs on this table to the
287 foreign key invalidator, to be used at a later stage to invalidate the
288 dd::Table objects.
289
290 @param thd Thread handle.
291 @param db Table's old schema.
292 @param table_name Table's old name.
293 @param table_def Table definition of table being RENAMEd.
294 @param new_db Table's new schema.
295 @param new_table_name Table's new name.
296 @param hton Table's SE.
297 @param[in,out] fk_invalidator Object keeping track of which dd::Table
298 objects to invalidate.
299
300 @retval operation outcome, false if no error.
301*/
303 THD *thd, const char *db, const char *table_name,
304 const dd::Table *table_def, const char *new_db, const char *new_table_name,
305 handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator);
306
307/**
308 As a result of simple rename table operation, orphan non-self-referencing
309 foreign keys may become non-orphan/adopted self-referencing foreign keys.
310 For such transformed foreign key, check that table has compatible referenced
311 column and parent key. Also, update DD.UNIQUE_CONSTRAINT_NAME.
312
313 @param thd Thread handle.
314 @param db Table's old schema.
315 @param table_name Table's old name.
316 @param new_db Table's new schema.
317 @param new_table_name Table's new name.
318 @param hton Table's SE.
319
320 @retval operation outcome, false if no error.
321*/
323 THD *thd, const char *db, const char *table_name, const char *new_db,
324 const char *new_table_name, handlerton *hton);
325
326/**
327 Update referenced table names and the unique constraint name for FKs
328 affected by RENAME TABLE operation.
329
330 @param thd Thread handle.
331 @param db Table's old schema.
332 @param table_name Table's old name.
333 @param new_db Table's new schema.
334 @param new_table_name Table's new name.
335 @param hton Table's SE.
336
337 @retval operation outcome, false if no error.
338*/
339[[nodiscard]] bool adjust_fks_for_rename_table(THD *thd, const char *db,
340 const char *table_name,
341 const char *new_db,
342 const char *new_table_name,
343 handlerton *hton);
344
345/*
346 Check if parent key for the foreign key exists, set foreign key's unique
347 constraint name accordingly. Emit error if no parent key found.
348
349 @note Prefer unique key if possible. If parent key is non-unique
350 unique constraint name is set to NULL.
351
352 @note DDL code use this function for non-self-referencing foreign keys.
353
354 @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
355
356 @param hton Handlerton for tables' storage engine.
357 @param parent_table_def Object describing new version of parent table.
358 @param old_child_table_def Object describing old version of child table.
359 Can be nullptr if old_parent_table_def is
360 nullptr. Used for error reporting.
361 @param old_parent_table_def Object describing old version of parent table.
362 nullptr indicates that this is not ALTER TABLE
363 operation. Used for error reporting.
364 @param is_self_referencing_fk If the parent and child is the same table.
365 @param fk[in,out] Object describing the foreign key,
366 its unique_constraint_name member
367 will be updated if matching parent
368 unique constraint is found.
369
370 @retval Operation result. False if success.
371*/
372[[nodiscard]] bool prepare_fk_parent_key(handlerton *hton,
373 const dd::Table *parent_table_def,
374 const dd::Table *old_parent_table_def,
375 const dd::Table *old_child_table_def,
376 bool is_self_referencing_fk,
377 dd::Foreign_key *fk);
378
379/**
380 Prepare Create_field and Key_spec objects for ALTER and upgrade.
381 @param[in,out] thd thread handle. Used as a memory pool
382 and source of environment information.
383 @param[in] src_table DD table object. Will be nullptr for temporary
384 tables and during upgrade.
385 @param[in] table the source table, open and locked
386 Used as an interface to the storage engine
387 to acquire additional information about
388 the original table.
389 @param[in,out] create_info A blob with CREATE/ALTER TABLE
390 parameters
391 @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
392 Originally create_info was used only in
393 CREATE TABLE and alter_info only in ALTER TABLE.
394 But since ALTER might end-up doing CREATE,
395 this distinction is gone and we just carry
396 around two structures.
397 @param[in,out] alter_ctx Runtime context for ALTER TABLE.
398 @param[in] used_fields used_fields from HA_CREATE_INFO.
399
400 @retval true error, out of memory or a semantical error in ALTER
401 TABLE instructions
402 @retval false success
403
404*/
405bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
406 HA_CREATE_INFO *create_info,
407 Alter_info *alter_info, Alter_table_ctx *alter_ctx,
408 const uint &used_fields);
409
410bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
411 TABLE *table, HA_CREATE_INFO *create_info,
412 Alter_info *alter_info,
413 Alter_table_ctx *alter_ctx);
416bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
417 HA_CREATE_INFO *create_info, TABLE_LIST *table_list,
418 Alter_info *alter_info);
419bool mysql_compare_tables(THD *thd, TABLE *table, Alter_info *alter_info,
420 HA_CREATE_INFO *create_info, bool *metadata_equal);
421bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy);
422bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table,
423 HA_CREATE_INFO *create_info);
424bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
425 const char *old_name, const char *old_fk_db,
426 const char *old_fk_name, const dd::Schema &new_schema,
427 const char *new_db, const char *new_name, uint flags);
428
429bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list,
430 HA_CHECK_OPT *check_opt);
431bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists,
432 bool drop_temporary);
433bool mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
434 bool drop_temporary, bool drop_database,
435 bool *dropped_non_atomic_flag,
436 std::set<handlerton *> *post_ddl_htons,
437 Foreign_key_parents_invalidator *fk_invalidator,
438 std::vector<MDL_ticket *> *safe_to_release_mdl);
439
440/**
441 Discover missing tables in SE and acquire locks on tables which participate
442 in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
443 will have to be updated or invalidated during this operation.
444
445 @param thd Thread context.
446 @param tables Tables to be dropped by DROP TABLES/DATABASE.
447
448 @retval False - Success.
449 @retval True - Failure.
450*/
451[[nodiscard]] bool rm_table_do_discovery_and_lock_fk_tables(THD *thd,
452 TABLE_LIST *tables);
453
454bool quick_rm_table(THD *thd, handlerton *base, const char *db,
455 const char *table_name, uint flags);
456bool prepare_sp_create_field(THD *thd, Create_field *field_def);
457bool prepare_pack_create_field(THD *thd, Create_field *sql_field,
458 longlong table_flags);
459
460const CHARSET_INFO *get_sql_field_charset(const Create_field *sql_field,
461 const HA_CREATE_INFO *create_info);
462bool validate_comment_length(THD *thd, const char *comment_str,
463 size_t *comment_len, uint max_len, uint err_code,
464 const char *comment_name);
465int write_bin_log(THD *thd, bool clear_error, const char *query,
466 size_t query_length, bool is_trans = false);
467void promote_first_timestamp_column(List<Create_field> *column_definitions);
468
469/**
470 Prepares the column definitions for table creation.
471
472 @param thd Thread object.
473 @param error_schema_name Schema name of the table used for error
474 reporting.
475 @param error_table_name Table name used for error reporting.
476 @param create_info Create information.
477 @param[in,out] create_list List of columns to create.
478 @param[in,out] select_field_pos Position where the SELECT columns start
479 for CREATE TABLE ... SELECT.
480 @param file The handler for the new table.
481 @param[in,out] sql_field Create_field to populate.
482 @param field_no Column number.
483
484 @retval false OK
485 @retval true error
486*/
487
488bool prepare_create_field(THD *thd, const char *error_schema_name,
489 const char *error_table_name,
490 HA_CREATE_INFO *create_info,
491 List<Create_field> *create_list,
492 int *select_field_pos, handler *file,
493 Create_field *sql_field, int field_no);
494
495/**
496 Prepares the table and key structures for table creation.
497
498 @param thd Thread object.
499 @param error_schema_name Schema name of the table to create/alter,
500 only error reporting.
501 @param error_table_name Name of table to create/alter, only used for
502 error reporting.
503 @param create_info Create information (like MAX_ROWS).
504 @param alter_info List of columns and indexes to create
505 @param file The handler for the new table.
506 @param is_partitioned Indicates whether table is partitioned.
507 @param[out] key_info_buffer An array of KEY structs for the indexes.
508 @param[out] key_count The number of elements in the array.
509 @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
510 foreign keys.
511 @param[out] fk_key_count The number of elements in the array.
512 @param[in] existing_fks An array of pre-existing FOREIGN KEYS
513 (in case of ALTER).
514 @param[in] existing_fks_count The number of pre-existing foreign keys.
515 @param[in] existing_fks_table dd::Table object for table version from
516 which pre-existing foreign keys come from.
517 Needed for error reporting.
518 @param[in] fk_max_generated_name_number Max value of number component among
519 existing generated foreign key names.
520 @param select_field_count The number of fields coming from a select
521 table.
522 @param find_parent_keys Indicates whether we need to lookup name of
523 unique constraint in parent table for foreign
524 keys.
525
526 @retval false OK
527 @retval true error
528*/
529
531 THD *thd, const char *error_schema_name, const char *error_table_name,
532 HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
533 bool is_partitioned, KEY **key_info_buffer, uint *key_count,
534 FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
535 FOREIGN_KEY *existing_fks, uint existing_fks_count,
536 const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
537 int select_field_count, bool find_parent_keys);
538
539size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
540 enum_explain_filename_mode explain_mode);
541
542extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
543
544/**
545 Acquire metadata lock on triggers associated with a list of tables.
546
547 @param[in] thd Current thread context
548 @param[in] tables Tables for that associated triggers have to locked.
549
550 @return Operation status.
551 @retval false Success
552 @retval true Failure
553*/
554
555bool lock_trigger_names(THD *thd, TABLE_LIST *tables);
556struct TYPELIB;
558
559/**
560 Method to collect check constraint names for the all the tables and acquire
561 MDL lock on them.
562
563 @param[in] thd Thread handle.
564 @param[in] tables Check constraints of tables to be locked.
565
566 @retval false Success.
567 @retval true Failure.
568*/
569bool lock_check_constraint_names(THD *thd, TABLE_LIST *tables);
570
571/**
572 Method to lock check constraint names for rename table operation.
573 Method acquire locks on the constraint names of source table and
574 also on the name of check constraint in the target table.
575
576 @param[in] thd Thread handle.
577 @param[in] db Database name.
578 @param[in] table_name Table name.
579 @param[in] table_def DD table object of source table.
580 @param[in] target_db Target database name.
581 @param[in] target_table_name Target table name.
582
583 @retval false Success.
584 @retval true Failure.
585*/
586bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
587 const char *table_name,
588 const dd::Table *table_def,
589 const char *target_db,
590 const char *target_table_name);
591
592/**
593 Method to prepare check constraints for the CREATE operation. If name of the
594 check constraint is not specified then name is generated, check constraint
595 is pre-validated and MDL on check constraint is acquired.
596
597 @param thd Thread handle.
598 @param db_name Database name.
599 @param table_name Table name.
600 @param alter_info Alter_info object with list of
601 check constraints to be created.
602
603 @retval false Success.
604 @retval true Failure.
605*/
607 const char *table_name,
608 Alter_info *alter_info);
609#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:138
void invalidate(THD *thd)
Definition: sql_table.cc:1481
const Parent_map & parents() const
Definition: sql_table.h:147
std::map< std::pair< dd::String_type, dd::String_type >, handlerton * > Parent_map
Definition: sql_table.h:141
void clear()
Definition: sql_table.h:149
Parent_map m_parent_map
Definition: sql_table.h:142
void add(const char *db_name, const char *table_name, handlerton *hton)
Definition: sql_table.cc:1474
bool is_empty() const
Definition: sql_table.h:148
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:945
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:4157
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
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:1277
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
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
static const uint NO_DD_COMMIT
Don't commit transaction after updating data-dictionary while renaming the table.
Definition: sql_table.h:83
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:9851
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:19561
static const uint FN_TO_IS_TMP
Definition: sql_table.h:75
int write_bin_log(THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans=false)
Definition: sql_table.cc:1219
size_t tablename_to_filename(const char *from, char *to, size_t to_length)
Definition: sql_table.cc:814
constexpr enum_mdl_type SECLOAD_SCAN_START_MDL
The MDL type used when initially opening a table for SECONDARY_LOAD.
Definition: sql_table.h:92
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:4168
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:9305
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:1403
bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary)
Definition: sql_table.cc:1545
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:6329
bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table, HA_CREATE_INFO *create_info)
Definition: sql_table.cc:10673
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:3814
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:7873
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:104
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:9888
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:15450
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:9966
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:413
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:4135
mysql_mutex_t mysql_mutex_t
Definition: sql_table.h:61
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:12327
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:15060
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:4114
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:10448
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:9237
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:14396
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:209
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:98
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:3963
static const uint NO_CC_RENAME
Don't change generated check constraint names while renaming table.
Definition: sql_table.h:87
static const uint FN_FROM_IS_TMP
Definition: sql_table.h:74
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
Definition: sql_table.cc:18534
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:19621
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:921
static const uint FN_IS_TMP
Definition: sql_table.h:76
static const uint NO_FK_RENAME
Don't change generated foreign key names while renaming table.
Definition: sql_table.h:85
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:618
bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:18560
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:9058
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:3088
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:15426
size_t filename_to_tablename(const char *from, char *to, size_t to_length, bool stay_quiet=false)
Definition: sql_table.cc:771
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:16078
bool lock_trigger_names(THD *thd, TABLE_LIST *tables)
Acquire metadata lock on triggers associated with a list of tables.
Definition: sql_table.cc:1234
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:863
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:4468
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table's copy phase.
Definition: sql_table.cc:18176
static const uint NO_FK_CHECKS
Don't check foreign key constraints while renaming table.
Definition: sql_table.h:78
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:15488
enum_explain_filename_mode
Definition: sql_table.h:67
@ EXPLAIN_PARTITIONS_VERBOSE
Definition: sql_table.h:69
@ EXPLAIN_ALL_VERBOSE
Definition: sql_table.h:68
@ EXPLAIN_PARTITIONS_AS_COMMENT
Definition: sql_table.h:70
TYPELIB * create_typelib(MEM_ROOT *mem_root, Create_field *field_def)
Definition: sql_table.cc:4053
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:9604
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:8319
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:18847
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:18196
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:354
Definition: handler.h:3375
Definition: handler.h:2790
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: table.h:2684
Definition: table.h:1394
Definition: typelib.h:34
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2416
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
unsigned int uint
Definition: uca-dump.cc:29