MySQL 8.4.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, 2024, 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 designed to work 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 either included with
15 the program or referenced in the documentation.
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
27#include "prealloced_array.h"
28
29class THD;
30class sp_name;
31class Table_ref;
32
33/**
34 Guard class which allows to invalidate TDC entries for specific tables/views.
35
36 We use it to get rid of TABLE_SHARE objects corresponding to tables/views
37 which definitions are not committed yet (and possibly won't be!).
38*/
39
41 public:
45
47
48 private:
51};
52
53/**
54 Update metadata of views referencing the table.
55
56 @param thd Thread handle.
57 @param db_name Database name.
58 @param table_name Update metadata of views referencing
59 this table.
60 @param commit_dd_changes Indicates whether changes to DD need
61 to be committed.
62 @param[in,out] uncommitted_tables Helper class to store list of views
63 which shares need to be removed from
64 TDC if we fail to commit changes to
65 DD. Only used if commit_dd_changes
66 is false.
67
68 @note In case when commit_dd_changes is false, the caller must rollback
69 both statement and transaction on failure, before any further
70 accesses to DD. This is because such a failure might be caused by
71 a deadlock, which requires rollback before any other operations on
72 SE (including reads using attachable transactions) can be done.
73 If case when commit_dd_changes is true this function will handle
74 transaction rollback itself.
75
76 @retval false Success.
77 @retval true Failure.
78*/
79
81 THD *thd, const char *db_name, const char *table_name,
82 bool commit_dd_changes, Uncommitted_tables_guard *uncommitted_tables);
83
84/**
85 Update metadata of views referencing the table.
86
87 @param thd Thread handle.
88 @param table Update metadata of views referencing
89 this table.
90 @param commit_dd_changes Indicates whether changes to DD need
91 to be committed.
92 @param[in,out] uncommitted_tables Helper class to store list of views
93 which shares need to be removed from
94 TDC if we fail to commit changes to
95 DD. Only used if commit_dd_changes
96 is false.
97
98 @note In case when commit_dd_changes is false, the caller must rollback
99 both statement and transaction on failure, before any further
100 accesses to DD. This is because such a failure might be caused by
101 a deadlock, which requires rollback before any other operations on
102 SE (including reads using attachable transactions) can be done.
103 If case when commit_dd_changes is true this function will handle
104 transaction rollback itself.
105
106 @retval false Success.
107 @retval true Failure.
108*/
109
111 THD *thd, const Table_ref *table, bool commit_dd_changes,
112 Uncommitted_tables_guard *uncommitted_tables);
113
114/**
115 Update metadata of views referencing "table" being renamed and views
116 referencing (if there any) new table name "new_db.new_table_name".
117
118 @param thd Thread handle.
119 @param table Update metadata of views referencing this
120 table.
121 @param new_db New db name set in the rename operation.
122 @param new_table_name New table name set in the rename
123 @param commit_dd_changes Indicates whether changes to DD need
124 to be committed.
125 @param[in,out] uncommitted_tables Helper class to store list of views
126 which shares need to be removed from
127 TDC if we fail to commit changes to
128 DD. Only used if commit_dd_changes
129 is false.
130
131 @note In case when commit_dd_changes is false, the caller must rollback
132 both statement and transaction on failure, before any further
133 accesses to DD. This is because such a failure might be caused by
134 a deadlock, which requires rollback before any other operations on
135 SE (including reads using attachable transactions) can be done.
136 If case when commit_dd_changes is true this function will handle
137 transaction rollback itself.
138 operation.
139
140 @retval false Success.
141 @retval true Failure.
142*/
143
145 THD *thd, const Table_ref *table, const char *new_db,
146 const char *new_table_name, bool commit_dd_changes,
147 Uncommitted_tables_guard *uncommitted_tables);
148
149/**
150 Method to update metadata of views using stored function.
151
152 @param thd Thread handle.
153 @param spname Name of the stored function.
154
155 @retval false Success.
156 @retval true Failure.
157*/
158
159bool update_referencing_views_metadata(THD *thd, const sp_name *spname);
160
161/**
162 Mark views referencing the table as invalid.
163
164 @param thd Thread handle.
165 @param table Views referencing this table need
166 to be marked as invalid.
167 @param skip_same_db Indicates whether it is OK to skip
168 views belonging to the same database
169 as table (as they will be dropped
170 anyway).
171 @param commit_dd_changes Indicates whether changes to DD need
172 to be committed.
173 @param mem_root Memory root for allocation of temporary
174 objects which will be cleared after
175 each call to this function.
176
177 @note In case when commit_dd_changes is false, the caller must rollback
178 both statement and transaction on failure, before any further
179 accesses to DD. This is because such a failure might be caused by
180 a deadlock, which requires rollback before any other operations on
181 SE (including reads using attachable transactions) can be done.
182 If case when commit_dd_changes is true this function will handle
183 transaction rollback itself.
184
185 @note This call is a version of update_referencing_views_metadata(),
186 which is optimized for DROP DATABASE case.
187
188
189 @retval false Success.
190 @retval true Failure.
191*/
192
194 bool skip_same_db, bool commit_dd_changes,
196
197/**
198 Mark views using stored function as invalid.
199
200 @param thd Thread handle.
201 @param spname Name of the stored function.
202 @param mem_root Memory root for allocation of temporary objects
203 which will be cleared after each call to this
204 function.
205
206 @note This call is a version of update_referencing_views_metadata(),
207 which is optimized for DROP DATABASE case.
208
209 @retval false Success.
210 @retval true Failure.
211*/
212
213bool mark_referencing_views_invalid(THD *thd, const sp_name *spname,
215
216/**
217 Push error or warnings in case a view is invalid and return
218 the error message to the caller.
219
220 @param thd Thread handle.
221 @param db Database name.
222 @param view_name View name.
223
224 returns The error/warning message string.
225*/
226std::string push_view_warning_or_error(THD *thd, const char *db,
227 const char *view_name);
228
229#endif // DD_SQL_VIEW_INCLUDED
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2863
Guard class which allows to invalidate TDC entries for specific tables/views.
Definition: dd_sql_view.h:40
~Uncommitted_tables_guard()
Definition: dd_sql_view.cc:208
Uncommitted_tables_guard(THD *thd)
Definition: dd_sql_view.h:42
THD * m_thd
Definition: dd_sql_view.h:49
void add_table(Table_ref *table)
Definition: dd_sql_view.h:46
Prealloced_array< Table_ref *, 1 > m_uncommitted_tables
Definition: dd_sql_view.h:50
Definition: sp_head.h:123
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
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:803
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:898
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:872
static constexpr unsigned PSI_INSTRUMENT_ME
Definition: psi_bits.h:43
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
Performance schema instrumentation interface.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83