1
# This test requires that --log-output includes 'table', and the general
4
# embedded server causes different stat
5
-- source include/not_embedded.inc
7
# PS causes different statistics
10
connect (con1,localhost,root,,);
11
connect (con2,localhost,root,,);
15
# Logging to the general query log table (--log-output=table --log) increments
16
# Table_locks_immediate with each query, so here Immediate becomes 1
17
show status like 'Table_lock%';
19
select * from information_schema.session_status where variable_name like 'Table_lock%';
24
set @old_general_log = @@global.general_log;
25
set global general_log = 'OFF';
28
drop table if exists t1;
32
create table t1(n int) engine=myisam;
34
insert into t1 values(1);
46
let $ID= `select connection_id()`;
47
# ++Immediate = 14 (Not +2, because this increments Table_locks_waited)
52
# wait for the other query to start executing
53
let $wait_condition= select 1 from INFORMATION_SCHEMA.PROCESSLIST where ID = $ID and STATE = "Table lock";
54
# Immediate = 14 + $wait_condition_reps ($wait_timeout is 0, so no extra select
55
# is done inside wait_condition.inc)
56
--source include/wait_condition.inc
57
# ++Immediate = 15 + $wait_condition_reps
62
# ++Immediate = 16 + $wait_condition_reps
63
show status like 'Table_locks_waited';
65
set global general_log = @old_general_log;
78
show status like 'last_query_cost';
79
create table t1 (a int);
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
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
83
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
84
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
85
select * from t1 where a=6;
86
show status like 'last_query_cost';
87
# Ensure value dosn't change by second status call
88
show status like 'last_query_cost';
90
show status like 'last_query_cost';
94
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
95
# if connections are cached
98
# The first suggested fix from the bug report was chosen
99
# (see http://bugs.mysql.com/bug.php?id=15933):
101
# a) On flushing the status, set max_used_connections to
102
# threads_connected, not to 0.
104
# b) Check if it is necessary to increment max_used_connections when
105
# taking a thread from the cache as well as when creating new threads
108
# Wait for at most $disconnect_timeout seconds for disconnects to finish.
109
let $disconnect_timeout = 10;
111
# Wait for any previous disconnects to finish.
115
eval SET @wait_left = $disconnect_timeout;
116
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
117
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
118
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
123
SET @wait_left = @wait_left - 1;
124
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
125
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
126
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
132
SHOW STATUS LIKE 'max_used_connections';
133
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections';
135
# Save original setting.
136
SET @save_thread_cache_size=@@thread_cache_size;
137
SET GLOBAL thread_cache_size=3;
139
connect (con1,localhost,root,,);
140
connect (con2,localhost,root,,);
145
# Check that max_used_connections still reflects maximum value.
146
SHOW STATUS LIKE 'max_used_connections';
147
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections';
149
# Check that after flush max_used_connections equals to current number
150
# of connections. First wait for previous disconnect to finish.
154
eval SET @wait_left = $disconnect_timeout;
155
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
156
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
157
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
162
SET @wait_left = @wait_left - 1;
163
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
164
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
165
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
169
# Check that we don't count disconnected thread any longer.
170
SHOW STATUS LIKE 'max_used_connections';
171
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections';
173
# Check that max_used_connections is updated when cached thread is
175
connect (con2,localhost,root,,);
176
SHOW STATUS LIKE 'max_used_connections';
177
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections';
179
# ...and when new thread is created.
180
connect (con3,localhost,root,,);
181
SHOW STATUS LIKE 'max_used_connections';
182
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME LIKE 'max_used_connections';
184
# Restore original setting.
186
SET GLOBAL thread_cache_size=@save_thread_cache_size;
194
# Bug #30377: EXPLAIN loses last_query_cost when used with UNION
197
CREATE TABLE t1 ( a INT );
198
INSERT INTO t1 VALUES (1), (2);
200
SELECT a FROM t1 LIMIT 1;
201
SHOW SESSION STATUS LIKE 'Last_query_cost';
203
EXPLAIN SELECT a FROM t1;
204
SHOW SESSION STATUS LIKE 'Last_query_cost';
206
SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a;
207
SHOW SESSION STATUS LIKE 'Last_query_cost';
209
EXPLAIN SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a;
210
SHOW SESSION STATUS LIKE 'Last_query_cost';
212
SELECT a IN (SELECT a FROM t1) FROM t1 LIMIT 1;
213
SHOW SESSION STATUS LIKE 'Last_query_cost';
215
SELECT (SELECT a FROM t1 LIMIT 1) x FROM t1 LIMIT 1;
216
SHOW SESSION STATUS LIKE 'Last_query_cost';
218
SELECT * FROM t1 a, t1 b LIMIT 1;
219
SHOW SESSION STATUS LIKE 'Last_query_cost';
227
# Ensure that SHOW STATUS only changes global status variables
230
connect (con1,localhost,root,,);
231
let $rnd_next = `show global status like 'handler_read_rnd_next'`;
232
let $tmp_table = `show global status like 'Created_tmp_tables'`;
233
show status like 'com_show_status';
234
show status like 'hand%write%';
235
show status like '%tmp%';
236
show status like 'hand%write%';
237
show status like '%tmp%';
238
show status like 'com_show_status';
239
let $rnd_next2 = `show global status like 'handler_read_rnd_next'`;
240
let $tmp_table2 = `show global status like 'Created_tmp_tables'`;
242
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;
246
# Bug#30252 Com_create_function is not incremented.
248
show global status like 'Com%function%';
251
create function f1 (x INTEGER) returns integer
261
show global status like 'Com%function%';
267
# Bug #17954: Threads_connected > Threads_created
270
SELECT VARIABLE_VALUE INTO @tc FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected';
271
SELECT VARIABLE_NAME FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_created' AND VARIABLE_VALUE < @tc;
272
SELECT VARIABLE_VALUE INTO @tr FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_running';
274
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected' AND VARIABLE_VALUE < @tc;
275
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_running' AND VARIABLE_VALUE < @tr;