| 1 |
# Test to check the proper nesting of events |
| 2 |
|
| 3 |
# Test requires: sp-protocol/ps-protocol/view-protocol/cursor-protocol disabled |
| 4 |
--source include/no_protocol.inc |
| 5 |
--source ../include/wait_for_pfs_thread_count.inc |
| 6 |
|
| 7 |
--disable_query_log |
| 8 |
|
| 9 |
create user user1@localhost; |
| 10 |
grant ALL on *.* to user1@localhost; |
| 11 |
|
| 12 |
flush privileges; |
| 13 |
|
| 14 |
--disable_warnings |
| 15 |
drop table if exists test.setup_actors; |
| 16 |
--enable_warnings |
| 17 |
|
| 18 |
create table test.setup_actors as |
| 19 |
select * from performance_schema.setup_actors; |
| 20 |
|
| 21 |
# Only instrument the user connections |
| 22 |
truncate table performance_schema.setup_actors; |
| 23 |
insert into performance_schema.setup_actors |
| 24 |
set host= 'localhost', user= 'user1', `role`= '%'; |
| 25 |
|
| 26 |
update performance_schema.threads set instrumented='NO'; |
| 27 |
|
| 28 |
# Only instrument a few events of each kind |
| 29 |
update performance_schema.setup_instruments set enabled='NO', timed='NO'; |
| 30 |
|
| 31 |
update performance_schema.setup_instruments set enabled='YES', timed='YES' |
| 32 |
where name in ('idle', |
| 33 |
'wait/io/table/sql/handler', |
| 34 |
'wait/lock/table/sql/handler', |
| 35 |
'wait/synch/rwlock/sql/LOCK_grant', |
| 36 |
'wait/synch/mutex/sql/THD::LOCK_thd_data', |
| 37 |
'wait/synch/mutex/sql/THD::LOCK_thd_query', |
| 38 |
'wait/io/file/sql/query_log'); |
| 39 |
|
| 40 |
update performance_schema.setup_instruments set enabled='YES', timed='YES' |
| 41 |
where name like ('stage/sql/%'); |
| 42 |
|
| 43 |
update performance_schema.setup_instruments set enabled='YES', timed='YES' |
| 44 |
where name in ('statement/sql/select', |
| 45 |
'statement/abstract/new_packet', |
| 46 |
'statement/abstract/Query', |
| 47 |
'statement/com/error'); |
| 48 |
|
| 49 |
# Start from a known clean state, to avoid noise from previous tests |
| 50 |
truncate table performance_schema.events_statements_summary_by_digest; |
| 51 |
flush tables; |
| 52 |
flush status; |
| 53 |
|
| 54 |
truncate performance_schema.events_waits_current; |
| 55 |
truncate performance_schema.events_waits_history; |
| 56 |
truncate performance_schema.events_waits_history_long; |
| 57 |
truncate performance_schema.events_stages_current; |
| 58 |
truncate performance_schema.events_stages_history; |
| 59 |
truncate performance_schema.events_stages_history_long; |
| 60 |
truncate performance_schema.events_statements_current; |
| 61 |
truncate performance_schema.events_statements_history; |
| 62 |
truncate performance_schema.events_statements_history_long; |
| 63 |
|
| 64 |
--enable_query_log |
| 65 |
|
| 66 |
connect (con1, localhost, user1, , ); |
| 67 |
|
| 68 |
echo "================== con1 connected =================="; |
| 69 |
|
| 70 |
select "MARKER_BEGIN" as marker; |
| 71 |
|
| 72 |
select "This is simple statement one" as payload; |
| 73 |
|
| 74 |
select "This is simple statement two" as payload; |
| 75 |
|
| 76 |
delimiter $$; |
| 77 |
select "This is the first part of a multi query" as payload; |
| 78 |
select "And this is the second part of a multi query" as payload; |
| 79 |
select "With a third part to make things complete" as payload; |
| 80 |
$$ |
| 81 |
delimiter ;$$ |
| 82 |
|
| 83 |
select "MARKER_END" as marker; |
| 84 |
|
| 85 |
select "Con1 is done with payload" as status; |
| 86 |
|
| 87 |
echo "================== con1 done =================="; |
| 88 |
|
| 89 |
--connection default |
| 90 |
|
| 91 |
set @con1_tid = (select thread_id from performance_schema.threads |
| 92 |
where processlist_user = 'user1'); |
| 93 |
|
| 94 |
select (@con1_tid is not null) as expected; |
| 95 |
|
| 96 |
set @marker_begin = (select event_id from performance_schema.events_statements_history_long |
| 97 |
where sql_text like "%MARKER_BEGIN%" and thread_id = @con1_tid); |
| 98 |
|
| 99 |
select (@marker_begin is not null) as expected; |
| 100 |
|
| 101 |
set @marker_end = (select end_event_id from performance_schema.events_statements_history_long |
| 102 |
where sql_text like "%MARKER_END%" and thread_id = @con1_tid); |
| 103 |
|
| 104 |
select (@marker_end is not null) as expected; |
| 105 |
|
| 106 |
# Will point to what happened on spurious test failures |
| 107 |
show global status like "performance_schema%_lost"; |
| 108 |
|
| 109 |
# |
| 110 |
# This is the test itself: |
| 111 |
# the full trace of every recorded event between MARKER_BEGIN |
| 112 |
# end MARKER_END is dumped. |
| 113 |
# The value of EVENT_ID, END_EVENT_ID, NESTING_EVENT_TYPE, NESTING_EVENT_ID |
| 114 |
# should reflect the relations between each events, |
| 115 |
# and this structure should stay the same between runs. |
| 116 |
# |
| 117 |
# Things to observe in the output: |
| 118 |
# - there are IDLE events between top level queries, |
| 119 |
# - there are no IDLE events between multi queries |
| 120 |
# - STATEMENT starts right after the IDLE event |
| 121 |
# - STAGE init starts right after |
| 122 |
# - SOCKET events, when receiving the command, |
| 123 |
# are childrens of the STATEMENT select / STAGE init |
| 124 |
|
| 125 |
select * from ( |
| 126 |
( |
| 127 |
select (event_id - @marker_begin) as relative_event_id, |
| 128 |
(end_event_id - @marker_begin) as relative_end_event_id, |
| 129 |
event_name, |
| 130 |
sql_text as comment, |
| 131 |
nesting_event_type, |
| 132 |
(nesting_event_id - @marker_begin) as relative_nesting_event_id |
| 133 |
from performance_schema.events_statements_history_long |
| 134 |
where (thread_id = @con1_tid) |
| 135 |
and (@marker_begin <= event_id) |
| 136 |
and (end_event_id <= @marker_end) |
| 137 |
) |
| 138 |
union |
| 139 |
( |
| 140 |
select (event_id - @marker_begin) as relative_event_id, |
| 141 |
(end_event_id - @marker_begin) as relative_end_event_id, |
| 142 |
event_name, |
| 143 |
"(stage)" as comment, |
| 144 |
nesting_event_type, |
| 145 |
(nesting_event_id - @marker_begin) as relative_nesting_event_id |
| 146 |
from performance_schema.events_stages_history_long |
| 147 |
where (thread_id = @con1_tid) |
| 148 |
and (@marker_begin <= event_id) |
| 149 |
and (end_event_id <= @marker_end) |
| 150 |
) |
| 151 |
union |
| 152 |
( |
| 153 |
select (event_id - @marker_begin) as relative_event_id, |
| 154 |
(end_event_id - @marker_begin) as relative_end_event_id, |
| 155 |
event_name, |
| 156 |
operation as comment, |
| 157 |
nesting_event_type, |
| 158 |
(nesting_event_id - @marker_begin) as relative_nesting_event_id |
| 159 |
from performance_schema.events_waits_history_long |
| 160 |
where (thread_id = @con1_tid) |
| 161 |
and (@marker_begin <= event_id) |
| 162 |
and (end_event_id <= @marker_end) |
| 163 |
) |
| 164 |
) all_events |
| 165 |
order by relative_event_id asc; |
| 166 |
|
| 167 |
# test cleanup |
| 168 |
|
| 169 |
--disconnect con1 |
| 170 |
|
| 171 |
--disable_query_log |
| 172 |
revoke all privileges, grant option from user1@localhost; |
| 173 |
drop user user1@localhost; |
| 174 |
flush privileges; |
| 175 |
|
| 176 |
truncate table performance_schema.setup_actors; |
| 177 |
insert into performance_schema.setup_actors |
| 178 |
select * from test.setup_actors; |
| 179 |
drop table test.setup_actors; |
| 180 |
|
| 181 |
update performance_schema.threads set instrumented='YES'; |
| 182 |
update performance_schema.setup_instruments set enabled='YES', timed='YES'; |
| 183 |
|
| 184 |
--enable_query_log |
| 185 |
|
| 186 |
|