MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_aggregate_setup.inc
1 # Tests for the performance schema
2 
3 # =============
4 # DOCUMENTATION
5 # =============
6 
7 # Verify how table io is aggregated into various tables
8 #
9 # In the instance dimension:
10 # - table_io_waits_summary_by_index_usage
11 # - table_io_waits_summary_by_table
12 # - table_lock_waits_summary_by_table
13 # - objects_summary_global_by_type
14 #
15 # In the thread dimension:
16 # - events_waits_summary_by_thread_by_event_name
17 # - events_waits_summary_by_account_by_event_name
18 # - events_waits_summary_by_user_by_event_name
19 # - events_waits_summary_by_host_by_event_name
20 #
21 # Globally:
22 # - events_waits_summary_global_by_event_name
23 #
24 # The tests are written with the following helpers:
25 # - include/table_aggregate_setup.inc
26 # - include/table_aggregate_load.inc
27 # - include/table_aggregate_cleanup.inc
28 #
29 # Helpers are intended to be used as follows.
30 #
31 # A Typical test t/table_aggregate_xxx.test will consist of:
32 # --source ../include/table_aggregate_setup.inc
33 #
34 # ... statements to modify the default configuration ...
35 #
36 # --source ../include/table_aggregate_load.inc
37 # --source ../include/table_aggregate_cleanup.inc
38 #
39 # Naming conventions for t/table_aggregate_xxx.test are as follows:
40 # t/<instrument>aggregate_<mode><actors><objects>
41 #
42 # <instrument> corresponds to different instruments settings
43 # - table: both table io and table lock are instrumented
44 # - table_io: only table io is instrumented
45 # - table_lock: only table lock is instrumented
46 #
47 # <mode> corresponds to different consumers settings
48 # - off: global_instrumentation OFF
49 # - global: global_instrumentation ON, thread_instrumentation OFF
50 # - thread: global_instrumentation ON, thread_instrumentation ON,
51 # events_* consumers OFF
52 # - history: global_instrumentation ON, thread_instrumentation ON,
53 # events_* consumers ON
54 #
55 # <actors> corresponds to different setup_actors settings
56 # - 4u: every test user (user1, user2, user3, user4) is ON
57 # - 2u: (user1, user3) are ON, (user2, user4) are OFF
58 #
59 # <objects> corresponds to different setup_objects settings
60 # - 3t: tables t1, t2 and t3 are ON
61 # - 2t: tables t1 and t3 are ON, table t2 is OFF
62 #
63 
64 # ========================================
65 # HELPER include/table_aggregate_setup.inc
66 # ========================================
67 
68 --source include/not_embedded.inc
69 --source include/have_perfschema.inc
70 --source ../include/no_protocol.inc
71 --source ../include/wait_for_pfs_thread_count.inc
72 
73 --disable_query_log
74 grant ALL on *.* to user1@localhost;
75 grant ALL on *.* to user2@localhost;
76 grant ALL on *.* to user3@localhost;
77 grant ALL on *.* to user4@localhost;
78 
79 flush privileges;
80 
81 # Purge old users, hosts, user/host from previous tests
82 truncate table performance_schema.accounts;
83 truncate table performance_schema.users;
84 truncate table performance_schema.hosts;
85 
86 # Save the setup
87 
88 --disable_warnings
89 drop table if exists test.setup_actors;
90 drop table if exists test.setup_objects;
91 --enable_warnings
92 
93 create table test.setup_actors as
94  select * from performance_schema.setup_actors;
95 
96 create table test.setup_objects as
97  select * from performance_schema.setup_objects;
98 
99 # Only instrument the user connections (by default)
100 truncate table performance_schema.setup_actors;
101 insert into performance_schema.setup_actors
102  set host= 'localhost', user= 'user1', role= '%';
103 insert into performance_schema.setup_actors
104  set host= 'localhost', user= 'user2', role= '%';
105 insert into performance_schema.setup_actors
106  set host= 'localhost', user= 'user3', role= '%';
107 insert into performance_schema.setup_actors
108  set host= 'localhost', user= 'user4', role= '%';
109 
110 # Only instrument test.t% tables (by default)
111 truncate table performance_schema.setup_objects;
112 insert into performance_schema.setup_objects
113  set object_type='TABLE', object_schema='test', object_name='t1', timed='YES';
114 insert into performance_schema.setup_objects
115  set object_type='TABLE', object_schema='test', object_name='t2', timed='NO';
116 insert into performance_schema.setup_objects
117  set object_type='TABLE', object_schema='test', object_name='t3', timed='NO';
118 
119 update performance_schema.threads set instrumented='NO';
120 
121 # Only instrument table io and lock (by default)
122 update performance_schema.setup_instruments set enabled='NO', timed='NO';
123 update performance_schema.setup_instruments set enabled='YES', timed='YES'
124  where name in ('wait/io/table/sql/handler',
125  'wait/lock/table/sql/handler');
126 
127 # Enable all consumers (by default)
128 update performance_schema.setup_consumers set enabled='YES';
129 
130 # Start from a known clean state, to avoid noise from previous tests
131 flush tables;
132 flush status;
133 
134 create table test.t1(a int, b int, c int, d int default 0,
135  primary key(a),
136  index index_b(b),
137  index index_cb(c, b));
138 create table test.t2 like test.t1;
139 create table test.t3 like test.t1;
140 
141 #
142 # Note:
143 # For test robustness and to avoid picking up noise from other tests scripts,
144 # it is better to use:
145 # in ('t1', 't2', 't3)
146 # explicitly instead of:
147 # like 't%'
148 
149 --disable_warnings
150 drop procedure if exists dump_thread;
151 drop procedure if exists dump_one_thread;
152 --enable_warnings
153 
154 delimiter $$;
155 
156 create procedure dump_thread()
157 begin
158  call dump_one_thread('user1');
159  call dump_one_thread('user2');
160  call dump_one_thread('user3');
161  call dump_one_thread('user4');
162 end
163 $$
164 
165 create procedure dump_one_thread(in username varchar(64))
166 begin
167  declare my_thread_id int;
168 
169  set my_thread_id = (select thread_id from performance_schema.threads
170  where processlist_user=username);
171 
172  if (my_thread_id is not null) then
173  select username, event_name, count_star
174  from performance_schema.events_waits_summary_by_thread_by_event_name
175  where event_name in
176  ('wait/io/table/sql/handler',
177  'wait/lock/table/sql/handler')
178  and thread_id = my_thread_id
179  order by event_name;
180  else
181  select username, "not found" as status;
182  end if;
183 end
184 $$
185 
186 delimiter ;$$
187 
188 prepare dump_waits_user from
189  "select user, event_name, count_star
190  from performance_schema.events_waits_summary_by_user_by_event_name
191  where user like \'user%\' and event_name in
192  (\'wait/io/table/sql/handler\',
193  \'wait/lock/table/sql/handler\')
194  order by user, event_name;";
195 
196 prepare dump_waits_account from
197  "select user, host, event_name, count_star
198  from performance_schema.events_waits_summary_by_account_by_event_name
199  where user like \'user%\' and event_name in
200  (\'wait/io/table/sql/handler\',
201  \'wait/lock/table/sql/handler\')
202  order by user, host, event_name;";
203 
204 prepare dump_waits_host from
205  "select host, event_name, count_star
206  from performance_schema.events_waits_summary_by_host_by_event_name
207  where host=\'localhost\' and event_name in
208  (\'wait/io/table/sql/handler\',
209  \'wait/lock/table/sql/handler\')
210  order by host, event_name;";
211 
212 prepare dump_waits_global from
213  "select event_name, count_star
214  from performance_schema.events_waits_summary_global_by_event_name
215  where event_name in
216  (\'wait/io/table/sql/handler\',
217  \'wait/lock/table/sql/handler\')
218  order by event_name;";
219 
220 prepare dump_waits_history from
221  "select event_name, count(event_name), object_type, object_schema, object_name
222  from performance_schema.events_waits_history_long
223  where event_name in
224  (\'wait/io/table/sql/handler\',
225  \'wait/lock/table/sql/handler\')
226  group by object_type, object_schema, object_name, event_name
227  order by object_type, object_schema, object_name, event_name;";
228 
229 prepare dump_waits_index_io from
230  "select object_type, object_schema, object_name, index_name,
231  count_star, count_read, count_write,
232  count_fetch, count_insert, count_update, count_delete
233  from performance_schema.table_io_waits_summary_by_index_usage
234  where object_type='TABLE' and object_schema='test'
235  and object_name in ('t1', 't2', 't3')
236  order by object_type, object_schema, object_name, index_name;";
237 
238 prepare dump_waits_table_io from
239  "select object_type, object_schema, object_name,
240  count_star, count_read, count_write,
241  count_fetch, count_insert, count_update, count_delete
242  from performance_schema.table_io_waits_summary_by_table
243  where object_type='TABLE' and object_schema='test'
244  and object_name in ('t1', 't2', 't3')
245  order by object_type, object_schema, object_name";
246 
247 prepare dump_waits_table_lock from
248  "select object_type, object_schema, object_name,
249  count_star, count_read, count_write,
250  count_read_normal, count_read_with_shared_locks,
251  count_read_high_priority, count_read_no_insert,
252  count_read_external,
253  count_write_delayed, count_write_low_priority,
254  count_write_external
255  from performance_schema.table_lock_waits_summary_by_table
256  where object_type='TABLE' and object_schema='test'
257  and object_name in ('t1', 't2', 't3')
258  order by object_type, object_schema, object_name";
259 
260 prepare dump_objects_summary from
261  "select object_type, object_schema, object_name, count_star
262  from performance_schema.objects_summary_global_by_type
263  where object_type='TABLE' and object_schema='test'
264  and object_name in ('t1', 't2', 't3')
265  order by object_type, object_schema, object_name";
266 
267 --enable_query_log