MySQL  8.0.17
Source Code Documentation
sql_table.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
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 <utility>
31 #include <vector>
32 
33 #include "dd/string_type.h"
34 #include "mdl.h"
35 #include "my_compiler.h"
36 #include "my_inttypes.h"
37 #include "my_sharedlib.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 TABLE;
49 struct TABLE_LIST;
50 struct handlerton;
51 
52 namespace dd {
53 class Foreign_key;
54 class Schema;
55 class Table;
56 } // namespace dd
57 
58 struct HA_CHECK_OPT;
60 
62 template <typename T>
63 class List;
64 
69 };
70 
71 /* Flags for conversion functions. */
72 static const uint FN_FROM_IS_TMP = 1 << 0;
73 static const uint FN_TO_IS_TMP = 1 << 1;
75 /** Don't check foreign key constraints while renaming table */
76 static const uint NO_FK_CHECKS = 1 << 2;
77 /**
78  Don't commit transaction after updating data-dictionary while renaming
79  the table.
80 */
81 static const uint NO_DD_COMMIT = 1 << 3;
82 /** Don't change generated foreign key names while renaming table. */
83 static const uint NO_FK_RENAME = 1 << 4;
84 /** Don't change generated check constraint names while renaming table. */
85 static const uint NO_CC_RENAME = 1 << 5;
86 
87 size_t filename_to_tablename(const char *from, char *to, size_t to_length,
88  bool stay_quiet = false);
89 size_t tablename_to_filename(const char *from, char *to, size_t to_length);
90 size_t build_table_filename(char *buff, size_t bufflen, const char *db,
91  const char *table, const char *ext, uint flags,
92  bool *was_truncated);
93 // For caller's who are mostly sure that path do not truncate
94 size_t inline build_table_filename(char *buff, size_t bufflen, const char *db,
95  const char *table, const char *ext,
96  uint flags) {
97  bool truncated_not_used;
98  return build_table_filename(buff, bufflen, db, table, ext, flags,
99  &truncated_not_used);
100 }
101 size_t build_tmptable_filename(THD *thd, char *buff, size_t bufflen);
103  HA_CREATE_INFO *create_info, Alter_info *alter_info);
104 bool mysql_create_table_no_lock(THD *thd, const char *db,
105  const char *table_name,
106  HA_CREATE_INFO *create_info,
107  Alter_info *alter_info, uint select_field_count,
108  bool find_parent_keys, bool *is_trans,
109  handlerton **post_ddl_ht);
110 bool mysql_discard_or_import_tablespace(THD *thd, TABLE_LIST *table_list);
111 
112 /**
113  Helper class for keeping track for which tables we need to invalidate
114  data-dictionary cache entries and performing such invalidation.
115 */
117  private:
118  typedef std::map<std::pair<dd::String_type, dd::String_type>, handlerton *>
121 
122  public:
123  void add(const char *db_name, const char *table_name, handlerton *hton);
124  void invalidate(THD *thd);
125  const Parent_map &parents() const { return m_parent_map; }
126  bool is_empty() const { return m_parent_map.empty(); }
127  void clear() { m_parent_map.clear(); }
128 };
129 
130 /*
131  Reload the foreign key parent information of the referenced
132  tables and for the table itself.
133 
134  @param thd Thread handle.
135  @param db Table schema name.
136  @param name Table name.
137  @param reload_self Reload FK parent info also for the
138  table itself.
139  @param fk_invalidator Object keeping track of which dd::Table
140  objects to invalidate. If submitted, use this
141  to restrict which FK parents should have their
142  FK parent information reloaded.
143 
144  @retval operation outcome, false if no error.
145 */
146 bool adjust_fk_parents(THD *thd, const char *db, const char *name,
147  bool reload_self,
148  const Foreign_key_parents_invalidator *fk_invalidator);
149 
150 /**
151  Check if new definition of parent table is compatible with foreign keys
152  which reference it. Update the unique constraint names and referenced
153  column names for the foreign keys accordingly.
154 
155  @param thd Thread handle.
156  @param check_charsets Indicates whether we need to check charsets of
157  columns participating in foreign keys.
158  @param parent_table_db Parent table schema name.
159  @param parent_table_name Parent table name.
160  @param hton Handlerton for table's storage engine.
161  @param parent_table_def Table object representing the referenced table.
162  @param parent_alter_info Alter_info containing information about renames
163  of parent columns. Can be nullptr if there are
164  no such renames.
165  @param invalidate_tdc Indicates whether we need to invalidate TDC for
166  referencing tables after updating their
167  definitions.
168 
169  @retval operation outcome, false if no error.
170 */
172  THD *thd, bool check_charsets, const char *parent_table_db,
173  const char *parent_table_name, handlerton *hton,
174  const dd::Table *parent_table_def, Alter_info *parent_alter_info,
175  bool invalidate_tdc) MY_ATTRIBUTE((warn_unused_result));
176 
177 /**
178  Check if new definition of parent table is compatible with foreign keys
179  which reference it. Update the unique constraint names and referenced
180  column names for the foreign keys accordingly. Do mandatory character
181  set checks and TDC invalidation.
182 */
184  THD *thd, const char *parent_table_db, const char *parent_table_name,
185  handlerton *hton, const dd::Table *parent_table_def,
186  Alter_info *parent_alter_info) {
188  thd, true, parent_table_db, parent_table_name, hton, parent_table_def,
189  parent_alter_info, true);
190 }
191 
192 /**
193  Add MDL requests for specified lock type on all tables referencing the given
194  schema qualified table name to the list.
195 
196  @param thd Thread handle.
197  @param schema Schema name.
198  @param table_name Table name.
199  @param hton Handlerton for table's storage engine.
200  @param lock_type Type of MDL requests to add.
201  @param[in,out] mdl_requests List to which MDL requests are to be added.
202 
203  @retval operation outcome, false if no error.
204 */
205 bool collect_fk_children(THD *thd, const char *schema, const char *table_name,
206  handlerton *hton, enum_mdl_type lock_type,
207  MDL_request_list *mdl_requests)
208  MY_ATTRIBUTE((warn_unused_result));
209 
210 /**
211  Add MDL requests for lock of specified type on tables referenced by the
212  foreign keys to be added by the CREATE TABLE or ALTER TABLE operation.
213  Also add the referenced table names to the foreign key invalidator,
214  to be used at a later stage to invalidate the dd::Table objects.
215 
216  @param thd Thread handle.
217  @param db_name Table's database name.
218  @param table_name Table name.
219  @param alter_info Alter_info object with the list of FKs
220  to be added.
221  @param lock_type Type of metadata lock to be requested.
222  @param hton Handlerton for table's storage engine.
223  @param[in,out] mdl_requests List to which MDL requests are to be added.
224  @param[in,out] fk_invalidator Object keeping track of which dd::Table
225  objects to invalidate.
226 
227  @retval operation outcome, false if no error.
228 */
230  THD *thd, const char *db_name, const char *table_name,
231  const Alter_info *alter_info, enum_mdl_type lock_type, handlerton *hton,
232  MDL_request_list *mdl_requests,
233  Foreign_key_parents_invalidator *fk_invalidator)
234  MY_ATTRIBUTE((warn_unused_result));
235 
236 /**
237  Add MDL requests for exclusive metadata locks on names of foreign keys
238  to be added by the CREATE TABLE or ALTER TABLE operation.
239 
240  @param thd Thread context.
241  @param db_name Table's database name.
242  @param table_name Table name.
243  @param alter_info Alter_info object with the
244  list of FKs to be added.
245  @param fk_max_generated_name_number Max value of number component
246  among existing generated foreign
247  key names.
248  @param[in,out] mdl_requests List to which MDL requests
249  are to be added.
250 
251  @retval operation outcome, false if no error.
252 */
253 bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
254  const char *table_name,
255  const Alter_info *alter_info,
256  uint fk_max_generated_name_number,
257  MDL_request_list *mdl_requests);
258 
259 /**
260  Acquire exclusive metadata locks on tables which definitions need to
261  be updated or invalidated since they are related through foreign keys
262  to the table to be renamed,
263  Also add the referenced table names for the FKs on this table to the
264  foreign key invalidator, to be used at a later stage to invalidate the
265  dd::Table objects.
266 
267  @param thd Thread handle.
268  @param db Table's old schema.
269  @param table_name Table's old name.
270  @param table_def Table definition of table being RENAMEd.
271  @param new_db Table's new schema.
272  @param new_table_name Table's new name.
273  @param hton Table's SE.
274  @param[in,out] fk_invalidator Object keeping track of which dd::Table
275  objects to invalidate.
276 
277  @retval operation outcome, false if no error.
278 */
280  THD *thd, const char *db, const char *table_name,
281  const dd::Table *table_def, const char *new_db, const char *new_table_name,
282  handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator)
283  MY_ATTRIBUTE((warn_unused_result));
284 
285 /**
286  Update referenced table names and the unique constraint name for FKs
287  affected by RENAME TABLE operation.
288 
289  @param thd Thread handle.
290  @param db Table's old schema.
291  @param table_name Table's old name.
292  @param new_db Table's new schema.
293  @param new_table_name Table's new name.
294  @param hton Table's SE.
295 
296  @retval operation outcome, false if no error.
297 */
298 bool adjust_fks_for_rename_table(THD *thd, const char *db,
299  const char *table_name, const char *new_db,
300  const char *new_table_name, handlerton *hton)
301  MY_ATTRIBUTE((warn_unused_result));
302 
303 /*
304  Check if parent key for the foreign key exists, set foreign key's unique
305  constraint name accordingly. Emit error if no parent key found.
306 
307  @note Prefer unique key if possible. If parent key is non-unique
308  unique constraint name is set to NULL.
309 
310  @note DDL code use this function for non-self-referencing foreign keys.
311 
312  @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
313 
314  @param hton Handlerton for tables' storage engine.
315  @param parent_table_def Object describing new version of parent table.
316  @param old_child_table_def Object describing old version of child table.
317  Can be nullptr if old_parent_table_def is
318  nullptr. Used for error reporting.
319  @param old_parent_table_def Object describing old version of parent table.
320  nullptr indicates that this is not ALTER TABLE
321  operation. Used for error reporting.
322  @param is_self_referencing_fk If the parent and child is the same table.
323  @param fk[in,out] Object describing the foreign key,
324  its unique_constraint_name member
325  will be updated if matching parent
326  unique constraint is found.
327 
328  @retval Operation result. False if success.
329 */
330 bool prepare_fk_parent_key(handlerton *hton, const dd::Table *parent_table_def,
331  const dd::Table *old_parent_table_def,
332  const dd::Table *old_child_table_def,
333  bool is_self_referencing_fk, dd::Foreign_key *fk)
334  MY_ATTRIBUTE((warn_unused_result));
335 
336 /**
337  Prepare Create_field and Key_spec objects for ALTER and upgrade.
338  @param[in,out] thd thread handle. Used as a memory pool
339  and source of environment information.
340  @param[in] src_table DD table object. Will be nullptr for temporary
341  tables and during upgrade.
342  @param[in] table the source table, open and locked
343  Used as an interface to the storage engine
344  to acquire additional information about
345  the original table.
346  @param[in,out] create_info A blob with CREATE/ALTER TABLE
347  parameters
348  @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
349  Originally create_info was used only in
350  CREATE TABLE and alter_info only in ALTER TABLE.
351  But since ALTER might end-up doing CREATE,
352  this distinction is gone and we just carry
353  around two structures.
354  @param[in,out] alter_ctx Runtime context for ALTER TABLE.
355  @param[in] used_fields used_fields from HA_CREATE_INFO.
356 
357  @retval true error, out of memory or a semantical error in ALTER
358  TABLE instructions
359  @retval false success
360 
361 */
362 bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
363  HA_CREATE_INFO *create_info,
364  Alter_info *alter_info, Alter_table_ctx *alter_ctx,
365  const uint &used_fields);
366 
367 bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
368  TABLE *table, HA_CREATE_INFO *create_info,
369  Alter_info *alter_info,
370  Alter_table_ctx *alter_ctx);
373 bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
374  HA_CREATE_INFO *create_info, TABLE_LIST *table_list,
375  Alter_info *alter_info);
376 bool mysql_compare_tables(TABLE *table, Alter_info *alter_info,
377  HA_CREATE_INFO *create_info, bool *metadata_equal);
378 bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy);
379 bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table,
380  HA_CREATE_INFO *create_info);
381 bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
382  const char *old_name, const char *old_fk_db,
383  const char *old_fk_name, const dd::Schema &new_schema,
384  const char *new_db, const char *new_name, uint flags);
385 
386 bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list,
387  HA_CHECK_OPT *check_opt);
388 bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists,
389  bool drop_temporary);
390 bool mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
391  bool drop_temporary, bool drop_database,
392  bool *dropped_non_atomic_flag,
393  std::set<handlerton *> *post_ddl_htons,
394  Foreign_key_parents_invalidator *fk_invalidator,
395  std::vector<MDL_ticket *> *safe_to_release_mdl);
396 
397 /**
398  Discover missing tables in SE and acquire locks on tables which participate
399  in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
400  will have to be updated or invalidated during this operation.
401 
402  @param thd Thread context.
403  @param tables Tables to be dropped by DROP TABLES/DATABASE.
404 
405  @retval False - Success.
406  @retval True - Failure.
407 */
409  MY_ATTRIBUTE((warn_unused_result));
410 
411 bool quick_rm_table(THD *thd, handlerton *base, const char *db,
412  const char *table_name, uint flags);
413 bool prepare_sp_create_field(THD *thd, Create_field *field_def);
415  longlong table_flags);
416 
418  const HA_CREATE_INFO *create_info);
419 bool validate_comment_length(THD *thd, const char *comment_str,
420  size_t *comment_len, uint max_len, uint err_code,
421  const char *comment_name);
422 int write_bin_log(THD *thd, bool clear_error, const char *query,
423  size_t query_length, bool is_trans = false);
424 void promote_first_timestamp_column(List<Create_field> *column_definitions);
425 
426 /**
427  Prepares the column definitions for table creation.
428 
429  @param thd Thread object.
430  @param create_info Create information.
431  @param[in,out] create_list List of columns to create.
432  @param[in,out] select_field_pos Position where the SELECT columns start
433  for CREATE TABLE ... SELECT.
434  @param file The handler for the new table.
435  @param[in,out] sql_field Create_field to populate.
436  @param field_no Column number.
437 
438  @retval false OK
439  @retval true error
440 */
441 
442 bool prepare_create_field(THD *thd, HA_CREATE_INFO *create_info,
443  List<Create_field> *create_list,
444  int *select_field_pos, handler *file,
445  Create_field *sql_field, int field_no);
446 
447 /**
448  Prepares the table and key structures for table creation.
449 
450  @param thd Thread object.
451  @param error_schema_name Schema name of the table to create/alter,
452  only error reporting.
453  @param error_table_name Name of table to create/alter, only used for
454  error reporting.
455  @param create_info Create information (like MAX_ROWS).
456  @param alter_info List of columns and indexes to create
457  @param file The handler for the new table.
458  @param is_partitioned Indicates whether table is partitioned.
459  @param[out] key_info_buffer An array of KEY structs for the indexes.
460  @param[out] key_count The number of elements in the array.
461  @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
462  foreign keys.
463  @param[out] fk_key_count The number of elements in the array.
464  @param[in] existing_fks An array of pre-existing FOREIGN KEYS
465  (in case of ALTER).
466  @param[in] existing_fks_count The number of pre-existing foreign keys.
467  @param[in] existing_fks_table dd::Table object for table version from
468  which pre-existing foreign keys come from.
469  Needed for error reporting.
470  @param[in] fk_max_generated_name_number Max value of number component among
471  existing generated foreign key names.
472  @param select_field_count The number of fields coming from a select
473  table.
474  @param find_parent_keys Indicates whether we need to lookup name of
475  unique constraint in parent table for foreign
476  keys.
477 
478  @retval false OK
479  @retval true error
480 */
481 
483  THD *thd, const char *error_schema_name, const char *error_table_name,
484  HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
485  bool is_partitioned, KEY **key_info_buffer, uint *key_count,
486  FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
487  FOREIGN_KEY *existing_fks, uint existing_fks_count,
488  const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
489  int select_field_count, bool find_parent_keys);
490 
491 size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
492  enum_explain_filename_mode explain_mode);
493 
494 void parse_filename(const char *filename, size_t filename_length,
495  const char **schema_name, size_t *schema_name_length,
496  const char **table_name, size_t *table_name_length,
497  const char **partition_name, size_t *partition_name_length,
498  const char **subpartition_name,
499  size_t *subpartition_name_length);
500 
501 extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
502 
503 /**
504  Acquire metadata lock on triggers associated with a list of tables.
505 
506  @param[in] thd Current thread context
507  @param[in] tables Tables for that associated triggers have to locked.
508 
509  @return Operation status.
510  @retval false Success
511  @retval true Failure
512 */
513 
514 bool lock_trigger_names(THD *thd, TABLE_LIST *tables);
515 struct TYPELIB;
517 
518 /**
519  Method to collect check constraint names for the all the tables and acquire
520  MDL lock on them.
521 
522  @param[in] thd Thread handle.
523  @param[in] tables Check constraints of tables to be locked.
524 
525  @retval false Success.
526  @retval true Failure.
527 */
528 bool lock_check_constraint_names(THD *thd, TABLE_LIST *tables);
529 
530 /**
531  Method to lock check constraint names for rename table operation.
532  Method acquire locks on the constraint names of source table and
533  also on the name of check constraint in the target table.
534 
535  @param[in] thd Thread handle.
536  @param[in] db Database name.
537  @param[in] table_name Table name.
538  @param[in] table_def DD table object of source table.
539  @param[in] target_db Target database name.
540  @param[in] target_table_name Target table name.
541 
542  @retval false Success.
543  @retval true Failure.
544 */
545 bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
546  const char *table_name,
547  const dd::Table *table_def,
548  const char *target_db,
549  const char *target_table_name);
550 
551 #endif /* SQL_TABLE_INCLUDED */
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:3629
void add(const char *db_name, const char *table_name, handlerton *hton)
Definition: sql_table.cc:1319
MYSQL_PLUGIN_IMPORT const char * primary_key_name
Definition: sql_table.cc:174
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:777
static const uint NO_CC_RENAME
Don&#39;t change generated check constraint names while renaming table.
Definition: sql_table.h:85
const char * db_name
Definition: rules_table_service.cc:54
void parse_filename(const char *filename, size_t filename_length, const char **schema_name, size_t *schema_name_length, const char **table_name, size_t *table_name_length, const char **partition_name, size_t *partition_name_length, const char **subpartition_name, size_t *subpartition_name_length)
Definition: sql_table.cc:514
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:15142
Definition: handler.h:3173
static char * query
Definition: myisam_ftdump.cc:44
bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary)
Definition: sql_table.cc:1390
bool lock_trigger_names(THD *thd, TABLE_LIST *tables)
Acquire metadata lock on triggers associated with a list of tables.
Definition: sql_table.cc:1090
const string name("\ame\)
Some integer typedefs for easier portability.
static const uint NO_FK_CHECKS
Don&#39;t check foreign key constraints while renaming table.
Definition: sql_table.h:76
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
bool collect_fk_names_for_new_fks(THD *thd, const char *db_name, const char *table_name, const Alter_info *alter_info, 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:9368
bool mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:17211
size_t tablename_to_filename(const char *from, char *to, size_t to_length)
Definition: sql_table.cc:670
enum_mdl_type
Type of metadata lock request.
Definition: mdl.h:179
static const uint NO_FK_RENAME
Don&#39;t change generated foreign key names while renaming table.
Definition: sql_table.h:83
void invalidate(THD *thd)
Definition: sql_table.cc:1326
static const uint FN_FROM_IS_TMP
Definition: sql_table.h:72
Definition: sql_table.h:68
mysql_mutex_t mysql_mutex_t
Definition: sql_table.h:59
st_send_field_n sql_field[64]
Definition: test_sql_9_sessions.cc:64
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:4234
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3987
static const uint NO_DD_COMMIT
Don&#39;t commit transaction after updating data-dictionary while renaming the table. ...
Definition: sql_table.h:81
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:14539
bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:17541
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:18540
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:2912
Definition: table.h:1294
const CHARSET_INFO * get_sql_field_charset(const Create_field *sql_field, const HA_CREATE_INFO *create_info)
Definition: sql_table.cc:3953
Functions related to handling of plugins and other dynamically loaded libraries.
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:6064
Runtime context for ALTER TABLE.
Definition: sql_alter.h:467
size_t filename_to_tablename(const char *from, char *to, size_t to_length, bool stay_quiet=false)
Definition: sql_table.cc:627
bool mysql_trans_prepare_alter_copy_data(THD *thd)
Prepare the transaction for the alter table&#39;s copy phase.
Definition: sql_table.cc:17193
const Parent_map & parents() const
Definition: sql_table.h:125
Parent_map m_parent_map
Definition: sql_table.h:120
void clear()
Definition: sql_table.h:127
Definition: aggregate_check.h:523
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:3778
Header for compiler-dependent features.
static const uint FN_IS_TMP
Definition: sql_table.h:74
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:1259
bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table, HA_CREATE_INFO *create_info)
Definition: sql_table.cc:10094
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:14219
unsigned int uint
Definition: uca-dump.cc:29
bool is_empty() const
Definition: sql_table.h:126
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:1118
long long int longlong
Definition: my_inttypes.h:73
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:3927
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2275
int write_bin_log(THD *thd, bool clear_error, const char *query, size_t query_length, bool is_trans=false)
Some handler functions defined in sql/sql_table.cc and sql/handler.cc etc.
Definition: sql_table.cc:1075
Definition: m_ctype.h:359
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:9331
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:8757
bool mysql_compare_tables(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:11632
Intrusive parameterized list.
Definition: sql_plist.h:74
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:8584
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
Definition: sql_table.cc:17516
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:8825
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:3976
Definition: typelib.h:34
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
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:14563
const char * filename
Definition: pfs_example_component_population.cc:64
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:50
Helper class for keeping track for which tables we need to invalidate data-dictionary cache entries a...
Definition: sql_table.h:116
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
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:374
Definition: key.h:111
TYPELIB * create_typelib(MEM_ROOT *mem_root, Create_field *field_def)
Definition: sql_table.cc:3866
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:7431
enum_explain_filename_mode
Definition: sql_table.h:65
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:188
Definition: key.h:41
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:7844
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:9444
ABI for instrumented mutexes.
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:13607
std::map< std::pair< dd::String_type, dd::String_type >, handlerton * > Parent_map
Definition: sql_table.h:119
Definition: handler.h:2607
static const uint FN_TO_IS_TMP
Definition: sql_table.h:73
bool mysql_discard_or_import_tablespace(THD *thd, TABLE_LIST *table_list)
Definition: schema.h:61
Definition: test_sql_stmt.cc:150
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
A table definition from the master.
Definition: rpl_utility.h:245
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
Definition: table.h:2442
static int flags[50]
Definition: hp_test1.cc:39
Definition: sql_table.h:67
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:18600
Definition: table.h:43
Definition: foreign_key.h:46
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:719
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:9105
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:9869
Definition: sql_table.h:66
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
const char * table_name
Definition: rules_table_service.cc:55