MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esgs_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_esgs_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 
77 table_esgs_by_account_by_event_name::m_field_def=
78 { 8, field_types };
79 
82 {
83  { C_STRING_WITH_LEN("events_stages_summary_by_account_by_event_name") },
85  table_esgs_by_account_by_event_name::create,
86  NULL, /* write_row */
87  table_esgs_by_account_by_event_name::delete_all_rows,
88  NULL, /* get_row_count */
89  1000, /* records */
91  &m_table_lock,
92  &m_field_def,
93  false /* checked */
94 };
95 
97 table_esgs_by_account_by_event_name::create(void)
98 {
100 }
101 
102 int
103 table_esgs_by_account_by_event_name::delete_all_rows(void)
104 {
107  return 0;
108 }
109 
110 table_esgs_by_account_by_event_name::table_esgs_by_account_by_event_name()
111  : PFS_engine_table(&m_share, &m_pos),
112  m_row_exists(false), m_pos(), m_next_pos()
113 {}
114 
116 {
117  m_pos.reset();
118  m_next_pos.reset();
119 }
120 
122 {
124  return 0;
125 }
126 
128 {
129  PFS_account *account;
130  PFS_stage_class *stage_class;
131 
132  for (m_pos.set_at(&m_next_pos);
133  m_pos.has_more_account();
134  m_pos.next_account())
135  {
136  account= &account_array[m_pos.m_index_1];
137  if (account->m_lock.is_populated())
138  {
139  stage_class= find_stage_class(m_pos.m_index_2);
140  if (stage_class)
141  {
142  make_row(account, stage_class);
143  m_next_pos.set_after(&m_pos);
144  return 0;
145  }
146  }
147  }
148 
149  return HA_ERR_END_OF_FILE;
150 }
151 
152 int
154 {
155  PFS_account *account;
156  PFS_stage_class *stage_class;
157 
158  set_position(pos);
159  DBUG_ASSERT(m_pos.m_index_1 < account_max);
160 
161  account= &account_array[m_pos.m_index_1];
162  if (! account->m_lock.is_populated())
163  return HA_ERR_RECORD_DELETED;
164 
165  stage_class= find_stage_class(m_pos.m_index_2);
166  if (stage_class)
167  {
168  make_row(account, stage_class);
169  return 0;
170  }
171 
172  return HA_ERR_RECORD_DELETED;
173 }
174 
175 void table_esgs_by_account_by_event_name
176 ::make_row(PFS_account *account, PFS_stage_class *klass)
177 {
178  pfs_lock lock;
179  m_row_exists= false;
180 
181  account->m_lock.begin_optimistic_lock(&lock);
182 
183  if (m_row.m_account.make_row(account))
184  return;
185 
186  m_row.m_event_name.make_row(klass);
187 
188  PFS_connection_stage_visitor visitor(klass);
189  PFS_connection_iterator::visit_account(account, true, & visitor);
190 
191  if (! account->m_lock.end_optimistic_lock(&lock))
192  return;
193 
194  m_row_exists= true;
195  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
196 }
197 
199 ::read_row_values(TABLE *table, unsigned char *buf, Field **fields,
200  bool read_all)
201 {
202  Field *f;
203 
204  if (unlikely(! m_row_exists))
205  return HA_ERR_RECORD_DELETED;
206 
207  /* Set the null bits */
208  DBUG_ASSERT(table->s->null_bytes == 1);
209  buf[0]= 0;
210 
211  for (; (f= *fields) ; fields++)
212  {
213  if (read_all || bitmap_is_set(table->read_set, f->field_index))
214  {
215  switch(f->field_index)
216  {
217  case 0: /* USER */
218  case 1: /* HOST */
219  m_row.m_account.set_field(f->field_index, f);
220  break;
221  case 2: /* EVENT_NAME */
222  m_row.m_event_name.set_field(f);
223  break;
224  default: /* 3, ... COUNT/SUM/MIN/AVG/MAX */
225  m_row.m_stat.set_field(f->field_index - 3, f);
226  break;
227  }
228  }
229  }
230 
231  return 0;
232 }
233