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