MySQL 5.6.14 Source Code Document
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
table_helper.cc
Go to the documentation of this file.
1
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
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 as published by
5
the Free Software Foundation; version 2 of the License.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15
21
#include "my_global.h"
22
#include "my_pthread.h"
23
#include "
pfs_engine_table.h
"
24
#include "
table_helper.h
"
25
#include "
pfs_host.h
"
26
#include "
pfs_user.h
"
27
#include "
pfs_account.h
"
28
29
int
PFS_host_row::make_row
(
PFS_host
*pfs)
30
{
31
m_hostname_length
= pfs->m_hostname_length;
32
if
(
m_hostname_length
>
sizeof
(
m_hostname
))
33
return
1;
34
if
(
m_hostname_length
> 0)
35
memcpy(
m_hostname
, pfs->m_hostname,
sizeof
(
m_hostname
));
36
return
0;
37
}
38
39
void
PFS_host_row::set_field
(
Field
*f)
40
{
41
if
(
m_hostname_length
> 0)
42
PFS_engine_table::set_field_char_utf8
(f,
m_hostname
,
m_hostname_length
);
43
else
44
f->set_null();
45
}
46
47
int
PFS_user_row::make_row
(
PFS_user
*pfs)
48
{
49
m_username_length
= pfs->m_username_length;
50
if
(
m_username_length
>
sizeof
(
m_username
))
51
return
1;
52
if
(
m_username_length
> 0)
53
memcpy(
m_username
, pfs->m_username,
sizeof
(
m_username
));
54
return
0;
55
}
56
57
void
PFS_user_row::set_field
(
Field
*f)
58
{
59
if
(
m_username_length
> 0)
60
PFS_engine_table::set_field_char_utf8
(f,
m_username
,
m_username_length
);
61
else
62
f->set_null();
63
}
64
65
int
PFS_account_row::make_row
(
PFS_account
*pfs)
66
{
67
m_username_length
= pfs->m_username_length;
68
if
(
m_username_length
>
sizeof
(
m_username
))
69
return
1;
70
if
(
m_username_length
> 0)
71
memcpy(
m_username
, pfs->m_username,
sizeof
(
m_username
));
72
73
m_hostname_length
= pfs->m_hostname_length;
74
if
(
m_hostname_length
>
sizeof
(
m_hostname
))
75
return
1;
76
if
(
m_hostname_length
> 0)
77
memcpy(
m_hostname
, pfs->m_hostname,
sizeof
(
m_hostname
));
78
79
return
0;
80
}
81
82
void
PFS_account_row::set_field
(uint
index
,
Field
*f)
83
{
84
switch
(index)
85
{
86
case
0:
/* USER */
87
if
(
m_username_length
> 0)
88
PFS_engine_table::set_field_char_utf8
(f,
m_username
,
m_username_length
);
89
else
90
f->set_null();
91
break
;
92
case
1:
/* HOST */
93
if
(
m_hostname_length
> 0)
94
PFS_engine_table::set_field_char_utf8
(f,
m_hostname
,
m_hostname_length
);
95
else
96
f->set_null();
97
break
;
98
default
:
99
DBUG_ASSERT(
false
);
100
break
;
101
}
102
}
103
104
int
PFS_digest_row::make_row
(
PFS_statements_digest_stat
* pfs)
105
{
106
m_schema_name_length
= pfs->
m_digest_key
.m_schema_name_length;
107
if
(
m_schema_name_length
>
sizeof
(
m_schema_name
))
108
m_schema_name_length
= 0;
109
if
(
m_schema_name_length
> 0)
110
memcpy(
m_schema_name
, pfs->
m_digest_key
.m_schema_name,
m_schema_name_length
);
111
112
int
safe_byte_count= pfs->
m_digest_storage
.m_byte_count;
113
if
(safe_byte_count > PSI_MAX_DIGEST_STORAGE_SIZE)
114
safe_byte_count= 0;
115
116
/*
117
"0" value for byte_count indicates special entry i.e. aggregated
118
stats at index 0 of statements_digest_stat_array. So do not calculate
119
digest/digest_text as it should always be "NULL".
120
*/
121
if
(safe_byte_count > 0)
122
{
123
/*
124
Calculate digest from MD5 HASH collected to be shown as
125
DIGEST in this row.
126
*/
127
MD5_HASH_TO_STRING(pfs->
m_digest_key
.m_md5,
m_digest
);
128
m_digest_length
= MD5_HASH_TO_STRING_LENGTH;
129
130
/*
131
Calculate digest_text information from the token array collected
132
to be shown as DIGEST_TEXT column.
133
*/
134
get_digest_text(
m_digest_text
, &pfs->
m_digest_storage
);
135
m_digest_text_length
= strlen(
m_digest_text
);
136
137
if
(
m_digest_text_length
== 0)
138
m_digest_length
= 0;
139
}
140
else
141
{
142
m_digest_length
= 0;
143
m_digest_text_length
= 0;
144
}
145
146
return
0;
147
}
148
149
void
PFS_digest_row::set_field
(uint
index
,
Field
*f)
150
{
151
switch
(index)
152
{
153
case
0:
/* SCHEMA_NAME */
154
if
(
m_schema_name_length
> 0)
155
PFS_engine_table::set_field_varchar_utf8
(f,
m_schema_name
,
156
m_schema_name_length
);
157
else
158
f->set_null();
159
break
;
160
case
1:
/* DIGEST */
161
if
(
m_digest_length
> 0)
162
PFS_engine_table::set_field_varchar_utf8
(f,
m_digest
,
163
m_digest_length
);
164
else
165
f->set_null();
166
break
;
167
case
2:
/* DIGEST_TEXT */
168
if
(
m_digest_text_length
> 0)
169
PFS_engine_table::set_field_longtext_utf8
(f,
m_digest_text
,
170
m_digest_text_length
);
171
else
172
f->set_null();
173
break
;
174
default
:
175
DBUG_ASSERT(
false
);
176
break
;
177
}
178
}
179
180
int
PFS_object_row::make_row
(
PFS_table_share
*pfs)
181
{
182
m_object_type
= pfs->get_object_type();
183
184
m_schema_name_length
= pfs->
m_schema_name_length
;
185
if
(
m_schema_name_length
>
sizeof
(
m_schema_name
))
186
return
1;
187
if
(
m_schema_name_length
> 0)
188
memcpy(
m_schema_name
, pfs->
m_schema_name
,
sizeof
(
m_schema_name
));
189
190
m_object_name_length
= pfs->
m_table_name_length
;
191
if
(
m_object_name_length
>
sizeof
(
m_object_name
))
192
return
1;
193
if
(
m_object_name_length
> 0)
194
memcpy(
m_object_name
, pfs->
m_table_name
,
sizeof
(
m_object_name
));
195
196
return
0;
197
}
198
199
void
PFS_object_row::set_field
(uint
index
,
Field
*f)
200
{
201
switch
(index)
202
{
203
case
0:
/* OBJECT_TYPE */
204
set_field_object_type(f,
m_object_type
);
205
break
;
206
case
1:
/* SCHEMA_NAME */
207
PFS_engine_table::set_field_varchar_utf8
(f,
m_schema_name
,
m_schema_name_length
);
208
break
;
209
case
2:
/* OBJECT_NAME */
210
PFS_engine_table::set_field_varchar_utf8
(f,
m_object_name
,
m_object_name_length
);
211
break
;
212
default
:
213
DBUG_ASSERT(
false
);
214
}
215
}
216
217
int
PFS_index_row::make_row
(
PFS_table_share
*pfs, uint table_index)
218
{
219
if
(m_object_row.
make_row
(pfs))
220
return
1;
221
222
if
(table_index < MAX_INDEXES)
223
{
224
PFS_table_key
*key= &pfs->
m_keys
[table_index];
225
m_index_name_length
= key->
m_name_length
;
226
if
(
m_index_name_length
>
sizeof
(
m_index_name
))
227
return
1;
228
memcpy(
m_index_name
, key->
m_name
,
sizeof
(
m_index_name
));
229
}
230
else
231
m_index_name_length
= 0;
232
233
return
0;
234
}
235
236
void
PFS_index_row::set_field
(uint
index
,
Field
*f)
237
{
238
switch
(index)
239
{
240
case
0:
/* OBJECT_TYPE */
241
case
1:
/* SCHEMA_NAME */
242
case
2:
/* OBJECT_NAME */
243
m_object_row.
set_field
(index, f);
244
break
;
245
case
3:
/* INDEX_NAME */
246
if
(
m_index_name_length
> 0)
247
PFS_engine_table::set_field_varchar_utf8
(f,
m_index_name
,
m_index_name_length
);
248
else
249
f->set_null();
250
break
;
251
default
:
252
DBUG_ASSERT(
false
);
253
}
254
}
255
256
void
PFS_statement_stat_row::set_field
(uint
index
,
Field
*f)
257
{
258
switch
(index)
259
{
260
case
0:
/* COUNT_STAR */
261
case
1:
/* SUM_TIMER_WAIT */
262
case
2:
/* MIN_TIMER_WAIT */
263
case
3:
/* AVG_TIMER_WAIT */
264
case
4:
/* MAX_TIMER_WAIT */
265
m_timer1_row.
set_field
(index, f);
266
break
;
267
case
5:
/* SUM_LOCK_TIME */
268
PFS_engine_table::set_field_ulonglong
(f, m_lock_time);
269
break
;
270
case
6:
/* SUM_ERRORS */
271
PFS_engine_table::set_field_ulonglong
(f, m_error_count);
272
break
;
273
case
7:
/* SUM_WARNINGS */
274
PFS_engine_table::set_field_ulonglong
(f, m_warning_count);
275
break
;
276
case
8:
/* SUM_ROWS_AFFECTED */
277
PFS_engine_table::set_field_ulonglong
(f, m_rows_affected);
278
break
;
279
case
9:
/* SUM_ROWS_SENT */
280
PFS_engine_table::set_field_ulonglong
(f, m_rows_sent);
281
break
;
282
case
10:
/* SUM_ROWS_EXAMINED */
283
PFS_engine_table::set_field_ulonglong
(f, m_rows_examined);
284
break
;
285
case
11:
/* SUM_CREATED_TMP_DISK_TABLES */
286
PFS_engine_table::set_field_ulonglong
(f, m_created_tmp_disk_tables);
287
break
;
288
case
12:
/* SUM_CREATED_TMP_TABLES */
289
PFS_engine_table::set_field_ulonglong
(f, m_created_tmp_tables);
290
break
;
291
case
13:
/* SUM_SELECT_FULL_JOIN */
292
PFS_engine_table::set_field_ulonglong
(f, m_select_full_join);
293
break
;
294
case
14:
/* SUM_SELECT_FULL_RANGE_JOIN */
295
PFS_engine_table::set_field_ulonglong
(f, m_select_full_range_join);
296
break
;
297
case
15:
/* SUM_SELECT_RANGE */
298
PFS_engine_table::set_field_ulonglong
(f, m_select_range);
299
break
;
300
case
16:
/* SUM_SELECT_RANGE_CHECK */
301
PFS_engine_table::set_field_ulonglong
(f, m_select_range_check);
302
break
;
303
case
17:
/* SUM_SELECT_SCAN */
304
PFS_engine_table::set_field_ulonglong
(f, m_select_scan);
305
break
;
306
case
18:
/* SUM_SORT_MERGE_PASSES */
307
PFS_engine_table::set_field_ulonglong
(f, m_sort_merge_passes);
308
break
;
309
case
19:
/* SUM_SORT_RANGE */
310
PFS_engine_table::set_field_ulonglong
(f, m_sort_range);
311
break
;
312
case
20:
/* SUM_SORT_ROWS */
313
PFS_engine_table::set_field_ulonglong
(f, m_sort_rows);
314
break
;
315
case
21:
/* SUM_SORT_SCAN */
316
PFS_engine_table::set_field_ulonglong
(f, m_sort_scan);
317
break
;
318
case
22:
/* SUM_NO_INDEX_USED */
319
PFS_engine_table::set_field_ulonglong
(f, m_no_index_used);
320
break
;
321
case
23:
/* SUM_NO_GOOD_INDEX_USED */
322
PFS_engine_table::set_field_ulonglong
(f, m_no_good_index_used);
323
break
;
324
default
:
325
DBUG_ASSERT(
false
);
326
break
;
327
}
328
}
329
330
void
PFS_connection_stat_row::set_field
(uint
index
,
Field
*f)
331
{
332
switch
(index)
333
{
334
case
0:
/* CURRENT_CONNECTIONS */
335
PFS_engine_table::set_field_ulonglong
(f, m_current_connections);
336
break
;
337
case
1:
/* TOTAL_CONNECTIONS */
338
PFS_engine_table::set_field_ulonglong
(f, m_total_connections);
339
break
;
340
default
:
341
DBUG_ASSERT(
false
);
342
break
;
343
}
344
}
345
346
void
set_field_object_type(
Field
*f,
enum_object_type
object_type)
347
{
348
switch
(object_type)
349
{
350
case
OBJECT_TYPE_TABLE:
351
PFS_engine_table::set_field_varchar_utf8
(f,
"TABLE"
, 5);
352
break
;
353
case
OBJECT_TYPE_TEMPORARY_TABLE:
354
PFS_engine_table::set_field_varchar_utf8
(f,
"TEMPORARY TABLE"
, 15);
355
break
;
356
default
:
357
DBUG_ASSERT(
false
);
358
}
359
}
360
storage
perfschema
table_helper.cc
Generated on Sat Nov 9 2013 01:28:41 for MySQL 5.6.14 Source Code Document by
1.8.1.2