~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/suite/perfschema/t/nesting.test

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test to check the proper nesting of events
 
2
 
 
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
 
11
 
 
12
--disable_query_log
 
13
 
 
14
grant ALL on *.* to user1@localhost;
 
15
 
 
16
flush privileges;
 
17
 
 
18
--disable_warnings
 
19
drop table if exists test.setup_actors;
 
20
--enable_warnings
 
21
 
 
22
create table test.setup_actors as
 
23
  select * from performance_schema.setup_actors;
 
24
 
 
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= '%';
 
29
 
 
30
update performance_schema.threads set instrumented='NO';
 
31
 
 
32
# Only instrument a few events of each kind
 
33
update performance_schema.setup_instruments set enabled='NO', timed='NO';
 
34
 
 
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');
 
43
 
 
44
update performance_schema.setup_instruments set enabled='YES', timed='YES'
 
45
  where name like ('stage/sql/%');
 
46
 
 
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');
 
52
 
 
53
# Start from a known clean state, to avoid noise from previous tests
 
54
flush tables;
 
55
flush status;
 
56
 
 
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;
 
66
 
 
67
--enable_query_log
 
68
 
 
69
connect (con1, localhost, user1, , );
 
70
 
 
71
echo "================== con1 connected ==================";
 
72
 
 
73
select "MARKER_BEGIN" as marker;
 
74
 
 
75
select "This is simple statement one" as payload;
 
76
 
 
77
select "This is simple statement two" as payload;
 
78
 
 
79
delimiter $$;
 
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;
 
83
$$
 
84
delimiter ;$$
 
85
 
 
86
select "MARKER_END" as marker;
 
87
 
 
88
select "Con1 is done with payload" as status;
 
89
 
 
90
echo "================== con1 done ==================";
 
91
 
 
92
--connection default
 
93
 
 
94
set @con1_tid = (select thread_id from performance_schema.threads
 
95
  where processlist_user = 'user1');
 
96
 
 
97
select (@con1_tid is not null) as expected;
 
98
 
 
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);
 
101
 
 
102
select (@marker_begin is not null) as expected;
 
103
 
 
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);
 
106
 
 
107
select (@marker_end is not null) as expected;
 
108
 
 
109
# Will point to what happened on spurious test failures
 
110
show status like "performance_schema%";
 
111
 
 
112
#
 
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.
 
119
#
 
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
 
127
 
 
128
select * from (
 
129
(
 
130
select (event_id - @marker_begin) as relative_event_id,
 
131
       (end_event_id - @marker_begin) as relative_end_event_id,
 
132
       event_name,
 
133
       sql_text as comment,
 
134
       nesting_event_type,
 
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)
 
140
)
 
141
union
 
142
(
 
143
select (event_id - @marker_begin) as relative_event_id,
 
144
       (end_event_id - @marker_begin) as relative_end_event_id,
 
145
       event_name,
 
146
       "(stage)" as comment,
 
147
       nesting_event_type,
 
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)
 
153
)
 
154
union
 
155
(
 
156
select (event_id - @marker_begin) as relative_event_id,
 
157
       (end_event_id - @marker_begin) as relative_end_event_id,
 
158
       event_name,
 
159
       operation as comment,
 
160
       nesting_event_type,
 
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)
 
166
)
 
167
) all_events
 
168
order by relative_event_id asc;
 
169
 
 
170
# test cleanup
 
171
 
 
172
--disconnect con1
 
173
 
 
174
--disable_query_log
 
175
revoke all privileges, grant option from user1@localhost;
 
176
drop user user1@localhost;
 
177
flush privileges;
 
178
 
 
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;
 
183
 
 
184
update performance_schema.threads set instrumented='YES';
 
185
update performance_schema.setup_instruments set enabled='YES', timed='YES';
 
186
 
 
187
--enable_query_log
 
188
 
 
189