MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esms_by_digest.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 Street, 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"
26 #include "table_esms_by_digest.h"
27 #include "pfs_global.h"
28 #include "pfs_instr.h"
29 #include "pfs_timer.h"
30 #include "pfs_visitor.h"
31 #include "table_esms_by_digest.h"
32 #include "pfs_digest.h"
33 
34 THR_LOCK table_esms_by_digest::m_table_lock;
35 
36 static const TABLE_FIELD_TYPE field_types[]=
37 {
38  {
39  { C_STRING_WITH_LEN("SCHEMA_NAME") },
40  { C_STRING_WITH_LEN("varchar(64)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("DIGEST") },
45  { C_STRING_WITH_LEN("varchar(32)") },
46  { NULL, 0}
47  },
48  {
49  { C_STRING_WITH_LEN("DIGEST_TEXT") },
50  { C_STRING_WITH_LEN("longtext") },
51  { NULL, 0}
52  },
53  {
54  { C_STRING_WITH_LEN("COUNT_STAR") },
55  { C_STRING_WITH_LEN("bigint(20)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
60  { C_STRING_WITH_LEN("bigint(20)") },
61  { NULL, 0}
62  },
63  {
64  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
65  { C_STRING_WITH_LEN("bigint(20)") },
66  { NULL, 0}
67  },
68  {
69  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
70  { C_STRING_WITH_LEN("bigint(20)") },
71  { NULL, 0}
72  },
73  {
74  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
75  { C_STRING_WITH_LEN("bigint(20)") },
76  { NULL, 0}
77  },
78  {
79  { C_STRING_WITH_LEN("SUM_LOCK_TIME") },
80  { C_STRING_WITH_LEN("bigint(20)") },
81  { NULL, 0}
82  },
83  {
84  { C_STRING_WITH_LEN("SUM_ERRORS") },
85  { C_STRING_WITH_LEN("bigint(20)") },
86  { NULL, 0}
87  },
88  {
89  { C_STRING_WITH_LEN("SUM_WARNINGS") },
90  { C_STRING_WITH_LEN("bigint(20)") },
91  { NULL, 0}
92  },
93  {
94  { C_STRING_WITH_LEN("SUM_ROWS_AFFECTED") },
95  { C_STRING_WITH_LEN("bigint(20)") },
96  { NULL, 0}
97  },
98  {
99  { C_STRING_WITH_LEN("SUM_ROWS_SENT") },
100  { C_STRING_WITH_LEN("bigint(20)") },
101  { NULL, 0}
102  },
103  {
104  { C_STRING_WITH_LEN("SUM_ROWS_EXAMINED") },
105  { C_STRING_WITH_LEN("bigint(20)") },
106  { NULL, 0}
107  },
108  {
109  { C_STRING_WITH_LEN("SUM_CREATED_TMP_DISK_TABLES") },
110  { C_STRING_WITH_LEN("bigint(20)") },
111  { NULL, 0}
112  },
113  {
114  { C_STRING_WITH_LEN("SUM_CREATED_TMP_TABLES") },
115  { C_STRING_WITH_LEN("bigint(20)") },
116  { NULL, 0}
117  },
118  {
119  { C_STRING_WITH_LEN("SUM_SELECT_FULL_JOIN") },
120  { C_STRING_WITH_LEN("bigint(20)") },
121  { NULL, 0}
122  },
123  {
124  { C_STRING_WITH_LEN("SUM_SELECT_FULL_RANGE_JOIN") },
125  { C_STRING_WITH_LEN("bigint(20)") },
126  { NULL, 0}
127  },
128  {
129  { C_STRING_WITH_LEN("SUM_SELECT_RANGE") },
130  { C_STRING_WITH_LEN("bigint(20)") },
131  { NULL, 0}
132  },
133  {
134  { C_STRING_WITH_LEN("SUM_SELECT_RANGE_CHECK") },
135  { C_STRING_WITH_LEN("bigint(20)") },
136  { NULL, 0}
137  },
138  {
139  { C_STRING_WITH_LEN("SUM_SELECT_SCAN") },
140  { C_STRING_WITH_LEN("bigint(20)") },
141  { NULL, 0}
142  },
143  {
144  { C_STRING_WITH_LEN("SUM_SORT_MERGE_PASSES") },
145  { C_STRING_WITH_LEN("bigint(20)") },
146  { NULL, 0}
147  },
148  {
149  { C_STRING_WITH_LEN("SUM_SORT_RANGE") },
150  { C_STRING_WITH_LEN("bigint(20)") },
151  { NULL, 0}
152  },
153  {
154  { C_STRING_WITH_LEN("SUM_SORT_ROWS") },
155  { C_STRING_WITH_LEN("bigint(20)") },
156  { NULL, 0}
157  },
158  {
159  { C_STRING_WITH_LEN("SUM_SORT_SCAN") },
160  { C_STRING_WITH_LEN("bigint(20)") },
161  { NULL, 0}
162  },
163  {
164  { C_STRING_WITH_LEN("SUM_NO_INDEX_USED") },
165  { C_STRING_WITH_LEN("bigint(20)") },
166  { NULL, 0}
167  },
168  {
169  { C_STRING_WITH_LEN("SUM_NO_GOOD_INDEX_USED") },
170  { C_STRING_WITH_LEN("bigint(20)") },
171  { NULL, 0}
172  },
173  {
174  { C_STRING_WITH_LEN("FIRST_SEEN") },
175  { C_STRING_WITH_LEN("timestamp") },
176  { NULL, 0}
177  },
178  {
179  { C_STRING_WITH_LEN("LAST_SEEN") },
180  { C_STRING_WITH_LEN("timestamp") },
181  { NULL, 0}
182  }
183 };
184 
186 table_esms_by_digest::m_field_def=
187 { 29, field_types };
188 
191 {
192  { C_STRING_WITH_LEN("events_statements_summary_by_digest") },
194  table_esms_by_digest::create,
195  NULL, /* write_row */
196  table_esms_by_digest::delete_all_rows,
197  NULL, /* get_row_count */
198  1000, /* records */
199  sizeof(PFS_simple_index),
200  &m_table_lock,
201  &m_field_def,
202  false /* checked */
203 };
204 
206 table_esms_by_digest::create(void)
207 {
208  return new table_esms_by_digest();
209 }
210 
211 int
212 table_esms_by_digest::delete_all_rows(void)
213 {
214  reset_esms_by_digest();
215  return 0;
216 }
217 
218 table_esms_by_digest::table_esms_by_digest()
219  : PFS_engine_table(&m_share, &m_pos),
220  m_row_exists(false), m_pos(0), m_next_pos(0)
221 {}
222 
224 {
225  m_pos= 0;
226  m_next_pos= 0;
227 }
228 
230 {
231  PFS_statements_digest_stat* digest_stat;
232 
233  if (statements_digest_stat_array == NULL)
234  return HA_ERR_END_OF_FILE;
235 
236  for (m_pos.set_at(&m_next_pos);
237  m_pos.m_index < digest_max;
238  m_pos.next())
239  {
240  digest_stat= &statements_digest_stat_array[m_pos.m_index];
241  if (digest_stat->m_first_seen != 0)
242  {
243  make_row(digest_stat);
244  m_next_pos.set_after(&m_pos);
245  return 0;
246  }
247  }
248 
249  return HA_ERR_END_OF_FILE;
250 }
251 
252 int
254 {
255  PFS_statements_digest_stat* digest_stat;
256 
257  if (statements_digest_stat_array == NULL)
258  return HA_ERR_END_OF_FILE;
259 
260  set_position(pos);
261  digest_stat= &statements_digest_stat_array[m_pos.m_index];
262 
263  if (digest_stat->m_first_seen != 0)
264  {
265  make_row(digest_stat);
266  return 0;
267  }
268 
269  return HA_ERR_RECORD_DELETED;
270 }
271 
272 
273 void table_esms_by_digest::make_row(PFS_statements_digest_stat* digest_stat)
274 {
275  m_row_exists= false;
276  m_row.m_first_seen= digest_stat->m_first_seen;
277  m_row.m_last_seen= digest_stat->m_last_seen;
278  m_row.m_digest.make_row(digest_stat);
279 
280  /*
281  Get statements stats.
282  */
284  m_row.m_stat.set(normalizer, & digest_stat->m_stat);
285 
286  m_row_exists= true;
287 }
288 
290 ::read_row_values(TABLE *table, unsigned char *buf, Field **fields,
291  bool read_all)
292 {
293  Field *f;
294 
295  if (unlikely(! m_row_exists))
296  return HA_ERR_RECORD_DELETED;
297 
298  /*
299  Set the null bits. It indicates how many fields could be null
300  in the table.
301  */
302  DBUG_ASSERT(table->s->null_bytes == 1);
303  buf[0]= 0;
304 
305  for (; (f= *fields) ; fields++)
306  {
307  if (read_all || bitmap_is_set(table->read_set, f->field_index))
308  {
309  switch(f->field_index)
310  {
311  case 0: /* SCHEMA_NAME */
312  case 1: /* DIGEST */
313  case 2: /* DIGEST_TEXT */
314  m_row.m_digest.set_field(f->field_index, f);
315  break;
316  case 27: /* FIRST_SEEN */
317  set_field_timestamp(f, m_row.m_first_seen);
318  break;
319  case 28: /* LAST_SEEN */
320  set_field_timestamp(f, m_row.m_last_seen);
321  break;
322  default: /* 3, ... COUNT/SUM/MIN/AVG/MAX */
323  m_row.m_stat.set_field(f->field_index - 3, f);
324  break;
325  }
326  }
327  }
328 
329  return 0;
330 }
331