MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stage_setup.inc
1 # Tests for the performance schema
2 
3 # =============
4 # DOCUMENTATION
5 # =============
6 
7 # Verify critical stages of a statement
8 #
9 # The tests are written with the following helpers:
10 # - include/stage_setup.inc
11 # - include/stage_cleanup.inc
12 #
13 # Helpers are intended to be used as follows.
14 #
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
20 #
21 # ==============================
22 # HELPER include/stage_setup.inc
23 # ==============================
24 
25 --source include/not_embedded.inc
26 --source include/have_perfschema.inc
27 --source ../include/no_protocol.inc
28 
29 --disable_query_log
30 
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;
35 
36 flush privileges;
37 
38 # Save the setup
39 
40 --disable_warnings
41 drop table if exists test.setup_actors;
42 drop table if exists test.t1;
43 --enable_warnings
44 
45 create table test.t1(a varchar(64));
46 
47 create table test.setup_actors as
48  select * from performance_schema.setup_actors;
49 
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= '%';
60 
61 update performance_schema.threads set instrumented='NO';
62 
63 # Only instrument a few events of each kind
64 update performance_schema.setup_instruments set enabled='YES', timed='YES';
65 
66 # Start from a known clean state, to avoid noise from previous tests
67 flush tables;
68 flush status;
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;
77 
78 --disable_warnings
79 drop procedure if exists dump_thread;
80 drop procedure if exists dump_one_thread;
81 --enable_warnings
82 
83 delimiter $$;
84 
85 create procedure dump_thread()
86 begin
87  call dump_one_thread('user1');
88  call dump_one_thread('user2');
89  call dump_one_thread('user3');
90  call dump_one_thread('user4');
91 end
92 $$
93 
94 create procedure dump_one_thread(in username varchar(64))
95 begin
96  declare my_thread_id int;
97  declare my_statement_id int;
98 
99  set my_thread_id = (select thread_id from performance_schema.threads
100  where processlist_user=username);
101 
102  if (my_thread_id is not null) then
103  begin
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;
108 
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);
113 
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;
125  end;
126  else
127  select username, "not found" as status;
128  end if;
129 end
130 $$
131 
132 delimiter ;$$
133 
134 --enable_query_log