MySQL  8.0.18
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 hton Table's storage engine.
246  @param fk_max_generated_name_number Max value of number component
247  among existing generated foreign
248  key names.
249  @param[in,out] mdl_requests List to which MDL requests
250  are to be added.
251 
252  @retval operation outcome, false if no error.
253 */
254 bool collect_fk_names_for_new_fks(THD *thd, const char *db_name,
255  const char *table_name,
256  const Alter_info *alter_info,
257  handlerton *hton,
258  uint fk_max_generated_name_number,
259  MDL_request_list *mdl_requests);
260 
261 /**
262  Acquire exclusive metadata locks on tables which definitions need to
263  be updated or invalidated since they are related through foreign keys
264  to the table to be renamed,
265  Also add the referenced table names for the FKs on this table to the
266  foreign key invalidator, to be used at a later stage to invalidate the
267  dd::Table objects.
268 
269  @param thd Thread handle.
270  @param db Table's old schema.
271  @param table_name Table's old name.
272  @param table_def Table definition of table being RENAMEd.
273  @param new_db Table's new schema.
274  @param new_table_name Table's new name.
275  @param hton Table's SE.
276  @param[in,out] fk_invalidator Object keeping track of which dd::Table
277  objects to invalidate.
278 
279  @retval operation outcome, false if no error.
280 */
282  THD *thd, const char *db, const char *table_name,
283  const dd::Table *table_def, const char *new_db, const char *new_table_name,
284  handlerton *hton, Foreign_key_parents_invalidator *fk_invalidator)
285  MY_ATTRIBUTE((warn_unused_result));
286 
287 /**
288  Update referenced table names and the unique constraint name for FKs
289  affected by RENAME TABLE operation.
290 
291  @param thd Thread handle.
292  @param db Table's old schema.
293  @param table_name Table's old name.
294  @param new_db Table's new schema.
295  @param new_table_name Table's new name.
296  @param hton Table's SE.
297 
298  @retval operation outcome, false if no error.
299 */
300 bool adjust_fks_for_rename_table(THD *thd, const char *db,
301  const char *table_name, const char *new_db,
302  const char *new_table_name, handlerton *hton)
303  MY_ATTRIBUTE((warn_unused_result));
304 
305 /*
306  Check if parent key for the foreign key exists, set foreign key's unique
307  constraint name accordingly. Emit error if no parent key found.
308 
309  @note Prefer unique key if possible. If parent key is non-unique
310  unique constraint name is set to NULL.
311 
312  @note DDL code use this function for non-self-referencing foreign keys.
313 
314  @sa prepare_fk_parent_key(THD, handlerton, FOREIGN_KEY)
315 
316  @param hton Handlerton for tables' storage engine.
317  @param parent_table_def Object describing new version of parent table.
318  @param old_child_table_def Object describing old version of child table.
319  Can be nullptr if old_parent_table_def is
320  nullptr. Used for error reporting.
321  @param old_parent_table_def Object describing old version of parent table.
322  nullptr indicates that this is not ALTER TABLE
323  operation. Used for error reporting.
324  @param is_self_referencing_fk If the parent and child is the same table.
325  @param fk[in,out] Object describing the foreign key,
326  its unique_constraint_name member
327  will be updated if matching parent
328  unique constraint is found.
329 
330  @retval Operation result. False if success.
331 */
332 bool prepare_fk_parent_key(handlerton *hton, const dd::Table *parent_table_def,
333  const dd::Table *old_parent_table_def,
334  const dd::Table *old_child_table_def,
335  bool is_self_referencing_fk, dd::Foreign_key *fk)
336  MY_ATTRIBUTE((warn_unused_result));
337 
338 /**
339  Prepare Create_field and Key_spec objects for ALTER and upgrade.
340  @param[in,out] thd thread handle. Used as a memory pool
341  and source of environment information.
342  @param[in] src_table DD table object. Will be nullptr for temporary
343  tables and during upgrade.
344  @param[in] table the source table, open and locked
345  Used as an interface to the storage engine
346  to acquire additional information about
347  the original table.
348  @param[in,out] create_info A blob with CREATE/ALTER TABLE
349  parameters
350  @param[in,out] alter_info Another blob with ALTER/CREATE parameters.
351  Originally create_info was used only in
352  CREATE TABLE and alter_info only in ALTER TABLE.
353  But since ALTER might end-up doing CREATE,
354  this distinction is gone and we just carry
355  around two structures.
356  @param[in,out] alter_ctx Runtime context for ALTER TABLE.
357  @param[in] used_fields used_fields from HA_CREATE_INFO.
358 
359  @retval true error, out of memory or a semantical error in ALTER
360  TABLE instructions
361  @retval false success
362 
363 */
364 bool prepare_fields_and_keys(THD *thd, const dd::Table *src_table, TABLE *table,
365  HA_CREATE_INFO *create_info,
366  Alter_info *alter_info, Alter_table_ctx *alter_ctx,
367  const uint &used_fields);
368 
369 bool mysql_prepare_alter_table(THD *thd, const dd::Table *src_table,
370  TABLE *table, HA_CREATE_INFO *create_info,
371  Alter_info *alter_info,
372  Alter_table_ctx *alter_ctx);
375 bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
376  HA_CREATE_INFO *create_info, TABLE_LIST *table_list,
377  Alter_info *alter_info);
378 bool mysql_compare_tables(TABLE *table, Alter_info *alter_info,
379  HA_CREATE_INFO *create_info, bool *metadata_equal);
380 bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy);
381 bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table,
382  HA_CREATE_INFO *create_info);
383 bool mysql_rename_table(THD *thd, handlerton *base, const char *old_db,
384  const char *old_name, const char *old_fk_db,
385  const char *old_fk_name, const dd::Schema &new_schema,
386  const char *new_db, const char *new_name, uint flags);
387 
388 bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list,
389  HA_CHECK_OPT *check_opt);
390 bool mysql_rm_table(THD *thd, TABLE_LIST *tables, bool if_exists,
391  bool drop_temporary);
392 bool mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
393  bool drop_temporary, bool drop_database,
394  bool *dropped_non_atomic_flag,
395  std::set<handlerton *> *post_ddl_htons,
396  Foreign_key_parents_invalidator *fk_invalidator,
397  std::vector<MDL_ticket *> *safe_to_release_mdl);
398 
399 /**
400  Discover missing tables in SE and acquire locks on tables which participate
401  in FKs on tables to be dropped by DROP TABLES/DATABASE and which definitions
402  will have to be updated or invalidated during this operation.
403 
404  @param thd Thread context.
405  @param tables Tables to be dropped by DROP TABLES/DATABASE.
406 
407  @retval False - Success.
408  @retval True - Failure.
409 */
411  MY_ATTRIBUTE((warn_unused_result));
412 
413 bool quick_rm_table(THD *thd, handlerton *base, const char *db,
414  const char *table_name, uint flags);
415 bool prepare_sp_create_field(THD *thd, Create_field *field_def);
417  longlong table_flags);
418 
420  const HA_CREATE_INFO *create_info);
421 bool validate_comment_length(THD *thd, const char *comment_str,
422  size_t *comment_len, uint max_len, uint err_code,
423  const char *comment_name);
424 int write_bin_log(THD *thd, bool clear_error, const char *query,
425  size_t query_length, bool is_trans = false);
426 void promote_first_timestamp_column(List<Create_field> *column_definitions);
427 
428 /**
429  Prepares the column definitions for table creation.
430 
431  @param thd Thread object.
432  @param create_info Create information.
433  @param[in,out] create_list List of columns to create.
434  @param[in,out] select_field_pos Position where the SELECT columns start
435  for CREATE TABLE ... SELECT.
436  @param file The handler for the new table.
437  @param[in,out] sql_field Create_field to populate.
438  @param field_no Column number.
439 
440  @retval false OK
441  @retval true error
442 */
443 
444 bool prepare_create_field(THD *thd, HA_CREATE_INFO *create_info,
445  List<Create_field> *create_list,
446  int *select_field_pos, handler *file,
447  Create_field *sql_field, int field_no);
448 
449 /**
450  Prepares the table and key structures for table creation.
451 
452  @param thd Thread object.
453  @param error_schema_name Schema name of the table to create/alter,
454  only error reporting.
455  @param error_table_name Name of table to create/alter, only used for
456  error reporting.
457  @param create_info Create information (like MAX_ROWS).
458  @param alter_info List of columns and indexes to create
459  @param file The handler for the new table.
460  @param is_partitioned Indicates whether table is partitioned.
461  @param[out] key_info_buffer An array of KEY structs for the indexes.
462  @param[out] key_count The number of elements in the array.
463  @param[out] fk_key_info_buffer An array of FOREIGN_KEY structs for the
464  foreign keys.
465  @param[out] fk_key_count The number of elements in the array.
466  @param[in] existing_fks An array of pre-existing FOREIGN KEYS
467  (in case of ALTER).
468  @param[in] existing_fks_count The number of pre-existing foreign keys.
469  @param[in] existing_fks_table dd::Table object for table version from
470  which pre-existing foreign keys come from.
471  Needed for error reporting.
472  @param[in] fk_max_generated_name_number Max value of number component among
473  existing generated foreign key names.
474  @param select_field_count The number of fields coming from a select
475  table.
476  @param find_parent_keys Indicates whether we need to lookup name of
477  unique constraint in parent table for foreign
478  keys.
479 
480  @retval false OK
481  @retval true error
482 */
483 
485  THD *thd, const char *error_schema_name, const char *error_table_name,
486  HA_CREATE_INFO *create_info, Alter_info *alter_info, handler *file,
487  bool is_partitioned, KEY **key_info_buffer, uint *key_count,
488  FOREIGN_KEY **fk_key_info_buffer, uint *fk_key_count,
489  FOREIGN_KEY *existing_fks, uint existing_fks_count,
490  const dd::Table *existing_fks_table, uint fk_max_generated_name_number,
491  int select_field_count, bool find_parent_keys);
492 
493 size_t explain_filename(THD *thd, const char *from, char *to, size_t to_length,
494  enum_explain_filename_mode explain_mode);
495 
496 void parse_filename(const char *filename, size_t filename_length,
497  const char **schema_name, size_t *schema_name_length,
498  const char **table_name, size_t *table_name_length,
499  const char **partition_name, size_t *partition_name_length,
500  const char **subpartition_name,
501  size_t *subpartition_name_length);
502 
503 extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
504 
505 /**
506  Acquire metadata lock on triggers associated with a list of tables.
507 
508  @param[in] thd Current thread context
509  @param[in] tables Tables for that associated triggers have to locked.
510 
511  @return Operation status.
512  @retval false Success
513  @retval true Failure
514 */
515 
516 bool lock_trigger_names(THD *thd, TABLE_LIST *tables);
517 struct TYPELIB;
519 
520 /**
521  Method to collect check constraint names for the all the tables and acquire
522  MDL lock on them.
523 
524  @param[in] thd Thread handle.
525  @param[in] tables Check constraints of tables to be locked.
526 
527  @retval false Success.
528  @retval true Failure.
529 */
530 bool lock_check_constraint_names(THD *thd, TABLE_LIST *tables);
531 
532 /**
533  Method to lock check constraint names for rename table operation.
534  Method acquire locks on the constraint names of source table and
535  also on the name of check constraint in the target table.
536 
537  @param[in] thd Thread handle.
538  @param[in] db Database name.
539  @param[in] table_name Table name.
540  @param[in] table_def DD table object of source table.
541  @param[in] target_db Target database name.
542  @param[in] target_table_name Target table name.
543 
544  @retval false Success.
545  @retval true Failure.
546 */
547 bool lock_check_constraint_names_for_rename(THD *thd, const char *db,
548  const char *table_name,
549  const dd::Table *table_def,
550  const char *target_db,
551  const char *target_table_name);
552 
553 /**
554  Method to prepare check constraints for the CREATE operation. If name of the
555  check constraint is not specified then name is generated, check constraint
556  is pre-validated and MDL on check constraint is acquired.
557 
558  @param thd Thread handle.
559  @param db_name Database name.
560  @param table_name Table name.
561  @param alter_info Alter_info object with list of
562  check constraints to be created.
563 
564  @retval false Success.
565  @retval true Failure.
566 */
567 bool prepare_check_constraints_for_create(THD *thd, const char *db_name,
568  const char *table_name,
569  Alter_info *alter_info);
570 #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:177
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 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:17958
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:15241
Definition: handler.h:3195
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 mysql_trans_commit_alter_copy_data(THD *thd)
Commit the copy phase of the alter table.
Definition: sql_table.cc:17303
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:4236
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4009
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:14640
bool mysql_checksum_table(THD *thd, TABLE_LIST *table_list, HA_CHECK_OPT *check_opt)
Definition: sql_table.cc:17635
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:18661
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:2913
Definition: table.h:1301
const CHARSET_INFO * get_sql_field_charset(const Create_field *sql_field, const HA_CREATE_INFO *create_info)
Definition: sql_table.cc:3955
Functions related to handling of plugins and other dynamically loaded libraries.
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:9443
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:6081
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:17285
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:10172
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:14320
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:54
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:3929
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2272
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:9406
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:8832
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:11710
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:8660
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
Definition: sql_table.cc:17610
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:8900
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:3978
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:14664
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:3868
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:7499
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:7914
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:9520
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:13685
std::map< std::pair< dd::String_type, dd::String_type >, handlerton * > Parent_map
Definition: sql_table.h:119
Definition: handler.h:2629
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:2468
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:18721
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:9180
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:9946
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:778
const char * table_name
Definition: rules_table_service.cc:55