summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/include/event_aggregate_setup.inc
blob: f116b09ff0473b97f86a2b25c213a7db6a3c682c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# Tests for the performance schema

# =============
# DOCUMENTATION
# =============

# Verify how events are aggregated into various tables
#
# In the thread dimension:
# - events_waits_summary_by_thread_by_event_name
# - events_waits_summary_by_account_by_event_name
# - events_waits_summary_by_user_by_event_name
# - events_waits_summary_by_host_by_event_name
# - events_stages_summary_by_thread_by_event_name
# - events_stages_summary_by_account_by_event_name
# - events_stages_summary_by_user_by_event_name
# - events_stages_summary_by_host_by_event_name
# - events_statements_summary_by_thread_by_event_name
# - events_statements_summary_by_account_by_event_name
# - events_statements_summary_by_user_by_event_name
# - events_statements_summary_by_host_by_event_name
#
# Globally:
# - events_waits_summary_global_by_event_name
# - events_stages_summary_global_by_event_name
# - events_statements_summary_global_by_event_name
#
# The tests are written with the following helpers:
# - include/event_aggregate_setup.inc
# - include/event_aggregate_load.inc
# - include/event_aggregate_cleanup.inc
#
# Helpers are intended to be used as follows.
#
# A Typical test t/event_aggregate_xxx.test will consist of:
# --source ../include/event_aggregate_setup.inc
# --source ../include/event_aggregate_load.inc
# --source ../include/event_aggregate_cleanup.inc
# and a t/event_aggregate_xxx-master.opt file
#
# Naming conventions for t/event_aggregate_xxx.test are as follows:
# t/event_aggregate_<account><user><host>
#
# <account> corresponds to different sizing settings for 
# the variable performance-schema-accounts-size
# - (blank): accounts-size sufficient to represent all records
# - no_a: accounts-size set to 0
#
# <user> corresponds to different sizing settings for 
# the variable performance-schema-users-size
# - (blank): users-size sufficient to represent all records
# - no_u: users-size set to 0
#
# <host> corresponds to different sizing settings for 
# the variable performance-schema-hosts-size
# - (blank): hosts-size sufficient to represent all records
# - no_h: hosts-size set to 0

# ========================================
# HELPER include/event_aggregate_setup.inc
# ========================================

--source include/not_embedded.inc
--source include/have_perfschema.inc
--source include/no_protocol.inc
--source ../include/wait_for_pfs_thread_count.inc

--disable_query_log
create user user1@localhost;
grant ALL on *.* to user1@localhost;
create user user2@localhost;
grant ALL on *.* to user2@localhost;
create user user3@localhost;
grant ALL on *.* to user3@localhost;
create user user4@localhost;
grant ALL on *.* to user4@localhost;

flush privileges;

# Purge old users, hosts, user/host from previous tests
truncate table performance_schema.accounts;
truncate table performance_schema.users;
truncate table performance_schema.hosts;

# Save the setup

--disable_warnings
drop table if exists test.setup_actors;
drop table if exists test.t1;
--enable_warnings

create table test.t1(a varchar(64));

create table test.setup_actors as
  select * from performance_schema.setup_actors;

# Only instrument the user connections
truncate table performance_schema.setup_actors;
insert into performance_schema.setup_actors
  set host= 'localhost', user= 'user1', role= '%';
insert into performance_schema.setup_actors
  set host= 'localhost', user= 'user2', role= '%';
insert into performance_schema.setup_actors
  set host= 'localhost', user= 'user3', role= '%';
insert into performance_schema.setup_actors
  set host= 'localhost', user= 'user4', role= '%';

update performance_schema.threads set instrumented='NO';

# Only instrument a few events of each kind
update performance_schema.setup_instruments set enabled='NO', timed='NO';

update performance_schema.setup_instruments set enabled='YES', timed='YES'
  where name in ('wait/synch/mutex/sql/LOCK_connection_count',
                 'wait/synch/mutex/sql/LOCK_user_locks',
                 'wait/synch/rwlock/sql/LOCK_grant',
                 'wait/io/file/sql/query_log',
                 'idle');

