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