1 # Tests for the performance schema
7 # Verify critical stages of a statement
9 # The tests are written with the following helpers:
10 # - include/stage_setup.inc
11 # - include/stage_cleanup.inc
13 # Helpers are intended to be used as follows.
15 # A Typical test t/stage_xxx.test will consist of:
16 # --source ../include/stage_setup.inc
17 # ... test specific payload ...
18 # --source ../include/stage_cleanup.inc
19 # and a t/stage_xxx-master.opt file
21 # ==============================
22 # HELPER include/stage_setup.inc
23 # ==============================
25 --source include/not_embedded.inc
26 --source include/have_perfschema.inc
27 --source ../include/no_protocol.inc
31 grant ALL on *.*
to user1@localhost;
32 grant ALL on *.*
to user2@localhost;
33 grant ALL on *.*
to user3@localhost;
34 grant ALL on *.*
to user4@localhost;
48 select * from performance_schema.setup_actors;
50 # Only instrument the user connections
51 truncate
table performance_schema.setup_actors;
52 insert into performance_schema.setup_actors
53 set host=
'localhost', user=
'user1', role=
'%';
54 insert into performance_schema.setup_actors
55 set host=
'localhost', user=
'user2', role=
'%';
56 insert into performance_schema.setup_actors
57 set host=
'localhost', user=
'user3', role=
'%';
58 insert into performance_schema.setup_actors
59 set host=
'localhost', user=
'user4', role=
'%';
61 update performance_schema.threads
set instrumented=
'NO';
63 # Only instrument a few events of each kind
64 update performance_schema.setup_instruments
set enabled=
'YES', timed=
'YES';
66 # Start from a known clean state, to avoid noise from previous tests
69 truncate performance_schema.events_stages_summary_by_thread_by_event_name;
70 truncate performance_schema.events_stages_summary_global_by_event_name;
71 truncate performance_schema.events_stages_history;
72 truncate performance_schema.events_stages_history_long;
73 truncate performance_schema.events_statements_summary_by_thread_by_event_name;
74 truncate performance_schema.events_statements_summary_global_by_event_name;
75 truncate performance_schema.events_statements_history;
76 truncate performance_schema.events_statements_history_long;
79 drop procedure
if exists dump_thread;
80 drop procedure
if exists dump_one_thread;
85 create procedure dump_thread()
87 call dump_one_thread('user1');
88 call dump_one_thread('user2');
89 call dump_one_thread('user3');
90 call dump_one_thread('user4');
94 create procedure dump_one_thread(in username varchar(64))
96 declare my_thread_id
int;
97 declare my_statement_id
int;
99 set my_thread_id = (select thread_id from performance_schema.threads
100 where processlist_user=username);
102 if (my_thread_id is not null) then
104 # Dump the current statement for this thread
105 select username, event_name, sql_text
106 from performance_schema.events_statements_current
107 where thread_id = my_thread_id;
109 # Get the current statement
110 set my_statement_id = (select event_id from
111 performance_schema.events_statements_current
112 where thread_id = my_thread_id);
114 # Dump the stages for this statement
115 select username, event_name, nesting_event_type
116 from performance_schema.events_stages_current
117 where thread_id = my_thread_id
118 and nesting_event_id = my_statement_id
119 order by event_id asc;
120 select username, event_name, nesting_event_type
121 from performance_schema.events_stages_history
122 where thread_id = my_thread_id
123 and nesting_event_id = my_statement_id
124 order by event_id asc;
127 select username,
"not found" as status;