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
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#ifndef PFS_EVENTS_STATEMENTS_H
17#define PFS_EVENTS_STATEMENTS_H
18
19/**
20 @file storage/perfschema/pfs_events_statements.h
21 Events statements data structures (declarations).
22*/
23
24#include "pfs_column_types.h"
25#include "pfs_events.h"
26#include "pfs_digest.h"
27
28struct PFS_thread;
29struct PFS_account;
30struct PFS_user;
31struct PFS_host;
32
33/** A statement record. */
34struct PFS_events_statements : public PFS_events
35{
36 /** Database name. */
37 char m_current_schema_name[NAME_LEN];
38 /** Length of @c m_current_schema_name. */
39 uint m_current_schema_name_length;
40 /** SQL_TEXT */
41 char m_sqltext[COL_INFO_SIZE];
42 /** Length of @ m_info. */
43 uint m_sqltext_length;
44
45 /** Locked time. */
46 ulonglong m_lock_time;
47
48 /** Diagnostics area, message text. */
49 char m_message_text[MYSQL_ERRMSG_SIZE+1];
50 /** Diagnostics area, error number. */
51 uint m_sql_errno;
52 /** Diagnostics area, SQLSTATE. */
53 char m_sqlstate[SQLSTATE_LENGTH];
54 /** Diagnostics area, error count. */
55 uint m_error_count;
56 /** Diagnostics area, warning count. */
57 uint m_warning_count;
58 /** Diagnostics area, rows affected. */
59 ulonglong m_rows_affected;
60
61 /** Optimizer metric, number of rows sent. */
62 ulonglong m_rows_sent;
63 /** Optimizer metric, number of rows examined. */
64 ulonglong m_rows_examined;
65 /** Optimizer metric, number of temporary tables created on disk. */
66 ulonglong m_created_tmp_disk_tables;
67 /** Optimizer metric, number of temporary tables created. */
68 ulonglong m_created_tmp_tables;
69 /** Optimizer metric, number of full join. */
70 ulonglong m_select_full_join;
71 /** Optimizer metric, number of full range join. */
72 ulonglong m_select_full_range_join;
73 /** Optimizer metric, number of select range. */
74 ulonglong m_select_range;
75 /** Optimizer metric, number of select range checks. */
76 ulonglong m_select_range_check;
77 /** Optimizer metric, number of select scans. */
78 ulonglong m_select_scan;
79 /** Optimizer metric, number of sort merge passes. */
80 ulonglong m_sort_merge_passes;
81 /** Optimizer metric, number of sort ranges. */
82 ulonglong m_sort_range;
83 /** Optimizer metric, number of sort rows. */
84 ulonglong m_sort_rows;
85 /** Optimizer metric, number of sort scans. */
86 ulonglong m_sort_scan;
87 /** Optimizer metric, number of 'no index used'. */
88 ulonglong m_no_index_used;
89 /** Optimizer metric, number of 'no good index used'. */
90 ulonglong m_no_good_index_used;
91
92 /** True if sqltext was truncated. */
93 bool m_sqltext_truncated;
94 /** Statement character set number. */
95 uint m_sqltext_cs_number;
96
97 /**
98 Statement digest.
99 This underlying token array storage pointer is immutable,
100 and always point to pre allocated memory.
101 */
102 sql_digest_storage m_digest_storage;
103};
104
105void insert_events_statements_history(PFS_thread *thread, PFS_events_statements *statement);
106void insert_events_statements_history_long(PFS_events_statements *statement);
107
108extern bool flag_events_statements_current;
109extern bool flag_events_statements_history;
110extern bool flag_events_statements_history_long;
111
112extern bool events_statements_history_long_full;
113extern volatile uint32 events_statements_history_long_index;
114extern PFS_events_statements *events_statements_history_long_array;
115extern size_t events_statements_history_long_size;
116
117int init_events_statements_history_long(size_t events_statements_history_long_sizing);
118void cleanup_events_statements_history_long();
119
120void reset_events_statements_current();
121void reset_events_statements_history();
122void reset_events_statements_history_long();
123void reset_events_statements_by_thread();
124void reset_events_statements_by_account();
125void reset_events_statements_by_user();
126void reset_events_statements_by_host();
127void reset_events_statements_global();
128void aggregate_account_statements(PFS_account *account);
129void aggregate_user_statements(PFS_user *user);
130void aggregate_host_statements(PFS_host *host);
131
132#endif
133
134