MySQL 5.6.14 Source Code Document
 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 
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 
40 {
41  if (m_hostname_length > 0)
43  else
44  f->set_null();
45 }
46 
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 
58 {
59  if (m_username_length > 0)
61  else
62  f->set_null();
63 }
64 
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 
83 {
84  switch (index)
85  {
86  case 0: /* USER */
87  if (m_username_length > 0)
89  else
90  f->set_null();
91  break;
92  case 1: /* HOST */
93  if (m_hostname_length > 0)
95  else
96  f->set_null();
97  break;
98  default:
99  DBUG_ASSERT(false);
100  break;
101  }
102 }
103 
105 {
106  m_schema_name_length= pfs->m_digest_key.m_schema_name_length;
107  if (m_schema_name_length > sizeof(m_schema_name))
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);
136 
137  if (m_digest_text_length == 0)
138  m_digest_length= 0;
139  }
140  else
141  {
142  m_digest_length= 0;
144  }
145 
146  return 0;
147 }
148 
150 {
151  switch (index)
152  {
153  case 0: /* SCHEMA_NAME */
154  if (m_schema_name_length > 0)
157  else
158  f->set_null();
159  break;
160  case 1: /* DIGEST */
161  if (m_digest_length > 0)
164  else
165  f->set_null();
166  break;
167  case 2: /* DIGEST_TEXT */
168  if (m_digest_text_length > 0)
171  else
172  f->set_null();
173  break;
174  default:
175  DBUG_ASSERT(false);
176  break;
177  }
178 }
179 
181 {
182  m_object_type= pfs->get_object_type();
183 
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 
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 
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 */
208  break;
209  case 2: /* OBJECT_NAME */
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];
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
232 
233  return 0;
234 }
235 
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)
248  else
249  f->set_null();
250  break;
251  default:
252  DBUG_ASSERT(false);
253  }
254 }
255 
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 */
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 */
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 */
314  break;
315  case 21: /* SUM_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 
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:
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