MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esms_global_by_event_name.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_instr.h"
29 #include "pfs_timer.h"
30 #include "pfs_visitor.h"
31 
32 THR_LOCK table_esms_global_by_event_name::m_table_lock;
33 
34 static const TABLE_FIELD_TYPE field_types[]=
35 {
36  {
37  { C_STRING_WITH_LEN("EVENT_NAME") },
38  { C_STRING_WITH_LEN("varchar(128)") },
39  { NULL, 0}
40  },
41  {
42  { C_STRING_WITH_LEN("COUNT_STAR") },
43  { C_STRING_WITH_LEN("bigint(20)") },
44  { NULL, 0}
45  },
46  {
47  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
48  { C_STRING_WITH_LEN("bigint(20)") },
49  { NULL, 0}
50  },
51  {
52  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
53  { C_STRING_WITH_LEN("bigint(20)") },
54  { NULL, 0}
55  },
56  {
57  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
58  { C_STRING_WITH_LEN("bigint(20)") },
59  { NULL, 0}
60  },
61  {
62  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
63  { C_STRING_WITH_LEN("bigint(20)") },
64  { NULL, 0}
65  },
66  {
67  { C_STRING_WITH_LEN("SUM_LOCK_TIME") },
68  { C_STRING_WITH_LEN("bigint(20)") },
69  { NULL, 0}
70  },
71  {
72  { C_STRING_WITH_LEN("SUM_ERRORS") },
73  { C_STRING_WITH_LEN("bigint(20)") },
74  { NULL, 0}
75  },
76  {
77  { C_STRING_WITH_LEN("SUM_WARNINGS") },
78  { C_STRING_WITH_LEN("bigint(20)") },
79  { NULL, 0}
80  },
81  {
82  { C_STRING_WITH_LEN("SUM_ROWS_AFFECTED") },
83  { C_STRING_WITH_LEN("bigint(20)") },
84  { NULL, 0}
85  },
86  {
87  { C_STRING_WITH_LEN("SUM_ROWS_SENT") },
88  { C_STRING_WITH_LEN("bigint(20)") },
89  { NULL, 0}
90  },
91  {
92  { C_STRING_WITH_LEN("SUM_ROWS_EXAMINED") },
93  { C_STRING_WITH_LEN("bigint(20)") },
94  { NULL, 0}
95  },
96  {
97  { C_STRING_WITH_LEN("SUM_CREATED_TMP_DISK_TABLES") },
98  { C_STRING_WITH_LEN("bigint(20)") },
99  { NULL, 0}
100  },
101  {
102  { C_STRING_WITH_LEN("SUM_CREATED_TMP_TABLES") },
103  { C_STRING_WITH_LEN("bigint(20)") },
104  { NULL, 0}
105  },
106  {
107  { C_STRING_WITH_LEN("SUM_SELECT_FULL_JOIN") },
108  { C_STRING_WITH_LEN("bigint(20)") },
109  { NULL, 0}
110  },
111  {
112  { C_STRING_WITH_LEN("SUM_SELECT_FULL_RANGE_JOIN") },
113  { C_STRING_WITH_LEN("bigint(20)") },
114  { NULL, 0}
115  },
116  {
117  { C_STRING_WITH_LEN("SUM_SELECT_RANGE") },
118  { C_STRING_WITH_LEN("bigint(20)") },
119  { NULL, 0}
120  },
121  {
122  { C_STRING_WITH_LEN("SUM_SELECT_RANGE_CHECK") },
123  { C_STRING_WITH_LEN("bigint(20)") },
124  { NULL, 0}
125  },
126  {
127  { C_STRING_WITH_LEN("SUM_SELECT_SCAN") },
128  { C_STRING_WITH_LEN("bigint(20)") },
129  { NULL, 0}
130  },
131  {
132  { C_STRING_WITH_LEN("SUM_SORT_MERGE_PASSES") },
133  { C_STRING_WITH_LEN("bigint(20)") },
134  { NULL, 0}
135  },
136  {
137  { C_STRING_WITH_LEN("SUM_SORT_RANGE") },
138  { C_STRING_WITH_LEN("bigint(20)") },
139  { NULL, 0}
140  },
141  {
142  { C_STRING_WITH_LEN("SUM_SORT_ROWS") },
143  { C_STRING_WITH_LEN("bigint(20)") },
144  { NULL, 0}
145  },
146  {
147  { C_STRING_WITH_LEN("SUM_SORT_SCAN") },
148  { C_STRING_WITH_LEN("bigint(20)") },
149  { NULL, 0}
150  },
151  {
152  { C_STRING_WITH_LEN("SUM_NO_INDEX_USED") },
153  { C_STRING_WITH_LEN("bigint(20)") },
154  { NULL, 0}
155  },
156  {
157  { C_STRING_WITH_LEN("SUM_NO_GOOD_INDEX_USED") },
158  { C_STRING_WITH_LEN("bigint(20)") },
159  { NULL, 0}
160  }
161 };
162 
164 table_esms_global_by_event_name::m_field_def=
165 { 25, field_types };
166 
169 {
170  { C_STRING_WITH_LEN("events_statements_summary_global_by_event_name") },
172  table_esms_global_by_event_name::create,
173  NULL, /* write_row */
174  table_esms_global_by_event_name::delete_all_rows,
175  NULL, /* get_row_count */
176  1000, /* records */
177  sizeof(PFS_simple_index),
178  &m_table_lock,
179  &m_field_def,
180  false /* checked */
181 };
182 
184 table_esms_global_by_event_name::create(void)
185 {
186  return new table_esms_global_by_event_name();
187 }
188 
189 int
190 table_esms_global_by_event_name::delete_all_rows(void)
191 {
197  return 0;
198 }
199 
200 table_esms_global_by_event_name::table_esms_global_by_event_name()
201  : PFS_engine_table(&m_share, &m_pos),
202  m_row_exists(false), m_pos(1), m_next_pos(1)
203 {}
204 
206 {
207  m_pos= 1;
208  m_next_pos= 1;
209 }
210 
212 {
214  return 0;
215 }
216 
218 {
219  PFS_statement_class *statement_class;
220 
221  if (global_instr_class_statements_array == NULL)
222  return HA_ERR_END_OF_FILE;
223 
224  m_pos.set_at(&m_next_pos);
225 
226  statement_class= find_statement_class(m_pos.m_index);
227  if (statement_class)
228  {
229  make_row(statement_class);
230  m_next_pos.set_after(&m_pos);
231  return 0;
232  }
233 
234  return HA_ERR_END_OF_FILE;
235 }
236 
237 int
239 {
240  PFS_statement_class *statement_class;
241 
242  set_position(pos);
243 
244  if (global_instr_class_statements_array == NULL)
245  return HA_ERR_END_OF_FILE;
246 
247  statement_class=find_statement_class(m_pos.m_index);
248  if (statement_class)
249  {
250  make_row(statement_class);
251  return 0;
252  }
253 
254  return HA_ERR_RECORD_DELETED;
255 }
256 
257 
258 void table_esms_global_by_event_name
259 ::make_row(PFS_statement_class *klass)
260 {
261  m_row.m_event_name.make_row(klass);
262 
263  PFS_connection_statement_visitor visitor(klass);
264  PFS_connection_iterator::visit_global(true, /* hosts */
265  false, /* users */
266  true, true, & visitor);
267 
268  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
269  m_row_exists= true;
270 }
271 
273 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
274  bool read_all)
275 {
276  Field *f;
277 
278  if (unlikely(! m_row_exists))
279  return HA_ERR_RECORD_DELETED;
280 
281  /* Set the null bits */
282  DBUG_ASSERT(table->s->null_bytes == 0);
283 
284  for (; (f= *fields) ; fields++)
285  {
286  if (read_all || bitmap_is_set(table->read_set, f->field_index))
287  {
288  switch(f->field_index)
289  {
290  case 0: /* NAME */
291  m_row.m_event_name.set_field(f);
292  break;
293  default: /* 1, ... COUNT/SUM/MIN/AVG/MAX */
294  m_row.m_stat.set_field(f->field_index - 1, f);
295  break;
296  }
297  }
298  }
299 
300  return 0;
301 }
302