log_state.test 13.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
### t/log_state.test ###
#
# This test suffers from server
# Bug#38124 "general_log_file" variable silently unset when using expression
# In short:
#    SET GLOBAL general_log_file = @<whatever>
#    SET GLOBAL slow_query_log = @<whatever>
# cause that the value of these server system variables is set to default
# instead of the assigned values. There comes no error message or warning.
# If this bug is fixed please
# 1. try this test with "let $fixed_bug38124 = 0;"
# 2. remove all workarounds if 1. was successful.
let $fixed_bug38124 = 0;

--source include/not_embedded.inc
16 17
--source include/have_csv.inc

18 19 20 21 22 23 24 25
# Several subtests modify global variables. Save the initial values only here,
# but reset to the initial values per subtest.
SET @old_general_log= @@global.general_log;
SET @old_general_log_file= @@global.general_log_file;
SET @old_slow_query_log= @@global.slow_query_log;
SET @old_slow_query_log_file= @@global.slow_query_log_file;


26
--disable_ps_protocol
27

28 29 30 31 32 33 34 35 36
set global general_log= OFF;
truncate table mysql.general_log;
truncate table mysql.slow_log;
show global variables
where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
Variable_name = 'general_log' or Variable_name = 'slow_query_log';
flush logs;
set global general_log= ON;
create table t1(f1 int);
37
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
38 39 40
select * from mysql.general_log;
set global general_log= OFF;
drop table t1;
41
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
42 43 44 45 46 47 48
select * from mysql.general_log;
set global general_log= ON;
flush logs;
show global variables
where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
Variable_name = 'general_log' or Variable_name = 'slow_query_log';

49
--echo # Establish connection con1 (user=root)
50
connect (con1,localhost,root,,);
51
--echo # Switch to connection con1
52
connection con1;
53 54 55 56 57 58 59 60 61
# Please increase @long_query_time if the corresponding selects show an
# additional unexpected entry like
#    start_time ... sql_text
#    TIMESTAMP  ... set session long_query_time=...
# (Bug#40377 sporadic pushbuild failure in log_state: result mismatch)
--replace_result 2 <long_query_time>
set @long_query_time = 2;
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
62
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
63
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
64
--echo # Switch to connection default
65 66 67
connection default;

set global slow_query_log= ON;
68
--echo # Switch to connection con1
69
connection con1;
70 71
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
72
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
73
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
74
--echo # Switch to connection default
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
connection default;
show global variables
where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
Variable_name = 'general_log' or Variable_name = 'slow_query_log';

set global general_log= ON;
set global general_log= OFF;
set global general_log= OFF;
set global slow_query_log= ON;
set global slow_query_log= OFF;
set global slow_query_log= OFF;

set global general_log= ON;
truncate table mysql.general_log;
create table t1(f1 int);
drop table t1;
91
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
92 93 94
select * from mysql.general_log;
set global general_log= OFF;
truncate table mysql.general_log;
95
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
96 97 98 99 100 101 102 103 104 105 106 107
select * from mysql.general_log;
set global general_log= ON;
show global variables
where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
Variable_name = 'general_log' or Variable_name = 'slow_query_log';

--replace_column 2 #
show variables like 'general_log_file';
--replace_column 2 #
show variables like 'slow_query_log_file';
show variables like 'log_output';

108
# Can't set general_log_file to a non existing file
109
--error ER_WRONG_VALUE_FOR_VAR
110
set global general_log_file='/not existing path/log.master';
111 112 113

# Can't set general_log_file to a directory
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
114
--error ER_WRONG_VALUE_FOR_VAR
115 116 117
eval set global general_log_file='$MYSQLTEST_VARDIR';

# Can't set general_log_file to empty string
118
--error ER_WRONG_VALUE_FOR_VAR
119
set global general_log_file='';
120

121 122 123
--replace_column 2 #
show variables like 'general_log_file';
set global general_log= OFF;
124 125
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval set global general_log_file='$MYSQLTEST_VARDIR/tmp/log.master';
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
set global general_log= ON;
create table t1(f1 int);
drop table t1;
set global general_log= OFF;
set global general_log_file=default;
set global general_log= ON;
create table t1(f1 int);
drop table t1;
--replace_column 2 #
show variables like 'general_log_file';
--replace_column 2 #
show variables like 'slow_query_log_file';

set global general_log= default;
set global slow_query_log= default;
set global general_log_file= default;
set global slow_query_log_file= default;
show variables like 'general_log';
show variables like 'slow_query_log';
set global general_log=ON;
set global log_output=default;
show variables like 'log_output';
set global general_log=OFF;
set global log_output=FILE;
truncate table mysql.general_log;
show variables like 'log_output';
set global general_log=ON;
create table t1(f1 int);
154
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
155 156 157 158 159 160
select * from mysql.general_log;
set global general_log=OFF;
set global log_output="FILE,TABLE";
show variables like 'log_output';
set global general_log=ON;
drop table t1;
161
--replace_column 1 TIMESTAMP 2 USER_HOST 3 #
162 163
select * from mysql.general_log;

