-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathobject_table_impl.cc
More file actions
121 lines (99 loc) · 4.8 KB
/
object_table_impl.cc
File metadata and controls
121 lines (99 loc) · 4.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
/* Copyright (c) 2014, 2024, 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 */
#include <mysqld_error.h>
#include "sql/dd/impl/bootstrap/bootstrap_ctx.h" // DD_bootstrap_ctx
#include "sql/dd/impl/types/object_table_impl.h" // Object_table_impl
#include "sql/table.h"
namespace dd {
///////////////////////////////////////////////////////////////////////////
Object_table_impl::Object_table_impl()
: m_last_dd_version(0),
m_target_def(),
m_actual_present(false),
m_actual_def(),
m_hidden(true) {
m_target_def.add_option(static_cast<int>(Common_option::ENGINE), "ENGINE",
"ENGINE=INNODB");
m_target_def.add_option(static_cast<int>(Common_option::CHARSET), "CHARSET",
"DEFAULT CHARSET=utf8mb3");
m_target_def.add_option(static_cast<int>(Common_option::COLLATION),
"COLLATION", "COLLATE=utf8mb3_bin");
m_target_def.add_option(static_cast<int>(Common_option::ROW_FORMAT),
"ROW_FORMAT", "ROW_FORMAT=DYNAMIC");
m_target_def.add_option(static_cast<int>(Common_option::STATS_PERSISTENT),
"STATS_PERSISTENT", "STATS_PERSISTENT=0");
if (bootstrap::DD_bootstrap_ctx::instance().is_dd_encrypted()) {
m_target_def.add_option(static_cast<int>(Common_option::ENCRYPTION),
"ENCRYPTION", "ENCRYPTION='Y'");
}
m_target_def.add_option(
static_cast<int>(Common_option::TABLESPACE), "TABLESPACE",
String_type("TABLESPACE=") + String_type(MYSQL_TABLESPACE_NAME.str));
}
bool Object_table_impl::is_target_encrypted() const {
return m_target_def.has_option(static_cast<int>(Common_option::ENCRYPTION));
}
void Object_table_impl::unset_target_encrypted() const {
m_target_def.remove_option("ENCRYPTION");
}
void Object_table_impl::set_target_encrypted() const {
if (!m_target_def.has_option(static_cast<int>(Common_option::ENCRYPTION))) {
m_target_def.add_option(static_cast<int>(Common_option::ENCRYPTION),
"ENCRYPTION", "ENCRYPTION='Y'");
}
}
void Object_table_impl::set_actual_encrypted() const {
if (!m_actual_def.has_option(static_cast<int>(Common_option::ENCRYPTION))) {
m_actual_def.add_option(static_cast<int>(Common_option::ENCRYPTION),
"ENCRYPTION", "ENCRYPTION='Y'");
}
}
bool Object_table_impl::set_actual_table_definition(
const Properties &table_def_properties) const {
m_actual_present = true;
return m_actual_def.restore_from_properties(table_def_properties);
}
int Object_table_impl::field_number(int target_field_number,
const String_type &field_label) const {
/*
During upgrade, we must re-interpret the field number using the
field label. Otherwise, we use the target field number. Note that
for minor downgrade, we use the target field number directly since
only extensions are allowed.
*/
if (bootstrap::DD_bootstrap_ctx::instance().is_dd_upgrade())
return m_actual_def.field_number(field_label);
return target_field_number;
}
int Object_table_impl::field_number(const String_type &field_label) const {
/*
During upgrade, we must get the position of the field label from
the actual definition. Otherwise, we get the position from the
the target definition.
*/
if (bootstrap::DD_bootstrap_ctx::instance().is_dd_upgrade())
return m_actual_def.field_number(field_label);
return m_target_def.field_number(field_label);
}
///////////////////////////////////////////////////////////////////////////
Object_table *Object_table::create_object_table() {
return new (std::nothrow) Object_table_impl();
}
///////////////////////////////////////////////////////////////////////////
} // namespace dd