1/* Copyright (c) 2010, 2015, 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
16#ifndef TABLE_EVENTS_STATEMENTS_H
17#define TABLE_EVENTS_STATEMENTS_H
18
19/**
20 @file storage/perfschema/table_events_statements.h
21 Table EVENTS_STATEMENTS_xxx (declarations).
22*/
23
24#include "pfs_column_types.h"
25#include "pfs_engine_table.h"
26#include "pfs_events_statements.h"
27#include "table_helper.h"
28
29struct PFS_thread;
30
31/**
32 @addtogroup Performance_schema_tables
33 @{
34*/
35
36/** A row of table_events_statements_common. */
37struct row_events_statements
38{
39 /** Column THREAD_ID. */
40 ulonglong m_thread_internal_id;
41 /** Column EVENT_ID. */
42 ulonglong m_event_id;
43 /** Column END_EVENT_ID. */
44 ulonglong m_end_event_id;
45 /** Column NESTING_EVENT_ID. */
46 ulonglong m_nesting_event_id;
47 /** Column NESTING_EVENT_TYPE. */
48 enum_event_type m_nesting_event_type;
49 /** Column EVENT_NAME. */
50 const char *m_name;
51 /** Length in bytes of @c m_name. */
52 uint m_name_length;
53 /** Column TIMER_START. */
54 ulonglong m_timer_start;
55 /** Column TIMER_END. */
56 ulonglong m_timer_end;
57 /** Column TIMER_WAIT. */
58 ulonglong m_timer_wait;
59 /** Column LOCK_TIME. */
60 ulonglong m_lock_time;
61 /** Column SOURCE. */
62 char m_source[COL_SOURCE_SIZE];
63 /** Length in bytes of @c m_source. */
64 uint m_source_length;
65 /** Column SQL_TEXT. */
66 String m_sqltext;
67 /** Column DIGEST and DIGEST_TEXT. */
68 PFS_digest_row m_digest;
69 /** Column CURRENT_SCHEMA. */
70 char m_current_schema_name[NAME_LEN];
71 /** Length in bytes of @c m_current_schema_name. */
72 uint m_current_schema_name_length;
73
74 /** Column MESSAGE_TEXT. */
75 char m_message_text[MYSQL_ERRMSG_SIZE+1];
76 /** Column MYSQL_ERRNO. */
77 uint m_sql_errno;
78 /** Column RETURNED_SQLSTATE. */
79 char m_sqlstate[SQLSTATE_LENGTH];
80 /** Column ERRORS. */
81 uint m_error_count;
82 /** Column WARNINGS. */
83 uint m_warning_count;
84 /** Column ROWS_AFFECTED. */
85 ulonglong m_rows_affected;
86 /** Column ROWS_SENT. */
87 ulonglong m_rows_sent;
88 /** Column ROWS_EXAMINED. */
89 ulonglong m_rows_examined;
90 /** Column CREATED_TMP_DISK_TABLES. */
91 ulonglong m_created_tmp_disk_tables;
92 /** Column CREATED_TMP_TABLES. */
93 ulonglong m_created_tmp_tables;
94 /** Column SELECT_FULL_JOIN. */
95 ulonglong m_select_full_join;
96 /** Column SELECT_FULL_RANGE_JOIN. */
97 ulonglong m_select_full_range_join;
98 /** Column SELECT_RANGE. */
99 ulonglong m_select_range;
100 /** Column SELECT_RANGE_CHECK. */
101 ulonglong m_select_range_check;
102 /** Column SELECT_SCAN. */
103 ulonglong m_select_scan;
104 /** Column SORT_MERGE_PASSES. */
105 ulonglong m_sort_merge_passes;
106 /** Column SORT_RANGE. */
107 ulonglong m_sort_range;
108 /** Column SORT_ROWS. */
109 ulonglong m_sort_rows;
110 /** Column SORT_SCAN. */
111 ulonglong m_sort_scan;
112 /** Column NO_INDEX_USED. */
113 ulonglong m_no_index_used;
114 /** Column NO_GOOD_INDEX_USED. */
115 ulonglong m_no_good_index_used;
116};
117
118/** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_CURRENT. */
119struct pos_events_statements_current : public PFS_double_index
120{
121 pos_events_statements_current()
122 : PFS_double_index(0, 0)
123 {}
124
125 inline void reset(void)
126 {
127 m_index_1= 0;
128 m_index_2= 0;
129 }
130
131 inline void next_thread(void)
132 {
133 m_index_1++;
134 m_index_2= 0;
135 }
136};
137
138/** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_HISTORY. */
139struct pos_events_statements_history : public PFS_double_index
140{
141 pos_events_statements_history()
142 : PFS_double_index(0, 0)
143 {}
144
145 inline void reset(void)
146 {
147 m_index_1= 0;
148 m_index_2= 0;
149 }
150
151 inline void next_thread(void)
152 {
153 m_index_1++;
154 m_index_2= 0;
155 }
156};
157
158/**
159 Adapter, for table sharing the structure of
160 PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_CURRENT.
161*/
162class table_events_statements_common : public PFS_engine_table
163{
164protected:
165 virtual int read_row_values(TABLE *table,
166 unsigned char *buf,
167 Field **fields,
168 bool read_all);
169
170 table_events_statements_common(const PFS_engine_table_share *share, void *pos);
171
172 ~table_events_statements_common()
173 {}
174
175 void make_row_part_1(PFS_events_statements *statement,
176 sql_digest_storage *digest);
177
178 void make_row_part_2(const sql_digest_storage *digest);
179
180 /** Current row. */
181 row_events_statements m_row;
182 /** True if the current row exists. */
183 bool m_row_exists;
184 unsigned char m_token_array[MAX_DIGEST_STORAGE_SIZE];
185};
186
187/** Table PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_CURRENT. */
188class table_events_statements_current : public table_events_statements_common
189{
190public:
191 /** Table share */
192 static PFS_engine_table_share m_share;
193 static PFS_engine_table* create();
194 static int delete_all_rows();
195
196 virtual int rnd_init(bool scan);
197 virtual int rnd_next();
198 virtual int rnd_pos(const void *pos);
199 virtual void reset_position(void);
200
201protected:
202 table_events_statements_current();
203
204public:
205 ~table_events_statements_current()
206 {}
207
208private:
209 friend class table_events_statements_history;
210 friend class table_events_statements_history_long;
211
212 /** Table share lock. */
213 static THR_LOCK m_table_lock;
214
215 void make_row(PFS_thread* pfs_thread, PFS_events_statements *statement);
216
217 /** Current position. */
218 pos_events_statements_current m_pos;
219 /** Next position. */
220 pos_events_statements_current m_next_pos;
221};
222
223/** Table PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_HISTORY. */
224class table_events_statements_history : public table_events_statements_common
225{
226public:
227 /** Table share */
228 static PFS_engine_table_share m_share;
229 static PFS_engine_table* create();
230 static int delete_all_rows();
231
232 virtual int rnd_init(bool scan);
233 virtual int rnd_next();
234 virtual int rnd_pos(const void *pos);
235 virtual void reset_position(void);
236
237protected:
238 table_events_statements_history();
239
240public:
241 ~table_events_statements_history()
242 {}
243
244private:
245 /** Table share lock. */
246 static THR_LOCK m_table_lock;
247
248 void make_row(PFS_thread* pfs_thread, PFS_events_statements *statement);
249
250 /** Current position. */
251 pos_events_statements_history m_pos;
252 /** Next position. */
253 pos_events_statements_history m_next_pos;
254};
255
256/** Table PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_HISTORY_LONG. */
257class table_events_statements_history_long : public table_events_statements_common
258{
259public:
260 /** Table share */
261 static PFS_engine_table_share m_share;
262 static PFS_engine_table* create();
263 static int delete_all_rows();
264
265 virtual int rnd_init(bool scan);
266 virtual int rnd_next();
267 virtual int rnd_pos(const void *pos);
268 virtual void reset_position(void);
269
270protected:
271 table_events_statements_history_long();
272
273public:
274 ~table_events_statements_history_long()
275 {}
276
277private:
278 /** Table share lock. */
279 static THR_LOCK m_table_lock;
280
281 void make_row(PFS_events_statements *statement);
282
283 /** Current position. */
284 PFS_simple_index m_pos;
285 /** Next position. */
286 PFS_simple_index m_next_pos;
287};
288
289/** @} */
290#endif
291