MySQL 8.3.0
Source Code Documentation
dict0inst.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 2018, 2023, 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 @retval true Failure
93 @retval false Success */
94 bool commit_instant_ddl();
95
96 /** Check if INSTANT ADD/DROP can be done.
97 @param[in] ha_alter_info alter info
98 @param[in] table MySQL table before ALTER
99 @param[in] altered_table MySQL table after ALTER
100 @param[in] dict_table InnoDB table definition cache
101 @return true if INSTANT ADD/DROP can be done, false otherwise. */
103 const Alter_inplace_info *ha_alter_info, const TABLE *table,
104 const TABLE *altered_table, const dict_table_t *dict_table);
105
106 private:
107 /** Add column instantly
108 @retval true Failure
109 @retval false Success */
111
112 /** Add column instantly
113 @retval true Failure
114 @retval false Success */
116
117 /** Add columns instantly
118 @retval true Failure
119 @retval false Success */
121
122 /** Drop columns instantly
123 @retval true Failure
124 @retval false Success */
126
127 /** Fetch columns which are to be added or dropped instantly */
129
130 /** Update metadata in commit phase when the alter table does
131 no change to the table
132 @param[in] ignore_fts ignore FTS update if true */
133 void dd_commit_inplace_no_change(bool ignore_fts);
134
135 private:
136 /* Columns which are to be added instantly */
138
139 /* Columns which are to be dropped instantly */
141
142 /* Inpalce alter info */
144
145 /* User thread */
147
148 /* Transaction */
150
151 /* InnoDB dictionary table object */
153
154 /* MySQL table as it is before the ALTER operation */
156
157 /* MySQL table that is being altered */
159
160 /* Old Table/Partition definition */
161 const Table *m_old_dd_tab;
162
163 /* New Table/Partition definition */
165
166 uint64_t *m_autoinc;
167};
168
169#endif /* dict0inst_h */
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:3328
Definition: dict0inst.h:60
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:152
trx_t * m_trx
Definition: dict0inst.h:149
bool commit_instant_drop_col_low()
Add column instantly.
Definition: dict0inst.cc:156
Columns m_cols_to_drop
Definition: dict0inst.h:140
Columns m_cols_to_add
Definition: dict0inst.h:137
Instant_ddl_impl()=delete
bool commit_instant_add_col()
Add columns instantly.
bool commit_instant_add_col_low()
Add column instantly.
Definition: dict0inst.cc:118
Table * m_new_dd_tab
Definition: dict0inst.h:164
const TABLE * m_altered_table
Definition: dict0inst.h:158
THD * m_thd
Definition: dict0inst.h:146
void populate_to_be_instant_columns()
Fetch columns which are to be added or dropped instantly.
Definition: dict0inst.cc:422
~Instant_ddl_impl()
Destructor.
Definition: dict0inst.h:89
bool commit_instant_ddl()
Commit instant DDL.
Definition: dict0inst.cc:193
Alter_inplace_info * m_ha_alter_info
Definition: dict0inst.h:143
bool commit_instant_drop_col()
Drop columns instantly.
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:429
uint64_t * m_autoinc
Definition: dict0inst.h:166
const TABLE * m_old_table
Definition: dict0inst.h:155
const Table * m_old_dd_tab
Definition: dict0inst.h:161
static bool is_instant_add_drop_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/DROP can be done.
Definition: dict0inst.cc:41
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Data dictionary interface.
std::vector< Field * > Columns
Definition: dict0dd.h:776
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.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
Definition: table.h:1403
Data structure for a database table.
Definition: dict0mem.h:1908
Definition: trx0trx.h:683