1 # Tests for the performance schema
7 # Verify how events are aggregated into various tables
9 # In the thread dimension:
10 # - events_waits_summary_by_thread_by_event_name
11 # - events_waits_summary_by_account_by_event_name
12 # - events_waits_summary_by_user_by_event_name
13 # - events_waits_summary_by_host_by_event_name
14 # - events_stages_summary_by_thread_by_event_name
15 # - events_stages_summary_by_account_by_event_name
16 # - events_stages_summary_by_user_by_event_name
17 # - events_stages_summary_by_host_by_event_name
18 # - events_statements_summary_by_thread_by_event_name
19 # - events_statements_summary_by_account_by_event_name
20 # - events_statements_summary_by_user_by_event_name
21 # - events_statements_summary_by_host_by_event_name
24 # - events_waits_summary_global_by_event_name
25 # - events_stages_summary_global_by_event_name
26 # - events_statements_summary_global_by_event_name
28 # The tests are written with the following helpers:
29 # - include/event_aggregate_setup.inc
30 # - include/event_aggregate_load.inc
31 # - include/event_aggregate_cleanup.inc
33 # Helpers are intended to be used as follows.
35 # A Typical test t/event_aggregate_xxx.test will consist of:
36 # --source ../include/event_aggregate_setup.inc
37 # --source ../include/event_aggregate_load.inc
38 # --source ../include/event_aggregate_cleanup.inc
39 # and a t/event_aggregate_xxx-master.opt file
41 # Naming conventions for t/event_aggregate_xxx.test are as follows:
42 # t/event_aggregate_<account><user><host>
44 # <account> corresponds to different sizing settings for
45 # the variable performance-schema-accounts-size
46 # - (blank): accounts-size sufficient to represent all records
47 # - no_a: accounts-size set to 0
49 # <user> corresponds to different sizing settings for
50 # the variable performance-schema-users-size
51 # - (blank): users-size sufficient to represent all records
52 # - no_u: users-size set to 0
54 # <host> corresponds to different sizing settings for
55 # the variable performance-schema-hosts-size
56 # - (blank): hosts-size sufficient to represent all records
57 # - no_h: hosts-size set to 0
59 # ========================================
60 # HELPER include/event_aggregate_setup.inc
61 # ========================================
63 --source include/not_embedded.inc
64 --source include/have_perfschema.inc
65 --source ../include/no_protocol.inc
66 --source ../include/wait_for_pfs_thread_count.inc
70 grant ALL on *.*
to user1@localhost;
71 grant ALL on *.*
to user2@localhost;
72 grant ALL on *.*
to user3@localhost;
73 grant ALL on *.*
to user4@localhost;
77 # Purge old users, hosts, user/host from previous tests
78 truncate
table performance_schema.accounts;
79 truncate
table performance_schema.users;
80 truncate
table performance_schema.hosts;
92 select * from performance_schema.setup_actors;
94 # Only instrument the user connections
95 truncate
table performance_schema.setup_actors;
96 insert into performance_schema.setup_actors
97 set host=
'localhost', user=
'user1', role=
'%';
98 insert into performance_schema.setup_actors
99 set host=
'localhost', user=
'user2', role=
'%';
100 insert into performance_schema.setup_actors
101 set host=
'localhost', user=
'user3', role=
'%';
102 insert into performance_schema.setup_actors
103 set host=
'localhost', user=
'user4', role=
'%';
105 update performance_schema.threads
set instrumented=
'NO';
107 # Only instrument a few events of each kind
108 update performance_schema.setup_instruments
set enabled=
'NO', timed=
'NO';
110 update performance_schema.setup_instruments
set enabled=
'YES', timed=
'YES'
111 where
name in (
'wait/synch/mutex/sql/LOCK_connection_count',
112 'wait/synch/mutex/sql/LOCK_user_locks',
113 'wait/synch/rwlock/sql/LOCK_grant',
114 'wait/io/file/sql/query_log',
117 update performance_schema.setup_instruments
set enabled=
'YES', timed=
'YES'
118 where
name in (
'stage/sql/init',
119 'stage/sql/checking permissions',
120 'stage/sql/Opening tables',
121 'stage/sql/closing tables');
123 update performance_schema.setup_instruments
set enabled=
'YES', timed=
'YES'
124 where
name in (
'statement/sql/select',
125 'statement/sql/insert',
127 'statement/com/Query',
128 'statement/com/Quit',
129 'statement/com/error');
131 # Start from a known clean state, to avoid noise from previous tests
134 truncate performance_schema.events_waits_summary_by_thread_by_event_name;
135 truncate performance_schema.events_waits_summary_by_account_by_event_name;
136 truncate performance_schema.events_waits_summary_by_user_by_event_name;
137 truncate performance_schema.events_waits_summary_by_host_by_event_name;
138 truncate performance_schema.events_waits_summary_global_by_event_name;
139 truncate performance_schema.events_waits_history_long;
141 truncate performance_schema.events_stages_summary_by_thread_by_event_name;
142 truncate performance_schema.events_stages_summary_by_account_by_event_name;
143 truncate performance_schema.events_stages_summary_by_user_by_event_name;
144 truncate performance_schema.events_stages_summary_by_host_by_event_name;
145 truncate performance_schema.events_stages_summary_global_by_event_name;
146 truncate performance_schema.events_stages_history_long;
148 truncate performance_schema.events_statements_summary_by_thread_by_event_name;
149 truncate performance_schema.events_statements_summary_by_account_by_event_name;
150 truncate performance_schema.events_statements_summary_by_user_by_event_name;
151 truncate performance_schema.events_statements_summary_by_host_by_event_name;
152 truncate performance_schema.events_statements_summary_global_by_event_name;
153 truncate performance_schema.events_statements_history_long;
156 drop procedure
if exists dump_thread;
157 drop procedure
if exists dump_one_thread;
162 create procedure dump_thread()
164 call dump_one_thread('user1');
165 call dump_one_thread('user2');
166 call dump_one_thread('user3');
167 call dump_one_thread('user4');
171 create procedure dump_one_thread(in username varchar(64))
173 declare my_thread_id
int;
175 set my_thread_id = (select thread_id from performance_schema.threads
176 where processlist_user=username);
178 if (my_thread_id is not null) then
179 select username, event_name, count_star
180 from performance_schema.events_waits_summary_by_thread_by_event_name
181 where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
182 'wait/synch/mutex/sql/LOCK_user_locks',
183 'wait/synch/rwlock/sql/LOCK_grant',
184 'wait/io/
file/sql/query_log')
185 and thread_id = my_thread_id
188 select username, "not found" as status;
195 prepare dump_waits_account from
196 "select user, host, event_name, count_star
197 from performance_schema.events_waits_summary_by_account_by_event_name
198 where user like \'user%\'
199 and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
200 'wait/synch/mutex/sql/LOCK_user_locks',
201 'wait/synch/rwlock/sql/LOCK_grant',
202 'wait/io/
file/sql/query_log')
203 order by user, host, event_name;";
205 prepare dump_waits_user from
206 "select user, event_name, count_star
207 from performance_schema.events_waits_summary_by_user_by_event_name
208 where user like \'user%\'
209 and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
210 'wait/synch/mutex/sql/LOCK_user_locks',
211 'wait/synch/rwlock/sql/LOCK_grant',
212 'wait/io/
file/sql/query_log')
213 order by user, event_name;";
215 prepare dump_waits_host from
216 "select host, event_name, count_star
217 from performance_schema.events_waits_summary_by_host_by_event_name
218 where host=\'localhost\'
219 and event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
220 'wait/synch/mutex/sql/LOCK_user_locks',
221 'wait/synch/rwlock/sql/LOCK_grant',
222 'wait/io/
file/sql/query_log')
223 order by host, event_name;";
225 prepare dump_waits_global from
226 "select event_name, count_star
227 from performance_schema.events_waits_summary_global_by_event_name
228 where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
229 'wait/synch/mutex/sql/LOCK_user_locks',
230 'wait/synch/rwlock/sql/LOCK_grant',
231 'wait/io/
file/sql/query_log')
232 order by event_name;";
234 prepare dump_waits_history from
235 "select event_name, count(event_name)
236 from performance_schema.events_waits_history_long
237 where event_name in ('wait/synch/mutex/sql/LOCK_connection_count',
238 'wait/synch/mutex/sql/LOCK_user_locks',
239 'wait/synch/rwlock/sql/LOCK_grant',
240 'wait/io/
file/sql/query_log')
241 group by event_name order by event_name;";
243 prepare dump_stages_account from
244 "select user, host, event_name, count_star
245 from performance_schema.events_stages_summary_by_account_by_event_name
246 where user like \'user%\'
247 and event_name in ('stage/sql/init',
248 'stage/sql/checking permissions',
249 'stage/sql/Opening tables',
250 'stage/sql/closing tables')
251 order by user, host, event_name;";
253 prepare dump_stages_user from
254 "select user, event_name, count_star
255 from performance_schema.events_stages_summary_by_user_by_event_name
256 where user like \'user%\'
257 and event_name in ('stage/sql/init',
258 'stage/sql/checking permissions',
259 'stage/sql/Opening tables',
260 'stage/sql/closing tables')
261 order by user, event_name;";
263 prepare dump_stages_host from
264 "select host, event_name, count_star
265 from performance_schema.events_stages_summary_by_host_by_event_name
266 where host=\'localhost\'
267 and event_name in ('stage/sql/init',
268 'stage/sql/checking permissions',
269 'stage/sql/Opening tables',
270 'stage/sql/closing tables')
271 order by host, event_name;";
273 prepare dump_stages_global from
274 "select event_name, count_star
275 from performance_schema.events_stages_summary_global_by_event_name
276 where event_name in ('stage/sql/init',
277 'stage/sql/checking permissions',
278 'stage/sql/Opening tables',
279 'stage/sql/closing tables')
280 order by event_name;";
282 prepare dump_stages_history from
283 "select event_name, count(event_name)
284 from performance_schema.events_stages_history_long
285 where event_name in ('stage/sql/init',
286 'stage/sql/checking permissions',
287 'stage/sql/Opening tables',
288 'stage/sql/closing tables')
289 group by event_name order by event_name;";
291 prepare dump_statements_account from
292 "select user, host, event_name, count_star
293 from performance_schema.events_statements_summary_by_account_by_event_name
294 where user like \'user%\'
295 and event_name in ('
statement/sql/select',
299 order by user, host, event_name;";
301 prepare dump_statements_user from
302 "select user, event_name, count_star
303 from performance_schema.events_statements_summary_by_user_by_event_name
304 where user like \'user%\'
305 and event_name in ('
statement/sql/select',
309 order by user, event_name;";
311 prepare dump_statements_host from
312 "select host, event_name, count_star
313 from performance_schema.events_statements_summary_by_host_by_event_name
314 where host=\'localhost\'
315 and event_name in ('
statement/sql/select',
319 order by host, event_name;";
321 prepare dump_statements_global from
322 "select event_name, count_star
323 from performance_schema.events_statements_summary_global_by_event_name
324 where event_name in ('
statement/sql/select',
328 order by event_name;";
330 prepare dump_statements_history from
331 "select event_name, count(event_name)
332 from performance_schema.events_statements_history_long
333 where event_name in ('
statement/sql/select',
337 group by event_name order by event_name;";
339 prepare dump_users from
340 "select * from performance_schema.users where user is not null order by user;";
342 prepare dump_hosts from
343 "select * from performance_schema.hosts where host is not null order by host;";
345 prepare dump_accounts from
346 "select * from performance_schema.accounts where (user is not null) and (host is not null) order by user, host;";