1
by brian
clean slate |
1 |
# This test requires that --log-output includes 'table', and the general
|
2 |
# log is on
|
|
3 |
||
4 |
# PS causes different statistics
|
|
5 |
--disable_ps_protocol |
|
6 |
||
7 |
connect (con1,localhost,root,,); |
|
8 |
connect (con2,localhost,root,,); |
|
9 |
||
10 |
flush status; |
|
11 |
||
12 |
# Logging to the general query log table (--log-output=table --log) increments
|
|
13 |
# Table_locks_immediate with each query, so here Immediate becomes 1
|
|
14 |
show status like 'Table_lock%'; |
|
15 |
# ++Immediate = 2
|
|
16 |
select * from information_schema.session_status where variable_name like 'Table_lock%'; |
|
17 |
||
18 |
connection con1; |
|
19 |
# ++Immediate = 3
|
|
20 |
SET SQL_LOG_BIN=0; |
|
21 |
set @old_general_log = @@global.general_log; |
|
22 |
set global general_log = 'OFF'; |
|
23 |
--disable_warnings |
|
24 |
# ++Immediate = 4
|
|
25 |
drop table if exists t1; |
|
26 |
--enable_warnings |
|
27 |
||
28 |
# ++Immediate = 5
|
|
29 |
create table t1(n int) engine=myisam; |
|
30 |
# Immediate + 2 = 7
|
|
31 |
insert into t1 values(1); |
|
32 |
||
33 |
connection con2; |
|
34 |
# Immediate + 2 = 9
|
|
35 |
lock tables t1 read; |
|
36 |
# ++Immediate = 10
|
|
37 |
unlock tables; |
|
38 |
# Immediate + 2 = 12
|
|
39 |
lock tables t1 read; |
|
40 |
||
41 |
connection con1; |
|
42 |
# ++Immediate = 13
|
|
43 |
let $ID= `select connection_id()`; |
|
44 |
# ++Immediate = 14 (Not +2, because this increments Table_locks_waited)
|
|
45 |
--send |
|
46 |
update t1 set n = 3; |
|
47 |
||
48 |
connection con2; |
|
49 |
# wait for the other query to start executing
|
|
50 |
let $wait_condition= select 1 from INFORMATION_SCHEMA.PROCESSLIST where ID = $ID and STATE = "Table lock"; |
|
51 |
# Immediate = 14 + $wait_condition_reps ($wait_timeout is 0, so no extra select
|
|
52 |
# is done inside wait_condition.inc)
|
|
53 |
--source include/wait_condition.inc |
|
54 |
# ++Immediate = 15 + $wait_condition_reps
|
|
55 |
unlock tables; |
|
56 |
||
57 |
connection con1; |
|
58 |
reap; |
|
59 |
# ++Immediate = 16 + $wait_condition_reps
|
|
60 |
show status like 'Table_locks_waited'; |
|
61 |
drop table t1; |
|
62 |
set global general_log = @old_general_log; |
|
63 |
||
64 |
disconnect con2; |
|
65 |
disconnect con1; |
|
66 |
connection default; |
|
67 |
||
68 |
# End of 4.1 tests
|
|
69 |
||
70 |
#
|
|
71 |
# last_query_cost
|
|
72 |
#
|
|
73 |
||
74 |
select 1; |
|
75 |
show status like 'last_query_cost'; |
|
76 |
create table t1 (a int); |
|
77 |
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); |
|
78 |
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); |
|
79 |
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); |
|
80 |
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); |
|
81 |
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); |
|
82 |
select * from t1 where a=6; |
|
83 |
show status like 'last_query_cost'; |
|
84 |
# Ensure value dosn't change by second status call
|
|
85 |
show status like 'last_query_cost'; |
|
86 |
select 1; |
|
87 |
show status like 'last_query_cost'; |
|
88 |
drop table t1; |
|
89 |
||
90 |
#
|
|
91 |
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
|
|
92 |
# if connections are cached
|
|
93 |
#
|
|
94 |
#
|
|
95 |
# The first suggested fix from the bug report was chosen
|
|
96 |
# (see http://bugs.mysql.com/bug.php?id=15933):
|
|
97 |
#
|
|
98 |
# a) On flushing the status, set max_used_connections to
|
|
99 |
# threads_connected, not to 0.
|
|
100 |
#
|
|
101 |
# b) Check if it is necessary to increment max_used_connections when
|
|
102 |
# taking a thread from the cache as well as when creating new threads
|
|
103 |
#
|
|
104 |
||
105 |
# Wait for at most $disconnect_timeout seconds for disconnects to finish.
|
|
106 |
let $disconnect_timeout = 10; |
|
107 |
||
108 |
# Wait for any previous disconnects to finish.
|
|
109 |
FLUSH STATUS; |
|
110 |
--disable_query_log |
|
111 |
--disable_result_log |
|
112 |
eval SET @wait_left = $disconnect_timeout; |
|
113 |
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; |
|
114 |
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; |
|
115 |
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`; |
|
116 |
while ($wait_more) |
|
117 |
{
|
|
118 |
sleep 1; |
|
119 |
FLUSH STATUS; |
|
120 |
SET @wait_left = @wait_left - 1; |
|
121 |
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; |
|
122 |
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; |
|
123 |
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`; |
|
124 |
}
|
|
125 |
--enable_query_log |
|
126 |
--enable_result_log |
|
127 |
||
128 |
# Prerequisite.
|
|
129 |
SHOW STATUS LIKE 'max_used_connections'; |
|
130 |
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections'; |
|
131 |
||
132 |
# Save original setting.
|
|
133 |
SET @save_thread_cache_size=@@thread_cache_size; |
|
134 |
SET GLOBAL thread_cache_size=3; |
|
135 |
||
136 |
connect (con1,localhost,root,,); |
|
137 |
connect (con2,localhost,root,,); |
|
138 |
||
139 |
connection con1; |
|
140 |
disconnect con2; |
|
141 |
||
142 |
# Check that max_used_connections still reflects maximum value.
|
|
143 |
SHOW STATUS LIKE 'max_used_connections'; |
|
144 |
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections'; |
|
145 |
||
146 |
# Check that after flush max_used_connections equals to current number
|
|
147 |
# of connections. First wait for previous disconnect to finish.
|
|
148 |
FLUSH STATUS; |
|
149 |
--disable_query_log |
|
150 |
--disable_result_log |
|
151 |
eval SET @wait_left = $disconnect_timeout; |
|
152 |
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; |
|
153 |
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; |
|
154 |
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`; |
|
155 |
while ($wait_more) |
|
156 |
{
|
|
157 |
sleep 1; |
|
158 |
FLUSH STATUS; |
|
159 |
SET @wait_left = @wait_left - 1; |
|
160 |
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`; |
|
161 |
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0; |
|
162 |
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`; |
|
163 |
}
|
|
164 |
--enable_query_log |
|
165 |
--enable_result_log |
|
166 |
# Check that we don't count disconnected thread any longer.
|
|
167 |
SHOW STATUS LIKE 'max_used_connections'; |
|
168 |
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections'; |
|
169 |
||
170 |
# Check that max_used_connections is updated when cached thread is
|
|
171 |
# reused...
|
|
172 |
connect (con2,localhost,root,,); |
|
173 |
SHOW STATUS LIKE 'max_used_connections'; |
|
174 |
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections'; |
|
175 |
||
176 |
# ...and when new thread is created.
|
|
177 |
connect (con3,localhost,root,,); |
|
178 |
SHOW STATUS LIKE 'max_used_connections'; |
|
179 |
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections'; |
|
180 |
||
181 |
# Restore original setting.
|
|
182 |
connection default; |
|
183 |
SET GLOBAL thread_cache_size=@save_thread_cache_size; |
|
184 |
||
185 |
disconnect con3; |
|
186 |
disconnect con2; |
|
187 |
disconnect con1; |
|
188 |
||
189 |
||
190 |
#
|
|
191 |
# Bug #30377: EXPLAIN loses last_query_cost when used with UNION
|
|
192 |
#
|
|
193 |
||
194 |
CREATE TABLE t1 ( a INT ); |
|
195 |
INSERT INTO t1 VALUES (1), (2); |
|
196 |
||
197 |
SELECT a FROM t1 LIMIT 1; |
|
198 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
199 |
||
200 |
EXPLAIN SELECT a FROM t1; |
|
201 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
202 |
||
203 |
SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a; |
|
204 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
205 |
||
206 |
EXPLAIN SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a; |
|
207 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
208 |
||
209 |
SELECT a IN (SELECT a FROM t1) FROM t1 LIMIT 1; |
|
210 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
211 |
||
212 |
SELECT (SELECT a FROM t1 LIMIT 1) x FROM t1 LIMIT 1; |
|
213 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
214 |
||
215 |
SELECT * FROM t1 a, t1 b LIMIT 1; |
|
216 |
SHOW SESSION STATUS LIKE 'Last_query_cost'; |
|
217 |
||
218 |
DROP TABLE t1; |
|
219 |
||
220 |
||
221 |
# End of 5.0 tests
|
|
222 |
||
223 |
#
|
|
224 |
# Ensure that SHOW STATUS only changes global status variables
|
|
225 |
#
|
|
226 |
||
227 |
connect (con1,localhost,root,,); |
|
228 |
let $rnd_next = `show global status like 'handler_read_rnd_next'`; |
|
229 |
let $tmp_table = `show global status like 'Created_tmp_tables'`; |
|
230 |
show status like 'com_show_status'; |
|
231 |
show status like 'hand%write%'; |
|
232 |
show status like '%tmp%'; |
|
233 |
show status like 'hand%write%'; |
|
234 |
show status like '%tmp%'; |
|
235 |
show status like 'com_show_status'; |
|
236 |
let $rnd_next2 = `show global status like 'handler_read_rnd_next'`; |
|
237 |
let $tmp_table2 = `show global status like 'Created_tmp_tables'`; |
|
238 |
--disable_query_log |
|
239 |
eval select substring_index('$rnd_next2',0x9,-1)-substring_index('$rnd_next',0x9,-1) as rnd_diff, substring_index('$tmp_table2',0x9,-1)-substring_index('$tmp_table',0x9,-1) as tmp_table_diff; |
|
240 |
--enable_query_log |
|
241 |
||
242 |
#
|
|
243 |
# Bug#30252 Com_create_function is not incremented.
|
|
244 |
#
|
|
245 |
show global status like 'Com%function%'; |
|
246 |
||
247 |
DELIMITER //; |
|
248 |
create function f1 (x INTEGER) returns integer |
|
249 |
begin
|
|
250 |
declare ret integer; |
|
251 |
set ret = x * 10; |
|
252 |
return ret; |
|
253 |
end // |
|
254 |
DELIMITER ;// |
|
255 |
||
256 |
drop function f1; |
|
257 |
||
258 |
show global status like 'Com%function%'; |
|
259 |
||
260 |
||
261 |
# End of 5.1 tests
|
|
262 |
||
263 |
#
|
|
264 |
# Bug #17954: Threads_connected > Threads_created
|
|
265 |
#
|
|
266 |
||
267 |
SELECT VARIABLE_VALUE INTO @tc FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected'; |
|
268 |
SELECT VARIABLE_NAME FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_created' AND VARIABLE_VALUE < @tc; |
|
269 |
SELECT VARIABLE_VALUE INTO @tr FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_running'; |
|
270 |
FLUSH STATUS; |
|
271 |
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected' AND VARIABLE_VALUE < @tc; |
|
272 |
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_running' AND VARIABLE_VALUE < @tr; |