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
|
/* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
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 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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
/**
@file storage/perfschema/table_helper.cc
Performance schema table helpers (implementation).
*/
#include "my_global.h"
#include "my_pthread.h"
#include "pfs_engine_table.h"
#include "table_helper.h"
#include "pfs_host.h"
#include "pfs_user.h"
#include "pfs_account.h"
#include "pfs_instr.h"
int PFS_host_row::make_row(PFS_host *pfs)
{
m_hostname_length= pfs->m_hostname_length;
if (m_hostname_length > sizeof(m_hostname))
return 1;
if (m_hostname_length > 0)
memcpy(m_hostname, pfs->m_hostname, sizeof(m_hostname));
return 0;
}
void PFS_host_row::set_field(Field *f)
{
if (m_hostname_length > 0)
PFS_engine_table::set_field_char_utf8(f, m_hostname, m_hostname_length);
else
f->set_null();
}
int PFS_user_row::make_row(PFS_user *pfs)
{
m_username_length= pfs->m_username_length;
if (m_username_length > sizeof(m_username))
return 1;
if (m_username_length > 0)
memcpy(m_username, pfs->m_username, sizeof(m_username));
return 0;
}
void PFS_user_row::set_field(Field *f)
{
if (m_username_length > 0)
PFS_engine_table::set_field_char_utf8(f, m_username, m_username_length);
else
f->set_null();
}
int PFS_account_row::make_row(PFS_account *pfs)
{
m_username_length= pfs->m_username_length;
if (m_username_length > sizeof(m_username))
return 1;
if (m_username_length > 0)
memcpy(m_username, pfs->m_username, sizeof(m_username));
m_hostname_length= pfs->m_hostname_length;
if (m_hostname_length > sizeof(m_hostname))
return 1;
if (m_hostname_length > 0)
memcpy(m_hostname, pfs->m_hostname, sizeof(m_hostname));
return 0;
}
void PFS_account_row::set_field(uint index, Field *f)
{
switch (index)
{
case 0: /* USER */
if (m_username_length > 0)
PFS_engine_table::set_field_char_utf8(f, m_username, m_username_length);
else
f->set_null();
break;
case 1: /* HOST */
if (m_hostname_length > 0)
PFS_engine_table::set_field_char_utf8(f, m_hostname, m_hostname_length);
else
f->set_null();
break;
default:
DBUG_ASSERT(false);
break;
}
}
int PFS_digest_row::make_row(PFS_statements_digest_stat* pfs)
{
m_schema_name_length= pfs->m_digest_key.m_schema_name_length;
if (m_schema_name_length > sizeof(m_schema_name))
m_schema_name_length= 0;
if (m_schema_name_length > 0)
memcpy(m_schema_name, pfs->m_digest_key.m_schema_name, m_schema_name_length);
size_t safe_byte_count= pfs->m_digest_storage.m_byte_count;
if (safe_byte_count > pfs_max_digest_length)
safe_byte_count= 0;
/*
"0" value for byte_count indicates special entry i.e. aggregated
stats at index 0 of statements_digest_stat_array. So do not calculate
digest/digest_text as it should always be "NULL".
*/
if (safe_byte_count > 0)
{
/*
Calculate digest from MD5 HASH collected to be shown as
DIGEST in this row.
*/
MD5_HASH_TO_STRING(pfs->m_digest_storage.m_md5, m_digest);
m_digest_length= MD5_HASH_TO_STRING_LENGTH;
/*
Calculate digest_text information from the token array collected
to be shown as DIGEST_TEXT column.
*/
compute_digest_text(&pfs->m_digest_storage, &m_digest_text);
if (m_digest_text.length() == 0)
m_digest_length= 0;
}
else
{
m_digest_length= 0;
m_digest_text.length(0);
}
return 0;
}
void PFS_digest_row::set_field(uint index, Field *f)
{
switch (index)
{
case 0: /* SCHEMA_NAME */
if (m_schema_name_length > 0)
PFS_engine_table::set_field_varchar_utf8(f, m_schema_name,
m_schema_name_length);
else
f->set_null();
break;
case 1: /* DIGEST */
if (m_digest_length > 0)
PFS_engine_table::set_field_varchar_utf8(f, m_digest,
m_digest_length);
else
f->set_null();
break;
case 2: /* DIGEST_TEXT */
if (m_digest_text.length() > 0)
PFS_engine_table::set_field_longtext_utf8(f, m_digest_text.ptr(),
m_digest_text.length());
else
f->set_null();
break;
default:
DBUG_ASSERT(false);
break;
}
}
int PFS_object_row::make_row(PFS_table_share *pfs)
{
m_object_type= pfs->get_object_type();
m_schema_name_length= pfs->m_schema_name_length;
if (m_schema_name_length > sizeof(m_schema_name))
return 1;
if (m_schema_name_length > 0)
memcpy(m_schema_name, pfs->m_schema_name, sizeof(m_schema_name));
m_object_name_length= pfs->m_table_name_length;
if (m_object_name_length > sizeof(m_object_name))
return 1;
if (m_object_name_length > 0)
memcpy(m_object_name, pfs->m_table_name, sizeof(m_object_name));
return 0;
}
void PFS_object_row::set_field(uint index, Field *f)
{
switch(index)
{
case 0: /* OBJECT_TYPE */
set_field_object_type(f, m_object_type);
break;
case 1: /* SCHEMA_NAME */
PFS_engine_table::set_field_varchar_utf8(f, m_schema_name, m_schema_name_length);
break;
case 2: /* OBJECT_NAME */
PFS_engine_table::set_field_varchar_utf8(f, m_object_name, m_object_name_length);
break;
default:
DBUG_ASSERT(false);
}
}
int PFS_index_row::make_row(PFS_table_share *pfs, uint table_index)
{
if (m_object_row.make_row(pfs))
return 1;
if (table_index < MAX_INDEXES)
{
PFS_table_key *key= &pfs->m_keys[table_index];
m_index_name_length= key->m_name_length;
if (m_index_name_length > sizeof(m_index_name))
return 1;
memcpy(m_index_name, key->m_name, sizeof(m_index_name));
}
else
m_index_name_length= 0;
return 0;
}
void PFS_index_row::set_field(uint index, Field *f)
{
switch(index)
{
case 0: /* OBJECT_TYPE */
case 1: /* SCHEMA_NAME */
case 2: /* OBJECT_NAME */
m_object_row.set_field(index, f);
break;
case 3: /* INDEX_NAME */
if (m_index_name_length > 0)
PFS_engine_table::set_field_varchar_utf8(f, m_index_name, m_index_name_length);
else
f->set_null();
break;
default:
DBUG_ASSERT(false);
}
}
void PFS_statement_stat_row::set_field(uint index, Field *f)
{
switch (index)
{
case 0: /* COUNT_STAR */
case 1: /* SUM_TIMER_WAIT */
case 2: /* MIN_TIMER_WAIT */
case 3: /* AVG_TIMER_WAIT */
case 4: /* MAX_TIMER_WAIT */
m_timer1_row.set_field(index, f);
break;
case 5: /* SUM_LOCK_TIME */
PFS_engine_table::set_field_ulonglong(f, m_lock_time);
break;
case 6: /* SUM_ERRORS */
PFS_engine_table::set_field_ulonglong(f, m_error_count);
break;
case 7: /* SUM_WARNINGS */
PFS_engine_table::set_field_ulonglong(f, m_warning_count);
break;
case 8: /* SUM_ROWS_AFFECTED */
PFS_engine_table::set_field_ulonglong(f, m_rows_affected);
break;
case 9: /* SUM_ROWS_SENT */
PFS_engine_table::set_field_ulonglong(f, m_rows_sent);
break;
case 10: /* SUM_ROWS_EXAMINED */
PFS_engine_table::set_field_ulonglong(f, m_rows_examined);
break;
case 11: /* SUM_CREATED_TMP_DISK_TABLES */
PFS_engine_table::set_field_ulonglong(f, m_created_tmp_disk_tables);
break;
case 12: /* SUM_CREATED_TMP_TABLES */
PFS_engine_table::set_field_ulonglong(f, m_created_tmp_tables);
break;
case 13: /* SUM_SELECT_FULL_JOIN */
PFS_engine_table::set_field_ulonglong(f, m_select_full_join);
break;
case 14: /* SUM_SELECT_FULL_RANGE_JOIN */
PFS_engine_table::set_field_ulonglong(f, m_select_full_range_join);
break;
case 15: /* SUM_SELECT_RANGE */
PFS_engine_table::set_field_ulonglong(f, m_select_range);
break;
case 16: /* SUM_SELECT_RANGE_CHECK */
PFS_engine_table::set_field_ulonglong(f, m_select_range_check);
break;
case 17: /* SUM_SELECT_SCAN */
PFS_engine_table::set_field_ulonglong(f, m_select_scan);
break;
case 18: /* SUM_SORT_MERGE_PASSES */
PFS_engine_table::set_field_ulonglong(f, m_sort_merge_passes);
break;
case 19: /* SUM_SORT_RANGE */
PFS_engine_table::set_field_ulonglong(f, m_sort_range);
break;
case 20: /* SUM_SORT_ROWS */
PFS_engine_table::set_field_ulonglong(f, m_sort_rows);
break;
case 21: /* SUM_SORT_SCAN */
PFS_engine_table::set_field_ulonglong(f, m_sort_scan);
break;
case 22: /* SUM_NO_INDEX_USED */
PFS_engine_table::set_field_ulonglong(f, m_no_index_used);
break;
case 23: /* SUM_NO_GOOD_INDEX_USED */
PFS_engine_table::set_field_ulonglong(f, m_no_good_index_used);
break;
default:
DBUG_ASSERT(false);
break;
}
}
void PFS_connection_stat_row::set_field(uint index, Field *f)
{
switch (index)
{
case 0: /* CURRENT_CONNECTIONS */
PFS_engine_table::set_field_ulonglong(f, m_current_connections);
break;
case 1: /* TOTAL_CONNECTIONS */
PFS_engine_table::set_field_ulonglong(f, m_total_connections);
break;
default:
DBUG_ASSERT(false);
break;
}
}
void set_field_object_type(Field *f, enum_object_type object_type)
{
switch (object_type)
{
case OBJECT_TYPE_TABLE:
PFS_engine_table::set_field_varchar_utf8(f, "TABLE", 5);
break;
case OBJECT_TYPE_TEMPORARY_TABLE:
PFS_engine_table::set_field_varchar_utf8(f, "TEMPORARY TABLE", 15);
break;
default:
DBUG_ASSERT(false);
}
}
|