delimiter $ drop procedure if exists p1 $ create procedure `p1`(iterations int) begin declare i int default 0; declare timestart int default 0; declare timeend int default 0; drop table if exists `t1`; create table `t1` (`a` int not null auto_increment primary key,`b` varchar(15),`c` varchar(15),key `b`(`b`)) engine=innodb default charset=latin1; start transaction; repeat replace into `t1`(`b`,`c`) values (concat('',floor(rand()*255)),'1'); set i:=i+1; until i>iterations end repeat; commit; select * from mysql.innodb_table_stats where table_name='t1'; set timestart:=unix_timestamp(); repeat -- select * from mysql.innodb_table_stats where table_name='t2'; select n_rows from mysql.innodb_table_stats where table_name='t1' into @n; if @n > iterations/2 then set timeend:=unix_timestamp(); end if; until timeend > 0 end repeat; select * from mysql.innodb_table_stats where table_name='t1'; select concat('stats took ',(timeend-timestart),' seconds!') as `time`; end $ delimiter ; call p1(1000);