MySQL  8.0.20
Source Code Documentation
sql_tablespace.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
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 "lex_string.h"
29 #include "my_inttypes.h"
30 #include "my_sqlcommand.h"
31 #include "sql/handler.h" // ts_command_type
32 #include "sql/sql_cmd.h" // Sql_cmd
33 
34 class THD;
35 
36 /**
37  Structure used by parser to store options for tablespace statements
38  and pass them on to Excution classes.
39  */
41  ulonglong extent_size = 1024 * 1024; // Default 1 MByte
42  ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
43  ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
44  ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
45  ulonglong autoextend_size = 0; // No autoextension as default
46  ulonglong max_size = 0; // Max size == initial size => no extension
47  ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
49  bool wait_until_completed = true;
50  LEX_STRING ts_comment = {nullptr, 0}; // FIXME: Rename to comment?
51  LEX_CSTRING engine_name = {nullptr, 0};
52  LEX_STRING encryption = {nullptr, 0};
53 };
54 
55 /**
56  Check if tablespace name has valid length.
57 
58  @param tablespace_name Name of the tablespace
59 
60  @note Tablespace names are not reflected in the file system, so
61  character case conversion or consideration is not relevant.
62 
63  @note Checking for path characters or ending space is not done.
64  The checks are for identifier length, both in terms of
65  number of characters and number of bytes.
66 
67  @retval false No error encountered while checking length.
68  @retval true Error encountered and reported.
69 */
70 
71 bool validate_tablespace_name_length(const char *tablespace_name);
72 
73 /**
74  Check if a tablespace name is valid.
75 
76  SE specific validation is done by the SE by invoking a handlerton method.
77 
78  @param ts_cmd Whether this is tablespace DDL or not.
79  @param tablespace_name Name of the tablespace
80  @param engine Handlerton for the tablespace.
81 
82  @retval false No error encountered while checking the name.
83  @retval true Error encountered and reported.
84 */
85 
87  const char *tablespace_name,
88  const handlerton *engine);
89 
90 /**
91  Base class for tablespace execution classes including
92  CREATE/ALTER/DROP TABLESPACE and LOGFILE GROUP commands.
93  */
94 class Sql_cmd_tablespace : public Sql_cmd /* purecov: inspected */
95 {
96  protected:
99 
100  /**
101  Creates shared base object.
102 
103  @param name name of tablespace
104  @param options additional options to statement
105  */
107 
108  public:
109  /**
110  Provide access to the command code enum value.
111  @return command code enum value
112  */
113  enum_sql_command sql_command_code() const override final;
114  /**
115  Return the Tablespace_options for this object.
116  */
117  const Tablespace_options get_options() const { return *m_options; }
118 };
119 
120 /**
121  Execution class for CREATE TABLESPACE ... ADD DATAFILE ...
122  */
124  : public Sql_cmd_tablespace /* purecov: inspected */
125 {
129 
130  public:
131  /**
132  Creates execution class instance for create tablespace statement.
133 
134  @param tsname name of tablespace
135  @param dfname name of data file
136  @param lfgname name of logfile group (may be {nullptr, 0})
137  @param options additional options to statement
138  */
139  Sql_cmd_create_tablespace(const LEX_STRING &tsname, const LEX_STRING &dfname,
140  const LEX_STRING &lfgname,
141  const Tablespace_options *options);
142 
143  bool execute(THD *) override;
144 };
145 
146 /**
147  Execution class for DROP TABLESPACE ...
148  */
150  : public Sql_cmd_tablespace /* purecov: inspected */
151 {
152  public:
153  /**
154  Creates execution class instance for drop tablespace statement.
155 
156  @param tsname name of tablespace
157  @param options additional options to statement
158  */
159  Sql_cmd_drop_tablespace(const LEX_STRING &tsname,
160  const Tablespace_options *options);
161  bool execute(THD *) override;
162 };
163 
164 /**
165  Execution class for ALTER TABLESPACE ... tablespace_options
166  */
168  public:
169  /**
170  Creates execution class instance for plain alter tablespace
171  (modifying options).
172 
173  @param ts_name name of tablespace
174  @param options additional options to statement
175  */
176  Sql_cmd_alter_tablespace(const LEX_STRING &ts_name,
177  const Tablespace_options *options);
178 
179  bool execute(THD *thd) override;
180 };
181 
182 /**
183  Execution class for ALTER TABLESPACE ... ADD DATAFILE ...
184  */
186  : public Sql_cmd_tablespace /* purecov: inspected */
187 {
189 
190  public:
191  /**
192  Creates execution class instance for add datafile statement.
193 
194  @param tsname name of tablespace
195  @param dfname name of data file to add
196  @param options additional options to statement
197  */
199  const LEX_STRING &dfname,
200  const Tablespace_options *options);
201  bool execute(THD *) override;
202 };
203 
204 /**
205  Execution class for ALTER TABLESPACE ... DROP DATAFILE ...
206  */
208  : public Sql_cmd_tablespace /* purecov: inspected */
209 {
211 
212  public:
213  /**
214  Creates execution class instance for drop datafile statement.
215 
216  @param tsname name of tablespace
217  @param dfname name of data file to drop
218  @param options additional options to statement
219  */
221  const LEX_STRING &dfname,
222  const Tablespace_options *options);
223  bool execute(THD *) override;
224 };
225 
226 /**
227  Execution class for ALTER TABLESPACE ... RENAME TO ...
228  */
230  : public Sql_cmd_tablespace /* purecov: inspected */
231 {
233 
234  public:
235  /**
236  Creates execution class instance for rename statement.
237 
238  @param old_name existing tablespace
239  @param new_name desired tablespace name
240  */
242  const LEX_STRING &new_name);
243  bool execute(THD *) override;
244 };
245 
246 /**
247  Execution class for CREATE UNDO TABLESPACE
248  */
254 
255  public:
256  /**
257  Creates execution class instance for undo tablespace statements.
258 
259  @param cmd_type subcommand passed to se
260  @param utsname name of undo tablespace
261  @param dfname name of data file
262  @param options additional options to statemente
263  */
265  const LEX_STRING &utsname,
266  const LEX_STRING &dfname,
267  const Tablespace_options *options);
268 
269  bool execute(THD *) override;
270  enum_sql_command sql_command_code() const override;
271 };
272 
273 /**
274  Execution class for ALTER UNDO TABLESPACE
275  */
282 
283  public:
284  /**
285  Creates execution class instance for undo tablespace statements.
286 
287  @param cmd_type subcommand passed to se
288  @param utsname name of undo tablespace
289  @param dfname name of data file
290  @param options additional options to statemente
291  @param at_type alter tablespace subcommand passed to se
292  */
294  const ts_command_type cmd_type, const LEX_STRING &utsname,
295  const LEX_STRING &dfname, const Tablespace_options *options,
297 
298  bool execute(THD *) override;
299  enum_sql_command sql_command_code() const override;
300 };
301 
302 /**
303  Execution class for DROP UNDO TABLESPACE
304  */
310 
311  public:
312  /**
313  Creates execution class instance for drop undo tablespace statements.
314 
315  @param cmd_type subcommand passed to se
316  @param utsname name of undo tablespace
317  @param dfname name of data file
318  @param options additional options to statemente
319  */
321  const LEX_STRING &utsname,
322  const LEX_STRING &dfname,
323  const Tablespace_options *options);
324 
325  bool execute(THD *) override;
326  enum_sql_command sql_command_code() const override;
327 };
328 
329 /**
330  Execution class for CREATE/DROP/ALTER LOGFILE GROUP ...
331  */
332 class Sql_cmd_logfile_group final : public Sql_cmd /* purecov: inspected */
333 {
338 
339  public:
340  /**
341  Creates execution class instance for logfile group statements.
342 
343  @param cmd_type subcommand passed to se
344  @param logfile_group_name name of logfile group
345  @param options additional options to statement
346  @param undofile_name name of undo file
347  */
348  Sql_cmd_logfile_group(const ts_command_type cmd_type,
349  const LEX_STRING &logfile_group_name,
351  const LEX_STRING &undofile_name = {nullptr, 0});
352 
353  bool execute(THD *thd) override;
354 
355  enum_sql_command sql_command_code() const override;
356 };
357 
358 #endif /* SQL_TABLESPACE_INCLUDED */
const Tablespace_options * m_options
Definition: sql_tablespace.h:309
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:308
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Representation of an SQL command.
Definition: sql_cmd.h:63
ENGINE_HANDLE * engine
Definition: mock_server.c:28
ulonglong autoextend_size
Definition: sql_tablespace.h:45
Definition: mysql_lex_string.h:34
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:279
const LEX_STRING m_tablespace_name
Definition: sql_tablespace.h:97
ulonglong undo_buffer_size
Definition: sql_tablespace.h:42
Some integer typedefs for easier portability.
const Tablespace_options * m_options
Definition: sql_tablespace.h:281
enum_sql_command
Definition: my_sqlcommand.h:45
Definition: mysql_lex_string.h:39
Execution class for ALTER TABLESPACE ...
Definition: sql_tablespace.h:167
bool m_auto_generate_datafile_name
Definition: sql_tablespace.h:128
LEX_CSTRING engine_name
Definition: sql_tablespace.h:51
bool wait_until_completed
Definition: sql_tablespace.h:49
static bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
Definition: libmysql.cc:1918
Representation of an SQL command.
const ts_command_type m_cmd
Definition: sql_tablespace.h:250
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:251
Execution class for CREATE TABLESPACE ...
Definition: sql_tablespace.h:123
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:188
Execution class for DROP TABLESPACE ...
Definition: sql_tablespace.h:149
Execution class for ALTER TABLESPACE ...
Definition: sql_tablespace.h:207
const ts_alter_tablespace_type m_at_type
Definition: sql_tablespace.h:280
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:210
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:119
Definition: handler.h:813
const Tablespace_options * m_options
Definition: sql_tablespace.h:253
#define UNDEF_NODEGROUP
Definition: handler.h:794
const LEX_STRING m_logfile_group_name
Definition: sql_tablespace.h:127
Execution class for CREATE UNDO TABLESPACE.
Definition: sql_tablespace.h:249
static int get_options(int *argc, char ***argv, MEM_ROOT *alloc)
Definition: mysqlcheck.cc:397
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
case opt name
Definition: sslopt-case.h:32
const LEX_STRING m_new_name
Definition: sql_tablespace.h:232
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2269
ts_command_type
Definition: handler.h:797
Execution class for ALTER TABLESPACE ...
Definition: sql_tablespace.h:185
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:307
const LEX_STRING m_logfile_group_name
Definition: sql_tablespace.h:335
Execution class for ALTER UNDO TABLESPACE.
Definition: sql_tablespace.h:276
uint nodegroup_id
Definition: sql_tablespace.h:48
const ts_command_type m_cmd
Definition: sql_tablespace.h:306
const Tablespace_options * m_options
Definition: sql_tablespace.h:98
ulonglong file_block_size
Definition: sql_tablespace.h:47
Base class for tablespace execution classes including CREATE/ALTER/DROP TABLESPACE and LOGFILE GROUP ...
Definition: sql_tablespace.h:94
const Tablespace_options * m_options
Definition: sql_tablespace.h:337
static const Query_options options
Definition: show_query_builder.cc:48
ulonglong redo_buffer_size
Definition: sql_tablespace.h:43
Execution class for CREATE/DROP/ALTER LOGFILE GROUP ...
Definition: sql_tablespace.h:332
ts_alter_tablespace_type
Definition: handler.h:812
Structure used by parser to store options for tablespace statements and pass them on to Excution clas...
Definition: sql_tablespace.h:40
ulonglong max_size
Definition: sql_tablespace.h:46
LEX_STRING ts_comment
Definition: sql_tablespace.h:50
const ts_command_type m_cmd
Definition: sql_tablespace.h:277
const ts_command_type m_cmd
Definition: sql_tablespace.h:334
ulonglong initial_size
Definition: sql_tablespace.h:44
bool validate_tablespace_name_length(const char *tablespace_name)
Check if tablespace name has valid length.
Definition: sql_tablespace.cc:113
ulonglong extent_size
Definition: sql_tablespace.h:41
const LEX_STRING m_undo_tablespace_name
Definition: sql_tablespace.h:278
Execution class for ALTER TABLESPACE ...
Definition: sql_tablespace.h:229
Execution class for DROP UNDO TABLESPACE.
Definition: sql_tablespace.h:305
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:126
LEX_STRING encryption
Definition: sql_tablespace.h:52
const LEX_STRING m_undofile_name
Definition: sql_tablespace.h:336
const LEX_STRING m_datafile_name
Definition: sql_tablespace.h:252
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:765