MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_helper.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 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 
16 #ifndef PFS_TABLE_HELPER_H
17 #define PFS_TABLE_HELPER_H
18 
19 #include "pfs_column_types.h"
20 #include "pfs_stat.h"
21 #include "pfs_timer.h"
22 #include "pfs_engine_table.h"
23 #include "pfs_instr_class.h"
24 #include "pfs_digest.h"
25 
26 /*
27  Write MD5 hash value in a string to be used
28  as DIGEST for the statement.
29 */
30 #define MD5_HASH_TO_STRING(_hash, _str) \
31  sprintf(_str, "%02x%02x%02x%02x%02x%02x%02x%02x" \
32  "%02x%02x%02x%02x%02x%02x%02x%02x", \
33  _hash[0], _hash[1], _hash[2], _hash[3], \
34  _hash[4], _hash[5], _hash[6], _hash[7], \
35  _hash[8], _hash[9], _hash[10], _hash[11], \
36  _hash[12], _hash[13], _hash[14], _hash[15])
37 
38 #define MD5_HASH_TO_STRING_LENGTH 32
39 
40 struct PFS_host;
41 struct PFS_user;
42 struct PFS_account;
43 
56 {
57  static const uint FIRST_VIEW= 1;
58  static const uint VIEW_MUTEX= 1;
59  static const uint VIEW_RWLOCK= 2;
60  static const uint VIEW_COND= 3;
61  static const uint VIEW_FILE= 4;
62  static const uint VIEW_TABLE= 5;
63  static const uint VIEW_SOCKET= 6;
64  static const uint VIEW_IDLE= 7;
65  static const uint LAST_VIEW= 7;
66 };
67 
70 {
71  static const uint FIRST_VIEW= 1;
72  static const uint VIEW_TABLE= 1;
73  static const uint LAST_VIEW= 1;
74 
75  /* Future use */
76  static const uint VIEW_EVENT= 2;
77  static const uint VIEW_PROCEDURE= 3;
78  static const uint VIEW_FUNCTION= 4;
79 };
80 
83 {
85  char m_hostname[HOSTNAME_LENGTH];
88 
90  int make_row(PFS_host *pfs);
92  void set_field(Field *f);
93 };
94 
97 {
99  char m_username[USERNAME_LENGTH];
102 
104  int make_row(PFS_user *pfs);
106  void set_field(Field *f);
107 };
108 
111 {
113  char m_username[USERNAME_LENGTH];
117  char m_hostname[HOSTNAME_LENGTH];
120 
122  int make_row(PFS_account *pfs);
124  void set_field(uint index, Field *f);
125 };
126 
129 {
131  char m_schema_name[NAME_LEN];
142 
146  void set_field(uint index, Field *f);
147 };
148 
151 {
153  const char *m_name;
156 
158  inline void make_row(PFS_instr_class *pfs)
159  {
160  m_name= pfs->m_name;
162  }
163 
165  inline void set_field(Field *f)
166  {
168  }
169 };
170 
173 {
177  char m_schema_name[NAME_LEN];
181  char m_object_name[NAME_LEN];
184 
186  int make_row(PFS_table_share *pfs);
188  void set_field(uint index, Field *f);
189 };
190 
193 {
194  PFS_object_row m_object_row;
196  char m_index_name[NAME_LEN];
199 
201  int make_row(PFS_table_share *pfs, uint table_index);
203  void set_field(uint index, Field *f);
204 };
205 
208 {
210  ulonglong m_count;
212  ulonglong m_sum;
214  ulonglong m_min;
216  ulonglong m_avg;
218  ulonglong m_max;
219 
221  inline void set(time_normalizer *normalizer, const PFS_single_stat *stat)
222  {
223  m_count= stat->m_count;
224 
225  if ((m_count != 0) && stat->has_timed_stats())
226  {
227  m_sum= normalizer->wait_to_pico(stat->m_sum);
228  m_min= normalizer->wait_to_pico(stat->m_min);
229  m_max= normalizer->wait_to_pico(stat->m_max);
230  m_avg= normalizer->wait_to_pico(stat->m_sum / m_count);
231  }
232  else
233  {
234  m_sum= 0;
235  m_min= 0;
236  m_avg= 0;
237  m_max= 0;
238  }
239  }
240 
242  void set_field(uint index, Field *f)
243  {
244  switch (index)
245  {
246  case 0: /* COUNT */
248  break;
249  case 1: /* SUM */
251  break;
252  case 2: /* MIN */
254  break;
255  case 3: /* AVG */
257  break;
258  case 4: /* MAX */
260  break;
261  default:
262  DBUG_ASSERT(false);
263  }
264  }
265 };
266 
269 {
270  PFS_stat_row m_waits;
271  ulonglong m_bytes;
272 
274  inline void set(time_normalizer *normalizer, const PFS_byte_stat *stat)
275  {
276  m_waits.set(normalizer, stat);
277  m_bytes= stat->m_bytes;
278  }
279 };
280 
283 {
284  PFS_stat_row m_all;
285  PFS_stat_row m_all_read;
286  PFS_stat_row m_all_write;
287  PFS_stat_row m_fetch;
288  PFS_stat_row m_insert;
289  PFS_stat_row m_update;
290  PFS_stat_row m_delete;
291 
293  inline void set(time_normalizer *normalizer, const PFS_table_io_stat *stat)
294  {
295  PFS_single_stat all_read;
296  PFS_single_stat all_write;
297  PFS_single_stat all;
298 
299  m_fetch.set(normalizer, & stat->m_fetch);
300 
301  all_read.aggregate(& stat->m_fetch);
302 
303  m_insert.set(normalizer, & stat->m_insert);
304  m_update.set(normalizer, & stat->m_update);
305  m_delete.set(normalizer, & stat->m_delete);
306 
307  all_write.aggregate(& stat->m_insert);
308  all_write.aggregate(& stat->m_update);
309  all_write.aggregate(& stat->m_delete);
310 
311  all.aggregate(& all_read);
312  all.aggregate(& all_write);
313 
314  m_all_read.set(normalizer, & all_read);
315  m_all_write.set(normalizer, & all_write);
316  m_all.set(normalizer, & all);
317  }
318 };
319 
322 {
323  PFS_stat_row m_all;
324  PFS_stat_row m_all_read;
325  PFS_stat_row m_all_write;
326  PFS_stat_row m_read_normal;
327  PFS_stat_row m_read_with_shared_locks;
328  PFS_stat_row m_read_high_priority;
329  PFS_stat_row m_read_no_insert;
330  PFS_stat_row m_read_external;
331  PFS_stat_row m_write_allow_write;
332  PFS_stat_row m_write_concurrent_insert;
333  PFS_stat_row m_write_delayed;
334  PFS_stat_row m_write_low_priority;
335  PFS_stat_row m_write_normal;
336  PFS_stat_row m_write_external;
337 
339  inline void set(time_normalizer *normalizer, const PFS_table_lock_stat *stat)
340  {
341  PFS_single_stat all_read;
342  PFS_single_stat all_write;
343  PFS_single_stat all;
344 
345  m_read_normal.set(normalizer, & stat->m_stat[PFS_TL_READ]);
346  m_read_with_shared_locks.set(normalizer, & stat->m_stat[PFS_TL_READ_WITH_SHARED_LOCKS]);
347  m_read_high_priority.set(normalizer, & stat->m_stat[PFS_TL_READ_HIGH_PRIORITY]);
348  m_read_no_insert.set(normalizer, & stat->m_stat[PFS_TL_READ_NO_INSERT]);
349  m_read_external.set(normalizer, & stat->m_stat[PFS_TL_READ_EXTERNAL]);
350 
351  all_read.aggregate(& stat->m_stat[PFS_TL_READ]);
352  all_read.aggregate(& stat->m_stat[PFS_TL_READ_WITH_SHARED_LOCKS]);
353  all_read.aggregate(& stat->m_stat[PFS_TL_READ_HIGH_PRIORITY]);
354  all_read.aggregate(& stat->m_stat[PFS_TL_READ_NO_INSERT]);
355  all_read.aggregate(& stat->m_stat[PFS_TL_READ_EXTERNAL]);
356 
357  m_write_allow_write.set(normalizer, & stat->m_stat[PFS_TL_WRITE_ALLOW_WRITE]);
358  m_write_concurrent_insert.set(normalizer, & stat->m_stat[PFS_TL_WRITE_CONCURRENT_INSERT]);
359  m_write_delayed.set(normalizer, & stat->m_stat[PFS_TL_WRITE_DELAYED]);
360  m_write_low_priority.set(normalizer, & stat->m_stat[PFS_TL_WRITE_LOW_PRIORITY]);
361  m_write_normal.set(normalizer, & stat->m_stat[PFS_TL_WRITE]);
362  m_write_external.set(normalizer, & stat->m_stat[PFS_TL_WRITE_EXTERNAL]);
363 
364  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE_ALLOW_WRITE]);
365  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE_CONCURRENT_INSERT]);
366  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE_DELAYED]);
367  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE_LOW_PRIORITY]);
368  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE]);
369  all_write.aggregate(& stat->m_stat[PFS_TL_WRITE_EXTERNAL]);
370 
371  all.aggregate(& all_read);
372  all.aggregate(& all_write);
373 
374  m_all_read.set(normalizer, & all_read);
375  m_all_write.set(normalizer, & all_write);
376  m_all.set(normalizer, & all);
377  }
378 };
379 
382 {
383  PFS_stat_row m_timer1_row;
384 
386  inline void set(time_normalizer *normalizer, const PFS_stage_stat *stat)
387  {
388  m_timer1_row.set(normalizer, & stat->m_timer1_stat);
389  }
390 
392  void set_field(uint index, Field *f)
393  {
394  m_timer1_row.set_field(index, f);
395  }
396 };
397 
400 {
401  PFS_stat_row m_timer1_row;
402  ulonglong m_error_count;
403  ulonglong m_warning_count;
404  ulonglong m_rows_affected;
405  ulonglong m_lock_time;
406  ulonglong m_rows_sent;
407  ulonglong m_rows_examined;
408  ulonglong m_created_tmp_disk_tables;
409  ulonglong m_created_tmp_tables;
410  ulonglong m_select_full_join;
411  ulonglong m_select_full_range_join;
412  ulonglong m_select_range;
413  ulonglong m_select_range_check;
414  ulonglong m_select_scan;
415  ulonglong m_sort_merge_passes;
416  ulonglong m_sort_range;
417  ulonglong m_sort_rows;
418  ulonglong m_sort_scan;
419  ulonglong m_no_index_used;
420  ulonglong m_no_good_index_used;
421 
423  inline void set(time_normalizer *normalizer, const PFS_statement_stat *stat)
424  {
425  m_timer1_row.set(normalizer, & stat->m_timer1_stat);
426 
427  m_error_count= stat->m_error_count;
428  m_warning_count= stat->m_warning_count;
429  m_lock_time= stat->m_lock_time * MICROSEC_TO_PICOSEC;
430  m_rows_affected= stat->m_rows_affected;
431  m_rows_sent= stat->m_rows_sent;
432  m_rows_examined= stat->m_rows_examined;
433  m_created_tmp_disk_tables= stat->m_created_tmp_disk_tables;
434  m_created_tmp_tables= stat->m_created_tmp_tables;
435  m_select_full_join= stat->m_select_full_join;
436  m_select_full_range_join= stat->m_select_full_range_join;
437  m_select_range= stat->m_select_range;
438  m_select_range_check= stat->m_select_range_check;
439  m_select_scan= stat->m_select_scan;
440  m_sort_merge_passes= stat->m_sort_range;
441  m_sort_range= stat->m_sort_range;
442  m_sort_rows= stat->m_sort_rows;
443  m_sort_scan= stat->m_sort_scan;
444  m_no_index_used= stat->m_no_index_used;
445  m_no_good_index_used= stat->m_no_good_index_used;
446  }
447 
449  void set_field(uint index, Field *f);
450 };
451 
453 {
454  ulonglong m_current_connections;
455  ulonglong m_total_connections;
456 
457  inline void set(const PFS_connection_stat *stat)
458  {
459  m_current_connections= stat->m_current_connections;
460  m_total_connections= stat->m_total_connections;
461  }
462 
464  void set_field(uint index, Field *f);
465 };
466 
467 void set_field_object_type(Field *f, enum_object_type object_type);
468 
471 {
472  PFS_byte_stat_row m_read;
473  PFS_byte_stat_row m_write;
474  PFS_byte_stat_row m_misc;
475  PFS_byte_stat_row m_all;
476 
477  inline void set(time_normalizer *normalizer, const PFS_socket_io_stat *stat)
478  {
479  PFS_byte_stat all;
480 
481  m_read.set(normalizer, &stat->m_read);
482  m_write.set(normalizer, &stat->m_write);
483  m_misc.set(normalizer, &stat->m_misc);
484 
485  /* Combine stats for all operations */
486  all.aggregate(&stat->m_read);
487  all.aggregate(&stat->m_write);
488  all.aggregate(&stat->m_misc);
489 
490  m_all.set(normalizer, &all);
491  }
492 };
493 
496 {
497  PFS_byte_stat_row m_read;
498  PFS_byte_stat_row m_write;
499  PFS_byte_stat_row m_misc;
500  PFS_byte_stat_row m_all;
501 
502  inline void set(time_normalizer *normalizer, const PFS_file_io_stat *stat)
503  {
504  PFS_byte_stat all;
505 
506  m_read.set(normalizer, &stat->m_read);
507  m_write.set(normalizer, &stat->m_write);
508  m_misc.set(normalizer, &stat->m_misc);
509 
510  /* Combine stats for all operations */
511  all.aggregate(&stat->m_read);
512  all.aggregate(&stat->m_write);
513  all.aggregate(&stat->m_misc);
514 
515  m_all.set(normalizer, &all);
516  }
517 };
518 
521 #endif
522