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