MySQL  8.0.16
Source Code Documentation
sql_update.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2018, 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 THD;
40 class Temp_table_param;
41 struct TABLE;
42 struct TABLE_LIST;
43 
45 bool compare_records(const TABLE *table);
46 
48  /// Number of tables being updated
50  /// Pointer to list of updated tables, linked via 'next_local'
52  /// Array of references to temporary tables used to store cached updates
54  /// Array of parameter structs for creation of temporary tables
56  /// The first table in the join operation
58  /**
59  In a multi-table update, this is equal to the first table in the join
60  operation (#main_table) if that table can be updated on the fly while
61  scanning it. It is `nullptr` otherwise.
62 
63  @see safe_update_on_fly
64  */
66  /// Number of rows found that matches join and WHERE conditions
68  /// Number of rows actually updated, in all affected tables
70  /// List of pointers to fields to update, in order from statement
72  /// List of pointers to values to update with, in order from statement
74  /// The fields list decomposed into separate lists per table
76  /// The values list decomposed into separate lists per table
78  /**
79  List of tables referenced in the CHECK OPTION condition of
80  the updated view excluding the updated table.
81  */
83  /// ???
85  /// Length of the copy_field array.
86  size_t max_fields{0};
87  /// True if the full update operation is complete
89  /// True if all tables to be updated are transactional.
90  bool trans_safe;
91  /// True if the update operation has made a change in a transactional table
93  /**
94  error handling (rollback and binlogging) can happen in send_eof()
95  so that afterward send_error() needs to find out that.
96  */
98 
99  /**
100  Array of update operations, arranged per _updated_ table. For each
101  _updated_ table in the multiple table update statement, a COPY_INFO
102  pointer is present at the table's position in this array.
103 
104  The array is allocated and populated during Query_result_update::prepare().
105  The position that each table is assigned is also given here and is stored
106  in the member TABLE::pos_in_table_list::shared. However, this is a publicly
107  available field, so nothing can be trusted about its integrity.
108 
109  This member is NULL when the Query_result_update is created.
110 
111  @see Query_result_update::prepare
112  */
114 
115  public:
116  Query_result_update(List<Item> *field_list, List<Item> *value_list)
120  tmp_tables(NULL),
121  main_table(NULL),
123  found_rows(0),
124  updated_rows(0),
125  fields(field_list),
126  values(value_list),
127  copy_field(NULL),
129  trans_safe(true),
133  bool need_explain_interceptor() const override { return true; }
134  bool prepare(THD *thd, List<Item> &list, SELECT_LEX_UNIT *u) override;
135  bool optimize() override;
136  bool start_execution(THD *) override {
137  update_completed = false;
138  return false;
139  }
140  bool send_data(THD *thd, List<Item> &items) override;
141  void send_error(THD *thd, uint errcode, const char *err) override;
142  bool do_updates(THD *thd);
143  bool send_eof(THD *thd) override;
144  void abort_result_set(THD *thd) override;
145  void cleanup(THD *thd) override;
146 };
147 
149  public:
150  Sql_cmd_update(bool multitable_arg, List<Item> *update_values)
151  : multitable(multitable_arg), update_value_list(update_values) {}
152 
155  }
156 
157  bool is_single_table_plan() const override { return !multitable; }
158 
159  protected:
160  bool precheck(THD *thd) override;
161 
162  bool prepare_inner(THD *thd) override;
163 
164  bool execute_inner(THD *thd) override;
165 
166  private:
167  bool update_single_table(THD *thd);
168 
170 
171  bool accept(THD *thd, Select_lex_visitor *visitor) override;
172 
173  public:
175 };
176 
177 #endif /* SQL_UPDATE_INCLUDED */
ha_rows updated_rows
Number of rows actually updated, in all affected tables.
Definition: sql_update.h:69
bool start_execution(THD *) override
Prepare for execution of the query expression or DML statement.
Definition: sql_update.h:136
COPY_INFO ** update_operations
Array of update operations, arranged per updated table.
Definition: sql_update.h:113
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:65
List< Item > * values
List of pointers to values to update with, in order from statement.
Definition: sql_update.h:73
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4601
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:161
bool need_explain_interceptor() const override
Definition: sql_update.h:133
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:157
enum_sql_command
Definition: my_sqlcommand.h:45
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
bool update_single_table(THD *thd)
Perform an update to a set of rows in a single table.
Definition: sql_update.cc:269
ha_rows found_rows
Number of rows found that matches join and WHERE conditions.
Definition: sql_update.h:67
TABLE_LIST * update_tables
Pointer to list of updated tables, linked via &#39;next_local&#39;.
Definition: sql_update.h:51
class udf_list * list
TABLE * main_table
The first table in the join operation.
Definition: sql_update.h:57
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_update.h:153
bool precheck(THD *thd) override
Perform a precheck of table privileges for the specific operation.
Definition: sql_update.cc:107
TABLE * table
Definition: table.h:3096
bool update_completed
True if the full update operation is complete.
Definition: sql_update.h:88
bool send_eof(THD *thd) override
Definition: sql_update.cc:2473
TABLE ** tmp_tables
Array of references to temporary tables used to store cached updates.
Definition: sql_update.h:53
Definition: table.h:1294
void abort_result_set(THD *thd) override
Definition: sql_update.cc:2210
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:143
List< TABLE > unupdated_check_opt_tables
List of tables referenced in the CHECK OPTION condition of the updated view excluding the updated ta...
Definition: sql_update.h:82
bool accept(THD *thd, Select_lex_visitor *visitor) override
Definition: sql_update.cc:2546
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:92
List< Item > * fields
List of pointers to fields to update, in order from statement.
Definition: sql_update.h:71
bool prepare_inner(THD *thd) override
Perform the command-specific parts of DML command preparation, to be called from prepare() ...
Definition: sql_update.cc:1272
size_t max_fields
Length of the copy_field array.
Definition: sql_update.h:86
void cleanup(THD *thd) override
Cleanup after this execution.
Definition: sql_update.cc:2032
Copy_field * copy_field
???
Definition: sql_update.h:84
bool multitable
Definition: sql_update.h:169
Definition: item.h:666
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:2056
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:910
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:614
Definition: my_sqlcommand.h:50
bool do_updates(THD *thd)
Definition: sql_update.cc:2253
bool trans_safe
True if all tables to be updated are transactional.
Definition: sql_update.h:90
List< Item > * update_value_list
Definition: sql_update.h:174
bool error_handled
error handling (rollback and binlogging) can happen in send_eof() so that afterward send_error() need...
Definition: sql_update.h:97
Definition: query_result.h:177
bool optimize() override
Set up data structures for multi-table UPDATE.
Definition: sql_update.cc:1824
List< Item > ** fields_for_table
The fields list decomposed into separate lists per table.
Definition: sql_update.h:75
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:55
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:1592
Query_result_update(List< Item > *field_list, List< Item > *value_list)
Definition: sql_update.h:116
Definition: sql_update.h:148
Definition: sql_cmd_dml.h:32
uint update_table_count
Number of tables being updated.
Definition: sql_update.h:49
void send_error(THD *thd, uint errcode, const char *err) override
Definition: sql_update.cc:2205
Definition: table.h:2439
Definition: sql_update.h:47
List< Item > ** values_for_table
The values list decomposed into separate lists per table.
Definition: sql_update.h:77
Sql_cmd_update(bool multitable_arg, List< Item > *update_values)
Definition: sql_update.h:150
#define false
Definition: config_static.h:43
bool execute_inner(THD *thd) override
The inner parts of query optimization and execution.
Definition: sql_update.cc:1583
my_off_t ha_rows
Definition: my_base.h:1066
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:70
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:776