MySQL 8.1.0
Source Code Documentation
dd_sql_view.h
Go to the documentation of this file.
1#ifndef DD_SQL_VIEW_INCLUDED
2#define DD_SQL_VIEW_INCLUDED
3/* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
26#include "prealloced_array.h"
27
28class THD;
29class sp_name;
30class Table_ref;
31
32/**
33 Guard class which allows to invalidate TDC entries for specific tables/views.
34
35 We use it to get rid of TABLE_SHARE objects corresponding to tables/views
36 which definitions are not committed yet (and possibly won't be!).
37*/
38
40 public:
44
46
47 private:
50};
51
52/**
53 Update metadata of views referencing the table.
54
55 @param thd Thread handle.
56 @param db_name Database name.
57 @param table_name Update metadata of views referencing
58 this table.
59 @param commit_dd_changes Indicates whether changes to DD need
60 to be committed.
61 @param[in,out] uncommitted_tables Helper class to store list of views
62 which shares need to be removed from
63 TDC if we fail to commit changes to
64 DD. Only used if commit_dd_changes
65 is false.
66
67 @note In case when commit_dd_changes is false, the caller must rollback
68 both statement and transaction on failure, before any further
69 accesses to DD. This is because such a failure might be caused by
70 a deadlock, which requires rollback before any other operations on
71 SE (including reads using attachable transactions) can be done.
72 If case when commit_dd_changes is true this function will handle
73 transaction rollback itself.
74
75 @retval false Success.
76 @retval true Failure.
77*/
78
80 THD *thd, const char *db_name, const char *table_name,
81 bool commit_dd_changes, Uncommitted_tables_guard *uncommitted_tables);
82
83/**
84 Update metadata of views referencing the table.
85
86 @param thd Thread handle.
87 @param table Update metadata of views referencing
88 this table.
89 @param commit_dd_changes Indicates whether changes to DD need
90 to be committed.
91 @param[in,out] uncommitted_tables Helper class to store list of views
92 which shares need to be removed from
93 TDC if we fail to commit changes to
94 DD. Only used if commit_dd_changes
95 is false.
96
97 @note In case when commit_dd_changes is false, the caller must rollback
98 both statement and transaction on failure, before any further
99 accesses to DD. This is because such a failure might be caused by
100 a deadlock, which requires rollback before any other operations on
101 SE (including reads using attachable transactions) can be done.
102 If case when commit_dd_changes is true this function will handle
103 transaction rollback itself.
104
105 @retval false Success.
106 @retval true Failure.
107*/
108
110 THD *thd, const Table_ref *table, bool commit_dd_changes,
111 Uncommitted_tables_guard *uncommitted_tables);
112
113/**
114 Update metadata of views referencing "table" being renamed and views
115 referencing (if there any) new table name "new_db.new_table_name".
116
117 @param thd Thread handle.
118 @param table Update metadata of views referencing this
119 table.
120 @param new_db New db name set in the rename operation.
121 @param new_table_name New table name set in the rename
122 @param commit_dd_changes Indicates whether changes to DD need
123 to be committed.
124 @param[in,out] uncommitted_tables Helper class to store list of views
125 which shares need to be removed from
126 TDC if we fail to commit changes to
127 DD. Only used if commit_dd_changes
128 is false.
129
130 @note In case when commit_dd_changes is false, the caller must rollback
131 both statement and transaction on failure, before any further
132 accesses to DD. This is because such a failure might be caused by
133 a deadlock, which requires rollback before any other operations on
134 SE (including reads using attachable transactions) can be done.
135 If case when commit_dd_changes is true this function will handle
136 transaction rollback itself.
137 operation.
138
139 @retval false Success.
140 @retval true Failure.
141*/
142
144 THD *thd, const Table_ref *table, const char *new_db,
145 const char *new_table_name, bool commit_dd_changes,
146 Uncommitted_tables_guard *uncommitted_tables);
147
148/**
149 Method to update metadata of views using stored function.
150
151 @param thd Thread handle.
152 @param spname Name of the stored function.
153
154 @retval false Success.
155 @retval true Failure.
156*/
157
158bool update_referencing_views_metadata(THD *thd, const sp_name *spname);
159
160/**
161 Mark views referencing the table as invalid.
162
163 @param thd Thread handle.
164 @param table Views referencing this table need
165 to be marked as invalid.
166 @param skip_same_db Indicates whether it is OK to skip
167 views belonging to the same database
168 as table (as they will be dropped
169 anyway).
170 @param commit_dd_changes Indicates whether changes to DD need
171 to be committed.
172 @param mem_root Memory root for allocation of temporary
173 objects which will be cleared after
174 each call to this function.
175
176 @note In case when commit_dd_changes is false, the caller must rollback
177 both statement and transaction on failure, before any further
178 accesses to DD. This is because such a failure might be caused by
179 a deadlock, which requires rollback before any other operations on
180 SE (including reads using attachable transactions) can be done.
181 If case when commit_dd_changes is true this function will handle
182 transaction rollback itself.
183
184 @note This call is a version of update_referencing_views_metadata(),
185 which is optimized for DROP DATABASE case.
186
187
188 @retval false Success.
189 @retval true Failure.
190*/
191
193 bool skip_same_db, bool commit_dd_changes,
195
196/**
197 Mark views using stored function as invalid.
198
199 @param thd Thread handle.
200 @param spname Name of the stored function.
201 @param mem_root Memory root for allocation of temporary objects
202 which will be cleared after each call to this
203 function.
204
205 @note This call is a version of update_referencing_views_metadata(),
206 which is optimized for DROP DATABASE case.
207
208 @retval false Success.
209 @retval true Failure.
210*/
211
212bool mark_referencing_views_invalid(THD *thd, const sp_name *spname,
214
215/**
216 Push error or warnings in case a view is invalid and return
217 the error message to the caller.
218
219 @param thd Thread handle.
220 @param db Database name.
221 @param view_name View name.
222
223 returns The error/warning message string.
224*/
225std::string push_view_warning_or_error(THD *thd, const char *db,
226 const char *view_name);
227
228#endif // DD_SQL_VIEW_INCLUDED
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:70
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:2800
Guard class which allows to invalidate TDC entries for specific tables/views.
Definition: dd_sql_view.h:39
~Uncommitted_tables_guard()
Definition: dd_sql_view.cc:207
Uncommitted_tables_guard(THD *thd)
Definition: dd_sql_view.h:41
THD * m_thd
Definition: dd_sql_view.h:48
void add_table(Table_ref *table)
Definition: dd_sql_view.h:45
Prealloced_array< Table_ref *, 1 > m_uncommitted_tables
Definition: dd_sql_view.h:49
Definition: sp_head.h:122
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
bool update_referencing_views_metadata(THD *thd, const char *db_name, const char *table_name, bool commit_dd_changes, Uncommitted_tables_guard *uncommitted_tables)
Update metadata of views referencing the table.
Definition: dd_sql_view.cc:802
std::string push_view_warning_or_error(THD *thd, const char *db, const char *view_name)
Push error or warnings in case a view is invalid and return the error message to the caller.
Definition: dd_sql_view.cc:897
bool mark_referencing_views_invalid(THD *thd, const Table_ref *table, bool skip_same_db, bool commit_dd_changes, MEM_ROOT *mem_root)
Mark views referencing the table as invalid.
Definition: dd_sql_view.cc:871
static constexpr unsigned PSI_INSTRUMENT_ME
Definition: psi_bits.h:42
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
Performance schema instrumentation interface.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82