forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_impl.h
More file actions
628 lines (479 loc) · 20.8 KB
/
table_impl.h
File metadata and controls
628 lines (479 loc) · 20.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef DD__TABLE_IMPL_INCLUDED
#define DD__TABLE_IMPL_INCLUDED
#include <sys/types.h>
#include <memory>
#include <new>
#include <string>
#include "my_inttypes.h"
#include "mysql_version.h" // MYSQL_VERSION_ID
#include "sql/dd/impl/properties_impl.h"
#include "sql/dd/impl/raw/raw_record.h"
#include "sql/dd/impl/types/abstract_table_impl.h" // dd::Abstract_table_impl
#include "sql/dd/impl/types/entity_object_impl.h"
#include "sql/dd/impl/types/weak_object_impl.h"
#include "sql/dd/object_id.h"
#include "sql/dd/sdi_fwd.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/check_constraint.h" // dd::Check_constraint
#include "sql/dd/types/foreign_key.h" // dd::Foreign_key
#include "sql/dd/types/index.h" // dd::Index
#include "sql/dd/types/partition.h" // dd::Partition
#include "sql/dd/types/table.h" // dd:Table
#include "sql/dd/types/trigger.h" // dd::Trigger
#include "sql/strfunc.h"
namespace dd {
///////////////////////////////////////////////////////////////////////////
class Column;
class Foreign_key;
class Index;
class Object_table;
class Open_dictionary_tables_ctx;
class Partition;
class Properties;
class Sdi_rcontext;
class Sdi_wcontext;
class Trigger_impl;
class Weak_object;
class Object_table;
class Table_impl : public Abstract_table_impl, virtual public Table {
public:
Table_impl();
~Table_impl() override;
public:
/////////////////////////////////////////////////////////////////////////
// enum_table_type.
/////////////////////////////////////////////////////////////////////////
enum_table_type type() const override { return enum_table_type::BASE_TABLE; }
public:
static void register_tables(Open_dictionary_tables_ctx *otx);
bool validate() const override;
bool restore_children(Open_dictionary_tables_ctx *otx) override;
bool store_children(Open_dictionary_tables_ctx *otx) override;
bool drop_children(Open_dictionary_tables_ctx *otx) const override;
bool restore_attributes(const Raw_record &r) override;
bool store_attributes(Raw_record *r) override;
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
void debug_print(String_type &outb) const override;
private:
/**
Store the trigger object in DD table.
@param otx current Open_dictionary_tables_ctx
@returns
false on success.
true on failure.
*/
bool store_triggers(Open_dictionary_tables_ctx *otx);
public:
/////////////////////////////////////////////////////////////////////////
// is_temporary.
/////////////////////////////////////////////////////////////////////////
bool is_temporary() const override { return m_is_temporary; }
void set_is_temporary(bool is_temporary) override {
m_is_temporary = is_temporary;
}
/////////////////////////////////////////////////////////////////////////
// collation.
/////////////////////////////////////////////////////////////////////////
Object_id collation_id() const override { return m_collation_id; }
void set_collation_id(Object_id collation_id) override {
m_collation_id = collation_id;
}
/////////////////////////////////////////////////////////////////////////
// tablespace.
/////////////////////////////////////////////////////////////////////////
Object_id tablespace_id() const override { return m_tablespace_id; }
void set_tablespace_id(Object_id tablespace_id) override {
m_tablespace_id = tablespace_id;
}
bool is_explicit_tablespace() const override {
bool is_explicit = false;
if (options().exists("explicit_tablespace"))
options().get("explicit_tablespace", &is_explicit);
return is_explicit;
}
/////////////////////////////////////////////////////////////////////////
// engine.
/////////////////////////////////////////////////////////////////////////
const String_type &engine() const override { return m_engine; }
void set_engine(const String_type &engine) override { m_engine = engine; }
/////////////////////////////////////////////////////////////////////////
// row_format
/////////////////////////////////////////////////////////////////////////
enum_row_format row_format() const override { return m_row_format; }
void set_row_format(enum_row_format row_format) override {
m_row_format = row_format;
}
/////////////////////////////////////////////////////////////////////////
// comment
/////////////////////////////////////////////////////////////////////////
const String_type &comment() const override { return m_comment; }
void set_comment(const String_type &comment) override { m_comment = comment; }
/////////////////////////////////////////////////////////////////////////
// last_checked_for_upgrade_version_id
/////////////////////////////////////////////////////////////////////////
uint last_checked_for_upgrade_version_id() const override {
return m_last_checked_for_upgrade_version_id;
}
void mark_as_checked_for_upgrade() override {
m_last_checked_for_upgrade_version_id = MYSQL_VERSION_ID;
}
/////////////////////////////////////////////////////////////////////////
// se_private_data.
/////////////////////////////////////////////////////////////////////////
const Properties &se_private_data() const override {
return m_se_private_data;
}
Properties &se_private_data() override { return m_se_private_data; }
bool set_se_private_data(const String_type &se_private_data_raw) override {
return m_se_private_data.insert_values(se_private_data_raw);
}
bool set_se_private_data(const Properties &se_private_data) override {
return m_se_private_data.insert_values(se_private_data);
}
/////////////////////////////////////////////////////////////////////////
// se_private_id.
/////////////////////////////////////////////////////////////////////////
Object_id se_private_id() const override { return m_se_private_id; }
void set_se_private_id(Object_id se_private_id) override {
m_se_private_id = se_private_id;
}
/////////////////////////////////////////////////////////////////////////
// Storage engine attributes
/////////////////////////////////////////////////////////////////////////
LEX_CSTRING engine_attribute() const override {
return lex_cstring_handle(m_engine_attribute);
}
void set_engine_attribute(LEX_CSTRING a) override {
m_engine_attribute.assign(a.str, a.length);
}
LEX_CSTRING secondary_engine_attribute() const override {
return lex_cstring_handle(m_secondary_engine_attribute);
}
void set_secondary_engine_attribute(LEX_CSTRING a) override {
m_secondary_engine_attribute.assign(a.str, a.length);
}
/////////////////////////////////////////////////////////////////////////
// Partition type
/////////////////////////////////////////////////////////////////////////
enum_partition_type partition_type() const override {
return m_partition_type;
}
void set_partition_type(enum_partition_type partition_type) override {
m_partition_type = partition_type;
}
/////////////////////////////////////////////////////////////////////////
// default_partitioning
/////////////////////////////////////////////////////////////////////////
enum_default_partitioning default_partitioning() const override {
return m_default_partitioning;
}
void set_default_partitioning(
enum_default_partitioning default_partitioning) override {
m_default_partitioning = default_partitioning;
}
/////////////////////////////////////////////////////////////////////////
// partition_expression
/////////////////////////////////////////////////////////////////////////
const String_type &partition_expression() const override {
return m_partition_expression;
}
void set_partition_expression(
const String_type &partition_expression) override {
m_partition_expression = partition_expression;
}
/////////////////////////////////////////////////////////////////////////
// partition_expression_utf8
/////////////////////////////////////////////////////////////////////////
const String_type &partition_expression_utf8() const override {
return m_partition_expression_utf8;
}
void set_partition_expression_utf8(
const String_type &partition_expression_utf8) override {
m_partition_expression_utf8 = partition_expression_utf8;
}
/////////////////////////////////////////////////////////////////////////
// subpartition_type
/////////////////////////////////////////////////////////////////////////
enum_subpartition_type subpartition_type() const override {
return m_subpartition_type;
}
void set_subpartition_type(
enum_subpartition_type subpartition_type) override {
m_subpartition_type = subpartition_type;
}
/////////////////////////////////////////////////////////////////////////
// default_subpartitioning
/////////////////////////////////////////////////////////////////////////
enum_default_partitioning default_subpartitioning() const override {
return m_default_subpartitioning;
}
void set_default_subpartitioning(
enum_default_partitioning default_subpartitioning) override {
m_default_subpartitioning = default_subpartitioning;
}
/////////////////////////////////////////////////////////////////////////
// subpartition_expression
/////////////////////////////////////////////////////////////////////////
const String_type &subpartition_expression() const override {
return m_subpartition_expression;
}
void set_subpartition_expression(
const String_type &subpartition_expression) override {
m_subpartition_expression = subpartition_expression;
}
/////////////////////////////////////////////////////////////////////////
// subpartition_expression_utf8
/////////////////////////////////////////////////////////////////////////
const String_type &subpartition_expression_utf8() const override {
return m_subpartition_expression_utf8;
}
void set_subpartition_expression_utf8(
const String_type &subpartition_expression_utf8) override {
m_subpartition_expression_utf8 = subpartition_expression_utf8;
}
/////////////////////////////////////////////////////////////////////////
// Index collection.
/////////////////////////////////////////////////////////////////////////
Index *add_index() override;
Index *add_first_index() override;
const Index_collection &indexes() const override { return m_indexes; }
Index_collection *indexes() override { return &m_indexes; }
const Index *get_index(Object_id index_id) const {
return const_cast<Table_impl *>(this)->get_index(index_id);
}
Index *get_index(Object_id index_id);
/////////////////////////////////////////////////////////////////////////
// Foreign key collection.
/////////////////////////////////////////////////////////////////////////
Foreign_key *add_foreign_key() override;
const Foreign_key_collection &foreign_keys() const override {
return m_foreign_keys;
}
Foreign_key_collection *foreign_keys() override { return &m_foreign_keys; }
/////////////////////////////////////////////////////////////////////////
// Foreign key parent collection.
/////////////////////////////////////////////////////////////////////////
virtual Foreign_key_parent *add_foreign_key_parent();
private:
bool load_foreign_key_parents(Open_dictionary_tables_ctx *otx);
public:
bool reload_foreign_key_parents(THD *thd) override;
const Foreign_key_parent_collection &foreign_key_parents() const override {
return m_foreign_key_parents;
}
/////////////////////////////////////////////////////////////////////////
// Partition collection.
/////////////////////////////////////////////////////////////////////////
Partition *add_partition() override;
const Partition_collection &partitions() const override {
return m_partitions;
}
Partition_collection *partitions() override { return &m_partitions; }
const Partition_leaf_vector &leaf_partitions() const override {
return m_leaf_partitions;
}
Partition_leaf_vector *leaf_partitions() override {
return &m_leaf_partitions;
}
Partition *get_leaf_partition(const std::string &part_name) override;
const Partition *get_leaf_partition(
const std::string &part_name) const override;
// non-virtual
void add_leaf_partition(Partition *p) { m_leaf_partitions.push_back(p); }
const Partition *get_partition(Object_id partition_id) const {
return const_cast<Table_impl *>(this)->get_partition(partition_id);
}
Partition *get_partition(Object_id partition_id);
Partition *get_partition(const String_type &name);
// Fix "inherits ... via dominance" warnings
Entity_object_impl *impl() override { return Entity_object_impl::impl(); }
const Entity_object_impl *impl() const override {
return Entity_object_impl::impl();
}
Object_id id() const override { return Entity_object_impl::id(); }
bool is_persistent() const override {
return Entity_object_impl::is_persistent();
}
const String_type &name() const override {
return Entity_object_impl::name();
}
void set_name(const String_type &name) override {
Entity_object_impl::set_name(name);
}
Object_id schema_id() const override {
return Abstract_table_impl::schema_id();
}
void set_schema_id(Object_id schema_id) override {
Abstract_table_impl::set_schema_id(schema_id);
}
uint mysql_version_id() const override {
return Abstract_table_impl::mysql_version_id();
}
const Properties &options() const override {
return Abstract_table_impl::options();
}
Properties &options() override { return Abstract_table_impl::options(); }
bool set_options(const Properties &options) override {
return Abstract_table_impl::set_options(options);
}
bool set_options(const String_type &options_raw) override {
return Abstract_table_impl::set_options(options_raw);
}
ulonglong created(bool convert_time) const override {
return Abstract_table_impl::created(convert_time);
}
void set_created(ulonglong created) override {
Abstract_table_impl::set_created(created);
}
ulonglong last_altered(bool convert_time) const override {
return Abstract_table_impl::last_altered(convert_time);
}
void set_last_altered(ulonglong last_altered) override {
Abstract_table_impl::set_last_altered(last_altered);
}
Column *add_column() override { return Abstract_table_impl::add_column(); }
bool drop_column(const String_type &name) override {
return Abstract_table_impl::drop_column(name);
}
const Column_collection &columns() const override {
return Abstract_table_impl::columns();
}
Column_collection *columns() override {
return Abstract_table_impl::columns();
}
const Column *get_column(Object_id column_id) const {
return Abstract_table_impl::get_column(column_id);
}
Column *get_column(Object_id column_id) {
return Abstract_table_impl::get_column(column_id);
}
const Column *get_column(const String_type &name) const override {
return Abstract_table_impl::get_column(name);
}
Column *get_column(const String_type &name) {
return Abstract_table_impl::get_column(name);
}
bool update_aux_key(Aux_key *key) const override {
return Table::update_aux_key(key);
}
enum_hidden_type hidden() const override {
return Abstract_table_impl::hidden();
}
void set_hidden(enum_hidden_type hidden) override {
Abstract_table_impl::set_hidden(hidden);
}
/////////////////////////////////////////////////////////////////////////
// Trigger collection.
/////////////////////////////////////////////////////////////////////////
bool has_trigger() const override { return (m_triggers.size() > 0); }
const Trigger_collection &triggers() const override { return m_triggers; }
Trigger_collection *triggers() override { return &m_triggers; }
void copy_triggers(const Table *tab_obj) override;
Trigger *add_trigger(Trigger::enum_action_timing at,
Trigger::enum_event_type et) override;
const Trigger *get_trigger(const char *name) const override;
Trigger *add_trigger_following(const Trigger *trigger,
Trigger::enum_action_timing at,
Trigger::enum_event_type et) override;
Trigger *add_trigger_preceding(const Trigger *trigger,
Trigger::enum_action_timing at,
Trigger::enum_event_type et) override;
void drop_trigger(const Trigger *trigger) override;
void drop_all_triggers() override;
private:
uint get_max_action_order(Trigger::enum_action_timing at,
Trigger::enum_event_type et) const;
void reorder_action_order(Trigger::enum_action_timing at,
Trigger::enum_event_type et);
Trigger_impl *create_trigger();
public:
/////////////////////////////////////////////////////////////////////////
// Check constraints.
/////////////////////////////////////////////////////////////////////////
Check_constraint *add_check_constraint() override;
const Check_constraint_collection &check_constraints() const override {
return m_check_constraints;
}
Check_constraint_collection *check_constraints() override {
return &m_check_constraints;
}
private:
// Fields.
Object_id m_se_private_id;
String_type m_engine;
String_type m_comment;
// Setting this to 0 means that every table will be checked by CHECK
// TABLE FOR UPGRADE once, even if it was created in this version.
// If we instead initialize to MYSQL_VERSION_ID, it will only run
// CHECK TABLE FOR UPGRADE after a real upgrade.
uint m_last_checked_for_upgrade_version_id = 0;
Properties_impl m_se_private_data;
// SE-specific json attributes
dd::String_type m_engine_attribute;
dd::String_type m_secondary_engine_attribute;
enum_row_format m_row_format;
bool m_is_temporary;
// - Partitioning related fields.
enum_partition_type m_partition_type;
String_type m_partition_expression;
String_type m_partition_expression_utf8;
enum_default_partitioning m_default_partitioning;
enum_subpartition_type m_subpartition_type;
String_type m_subpartition_expression;
String_type m_subpartition_expression_utf8;
enum_default_partitioning m_default_subpartitioning;
// References to tightly-coupled objects.
Index_collection m_indexes;
Foreign_key_collection m_foreign_keys;
Foreign_key_parent_collection m_foreign_key_parents;
Partition_collection m_partitions;
Partition_leaf_vector m_leaf_partitions;
Trigger_collection m_triggers;
Check_constraint_collection m_check_constraints;
// References to other objects.
Object_id m_collation_id;
Object_id m_tablespace_id;
Table_impl(const Table_impl &src);
Table_impl *clone() const override { return new Table_impl(*this); }
// N.B.: returning dd::Table from this function might confuse MSVC
// compiler thanks to diamond inheritance.
Table_impl *clone_dropped_object_placeholder() const override {
/*
TODO: In future we might want to save even more memory and use separate
placeholder class implementing dd::Table interface instead of
Table_impl. Instances of such class can be several times smaller
than an empty Table_impl. It might make sense to do the same for
for some of other types as well.
*/
Table_impl *placeholder = new Table_impl();
placeholder->set_id(id());
placeholder->set_schema_id(schema_id());
placeholder->set_name(name());
placeholder->set_engine(engine());
placeholder->set_se_private_id(se_private_id());
return placeholder;
}
};
///////////////////////////////////////////////////////////////////////////
} // namespace dd
#endif // DD__TABLE_IMPL_INCLUDED