MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_tiws_by_index_usage.cc
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2011, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
21 #include "my_global.h"
22 #include "my_pthread.h"
23 #include "pfs_instr_class.h"
24 #include "pfs_column_types.h"
25 #include "pfs_column_values.h"
27 #include "pfs_global.h"
28 #include "pfs_visitor.h"
29 
30 THR_LOCK table_tiws_by_index_usage::m_table_lock;
31 
32 static const TABLE_FIELD_TYPE field_types[]=
33 {
34  {
35  { C_STRING_WITH_LEN("OBJECT_TYPE") },
36  { C_STRING_WITH_LEN("varchar(64)") },
37  { NULL, 0}
38  },
39  {
40  { C_STRING_WITH_LEN("OBJECT_SCHEMA") },
41  { C_STRING_WITH_LEN("varchar(64)") },
42  { NULL, 0}
43  },
44  {
45  { C_STRING_WITH_LEN("OBJECT_NAME") },
46  { C_STRING_WITH_LEN("varchar(64)") },
47  { NULL, 0}
48  },
49  {
50  { C_STRING_WITH_LEN("INDEX_NAME") },
51  { C_STRING_WITH_LEN("varchar(64)") },
52  { NULL, 0}
53  },
54  {
55  { C_STRING_WITH_LEN("COUNT_STAR") },
56  { C_STRING_WITH_LEN("bigint(20)") },
57  { NULL, 0}
58  },
59  {
60  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
61  { C_STRING_WITH_LEN("bigint(20)") },
62  { NULL, 0}
63  },
64  {
65  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
66  { C_STRING_WITH_LEN("bigint(20)") },
67  { NULL, 0}
68  },
69  {
70  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
71  { C_STRING_WITH_LEN("bigint(20)") },
72  { NULL, 0}
73  },
74  {
75  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
76  { C_STRING_WITH_LEN("bigint(20)") },
77  { NULL, 0}
78  },
79  {
80  { C_STRING_WITH_LEN("COUNT_READ") },
81  { C_STRING_WITH_LEN("bigint(20)") },
82  { NULL, 0}
83  },
84  {
85  { C_STRING_WITH_LEN("SUM_TIMER_READ") },
86  { C_STRING_WITH_LEN("bigint(20)") },
87  { NULL, 0}
88  },
89  {
90  { C_STRING_WITH_LEN("MIN_TIMER_READ") },
91  { C_STRING_WITH_LEN("bigint(20)") },
92  { NULL, 0}
93  },
94  {
95  { C_STRING_WITH_LEN("AVG_TIMER_READ") },
96  { C_STRING_WITH_LEN("bigint(20)") },
97  { NULL, 0}
98  },
99  {
100  { C_STRING_WITH_LEN("MAX_TIMER_READ") },
101  { C_STRING_WITH_LEN("bigint(20)") },
102  { NULL, 0}
103  },
104  {
105  { C_STRING_WITH_LEN("COUNT_WRITE") },
106  { C_STRING_WITH_LEN("bigint(20)") },
107  { NULL, 0}
108  },
109  {
110  { C_STRING_WITH_LEN("SUM_TIMER_WRITE") },
111  { C_STRING_WITH_LEN("bigint(20)") },
112  { NULL, 0}
113  },
114  {
115  { C_STRING_WITH_LEN("MIN_TIMER_WRITE") },
116  { C_STRING_WITH_LEN("bigint(20)") },
117  { NULL, 0}
118  },
119  {
120  { C_STRING_WITH_LEN("AVG_TIMER_WRITE") },
121  { C_STRING_WITH_LEN("bigint(20)") },
122  { NULL, 0}
123  },
124  {
125  { C_STRING_WITH_LEN("MAX_TIMER_WRITE") },
126  { C_STRING_WITH_LEN("bigint(20)") },
127  { NULL, 0}
128  },
129  {
130  { C_STRING_WITH_LEN("COUNT_FETCH") },
131  { C_STRING_WITH_LEN("bigint(20)") },
132  { NULL, 0}
133  },
134  {
135  { C_STRING_WITH_LEN("SUM_TIMER_FETCH") },
136  { C_STRING_WITH_LEN("bigint(20)") },
137  { NULL, 0}
138  },
139  {
140  { C_STRING_WITH_LEN("MIN_TIMER_FETCH") },
141  { C_STRING_WITH_LEN("bigint(20)") },
142  { NULL, 0}
143  },
144  {
145  { C_STRING_WITH_LEN("AVG_TIMER_FETCH") },
146  { C_STRING_WITH_LEN("bigint(20)") },
147  { NULL, 0}
148  },
149  {
150  { C_STRING_WITH_LEN("MAX_TIMER_FETCH") },
151  { C_STRING_WITH_LEN("bigint(20)") },
152  { NULL, 0}
153  },
154  {
155  { C_STRING_WITH_LEN("COUNT_INSERT") },
156  { C_STRING_WITH_LEN("bigint(20)") },
157  { NULL, 0}
158  },
159  {
160  { C_STRING_WITH_LEN("SUM_TIMER_INSERT") },
161  { C_STRING_WITH_LEN("bigint(20)") },
162  { NULL, 0}
163  },
164  {
165  { C_STRING_WITH_LEN("MIN_TIMER_INSERT") },
166  { C_STRING_WITH_LEN("bigint(20)") },
167  { NULL, 0}
168  },
169  {
170  { C_STRING_WITH_LEN("AVG_TIMER_INSERT") },
171  { C_STRING_WITH_LEN("bigint(20)") },
172  { NULL, 0}
173  },
174  {
175  { C_STRING_WITH_LEN("MAX_TIMER_INSERT") },
176  { C_STRING_WITH_LEN("bigint(20)") },
177  { NULL, 0}
178  },
179  {
180  { C_STRING_WITH_LEN("COUNT_UPDATE") },
181  { C_STRING_WITH_LEN("bigint(20)") },
182  { NULL, 0}
183  },
184  {
185  { C_STRING_WITH_LEN("SUM_TIMER_UPDATE") },
186  { C_STRING_WITH_LEN("bigint(20)") },
187  { NULL, 0}
188  },
189  {
190  { C_STRING_WITH_LEN("MIN_TIMER_UPDATE") },
191  { C_STRING_WITH_LEN("bigint(20)") },
192  { NULL, 0}
193  },
194  {
195  { C_STRING_WITH_LEN("AVG_TIMER_UPDATE") },
196  { C_STRING_WITH_LEN("bigint(20)") },
197  { NULL, 0}
198  },
199  {
200  { C_STRING_WITH_LEN("MAX_TIMER_UPDATE") },
201  { C_STRING_WITH_LEN("bigint(20)") },
202  { NULL, 0}
203  },
204  {
205  { C_STRING_WITH_LEN("COUNT_DELETE") },
206  { C_STRING_WITH_LEN("bigint(20)") },
207  { NULL, 0}
208  },
209  {
210  { C_STRING_WITH_LEN("SUM_TIMER_DELETE") },
211  { C_STRING_WITH_LEN("bigint(20)") },
212  { NULL, 0}
213  },
214  {
215  { C_STRING_WITH_LEN("MIN_TIMER_DELETE") },
216  { C_STRING_WITH_LEN("bigint(20)") },
217  { NULL, 0}
218  },
219  {
220  { C_STRING_WITH_LEN("AVG_TIMER_DELETE") },
221  { C_STRING_WITH_LEN("bigint(20)") },
222  { NULL, 0}
223  },
224  {
225  { C_STRING_WITH_LEN("MAX_TIMER_DELETE") },
226  { C_STRING_WITH_LEN("bigint(20)") },
227  { NULL, 0}
228  }
229 };
230 
232 table_tiws_by_index_usage::m_field_def=
233 { 39, field_types };
234 
237 {
238  { C_STRING_WITH_LEN("table_io_waits_summary_by_index_usage") },
240  table_tiws_by_index_usage::create,
241  NULL, /* write_row */
242  table_tiws_by_index_usage::delete_all_rows,
243  NULL, /* get_row_count */
244  1000, /* records */
245  sizeof(pos_tiws_by_index_usage),
246  &m_table_lock,
247  &m_field_def,
248  false /* checked */
249 };
250 
252 table_tiws_by_index_usage::create(void)
253 {
254  return new table_tiws_by_index_usage();
255 }
256 
257 int
258 table_tiws_by_index_usage::delete_all_rows(void)
259 {
260  reset_table_io_waits_by_table_handle();
261  reset_table_io_waits_by_table();
262  return 0;
263 }
264 
265 table_tiws_by_index_usage::table_tiws_by_index_usage()
266  : PFS_engine_table(&m_share, &m_pos),
267  m_row_exists(false), m_pos(), m_next_pos()
268 {}
269 
271 {
272  m_pos.reset();
273  m_next_pos.reset();
274 }
275 
277 {
279  return 0;
280 }
281 
283 {
284  PFS_table_share *table_share;
285 
286  for (m_pos.set_at(&m_next_pos);
287  m_pos.has_more_table();
288  m_pos.next_table())
289  {
290  table_share= &table_share_array[m_pos.m_index_1];
291  if (table_share->m_lock.is_populated())
292  {
293  uint safe_key_count= sanitize_index_count(table_share->m_key_count);
294  if (m_pos.m_index_2 < safe_key_count)
295  {
296  make_row(table_share, m_pos.m_index_2);
297  m_next_pos.set_after(&m_pos);
298  return 0;
299  }
300  if (m_pos.m_index_2 <= MAX_INDEXES)
301  {
302  m_pos.m_index_2= MAX_INDEXES;
303  make_row(table_share, m_pos.m_index_2);
304  m_next_pos.set_after(&m_pos);
305  return 0;
306  }
307  }
308  }
309 
310  return HA_ERR_END_OF_FILE;
311 }
312 
313 int
315 {
316  PFS_table_share *table_share;
317 
318  set_position(pos);
319 
320  table_share= &table_share_array[m_pos.m_index_1];
321  if (table_share->m_lock.is_populated())
322  {
323  uint safe_key_count= sanitize_index_count(table_share->m_key_count);
324  if (m_pos.m_index_2 < safe_key_count)
325  {
326  make_row(table_share, m_pos.m_index_2);
327  return 0;
328  }
329  if (m_pos.m_index_2 == MAX_INDEXES)
330  {
331  make_row(table_share, m_pos.m_index_2);
332  return 0;
333  }
334  }
335 
336  return HA_ERR_RECORD_DELETED;
337 }
338 
339 void table_tiws_by_index_usage::make_row(PFS_table_share *share, uint index)
340 {
341  pfs_lock lock;
342 
343  m_row_exists= false;
344 
345  share->m_lock.begin_optimistic_lock(&lock);
346 
347  if (m_row.m_index.make_row(share, index))
348  return;
349 
351  PFS_object_iterator::visit_table_indexes(share, index, & visitor);
352 
353  if (! share->m_lock.end_optimistic_lock(&lock))
354  return;
355 
356  m_row_exists= true;
357  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
358 }
359 
361  unsigned char *buf,
362  Field **fields,
363  bool read_all)
364 {
365  Field *f;
366 
367  if (unlikely(! m_row_exists))
368  return HA_ERR_RECORD_DELETED;
369 
370  /* Set the null bits */
371  DBUG_ASSERT(table->s->null_bytes == 1);
372  buf[0]= 0;
373 
374  for (; (f= *fields) ; fields++)
375  {
376  if (read_all || bitmap_is_set(table->read_set, f->field_index))
377  {
378  switch(f->field_index)
379  {
380  case 0: /* OBJECT_TYPE */
381  case 1: /* SCHEMA_NAME */
382  case 2: /* OBJECT_NAME */
383  case 3: /* INDEX_NAME */
384  m_row.m_index.set_field(f->field_index, f);
385  break;
386  case 4: /* COUNT_STAR */
387  set_field_ulonglong(f, m_row.m_stat.m_all.m_count);
388  break;
389  case 5: /* SUM */
390  set_field_ulonglong(f, m_row.m_stat.m_all.m_sum);
391  break;
392  case 6: /* MIN */
393  set_field_ulonglong(f, m_row.m_stat.m_all.m_min);
394  break;
395  case 7: /* AVG */
396  set_field_ulonglong(f, m_row.m_stat.m_all.m_avg);
397  break;
398  case 8: /* MAX */
399  set_field_ulonglong(f, m_row.m_stat.m_all.m_max);
400  break;
401  case 9: /* COUNT_READ */
402  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_count);
403  break;
404  case 10: /* SUM_READ */
405  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_sum);
406  break;
407  case 11: /* MIN_READ */
408  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_min);
409  break;
410  case 12: /* AVG_READ */
411  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_avg);
412  break;
413  case 13: /* MAX_READ */
414  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_max);
415  break;
416  case 14: /* COUNT_WRITE */
417  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_count);
418  break;
419  case 15: /* SUM_WRITE */
420  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_sum);
421  break;
422  case 16: /* MIN_WRITE */
423  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_min);
424  break;
425  case 17: /* AVG_WRITE */
426  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_avg);
427  break;
428  case 18: /* MAX_WRITE */
429  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_max);
430  break;
431  case 19: /* COUNT_FETCH */
432  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_count);
433  break;
434  case 20: /* SUM_FETCH */
435  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_sum);
436  break;
437  case 21: /* MIN_FETCH */
438  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_min);
439  break;
440  case 22: /* AVG_FETCH */
441  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_avg);
442  break;
443  case 23: /* MAX_FETCH */
444  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_max);
445  break;
446  case 24: /* COUNT_INSERT */
447  set_field_ulonglong(f, m_row.m_stat.m_insert.m_count);
448  break;
449  case 25: /* SUM_INSERT */
450  set_field_ulonglong(f, m_row.m_stat.m_insert.m_sum);
451  break;
452  case 26: /* MIN_INSERT */
453  set_field_ulonglong(f, m_row.m_stat.m_insert.m_min);
454  break;
455  case 27: /* AVG_INSERT */
456  set_field_ulonglong(f, m_row.m_stat.m_insert.m_avg);
457  break;
458  case 28: /* MAX_INSERT */
459  set_field_ulonglong(f, m_row.m_stat.m_insert.m_max);
460  break;
461  case 29: /* COUNT_UPDATE */
462  set_field_ulonglong(f, m_row.m_stat.m_update.m_count);
463  break;
464  case 30: /* SUM_UPDATE */
465  set_field_ulonglong(f, m_row.m_stat.m_update.m_sum);
466  break;
467  case 31: /* MIN_UPDATE */
468  set_field_ulonglong(f, m_row.m_stat.m_update.m_min);
469  break;
470  case 32: /* AVG_UPDATE */
471  set_field_ulonglong(f, m_row.m_stat.m_update.m_avg);
472  break;
473  case 33: /* MAX_UPDATE */
474  set_field_ulonglong(f, m_row.m_stat.m_update.m_max);
475  break;
476  case 34: /* COUNT_DELETE */
477  set_field_ulonglong(f, m_row.m_stat.m_delete.m_count);
478  break;
479  case 35: /* SUM_DELETE */
480  set_field_ulonglong(f, m_row.m_stat.m_delete.m_sum);
481  break;
482  case 36: /* MIN_DELETE */
483  set_field_ulonglong(f, m_row.m_stat.m_delete.m_min);
484  break;
485  case 37: /* AVG_DELETE */
486  set_field_ulonglong(f, m_row.m_stat.m_delete.m_avg);
487  break;
488  case 38: /* MAX_DELETE */
489  set_field_ulonglong(f, m_row.m_stat.m_delete.m_max);
490  break;
491  default:
492  DBUG_ASSERT(false);
493  }
494  }
495  }
496 
497  return 0;
498 }
499