MySQL 9.1.0
Source Code Documentation
sql_delete.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_DELETE_INCLUDED
25#define SQL_DELETE_INCLUDED
26
27#include "my_sqlcommand.h"
28#include "my_table_map.h"
29#include "sql/sql_cmd_dml.h" // Sql_cmd_dml
30
31class JOIN;
33class THD;
34class Table_ref;
35template <typename T>
36class SQL_I_List;
37
38class Sql_cmd_delete final : public Sql_cmd_dml {
39 public:
40 Sql_cmd_delete(bool multitable_arg, SQL_I_List<Table_ref> *delete_tables_arg)
41 : multitable(multitable_arg), delete_tables(delete_tables_arg) {}
42
45 }
46
47 bool is_single_table_plan() const override { return !multitable; }
48
49 bool accept(THD *thd, Select_lex_visitor *visitor) override;
50
51 protected:
52 bool precheck(THD *thd) override;
53 bool check_privileges(THD *thd) override;
54
55 bool prepare_inner(THD *thd) override;
56
57 bool execute_inner(THD *thd) override;
58
59 private:
61
63 /**
64 References to tables that are deleted from in a multitable delete statement.
65 Only used to track such tables from the parser. In preparation and
66 optimization, use the Table_ref::updating property instead.
67 */
69};
70
71/// Find out which of the delete target tables can be deleted from immediately
72/// while scanning. This is used by the old optimizer *after* the plan has been
73/// created. The hypergraph optimizer does not use this function, as it makes
74/// the decision about immediate delete *during* planning, not after planning.
76
77/// Checks if the sql_safe_updates option is enabled, and raises an error and
78/// returns true if the statement is likely to delete or update a large number
79/// of rows. Specifically, it raises an error if there is a full table scan or
80/// full index scan of one of the tables deleted from, and there is no LIMIT
81/// clause.
82bool CheckSqlSafeUpdate(THD *thd, const JOIN *join);
83
84#endif /* SQL_DELETE_INCLUDED */
Definition: sql_optimizer.h:133
Simple intrusive linked list.
Definition: sql_list.h:48
Abstract base class for traversing the Query_block tree.
Definition: select_lex_visitor.h:40
Definition: sql_delete.h:38
SQL_I_List< Table_ref > * delete_tables
References to tables that are deleted from in a multitable delete statement.
Definition: sql_delete.h:68
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_delete.h:43
bool execute_inner(THD *thd) override
Execute a DELETE statement.
Definition: sql_delete.cc:900
Sql_cmd_delete(bool multitable_arg, SQL_I_List< Table_ref > *delete_tables_arg)
Definition: sql_delete.h:40
bool prepare_inner(THD *thd) override
Prepare a DELETE statement.
Definition: sql_delete.cc:692
bool delete_from_single_table(THD *thd)
Delete a set of rows from a single table.
Definition: sql_delete.cc:204
bool precheck(THD *thd) override
Perform a precheck of table privileges for the specific operation.
Definition: sql_delete.cc:152
bool multitable
Definition: sql_delete.h:62
bool check_privileges(THD *thd) override
Check privileges on a prepared statement, called at start of execution of the statement.
Definition: sql_delete.cc:182
bool accept(THD *thd, Select_lex_visitor *visitor) override
Definition: sql_delete.cc:1266
bool is_single_table_plan() const override
Definition: sql_delete.h:47
Definition: sql_cmd_dml.h:35
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2900
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_DELETE
Definition: my_sqlcommand.h:54
@ SQLCOM_DELETE_MULTI
Definition: my_sqlcommand.h:121
uint64_t table_map
Definition: my_table_map.h:30
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
int delete_tables(PFS_engine_table_share_proxy **, unsigned int) noexcept
Definition: pfs_plugin_table_v1_all_empty.cc:39
bool CheckSqlSafeUpdate(THD *thd, const JOIN *join)
Checks if the sql_safe_updates option is enabled, and raises an error and returns true if the stateme...
Definition: sql_delete.cc:976
table_map GetImmediateDeleteTables(const JOIN *join, table_map delete_tables)
Find out which of the delete target tables can be deleted from immediately while scanning.
Definition: sql_delete.cc:1270