Debian Codegraph @

mysql-test/suite/perfschema/include/stage_setup.inc

raw
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 # Test requires: sp-protocol/ps-protocol/view-protocol/cursor-protocol disabled
26 --source include/no_protocol.inc
27
28 --disable_query_log
29
30 create user user1@localhost, user2@localhost,
31 user3@localhost, user4@localhost;
32 grant ALL on *.* to user1@localhost;
33 grant ALL on *.* to user2@localhost;
34 grant ALL on *.* to user3@localhost;
35 grant ALL on *.* to user4@localhost;
36
37 flush privileges;
38
39 # Save the setup
40
41 --disable_warnings
42 drop table if exists test.setup_actors;
43 drop table if exists test.t1;
44 --enable_warnings
45
46 create table test.t1(a varchar(64));
47
48 create table test.setup_actors as
49 select * from performance_schema.setup_actors;
50
51 # Only instrument the user connections
52 truncate table performance_schema.setup_actors;
53 insert into performance_schema.setup_actors
54 set host= 'localhost', user= 'user1', `role`= '%',
55 enabled='YES', history='YES';
56 insert into performance_schema.setup_actors
57 set host= 'localhost', user= 'user2', `role`= '%',
58 enabled='YES', history='YES';
59 insert into performance_schema.setup_actors
60 set host= 'localhost', user= 'user3', `role`= '%',
61 enabled='YES', history='YES';
62 insert into performance_schema.setup_actors
63 set host= 'localhost', user= 'user4', `role`= '%',
64 enabled='YES', history='YES';
65
66 update performance_schema.threads set instrumented='NO';
67
68 # Only instrument a few events of each kind
69 update performance_schema.setup_instruments set enabled='YES', timed='YES';
70
71 update performance_schema.setup_consumers set enabled='YES';
72
73 # Start from a known clean state, to avoid noise from previous tests
74 flush tables;
75 flush status;
76 truncate performance_schema.events_stages_summary_by_thread_by_event_name;
77 truncate performance_schema.events_stages_summary_global_by_event_name;
78 truncate performance_schema.events_stages_history;
79 truncate performance_schema.events_stages_history_long;
80 truncate performance_schema.events_statements_summary_by_thread_by_event_name;
81 truncate performance_schema.events_statements_summary_global_by_event_name;
82 truncate performance_schema.events_statements_history;
83 truncate performance_schema.events_statements_history_long;
84
85 --disable_warnings
86 drop procedure if exists dump_thread;
87 drop procedure if exists dump_one_thread;
88 --enable_warnings
89
90 delimiter $$;
91
92 create procedure dump_thread()
93 begin
94 call dump_one_thread('user1');
95 call dump_one_thread('user2');
96 call dump_one_thread('user3');
97 call dump_one_thread('user4');
98 end
99 $$
100
101 create procedure dump_one_thread(in username varchar(64))
102 begin
103 declare my_thread_id int;
104 declare my_statement_id int;
105
106 set my_thread_id = (select thread_id from performance_schema.threads
107 where processlist_user=username);
108
109 if (my_thread_id is not null) then
110 begin
111 # Dump the current statement for this thread
112 select username, event_name, sql_text
113 from performance_schema.events_statements_current
114 where thread_id = my_thread_id;
115
116 # Get the current statement
117 set my_statement_id = (select event_id from
118 performance_schema.events_statements_current
119 where thread_id = my_thread_id);
120
121 # Dump the stages for this statement
122 select username, event_name, nesting_event_type
123 from performance_schema.events_stages_current
124 where thread_id = my_thread_id
125 and nesting_event_id = my_statement_id
126 order by event_id asc;
127 select username, event_name, nesting_event_type
128 from performance_schema.events_stages_history
129 where thread_id = my_thread_id
130 and nesting_event_id = my_statement_id
131 order by event_id asc;
132 end;
133 else
134 select username, "not found" as status;
135 end if;
136 end
137 $$
138
139 delimiter ;$$
140
141 --enable_query_log