MySQL 9.1.0
Source Code Documentation
delete_rows_iterator.h
Go to the documentation of this file.
1#ifndef SQL_ITERATORS_DELETE_ROWS_ITERATOR_H_
2#define SQL_ITERATORS_DELETE_ROWS_ITERATOR_H_
3
4/* Copyright (c) 2021, 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 <assert.h>
28
29#include "my_alloc.h"
30#include "my_base.h"
31#include "my_table_map.h"
33#include "sql/mem_root_array.h"
34#include "sql/uniques.h"
35
36class JOIN;
37class THD;
38struct TABLE;
39
40/// An iterator that deletes all rows returned by its child iterator.
41class DeleteRowsIterator final : public RowIterator {
42 public:
44 JOIN *join, table_map tables_to_delete_from,
45 table_map immediate_tables);
46 bool Init() override;
47 int Read() override;
48 void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
49 void EndPSIBatchModeIfStarted() override {
50 m_source->EndPSIBatchModeIfStarted();
51 }
52 void SetNullRowFlag(bool /*is_null_row*/) override { assert(false); }
53 void UnlockRow() override { assert(false); }
54
55 private:
56 /// The iterator producing the rows to delete.
58 /// The join producing the rows to delete.
60 /// The tables to delete from.
62 /// The tables to delete from immediately while scanning the join result.
64 /// All the tables that are part of a hash join. We use this map to find out
65 /// how to get the row ID from a table when buffering row IDs for delayed
66 /// delete. For those tables that are part of a hash join, the row ID will
67 /// already be available in handler::ref, and calling handler::position() will
68 /// overwrite it with an incorrect row ID (most likely the last row read from
69 /// the table). For those that are not part of a hash join,
70 /// handler::position() must be called to get the current row ID from the
71 /// underlying scan.
73 /// The target tables that live in transactional storage engines.
75 /// The target tables that have before delete triggers.
77 /// The target tables that have after delete triggers.
79 /// Temporary files holding row IDs to delete after the scan of
80 /// the join result is complete.
82 /// The tables to delete from after the scan of the join result is
83 /// complete.
85 /// The number of rows that have been deleted.
87 /// True if any row ID has been stored in one of the m_tempfiles.
89
90 /// Perform all the immediate deletes for the current row returned by the
91 /// join, and buffer row IDs for the non-immediate tables.
93 /// Perform all the delayed deletes.
94 bool DoDelayedDeletes();
95 /// Perform all the delayed deletes for the given table.
97};
98
99/// Sets various flags in the TABLE and handler objects associated with the
100/// target tables of a DELETE statement, in order to make them ready to be
101/// deleted from.
102///
103/// @param thd The session object.
104/// @param join The top-level JOIN object of the DELETE operation.
105void SetUpTablesForDelete(THD *thd, JOIN *join);
106
107#endif // SQL_ITERATORS_DELETE_ROWS_ITERATOR_H_
An iterator that deletes all rows returned by its child iterator.
Definition: delete_rows_iterator.h:41
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: delete_rows_iterator.h:48
table_map m_transactional_tables
The target tables that live in transactional storage engines.
Definition: delete_rows_iterator.h:74
table_map m_tables_with_before_triggers
The target tables that have before delete triggers.
Definition: delete_rows_iterator.h:76
void UnlockRow() override
Definition: delete_rows_iterator.h:53
int Read() override
Read a single row.
Definition: sql_delete.cc:1196
JOIN * m_join
The join producing the rows to delete.
Definition: delete_rows_iterator.h:59
void SetNullRowFlag(bool) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: delete_rows_iterator.h:52
table_map m_hash_join_tables
All the tables that are part of a hash join.
Definition: delete_rows_iterator.h:72
Mem_root_array< TABLE * > m_delayed_tables
The tables to delete from after the scan of the join result is complete.
Definition: delete_rows_iterator.h:84
ha_rows m_deleted_rows
The number of rows that have been deleted.
Definition: delete_rows_iterator.h:86
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: delete_rows_iterator.h:49
table_map m_tables_to_delete_from
The tables to delete from.
Definition: delete_rows_iterator.h:61
bool DoImmediateDeletesAndBufferRowIds()
Perform all the immediate deletes for the current row returned by the join, and buffer row IDs for th...
Definition: sql_delete.cc:1054
table_map m_immediate_tables
The tables to delete from immediately while scanning the join result.
Definition: delete_rows_iterator.h:63
bool m_has_delayed_deletes
True if any row ID has been stored in one of the m_tempfiles.
Definition: delete_rows_iterator.h:88
bool DoDelayedDeletes()
Perform all the delayed deletes.
Definition: sql_delete.cc:1123
unique_ptr_destroy_only< RowIterator > m_source
The iterator producing the rows to delete.
Definition: delete_rows_iterator.h:57
DeleteRowsIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, JOIN *join, table_map tables_to_delete_from, table_map immediate_tables)
Definition: sql_delete.cc:926
table_map m_tables_with_after_triggers
The target tables that have after delete triggers.
Definition: delete_rows_iterator.h:78
bool DoDelayedDeletesFromTable(TABLE *table)
Perform all the delayed deletes for the given table.
Definition: sql_delete.cc:1137
Mem_root_array< unique_ptr_destroy_only< Unique > > m_tempfiles
Temporary files holding row IDs to delete after the scan of the join result is complete.
Definition: delete_rows_iterator.h:81
bool Init() override
Initialize or reinitialize the iterator.
Definition: sql_delete.cc:1008
Definition: sql_optimizer.h:133
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:82
THD * thd() const
Definition: row_iterator.h:228
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
void SetUpTablesForDelete(THD *thd, JOIN *join)
Sets various flags in the TABLE and handler objects associated with the target tables of a DELETE sta...
Definition: sql_delete.cc:963
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:480
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1141
uint64_t table_map
Definition: my_table_map.h:30
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Definition: table.h:1421