| 1 |
SET @old_log_output= @@global.log_output; |
| 2 |
SET @old_slow_query_log= @@global.slow_query_log; |
| 3 |
SET @old_long_query_time= @@session.long_query_time; |
| 4 |
SET @old_log_slow_disable_statements= @@global.log_slow_disabled_statements; |
| 5 |
|
| 6 |
# Log everything to slow log |
| 7 |
SET @@session.log_slow_verbosity="explain,innodb,query_plan"; |
| 8 |
|
| 9 |
CREATE TABLE t1 (i INT PRIMARY KEY AUTO_INCREMENT, j blob) ENGINE=MyISAM; |
| 10 |
insert into t1 (j) values ('a'),('b'),('c'),('d'); |
| 11 |
create table t2 (a int auto_increment primary key) engine=myisam; |
| 12 |
|
| 13 |
# enable slow logging to table |
| 14 |
SET GLOBAL log_output = 'file,table'; |
| 15 |
SET GLOBAL slow_query_log = on; |
| 16 |
|
| 17 |
DELIMITER $; |
| 18 |
CREATE PROCEDURE slow() |
| 19 |
BEGIN |
| 20 |
SELECT count(if(sleep(1) >= 0,0,NULL)) from t1 where j>'b'; |
| 21 |
SELECT count(*) from t1 where j>'a'; |
| 22 |
insert into t2 () values(); |
| 23 |
END |
| 24 |
$ |
| 25 |
|
| 26 |
CREATE PROCEDURE slow2() |
| 27 |
BEGIN |
| 28 |
SELECT j,count(*) from t1 group by j; |
| 29 |
create temporary table t3 (a int); |
| 30 |
alter table t3 add column (b int); |
| 31 |
call slow(); |
| 32 |
drop temporary table t3; |
| 33 |
SELECT j,count(*)+1 from t1 group by j,i; |
| 34 |
END |
| 35 |
$ |
| 36 |
|
| 37 |
DELIMITER ;$ |
| 38 |
|
| 39 |
SET SESSION long_query_time = 0; |
| 40 |
|
| 41 |
--disable_ps2_protocol |
| 42 |
SELECT @@log_slow_disabled_statements; |
| 43 |
TRUNCATE TABLE mysql.slow_log; |
| 44 |
ALTER TABLE t1 add column extra int; |
| 45 |
CALL slow2(); |
| 46 |
--disable_cursor_protocol |
| 47 |
SELECT count(if(sleep(1) >= 0,0,NULL)) from t1 where j>'b and part2'; |
| 48 |
--enable_cursor_protocol |
| 49 |
|
| 50 |
--echo --> |
| 51 |
SELECT sql_text FROM mysql.slow_log where sql_text <> "Close stmt" and sql_text <> "Prepare"; |
| 52 |
--echo <-- |
| 53 |
|
| 54 |
SET SESSION log_slow_disabled_statements="call,admin"; |
| 55 |
TRUNCATE TABLE mysql.slow_log; |
| 56 |
ALTER TABLE t1 add column extra2 int; |
| 57 |
CALL slow2(); |
| 58 |
--disable_cursor_protocol |
| 59 |
SELECT count(if(sleep(1) >= 0,0,NULL)) from t1 where j>'b and part3'; |
| 60 |
--enable_cursor_protocol |
| 61 |
|
| 62 |
--echo --> |
| 63 |
SELECT sql_text FROM mysql.slow_log where sql_text <> "Close stmt" and sql_text <> "Prepare"; |
| 64 |
--echo <-- |
| 65 |
|
| 66 |
SET SESSION log_slow_disabled_statements=""; |
| 67 |
TRUNCATE TABLE mysql.slow_log; |
| 68 |
ALTER TABLE t1 add column extra3 int; |
| 69 |
CALL slow2(); |
| 70 |
--disable_cursor_protocol |
| 71 |
SELECT count(if(sleep(1) >= 0,0,NULL)) from t1 where j>'b and part4'; |
| 72 |
--enable_cursor_protocol |
| 73 |
|
| 74 |
--echo --> |
| 75 |
SELECT sql_text FROM mysql.slow_log where sql_text <> "Close stmt" and sql_text <> "Prepare"; |
| 76 |
--echo <-- |
| 77 |
|
| 78 |
SET SESSION log_slow_disabled_statements="call,admin,slave,sp"; |
| 79 |
TRUNCATE TABLE mysql.slow_log; |
| 80 |
ALTER TABLE t1 add column extra4 int; |
| 81 |
CALL slow2(); |
| 82 |
--disable_cursor_protocol |
| 83 |
SELECT count(if(sleep(1) >= 0,0,NULL)) from t1 where j>'b and part5'; |
| 84 |
--enable_cursor_protocol |
| 85 |
|
| 86 |
--echo --> |
| 87 |
SELECT sql_text FROM mysql.slow_log where sql_text <> "Close stmt" and sql_text <> "Prepare"; |
| 88 |
--echo <-- |
| 89 |
--enable_ps2_protocol |
| 90 |
|
| 91 |
DROP TABLE t1,t2; |
| 92 |
DROP PROCEDURE slow; |
| 93 |
DROP PROCEDURE slow2; |
| 94 |
|
| 95 |
# |
| 96 |
# Restore setup |
| 97 |
# |
| 98 |
SET @@session.long_query_time= @old_long_query_time; |
| 99 |
TRUNCATE TABLE mysql.slow_log; |
| 100 |
SET @@global.log_output= @old_log_output; |
| 101 |
SET @@global.slow_query_log= @old_slow_query_log; |
| 102 |
SET @@global.log_slow_disabled_statements= @old_log_slow_disable_statements; |