MySQL 8.0.29
Source Code Documentation
pfs_name.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 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 PFS_NAME_H
24#define PFS_NAME_H
25
26/**
27 @file storage/perfschema/pfs_name.h
28 Object names (declarations).
29*/
30
31#include "m_ctype.h"
32#include "my_hostname.h" // HOSTNAME_LENGTH
33#include "mysql_com.h" // NAME_LEN
34
35/* Not used yet. */
36#define ROLENAME_CHAR_LENGTH 32
37#define ROLENAME_LENGTH (ROLENAME_CHAR_LENGTH * SYSTEM_CHARSET_MBMAXLEN)
38
39struct CHARSET_INFO;
40class Field;
41
42template <int max_length>
44 public:
46
48 assert(other.m_length <= max_length);
49
50 if (0 < other.m_length && other.m_length <= max_length) {
51 m_length = other.m_length;
52 memcpy(m_data, other.m_data, m_length);
53 } else {
54 m_length = 0;
55 }
56 }
57
59 assert(other.m_length <= max_length);
60
61 if (0 < other.m_length && other.m_length <= max_length) {
62 m_length = other.m_length;
63 memcpy(m_data, other.m_data, m_length);
64 } else {
65 m_length = 0;
66 }
67 return *this;
68 }
69
70 void reset() { m_length = 0; }
71
72 void set(const char *str, size_t len) {
73 assert(len <= max_length);
74
75 if (0 < len && len <= max_length) {
76 m_length = len;
77 memcpy(m_data, str, len);
78 } else {
79 m_length = 0;
80 }
81 }
82
83 void casedn(const CHARSET_INFO *cs) {
84 /*
85 Conversion in place:
86 - the string is not NUL terminated.
87 - the result after conversion can be shorter.
88 */
89 char *data = reinterpret_cast<char *>(m_data);
90 m_length = cs->cset->casedn(cs, data, m_length, data, m_length);
91 assert(m_length <= max_length);
92 }
93
94 size_t length() const { return m_length; }
95
96 const char *ptr() const { return reinterpret_cast<const char *>(m_data); }
97
98 void hash(const CHARSET_INFO *cs, uint64 *nr1, uint64 *nr2) const {
99 cs->coll->hash_sort(cs, m_data, m_length, nr1, nr2);
100 }
101
102 int sort(const CHARSET_INFO *cs,
103 const PFS_any_name<max_length> *other) const {
104 int cmp;
105 cmp = my_strnncoll(cs, m_data, m_length, other->m_data, other->m_length);
106 return cmp;
107 }
108
109 uchar m_data[max_length];
110 size_t m_length;
111};
112
114 public:
115 void reset() { m_name.reset(); }
116
117 void set(const char *str, size_t len);
118
119 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(get_cs(), nr1, nr2); }
120
121 int sort(const PFS_schema_name *other) const {
122 return m_name.sort(get_cs(), &other->m_name);
123 }
124
125 size_t length() const { return m_name.length(); }
126 const char *ptr() const { return m_name.ptr(); }
127 const CHARSET_INFO *charset() const { return get_cs(); }
128
129 private:
130 static const CHARSET_INFO *get_cs();
132};
133
135 public:
136 void reset() { m_name.reset(); }
137
138 void set(const char *str, size_t len);
139
140 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(get_cs(), nr1, nr2); }
141
142 int sort(const PFS_table_name *other) const {
143 return m_name.sort(get_cs(), &other->m_name);
144 }
145
146 size_t length() const { return m_name.length(); }
147 const char *ptr() const { return m_name.ptr(); }
148 const CHARSET_INFO *charset() const { return get_cs(); }
149
150 private:
151 friend struct PFS_object_name;
152
153 static const CHARSET_INFO *get_cs();
155};
156
158 public:
159 void reset() { m_name.reset(); }
160
161 void set(const char *str, size_t len);
162
163 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(m_cs, nr1, nr2); }
164
165 int sort(const PFS_routine_name *other) const {
166 return m_name.sort(m_cs, &other->m_name);
167 }
168
169 size_t length() const { return m_name.length(); }
170 const char *ptr() const { return m_name.ptr(); }
171 const CHARSET_INFO *charset() const { return m_cs; }
172
173 private:
174 friend struct PFS_object_name;
175
176 static const CHARSET_INFO *m_cs;
178};
179
181 public:
182 void reset() { m_name.reset(); }
183
184 void set_as_table(const char *str, size_t len);
185 void set_as_routine(const char *str, size_t len);
186
187 void hash_as_table(uint64 *nr1, uint64 *nr2) const {
188 m_name.hash(PFS_table_name::get_cs(), nr1, nr2);
189 }
190
191 int sort_as_table(const PFS_object_name *other) const {
192 return m_name.sort(PFS_table_name::get_cs(), &other->m_name);
193 }
194
195 void hash_as_routine(uint64 *nr1, uint64 *nr2) const {
196 m_name.hash(PFS_routine_name::m_cs, nr1, nr2);
197 }
198
199 int sort_as_routine(const PFS_object_name *other) const {
200 return m_name.sort(PFS_routine_name::m_cs, &other->m_name);
201 }
202
204 m_name = other.m_name;
205 return *this;
206 }
207
209 m_name = other.m_name;
210 return *this;
211 }
212
213 size_t length() const { return m_name.length(); }
214 const char *ptr() const { return m_name.ptr(); }
215
216 private:
218};
219
221 public:
222 void reset() { m_name.reset(); }
223
224 void set(const char *str, size_t len);
225
226 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(m_cs, nr1, nr2); }
227
228 int sort(const PFS_user_name *other) const {
229 return m_name.sort(m_cs, &other->m_name);
230 }
231
232 size_t length() const { return m_name.length(); }
233 const char *ptr() const { return m_name.ptr(); }
234 const CHARSET_INFO *charset() const { return m_cs; }
235
236 private:
237 static const CHARSET_INFO *m_cs;
239};
240
242 public:
243 void reset() { m_name.reset(); }
244
245 void set(const char *str, size_t len);
246
247 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(m_cs, nr1, nr2); }
248
249 int sort(const PFS_host_name *other) const {
250 return m_name.sort(m_cs, &other->m_name);
251 }
252
253 size_t length() const { return m_name.length(); }
254 const char *ptr() const { return m_name.ptr(); }
255 const CHARSET_INFO *charset() const { return m_cs; }
256
257 private:
258 static const CHARSET_INFO *m_cs;
260};
261
263 public:
264 void reset() { m_name.reset(); }
265
266 void set(const char *str, size_t len);
267
268 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(m_cs, nr1, nr2); }
269
270 int sort(const PFS_role_name *other) const {
271 return m_name.sort(m_cs, &other->m_name);
272 }
273
274 size_t length() const { return m_name.length(); }
275 const char *ptr() const { return m_name.ptr(); }
276 const CHARSET_INFO *charset() const { return m_cs; }
277
278 private:
279 static const CHARSET_INFO *m_cs;
281};
282
284 public:
285 void reset() { m_name.reset(); }
286
287 void set(const char *str, size_t len);
288
289 void hash(uint64 *nr1, uint64 *nr2) const { m_name.hash(m_cs, nr1, nr2); }
290
291 int sort(const PFS_file_name *other) const {
292 return m_name.sort(m_cs, &other->m_name);
293 }
294
295 size_t length() const { return m_name.length(); }
296 const char *ptr() const { return m_name.ptr(); }
297 const CHARSET_INFO *charset() const { return m_cs; }
298
299 private:
300 static const CHARSET_INFO *m_cs;
302};
303
304#endif
Definition: field.h:573
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1064
A better implementation of the UNIX ctype(3) library.
#define my_strnncoll(s, a, b, c, d)
Definition: m_ctype.h:671
Common definition used by mysys, performance schema and server & client.
unsigned char uchar
Definition: my_inttypes.h:51
uint64_t uint64
Definition: my_inttypes.h:68
Common definition between mysql server & client.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1055
Definition: commit_order_queue.h:33
Definition: m_ctype.h:354
Definition: pfs_name.h:43
int sort(const CHARSET_INFO *cs, const PFS_any_name< max_length > *other) const
Definition: pfs_name.h:102
void reset()
Definition: pfs_name.h:70
size_t m_length
Definition: pfs_name.h:110
const char * ptr() const
Definition: pfs_name.h:96
void casedn(const CHARSET_INFO *cs)
Definition: pfs_name.h:83
void set(const char *str, size_t len)
Definition: pfs_name.h:72
PFS_any_name< max_length > & operator=(const PFS_any_name< max_length > &other)
Definition: pfs_name.h:58
size_t length() const
Definition: pfs_name.h:94
void hash(const CHARSET_INFO *cs, uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:98
uchar m_data[max_length]
Definition: pfs_name.h:109
Definition: pfs_name.h:283
void set(const char *str, size_t len)
Definition: pfs_name.cc:89
const CHARSET_INFO * charset() const
Definition: pfs_name.h:297
int sort(const PFS_file_name *other) const
Definition: pfs_name.h:291
const char * ptr() const
Definition: pfs_name.h:296
void reset()
Definition: pfs_name.h:285
static const CHARSET_INFO * m_cs
Definition: pfs_name.h:300
size_t length() const
Definition: pfs_name.h:295
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:289
PFS_any_name< FN_REFLEN > m_name
Definition: pfs_name.h:301
Definition: pfs_name.h:241
const CHARSET_INFO * charset() const
Definition: pfs_name.h:255
int sort(const PFS_host_name *other) const
Definition: pfs_name.h:249
PFS_any_name< HOSTNAME_LENGTH > m_name
Definition: pfs_name.h:259
const char * ptr() const
Definition: pfs_name.h:254
void reset()
Definition: pfs_name.h:243
void set(const char *str, size_t len)
Definition: pfs_name.cc:81
static const CHARSET_INFO * m_cs
Definition: pfs_name.h:258
size_t length() const
Definition: pfs_name.h:253
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:247
Definition: pfs_name.h:180
int sort_as_routine(const PFS_object_name *other) const
Definition: pfs_name.h:199
void reset()
Definition: pfs_name.h:182
PFS_any_name< NAME_LEN > m_name
Definition: pfs_name.h:217
const char * ptr() const
Definition: pfs_name.h:214
PFS_object_name & operator=(const PFS_routine_name &other)
Definition: pfs_name.h:203
void set_as_table(const char *str, size_t len)
Definition: pfs_name.cc:64
PFS_object_name & operator=(const PFS_table_name &other)
Definition: pfs_name.h:208
size_t length() const
Definition: pfs_name.h:213
int sort_as_table(const PFS_object_name *other) const
Definition: pfs_name.h:191
void set_as_routine(const char *str, size_t len)
Definition: pfs_name.cc:73
void hash_as_routine(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:195
void hash_as_table(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:187
Definition: pfs_name.h:262
PFS_any_name< ROLENAME_LENGTH > m_name
Definition: pfs_name.h:280
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:268
int sort(const PFS_role_name *other) const
Definition: pfs_name.h:270
size_t length() const
Definition: pfs_name.h:274
void set(const char *str, size_t len)
Definition: pfs_name.cc:85
static const CHARSET_INFO * m_cs
Definition: pfs_name.h:279
void reset()
Definition: pfs_name.h:264
const char * ptr() const
Definition: pfs_name.h:275
const CHARSET_INFO * charset() const
Definition: pfs_name.h:276
Definition: pfs_name.h:157
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:163
const CHARSET_INFO * charset() const
Definition: pfs_name.h:171
void reset()
Definition: pfs_name.h:159
size_t length() const
Definition: pfs_name.h:169
PFS_any_name< NAME_LEN > m_name
Definition: pfs_name.h:177
const char * ptr() const
Definition: pfs_name.h:170
int sort(const PFS_routine_name *other) const
Definition: pfs_name.h:165
void set(const char *str, size_t len)
Definition: pfs_name.cc:57
static const CHARSET_INFO * m_cs
Definition: pfs_name.h:176
Definition: pfs_name.h:113
size_t length() const
Definition: pfs_name.h:125
void set(const char *str, size_t len)
Definition: pfs_name.cc:33
static const CHARSET_INFO * get_cs()
Definition: pfs_name.cc:41
const CHARSET_INFO * charset() const
Definition: pfs_name.h:127
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:119
int sort(const PFS_schema_name *other) const
Definition: pfs_name.h:121
const char * ptr() const
Definition: pfs_name.h:126
void reset()
Definition: pfs_name.h:115
PFS_any_name< NAME_LEN > m_name
Definition: pfs_name.h:131
Definition: pfs_name.h:134
const CHARSET_INFO * charset() const
Definition: pfs_name.h:148
void reset()
Definition: pfs_name.h:136
PFS_any_name< NAME_LEN > m_name
Definition: pfs_name.h:154
const char * ptr() const
Definition: pfs_name.h:147
int sort(const PFS_table_name *other) const
Definition: pfs_name.h:142
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:140
void set(const char *str, size_t len)
Definition: pfs_name.cc:45
static const CHARSET_INFO * get_cs()
Definition: pfs_name.cc:53
size_t length() const
Definition: pfs_name.h:146
Definition: pfs_name.h:220
const char * ptr() const
Definition: pfs_name.h:233
size_t length() const
Definition: pfs_name.h:232
void set(const char *str, size_t len)
Definition: pfs_name.cc:77
void reset()
Definition: pfs_name.h:222
int sort(const PFS_user_name *other) const
Definition: pfs_name.h:228
static const CHARSET_INFO * m_cs
Definition: pfs_name.h:237
PFS_any_name< USERNAME_LENGTH > m_name
Definition: pfs_name.h:238
const CHARSET_INFO * charset() const
Definition: pfs_name.h:234
void hash(uint64 *nr1, uint64 *nr2) const
Definition: pfs_name.h:226