MySQL 8.0.32
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, 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 also distributed 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 included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include <cassert>
27#include <memory>
28
29#include "my_alloc.h"
30#include "my_base.h"
31#include "my_table_map.h"
33#include "sql/sql_list.h"
34
35class COPY_INFO;
36class Copy_field;
37class Item;
38class THD;
39struct TABLE;
40class Table_ref;
41template <class T>
42class mem_root_deque;
43
44/// An iterator that performs updates to rows returned by its child iterator.
45class UpdateRowsIterator final : public RowIterator {
46 public:
48 TABLE *outermost_table, TABLE *immediate_table,
49 Table_ref *update_tables, TABLE **tmp_tables,
51 List<TABLE> unupdated_check_opt_tables,
52 COPY_INFO **update_operations,
53 mem_root_deque<Item *> **fields_for_table,
54 mem_root_deque<Item *> **values_for_table,
55 table_map tables_with_rowid_in_buffer);
56 ~UpdateRowsIterator() override;
57 bool Init() override;
58 int Read() 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 /// All the tables that are part of a hash join. We use this map to find out
101 /// how to get the row ID from a table when buffering row IDs for delayed
102 /// update. For those tables that are part of a hash join, the row ID will
103 /// already be available in handler::ref, and calling handler::position() will
104 /// overwrite it with an incorrect row ID (most likely the last row read from
105 /// the table). For those that are not part of a hash join,
106 /// handler::position() must be called to get the current row ID from the
107 /// underlying scan.
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:73
Definition: field.h:4572
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
Definition: sql_list.h:433
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:81
THD * thd() const
Definition: row_iterator.h:227
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:2755
An iterator that performs updates to rows returned by its child iterator.
Definition: update_rows_iterator.h:45
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
table_map m_hash_join_tables
All the tables that are part of a hash join.
Definition: update_rows_iterator.h:108
int Read() override
Read a single row.
Definition: sql_update.cc:2860
bool DoDelayedUpdates(bool *trans_safe, bool *transactional_tables)
Perform all the delayed updates.
Definition: sql_update.cc:2580
mem_root_deque< Item * > ** m_values_for_table
The values list decomposed into separate lists per table.
Definition: update_rows_iterator.h:95
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:2414
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: update_rows_iterator.h:59
~UpdateRowsIterator() override
Definition: sql_update.cc:2854
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
bool Init() override
Initialize or reinitialize the iterator.
Definition: sql_update.cc:2839
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
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
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:3038
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:109
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:4229
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:488
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1139
uint64_t table_map
Definition: my_table_map.h:29
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:41
Definition: table.h:1395