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