| 1 |
SET @global_slow_query_log = @@global.slow_query_log; |
| 2 |
SET @global_log_output = @@global.log_output; |
| 3 |
SET @@session.long_query_time=1; |
| 4 |
SET @@global.log_output = 'TABLE'; |
| 5 |
Bug53191 Lock_time in slow log is negative when logging stored routines |
| 6 |
TRUNCATE mysql.slow_log; |
| 7 |
SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; |
| 8 |
CREATE TABLE t1 (c0 INT PRIMARY KEY AUTO_INCREMENT, c1 TIMESTAMP, c2 TIMESTAMP); |
| 9 |
CREATE FUNCTION f_slow_now() RETURNS TIMESTAMP |
| 10 |
BEGIN |
| 11 |
DO SLEEP(2); |
| 12 |
RETURN NOW(); |
| 13 |
END// |
| 14 |
CREATE FUNCTION f_slow_current_time() RETURNS TIME |
| 15 |
BEGIN |
| 16 |
DO SLEEP(2); |
| 17 |
RETURN CURRENT_TIME(); |
| 18 |
END |
| 19 |
// |
| 20 |
INSERT INTO t1 (c1,c2) VALUES (now(), f_slow_now())// |
| 21 |
CREATE TRIGGER tf_before BEFORE INSERT ON t1 |
| 22 |
FOR EACH ROW BEGIN |
| 23 |
SET new.c2 = f_slow_now(); |
| 24 |
END// |
| 25 |
CREATE PROCEDURE p1() |
| 26 |
BEGIN |
| 27 |
INSERT INTO t1 (c1,c2) values (now(),now()); |
| 28 |
DO SLEEP(2); |
| 29 |
INSERT INTO t1 (c1,c2) values (now(),now()); |
| 30 |
end// |
| 31 |
INSERT INTO t1 (c1,c2) VALUES (now(), now()); |
| 32 |
CALL p1(); |
| 33 |
SELECT c1-c2 FROM t1; |
| 34 |
c1-c2 |
| 35 |
0 |
| 36 |
0 |
| 37 |
0 |
| 38 |
0 |
| 39 |
*** There shouldn't less than 1 s difference between each row |
| 40 |
SELECT t1.c1-self.c1 > 1 FROM t1, t1 as self WHERE t1.c0=self.c0+1 ORDER BY t1.c0; |
| 41 |
t1.c1-self.c1 > 1 |
| 42 |
1 |
| 43 |
1 |
| 44 |
1 |
| 45 |
DROP TRIGGER tf_before; |
| 46 |
DROP FUNCTION f_slow_now; |
| 47 |
DROP FUNCTION f_slow_current_time; |
| 48 |
DROP TABLE t1; |
| 49 |
DROP TABLE IF EXISTS t1; |
| 50 |
Warnings: |
| 51 |
Note 1051 Unknown table 'test.t1' |
| 52 |
CREATE TABLE t1(c1 INT) ENGINE=MyISAM; |
| 53 |
DROP PROCEDURE IF EXISTS p1; |
| 54 |
CREATE PROCEDURE p1() |
| 55 |
BEGIN |
| 56 |
INSERT INTO t1 VALUES (1); |
| 57 |
SELECT COUNT(*) FROM t1 WHERE c1= 1; |
| 58 |
UPDATE t1 SET c1=c1*2; |
| 59 |
END| |
| 60 |
Connection 2 |
| 61 |
LOCK TABLE t1 WRITE; |
| 62 |
Back to default connection |
| 63 |
CALL p1(); |
| 64 |
Wait three seconds and unlock the table |
| 65 |
UNLOCK TABLES; |
| 66 |
COUNT(*) |
| 67 |
1 |
| 68 |
Slow log: |
| 69 |
**** 1 == we have slow log entries |
| 70 |
SELECT count(*) > 0 FROM mysql.slow_log; |
| 71 |
count(*) > 0 |
| 72 |
1 |
| 73 |
**** 0 == None of the entries have a lock time greater than 10 s |
| 74 |
SELECT count(*) FROM mysql.slow_log WHERE lock_time > 10; |
| 75 |
count(*) |
| 76 |
0 |
| 77 |
DROP TABLE t1; |
| 78 |
DROP PROCEDURE p1; |
| 79 |
SET sql_mode = default; |
| 80 |
SET @@global.log_output = @global_log_output; |
| 81 |
SET @global.slow_query_log = @global_slow_query_log; |
| 82 |
TRUNCATE TABLE mysql.general_log; |
| 83 |
TRUNCATE TABLE mysql.slow_log; |