MySQL 9.0.0
Source Code Documentation
table.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__TABLE_INCLUDED
25#define DD__TABLE_INCLUDED
26
27#include "lex_string.h" // LEX_CSTRING
28#include "mysql_version.h" // MYSQL_VERSION_ID
29
30#include "sql/dd/sdi_fwd.h" // Sdi_wcontext
31#include "sql/dd/types/abstract_table.h" // dd::Abstract_table
32#include "sql/dd/types/foreign_key.h" // IWYU pragma: keep
33#include "sql/dd/types/index.h" // IWYU pragma: keep
34#include "sql/dd/types/trigger.h" // dd::Trigger::enum_*
35
36namespace dd {
37
38///////////////////////////////////////////////////////////////////////////
39
40class Check_constraint;
41class Partition;
42class Table_impl;
43class Trigger;
44
45///////////////////////////////////////////////////////////////////////////
46
47class Table : virtual public Abstract_table {
48 public:
52 typedef std::vector<Foreign_key_parent *> Foreign_key_parent_collection;
56
57 /*
58 The type Partition_collection object 'own' the Partition* object. That
59 means that the object Partition* would be deleted when the
60 Partition_collection is deleted. However the Partition_leaf_vector type
61 does not 'own' the Partition* object and points to one of element
62 owned by Partition_collection. Deleting Partition_leaf_vector will not
63 delete the Partition* objects pointed by it.
64 */
65 typedef std::vector<Partition *> Partition_leaf_vector;
66
67 // We need a set of functions to update a preallocated se private id key,
68 // which requires special handling for table objects.
69 bool update_aux_key(Aux_key *key) const override {
71 }
72
73 static bool update_aux_key(Aux_key *key, const String_type &engine,
75
76 public:
77 ~Table() override = default;
78
79 public:
87 };
88
89 /* Keep in sync with subpartition type for forward compatibility.*/
104 };
105
114 };
115
116 /* Also used for default subpartitioning. */
118
119 public:
120 /////////////////////////////////////////////////////////////////////////
121 // is_temporary.
122 /////////////////////////////////////////////////////////////////////////
123
124 virtual bool is_temporary() const = 0;
125 virtual void set_is_temporary(bool is_temporary) = 0;
126
127 /////////////////////////////////////////////////////////////////////////
128 // collation.
129 /////////////////////////////////////////////////////////////////////////
130
131 virtual Object_id collation_id() const = 0;
133
134 /////////////////////////////////////////////////////////////////////////
135 // tablespace.
136 /////////////////////////////////////////////////////////////////////////
137
138 virtual Object_id tablespace_id() const = 0;
140 virtual bool is_explicit_tablespace() const = 0;
141
142 /////////////////////////////////////////////////////////////////////////
143 // engine.
144 /////////////////////////////////////////////////////////////////////////
145
146 virtual const String_type &engine() const = 0;
147 virtual void set_engine(const String_type &engine) = 0;
148
149 /////////////////////////////////////////////////////////////////////////
150 // row_format
151 /////////////////////////////////////////////////////////////////////////
152 virtual enum_row_format row_format() const = 0;
154
155 /////////////////////////////////////////////////////////////////////////
156 // comment
157 /////////////////////////////////////////////////////////////////////////
158
159 virtual const String_type &comment() const = 0;
160 virtual void set_comment(const String_type &comment) = 0;
161
162 /////////////////////////////////////////////////////////////////////////
163 // last_checked_for_upgrade_version_id api
164 /////////////////////////////////////////////////////////////////////////
165
166 virtual uint last_checked_for_upgrade_version_id() const = 0;
167 virtual void mark_as_checked_for_upgrade() = 0;
168
169 /////////////////////////////////////////////////////////////////////////
170 // se_private_data.
171 /////////////////////////////////////////////////////////////////////////
172
173 virtual const Properties &se_private_data() const = 0;
174
176 virtual bool set_se_private_data(const String_type &se_private_data_raw) = 0;
178
179 /////////////////////////////////////////////////////////////////////////
180 // se_private_id.
181 /////////////////////////////////////////////////////////////////////////
182
183 virtual Object_id se_private_id() const = 0;
185
186 /////////////////////////////////////////////////////////////////////////
187 // SE-specific json attributes
188 /////////////////////////////////////////////////////////////////////////
189
190 virtual LEX_CSTRING engine_attribute() const = 0;
191 virtual void set_engine_attribute(LEX_CSTRING attrs) = 0;
192
195
196 /////////////////////////////////////////////////////////////////////////
197 // Partition related.
198 /////////////////////////////////////////////////////////////////////////
199
202
206
207 virtual const String_type &partition_expression() const = 0;
210
211 virtual const String_type &partition_expression_utf8() const = 0;
214
218
222
223 virtual const String_type &subpartition_expression() const = 0;
226
227 virtual const String_type &subpartition_expression_utf8() const = 0;
230
231 /** Dummy method to be able to use Partition and Table interchangeably
232 in templates. */
233 const Table &table() const { return *this; }
234 Table &table() { return *this; }
235
236 /////////////////////////////////////////////////////////////////////////
237 // Index collection.
238 /////////////////////////////////////////////////////////////////////////
239
240 virtual Index *add_index() = 0;
241
242 virtual Index *add_first_index() = 0;
243
244 virtual const Index_collection &indexes() const = 0;
245
246 virtual Index_collection *indexes() = 0;
247
248 /////////////////////////////////////////////////////////////////////////
249 // Foreign key collection.
250 /////////////////////////////////////////////////////////////////////////
251
253
254 virtual const Foreign_key_collection &foreign_keys() const = 0;
255
257
258 /////////////////////////////////////////////////////////////////////////
259 // Foreign key parent collection.
260 /////////////////////////////////////////////////////////////////////////
261
262 // The Foreign_key_parent_collection represents a list of tables that
263 // have a foreign key referencing this table. It is constructed when
264 // the dd::Table object is fetched from disk, and it can be reloaded
265 // from the DD tables on demand using 'reload_foreign_key_parents()'.
266
268
269 virtual bool reload_foreign_key_parents(THD *thd) = 0;
270
271 /////////////////////////////////////////////////////////////////////////
272 // Partition collection.
273 /////////////////////////////////////////////////////////////////////////
274
275 virtual Partition *add_partition() = 0;
276
277 virtual const Partition_collection &partitions() const = 0;
278
280
281 /*
282 This API to list only the leaf partition entries of a table. This depicts
283 the real physical partitions. In case of table with no sub-partitions,
284 this API returns list of all partitions. In case of table with
285 sub-partitions, the API lists only the sub-partition entries.
286
287 @return Partition_leaf_vector - List of pointers to dd::Partition objects.
288 */
289 virtual const Partition_leaf_vector &leaf_partitions() const = 0;
290
292
293 /////////////////////////////////////////////////////////////////////////
294 // Trigger collection.
295 /////////////////////////////////////////////////////////////////////////
296
297 /**
298 Check if table has any triggers.
299
300 @return true - if there are triggers on the table installed.
301 @return false - if not.
302 */
303
304 virtual bool has_trigger() const = 0;
305
306 /**
307 Get const reference to Trigger_collection.
308
309 @return Trigger_collection& - Const reference to a collection of triggers.
310 */
311
312 virtual const Trigger_collection &triggers() const = 0;
313
314 /**
315 Get non-const pointer to Trigger_collection.
316
317 @return Trigger_collection* - Pointer to collection of triggers.
318 */
319
321
322 /**
323 Copy all the triggers from another dd::Table object.
324
325 @param tab_obj Pointer to Table from which the triggers are copied.
326 */
327
328 virtual void copy_triggers(const Table *tab_obj) = 0;
329
330 /**
331 Add new trigger to the table.
332
333 @param at - Action timing of the trigger to be added.
334 @param et - Event type of the trigger to be added.
335
336 @return Trigger* - Pointer to new Trigger that is added to table.
337 */
338
341
342 /**
343 Get dd::Trigger object for the given trigger name.
344
345 @return Trigger* - Pointer to Trigger.
346 */
347
348 virtual const Trigger *get_trigger(const char *name) const = 0;
349
350 /**
351 Add new trigger just after the trigger specified in argument.
352
353 @param trigger - dd::Trigger object after which the new
354 trigger should be created.
355 @param at - Action timing of the trigger to be added.
356 @param et - Event type of the trigger to be added.
357
358 @return Trigger* - Pointer to newly created dd::Trigger object.
359 */
360
361 virtual Trigger *add_trigger_following(const Trigger *trigger,
364
365 /**
366 Add new trigger just before the trigger specified in argument.
367
368 @param trigger - dd::Trigger object before which the new
369 trigger should be created.
370 @param at - Action timing of the trigger to be added.
371 @param et - Event type of the trigger to be added.
372
373 @return Trigger* - Pointer to newly created dd::Trigger object.
374 */
375
376 virtual Trigger *add_trigger_preceding(const Trigger *trigger,
379
380 /**
381 Drop the given trigger object.
382
383 The method returns void, as we just remove the trigger from
384 dd::Collection (dd::Table_impl::m_triggers) in memory. The
385 trigger will be removed from mysql.triggers DD table when the
386 dd::Table object is stored/updated.
387
388 @param trigger - dd::Trigger object to be dropped.
389 */
390
391 virtual void drop_trigger(const Trigger *trigger) = 0;
392
393 /**
394 Drop all the trigger on this dd::Table object.
395
396 The method returns void, as we just remove the trigger from
397 dd::Collection (dd::Table_impl::m_triggers) in memory. The
398 trigger will be removed from mysql.triggers DD table when the
399 dd::Table object is stored/updated.
400 */
401
402 virtual void drop_all_triggers() = 0;
403
404 /////////////////////////////////////////////////////////////////////////
405 // Check constraint collection.
406 /////////////////////////////////////////////////////////////////////////
407
409
411
413
414 public:
415 /**
416 Allocate a new object graph and invoke the copy constructor for
417 each object.
418
419 @return pointer to dynamically allocated copy
420 */
421 Table *clone() const override = 0;
422
423 /**
424 Allocate a new object which can serve as a placeholder for the original
425 object in the Dictionary_client's dropped registry. Such object has the
426 same keys as the original but has no other info and as result occupies
427 less memory.
428 */
430
431 /**
432 Converts *this into json.
433
434 Converts all member variables that are to be included in the sdi
435 into json by transforming them appropriately and passing them to
436 the rapidjson writer provided.
437
438 @param wctx opaque context for data needed by serialization
439 @param w rapidjson writer which will perform conversion to json
440
441 */
442
443 virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
444
445 /**
446 Re-establishes the state of *this by reading sdi information from
447 the rapidjson DOM subobject provided.
448
449 Cross-references encountered within this object are tracked in
450 sdictx, so that they can be updated when the entire object graph
451 has been established.
452
453 @param rctx stores book-keeping information for the
454 deserialization process
455 @param val subobject of rapidjson DOM containing json
456 representation of this object
457 */
458
459 virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
460};
461
462///////////////////////////////////////////////////////////////////////////
463
464inline bool is_checked_for_upgrade(const Table &t) {
466}
467} // namespace dd
468
469#endif // DD__TABLE_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class represents a trigger object.
Definition: trigger.h:75
Abstract base class for tables and views.
Definition: abstract_table.h:69
Se_private_id_key Aux_key
Definition: abstract_table.h:76
Definition: check_constraint.h:42
Definition: collection.h:44
virtual const String_type & name() const =0
Definition: foreign_key.h:47
Definition: index.h:51
Definition: partition.h:51
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:74
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:231
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:129
Definition: object_keys.h:219
Definition: table_impl.h:68
Definition: table.h:47
virtual const Trigger * get_trigger(const char *name) const =0
Get dd::Trigger object for the given trigger name.
virtual const Partition_leaf_vector & leaf_partitions() const =0
virtual bool is_temporary() const =0
virtual Index_collection * indexes()=0
virtual const Index_collection & indexes() const =0
virtual Partition * add_partition()=0
virtual void copy_triggers(const Table *tab_obj)=0
Copy all the triggers from another dd::Table object.
virtual Index * add_first_index()=0
Collection< Trigger * > Trigger_collection
Definition: table.h:54
Table * clone_dropped_object_placeholder() const override=0
Allocate a new object which can serve as a placeholder for the original object in the Dictionary_clie...
virtual LEX_CSTRING engine_attribute() const =0
Collection< Check_constraint * > Check_constraint_collection
Definition: table.h:55
virtual Check_constraint_collection * check_constraints()=0
virtual void set_se_private_id(Object_id se_private_id)=0
virtual const Partition_collection & partitions() const =0
virtual enum_partition_type partition_type() const =0
virtual Partition_collection * partitions()=0
virtual Trigger * add_trigger_following(const Trigger *trigger, Trigger::enum_action_timing at, Trigger::enum_event_type et)=0
Add new trigger just after the trigger specified in argument.
virtual LEX_CSTRING secondary_engine_attribute() const =0
virtual void set_secondary_engine_attribute(LEX_CSTRING attrs)=0
std::vector< Foreign_key_parent * > Foreign_key_parent_collection
Definition: table.h:52
virtual Object_id tablespace_id() const =0
~Table() override=default
virtual const Check_constraint_collection & check_constraints() const =0
virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const =0
Converts *this into json.
std::vector< Partition * > Partition_leaf_vector
Definition: table.h:65
virtual void set_collation_id(Object_id collation_id)=0
virtual void set_subpartition_type(enum_subpartition_type subpartition_type)=0
virtual void mark_as_checked_for_upgrade()=0
virtual bool set_se_private_data(const String_type &se_private_data_raw)=0
Collection< Index * > Index_collection
Definition: table.h:50
virtual const Foreign_key_parent_collection & foreign_key_parents() const =0
virtual void set_default_subpartitioning(enum_default_partitioning default_subpartitioning)=0
virtual bool has_trigger() const =0
Check if table has any triggers.
virtual Object_id collation_id() const =0
virtual void set_subpartition_expression(const String_type &subpartition_expression)=0
enum_row_format
Definition: table.h:80
@ RF_COMPRESSED
Definition: table.h:83
@ RF_FIXED
Definition: table.h:81
@ RF_REDUNDANT
Definition: table.h:84
@ RF_DYNAMIC
Definition: table.h:82
@ RF_COMPACT
Definition: table.h:85
@ RF_PAGED
Definition: table.h:86
virtual const Trigger_collection & triggers() const =0
Get const reference to Trigger_collection.
virtual Partition_leaf_vector * leaf_partitions()=0
virtual void set_is_temporary(bool is_temporary)=0
virtual const Properties & se_private_data() const =0
virtual void set_engine(const String_type &engine)=0
virtual void set_subpartition_expression_utf8(const String_type &subpartition_expression)=0
virtual enum_subpartition_type subpartition_type() const =0
virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)=0
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
virtual Index * add_index()=0
virtual bool reload_foreign_key_parents(THD *thd)=0
virtual Trigger_collection * triggers()=0
Get non-const pointer to Trigger_collection.
virtual void set_engine_attribute(LEX_CSTRING attrs)=0
virtual void drop_trigger(const Trigger *trigger)=0
Drop the given trigger object.
virtual void set_partition_type(enum_partition_type partition_type)=0
virtual void set_partition_expression_utf8(const String_type &partition_expression)=0
virtual void set_default_partitioning(enum_default_partitioning default_partitioning)=0
virtual enum_row_format row_format() const =0
virtual const String_type & partition_expression() const =0
virtual const String_type & comment() const =0
virtual uint last_checked_for_upgrade_version_id() const =0
virtual bool set_se_private_data(const Properties &se_private_data)=0
virtual const String_type & subpartition_expression_utf8() const =0
virtual bool is_explicit_tablespace() const =0
Collection< Foreign_key * > Foreign_key_collection
Definition: table.h:51
Table * clone() const override=0
Allocate a new object graph and invoke the copy constructor for each object.
virtual const String_type & engine() const =0
virtual Properties & se_private_data()=0
Table & table()
Definition: table.h:234
virtual Trigger * add_trigger_preceding(const Trigger *trigger, Trigger::enum_action_timing at, Trigger::enum_event_type et)=0
Add new trigger just before the trigger specified in argument.
virtual void set_partition_expression(const String_type &partition_expression)=0
Collection< Partition * > Partition_collection
Definition: table.h:53
virtual enum_default_partitioning default_partitioning() const =0
enum_partition_type
Definition: table.h:90
@ PT_NONE
Definition: table.h:91
@ PT_LINEAR_HASH
Definition: table.h:95
@ PT_LINEAR_KEY_55
Definition: table.h:97
@ PT_RANGE
Definition: table.h:98
@ PT_KEY_55
Definition: table.h:94
@ PT_KEY_51
Definition: table.h:93
@ PT_AUTO_LINEAR
Definition: table.h:103
@ PT_RANGE_COLUMNS
Definition: table.h:100
@ PT_LIST
Definition: table.h:99
@ PT_LINEAR_KEY_51
Definition: table.h:96
@ PT_HASH
Definition: table.h:92
@ PT_LIST_COLUMNS
Definition: table.h:101
@ PT_AUTO
Definition: table.h:102
enum_subpartition_type
Definition: table.h:106
@ ST_NONE
Definition: table.h:107
@ ST_LINEAR_KEY_51
Definition: table.h:112
@ ST_LINEAR_HASH
Definition: table.h:111
@ ST_KEY_55
Definition: table.h:110
@ ST_HASH
Definition: table.h:108
@ ST_LINEAR_KEY_55
Definition: table.h:113
@ ST_KEY_51
Definition: table.h:109
virtual void set_row_format(enum_row_format row_format)=0
virtual const Foreign_key_collection & foreign_keys() const =0
Table_impl Impl
Definition: table.h:49
virtual Trigger * add_trigger(Trigger::enum_action_timing at, Trigger::enum_event_type et)=0
Add new trigger to the table.
virtual void set_comment(const String_type &comment)=0
virtual Foreign_key_collection * foreign_keys()=0
virtual void set_tablespace_id(Object_id tablespace_id)=0
virtual const String_type & partition_expression_utf8() const =0
virtual void drop_all_triggers()=0
Drop all the trigger on this dd::Table object.
virtual Object_id se_private_id() const =0
bool update_aux_key(Aux_key *key) const override
Definition: table.h:69
virtual Foreign_key * add_foreign_key()=0
virtual Check_constraint * add_check_constraint()=0
enum_default_partitioning
Definition: table.h:117
@ DP_NO
Definition: table.h:117
@ DP_NONE
Definition: table.h:117
@ DP_NUMBER
Definition: table.h:117
@ DP_YES
Definition: table.h:117
virtual enum_default_partitioning default_subpartitioning() const =0
const Table & table() const
Dummy method to be able to use Partition and Table interchangeably in templates.
Definition: table.h:233
virtual const String_type & subpartition_expression() const =0
Class representing a Trigger in DD framework.
Definition: trigger.h:54
enum_event_type
Definition: trigger.h:60
enum_action_timing
Definition: trigger.h:62
#define MYSQL_VERSION_ID
Definition: mysql_version.h:15
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:64
unsigned long long Object_id
Definition: object_id.h:31
bool is_checked_for_upgrade(const Table &t)
Definition: table.h:464
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:49
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
partition_type
An enum and a struct to handle partitioning and subpartitioning.
Definition: partition_element.h:33
required string key
Definition: replication_asynchronous_connection_failover.proto:60
This header provides Rapidjson Type Aliases.
Definition: mysql_lex_string.h:40