
use DBI;

$dbh=DBI->connect("dbi:mysql:test", "root", "") or die $DBI::errstr;

$total_rows=100000;

print "Creating table\n";

$dbh->do("drop table if exists bench1");

$dbh->do("create table bench1 (id int NOT NULL,id2 int NOT NULL,
                               id3 int NOT NULL, dummy1 char(30),
                               primary key (id,id2), index ix_id3 (id3)) ENGINE=Falcon");

print "Inserting data in reverse order: $total_rows rows\n";

$query="insert into bench1 (id,id2,id3,dummy1) values ";

for ($i=0 ; $i < $total_rows ; $i++)
{
  $sth = $dbh->do($query . "(" . ($total_rows-1-$i) . "," .
         ($total_rows-1-$i) . "," .
         ($total_rows-1-$i) . ",'BCDEFGHIJK')") or die $DBI::errstr;
}

$stmt=$dbh->prepare("select * from bench1 where id3=?");

print "Retrieving inserted data:\n";
$ok=0;
$nok=0;
for ($i=0; $i<$total_rows; $i++)
{

  $n=$stmt->execute($i) or  die $DBI::errstr;
  if ($n==1)
  {
   #print "ok $n\n";
   $ok++;
  }
  else
  {
   print "rows for id3=$i not found but they exist $n\n";
   $nok++;
  }
}
$stmt->finish();
$dbh->disconnect();


print "Total ok=$ok nok=$nok\n";