update performance_schema.setup_instruments set enabled='YES', timed='YES'
  where name in ('stage/sql/Init', 'stage/sql/Init for update',
                 'stage/sql/Checking permissions',
                 'stage/sql/Opening tables',
                 'stage/sql/Closing tables');

update performance_schema.setup_instruments set enabled='YES', timed='YES'
  where name in ('statement/sql/select',
                 'statement/sql/insert',
                 'statement/abstract/new_packet',
                 'statement/abstract/Query',
                 'statement/com/Quit',
                 'statement/com/error');

# Start from a known clean state, to avoid noise from previous tests
flush tables;
flush status;
truncate performance_schema.events_waits_summary_by_thread_by_event_name;
truncate performance_schema.events_waits_summary_by_account_by_event_name;
truncate performance_schema.events_waits_summary_by_user_by_event_name;
truncate performance_schema.events_waits_summary_by_host_by_event_name;
truncate performance_schema.events_waits_summary_global_by_event_name;
truncate performance_schema.events_waits_history_long;

truncate performance_schema.events_stages_summary_by_thread_by_event_name;
truncate performance_schema.events_stages_summary_by_account_by_event_name;
truncate performance_schema.events_stages_summary_by_user_by_event_name;
truncate performance_schema.events_stages_summary_by_host_by_event_name;
truncate performance_schema.events_stages_summary_global_by_event_name;
truncate performance_schema.events_stages_history_long;

truncate performance_schema.events_statements_summary_by_thread_by_event_name;
truncate performance_schema.events_statements_summary_by_account_by_event_name;
truncate performance_schema.events_statements_summary_by_user_by_event_name;
truncate performance_schema.events_statements_summary_by_host_by_event_name;
truncate performance_schema.events_statements_summary_global_by_event_name;
truncate performance_schema.events_statements_history_long;

--disable_warnings
drop procedure if exists dump_thread;
drop procedure if exists dump_one_thread;
--enable_warnings

delimiter $$;

create procedure dump_thread()
begin
  call dump_one_thread('user1');
  call dump_one_thread('user2');
  call dump_one_thread('user3');
  call dump_one_thread('user4');
end
$$

create procedure dump_one_thread(in username varchar(64))
begin
  declare my_thread_id int;

  set my_thread_id = (select thread_id from performance_schema.threads
                        where processlist_user=username);

  if (my_thread_id is not null) then
    select username, event_name, count_star
      from performance_schema.events_waits_summary_by_thread_by_event_name
      where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                           'wait/synch/mutex/sql/LOCK_user_locks',
                           'wait/synch/rwlock/sql/LOCK_grant',
                           'wait/io/file/sql/query_log')
      and thread_id = my_thread_id
      order by event_name;
  else
    select username, "not found" as status;
  end if;
end
$$

delimiter ;$$

prepare dump_waits_account from
  "select user, host, event_name, count_star
  from performance_schema.events_waits_summary_by_account_by_event_name
  where user like \'user%\'
  and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                     'wait/synch/mutex/sql/LOCK_user_locks',
                     'wait/synch/rwlock/sql/LOCK_grant',
                     'wait/io/file/sql/query_log')
  order by user, host, event_name;";

prepare dump_waits_user from
  "select user, event_name, count_star
  from performance_schema.events_waits_summary_by_user_by_event_name
  where user like \'user%\'
  and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                     'wait/synch/mutex/sql/LOCK_user_locks',
                     'wait/synch/rwlock/sql/LOCK_grant',
                     'wait/io/file/sql/query_log')
  order by user, event_name;";

prepare dump_waits_host from
  "select host, event_name, count_star
  from performance_schema.events_waits_summary_by_host_by_event_name
  where host=\'localhost\'
  and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                     'wait/synch/mutex/sql/LOCK_user_locks',
                     'wait/synch/rwlock/sql/LOCK_grant',
                     'wait/io/file/sql/query_log')
  order by host, event_name;";

prepare dump_waits_global from
  "select event_name, count_star
  from performance_schema.events_waits_summary_global_by_event_name
  where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                       'wait/synch/mutex/sql/LOCK_user_locks',
                       'wait/synch/rwlock/sql/LOCK_grant',
                       'wait/io/file/sql/query_log')
  order by event_name;";

