1/* Copyright (c) 2010, 2013, 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
16/**
17 @file storage/perfschema/table_esms_global_by_event_name.cc
18 Table EVENTS_STATEMENTS_SUMMARY_GLOBAL_BY_EVENT_NAME (implementation).
19*/
20
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"
26#include "table_esms_global_by_event_name.h"
27#include "pfs_global.h"
28#include "pfs_instr.h"
29#include "pfs_timer.h"
30#include "pfs_visitor.h"
31
32THR_LOCK table_esms_global_by_event_name::m_table_lock;
33
34PFS_engine_table_share
35table_esms_global_by_event_name::m_share=
36{
37 { C_STRING_WITH_LEN("events_statements_summary_global_by_event_name") },
38 &pfs_truncatable_acl,
39 table_esms_global_by_event_name::create,
40 NULL, /* write_row */
41 table_esms_global_by_event_name::delete_all_rows,
42 NULL, /* get_row_count */
43 1000, /* records */
44 sizeof(PFS_simple_index),
45 &m_table_lock,
46 { C_STRING_WITH_LEN("CREATE TABLE events_statements_summary_global_by_event_name("
47 "EVENT_NAME VARCHAR(128) not null,"
48 "COUNT_STAR BIGINT unsigned not null,"
49 "SUM_TIMER_WAIT BIGINT unsigned not null,"
50 "MIN_TIMER_WAIT BIGINT unsigned not null,"
51 "AVG_TIMER_WAIT BIGINT unsigned not null,"
52 "MAX_TIMER_WAIT BIGINT unsigned not null,"
53 "SUM_LOCK_TIME BIGINT unsigned not null,"
54 "SUM_ERRORS BIGINT unsigned not null,"
55 "SUM_WARNINGS BIGINT unsigned not null,"
56 "SUM_ROWS_AFFECTED BIGINT unsigned not null,"
57 "SUM_ROWS_SENT BIGINT unsigned not null,"
58 "SUM_ROWS_EXAMINED BIGINT unsigned not null,"
59 "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null,"
60 "SUM_CREATED_TMP_TABLES BIGINT unsigned not null,"
61 "SUM_SELECT_FULL_JOIN BIGINT unsigned not null,"
62 "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null,"
63 "SUM_SELECT_RANGE BIGINT unsigned not null,"
64 "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null,"
65 "SUM_SELECT_SCAN BIGINT unsigned not null,"
66 "SUM_SORT_MERGE_PASSES BIGINT unsigned not null,"
67 "SUM_SORT_RANGE BIGINT unsigned not null,"
68 "SUM_SORT_ROWS BIGINT unsigned not null,"
69 "SUM_SORT_SCAN BIGINT unsigned not null,"
70 "SUM_NO_INDEX_USED BIGINT unsigned not null,"
71 "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null)") }
72};
73
74PFS_engine_table*
75table_esms_global_by_event_name::create(void)
76{
77 return new table_esms_global_by_event_name();
78}
79
80int
81table_esms_global_by_event_name::delete_all_rows(void)
82{
83 reset_events_statements_by_thread();
84 reset_events_statements_by_account();
85 reset_events_statements_by_user();
86 reset_events_statements_by_host();
87 reset_events_statements_global();
88 return 0;
89}
90
91table_esms_global_by_event_name::table_esms_global_by_event_name()
92 : PFS_engine_table(&m_share, &m_pos),
93 m_row_exists(false), m_pos(1), m_next_pos(1)
94{}
95
96void table_esms_global_by_event_name::reset_position(void)
97{
98 m_pos= 1;
99 m_next_pos= 1;
100}
101
102int table_esms_global_by_event_name::rnd_init(bool scan)
103{
104 m_normalizer= time_normalizer::get(statement_timer);
105 return 0;
106}
107
108int table_esms_global_by_event_name::rnd_next(void)
109{
110 PFS_statement_class *statement_class;
111
112 if (global_instr_class_statements_array == NULL)
113 return HA_ERR_END_OF_FILE;
114
115 m_pos.set_at(&m_next_pos);
116
117 statement_class= find_statement_class(m_pos.m_index);
118 if (statement_class)
119 {
120 make_row(statement_class);
121 m_next_pos.set_after(&m_pos);
122 return 0;
123 }
124
125 return HA_ERR_END_OF_FILE;
126}
127
128int
129table_esms_global_by_event_name::rnd_pos(const void *pos)
130{
131 PFS_statement_class *statement_class;
132
133 set_position(pos);
134
135 if (global_instr_class_statements_array == NULL)
136 return HA_ERR_END_OF_FILE;
137
138 statement_class=find_statement_class(m_pos.m_index);
139 if (statement_class)
140 {
141 make_row(statement_class);
142 return 0;
143 }
144
145 return HA_ERR_RECORD_DELETED;
146}
147
148
149void table_esms_global_by_event_name
150::make_row(PFS_statement_class *klass)
151{
152 m_row_exists= false;
153
154 if (klass->is_mutable())
155 return;
156
157 m_row.m_event_name.make_row(klass);
158
159 PFS_connection_statement_visitor visitor(klass);
160 PFS_connection_iterator::visit_global(true, /* hosts */
161 false, /* users */
162 true, true, & visitor);
163
164 m_row.m_stat.set(m_normalizer, & visitor.m_stat);
165 m_row_exists= true;
166}
167
168int table_esms_global_by_event_name
169::read_row_values(TABLE *table, unsigned char *, Field **fields,
170 bool read_all)
171{
172 Field *f;
173
174 if (unlikely(! m_row_exists))
175 return HA_ERR_RECORD_DELETED;
176
177 /* Set the null bits */
178 DBUG_ASSERT(table->s->null_bytes == 0);
179
180 for (; (f= *fields) ; fields++)
181 {
182 if (read_all || bitmap_is_set(table->read_set, f->field_index))
183 {
184 switch(f->field_index)
185 {
186 case 0: /* NAME */
187 m_row.m_event_name.set_field(f);
188 break;
189 default: /* 1, ... COUNT/SUM/MIN/AVG/MAX */
190 m_row.m_stat.set_field(f->field_index - 1, f);
191 break;
192 }
193 }
194 }
195
196 return 0;
197}
198
199