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