MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_setup_consumers.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 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 Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include "my_global.h"
22 #include "my_pthread.h"
23 #include "table_setup_consumers.h"
24 #include "pfs_instr.h"
25 #include "pfs_events_waits.h"
26 #include "pfs_digest.h"
27 
28 #define COUNT_SETUP_CONSUMERS 12
29 static row_setup_consumers all_setup_consumers_data[COUNT_SETUP_CONSUMERS]=
30 {
31  {
32  { C_STRING_WITH_LEN("events_stages_current") },
34  false
35  },
36  {
37  { C_STRING_WITH_LEN("events_stages_history") },
39  false
40  },
41  {
42  { C_STRING_WITH_LEN("events_stages_history_long") },
44  false
45  },
46  {
47  { C_STRING_WITH_LEN("events_statements_current") },
49  false
50  },
51  {
52  { C_STRING_WITH_LEN("events_statements_history") },
54  false
55  },
56  {
57  { C_STRING_WITH_LEN("events_statements_history_long") },
59  false
60  },
61  {
62  { C_STRING_WITH_LEN("events_waits_current") },
64  false
65  },
66  {
67  { C_STRING_WITH_LEN("events_waits_history") },
69  false
70  },
71  {
72  { C_STRING_WITH_LEN("events_waits_history_long") },
74  false
75  },
76  {
77  { C_STRING_WITH_LEN("global_instrumentation") },
79  true
80  },
81  {
82  { C_STRING_WITH_LEN("thread_instrumentation") },
84  false
85  },
86  {
87  { C_STRING_WITH_LEN("statements_digest") },
88  &flag_statements_digest,
89  false
90  }
91 };
92 
93 THR_LOCK table_setup_consumers::m_table_lock;
94 
95 static const TABLE_FIELD_TYPE field_types[]=
96 {
97  {
98  { C_STRING_WITH_LEN("NAME") },
99  { C_STRING_WITH_LEN("varchar(64)") },
100  { NULL, 0}
101  },
102  {
103  { C_STRING_WITH_LEN("ENABLED") },
104  { C_STRING_WITH_LEN("enum(\'YES\',\'NO\')") },
105  { NULL, 0}
106  }
107 };
108 
110 table_setup_consumers::m_field_def=
111 { 2, field_types };
112 
115 {
116  { C_STRING_WITH_LEN("setup_consumers") },
118  &table_setup_consumers::create,
119  NULL, /* write_row */
120  NULL, /* delete_all_rows */
121  NULL, /* get_row_count */
122  COUNT_SETUP_CONSUMERS, /* records */
123  sizeof(PFS_simple_index), /* ref length */
124  &m_table_lock,
125  &m_field_def,
126  false /* checked */
127 };
128 
129 PFS_engine_table* table_setup_consumers::create(void)
130 {
131  return new table_setup_consumers();
132 }
133 
134 table_setup_consumers::table_setup_consumers()
135  : PFS_engine_table(&m_share, &m_pos),
136  m_row(NULL), m_pos(0), m_next_pos(0)
137 {}
138 
140 {
141  m_pos.m_index= 0;
142  m_next_pos.m_index= 0;
143 }
144 
146 {
147  int result;
148 
149  m_pos.set_at(&m_next_pos);
150 
151  if (m_pos.m_index < COUNT_SETUP_CONSUMERS)
152  {
153  m_row= &all_setup_consumers_data[m_pos.m_index];
154  m_next_pos.set_after(&m_pos);
155  result= 0;
156  }
157  else
158  {
159  m_row= NULL;
160  result= HA_ERR_END_OF_FILE;
161  }
162 
163  return result;
164 }
165 
166 int table_setup_consumers::rnd_pos(const void *pos)
167 {
168  set_position(pos);
169  DBUG_ASSERT(m_pos.m_index < COUNT_SETUP_CONSUMERS);
170  m_row= &all_setup_consumers_data[m_pos.m_index];
171  return 0;
172 }
173 
175  unsigned char *,
176  Field **fields,
177  bool read_all)
178 {
179  Field *f;
180 
181  DBUG_ASSERT(m_row);
182 
183 
184  /* Set the null bits */
185  DBUG_ASSERT(table->s->null_bytes == 0);
186 
187  for (; (f= *fields) ; fields++)
188  {
189  if (read_all || bitmap_is_set(table->read_set, f->field_index))
190  {
191  switch(f->field_index)
192  {
193  case 0: /* NAME */
194  set_field_varchar_utf8(f, m_row->m_name.str, m_row->m_name.length);
195  break;
196  case 1: /* ENABLED */
197  set_field_enum(f, (*m_row->m_enabled_ptr) ? ENUM_YES : ENUM_NO);
198  break;
199  default:
200  DBUG_ASSERT(false);
201  }
202  }
203  }
204 
205  return 0;
206 }
207 
209  const unsigned char *,
210  unsigned char *,
211  Field **fields)
212 {
213  Field *f;
214  enum_yes_no value;
215 
216  DBUG_ASSERT(m_row);
217 
218  for (; (f= *fields) ; fields++)
219  {
220  if (bitmap_is_set(table->write_set, f->field_index))
221  {
222  switch(f->field_index)
223  {
224  case 0: /* NAME */
225  return HA_ERR_WRONG_COMMAND;
226  case 1: /* ENABLED */
227  {
228  value= (enum_yes_no) get_field_enum(f);
229  *m_row->m_enabled_ptr= (value == ENUM_YES) ? true : false;
230  break;
231  }
232  default:
233  DBUG_ASSERT(false);
234  }
235  }
236  }
237 
238  if (m_row->m_refresh)
240 
241  return 0;
242 }
243 
244