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