MySQL 8.0.31
Source Code Documentation
dict0inst.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 2018, 2022, Oracle and/or its affiliates.
3
4This program is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License, version 2.0, as published by the
6Free Software Foundation.
7
8This program is also distributed with certain software (including but not
9limited to OpenSSL) that is licensed under separate terms, as designated in a
10particular file or component or in included license documentation. The authors
11of MySQL hereby grant you an additional permission to link the program and
12your derivative works with the separately licensed software that they have
13included with MySQL.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
18for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24*****************************************************************************/
25
26/** @file dict0inst.h
27Instant DDL interface
28
29Created 2020-04-24 by Mayank Prasad. */
30
31#ifndef dict0inst_h
32#define dict0inst_h
33
34#include "dict0dd.h"
35#include "ha_innopart.h"
36#include "handler0alter.h"
37
38/** Flags indicating if current operation can be done instantly */
39enum class Instant_Type : uint16_t {
40 /** Impossible to alter instantly */
42
43 /** Can be instant without any change */
45
46 /** Adding or dropping virtual columns only */
48
49 /** ADD/DROP COLUMN which can be done instantly, including adding/dropping
50 stored column only (or along with adding/dropping virtual columns) */
52
53 /** Column rename */
55};
56
57using Columns = std::vector<Field *>;
58
59template <typename Table>
61 public:
62 Instant_ddl_impl() = delete;
63
64 /** Constructor
65 @param[in] alter_info inplace alter information
66 @param[in] thd user thread
67 @param[in] trx transaction
68 @param[in,out] dict_table innodb dictionary cache object
69 @param[in] old_table old global DD cache object
70 @param[in,out] altered_table new MySQL table object
71 @param[in] old_dd_tab old global DD cache object
72 @param[in,out] new_dd_tab new global DD cache object
73 @param[in] autoinc auto increment */
75 dict_table_t *dict_table, const TABLE *old_table,
76 const TABLE *altered_table, const Table *old_dd_tab,
77 Table *new_dd_tab, uint64_t *autoinc)
78 : m_ha_alter_info(alter_info),
79 m_thd(thd),
80 m_trx(trx),
81 m_dict_table(dict_table),
82 m_old_table(old_table),
83 m_altered_table(altered_table),
84 m_old_dd_tab(old_dd_tab),
85 m_new_dd_tab(new_dd_tab),
86 m_autoinc(autoinc) {}
87
88 /** Destructor */
90
91 /** Commit instant DDL */
92 void commit_instant_ddl();
93
94 /** Check if INSTANT ADD can be done.
95 @param[in] ha_alter_info alter info
96 @param[in] table MySQL table before ALTER
97 @param[in] altered_table MySQL table after ALTER
98 @param[in] dict_table InnoDB table definition cache
99 @return true if INSTANT ADD can be done, false otherwise. */
100 static bool is_instant_add_possible(const Alter_inplace_info *ha_alter_info,
101 const TABLE *table,
102 const TABLE *altered_table,
103 const dict_table_t *dict_table);
104
105 private:
106 /** Add column instantly */
108
109 /** Add column instantly */
111
112 /** Add columns instantly */
114
115 /** Drop columns instantly */
117
118 /** Fetch columns which are to be added or dropped instantly */
120
121 /** Update metadata in commit phase when the alter table does
122 no change to the table
123 @param[in] ignore_fts ignore FTS update if true */
124 void dd_commit_inplace_no_change(bool ignore_fts);
125
126 private:
127 /* Columns which are to be added instantly */
129
130 /* Columns which are to be dropped instantly */
132
133 /* Inpalce alter info */
135
136 /* User thread */
138
139 /* Transaction */
141
142 /* InnoDB dictionary table object */
144
145 /* MySQL table as it is before the ALTER operation */
147
148 /* MySQL table that is being altered */
150
151 /* Old Table/Partition definition */
152 const Table *m_old_dd_tab;
153
154 /* New Table/Partition definition */
156
157 uint64_t *m_autoinc;
158};
159
160#endif /* dict0inst_h */
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:3136
Definition: dict0inst.h:60
void commit_instant_drop_col()
Drop columns instantly.
Instant_ddl_impl(Alter_inplace_info *alter_info, THD *thd, trx_t *trx, dict_table_t *dict_table, const TABLE *old_table, const TABLE *altered_table, const Table *old_dd_tab, Table *new_dd_tab, uint64_t *autoinc)
Constructor.
Definition: dict0inst.h:74
dict_table_t * m_dict_table
Definition: dict0inst.h:143
trx_t * m_trx
Definition: dict0inst.h:140
Columns m_cols_to_drop
Definition: dict0inst.h:131
void commit_instant_drop_col_low()
Add column instantly.
Definition: dict0inst.cc:151
void commit_instant_add_col()
Add columns instantly.
Columns m_cols_to_add
Definition: dict0inst.h:128
Instant_ddl_impl()=delete
Table * m_new_dd_tab
Definition: dict0inst.h:155
const TABLE * m_altered_table
Definition: dict0inst.h:149
void commit_instant_add_col_low()
Add column instantly.
Definition: dict0inst.cc:117
THD * m_thd
Definition: dict0inst.h:137
void populate_to_be_instant_columns()
Fetch columns which are to be added or dropped instantly.
Definition: dict0inst.cc:412
~Instant_ddl_impl()
Destructor.
Definition: dict0inst.h:89
Alter_inplace_info * m_ha_alter_info
Definition: dict0inst.h:134
void commit_instant_ddl()
Commit instant DDL.
Definition: dict0inst.cc:184
void dd_commit_inplace_no_change(bool ignore_fts)
Update metadata in commit phase when the alter table does no change to the table.
Definition: dict0inst.cc:419
uint64_t * m_autoinc
Definition: dict0inst.h:157
static bool is_instant_add_possible(const Alter_inplace_info *ha_alter_info, const TABLE *table, const TABLE *altered_table, const dict_table_t *dict_table)
Check if INSTANT ADD can be done.
Definition: dict0inst.cc:41
const TABLE * m_old_table
Definition: dict0inst.h:146
const Table * m_old_dd_tab
Definition: dict0inst.h:152
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
Data dictionary interface.
std::vector< Field * > Columns
Definition: dict0dd.h:774
Instant_Type
Flags indicating if current operation can be done instantly.
Definition: dict0inst.h:39
@ INSTANT_VIRTUAL_ONLY
Adding or dropping virtual columns only.
@ INSTANT_NO_CHANGE
Can be instant without any change.
@ INSTANT_ADD_DROP_COLUMN
ADD/DROP COLUMN which can be done instantly, including adding/dropping stored column only (or along w...
@ INSTANT_COLUMN_RENAME
Column rename.
@ INSTANT_IMPOSSIBLE
Impossible to alter instantly.
Smart ALTER TABLE.
Definition: table.h:1396
Data structure for a database table.
Definition: dict0mem.h:1884
Definition: trx0trx.h:680