MySQL 8.4.0
Source Code Documentation
sql_alter.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_ALTER_TABLE_H
25#define SQL_ALTER_TABLE_H
26
27#include <assert.h>
28#include <stddef.h>
29#include <sys/types.h>
30#include <functional> // std::function
31#include <optional>
32
33#include "lex_string.h"
34
35#include "field_types.h"
36#include "my_io.h"
37#include "my_sqlcommand.h"
39#include "sql/dd/types/column.h"
40#include "sql/gis/srid.h"
41#include "sql/mdl.h" // MDL_request
42#include "sql/mem_root_array.h" // Mem_root_array
43#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec_list
44#include "sql/sql_cmd.h" // Sql_cmd
45#include "sql/sql_cmd_ddl_table.h" // Sql_cmd_ddl_table
46#include "sql/sql_list.h" // List
47#include "sql/thr_malloc.h"
48
49class Alter_info;
50class Create_field;
51class FOREIGN_KEY;
52class Value_generator;
53class Item;
54class Key_spec;
55class String;
56class THD;
57struct CHARSET_INFO;
58class Table_ref;
59
60/**
61 Class representing DROP COLUMN, DROP KEY, DROP FOREIGN KEY, DROP CHECK
62 CONSTRAINT and DROP CONSTRAINT clauses in ALTER TABLE statement.
63*/
64
66 public:
68 const char *name;
70
71 Alter_drop(drop_type par_type, const char *par_name)
72 : name(par_name), type(par_type) {
73 assert(par_name != nullptr);
74 }
75};
76
77/**
78 Class representing SET DEFAULT, DROP DEFAULT, RENAME COLUMN, SET VISIBLE and
79 SET INVISIBLE clause in ALTER TABLE statement.
80*/
81
83 public:
84 /// The column name being altered.
85 const char *name;
86
87 /// The default value supplied.
89
90 /// The expression to be used to generate the default value.
92
93 /// The new column name.
94 const char *m_new_name;
95
96 enum class Type {
102 };
103
104 public:
105 /// Type of change requested in ALTER TABLE.
106 inline Type change_type() const { return m_type; }
107
108 /// Constructor used when altering the field's default value with a literal
109 /// constant or when dropping a field's default value.
110 Alter_column(const char *par_name, Item *literal)
111 : name(par_name),
112 def(literal),
115 if (def)
117 else
119 }
120
121 /// Constructor used when setting a field's DEFAULT value to an expression.
122 Alter_column(const char *par_name, Value_generator *gen_def)
123 : name(par_name),
124 def(nullptr),
125 m_default_val_expr(gen_def),
127 m_type(Type::SET_DEFAULT) {}
128
129 /// Constructor used while renaming field name.
130 Alter_column(const char *old_name, const char *new_name)
131 : name(old_name),
132 def(nullptr),
133 m_new_name(new_name),
134 m_type(Type::RENAME_COLUMN) {}
135
136 /// Constructor used while altering column visibility.
137 Alter_column(const char *par_name, bool par_is_visible)
138 : name(par_name), def(nullptr), m_new_name(nullptr) {
139 m_type = (par_is_visible ? Type::SET_COLUMN_VISIBLE
141 }
142
143 private:
145};
146
147/// An ALTER INDEX operation that changes the visibility of an index.
149 public:
152 assert(name != nullptr);
153 }
154
155 const char *name() const { return m_name; }
156
157 /// The visibility after the operation is performed.
158 bool is_visible() const { return m_is_visible; }
159
160 private:
161 const char *m_name;
163};
164
165/**
166 Class which instances represent RENAME INDEX clauses in
167 ALTER TABLE statement.
168*/
169
171 public:
172 const char *old_name;
173 const char *new_name;
174
175 Alter_rename_key(const char *old_name_arg, const char *new_name_arg)
176 : old_name(old_name_arg), new_name(new_name_arg) {}
177};
178
179/**
180 Class representing ALTER CHECK and ALTER CONSTRAINT clauses in ALTER TABLE
181 statement.
182*/
183
185 public:
187 const char *name;
190
191 Alter_constraint_enforcement(Type par_type, const char *par_name,
192 bool par_is_enforced)
193 : name(par_name), type(par_type), is_enforced(par_is_enforced) {
194 assert(par_name != nullptr);
195 }
196};
197
198using CreateFieldApplier = std::function<bool(Create_field *, Alter_info *)>;
199
200/**
201 Data describing the table being created by CREATE TABLE or
202 altered by ALTER TABLE.
203*/
204
206 public:
207 /*
208 These flags are set by the parser and describes the type of
209 operation(s) specified by the ALTER TABLE statement.
210
211 They do *not* describe the type operation(s) to be executed
212 by the storage engine. For example, we don't yet know the
213 type of index to be added/dropped.
214 */
215
217 /// Set for ADD [COLUMN]
218 ALTER_ADD_COLUMN = 1ULL << 0,
219
220 /// Set for DROP [COLUMN]
221 ALTER_DROP_COLUMN = 1ULL << 1,
222
223 /// Set for CHANGE [COLUMN] | MODIFY [CHANGE]
224 /// Set by mysql_recreate_table()
226
227 /// Set for ADD INDEX | ADD KEY | ADD PRIMARY KEY | ADD UNIQUE KEY |
228 /// ADD UNIQUE INDEX | ALTER ADD [COLUMN]
229 ALTER_ADD_INDEX = 1ULL << 3,
230
231 /// Set for DROP PRIMARY KEY | DROP FOREIGN KEY | DROP KEY | DROP INDEX
232 ALTER_DROP_INDEX = 1ULL << 4,
233
234 /// Set for RENAME [TO]
235 ALTER_RENAME = 1ULL << 5,
236
237 /// Set for ORDER BY
238 ALTER_ORDER = 1ULL << 6,
239
240 /// Set for table_options
241 ALTER_OPTIONS = 1ULL << 7,
242
243 /// Set for ALTER [COLUMN] ... SET DEFAULT ... | DROP DEFAULT
245
246 /// Set for DISABLE KEYS | ENABLE KEYS
247 ALTER_KEYS_ONOFF = 1ULL << 9,
248
249 /// Set for FORCE
250 /// Set for ENGINE(same engine)
251 /// Set by mysql_recreate_table()
252 ALTER_RECREATE = 1ULL << 10,
253
254 /// Set for ADD PARTITION
256
257 /// Set for DROP PARTITION
259
260 /// Set for COALESCE PARTITION
262
263 /// Set for REORGANIZE PARTITION ... INTO
265
266 /// Set for partition_options
267 ALTER_PARTITION = 1ULL << 15,
268
269 /// Set for LOAD INDEX INTO CACHE ... PARTITION
270 /// Set for CACHE INDEX ... PARTITION
272
273 /// Set for REORGANIZE PARTITION
274 ALTER_TABLE_REORG = 1ULL << 17,
275
276 /// Set for REBUILD PARTITION
278
279 /// Set for partitioning operations specifying ALL keyword
281
282 /// Set for REMOVE PARTITIONING
284
285 /// Set for ADD FOREIGN KEY
286 ADD_FOREIGN_KEY = 1ULL << 21,
287
288 /// Set for DROP FOREIGN KEY
289 DROP_FOREIGN_KEY = 1ULL << 22,
290
291 /// Set for EXCHANGE PARTITION
293
294 /// Set by Sql_cmd_alter_table_truncate_partition::execute()
296
297 /// Set for ADD [COLUMN] FIRST | AFTER
298 ALTER_COLUMN_ORDER = 1ULL << 25,
299
300 /// Set for RENAME INDEX
301 ALTER_RENAME_INDEX = 1ULL << 26,
302
303 /// Set for discarding the tablespace
305
306 /// Set for importing the tablespace
308
309 /// Means that the visibility of an index is changed.
311
312 /// Set for SECONDARY LOAD
314
315 /// Set for SECONDARY UNLOAD
317
318 /// Set for add check constraint.
320
321 /// Set for drop check constraint.
323
324 /// Set for check constraint enforce.
326
327 /// Set for check constraint suspend.
329
330 /// Set for DROP CONSTRAINT.
332
333 /// Set for ALTER CONSTRAINT symbol ENFORCED.
335
336 /// Set for ALTER CONSTRAINT symbol NOT ENFORCED.
338
339 /// Set if ANY engine attribute is used (also in CREATE) Note that
340 /// this is NOT to be set for SECONDARY_ENGINE_ATTRIBUTE as this flag
341 /// controls if execution should check if SE supports engine
342 /// attributes.
344
345 /// Set for column visibility attribute alter.
346 ALTER_COLUMN_VISIBILITY = 1ULL << 40
347 };
348
350
351 /**
352 The different values of the ALGORITHM clause.
353 Describes which algorithm to use when altering the table.
354 */
356 // In-place if supported, copy otherwise.
358
359 // In-place if supported, error otherwise.
361
362 // Instant if supported, error otherwise.
364
365 // Copy if supported, error otherwise.
367 };
368
369 /**
370 The different values of the LOCK clause.
371 Describes the level of concurrency during ALTER TABLE.
372 */
374 // Maximum supported level of concurrency for the given operation.
376
377 // Allow concurrent reads & writes. If not supported, give error.
379
380 // Allow concurrent reads only. If not supported, give error.
382
383 // Block reads and writes.
385 };
386
387 /**
388 Status of validation clause in ALTER TABLE statement. Used during
389 partitions and GC alterations.
390 */
392 /**
393 Default value, used when it's not specified in the statement.
394 Means WITH VALIDATION for partitions alterations and WITHOUT VALIDATION
395 for altering virtual GC.
396 */
400 };
401
402 /**
403 Columns, keys and constraints to be dropped.
404 */
406 // Columns for ALTER_COLUMN_CHANGE_DEFAULT.
408 // List of keys, used by both CREATE and ALTER TABLE.
409
411 // Keys to be renamed.
413
414 /// Indexes whose visibilities are to be changed.
416
417 /// List of check constraints whose enforcement state is changed.
420
421 /// Check constraints specification for CREATE and ALTER TABLE operations.
423
424 // List of columns, used by both CREATE and ALTER TABLE.
426 std::vector<CreateFieldApplier> cf_appliers;
427
428 // Type of ALTER TABLE operation.
430 // Enable or disable keys.
432 // List of partitions.
434 // Number of partitions.
436 // Type of ALTER TABLE algorithm.
438 // Type of ALTER TABLE lock.
440 /*
441 Whether VALIDATION is asked for an operation. Used during virtual GC and
442 partitions alterations.
443 */
445
446 /// "new_db" (if any) or "db" (if any) or default database from
447 /// ALTER TABLE [db.]table [ RENAME [TO|AS|=] [new_db.]new_table ]
449
450 /// New table name in the
451 /// \code
452 /// RENAME [TO] <table_name>
453 /// \endcode
454 /// clause or NULL_STR
456
465 flags(0),
467 num_parts(0),
473
474 /**
475 Construct a copy of this object to be used for mysql_alter_table
476 and mysql_create_table.
477
478 Historically, these two functions modify their Alter_info
479 arguments. This behaviour breaks re-execution of prepared
480 statements and stored procedures and is compensated by always
481 supplying a copy of Alter_info to these functions.
482
483 @param rhs Alter_info to make copy of
484 @param mem_root Mem_root for new Alter_info
485
486 @note You need to use check the error in THD for out
487 of memory condition after calling this function.
488 */
490
491 bool add_field(THD *thd, const LEX_STRING *field_name,
492 enum enum_field_types type, const char *length,
493 const char *decimal, uint type_modifier, Item *default_value,
494 Item *on_update_value, LEX_CSTRING *comment,
495 const char *change, List<String> *interval_list,
496 const CHARSET_INFO *cs, bool has_explicit_collation,
497 uint uint_geom_type, Value_generator *gcol_info,
498 Value_generator *default_val_expr, const char *opt_after,
499 std::optional<gis::srid_t> srid,
500 Sql_check_constraint_spec_list *check_cons_list,
501 dd::Column::enum_hidden_type hidden, bool is_array = false);
502
503 private:
504 Alter_info &operator=(const Alter_info &rhs); // not implemented
505 Alter_info(const Alter_info &rhs); // not implemented
506};
507
508/** Runtime context for ALTER TABLE. */
510 public:
512
513 Alter_table_ctx(THD *thd, Table_ref *table_list, uint tables_opened_arg,
514 const char *new_db_arg, const char *new_name_arg);
515
517
518 /**
519 @return true if the table is moved to another database, false otherwise.
520 */
521 bool is_database_changed() const { return (new_db != db); }
522
523 /**
524 @return true if the table name is changed, false otherwise.
525 */
526 bool is_table_name_changed() const { return (new_name != table_name); }
527
528 /**
529 @return true if the table is renamed (i.e. its name or database changed),
530 false otherwise.
531 */
532 bool is_table_renamed() const {
534 }
535
536 /**
537 @return path to the original table.
538 */
539 const char *get_path() const {
540 assert(!tmp_table);
541 return path;
542 }
543
544 /**
545 @return path to the temporary table created during ALTER TABLE.
546 */
547 const char *get_tmp_path() const { return tmp_path; }
548
549 public:
553
557 const char *db;
558 const char *table_name;
559 const char *alias;
560 const char *new_db;
561 const char *new_name;
562 const char *new_alias;
563 char tmp_name[80];
564
565 /* Used to remember which foreign keys already existed in the table. */
568 /**
569 Maximum number component used by generated foreign key names in the
570 old version of table.
571 */
573
574 /**
575 Metadata lock request on table's new name when this name or database
576 are changed.
577 */
579 /** Metadata lock request on table's new database if it is changed. */
581
582 private:
585 char path[FN_REFLEN + 1];
588
589#ifndef NDEBUG
590 /** Indicates that we are altering temporary table. Used only in asserts. */
592#endif
593
594 Alter_table_ctx &operator=(const Alter_table_ctx &rhs); // not implemented
595 Alter_table_ctx(const Alter_table_ctx &rhs); // not implemented
596};
597
598/**
599 Represents the common properties of the ALTER TABLE statements.
600 @todo move Alter_info and other ALTER generic structures from Lex here.
601*/
603 public:
605
606 ~Sql_cmd_common_alter_table() override = 0; // force abstract class
607
609};
610
612
613/**
614 Represents the generic ALTER TABLE statement.
615 @todo move Alter_info and other ALTER specific structures from Lex here.
616*/
618 public:
619 using Sql_cmd_common_alter_table::Sql_cmd_common_alter_table;
620
621 bool execute(THD *thd) override;
622};
623
624/**
625 Represents ALTER TABLE IMPORT/DISCARD TABLESPACE statements.
626*/
628 public:
629 using Sql_cmd_common_alter_table::Sql_cmd_common_alter_table;
630
631 bool execute(THD *thd) override;
632
633 private:
634 bool mysql_discard_or_import_tablespace(THD *thd, Table_ref *table_list);
635};
636
637/**
638 Represents ALTER TABLE SECONDARY_LOAD/SECONDARY_UNLOAD statements.
639*/
641 public:
642 // Inherit the constructors from the parent class.
643 using Sql_cmd_common_alter_table::Sql_cmd_common_alter_table;
644
645 bool execute(THD *thd) override;
646
647 private:
648 bool mysql_secondary_load_or_unload(THD *thd, Table_ref *table_list);
649};
650
651#endif
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Class representing SET DEFAULT, DROP DEFAULT, RENAME COLUMN, SET VISIBLE and SET INVISIBLE clause in ...
Definition: sql_alter.h:82
Alter_column(const char *old_name, const char *new_name)
Constructor used while renaming field name.
Definition: sql_alter.h:130
const char * m_new_name
The new column name.
Definition: sql_alter.h:94
Alter_column(const char *par_name, bool par_is_visible)
Constructor used while altering column visibility.
Definition: sql_alter.h:137
Value_generator * m_default_val_expr
The expression to be used to generate the default value.
Definition: sql_alter.h:91
Item * def
The default value supplied.
Definition: sql_alter.h:88
Alter_column(const char *par_name, Value_generator *gen_def)
Constructor used when setting a field's DEFAULT value to an expression.
Definition: sql_alter.h:122
Type
Definition: sql_alter.h:96
const char * name
The column name being altered.
Definition: sql_alter.h:85
Type change_type() const
Type of change requested in ALTER TABLE.
Definition: sql_alter.h:106
Alter_column(const char *par_name, Item *literal)
Constructor used when altering the field's default value with a literal constant or when dropping a f...
Definition: sql_alter.h:110
Type m_type
Definition: sql_alter.h:144
Class representing ALTER CHECK and ALTER CONSTRAINT clauses in ALTER TABLE statement.
Definition: sql_alter.h:184
const char * name
Definition: sql_alter.h:187
Type type
Definition: sql_alter.h:188
Type
Definition: sql_alter.h:186
Alter_constraint_enforcement(Type par_type, const char *par_name, bool par_is_enforced)
Definition: sql_alter.h:191
bool is_enforced
Definition: sql_alter.h:189
Class representing DROP COLUMN, DROP KEY, DROP FOREIGN KEY, DROP CHECK CONSTRAINT and DROP CONSTRAINT...
Definition: sql_alter.h:65
drop_type type
Definition: sql_alter.h:69
const char * name
Definition: sql_alter.h:68
Alter_drop(drop_type par_type, const char *par_name)
Definition: sql_alter.h:71
drop_type
Definition: sql_alter.h:67
@ FOREIGN_KEY
Definition: sql_alter.h:67
@ ANY_CONSTRAINT
Definition: sql_alter.h:67
@ KEY
Definition: sql_alter.h:67
@ COLUMN
Definition: sql_alter.h:67
@ CHECK_CONSTRAINT
Definition: sql_alter.h:67
An ALTER INDEX operation that changes the visibility of an index.
Definition: sql_alter.h:148
const char * m_name
Definition: sql_alter.h:161
bool is_visible() const
The visibility after the operation is performed.
Definition: sql_alter.h:158
Alter_index_visibility(const char *name, bool is_visible)
Definition: sql_alter.h:150
const char * name() const
Definition: sql_alter.h:155
bool m_is_visible
Definition: sql_alter.h:162
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:205
enum_alter_table_algorithm
The different values of the ALGORITHM clause.
Definition: sql_alter.h:355
@ ALTER_TABLE_ALGORITHM_DEFAULT
Definition: sql_alter.h:357
@ ALTER_TABLE_ALGORITHM_INPLACE
Definition: sql_alter.h:360
@ ALTER_TABLE_ALGORITHM_COPY
Definition: sql_alter.h:366
@ ALTER_TABLE_ALGORITHM_INSTANT
Definition: sql_alter.h:363
Sql_check_constraint_spec_list check_constraint_spec_list
Check constraints specification for CREATE and ALTER TABLE operations.
Definition: sql_alter.h:422
Alter_info & operator=(const Alter_info &rhs)
enum_alter_table_lock
The different values of the LOCK clause.
Definition: sql_alter.h:373
@ ALTER_TABLE_LOCK_DEFAULT
Definition: sql_alter.h:375
@ ALTER_TABLE_LOCK_EXCLUSIVE
Definition: sql_alter.h:384
@ ALTER_TABLE_LOCK_NONE
Definition: sql_alter.h:378
@ ALTER_TABLE_LOCK_SHARED
Definition: sql_alter.h:381
Alter_info(const Alter_info &rhs)
Mem_root_array< Key_spec * > key_list
Definition: sql_alter.h:410
Mem_root_array< const Alter_drop * > drop_list
Columns, keys and constraints to be dropped.
Definition: sql_alter.h:405
enum_alter_table_algorithm requested_algorithm
Definition: sql_alter.h:437
Mem_root_array< const Alter_constraint_enforcement * > alter_constraint_enforcement_list
List of check constraints whose enforcement state is changed.
Definition: sql_alter.h:419
enum_with_validation with_validation
Definition: sql_alter.h:444
List< String > partition_names
Definition: sql_alter.h:433
enum_with_validation
Status of validation clause in ALTER TABLE statement.
Definition: sql_alter.h:391
@ ALTER_VALIDATION_DEFAULT
Default value, used when it's not specified in the statement.
Definition: sql_alter.h:397
@ ALTER_WITHOUT_VALIDATION
Definition: sql_alter.h:399
@ ALTER_WITH_VALIDATION
Definition: sql_alter.h:398
enum_enable_or_disable
Definition: sql_alter.h:349
@ ENABLE
Definition: sql_alter.h:349
@ LEAVE_AS_IS
Definition: sql_alter.h:349
@ DISABLE
Definition: sql_alter.h:349
List< Create_field > create_list
Definition: sql_alter.h:425
Alter_info(MEM_ROOT *mem_root)
Definition: sql_alter.h:457
LEX_CSTRING new_table_name
New table name in the.
Definition: sql_alter.h:455
Mem_root_array< const Alter_column * > alter_list
Definition: sql_alter.h:407
LEX_CSTRING new_db_name
"new_db" (if any) or "db" (if any) or default database from ALTER TABLE [db.
Definition: sql_alter.h:448
enum_enable_or_disable keys_onoff
Definition: sql_alter.h:431
ulonglong flags
Definition: sql_alter.h:429
Mem_root_array< const Alter_rename_key * > alter_rename_key_list
Definition: sql_alter.h:412
std::vector< CreateFieldApplier > cf_appliers
Definition: sql_alter.h:426
uint num_parts
Definition: sql_alter.h:435
Alter_info_flag
Definition: sql_alter.h:216
@ ALTER_RENAME_INDEX
Set for RENAME INDEX.
Definition: sql_alter.h:301
@ ALTER_CHANGE_COLUMN_DEFAULT
Set for ALTER [COLUMN] ... SET DEFAULT ... | DROP DEFAULT.
Definition: sql_alter.h:244
@ ALTER_TRUNCATE_PARTITION
Set by Sql_cmd_alter_table_truncate_partition::execute()
Definition: sql_alter.h:295
@ DROP_CHECK_CONSTRAINT
Set for drop check constraint.
Definition: sql_alter.h:322
@ ALTER_REBUILD_PARTITION
Set for REBUILD PARTITION.
Definition: sql_alter.h:277
@ ALTER_DROP_INDEX
Set for DROP PRIMARY KEY | DROP FOREIGN KEY | DROP KEY | DROP INDEX.
Definition: sql_alter.h:232
@ ENFORCE_ANY_CONSTRAINT
Set for ALTER CONSTRAINT symbol ENFORCED.
Definition: sql_alter.h:334
@ ALTER_DROP_PARTITION
Set for DROP PARTITION.
Definition: sql_alter.h:258
@ ALTER_KEYS_ONOFF
Set for DISABLE KEYS | ENABLE KEYS.
Definition: sql_alter.h:247
@ ALTER_ADD_COLUMN
Set for ADD [COLUMN].
Definition: sql_alter.h:218
@ ALTER_INDEX_VISIBILITY
Means that the visibility of an index is changed.
Definition: sql_alter.h:310
@ ALTER_ADMIN_PARTITION
Set for LOAD INDEX INTO CACHE ... PARTITION Set for CACHE INDEX ... PARTITION.
Definition: sql_alter.h:271
@ ALTER_PARTITION
Set for partition_options.
Definition: sql_alter.h:267
@ ALTER_COLUMN_VISIBILITY
Set for column visibility attribute alter.
Definition: sql_alter.h:346
@ ALTER_ADD_PARTITION
Set for ADD PARTITION.
Definition: sql_alter.h:255
@ ADD_CHECK_CONSTRAINT
Set for add check constraint.
Definition: sql_alter.h:319
@ ALTER_RENAME
Set for RENAME [TO].
Definition: sql_alter.h:235
@ SUSPEND_CHECK_CONSTRAINT
Set for check constraint suspend.
Definition: sql_alter.h:328
@ ALTER_REORGANIZE_PARTITION
Set for REORGANIZE PARTITION ... INTO.
Definition: sql_alter.h:264
@ ALTER_ADD_INDEX
Set for ADD INDEX | ADD KEY | ADD PRIMARY KEY | ADD UNIQUE KEY | ADD UNIQUE INDEX | ALTER ADD [COLUMN...
Definition: sql_alter.h:229
@ ALTER_COALESCE_PARTITION
Set for COALESCE PARTITION.
Definition: sql_alter.h:261
@ DROP_FOREIGN_KEY
Set for DROP FOREIGN KEY.
Definition: sql_alter.h:289
@ ALTER_ALL_PARTITION
Set for partitioning operations specifying ALL keyword.
Definition: sql_alter.h:280
@ ALTER_CHANGE_COLUMN
Set for CHANGE [COLUMN] | MODIFY [CHANGE] Set by mysql_recreate_table()
Definition: sql_alter.h:225
@ ALTER_SECONDARY_LOAD
Set for SECONDARY LOAD.
Definition: sql_alter.h:313
@ ALTER_DROP_COLUMN
Set for DROP [COLUMN].
Definition: sql_alter.h:221
@ ALTER_RECREATE
Set for FORCE Set for ENGINE(same engine) Set by mysql_recreate_table()
Definition: sql_alter.h:252
@ ALTER_EXCHANGE_PARTITION
Set for EXCHANGE PARTITION.
Definition: sql_alter.h:292
@ ALTER_IMPORT_TABLESPACE
Set for importing the tablespace.
Definition: sql_alter.h:307
@ ANY_ENGINE_ATTRIBUTE
Set if ANY engine attribute is used (also in CREATE) Note that this is NOT to be set for SECONDARY_EN...
Definition: sql_alter.h:343
@ ALTER_OPTIONS
Set for table_options.
Definition: sql_alter.h:241
@ ALTER_SECONDARY_UNLOAD
Set for SECONDARY UNLOAD.
Definition: sql_alter.h:316
@ ALTER_REMOVE_PARTITIONING
Set for REMOVE PARTITIONING.
Definition: sql_alter.h:283
@ DROP_ANY_CONSTRAINT
Set for DROP CONSTRAINT.
Definition: sql_alter.h:331
@ ENFORCE_CHECK_CONSTRAINT
Set for check constraint enforce.
Definition: sql_alter.h:325
@ ALTER_COLUMN_ORDER
Set for ADD [COLUMN] FIRST | AFTER.
Definition: sql_alter.h:298
@ SUSPEND_ANY_CONSTRAINT
Set for ALTER CONSTRAINT symbol NOT ENFORCED.
Definition: sql_alter.h:337
@ ALTER_DISCARD_TABLESPACE
Set for discarding the tablespace.
Definition: sql_alter.h:304
@ ADD_FOREIGN_KEY
Set for ADD FOREIGN KEY.
Definition: sql_alter.h:286
@ ALTER_ORDER
Set for ORDER BY.
Definition: sql_alter.h:238
@ ALTER_TABLE_REORG
Set for REORGANIZE PARTITION.
Definition: sql_alter.h:274
Mem_root_array< const Alter_index_visibility * > alter_index_visibility_list
Indexes whose visibilities are to be changed.
Definition: sql_alter.h:415
enum_alter_table_lock requested_lock
Definition: sql_alter.h:439
Class which instances represent RENAME INDEX clauses in ALTER TABLE statement.
Definition: sql_alter.h:170
Alter_rename_key(const char *old_name_arg, const char *new_name_arg)
Definition: sql_alter.h:175
const char * new_name
Definition: sql_alter.h:173
const char * old_name
Definition: sql_alter.h:172
Runtime context for ALTER TABLE.
Definition: sql_alter.h:509
bool tmp_table
Indicates that we are altering temporary table.
Definition: sql_alter.h:591
char path[FN_REFLEN+1]
Definition: sql_alter.h:585
bool is_database_changed() const
Definition: sql_alter.h:521
Alter_table_ctx(const Alter_table_ctx &rhs)
const char * table_name
Definition: sql_alter.h:558
uint error_if_not_empty_mask
Definition: sql_alter.h:550
bool is_table_renamed() const
Definition: sql_alter.h:532
const char * new_name
Definition: sql_alter.h:561
uint fk_count
Definition: sql_alter.h:567
static const error_if_not_empty_mask DATETIME_WITHOUT_DEFAULT
Definition: sql_alter.h:551
FOREIGN_KEY * fk_info
Definition: sql_alter.h:566
char tmp_path[FN_REFLEN+1]
Definition: sql_alter.h:587
char tmp_name[80]
Definition: sql_alter.h:563
MDL_request target_db_mdl_request
Metadata lock request on table's new database if it is changed.
Definition: sql_alter.h:580
Alter_table_ctx & operator=(const Alter_table_ctx &rhs)
static const error_if_not_empty_mask GEOMETRY_WITHOUT_DEFAULT
Definition: sql_alter.h:552
bool is_table_name_changed() const
Definition: sql_alter.h:526
Alter_table_ctx()
Definition: sql_alter.cc:98
const char * get_tmp_path() const
Definition: sql_alter.h:547
const char * new_db
Definition: sql_alter.h:560
MDL_request target_mdl_request
Metadata lock request on table's new name when this name or database are changed.
Definition: sql_alter.h:578
const char * db
Definition: sql_alter.h:557
error_if_not_empty_mask error_if_not_empty
Definition: sql_alter.h:555
const char * new_alias
Definition: sql_alter.h:562
char new_alias_buff[FN_REFLEN+1]
Definition: sql_alter.h:584
Create_field * datetime_field
Definition: sql_alter.h:554
const char * get_path() const
Definition: sql_alter.h:539
char new_filename[FN_REFLEN+1]
Definition: sql_alter.h:583
uint fk_max_generated_name_number
Maximum number component used by generated foreign key names in the old version of table.
Definition: sql_alter.h:572
uint tables_opened
Definition: sql_alter.h:556
const char * alias
Definition: sql_alter.h:559
char new_path[FN_REFLEN+1]
Definition: sql_alter.h:586
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Definition: key.h:43
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:934
Definition: key_spec.h:208
Definition: sql_list.h:467
A pending metadata lock request.
Definition: mdl.h:802
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Represents the generic ALTER TABLE statement.
Definition: sql_alter.h:617
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_alter.cc:219
Represents the common properties of the ALTER TABLE statements.
Definition: sql_alter.h:602
~Sql_cmd_common_alter_table() override=0
enum_sql_command sql_command_code() const final
Return the command code for this statement.
Definition: sql_alter.h:608
A base class for CREATE/ALTER TABLE commands and friends.
Definition: sql_cmd_ddl_table.h:50
Sql_cmd_ddl_table(Alter_info *alter_info)
Definition: sql_cmd_ddl_table.cc:68
Represents ALTER TABLE IMPORT/DISCARD TABLESPACE statements.
Definition: sql_alter.h:627
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_alter.cc:359
bool mysql_discard_or_import_tablespace(THD *thd, Table_ref *table_list)
Definition: sql_table.cc:11410
Represents ALTER TABLE SECONDARY_LOAD/SECONDARY_UNLOAD statements.
Definition: sql_alter.h:640
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_alter.cc:413
bool mysql_secondary_load_or_unload(THD *thd, Table_ref *table_list)
Loads a table into a secondary engine if SECONDARY_LOAD, unloads from secondary engine if SECONDARY_U...
Definition: sql_table.cc:11649
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2863
Used for storing information associated with generated column, default values generated from expressi...
Definition: field.h:483
enum_hidden_type
Definition: column.h:95
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
bool add_field(THD *thd, const LEX_STRING *field_name, enum enum_field_types type, const char *length, const char *decimal, uint type_modifier, Item *default_value, Item *on_update_value, LEX_CSTRING *comment, const char *change, List< String > *interval_list, const CHARSET_INFO *cs, bool has_explicit_collation, uint uint_geom_type, Value_generator *gcol_info, Value_generator *default_val_expr, const char *opt_after, std::optional< gis::srid_t > srid, Sql_check_constraint_spec_list *check_cons_list, dd::Column::enum_hidden_type hidden, bool is_array=false)
Store field definition for create.
Definition: sql_parse.cc:5518
#define comment
Definition: lexyy.cc:959
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:83
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_ALTER_TABLE
Definition: my_sqlcommand.h:50
Definition: commit_order_queue.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Performance schema instrumentation interface.
required string type
Definition: replication_group_member_actions.proto:34
std::function< bool(Create_field *, Alter_info *)> CreateFieldApplier
Definition: sql_alter.h:198
Representation of an SQL command.
Definition: m_ctype.h:423
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: mysql_lex_string.h:35
A structure to store a decimal value together with its precision and number of decimals TODO: HCS-100...
Definition: protocol_local_v2.h:43