MySQL 8.0.30
Source Code Documentation
sql_constraint.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2022, Oracle and/or its affiliates.
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_CONSTRAINT_INCLUDED
24#define SQL_CONSTRAINT_INCLUDED
25
26#include "my_inttypes.h" // ulonglong
27
29class Alter_drop;
30class Alter_info;
31class KEY;
32struct TABLE;
33class THD;
34namespace dd {
35class Table;
36}
37
38/**
39 Base class to resolve constraints type for the constraints specified in the
40 ALTER TABLE ... DROP/ALTER CONSTRAINT operation.
41
42 For a constraint specified in the DROP/ALTER CONSTRAINT operations of a ALTER
43 TABLE statement, actual constraint type is unknown. This is the class to
44 resolve the actual constraint type (PRIMARY, UNIQUE, FOREIGN KEY or CHECK) of
45 a constraint by name. Changes to Alter_info instance are reverted in the
46 destructor to make operation safe for re-execution of a stored routines and
47 prepared statements.
48*/
50 public:
52 : m_alter_info(alter_info) {}
53 virtual ~Constraint_type_resolver() = default;
54
55 /**
56 Method to check if constraint type resolution is needed.
57
58 @retval true if ALTER TABLE statement has DROP/ALTER CONSTRAINT operations.
59 @retval false Otherwise.
60 */
61 virtual bool is_type_resolution_needed() const = 0;
62
63 /**
64 Method to resolve constraints type.
65
66 @param thd Thread handle.
67 @param src_table TABLE instance of a source table.
68 @param dd_src_table Data-dictionary table instance of
69 a source table.
70
71 @retval false Success.
72 @retval true Failure.
73 */
74 virtual bool resolve_constraints_type(THD *thd, const TABLE *src_table,
75 const dd::Table *dd_src_table) = 0;
76
77 protected:
78 /**
79 Helper method to check if "name" type is PRIMARY or UNIQUE constraint.
80
81 @param src_table TABLE instance of a source table.
82 @param name Constraint name.
83
84 @retval non-nullptr Returns pointer to KEY instance if "name" is PRIMARY
85 or UNIQUE constraint.
86 @retval nullptr Otherwise.
87 */
89 const char *name);
90
91 /**
92 Helper method to check if "name" type is REFERENTIAL constraint.
93
94 @param dd_src_table Data-dictionary table instance of a source table.
95 @param name Constraint name.
96
97 @retval true If "name" type is REFERENTIAL.
98 @retval false Otherwise.
99 */
100 bool is_referential_constraint(const dd::Table *dd_src_table,
101 const char *name);
102
103 /**
104 Helper method to check if "name" type is CHECK constraint.
105
106 @param src_table TABLE instance of a source table.
107 @param name Constraint name.
108
109 @retval true If "name" type is CHECK.
110 @retval false Otherwise.
111 */
112 bool is_check_constraint(const TABLE *src_table, const char *name);
113
114 protected:
115 /// Alter_info instance describing table being altered.
117};
118
119/**
120 Class to resolve constraints type for the constraints specified in the
121 ALTER TABLE ... DROP CONSTRAINT operation.
122
123 For a constraint specified in the DROP CONSTRAINT operations of a ALTER TABLE
124 statement, actual constraint type is unknown. This is the class to resolve
125 actual constraint type (PRIMARY, UNIQUE, FOREIGN KEY or CHECK) by constraint
126 name. Alter_drop elements with actual constraint type are added to the
127 Alter_info::Alter_drop list. To make changes safe for re-execution of a stored
128 routines and prepared statements, elements added to Alter_drop list are
129 removed in the destructor.
130*/
132 public:
134 : Constraint_type_resolver(alter_info) {}
136
137 /**
138 Method to check if constraint type resolution is needed.
139
140 @retval true if ALTER TABLE statement has DROP CONSTRAINT operations.
141 @retval false Otherwise.
142 */
143 bool is_type_resolution_needed() const override;
144
145 /**
146 Method to resolve constraints type.
147
148 @param thd Thread handle.
149 @param src_table TABLE instance of a source table.
150 @param dd_src_table Data-dictionary table instance of
151 a source table.
152
153 @retval false Success.
154 @retval true Failure.
155 */
156 bool resolve_constraints_type(THD *thd, const TABLE *src_table,
157 const dd::Table *dd_src_table) override;
158
159 private:
160 /**
161 Method to resolve constraint type.
162
163 @param thd Thread handle.
164 @param src_table TABLE instance of a source table.
165 @param dd_src_table Data-dictionary table instance of
166 a source table.
167 @param drop Alter_drop instance for which
168 type should be resolved.
169
170 @retval false Success.
171 @retval true Failure.
172 */
173 bool resolve_constraint_type(THD *thd, const TABLE *src_table,
174 const dd::Table *dd_src_table,
175 const Alter_drop *drop);
176
177 private:
178 /// Flags set in Alter_info::flags while fixing type for constraint.
180
181 /*
182 Alter_drop element with actual type is added to the Alter_info::drop_list
183 for each DROP CONSTRAINT operation. Member holds the position of the first
184 Alter_drop element with actual type in the Alter_info::drop_list list.
185 */
187};
188
189/**
190 Class to resolve constraints type for the constraints specified in the
191 ALTER TABLE ... ALTER CONSTRAINT operation.
192
193 For a constraint specified in the ALTER CONSTRAINT operations of a ALTER TABLE
194 statement, actual constraint type is unknown. This is the class to resolve
195 actual constraint type (PRIMARY, UNIQUE, FOREIGN KEY or CHECK) by constraint
196 name. Alter_constraint_enforcement elements with actual constraint type are
197 added to the alter_constraint_enforcement_list. To make changes safe for
198 re-execution of stored routines and prepared statements, elements added to
199 list are removed in the destructor.
200*/
202 public:
204 : Constraint_type_resolver(alter_info) {}
206
207 /**
208 Method to check if constraint type resolution is needed.
209
210 @retval true if ALTER TABLE statement has ALTER CONSTRAINT operations.
211 @retval false Otherwise.
212 */
213 bool is_type_resolution_needed() const override;
214
215 /**
216 Method to resolve constraints type.
217
218 @param thd Thread handle.
219 @param src_table TABLE instance of a source table.
220 @param dd_src_table Data-dictionary table instance of
221 a source table.
222
223 @retval false Success.
224 @retval true Failure.
225 */
226 bool resolve_constraints_type(THD *thd, const TABLE *src_table,
227 const dd::Table *dd_src_table) override;
228
229 private:
230 /**
231 Method to resolve constraint type.
232
233 @param thd Thread handle.
234 @param src_table TABLE instance of a source table.
235 @param dd_src_table Data-dictionary table instance of
236 a source table.
237 @param alter_constraint Alter_constraint_enforcement
238 instance for which type should be
239 resolved.
240
241 @retval false Success.
242 @retval true Failure.
243 */
245 THD *thd, const TABLE *src_table, const dd::Table *dd_src_table,
246 const Alter_constraint_enforcement *alter_constraint);
247
248 private:
249 /// Flags set in Alter_info::flags while fixing type for check constraint.
251
252 /*
253 Alter_constraint_enforcement element with actual type is added to the
254 Alter_info::alter_constraint_enforcement_list for each ALTER CONSTRAINT
255 operation. Member holds position of the first Alter_constraint_enforcement
256 element with actual type in the alter_constraint_enforcement_list.
257 */
259};
260#endif // SQL_CONSTRAINT_INCLUDED
Class representing ALTER CHECK and ALTER CONSTRAINT clauses in ALTER TABLE statement.
Definition: sql_alter.h:182
Class representing DROP COLUMN, DROP KEY, DROP FOREIGN KEY, DROP CHECK CONSTRAINT and DROP CONSTRAINT...
Definition: sql_alter.h:63
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:203
Base class to resolve constraints type for the constraints specified in the ALTER TABLE ....
Definition: sql_constraint.h:49
Alter_info * m_alter_info
Alter_info instance describing table being altered.
Definition: sql_constraint.h:116
virtual bool is_type_resolution_needed() const =0
Method to check if constraint type resolution is needed.
KEY * is_primary_or_unique_constraint(const TABLE *src_table, const char *name)
Helper method to check if "name" type is PRIMARY or UNIQUE constraint.
Definition: sql_constraint.cc:34
bool is_referential_constraint(const dd::Table *dd_src_table, const char *name)
Helper method to check if "name" type is REFERENTIAL constraint.
Definition: sql_constraint.cc:48
Constraint_type_resolver(Alter_info *alter_info)
Definition: sql_constraint.h:51
virtual ~Constraint_type_resolver()=default
bool is_check_constraint(const TABLE *src_table, const char *name)
Helper method to check if "name" type is CHECK constraint.
Definition: sql_constraint.cc:60
virtual bool resolve_constraints_type(THD *thd, const TABLE *src_table, const dd::Table *dd_src_table)=0
Method to resolve constraints type.
Class to resolve constraints type for the constraints specified in the ALTER TABLE ....
Definition: sql_constraint.h:131
Drop_constraint_type_resolver(Alter_info *alter_info)
Definition: sql_constraint.h:133
bool is_type_resolution_needed() const override
Method to check if constraint type resolution is needed.
Definition: sql_constraint.cc:85
~Drop_constraint_type_resolver() override
Definition: sql_constraint.cc:73
bool resolve_constraint_type(THD *thd, const TABLE *src_table, const dd::Table *dd_src_table, const Alter_drop *drop)
Method to resolve constraint type.
Definition: sql_constraint.cc:89
uint m_first_fixed_alter_drop_pos
Definition: sql_constraint.h:186
bool resolve_constraints_type(THD *thd, const TABLE *src_table, const dd::Table *dd_src_table) override
Method to resolve constraints type.
Definition: sql_constraint.cc:156
ulonglong m_flags
Flags set in Alter_info::flags while fixing type for constraint.
Definition: sql_constraint.h:179
Class to resolve constraints type for the constraints specified in the ALTER TABLE ....
Definition: sql_constraint.h:201
~Enforce_constraint_type_resolver() override
Definition: sql_constraint.cc:172
Enforce_constraint_type_resolver(Alter_info *alter_info)
Definition: sql_constraint.h:203
bool resolve_constraint_type(THD *thd, const TABLE *src_table, const dd::Table *dd_src_table, const Alter_constraint_enforcement *alter_constraint)
Method to resolve constraint type.
Definition: sql_constraint.cc:193
bool is_type_resolution_needed() const override
Method to check if constraint type resolution is needed.
Definition: sql_constraint.cc:188
ulonglong m_flags
Flags set in Alter_info::flags while fixing type for check constraint.
Definition: sql_constraint.h:250
bool resolve_constraints_type(THD *thd, const TABLE *src_table, const dd::Table *dd_src_table) override
Method to resolve constraints type.
Definition: sql_constraint.cc:241
uint m_first_fixed_alter_constraint_pos
Definition: sql_constraint.h:258
Definition: key.h:112
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
Definition: table.h:46
bool drop(THD *thd, const Table *tp)
Remove SDI for a table.
Definition: sdi.cc:638
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
case opt name
Definition: sslopt-case.h:32
Definition: table.h:1394
unsigned int uint
Definition: uca-dump.cc:29