MySQL  8.0.18
Source Code Documentation
sql_cmd_dml.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2017, 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_CMD_DML_INCLUDED
24 #define SQL_CMD_DML_INCLUDED
25 
26 #include "my_dbug.h"
27 #include "sql/sql_cmd.h"
28 
29 struct LEX;
30 class Query_result;
31 
32 class Sql_cmd_dml : public Sql_cmd {
33  public:
34  /// @return true if data change statement, false if not (SELECT statement)
35  virtual bool is_data_change_stmt() const { return true; }
36 
37  /**
38  Command-specific resolving (doesn't include LEX::prepare())
39 
40  @param thd Current THD.
41 
42  @returns false on success, true on error
43  */
44  virtual bool prepare(THD *thd);
45 
46  /**
47  Execute this query once.
48 
49  @param thd Thread handler
50 
51  @returns false on success, true on error
52  */
53  virtual bool execute(THD *thd);
54 
55  virtual bool is_dml() const { return true; }
56 
57  virtual bool is_single_table_plan() const { return false; }
58 
59  protected:
61 
62  /// @return true if query is guaranteed to return no data
63  /**
64  @todo Also check this for the following cases:
65  - Empty source for multi-table UPDATE and DELETE.
66  - Check empty query expression for INSERT
67  */
68  bool is_empty_query() const {
70  return m_empty_query;
71  }
72 
73  /// Set statement as returning no data
74  void set_empty_query() { m_empty_query = true; }
75 
76  /**
77  Perform a precheck of table privileges for the specific operation.
78 
79  @details
80  Check that user has some relevant privileges for all tables involved in
81  the statement, e.g. SELECT privileges for tables selected from, INSERT
82  privileges for tables inserted into, etc. This function will also populate
83  TABLE_LIST::grant with all privileges the user has for each table, which
84  is later used during checking of column privileges.
85  Note that at preparation time, views are not expanded yet. Privilege
86  checking is thus rudimentary and must be complemented with later calls to
87  SELECT_LEX::check_view_privileges().
88  The reason to call this function at such an early stage is to be able to
89  quickly reject statements for which the user obviously has insufficient
90  privileges.
91 
92  @param thd thread handler
93 
94  @returns false if success, true if false
95  */
96  virtual bool precheck(THD *thd) = 0;
97 
98  /**
99  Perform the command-specific parts of DML command preparation,
100  to be called from prepare()
101 
102  @param thd the current thread
103 
104  @returns false if success, true if error
105  */
106  virtual bool prepare_inner(THD *thd) = 0;
107 
108  /**
109  The inner parts of query optimization and execution.
110  Single-table DML operations needs to reimplement this.
111 
112  @param thd Thread handler
113 
114  @returns false on success, true on error
115  */
116  virtual bool execute_inner(THD *thd);
117 
118  protected:
119  LEX *lex; ///< Pointer to LEX for this statement
120  Query_result *result; ///< Pointer to object for handling of the result
121  bool m_empty_query; ///< True if query will produce no rows
122 };
123 
124 #endif /* SQL_CMD_DML_INCLUDED */
Definition: result.h:33
Representation of an SQL command.
Definition: sql_cmd.h:63
Definition: sql_lex.h:3192
Definition: query_result.h:48
void set_empty_query()
Set statement as returning no data.
Definition: sql_cmd_dml.h:74
virtual bool prepare_inner(THD *thd)=0
Perform the command-specific parts of DML command preparation, to be called from prepare() ...
Representation of an SQL command.
virtual bool prepare(THD *thd)
Command-specific resolving (doesn&#39;t include LEX::prepare())
Definition: sql_select.cc:395
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
virtual bool is_data_change_stmt() const
Definition: sql_cmd_dml.h:35
Sql_cmd_dml()
Definition: sql_cmd_dml.h:60
Query_result * result
Pointer to object for handling of the result.
Definition: sql_cmd_dml.h:120
LEX * lex
Pointer to LEX for this statement.
Definition: sql_cmd_dml.h:119
bool m_empty_query
True if query will produce no rows.
Definition: sql_cmd_dml.h:121
bool is_prepared() const
Definition: sql_cmd.h:75
bool is_empty_query() const
Definition: sql_cmd_dml.h:68
virtual bool precheck(THD *thd)=0
Perform a precheck of table privileges for the specific operation.
virtual bool execute_inner(THD *thd)
The inner parts of query optimization and execution.
Definition: sql_select.cc:884
virtual bool is_single_table_plan() const
Definition: sql_cmd_dml.h:57
#define NULL
Definition: types.h:55
virtual bool execute(THD *thd)
Execute this query once.
Definition: sql_select.cc:620
Definition: sql_cmd_dml.h:32
virtual bool is_dml() const
Definition: sql_cmd_dml.h:55
#define false
Definition: config_static.h:43
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778