164 165 166 167 168 169 170 171 172 173 174 175 176 177
# Reset to initial values
SET @@global.general_log = @old_general_log;
SET @@global.general_log_file = @old_general_log_file;
SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
if(!$fixed_bug38124)
{
   --disable_query_log
   let $my_var = `SELECT @old_general_log_file`;
   eval SET @@global.general_log_file = '$my_var';
   let $my_var = `SELECT @old_slow_query_log_file`;
   eval SET @@global.slow_query_log_file = '$my_var';
   --enable_query_log
}
178 179


180
###########################################################################
181

182 183 184 185
#
# Bug#29129 (Resetting general_log while the GLOBAL READ LOCK is set causes
#            a deadlock)
#
186

187
# Test ON->OFF transition under a GLOBAL READ LOCK
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
SET GLOBAL general_log = ON;
SET GLOBAL slow_query_log = ON;

FLUSH TABLES WITH READ LOCK;

SET GLOBAL general_log = OFF;
SET GLOBAL slow_query_log = OFF;

UNLOCK TABLES;

# Test OFF->ON transition under a GLOBAL READ LOCK
FLUSH TABLES WITH READ LOCK;

SET GLOBAL general_log = ON;
SET GLOBAL slow_query_log = ON;

UNLOCK TABLES;

# Test ON->OFF transition under a GLOBAL READ_ONLY
SET GLOBAL READ_ONLY = ON;

SET GLOBAL general_log = OFF;
SET GLOBAL slow_query_log = OFF;

SET GLOBAL READ_ONLY = OFF;

# Test OFF->ON transition under a GLOBAL READ_ONLY
SET GLOBAL READ_ONLY = ON;

SET GLOBAL general_log = ON;
SET GLOBAL slow_query_log = ON;

SET GLOBAL READ_ONLY = OFF;

222 223 224
# Reset to initial values
SET GLOBAL general_log = @old_general_log;
SET GLOBAL slow_query_log = @old_slow_query_log;
225 226


227
###########################################################################
228

229
#
230
# Bug#29131: SHOW VARIABLES reports variable 'log' but SET doesn't recognize it
231 232
#

233
SET GLOBAL general_log = ON;
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

SHOW VARIABLES LIKE 'general_log';
SHOW VARIABLES LIKE 'log';
SELECT @@general_log, @@log;
SET GLOBAL log = 0;
SHOW VARIABLES LIKE 'general_log';
SHOW VARIABLES LIKE 'log';
SELECT @@general_log, @@log;
SET GLOBAL general_log = 1;
SHOW VARIABLES LIKE 'general_log';
SHOW VARIABLES LIKE 'log';
SELECT @@general_log, @@log;

SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'log_slow_queries';
SELECT @@slow_query_log, @@log_slow_queries;
SET GLOBAL log_slow_queries = 0;
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'log_slow_queries';
SELECT @@slow_query_log, @@log_slow_queries;
SET GLOBAL slow_query_log = 1;
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'log_slow_queries';
SELECT @@slow_query_log, @@log_slow_queries;

259 260 261 262 263
SET GLOBAL general_log = @old_general_log;
SET GLOBAL slow_query_log = @old_slow_query_log;


###########################################################################
264

265
#
266
# Bug#31604: server crash when setting slow_query_log_file/general_log_file
267 268
#

269
--error ER_WRONG_VALUE_FOR_VAR
270
SET GLOBAL general_log_file= CONCAT('/not existing path/log.maste', 'r');
271
--error ER_WRONG_VALUE_FOR_VAR
272
SET GLOBAL general_log_file= NULL;
273
--error ER_WRONG_VALUE_FOR_VAR
274
SET GLOBAL slow_query_log_file= CONCAT('/not existing path/log.maste', 'r');
275
--error ER_WRONG_VALUE_FOR_VAR
276 277 278 279 280 281 282 283 284 285 286 287 288 289
SET GLOBAL slow_query_log_file= NULL;

# Reset to initial values in case a setting above was successful.
SET GLOBAL general_log_file= @old_general_log_file;
SET GLOBAL slow_query_log_file= @old_slow_query_log_file;
if(!$fixed_bug38124)
{
   --disable_query_log
   let $my_var = `SELECT @old_general_log_file`;
   eval SET @@global.general_log_file = '$my_var';
   let $my_var = `SELECT @old_slow_query_log_file`;
   eval SET @@global.slow_query_log_file = '$my_var';
   --enable_query_log
}
290

291 292 293 294 295
###########################################################################

--echo
--echo # --
--echo # -- Bug#32748: Inconsistent handling of assignments to
296
--echo # --            general_log_file/slow_query_log_file.
297 298 299 300 301 302 303 304 305
--echo # --

--echo
SET GLOBAL general_log_file = 'bug32748.query.log';
SET GLOBAL slow_query_log_file = 'bug32748.slow.log';

