MySQL 26.10.0
Source Code Documentation
update_rows_iterator.h
Go to the documentation of this file.
1#ifndef SQL_ITERATORS_UPDATE_ROWS_ITERATOR_H_
2#define SQL_ITERATORS_UPDATE_ROWS_ITERATOR_H_
3
4/* Copyright (c) 2022, 2026, 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 <cassert>
28#include <memory>
29
30#include "my_alloc.h"
31#include "my_base.h"
32#include "my_table_map.h"
34#include "sql/sql_list.h"
35
36class COPY_INFO;
37class Copy_field;
38class Item;
39class THD;
40struct TABLE;
41class Table_ref;
42template <class T>
43class mem_root_deque;
44
45/// An iterator that performs updates to rows returned by its child iterator.
46class UpdateRowsIterator final : public RowIterator {
47 public:
49 TABLE *outermost_table, TABLE *immediate_table,
50 Table_ref *update_tables, TABLE **tmp_tables,
52 List<TABLE> unupdated_check_opt_tables,
53 COPY_INFO **update_operations,
54 mem_root_deque<Item *> **fields_for_table,
55 mem_root_deque<Item *> **values_for_table,
56 table_map tables_to_get_rowid_for,
57 bool use_semi_consistent_read);
58 ~UpdateRowsIterator() override;
59 void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
60 void EndPSIBatchModeIfStarted() override {
61 m_source->EndPSIBatchModeIfStarted();
62 }
63 void SetNullRowFlag([[maybe_unused]] bool is_null_row) override {
64 assert(false);
65 }
66 void UnlockRow() override { assert(false); }
67 ha_rows found_rows() const { return m_found_rows; }
69
70 private:
71 /// The iterator producing the rows to update.
73 /// The outermost table of the join. It may or may not be one of the tables
74 /// being updated.
76 /// The table to perform immediate update on, or nullptr if immediate update
77 /// is not possible.
79 /// Pointer to list of updated tables, linked via 'next_local'.
81 /// Temporary tables used to store cached updates.
83 /// Objects that copy the updated values from a temporary table to the update
84 /// target table, and perform conversions if the types differ.
86 /// Tables referenced in the CHECK OPTION condition of the updated view
87 /// excluding the updated table.
89 /// The update operations of each table in m_update_tables (indexed in the
90 /// same order as m_update_tables).
92 /// The fields list decomposed into separate lists per table.
94 /// The values list decomposed into separate lists per table.
96 /// The number of rows matching the WHERE and join conditions.
98 /// The number of rows actually updated.
100 /// The tables for which handler::position() must be called to get the row ID.
101 /// For all other tables, the child iterator has already copied the correct
102 /// row ID into handler::ref.
104 /// Whether semi-consistent reads should be enabled on m_outermost_table.
106
107 bool DoInit() override;
108 int DoRead() override;
109
110 /// Perform all the immediate updates for the current row returned by the
111 /// join, and buffer row IDs for the non-immediate tables.
112 ///
113 /// @param[out] trans_safe Gets set to false if a non-transactional table
114 /// is updated.
115 /// @param[out] transactional_tables Gets set to true if a transactional
116 /// table is updated.
117 /// @return True on error.
118 bool DoImmediateUpdatesAndBufferRowIds(bool *trans_safe,
119 bool *transactional_tables);
120
121 /// Perform all the delayed updates.
122 ///
123 /// @param[in,out] trans_safe Gets set to false if a non-transactional table
124 /// is updated.
125 /// @param[out] transactional_tables Gets set to true if a transactional
126 /// table is updated.
127 /// @return True on error.
128 bool DoDelayedUpdates(bool *trans_safe, bool *transactional_tables);
129};
130
131#endif // SQL_ITERATORS_UPDATE_ROWS_ITERATOR_H_
This class encapsulates a data change operation.
Definition: sql_data_change.h:74
Definition: field.h:4586
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:935
Definition: sql_list.h:494
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:255
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:2958
An iterator that performs updates to rows returned by its child iterator.
Definition: update_rows_iterator.h:46
bool m_use_semi_consistent_read
Whether semi-consistent reads should be enabled on m_outermost_table.
Definition: update_rows_iterator.h:105
table_map m_tables_to_get_rowid_for
The tables for which handler::position() must be called to get the row ID.
Definition: update_rows_iterator.h:103
ha_rows updated_rows() const
Definition: update_rows_iterator.h:68
COPY_INFO ** m_update_operations
The update operations of each table in m_update_tables (indexed in the same order as m_update_tables)...
Definition: update_rows_iterator.h:91
Copy_field * m_copy_fields
Objects that copy the updated values from a temporary table to the update target table,...
Definition: update_rows_iterator.h:85
TABLE * m_immediate_table
The table to perform immediate update on, or nullptr if immediate update is not possible.
Definition: update_rows_iterator.h:78
mem_root_deque< Item * > ** m_fields_for_table
The fields list decomposed into separate lists per table.
Definition: update_rows_iterator.h:93
bool DoDelayedUpdates(bool *trans_safe, bool *transactional_tables)
Perform all the delayed updates.
Definition: sql_update.cc:2685
mem_root_deque< Item * > ** m_values_for_table
The values list decomposed into separate lists per table.
Definition: update_rows_iterator.h:95
bool DoInit() override
Definition: sql_update.cc:2955
ha_rows m_found_rows
The number of rows matching the WHERE and join conditions.
Definition: update_rows_iterator.h:97
bool DoImmediateUpdatesAndBufferRowIds(bool *trans_safe, bool *transactional_tables)
Perform all the immediate updates for the current row returned by the join, and buffer row IDs for th...
Definition: sql_update.cc:2506
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: update_rows_iterator.h:59
UpdateRowsIterator(THD *thd, unique_ptr_destroy_only< RowIterator > source, TABLE *outermost_table, TABLE *immediate_table, Table_ref *update_tables, TABLE **tmp_tables, Copy_field *copy_fields, List< TABLE > unupdated_check_opt_tables, COPY_INFO **update_operations, mem_root_deque< Item * > **fields_for_table, mem_root_deque< Item * > **values_for_table, table_map tables_to_get_rowid_for, bool use_semi_consistent_read)
Definition: sql_update.cc:3153
~UpdateRowsIterator() override
Definition: sql_update.cc:2969
TABLE * m_outermost_table
The outermost table of the join.
Definition: update_rows_iterator.h:75
ha_rows m_updated_rows
The number of rows actually updated.
Definition: update_rows_iterator.h:99
List< TABLE > m_unupdated_check_opt_tables
Tables referenced in the CHECK OPTION condition of the updated view excluding the updated table.
Definition: update_rows_iterator.h:88
Table_ref * m_update_tables
Pointer to list of updated tables, linked via 'next_local'.
Definition: update_rows_iterator.h:80
int DoRead() override
Definition: sql_update.cc:2975
TABLE ** m_tmp_tables
Temporary tables used to store cached updates.
Definition: update_rows_iterator.h:82
ha_rows found_rows() const
Definition: update_rows_iterator.h:67
unique_ptr_destroy_only< RowIterator > m_source
The iterator producing the rows to update.
Definition: update_rows_iterator.h:72
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: update_rows_iterator.h:63
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: update_rows_iterator.h:60
void UnlockRow() override
Definition: update_rows_iterator.h:66
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:172
bool copy_fields(Temp_table_param *param, const THD *thd, bool reverse_copy)
Make a copy of all simple SELECT'ed fields.
Definition: sql_executor.cc:4428
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:1229
uint64_t table_map
Definition: my_table_map.h:30
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Definition: table.h:1456