MySQL 8.0.40
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, 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 <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_with_rowid_in_buffer);
57 ~UpdateRowsIterator() override;
58 bool Init() override;
59 int Read() override;
60 void StartPSIBatchMode() override { m_source->StartPSIBatchMode(); }
61 void EndPSIBatchModeIfStarted() override {
62 m_source->EndPSIBatchModeIfStarted();
63 }
64 void SetNullRowFlag([[maybe_unused]] bool is_null_row) override {
65 assert(false);
66 }
67 void UnlockRow() override { assert(false); }
68 ha_rows found_rows() const { return m_found_rows; }
70
71 private:
72 /// The iterator producing the rows to update.
74 /// The outermost table of the join. It may or may not be one of the tables
75 /// being updated.
77 /// The table to perform immediate update on, or nullptr if immediate update
78 /// is not possible.
80 /// Pointer to list of updated tables, linked via 'next_local'.
82 /// Temporary tables used to store cached updates.
84 /// Objects that copy the updated values from a temporary table to the update
85 /// target table, and perform conversions if the types differ.
87 /// Tables referenced in the CHECK OPTION condition of the updated view
88 /// excluding the updated table.
90 /// The update operations of each table in m_update_tables (indexed in the
91 /// same order as m_update_tables).
93 /// The fields list decomposed into separate lists per table.
95 /// The values list decomposed into separate lists per table.
97 /// The number of rows matching the WHERE and join conditions.
99 /// The number of rows actually updated.
101 /// All the tables that are part of a hash join. We use this map to find out
102 /// how to get the row ID from a table when buffering row IDs for delayed
103 /// update. For those tables that are part of a hash join, the row ID will
104 /// already be available in handler::ref, and calling handler::position() will
105 /// overwrite it with an incorrect row ID (most likely the last row read from
106 /// the table). For those that are not part of a hash join,
107 /// handler::position() must be called to get the current row ID from the
108 /// underlying scan.
110
111 /// Perform all the immediate updates for the current row returned by the
112 /// join, and buffer row IDs for the non-immediate tables.
113 ///
114 /// @param[out] trans_safe Gets set to false if a non-transactional table
115 /// is updated.
116 /// @param[out] transactional_tables Gets set to true if a transactional
117 /// table is updated.
118 /// @return True on error.
119 bool DoImmediateUpdatesAndBufferRowIds(bool *trans_safe,
120 bool *transactional_tables);
121
122 /// Perform all the delayed updates.
123 ///
124 /// @param[in,out] trans_safe Gets set to false if a non-transactional table
125 /// is updated.
126 /// @param[out] transactional_tables Gets set to true if a transactional
127 /// table is updated.
128 /// @return True on error.
129 bool DoDelayedUpdates(bool *trans_safe, bool *transactional_tables);
130};
131
132#endif // SQL_ITERATORS_UPDATE_ROWS_ITERATOR_H_
This class encapsulates a data change operation.
Definition: sql_data_change.h:74
Definition: field.h:4654
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
Definition: sql_list.h:434
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:34
Definition: table.h:2791
An iterator that performs updates to rows returned by its child iterator.
Definition: update_rows_iterator.h:46
ha_rows updated_rows() const
Definition: update_rows_iterator.h:69
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:92
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:86
TABLE * m_immediate_table
The table to perform immediate update on, or nullptr if immediate update is not possible.
Definition: update_rows_iterator.h:79
mem_root_deque< Item * > ** m_fields_for_table
The fields list decomposed into separate lists per table.
Definition: update_rows_iterator.h:94
table_map m_hash_join_tables
All the tables that are part of a hash join.
Definition: update_rows_iterator.h:109
int Read() override
Read a single row.
Definition: sql_update.cc:2862
bool DoDelayedUpdates(bool *trans_safe, bool *transactional_tables)
Perform all the delayed updates.
Definition: sql_update.cc:2582
mem_root_deque< Item * > ** m_values_for_table
The values list decomposed into separate lists per table.
Definition: update_rows_iterator.h:96
ha_rows m_found_rows
The number of rows matching the WHERE and join conditions.
Definition: update_rows_iterator.h:98
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:2416
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: update_rows_iterator.h:60
~UpdateRowsIterator() override
Definition: sql_update.cc:2856
TABLE * m_outermost_table
The outermost table of the join.
Definition: update_rows_iterator.h:76
ha_rows m_updated_rows
The number of rows actually updated.
Definition: update_rows_iterator.h:100
bool Init() override
Initialize or reinitialize the iterator.
Definition: sql_update.cc:2841
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:89
Table_ref * m_update_tables
Pointer to list of updated tables, linked via 'next_local'.
Definition: update_rows_iterator.h:81
TABLE ** m_tmp_tables
Temporary tables used to store cached updates.
Definition: update_rows_iterator.h:83
ha_rows found_rows() const
Definition: update_rows_iterator.h:68
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_with_rowid_in_buffer)
Definition: sql_update.cc:3040
unique_ptr_destroy_only< RowIterator > m_source
The iterator producing the rows to update.
Definition: update_rows_iterator.h:73
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:64
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: update_rows_iterator.h:61
void UnlockRow() override
Definition: update_rows_iterator.h:67
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
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:4243
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:489
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1140
uint64_t table_map
Definition: my_table_map.h:30
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Definition: table.h:1399