1 # Tests for the performance schema
7 # Verify how table io is aggregated into various tables
9 # In the instance dimension:
10 # - table_io_waits_summary_by_index_usage
11 # - table_io_waits_summary_by_table
12 # - table_lock_waits_summary_by_table
13 # - objects_summary_global_by_type
15 # In the thread dimension:
16 # - events_waits_summary_by_thread_by_event_name
17 # - events_waits_summary_by_account_by_event_name
18 # - events_waits_summary_by_user_by_event_name
19 # - events_waits_summary_by_host_by_event_name
22 # - events_waits_summary_global_by_event_name
24 # The tests are written with the following helpers:
25 # - include/table_aggregate_setup.inc
26 # - include/table_aggregate_load.inc
27 # - include/table_aggregate_cleanup.inc
29 # Helpers are intended to be used as follows.
31 # A Typical test t/table_aggregate_xxx.test will consist of:
32 # --source ../include/table_aggregate_setup.inc
34 # ... statements to modify the default configuration ...
36 # --source ../include/table_aggregate_load.inc
37 # --source ../include/table_aggregate_cleanup.inc
39 # Naming conventions for t/table_aggregate_xxx.test are as follows:
40 # t/<instrument>aggregate_<mode><actors><objects>
42 # <instrument> corresponds to different instruments settings
43 # - table: both table io and table lock are instrumented
44 # - table_io: only table io is instrumented
45 # - table_lock: only table lock is instrumented
47 # <mode> corresponds to different consumers settings
48 # - off: global_instrumentation OFF
49 # - global: global_instrumentation ON, thread_instrumentation OFF
50 # - thread: global_instrumentation ON, thread_instrumentation ON,
51 # events_* consumers OFF
52 # - history: global_instrumentation ON, thread_instrumentation ON,
53 # events_* consumers ON
55 # <actors> corresponds to different setup_actors settings
56 # - 4u: every test user (user1, user2, user3, user4) is ON
57 # - 2u: (user1, user3) are ON, (user2, user4) are OFF
59 # <objects> corresponds to different setup_objects settings
60 # - 3t: tables t1, t2 and t3 are ON
61 # - 2t: tables t1 and t3 are ON, table t2 is OFF
64 # ========================================
65 # HELPER include/table_aggregate_setup.inc
66 # ========================================
68 --source include/not_embedded.inc
69 --source include/have_perfschema.inc
70 --source ../include/no_protocol.inc
71 --source ../include/wait_for_pfs_thread_count.inc
74 grant ALL on *.*
to user1@localhost;
75 grant ALL on *.*
to user2@localhost;
76 grant ALL on *.*
to user3@localhost;
77 grant ALL on *.*
to user4@localhost;
81 # Purge old users, hosts, user/host from previous tests
82 truncate
table performance_schema.accounts;
83 truncate
table performance_schema.users;
84 truncate
table performance_schema.hosts;
94 select * from performance_schema.setup_actors;
97 select * from performance_schema.setup_objects;
99 # Only instrument the user connections (by default)
100 truncate
table performance_schema.setup_actors;
101 insert into performance_schema.setup_actors
102 set host=
'localhost', user=
'user1', role=
'%';
103 insert into performance_schema.setup_actors
104 set host=
'localhost', user=
'user2', role=
'%';
105 insert into performance_schema.setup_actors
106 set host=
'localhost', user=
'user3', role=
'%';
107 insert into performance_schema.setup_actors
108 set host=
'localhost', user=
'user4', role=
'%';
110 # Only instrument test.t% tables (by default)
111 truncate
table performance_schema.setup_objects;
112 insert into performance_schema.setup_objects
113 set object_type=
'TABLE', object_schema=
'test', object_name=
't1', timed=
'YES';
114 insert into performance_schema.setup_objects
115 set object_type=
'TABLE', object_schema=
'test', object_name=
't2', timed=
'NO';
116 insert into performance_schema.setup_objects
117 set object_type=
'TABLE', object_schema=
'test', object_name=
't3', timed=
'NO';
119 update performance_schema.threads
set instrumented=
'NO';
121 # Only instrument table io and lock (by default)
122 update performance_schema.setup_instruments
set enabled=
'NO', timed=
'NO';
123 update performance_schema.setup_instruments
set enabled=
'YES', timed=
'YES'
124 where
name in (
'wait/io/table/sql/handler',
125 'wait/lock/table/sql/handler');
127 # Enable all consumers (by default)
128 update performance_schema.setup_consumers
set enabled=
'YES';
130 # Start from a known clean state, to avoid noise from previous tests
134 create
table test.t1(a
int, b
int, c
int, d
int default 0,
137 index index_cb(c, b));
143 # For test robustness and to avoid picking up noise from other tests scripts,
144 # it is better to use:
145 # in ('t1', 't2', 't3)
146 # explicitly instead of:
150 drop procedure
if exists dump_thread;
151 drop procedure
if exists dump_one_thread;
156 create procedure dump_thread()
158 call dump_one_thread('user1');
159 call dump_one_thread('user2');
160 call dump_one_thread('user3');
161 call dump_one_thread('user4');
165 create procedure dump_one_thread(in username varchar(64))
167 declare my_thread_id
int;
169 set my_thread_id = (select thread_id from performance_schema.threads
170 where processlist_user=username);
172 if (my_thread_id is not null) then
173 select username, event_name, count_star
174 from performance_schema.events_waits_summary_by_thread_by_event_name
177 'wait/lock/
table/sql/handler')
178 and thread_id = my_thread_id
181 select username, "not found" as status;
188 prepare dump_waits_user from
189 "select user, event_name, count_star
190 from performance_schema.events_waits_summary_by_user_by_event_name
191 where user like \'user%\' and event_name in
192 (\'wait/io/
table/sql/handler\',
193 \'wait/lock/
table/sql/handler\')
194 order by user, event_name;";
196 prepare dump_waits_account from
197 "select user, host, event_name, count_star
198 from performance_schema.events_waits_summary_by_account_by_event_name
199 where user like \'user%\' and event_name in
200 (\'wait/io/
table/sql/handler\',
201 \'wait/lock/
table/sql/handler\')
202 order by user, host, event_name;";
204 prepare dump_waits_host from
205 "select host, event_name, count_star
206 from performance_schema.events_waits_summary_by_host_by_event_name
207 where host=\'localhost\' and event_name in
208 (\'wait/io/
table/sql/handler\',
209 \'wait/lock/
table/sql/handler\')
210 order by host, event_name;";
212 prepare dump_waits_global from
213 "select event_name, count_star
214 from performance_schema.events_waits_summary_global_by_event_name
216 (\'wait/io/
table/sql/handler\',
217 \'wait/lock/
table/sql/handler\')
218 order by event_name;";
220 prepare dump_waits_history from
221 "select event_name, count(event_name), object_type, object_schema, object_name
222 from performance_schema.events_waits_history_long
224 (\'wait/io/
table/sql/handler\',
225 \'wait/lock/
table/sql/handler\')
226 group by object_type, object_schema, object_name, event_name
227 order by object_type, object_schema, object_name, event_name;";
229 prepare dump_waits_index_io from
230 "select object_type, object_schema, object_name, index_name,
231 count_star, count_read, count_write,
232 count_fetch, count_insert, count_update, count_delete
233 from performance_schema.table_io_waits_summary_by_index_usage
234 where object_type='
TABLE' and object_schema='
test'
235 and object_name in ('t1', 't2', 't3')
236 order by object_type, object_schema, object_name, index_name;";
238 prepare dump_waits_table_io from
239 "select object_type, object_schema, object_name,
240 count_star, count_read, count_write,
241 count_fetch, count_insert, count_update, count_delete
242 from performance_schema.table_io_waits_summary_by_table
243 where object_type='
TABLE' and object_schema='
test'
244 and object_name in ('t1', 't2', 't3')
245 order by object_type, object_schema, object_name";
247 prepare dump_waits_table_lock from
248 "select object_type, object_schema, object_name,
249 count_star, count_read, count_write,
250 count_read_normal, count_read_with_shared_locks,
251 count_read_high_priority, count_read_no_insert,
253 count_write_delayed, count_write_low_priority,
255 from performance_schema.table_lock_waits_summary_by_table
256 where object_type='
TABLE' and object_schema='
test'
257 and object_name in ('t1', 't2', 't3')
258 order by object_type, object_schema, object_name";
260 prepare dump_objects_summary from
261 "select object_type, object_schema, object_name, count_star
262 from performance_schema.objects_summary_global_by_type
263 where object_type='
TABLE' and object_schema='
test'
264 and object_name in ('t1', 't2', 't3')
265 order by object_type, object_schema, object_name";