MySQL 8.0.30
Source Code Documentation
sql_tablespace.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_TABLESPACE_INCLUDED
24#define SQL_TABLESPACE_INCLUDED
25
26#include <sys/types.h>
27
28#include <optional>
29
30#include "lex_string.h"
31#include "my_inttypes.h"
32#include "my_sqlcommand.h"
33#include "sql/handler.h" // ts_command_type
34#include "sql/sql_cmd.h" // Sql_cmd
35
36class THD;
37
38/**
39 Structure used by parser to store options for tablespace statements
40 and pass them on to Execution classes.
41 */
43 ulonglong extent_size = 1024 * 1024; // Default 1 MByte
44 ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
45 ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
46 ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
47 std::optional<ulonglong> autoextend_size; // No autoextension as default
48 ulonglong max_size = 0; // Max size == initial size => no extension
49 ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
52 LEX_STRING ts_comment = {nullptr, 0}; // FIXME: Rename to comment?
53 LEX_CSTRING engine_name = {nullptr, 0};
54 LEX_STRING encryption = {nullptr, 0};
55
57};
58
59/**
60 Check if tablespace name has valid length.
61
62 @param tablespace_name Name of the tablespace
63
64 @note Tablespace names are not reflected in the file system, so
65 character case conversion or consideration is not relevant.
66
67 @note Checking for path characters or ending space is not done.
68 The checks are for identifier length, both in terms of
69 number of characters and number of bytes.
70
71 @retval false No error encountered while checking length.
72 @retval true Error encountered and reported.
73*/
74
75bool validate_tablespace_name_length(const char *tablespace_name);
76
77/**
78 Check if a tablespace name is valid.
79
80 SE specific validation is done by the SE by invoking a handlerton method.
81
82 @param ts_cmd Whether this is tablespace DDL or not.
83 @param tablespace_name Name of the tablespace
84 @param engine Handlerton for the tablespace.
85
86 @retval false No error encountered while checking the name.
87 @retval true Error encountered and reported.
88*/
89
91 const char *tablespace_name,
92 const handlerton *engine);
93
94/**
95 Base class for tablespace execution classes including
96 CREATE/ALTER/DROP TABLESPACE and LOGFILE GROUP commands.
97 */
98class Sql_cmd_tablespace : public Sql_cmd /* purecov: inspected */
99{
100 protected:
103
104 /**
105 Creates shared base object.
106
107 @param name name of tablespace
108 @param options additional options to statement
109 */
111
112 public:
113 /**
114 Provide access to the command code enum value.
115 @return command code enum value
116 */
118 /**
119 Return the Tablespace_options for this object.
120 */
121 const Tablespace_options get_options() const { return *m_options; }
122};
123
124/**
125 Execution class for CREATE TABLESPACE ... ADD DATAFILE ...
126 */
128 : public Sql_cmd_tablespace /* purecov: inspected */
129{
133
134 public:
135 /**
136 Creates execution class instance for create tablespace statement.
137
138 @param tsname name of tablespace
139 @param dfname name of data file
140 @param lfgname name of logfile group (may be {nullptr, 0})
141 @param options additional options to statement
142 */
143 Sql_cmd_create_tablespace(const LEX_STRING &tsname, const LEX_STRING &dfname,
144 const LEX_STRING &lfgname,
146
147 bool execute(THD *) override;
148};
149
150/**
151 Execution class for DROP TABLESPACE ...
152 */
154 : public Sql_cmd_tablespace /* purecov: inspected */
155{
156 public:
157 /**
158 Creates execution class instance for drop tablespace statement.
159
160 @param tsname name of tablespace
161 @param options additional options to statement
162 */
165 bool execute(THD *) override;
166};
167
168/**
169 Execution class for ALTER TABLESPACE ... tablespace_options
170 */
172 public:
173 /**
174 Creates execution class instance for plain alter tablespace
175 (modifying options).
176
177 @param ts_name name of tablespace
178 @param options additional options to statement
179 */
182
183 bool execute(THD *thd) override;
184};
185
186/**
187 Execution class for ALTER TABLESPACE ... ADD DATAFILE ...
188 */
190 : public Sql_cmd_tablespace /* purecov: inspected */
191{
193
194 public:
195 /**
196 Creates execution class instance for add datafile statement.
197
198 @param tsname name of tablespace
199 @param dfname name of data file to add
200 @param options additional options to statement
201 */
203 const LEX_STRING &dfname,
205 bool execute(THD *) override;
206};
207
208/**
209 Execution class for ALTER TABLESPACE ... DROP DATAFILE ...
210 */
212 : public Sql_cmd_tablespace /* purecov: inspected */
213{
215
216 public:
217 /**
218 Creates execution class instance for drop datafile statement.
219
220 @param tsname name of tablespace
221 @param dfname name of data file to drop
222 @param options additional options to statement
223 */
225 const LEX_STRING &dfname,
227 bool execute(THD *) override;
228};
229
230/**
231 Execution class for ALTER TABLESPACE ... RENAME TO ...
232 */
234 : public Sql_cmd_tablespace /* purecov: inspected */
235{
237
238 public:
239 /**
240 Creates execution class instance for rename statement.
241
242 @param old_name existing tablespace
243 @param new_name desired tablespace name
244 */
246 const LEX_STRING &new_name);
247 bool execute(THD *) override;
248};
249
250/**
251 Execution class for CREATE UNDO TABLESPACE
252 */
258
259 public:
260 /**
261 Creates execution class instance for undo tablespace statements.
262
263 @param cmd_type subcommand passed to se
264 @param utsname name of undo tablespace
265 @param dfname name of data file
266 @param options additional options to statemente
267 */
269 const LEX_STRING &utsname,
270 const LEX_STRING &dfname,
272
273 bool execute(THD *) override;
274 enum_sql_command sql_command_code() const override;
275};
276
277/**
278 Execution class for ALTER UNDO TABLESPACE
279 */
286
287 public:
288 /**
289 Creates execution class instance for undo tablespace statements.
290
291 @param cmd_type subcommand passed to se
292 @param utsname name of undo tablespace
293 @param dfname name of data file
294 @param options additional options to statemente
295 @param at_type alter tablespace subcommand passed to se
296 */
298 const ts_command_type cmd_type, const LEX_STRING &utsname,
299 const LEX_STRING &dfname, const Tablespace_options *options,
301
302 bool execute(THD *) override;
303 enum_sql_command sql_command_code() const override;
304};
305
306/**
307 Execution class for DROP UNDO TABLESPACE
308 */
314
315 public:
316 /**
317 Creates execution class instance for drop undo tablespace statements.
318
319 @param cmd_type subcommand passed to se
320 @param utsname name of undo tablespace
321 @param dfname name of data file
322 @param options additional options to statemente
323 */
325 const LEX_STRING &utsname,
326 const LEX_STRING &dfname,
328
329 bool execute(THD *) override;
330 enum_sql_command sql_command_code() const override;
331};
332
333/**
334 Execution class for CREATE/DROP/ALTER LOGFILE GROUP ...
335 */
336class Sql_cmd_logfile_group final : public Sql_cmd /* purecov: inspected */
337{
342
343 public:
344 /**
345 Creates execution class instance for logfile group statements.
346
347 @param cmd_type subcommand passed to se
348 @param logfile_group_name name of logfile group
349 @param options additional options to statement
350 @param undofile_name name of undo file
351 */
353 const LEX_STRING &logfile_group_name,
355 const LEX_STRING &undofile_name = {nullptr, 0});
356
357 bool execute(THD *thd) override;
358
359 enum_sql_command sql_command_code() const override;
360};
361
362#endif /* SQL_TABLESPACE_INCLUDED */
Execution class for ALTER TABLESPACE ... ADD DATAFILE ...
Definition: sql_tablespace.h:191
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:192
Sql_cmd_alter_tablespace_add_datafile(const LEX_STRING &tsname, const LEX_STRING &dfname, const Tablespace_options *options)
Creates execution class instance for add datafile statement.
Definition: sql_tablespace.cc:1051
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1056
Execution class for ALTER TABLESPACE ... DROP DATAFILE ...
Definition: sql_tablespace.h:213
Sql_cmd_alter_tablespace_drop_datafile(const LEX_STRING &tsname, const LEX_STRING &dfname, const Tablespace_options *options)
Creates execution class instance for drop datafile statement.
Definition: sql_tablespace.cc:1142
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:214
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1147
Execution class for ALTER TABLESPACE ... RENAME TO ...
Definition: sql_tablespace.h:235
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1230
const LEX_STRING m_new_name
Definition: sql_tablespace.h:236
Sql_cmd_alter_tablespace_rename(const LEX_STRING &old_name, const LEX_STRING &new_name)
Creates execution class instance for rename statement.
Definition: sql_tablespace.cc:1226
Execution class for ALTER TABLESPACE ... tablespace_options.
Definition: sql_tablespace.h:171
Sql_cmd_alter_tablespace(const LEX_STRING &ts_name, const Tablespace_options *options)
Creates execution class instance for plain alter tablespace (modifying options).
Definition: sql_tablespace.cc:901
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_tablespace.cc:905
Execution class for ALTER UNDO TABLESPACE.
Definition: sql_tablespace.h:280
const Tablespace_options * m_options
Definition: sql_tablespace.h:285
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:283
const ts_alter_tablespace_type m_at_type
Definition: sql_tablespace.h:284
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:282
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1526
Sql_cmd_alter_undo_tablespace(const ts_command_type cmd_type, const LEX_STRING &utsname, const LEX_STRING &dfname, const Tablespace_options *options, ts_alter_tablespace_type at_type=TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED)
Creates execution class instance for undo tablespace statements.
Definition: sql_tablespace.cc:1511
const ts_command_type m_cmd
Definition: sql_tablespace.h:281
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_tablespace.cc:1605
Execution class for CREATE TABLESPACE ... ADD DATAFILE ...
Definition: sql_tablespace.h:129
bool m_auto_generate_datafile_name
Definition: sql_tablespace.h:132
Sql_cmd_create_tablespace(const LEX_STRING &tsname, const LEX_STRING &dfname, const LEX_STRING &lfgname, const Tablespace_options *options)
Creates execution class instance for create tablespace statement.
Definition: sql_tablespace.cc:443
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:130
const LEX_STRING m_logfile_group_name
Definition: sql_tablespace.h:131
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:451
Execution class for CREATE UNDO TABLESPACE.
Definition: sql_tablespace.h:253
const ts_command_type m_cmd
Definition: sql_tablespace.h:254
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:256
const Tablespace_options * m_options
Definition: sql_tablespace.h:257
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_tablespace.cc:1507
Sql_cmd_create_undo_tablespace(const ts_command_type cmd_type, const LEX_STRING &utsname, const LEX_STRING &dfname, const Tablespace_options *options)
Creates execution class instance for undo tablespace statements.
Definition: sql_tablespace.cc:1371
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1379
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:255
Execution class for DROP TABLESPACE ...
Definition: sql_tablespace.h:155
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:652
Sql_cmd_drop_tablespace(const LEX_STRING &tsname, const Tablespace_options *options)
Creates execution class instance for drop tablespace statement.
Definition: sql_tablespace.cc:648
Execution class for DROP UNDO TABLESPACE.
Definition: sql_tablespace.h:309
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:312
const Tablespace_options * m_options
Definition: sql_tablespace.h:313
const ts_command_type m_cmd
Definition: sql_tablespace.h:310
bool execute(THD *) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1617
Sql_cmd_drop_undo_tablespace(const ts_command_type cmd_type, const LEX_STRING &utsname, const LEX_STRING &dfname, const Tablespace_options *options)
Creates execution class instance for drop undo tablespace statements.
Definition: sql_tablespace.cc:1609
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_tablespace.cc:1708
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:311
Execution class for CREATE/DROP/ALTER LOGFILE GROUP ...
Definition: sql_tablespace.h:337
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_tablespace.cc:1720
const Tablespace_options * m_options
Definition: sql_tablespace.h:341
Sql_cmd_logfile_group(const ts_command_type cmd_type, const LEX_STRING &logfile_group_name, const Tablespace_options *options, const LEX_STRING &undofile_name={nullptr, 0})
Creates execution class instance for logfile group statements.
Definition: sql_tablespace.cc:1712
const LEX_STRING m_undofile_name
Definition: sql_tablespace.h:340
const ts_command_type m_cmd
Definition: sql_tablespace.h:338
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_tablespace.cc:1759
const LEX_STRING m_logfile_group_name
Definition: sql_tablespace.h:339
Base class for tablespace execution classes including CREATE/ALTER/DROP TABLESPACE and LOGFILE GROUP ...
Definition: sql_tablespace.h:99
const LEX_STRING m_tablespace_name
Definition: sql_tablespace.h:101
const Tablespace_options get_options() const
Return the Tablespace_options for this object.
Definition: sql_tablespace.h:121
const Tablespace_options * m_options
Definition: sql_tablespace.h:102
Sql_cmd_tablespace(const LEX_STRING &name, const Tablespace_options *options)
Creates shared base object.
Definition: sql_tablespace.cc:432
enum_sql_command sql_command_code() const final
Provide access to the command code enum value.
Definition: sql_tablespace.cc:437
Representation of an SQL command.
Definition: sql_cmd.h:64
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:46
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
enum_sql_command
Definition: my_sqlcommand.h:45
Definition: options.cc:48
#define UNDEF_NODEGROUP
Definition: handler.h:826
ts_command_type
Definition: handler.h:829
ts_alter_tablespace_type
Definition: handler.h:844
@ TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED
Definition: handler.h:845
Representation of an SQL command.
bool validate_tablespace_name_length(const char *tablespace_name)
Check if tablespace name has valid length.
Definition: sql_tablespace.cc:118
bool validate_tablespace_name(ts_command_type ts_cmd, const char *tablespace_name, const handlerton *engine)
Check if a tablespace name is valid.
Definition: sql_tablespace.cc:124
case opt name
Definition: sslopt-case.h:32
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Structure used by parser to store options for tablespace statements and pass them on to Execution cla...
Definition: sql_tablespace.h:42
ulonglong redo_buffer_size
Definition: sql_tablespace.h:45
ulonglong undo_buffer_size
Definition: sql_tablespace.h:44
LEX_CSTRING engine_attribute
Definition: sql_tablespace.h:56
ulonglong file_block_size
Definition: sql_tablespace.h:49
std::optional< ulonglong > autoextend_size
Definition: sql_tablespace.h:47
uint nodegroup_id
Definition: sql_tablespace.h:50
LEX_STRING ts_comment
Definition: sql_tablespace.h:52
LEX_STRING encryption
Definition: sql_tablespace.h:54
ulonglong max_size
Definition: sql_tablespace.h:48
LEX_CSTRING engine_name
Definition: sql_tablespace.h:53
ulonglong initial_size
Definition: sql_tablespace.h:46
bool wait_until_completed
Definition: sql_tablespace.h:51
ulonglong extent_size
Definition: sql_tablespace.h:43
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2542
unsigned int uint
Definition: uca-dump.cc:29