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