MySQL  8.0.20
Source Code Documentation
sql_update.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
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_UPDATE_INCLUDED
24 #define SQL_UPDATE_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 
29 #include "my_base.h"
30 #include "my_sqlcommand.h"
31 #include "sql/query_result.h" // Query_result_interceptor
32 #include "sql/sql_cmd_dml.h" // Sql_cmd_dml
33 #include "sql/sql_list.h"
34 
35 class COPY_INFO;
36 class Copy_field;
37 class Item;
38 class SELECT_LEX_UNIT;
39 class Select_lex_visitor;
40 class THD;
41 class Temp_table_param;
42 struct TABLE;
43 struct TABLE_LIST;
44 
46 bool compare_records(const TABLE *table);
47 
49  /// Number of tables being updated
51  /// Pointer to list of updated tables, linked via 'next_local'
53  /// Array of references to temporary tables used to store cached updates
55  /// Array of parameter structs for creation of temporary tables
57  /// The first table in the join operation
59  /**
60  In a multi-table update, this is equal to the first table in the join
61  operation (#main_table) if that table can be updated on the fly while
62  scanning it. It is `nullptr` otherwise.
63 
64  @see safe_update_on_fly
65  */
67  /// Number of rows found that matches join and WHERE conditions
69  /// Number of rows actually updated, in all affected tables
71  /// List of pointers to fields to update, in order from statement
73  /// List of pointers to values to update with, in order from statement
75  /// The fields list decomposed into separate lists per table
77  /// The values list decomposed into separate lists per table
79  /**
80  List of tables referenced in the CHECK OPTION condition of
81  the updated view excluding the updated table.
82  */
84  /// ???
86  /// Length of the copy_field array.
87  size_t max_fields{0};
88  /// True if the full update operation is complete
90  /// True if all tables to be updated are transactional.
91  bool trans_safe;
92  /// True if the update operation has made a change in a transactional table
94  /**
95  error handling (rollback and binlogging) can happen in send_eof()
96  so that afterward send_error() needs to find out that.
97  */
99 
100  /**
101  Array of update operations, arranged per _updated_ table. For each
102  _updated_ table in the multiple table update statement, a COPY_INFO
103  pointer is present at the table's position in this array.
104 
105  The array is allocated and populated during Query_result_update::prepare().
106  The position that each table is assigned is also given here and is stored
107  in the member TABLE::pos_in_table_list::shared. However, this is a publicly
108  available field, so nothing can be trusted about its integrity.
109 
110  This member is NULL when the Query_result_update is created.
111 
112  @see Query_result_update::prepare
113  */
115 
116  public:
117  Query_result_update(List<Item> *field_list, List<Item> *value_list)
119  update_table_count(0),
120  update_tables(nullptr),
121  tmp_tables(nullptr),
122  main_table(nullptr),
123  table_to_update(nullptr),
124  found_rows(0),
125  updated_rows(0),
126  fields(field_list),
127  values(value_list),
128  copy_field(nullptr),
129  update_completed(false),
130  trans_safe(true),
131  transactional_tables(false),
132  error_handled(false),
133  update_operations(nullptr) {}
134  bool need_explain_interceptor() const override { return true; }
135  bool prepare(THD *thd, List<Item> &list, SELECT_LEX_UNIT *u) override;
136  bool optimize() override;
137  bool start_execution(THD *) override {
138  update_completed = false;
139  return false;
140  }
141  bool send_data(THD *thd, List<Item> &items) override;
142  void send_error(THD *thd, uint errcode, const char *err) override;
143  bool do_updates(THD *thd);
144  bool send_eof(THD *thd) override;
145  void abort_result_set(THD *thd) override;
146  void cleanup(THD *thd) override;
147 };
148 
150  public:
151  Sql_cmd_update(bool multitable_arg, List<Item> *update_values)
152  : multitable(multitable_arg), update_value_list(update_values) {}
153 
155  return multitable ? SQLCOM_UPDATE_MULTI : SQLCOM_UPDATE;
156  }
157 
158  bool is_single_table_plan() const override { return !multitable; }
159 
160  protected:
161  bool precheck(THD *thd) override;
162 
163  bool prepare_inner(THD *thd) override;
164 
165  bool execute_inner(THD *thd) override;
166 
167  private:
168  bool update_single_table(THD *thd);
169 
171 
172  bool accept(THD *thd, Select_lex_visitor *visitor) override;
173 
174  public:
176 };
177 
178 #endif /* SQL_UPDATE_INCLUDED */
ha_rows updated_rows
Number of rows actually updated, in all affected tables.
Definition: sql_update.h:70
bool start_execution(THD *) override
Prepare for execution of the query expression or DML statement.
Definition: sql_update.h:137
COPY_INFO ** update_operations
Array of update operations, arranged per updated table.
Definition: sql_update.h:114
TABLE * table_to_update
In a multi-table update, this is equal to the first table in the join operation (main_table) if that ...
Definition: sql_update.h:66
List< Item > * values
List of pointers to values to update with, in order from statement.
Definition: sql_update.h:74
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4780
bool compare_records(const TABLE *table)
Compares the input and outbut record buffers of the table to see if a row has changed.
Definition: sql_update.cc:164
bool need_explain_interceptor() const override
Definition: sql_update.h:134
Abstract base class for traversing the SELECT_LEX tree.
Definition: select_lex_visitor.h:39
bool is_single_table_plan() const override
Definition: sql_update.h:158
enum_sql_command
Definition: my_sqlcommand.h:45
ha_rows found_rows
Number of rows found that matches join and WHERE conditions.
Definition: sql_update.h:68
TABLE_LIST * update_tables
Pointer to list of updated tables, linked via &#39;next_local&#39;.
Definition: sql_update.h:52
class udf_list * list
TABLE * main_table
The first table in the join operation.
Definition: sql_update.h:58
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_update.h:154
TABLE * table
Definition: table.h:3220
bool update_completed
True if the full update operation is complete.
Definition: sql_update.h:89
bool send_eof(THD *thd) override
Definition: sql_update.cc:2549
TABLE ** tmp_tables
Array of references to temporary tables used to store cached updates.
Definition: sql_update.h:54
Definition: table.h:1306
void abort_result_set(THD *thd) override
Definition: sql_update.cc:2253
bool records_are_comparable(const TABLE *table)
True if the table&#39;s input and output record buffers are comparable using compare_records(TABLE*).
Definition: sql_update.cc:146
List< TABLE > unupdated_check_opt_tables
List of tables referenced in the CHECK OPTION condition of the updated view excluding the updated tab...
Definition: sql_update.h:83
This file includes constants used by all storage engines.
bool transactional_tables
True if the update operation has made a change in a transactional table.
Definition: sql_update.h:93
List< Item > * fields
List of pointers to fields to update, in order from statement.
Definition: sql_update.h:72
size_t max_fields
Length of the copy_field array.
Definition: sql_update.h:87
void cleanup(THD *thd) override
Cleanup after this execution.
Definition: sql_update.cc:2067
Copy_field * copy_field
???
Definition: sql_update.h:85
bool multitable
Definition: sql_update.h:170
Definition: item.h:740
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
#define true
Definition: config_static.h:44
bool send_data(THD *thd, List< Item > &items) override
Definition: sql_update.cc:2091
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:587
Definition: my_sqlcommand.h:50
bool do_updates(THD *thd)
Definition: sql_update.cc:2296
bool trans_safe
True if all tables to be updated are transactional.
Definition: sql_update.h:91
List< Item > * update_value_list
Definition: sql_update.h:175
bool error_handled
error handling (rollback and binlogging) can happen in send_eof() so that afterward send_error() need...
Definition: sql_update.h:98
Definition: query_result.h:177
bool optimize() override
Set up data structures for multi-table UPDATE.
Definition: sql_update.cc:1859
List< Item > ** fields_for_table
The fields list decomposed into separate lists per table.
Definition: sql_update.h:76
This class encapsulates a data change operation.
Definition: sql_data_change.h:71
Temp_table_param * tmp_table_param
Array of parameter structs for creation of temporary tables.
Definition: sql_update.h:56
bool prepare(THD *thd, List< Item > &list, SELECT_LEX_UNIT *u) override
Perform preparation specific to the query expression or DML statement.
Definition: sql_update.cc:1627
Query_result_update(List< Item > *field_list, List< Item > *value_list)
Definition: sql_update.h:117
Definition: sql_update.h:149
Definition: sql_cmd_dml.h:32
uint update_table_count
Number of tables being updated.
Definition: sql_update.h:50
void send_error(THD *thd, uint errcode, const char *err) override
Definition: sql_update.cc:2248
Definition: table.h:2481
Definition: sql_update.h:48
List< Item > ** values_for_table
The values list decomposed into separate lists per table.
Definition: sql_update.h:78
Sql_cmd_update(bool multitable_arg, List< Item > *update_values)
Definition: sql_update.h:151
#define false
Definition: config_static.h:43
my_off_t ha_rows
Definition: my_base.h:1132
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:74
Definition: items.h:34
Definition: my_sqlcommand.h:121
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:765
Dialog Client Authentication nullptr
Definition: dialog.cc:353