Debian Codegraph @

storage/innobase/include/dict0inst.h

raw
1 /*****************************************************************************
2 Copyright (c) 2018, 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License, version 2.0, as published by the
6 Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25 *****************************************************************************/
26
27 /** @file dict0inst.h
28 Instant DDL interface
29
30 Created 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 */
40 enum class Instant_Type : uint16_t {
41 /** Impossible to alter instantly */
42 INSTANT_IMPOSSIBLE,
43
44 /** Can be instant without any change */
45 INSTANT_NO_CHANGE,
46
47 /** Adding or dropping virtual columns only */
48 INSTANT_VIRTUAL_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) */
52 INSTANT_ADD_DROP_COLUMN,
53
54 /** Column rename */
55 INSTANT_COLUMN_RENAME
56 };
57
58 using Columns = std::vector<Field *>;
59
60 template <typename Table>
61 class Instant_ddl_impl {
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 */
75 Instant_ddl_impl(Alter_inplace_info *alter_info, THD *thd, trx_t *trx,
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 */
90 ~Instant_ddl_impl() {}
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. */
103 static bool is_instant_add_drop_possible(
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 */
111 bool commit_instant_add_col_low();
112
113 /** Add column instantly
114 @retval true Failure
115 @retval false Success */
116 bool commit_instant_drop_col_low();
117
118 /** Add columns instantly
119 @retval true Failure
120 @retval false Success */
121 bool commit_instant_add_col();
122
123 /** Drop columns instantly
124 @retval true Failure
125 @retval false Success */
126 bool commit_instant_drop_col();
127
128 /** Fetch columns which are to be added or dropped instantly */
129 void populate_to_be_instant_columns();
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 */
138 Columns m_cols_to_add;
139
140 /* Columns which are to be dropped instantly */
141 Columns m_cols_to_drop;
142
143 /* Inpalce alter info */
144 Alter_inplace_info *m_ha_alter_info;
145
146 /* User thread */
147 THD *m_thd;
148
149 /* Transaction */
150 trx_t *m_trx;
151
152 /* InnoDB dictionary table object */
153 dict_table_t *m_dict_table;
154
155 /* MySQL table as it is before the ALTER operation */
156 const TABLE *m_old_table;
157
158 /* MySQL table that is being altered */
159 const TABLE *m_altered_table;
160
161 /* Old Table/Partition definition */
162 const Table *m_old_dd_tab;
163
164 /* New Table/Partition definition */
165 Table *m_new_dd_tab;
166
167 uint64_t *m_autoinc;
168 };
169
170 #endif /* dict0inst_h */