prepare dump_waits_history from
  "select event_name, count(event_name)
  from performance_schema.events_waits_history_long
  where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
                       'wait/synch/mutex/sql/LOCK_user_locks',
                       'wait/synch/rwlock/sql/LOCK_grant',
                       'wait/io/file/sql/query_log')
  group by event_name order by event_name;";

prepare dump_stages_account from
  "select user, host, event_name, count_star
  from performance_schema.events_stages_summary_by_account_by_event_name
  where user like \'user%\'
  and event_name in ('stage/sql/init', 'stage/sql/Init for update',
                     'stage/sql/checking permissions',
                     'stage/sql/Opening tables',
                     'stage/sql/closing tables')
  order by user, host, event_name;";

prepare dump_stages_user from
  "select user, event_name, count_star
  from performance_schema.events_stages_summary_by_user_by_event_name
  where user like \'user%\'
  and event_name in ('stage/sql/init', 'stage/sql/Init for update',
                     'stage/sql/checking permissions',
                     'stage/sql/Opening tables',
                     'stage/sql/closing tables')
  order by user, event_name;";

prepare dump_stages_host from
  "select host, event_name, count_star
  from performance_schema.events_stages_summary_by_host_by_event_name
  where host=\'localhost\'
  and event_name in ('stage/sql/init', 'stage/sql/Init for update',
                     'stage/sql/checking permissions',
                     'stage/sql/Opening tables',
                     'stage/sql/closing tables')
  order by host, event_name;";

prepare dump_stages_global from
  "select event_name, count_star
  from performance_schema.events_stages_summary_global_by_event_name
  where event_name in ('stage/sql/init', 'stage/sql/Init for update',
                       'stage/sql/checking permissions',
                       'stage/sql/Opening tables',
                       'stage/sql/closing tables')
  order by event_name;";

prepare dump_stages_history from
  "select event_name, count(event_name)
  from performance_schema.events_stages_history_long
  where event_name in ('stage/sql/init', 'stage/sql/Init for update',
                       'stage/sql/checking permissions',
                       'stage/sql/Opening tables',
                       'stage/sql/closing tables')
  group by event_name order by event_name;";

prepare dump_statements_account from
  "select user, host, event_name, count_star
  from performance_schema.events_statements_summary_by_account_by_event_name
  where user like \'user%\'
  and event_name in ('statement/sql/select',
                     'statement/sql/insert',
                     'statement/com/Quit',
                     'statement/com/error')
  order by user, host, event_name;";

prepare dump_statements_user from
  "select user, event_name, count_star
  from performance_schema.events_statements_summary_by_user_by_event_name
  where user like \'user%\'
  and event_name in ('statement/sql/select',
                     'statement/sql/insert',
                     'statement/com/Quit',
                     'statement/com/error')
  order by user, event_name;";

prepare dump_statements_host from
  "select host, event_name, count_star
  from performance_schema.events_statements_summary_by_host_by_event_name
  where host=\'localhost\'
  and event_name in ('statement/sql/select',
                     'statement/sql/insert',
                     'statement/com/Quit',
                     'statement/com/error')
  order by host, event_name;";

prepare dump_statements_global from
  "select event_name, count_star
  from performance_schema.events_statements_summary_global_by_event_name
  where event_name in ('statement/sql/select',
                       'statement/sql/insert',
                       'statement/com/Quit',
                       'statement/com/error')
  order by event_name;";

prepare dump_statements_history from
  "select event_name, count(event_name)
  from performance_schema.events_statements_history_long
  where event_name in ('statement/sql/select',
                       'statement/sql/insert',
                       'statement/com/Quit',
                       'statement/com/error')
  group by event_name order by event_name;";

prepare dump_users from
  "select * from performance_schema.users where user is not null order by user;";

prepare dump_hosts from
  "select * from performance_schema.hosts where host is not null order by host;";

prepare dump_accounts from
  "select * from performance_schema.accounts where (user is not null) and (host is not null) order by user, host;";

--enable_query_log