--source include/have_innodb.inc
--source include/have_sequence.inc
--source include/have_debug.inc

--let MYSQLD_DATADIR= `SELECT @@datadir`
--source include/shutdown_mysqld.inc
--copy_file $MYSQLD_DATADIR/ibdata1 $MYSQLD_DATADIR/ibdata1_copy
--copy_file $MYSQLD_DATADIR/ib_logfile0 $MYSQLD_DATADIR/ib_logfile0_copy
--source include/start_mysqld.inc

SET GLOBAL innodb_file_per_table= 0;
SET GLOBAL innodb_limit_optimistic_insert_debug = 2;
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, f3 INT NOT NULL)ENGINE=InnoDB;
INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384;
SET GLOBAL innodb_file_per_table= default;
CREATE TABLE t2(f1 INT NOT NULL PRIMARY KEY,f2 VARCHAR(40))ENGINE=InnoDB PARTITION BY KEY() PARTITIONS 256;
INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384;
DROP TABLE t2, t1;
--source include/wait_all_purged.inc

let $fsize=`select file_size from information_schema.innodb_sys_tablespaces where space = 0`;

set GLOBAL innodb_fast_shutdown= 0;
--source include/restart_mysqld.inc

let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN=InnoDB: Moving the data from extents 4096 through 22016;
--source include/search_pattern_in_file.inc

let SEARCH_PATTERN=InnoDB: Defragmentation of system tablespace is successful;
--source include/search_pattern_in_file.inc

evalp select name, file_size<$fsize shrunk
from information_schema.innodb_sys_tablespaces where space=0;

--source include/shutdown_mysqld.inc

--move_file $MYSQLD_DATADIR/ibdata1_copy $MYSQLD_DATADIR/ibdata1
--move_file $MYSQLD_DATADIR/ib_logfile0_copy $MYSQLD_DATADIR/ib_logfile0

--source include/start_mysqld.inc
