Bug #17839 | Event Scheduler: TRUNCATE TABLE mysql.slow_log doesn't work from within event | ||
---|---|---|---|
Submitted: | 1 Mar 2006 20:08 | Modified: | 1 May 2006 22:14 |
Reporter: | Markus Popp | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 5.1.7 | OS: | Linux (Linux) |
Assigned to: | CPU Architecture: | Any |
[1 Mar 2006 20:08]
Markus Popp
[2 Mar 2006 20:26]
Andrey Hristov
I cannot reproduce (5.1.8-bk). Especially INSERT INTO SELECT does not work. Tried the same with a stored procedure with the same body and effect is the same. INSERT INTO fails, and the code does not reach TRUNCATE. On the console : 060302 21:21:48 [Note] SCHEDULER: Started thread 7 060302 21:21:48 [Note] SCHEDULER: Executing event test.archiveSlowLog of root@localhost [EXPR:1] 060302 21:21:48 [ERROR] SCHEDULER: [`root`@`localhost`][`test`.`archiveSlowLog`] You can't use usual read lock with log tables. Try READ LOCAL instead.] 060302 21:21:48 [Note] SCHEDULER: Executed event test.archiveSlowLog of root@localhost [EXPR:1]. RetCode=1
[2 Mar 2006 21:19]
Andrey Hristov
You can try the followin SP (make it an event). However, don't put TRUNCATE in it because it will lock :( (just reported it as bug#17876). WHERE clause of the CURSOR seemed not to work for me, so you need two events. One with the following body and 1 that executes few seconds later and truncates the table (but you could get few statements loss on a busy server with a lot of slow statements). DELIMITER // DROP procedure archiveSlowLog // CREATE event archiveSlowLog on schedule every 1 minute DO BEGIN DECLARE start_time, query_time, lock_time CHAR(20); DECLARE user_host MEDIUMTEXT; DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id INT; DECLARE dbname MEDIUMTEXT; DECLARE sql_text BLOB; DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT * FROM mysql.slow_log; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur1; REPEAT FETCH cur1 INTO start_time, user_host, query_time, lock_time, rows_set, rows_examined, dbname, last_insert_id, insert_id, server_id, sql_text; IF NOT done THEN BEGIN INSERT INTO slow_log.slow_log_data VALUES(start_time, user_host, query_time, lock_time, rows_set, rows_examined, dbname, last_insert_id, insert_id, server_id, sql_text); END; END IF; UNTIL done END REPEAT; CLOSE cur1; TRUNCATE mysql.slow_log; END // DELIMITER ;
[8 Mar 2006 8:50]
Magnus BlÄudd
This happens on windows because the ha_tina is not included in the built binary. See bug#17368
[26 Apr 2006 9:20]
Valeriy Kravchuk
Sorry for a long delay with this bug report. Please, try to repeat with a newer version, 5.1.9 beta, and inform about the results.
[1 May 2006 22:14]
Markus Popp
This works now in 5.1.9.