--echo
SHOW VARIABLES LIKE '%log_file';

306
# Reset to initial values
307
--echo
308 309 310 311 312 313 314 315 316 317 318
SET GLOBAL general_log_file = @old_general_log_file;
SET GLOBAL slow_query_log_file = @old_slow_query_log_file;
if(!$fixed_bug38124)
{
   --disable_query_log
   let $my_var = `SELECT @old_general_log_file`;
   eval SET @@global.general_log_file = '$my_var';
   let $my_var = `SELECT @old_slow_query_log_file`;
   eval SET @@global.slow_query_log_file = '$my_var';
   --enable_query_log
}
319 320 321 322

--echo
--echo # -- End of Bug#32748.

323

324
###########################################################################
325

326
# WL#4403 - deprecate @log and @slow_log_queries variables
327

328 329
# These server system variables are all deprecated
# -- show for command-line as well!
330 331 332 333 334 335
--echo deprecated:
SET GLOBAL log = 0;
SET GLOBAL log_slow_queries = 0;
SET GLOBAL log = DEFAULT;
SET GLOBAL log_slow_queries = DEFAULT;

336
# These server system variables are NOT deprecated.
337 338 339 340 341 342 343 344 345 346 347 348
--echo not deprecated:
SELECT @@global.general_log_file INTO @my_glf;
SELECT @@global.slow_query_log_file INTO @my_sqlf;
SET GLOBAL general_log = 0;
SET GLOBAL slow_query_log = 0;
SET GLOBAL general_log_file = 'WL4403_G.log';
SET GLOBAL slow_query_log_file = 'WL4403_SQ.log';
SET GLOBAL general_log_file = @my_glf;
SET GLOBAL slow_query_log_file = @my_sqlf;
SET GLOBAL general_log = DEFAULT;
SET GLOBAL slow_query_log = DEFAULT;

349 350 351 352 353 354 355 356 357 358 359 360 361 362
## Reset to initial values
SET @@global.general_log = @old_general_log;
SET @@global.general_log_file = @old_general_log_file;
SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
if(!$fixed_bug38124)
{
   --disable_query_log
   let $my_var = `SELECT @old_general_log_file`;
   eval SET @@global.general_log_file = '$my_var';
   let $my_var = `SELECT @old_slow_query_log_file`;
   eval SET @@global.slow_query_log_file = '$my_var';
   --enable_query_log
}
363 364


365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
###########################################################################

--echo #
--echo # Bug #49756 Rows_examined is always 0 in the slow query log 
--echo # for update statements
--echo #

SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = "TABLE";
SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 0.001;

# clear slow_log of any residual slow queries
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INT, PRIMARY KEY (b));
INSERT INTO t2 VALUES (3),(4);

connect (con2,localhost,root,,);
INSERT INTO t1 VALUES (1+sleep(.01)),(2);
INSERT INTO t1 SELECT b+sleep(.01) from t2;
UPDATE t1 SET a=a+sleep(.01) WHERE a>2;
UPDATE t1 SET a=a+sleep(.01) ORDER BY a DESC;
UPDATE t2 set b=b+sleep(.01) limit 1;
UPDATE t1 SET a=a+sleep(.01) WHERE a in (SELECT b from t2);
DELETE FROM t1 WHERE a=a+sleep(.01) ORDER BY a LIMIT 2;

SELECT rows_examined,sql_text FROM mysql.slow_log;
disconnect con2;
connection default;
DROP TABLE t1,t2;
TRUNCATE TABLE mysql.slow_log;

--echo # end of bug#49756


401 402
--echo End of 5.1 tests

403
--enable_ps_protocol
404 405

#
406
# Cleanup
407
#
408 409
# Disconnect must be done last to avoid delayed 'Quit' message in general log
--echo # Close connection con1
410
disconnect con1;
411 412
# set back the saved default values
connection default;
Luis Soares's avatar
Luis Soares committed
413

414
# Reset global system variables to initial values if forgotten somewhere above.
415 416
SET GLOBAL long_query_time = DEFAULT;
SET GLOBAL log_output = @old_log_output;
417 418 419 420 421 422 423 424 425 426 427 428 429
SET global general_log = @old_general_log;
SET global general_log_file = @old_general_log_file;
SET global slow_query_log = @old_slow_query_log;
SET global slow_query_log_file = @old_slow_query_log_file;
if(!$fixed_bug38124)
{
   --disable_query_log
   let $my_var = `SELECT @old_general_log_file`;
   eval SET @@global.general_log_file = '$my_var';
   let $my_var = `SELECT @old_slow_query_log_file`;
   eval SET @@global.slow_query_log_file = '$my_var';
   --enable_query_log
}
430 431 432

# Remove the log files that was created in the "default location"
# i.e var/run
msvensson@pilot.mysql.com's avatar
msvensson@pilot.mysql.com committed
433
--remove_file $MYSQLTEST_VARDIR/run/mysqld.log
434
--remove_file $MYSQLTEST_VARDIR/tmp/log.master