# # WL#6965: Truncate explicitly created UNDO logs. # # While the purge thread is turned off, perform enough DML to cause # undo tablespace sizes grow beyond the truncation threshold. # Then check if truncation is accomplished by restarting mysqld # causing each undo tablespace to be truncated. # Create 2 explicit undo tablespaces. CREATE UNDO TABLESPACE undo_003 ADD DATAFILE 'undo_003.ibu'; CREATE UNDO TABLESPACE undo_004 ADD DATAFILE 'undo_004.ibu'; # Make the 2 implicit undo tablespaces inactive so they get truncated. SET GLOBAL innodb_purge_rseg_truncate_frequency=1; ALTER UNDO TABLESPACE innodb_undo_001 SET INACTIVE; ALTER UNDO TABLESPACE innodb_undo_002 SET INACTIVE; SET GLOBAL innodb_purge_rseg_truncate_frequency=default; # The two undo tablespaces to truncate at shutdown will be undo_003 and undo_004 SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE_TYPE = 'Undo' ORDER BY NAME; NAME SPACE_TYPE STATE AUTOEXTEND_SIZE innodb_undo_001 Undo empty 0 innodb_undo_002 Undo empty 0 undo_003 Undo active 0 undo_004 Undo active 0 # Turn off purging so that undo logs build up in the undo tablespaces. SET GLOBAL innodb_purge_stop_now=ON; # Perform enough DML action so that undo tablespace sizes grow beyond # the threshold set by --innodb-max-undo-log-size. create table t1( keyc int, c1 char(255), c2 char(255), c3 char(255), c4 char(255), c5 char(255), c6 char(255), primary key(keyc)) engine = innodb; CREATE PROCEDURE populate_t1() BEGIN DECLARE i INT DEFAULT 1; while (i <= 16000) DO insert into t1 values (i, 'a', 'b', 'c', 'd', 'e', 'f' ); SET i = i + 1; END WHILE; END | call populate_t1(); delete from t1 where keyc < 10000; update t1 set c1 = 'mysql' where keyc > 10000; update t1 set c2 = 'mysql' where keyc > 10000; update t1 set c3 = 'mysql' where keyc > 10000; update t1 set c4 = 'mysql' where keyc > 10000; update t1 set c5 = 'mysql' where keyc > 10000; update t1 set c6 = 'mysql' where keyc > 10000; # Start a new transaction for both tablespaces to get utilized create table t2 ( keyc int, c1 char(255), c2 char(255), c3 char(255), c4 char(255), c5 char(255), c6 char(255), primary key(keyc)) engine = innodb; CREATE PROCEDURE populate_t2() BEGIN DECLARE i INT DEFAULT 1; while (i <= 16000) DO insert into t2 values (i, 'a', 'b', 'c', 'd', 'e', 'f' ); SET i = i + 1; END WHILE; END | call populate_t2(); delete from t2 where keyc < 10000; update t2 set c1 = 'mysql' where keyc > 10000; update t2 set c2 = 'mysql' where keyc > 10000; update t2 set c3 = 'mysql' where keyc > 10000; update t2 set c4 = 'mysql' where keyc > 10000; update t2 set c5 = 'mysql' where keyc > 10000; update t2 set c6 = 'mysql' where keyc > 10000; drop PROCEDURE populate_t1; drop PROCEDURE populate_t2; drop table t1, t2; SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE_TYPE = 'Undo' ORDER BY NAME; NAME SPACE_TYPE STATE AUTOEXTEND_SIZE innodb_undo_001 Undo empty 0 innodb_undo_002 Undo empty 0 undo_003 Undo active 0 undo_004 Undo active 0 # Compare the undo tablespace sizes before and after DML growth. # Do a slow shut down so the undo tablespaces can be truncated. SET GLOBAL innodb_max_undo_log_size=20000000; SET GLOBAL innodb_fast_shutdown=0; SET GLOBAL innodb_purge_rseg_truncate_frequency=1; SET GLOBAL innodb_purge_run_now=ON; # restart: # Compare the undo tablespace sizes before and after truncation. SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE_TYPE = 'Undo' ORDER BY NAME; NAME SPACE_TYPE STATE AUTOEXTEND_SIZE innodb_undo_001 Undo empty 0 innodb_undo_002 Undo empty 0 undo_003 Undo active 0 undo_004 Undo active 0 # # Cleanup # ALTER UNDO TABLESPACE innodb_undo_001 SET ACTIVE; ALTER UNDO TABLESPACE innodb_undo_002 SET ACTIVE; ALTER UNDO TABLESPACE undo_003 SET INACTIVE; ALTER UNDO TABLESPACE undo_004 SET INACTIVE; SET GLOBAL innodb_purge_rseg_truncate_frequency=1; SET GLOBAL innodb_purge_rseg_truncate_frequency=default; DROP UNDO TABLESPACE undo_003; DROP UNDO TABLESPACE undo_004; SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE SPACE_TYPE = 'Undo' ORDER BY NAME; NAME SPACE_TYPE STATE AUTOEXTEND_SIZE innodb_undo_001 Undo active 0 innodb_undo_002 Undo active 0