MySQL  8.0.18
Source Code Documentation
table.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2019, 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 DD__TABLE_INCLUDED
24 #define DD__TABLE_INCLUDED
25 
26 #include "sql/dd/sdi_fwd.h" // Sdi_wcontext
27 #include "sql/dd/types/abstract_table.h" // dd::Abstract_table
28 #include "sql/dd/types/foreign_key.h" // IWYU pragma: keep
29 #include "sql/dd/types/index.h" // IWYU pragma: keep
30 #include "sql/dd/types/trigger.h" // dd::Trigger::enum_*
31 
32 namespace dd {
33 
34 ///////////////////////////////////////////////////////////////////////////
35 
36 class Check_constraint;
37 class Partition;
38 class Table_impl;
39 class Trigger;
40 
41 ///////////////////////////////////////////////////////////////////////////
42 
43 class Table : virtual public Abstract_table {
44  public:
45  typedef Table_impl Impl;
48  typedef std::vector<Foreign_key_parent *> Foreign_key_parent_collection;
52 
53  /*
54  The type Partition_collection object 'own' the Partition* object. That
55  means that the object Partition* would be deleted when the
56  Partition_collection is deleted. However the Partition_leaf_vector type
57  does not 'own' the Partition* object and points to one of element
58  owned by Partition_collection. Deleting Partition_leaf_vector will not
59  delete the Partition* objects pointed by it.
60  */
61  typedef std::vector<Partition *> Partition_leaf_vector;
62 
63  // We need a set of functions to update a preallocated se private id key,
64  // which requires special handling for table objects.
65  virtual bool update_aux_key(Aux_key *key) const {
66  return update_aux_key(key, engine(), se_private_id());
67  }
68 
69  static bool update_aux_key(Aux_key *key, const String_type &engine,
71 
72  public:
73  virtual ~Table() {}
74 
75  public:
77  RF_FIXED = 1,
83  };
84 
85  /* Keep in sync with subpartition type for forward compatibility.*/
87  PT_NONE = 0,
100  };
101 
103  ST_NONE = 0,
110  };
111 
112  /* Also used for default subpartitioning. */
114 
115  public:
116  /////////////////////////////////////////////////////////////////////////
117  // is_temporary.
118  /////////////////////////////////////////////////////////////////////////
119 
120  virtual bool is_temporary() const = 0;
121  virtual void set_is_temporary(bool is_temporary) = 0;
122 
123  /////////////////////////////////////////////////////////////////////////
124  // collation.
125  /////////////////////////////////////////////////////////////////////////
126 
127  virtual Object_id collation_id() const = 0;
128  virtual void set_collation_id(Object_id collation_id) = 0;
129 
130  /////////////////////////////////////////////////////////////////////////
131  // tablespace.
132  /////////////////////////////////////////////////////////////////////////
133 
134  virtual Object_id tablespace_id() const = 0;
135  virtual void set_tablespace_id(Object_id tablespace_id) = 0;
136  virtual bool is_explicit_tablespace() const = 0;
137 
138  /////////////////////////////////////////////////////////////////////////
139  // engine.
140  /////////////////////////////////////////////////////////////////////////
141 
142  virtual const String_type &engine() const = 0;
143  virtual void set_engine(const String_type &engine) = 0;
144 
145  /////////////////////////////////////////////////////////////////////////
146  // row_format
147  /////////////////////////////////////////////////////////////////////////
148  virtual enum_row_format row_format() const = 0;
149  virtual void set_row_format(enum_row_format row_format) = 0;
150 
151  /////////////////////////////////////////////////////////////////////////
152  // comment
153  /////////////////////////////////////////////////////////////////////////
154 
155  virtual const String_type &comment() const = 0;
156  virtual void set_comment(const String_type &comment) = 0;
157 
158  /////////////////////////////////////////////////////////////////////////
159  // last_checked_for_upgrade_version_id api
160  /////////////////////////////////////////////////////////////////////////
161 
162  virtual bool is_checked_for_upgrade() const = 0;
163  virtual void mark_as_checked_for_upgrade() = 0;
164 
165  /////////////////////////////////////////////////////////////////////////
166  // se_private_data.
167  /////////////////////////////////////////////////////////////////////////
168 
169  virtual const Properties &se_private_data() const = 0;
170 
171  virtual Properties &se_private_data() = 0;
172  virtual bool set_se_private_data(const String_type &se_private_data_raw) = 0;
173  virtual bool set_se_private_data(const Properties &se_private_data) = 0;
174 
175  /////////////////////////////////////////////////////////////////////////
176  // se_private_id.
177  /////////////////////////////////////////////////////////////////////////
178 
179  virtual Object_id se_private_id() const = 0;
180  virtual void set_se_private_id(Object_id se_private_id) = 0;
181 
182  /////////////////////////////////////////////////////////////////////////
183  // Partition related.
184  /////////////////////////////////////////////////////////////////////////
185 
186  virtual enum_partition_type partition_type() const = 0;
188 
190  virtual void set_default_partitioning(
192 
193  virtual const String_type &partition_expression() const = 0;
194  virtual void set_partition_expression(
195  const String_type &partition_expression) = 0;
196 
197  virtual const String_type &partition_expression_utf8() const = 0;
198  virtual void set_partition_expression_utf8(
199  const String_type &partition_expression) = 0;
200 
201  virtual enum_subpartition_type subpartition_type() const = 0;
202  virtual void set_subpartition_type(
204 
206  virtual void set_default_subpartitioning(
208 
209  virtual const String_type &subpartition_expression() const = 0;
210  virtual void set_subpartition_expression(
212 
213  virtual const String_type &subpartition_expression_utf8() const = 0;
216 
217  /** Dummy method to be able to use Partition and Table interchangeably
218  in templates. */
219  const Table &table() const { return *this; }
220  Table &table() { return *this; }
221 
222  /////////////////////////////////////////////////////////////////////////
223  // Index collection.
224  /////////////////////////////////////////////////////////////////////////
225 
226  virtual Index *add_index() = 0;
227 
228  virtual Index *add_first_index() = 0;
229 
230  virtual const Index_collection &indexes() const = 0;
231 
232  virtual Index_collection *indexes() = 0;
233 
234  /////////////////////////////////////////////////////////////////////////
235  // Foreign key collection.
236  /////////////////////////////////////////////////////////////////////////
237 
238  virtual Foreign_key *add_foreign_key() = 0;
239 
240  virtual const Foreign_key_collection &foreign_keys() const = 0;
241 
242  virtual Foreign_key_collection *foreign_keys() = 0;
243 
244  /////////////////////////////////////////////////////////////////////////
245  // Foreign key parent collection.
246  /////////////////////////////////////////////////////////////////////////
247 
248  // The Foreign_key_parent_collection represents a list of tables that
249  // have a foreign key referencing this table. It is constructed when
250  // the dd::Table object is fetched from disk, and it can be reloaded
251  // from the DD tables on demand using 'reload_foreign_key_parents()'.
252 
253  virtual const Foreign_key_parent_collection &foreign_key_parents() const = 0;
254 
255  virtual bool reload_foreign_key_parents(THD *thd) = 0;
256 
257  /////////////////////////////////////////////////////////////////////////
258  // Partition collection.
259  /////////////////////////////////////////////////////////////////////////
260 
261  virtual Partition *add_partition() = 0;
262 
263  virtual const Partition_collection &partitions() const = 0;
264 
265  virtual Partition_collection *partitions() = 0;
266 
267  /*
268  This API to list only the leaf partition entries of a table. This depicts
269  the real physical partitions. In case of table with no sub-partitions,
270  this API returns list of all partitions. In case of table with
271  sub-partitions, the API lists only the sub-partition entries.
272 
273  @return Partition_leaf_vector - List of pointers to dd::Partition objects.
274  */
275  virtual const Partition_leaf_vector &leaf_partitions() const = 0;
276 
277  virtual Partition_leaf_vector *leaf_partitions() = 0;
278 
279  /////////////////////////////////////////////////////////////////////////
280  // Trigger collection.
281  /////////////////////////////////////////////////////////////////////////
282 
283  /**
284  Check if table has any triggers.
285 
286  @return true - if there are triggers on the table installed.
287  @return false - if not.
288  */
289 
290  virtual bool has_trigger() const = 0;
291 
292  /**
293  Get const reference to Trigger_collection.
294 
295  @return Trigger_collection& - Const reference to a collection of triggers.
296  */
297 
298  virtual const Trigger_collection &triggers() const = 0;
299 
300  /**
301  Get non-const pointer to Trigger_collection.
302 
303  @return Trigger_collection* - Pointer to collection of triggers.
304  */
305 
306  virtual Trigger_collection *triggers() = 0;
307 
308  /**
309  Copy all the triggers from another dd::Table object.
310 
311  @param tab_obj Pointer to Table from which the triggers are copied.
312  */
313 
314  virtual void copy_triggers(const Table *tab_obj) = 0;
315 
316  /**
317  Add new trigger to the table.
318 
319  @param at - Action timing of the trigger to be added.
320  @param et - Event type of the trigger to be added.
321 
322  @return Trigger* - Pointer to new Trigger that is added to table.
323  */
324 
326  Trigger::enum_event_type et) = 0;
327 
328  /**
329  Get dd::Trigger object for the given trigger name.
330 
331  @return Trigger* - Pointer to Trigger.
332  */
333 
334  virtual const Trigger *get_trigger(const char *name) const = 0;
335 
336  /**
337  Add new trigger just after the trigger specified in argument.
338 
339  @param trigger - dd::Trigger object after which the new
340  trigger should be created.
341  @param at - Action timing of the trigger to be added.
342  @param et - Event type of the trigger to be added.
343 
344  @return Trigger* - Pointer to newly created dd::Trigger object.
345  */
346 
347  virtual Trigger *add_trigger_following(const Trigger *trigger,
349  Trigger::enum_event_type et) = 0;
350 
351  /**
352  Add new trigger just before the trigger specified in argument.
353 
354  @param trigger - dd::Trigger object before which the new
355  trigger should be created.
356  @param at - Action timing of the trigger to be added.
357  @param et - Event type of the trigger to be added.
358 
359  @return Trigger* - Pointer to newly created dd::Trigger object.
360  */
361 
362  virtual Trigger *add_trigger_preceding(const Trigger *trigger,
364  Trigger::enum_event_type et) = 0;
365 
366  /**
367  Drop the given trigger object.
368 
369  The method returns void, as we just remove the trigger from
370  dd::Collection (dd::Table_impl::m_triggers) in memory. The
371  trigger will be removed from mysql.triggers DD table when the
372  dd::Table object is stored/updated.
373 
374  @param trigger - dd::Trigger object to be dropped.
375  */
376 
377  virtual void drop_trigger(const Trigger *trigger) = 0;
378 
379  /**
380  Drop all the trigger on this dd::Table object.
381 
382  The method returns void, as we just remove the trigger from
383  dd::Collection (dd::Table_impl::m_triggers) in memory. The
384  trigger will be removed from mysql.triggers DD table when the
385  dd::Table object is stored/updated.
386  */
387 
388  virtual void drop_all_triggers() = 0;
389 
390  /////////////////////////////////////////////////////////////////////////
391  // Check constraint collection.
392  /////////////////////////////////////////////////////////////////////////
393 
394  virtual Check_constraint *add_check_constraint() = 0;
395 
396  virtual const Check_constraint_collection &check_constraints() const = 0;
397 
399 
400  public:
401  /**
402  Allocate a new object graph and invoke the copy contructor for
403  each object.
404 
405  @return pointer to dynamically allocated copy
406  */
407  virtual Table *clone() const = 0;
408 
409  /**
410  Converts *this into json.
411 
412  Converts all member variables that are to be included in the sdi
413  into json by transforming them appropriately and passing them to
414  the rapidjson writer provided.
415 
416  @param wctx opaque context for data needed by serialization
417  @param w rapidjson writer which will perform conversion to json
418 
419  */
420 
421  virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
422 
423  /**
424  Re-establishes the state of *this by reading sdi information from
425  the rapidjson DOM subobject provided.
426 
427  Cross-references encountered within this object are tracked in
428  sdictx, so that they can be updated when the entire object graph
429  has been established.
430 
431  @param rctx stores book-keeping information for the
432  deserialization process
433  @param val subobject of rapidjson DOM containing json
434  representation of this object
435  */
436 
437  virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
438 };
439 
440 ///////////////////////////////////////////////////////////////////////////
441 
442 } // namespace dd
443 
444 #endif // DD__TABLE_INCLUDED
Definition: table_impl.h:66
Definition: table.h:93
virtual Partition * add_partition()=0
Definition: table.h:113
virtual const Trigger_collection & triggers() const =0
Get const reference to Trigger_collection.
Definition: partition.h:50
Definition: table.h:99
Collection< Foreign_key * > Foreign_key_collection
Definition: table.h:47
virtual const Properties & se_private_data() const =0
Definition: index.h:49
virtual void set_row_format(enum_row_format row_format)=0
Collection< Check_constraint * > Check_constraint_collection
Definition: table.h:51
virtual enum_default_partitioning default_partitioning() const =0
virtual ~Table()
Definition: table.h:73
virtual const String_type & subpartition_expression_utf8() const =0
virtual void set_default_subpartitioning(enum_default_partitioning default_subpartitioning)=0
virtual void set_partition_expression(const String_type &partition_expression)=0
virtual bool is_temporary() const =0
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
virtual Trigger * add_trigger(Trigger::enum_action_timing at, Trigger::enum_event_type et)=0
Add new trigger to the table.
virtual void set_subpartition_expression(const String_type &subpartition_expression)=0
Definition: object_keys.h:218
Definition: table.h:96
Definition: table.h:77
virtual enum_default_partitioning default_subpartitioning() const =0
Definition: table.h:91
virtual Object_id tablespace_id() const =0
This header provides Rapidjson Type Aliases.
virtual void set_subpartition_type(enum_subpartition_type subpartition_type)=0
virtual void set_se_private_id(Object_id se_private_id)=0
virtual void copy_triggers(const Table *tab_obj)=0
Copy all the triggers from another dd::Table object.
Collection< Partition * > Partition_collection
Definition: table.h:49
virtual enum_subpartition_type subpartition_type() const =0
Definition: table.h:105
virtual bool reload_foreign_key_parents(THD *thd)=0
std::vector< Partition * > Partition_leaf_vector
Definition: table.h:61
Definition: table.h:103
virtual const Foreign_key_collection & foreign_keys() const =0
Definition: table.h:80
partition_type
An enum and a struct to handle partitioning and subpartitioning.
Definition: partition_element.h:32
virtual Index * add_index()=0
virtual void set_collation_id(Object_id collation_id)=0
virtual enum_partition_type partition_type() const =0
Definition: table.h:98
virtual void set_subpartition_expression_utf8(const String_type &subpartition_expression)=0
enum_action_timing
Definition: trigger.h:60
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:126
virtual Table * clone() const =0
Allocate a new object graph and invoke the copy contructor for each object.
virtual void set_partition_expression_utf8(const String_type &partition_expression)=0
virtual const Partition_leaf_vector & leaf_partitions() const =0
virtual Object_id collation_id() const =0
virtual enum_row_format row_format() const =0
Definition: table.h:79
Collection< Trigger * > Trigger_collection
Definition: table.h:50
virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const =0
Converts *this into json.
Definition: check_constraint.h:41
virtual const String_type & name() const =0
Definition: table.h:92
virtual Object_id se_private_id() const =0
enum_row_format
Definition: table.h:76
virtual const String_type & comment() const =0
virtual const String_type & engine() const =0
virtual const Index_collection & indexes() const =0
virtual Check_constraint * add_check_constraint()=0
enum_event_type
Definition: trigger.h:58
virtual void set_default_partitioning(enum_default_partitioning default_partitioning)=0
virtual const Check_constraint_collection & check_constraints() const =0
virtual const Foreign_key_parent_collection & foreign_key_parents() const =0
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:48
virtual bool is_checked_for_upgrade() const =0
Definition: table.h:106
virtual const String_type & partition_expression_utf8() const =0
Definition: table.h:104
virtual Index * add_first_index()=0
Definition: table.h:90
const Table & table() const
Dummy method to be able to use Partition and Table interchangeably in templates.
Definition: table.h:219
Definition: table.h:108
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.
Collection< Index * > Index_collection
Definition: table.h:46
unsigned long long Object_id
Definition: object_id.h:30
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.
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
virtual bool is_explicit_tablespace() const =0
Class representing a Trigger in DD framework.
Definition: trigger.h:52
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...
Abstract base class for tables and views.
Definition: abstract_table.h:68
virtual const String_type & subpartition_expression() const =0
virtual const String_type & partition_expression() const =0
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:229
Definition: table.h:89
Definition: table.h:88
static const char * key
Definition: suite_stubs.c:14
virtual bool update_aux_key(Aux_key *key) const
Definition: table.h:65
std::vector< Foreign_key_parent * > Foreign_key_parent_collection
Definition: table.h:48
Definition: table.h:82
Table & table()
Definition: table.h:220
virtual void set_tablespace_id(Object_id tablespace_id)=0
virtual Foreign_key * add_foreign_key()=0
Definition: table.h:94
Definition: table.h:97
Definition: table.h:113
virtual const Partition_collection & partitions() const =0
virtual void set_comment(const String_type &comment)=0
virtual void set_engine(const String_type &engine)=0
virtual void drop_trigger(const Trigger *trigger)=0
Drop the given trigger object.
Definition: collection.h:45
Definition: table.h:81
virtual void drop_all_triggers()=0
Drop all the trigger on this dd::Table object.
virtual bool set_se_private_data(const String_type &se_private_data_raw)=0
virtual const Trigger * get_trigger(const char *name) const =0
Get dd::Trigger object for the given trigger name.
enum_partition_type
Definition: table.h:86
enum_subpartition_type
Definition: table.h:102
Definition: table.h:113
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:63
Definition: table.h:87
Definition: table.h:95
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
enum_default_partitioning
Definition: table.h:113
Se_private_id_key Aux_key
Definition: abstract_table.h:75
virtual void set_partition_type(enum_partition_type partition_type)=0
virtual void set_is_temporary(bool is_temporary)=0
This class represents a trigger object.
Definition: trigger.h:73
virtual bool has_trigger() const =0
Check if table has any triggers.
Definition: table.h:107
Definition: table.h:113
Definition: table.h:78
Definition: table.h:43
virtual void mark_as_checked_for_upgrade()=0
Definition: foreign_key.h:46
Table_impl Impl
Definition: table.h:45
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
Definition: table.h:109