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