mariadb/tests/insert_and_repair.pl
unknown aeaf3fcf12 Don't do signal() on windows (Causes instability problems)
Safer, a bit faster filesort.
Code changes to avoid calls to current_thd() (faster code).
Removed all compiler warnings from readline.


BitKeeper/etc/ignore:
  Add my_global.h back.
Docs/manual.texi:
  4.0.1 Changelog
include/my_sys.h:
  Added strmake_root
libmysql/libmysql.c:
  Don't do signal() on windows (Causes instability problems)
mysys/my_alloc.c:
  Added strmake_root
readline/bind.c:
  Remove warnings
readline/complete.c:
  Remove warnings
readline/display.c:
  Remove warnings
readline/funmap.c:
  Remove warnings
readline/histexpand.c:
  Remove warnings
readline/histfile.c:
  Remove warnings
readline/history.h:
  Remove warnings
readline/histsearch.c:
  Remove warnings
readline/isearch.c:
  Remove warnings
readline/kill.c:
  Remove warnings
readline/macro.c:
  Remove warnings
readline/readline.c:
  Remove warnings
readline/readline.h:
  Remove warnings
readline/rltty.c:
  Remove warnings
readline/search.c:
  Remove warnings
readline/shell.c:
  Remove warnings
readline/terminal.c:
  Remove warnings
readline/tilde.c:
  Remove warnings
readline/tilde.h:
  Remove warnings
readline/undo.c:
  Remove warnings
readline/util.c:
  Remove warnings
readline/vi_mode.c:
  Remove warnings
sql-bench/server-cfg.sh:
  Added use of truncate table
sql-bench/test-insert.sh:
  Added use of truncate table
  Changed some tests to use keys instead of 'range'
sql-bench/test-wisconsin.sh:
  Cleanup
sql/field.cc:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/field.h:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/filesort.cc:
  Safer memory allocation;  Don't allocate pointer to buffers directly, but use an IO_CACHE instead.
  This will allow us to use more memory for keys and will also work better if the number of rows that is to be sorted is much larger than expected.
sql/item.cc:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/item.h:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/item_func.h:
  Cleanup
sql/opt_range.cc:
  Use mem_root instead of sql_alloc() to get more speed
sql/sql_class.cc:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/sql_class.h:
  Added strmake()
sql/sql_handler.cc:
  Add 'thd' to send() (To avoid usage of 'current_thd')
sql/sql_lex.cc:
  Use mem_root instead of sql_alloc() to get more speed
sql/sql_select.cc:
  Add 'thd' to send() (To avoid usage of 'current_thd')
tests/fork2_test.pl:
  Fixed typos
tests/fork_big.pl:
  Fixed typos
tests/insert_and_repair.pl:
  Fixed typos
tests/rename_test.pl:
  Fixed typos
tests/test_delayed_insert.pl:
  Fixed typos
2001-10-17 19:39:39 +03:00

180 lines
5 KiB
Perl
Executable file

#!/usr/bin/perl -w
#
# This is a test of insert and repair/check.
#
$opt_loop_count=100000; # Change this to make test harder/easier
##################### Standard benchmark inits ##############################
use DBI;
use Getopt::Long;
use Benchmark;
package main;
$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert=
$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0;
$opt_host=$opt_user=$opt_password=""; $opt_db="test";
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in",
"skip-delete","verbose","fast-insert","lock-tables","debug","fast",
"force","user=s","password=s") || die "Aborted";
$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
$firsttable = "bench_f1";
$secondtable = "bench_f2";
####
#### Start timeing and start test
####
$start_time=new Benchmark;
if (!$opt_skip_create)
{
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
$opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
$dbh->do("drop table if exists $firsttable, $secondtable");
print "Creating tables $firsttable and $secondtable in database $opt_db\n";
$dbh->do("create table $firsttable (id int(7) not null, thread tinyint not null, info varchar(32), marker char(1), primary key(id,thread))") or die $DBI::errstr;
$dbh->do("create table $secondtable (id int(7) not null, thread tinyint not null, row int(3) not null,value double, primary key(id,thread,row)) delay_key_write=1") or die $DBI::errstr;
$dbh->disconnect; $dbh=0; # Close handler
}
$|= 1; # Autoflush
####
#### Start the tests
####
insert_in_bench1() if (($pid=fork()) == 0); $work{$pid}="insert in bench1";
insert_in_bench2() if (($pid=fork()) == 0); $work{$pid}="insert in bench2";
repair_and_check() if (($pid=fork()) == 0); $work{$pid}="repair/check";
$errors=0;
while (($pid=wait()) != -1)
{
$ret=$?/256;
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
$errors++ if ($ret != 0);
}
if (!$opt_skip_delete && !$errors)
{
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
$opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
$dbh->do("drop table $firsttable,$secondtable");
}
print ($errors ? "Test failed\n" :"Test ok\n");
$end_time=new Benchmark;
print "Total time: " .
timestr(timediff($end_time, $start_time),"noc") . "\n";
exit(0);
#
# Insert records in the two tables
#
sub insert_in_bench1
{
my ($dbh,$rows,$found,$i);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
$opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
$rows=$found=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$sth=$dbh->do("insert into $firsttable values ($i,0,'This is entry $i','')") || die "Got error on insert: $DBI::errstr\n";
$row_count=($i % 7)+1;
$rows+=1+$row_count;
for ($j=0 ; $j < $row_count; $j++)
{
$sth=$dbh->do("insert into $secondtable values ($i,0,$j,0)") || die "Got error on insert: $DBI::errstr\n";
}
}
$dbh->disconnect; $dbh=0;
print "insert_in_bench1: Inserted $rows rows\n";
exit(0);
}
sub insert_in_bench2
{
my ($dbh,$rows,$found,$i);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
$opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
$rows=$found=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$sth=$dbh->do("insert into $firsttable values ($i,1,'This is entry $i','')") || die "Got error on insert: $DBI::errstr\n";
$row_count=((7-$i) % 7)+1;
$rows+=1+$row_count;
for ($j=0 ; $j < $row_count; $j++)
{
$sth=$dbh->do("insert into $secondtable values ($i,1,$j,0)") || die "Got error on insert: $DBI::errstr\n";
}
}
$dbh->disconnect; $dbh=0;
print "insert_in_bench2: Inserted $rows rows\n";
exit(0);
}
sub repair_and_check
{
my ($dbh,$row,@row,$found1,$found2,$last_found1,$last_found2,$i,$type,
$table);
$found1=$found2=0; $last_found1=$last_found2= -1;
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
$opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
for ($i=0; $found1 != $last_found1 && $found2 != $last_found1 ; $i++)
{
$type=($i & 2) ? "repair" : "check";
if ($i & 1)
{
$table=$firsttable;
$last_found1=$found1;
}
else
{
$table=$secondtable;
$last_found2=$found2;
}
$sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $dbh->errstr\n";
$sth->execute || die $dbh->errstr;
while (($row=$sth->fetchrow_arrayref))
{
if ($row->[3] ne "OK")
{
print "Got error " . $row->[3] . " when doing $type on $table\n";
exit(1);
}
}
$sth=$dbh->prepare("select count(*) from $table") || die "Got error on prepare: $dbh->errstr\n";
$sth->execute || die $dbh->errstr;
@row = $sth->fetchrow_array();
if ($i & 1)
{
$found1= $row[0];
}
else
{
$found2= $row[0];
}
$sth->finish;
sleep(2);
}
$dbh->disconnect; $dbh=0;
print "check/repair: Did $i repair/checks\n";
exit(0);
}