MySQL 8.0.39
Source Code Documentation
sql_truncate.h
Go to the documentation of this file.
1#ifndef SQL_TRUNCATE_INCLUDED
2#define SQL_TRUNCATE_INCLUDED
3
4/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <memory>
28#include <string>
29
30#include "my_sqlcommand.h"
31#include "sql/dd/types/table.h"
32#include "sql/sql_cmd.h"
33
34class MDL_ticket;
35class THD;
36class Table_ref;
37struct handlerton;
38
39using Up_table = std::unique_ptr<dd::Table>;
40
41/**
42 Sql_cmd_truncate_table represents the TRUNCATE statement.
43*/
45 /** Set if a lock must be downgraded after truncate is done. */
47
48 /** Track error status from functions called. */
49 bool m_error = true;
50
51 public:
52 /**
53 Constructor, used to represent a TRUNCATE statement.
54 */
56
57 ~Sql_cmd_truncate_table() override = default;
58
59 bool execute(THD *) override;
60
62
63 private:
64 /* Handle locking a base table for truncate. */
65 bool lock_table(THD *, Table_ref *);
66
67 /*
68 Optimized delete of all rows by doing a full regenerate of the table.
69 Depending on the storage engine, it can be accomplished through a
70 drop and recreate or via the handler truncate method.
71 */
72 void truncate_base(THD *, Table_ref *);
74
75 void end_transaction(THD *, bool, bool);
76 void cleanup_base(THD *, const handlerton *);
78 const std::string &);
79};
80
81#endif
A granted metadata lock.
Definition: mdl.h:984
Sql_cmd_truncate_table represents the TRUNCATE statement.
Definition: sql_truncate.h:44
void cleanup_base(THD *, const handlerton *)
Performs cleanup actions after truncate of a normal (non-temporary) table.
Definition: sql_truncate.cc:399
Sql_cmd_truncate_table()=default
Constructor, used to represent a TRUNCATE statement.
void truncate_base(THD *, Table_ref *)
Optimized delete of all rows by doing a full generate of the base (non-temporary) table.
Definition: sql_truncate.cc:468
bool execute(THD *) override
Execute a TRUNCATE statement at runtime.
Definition: sql_truncate.cc:745
MDL_ticket * m_ticket_downgrade
Set if a lock must be downgraded after truncate is done.
Definition: sql_truncate.h:46
~Sql_cmd_truncate_table() override=default
void cleanup_temporary(THD *, handlerton *, const Table_ref &, Up_table *, const std::string &)
Reopens a temporary table after truncate if supported.
Definition: sql_truncate.cc:422
bool lock_table(THD *, Table_ref *)
Definition: sql_truncate.cc:304
void end_transaction(THD *, bool, bool)
Completes transaction by attempting to binlog and commit if truncate has been successful so far.
Definition: sql_truncate.cc:372
void truncate_temporary(THD *, Table_ref *)
Optimized delete of all rows by doing a full generate of the temporary table.
Definition: sql_truncate.cc:631
bool m_error
Track error status from functions called.
Definition: sql_truncate.h:49
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_truncate.h:61
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
Definition: table.h:2791
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_TRUNCATE
Definition: my_sqlcommand.h:55
Representation of an SQL command.
std::unique_ptr< dd::Table > Up_table
Definition: sql_truncate.h:39
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622