1
# Test to check the proper nesting of events
3
--source include/not_embedded.inc
4
--source include/have_perfschema.inc
5
# On windows, the socket instrumentation collects an extra "opt"
6
# event, which changes the test output.
7
--source include/not_windows.inc
8
--source ../include/no_protocol.inc
9
--source ../include/wait_for_pfs_thread_count.inc
10
--source include/have_QC_Disabled.inc
14
grant ALL on *.* to user1@localhost;
19
drop table if exists test.setup_actors;
22
create table test.setup_actors as
23
select * from performance_schema.setup_actors;
25
# Only instrument the user connections
26
truncate table performance_schema.setup_actors;
27
insert into performance_schema.setup_actors
28
set host= 'localhost', user= 'user1', role= '%';
30
update performance_schema.threads set instrumented='NO';
32
# Only instrument a few events of each kind
33
update performance_schema.setup_instruments set enabled='NO', timed='NO';
35
update performance_schema.setup_instruments set enabled='YES', timed='YES'
36
where name in ('idle',
37
'wait/io/table/sql/handler',
38
'wait/lock/table/sql/handler',
39
'wait/io/socket/sql/client_connection',
40
'wait/synch/rwlock/sql/LOCK_grant',
41
'wait/synch/mutex/sql/THD::LOCK_thd_data',
42
'wait/io/file/sql/query_log');
44
update performance_schema.setup_instruments set enabled='YES', timed='YES'
45
where name like ('stage/sql/%');
47
update performance_schema.setup_instruments set enabled='YES', timed='YES'
48
where name in ('statement/sql/select',
49
'statement/abstract/new_packet',
50
'statement/abstract/Query',
51
'statement/com/error');
53
# Start from a known clean state, to avoid noise from previous tests
57
truncate performance_schema.events_waits_current;
58
truncate performance_schema.events_waits_history;
59
truncate performance_schema.events_waits_history_long;
60
truncate performance_schema.events_stages_current;
61
truncate performance_schema.events_stages_history;
62
truncate performance_schema.events_stages_history_long;
63
truncate performance_schema.events_statements_current;
64
truncate performance_schema.events_statements_history;
65
truncate performance_schema.events_statements_history_long;
69
connect (con1, localhost, user1, , );
71
echo "================== con1 connected ==================";
73
select "MARKER_BEGIN" as marker;
75
select "This is simple statement one" as payload;
77
select "This is simple statement two" as payload;
80
select "This is the first part of a multi query" as payload;
81
select "And this is the second part of a multi query" as payload;
82
select "With a third part to make things complete" as payload;
86
select "MARKER_END" as marker;
88
select "Con1 is done with payload" as status;
90
echo "================== con1 done ==================";
94
set @con1_tid = (select thread_id from performance_schema.threads
95
where processlist_user = 'user1');
97
select (@con1_tid is not null) as expected;
99
set @marker_begin = (select event_id from performance_schema.events_statements_history_long
100
where sql_text like "%MARKER_BEGIN%" and thread_id = @con1_tid);
102
select (@marker_begin is not null) as expected;
104
set @marker_end = (select end_event_id from performance_schema.events_statements_history_long
105
where sql_text like "%MARKER_END%" and thread_id = @con1_tid);
107
select (@marker_end is not null) as expected;
109
# Will point to what happened on spurious test failures
110
show status like "performance_schema%";
113
# This is the test itself:
114
# the full trace of every recorded event between MARKER_BEGIN
115
# end MARKER_END is dumped.
116
# The value of EVENT_ID, END_EVENT_ID, NESTING_EVENT_TYPE, NESTING_EVENT_ID
117
# should reflect the relations between each events,
118
# and this structure should stay the same between runs.
120
# Things to observe in the output:
121
# - there are IDLE events between top level queries,
122
# - there are no IDLE events between multi queries
123
# - STATEMENT starts right after the IDLE event
124
# - STAGE init starts right after
125
# - SOCKET events, when receiving the command,
126
# are childrens of the STATEMENT select / STAGE init
130
select (event_id - @marker_begin) as relative_event_id,
131
(end_event_id - @marker_begin) as relative_end_event_id,
135
(nesting_event_id - @marker_begin) as relative_nesting_event_id
136
from performance_schema.events_statements_history_long
137
where (thread_id = @con1_tid)
138
and (@marker_begin <= event_id)
139
and (end_event_id <= @marker_end)
143
select (event_id - @marker_begin) as relative_event_id,
144
(end_event_id - @marker_begin) as relative_end_event_id,
146
"(stage)" as comment,
148
(nesting_event_id - @marker_begin) as relative_nesting_event_id
149
from performance_schema.events_stages_history_long
150
where (thread_id = @con1_tid)
151
and (@marker_begin <= event_id)
152
and (end_event_id <= @marker_end)
156
select (event_id - @marker_begin) as relative_event_id,
157
(end_event_id - @marker_begin) as relative_end_event_id,
159
operation as comment,
161
(nesting_event_id - @marker_begin) as relative_nesting_event_id
162
from performance_schema.events_waits_history_long
163
where (thread_id = @con1_tid)
164
and (@marker_begin <= event_id)
165
and (end_event_id <= @marker_end)
168
order by relative_event_id asc;
175
revoke all privileges, grant option from user1@localhost;
176
drop user user1@localhost;
179
truncate table performance_schema.setup_actors;
180
insert into performance_schema.setup_actors
181
select * from test.setup_actors;
182
drop table test.setup_actors;
184
update performance_schema.threads set instrumented='YES';
185
update performance_schema.setup_instruments set enabled='YES', timed='YES';