drop procedure if exists `p1`; drop table if exists `rc`; create table `rc` (`a` int not null auto_increment primary key,`b` varchar(15),`c` varchar(15),key `b`(`b`)) engine=innodb default charset=latin1; drop table if exists `prod`,`old`,`tmp`; delimiter $ create procedure `p1`(iterations int) begin declare i int default 0; declare j int default 0; repeat create table if not exists `prod` like `rc`; truncate `rc`; set j:=0; start transaction; repeat replace into `rc`(`b`,`c`) values (concat('',floor(rand()*255)),concat('',floor(rand()*255))); set j:=j+1; until j>500 end repeat; commit; create table `tmp` like `rc`; start transaction; replace into `tmp` select * from `rc`; commit; rename table `prod` to `old`, `tmp` to `prod`; drop table `old`; set j:=0; repeat explain select * from `prod` where `b`='45'; select * from `prod` where `b`='45'; set j:=j+1; until j>5 end repeat; set i:=i+1; until i>iterations end repeat; end $ delimiter ; call p1(100);