summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorunknown <monty@donna.mysql.fi>2001-04-01 13:45:48 +0300
committerunknown <monty@donna.mysql.fi>2001-04-01 13:45:48 +0300
commit1776fbac85f35241d4c4726e40f9e40d8267e115 (patch)
treeb31bc7d8e38b04c6603c8f2240f10f86497e5003 /tests
parent05f08c18ac1de3b5b23aab88e87387d2031b3c9b (diff)
downloadmariadb-git-1776fbac85f35241d4c4726e40f9e40d8267e115.tar.gz
Fixed bug in ALTER TABLE
Removed _mi_rkey() function New fork_big.pl multi-thread test BitKeeper/deleted/.del-fork3_test.pl~c4a7bffb4f8e813c: Delete: tests/fork3_test.pl BitKeeper/deleted/.del-fork_test.pl~3d3535329ed8cd5e: Delete: tests/fork_test.pl Docs/manual.texi: Changelog. Updated support information client/mysqladmin.c: Removed not used --timeout option configure.in: Update version myisam/mi_extra.c: Fixed bug in ALTER TABLE myisam/mi_rkey.c: Removed _mi_rkey() function myisam/myisamdef.h: Removed _mi_rkey() function myisammrg/myrg_rkey.c: Removed _mi_rkey() function myisammrg/myrg_rnext.c: Removed _mi_rkey() function mysql-test/t/alter_table.test: Added test case for ALTER TABLE bug sql/derror.cc: Moved shutdown message to clean_up sql/mysql_priv.h: Moved shutdown message to clean_up sql/sql_class.cc: Fixed bug in MySQL compiled with transactions but using --skip-"table-handler" sql/sql_show.cc: Use time_after_lock for time of query when debugging sql/sql_test.cc: Check memory overruns when using 'mysqladmin debug' strings/ctype-tis620.c: F
Diffstat (limited to 'tests')
-rwxr-xr-xtests/fork3_test.pl188
-rwxr-xr-xtests/fork_big.pl449
-rwxr-xr-xtests/fork_test.pl247
3 files changed, 449 insertions, 435 deletions
diff --git a/tests/fork3_test.pl b/tests/fork3_test.pl
deleted file mode 100755
index 032f1bf15e9..00000000000
--- a/tests/fork3_test.pl
+++ /dev/null
@@ -1,188 +0,0 @@
-#!/usr/bin/perl -w
-#
-# This is a test with uses 4 processes to insert, delete , check and select
-#
-
-$opt_loop_count=200000; # 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_db="test";
-
-GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in","skip-delete",
-"verbose","fast-insert","lock-tables","debug","fast","force") || die "Aborted";
-$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
-
-print "Testing 4 multiple connections to a server with 1 insert, 1 delete\n";
-print "1 select and one repair/check connection.\n";
-
-$firsttable = "bench_f1";
-
-####
-#### 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");
-
- print "Creating table $firsttable in database $opt_db\n";
- $dbh->do("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
- $dbh->disconnect; $dbh=0; # Close handler
-}
-$|= 1; # Autoflush
-
-####
-#### Start the tests
-####
-
-test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
-test_delete() if (($pid=fork()) == 0); $work{$pid}="delete";
-test_select() if (($pid=fork()) == 0); $work{$pid}="select1";
-repair_and_check() if (($pid=fork()) == 0); $work{$pid}="repair/check";
-
-$errors=0;
-while (($pid=wait()) != -1)
-{
- $ret=$?/256;
- print "thread '" . $work{$pid} . "' finnished 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");
- $dbh->disconnect; $dbh=0; # Close handler
-}
-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 table
-#
-
-sub test_insert
-{
- my ($dbh,$i,$sth);
-
- $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
- $opt_user, $opt_password,
- { PrintError => 0}) || die $DBI::errstr;
- for ($i=0 ; $i < $opt_loop_count; $i++)
- {
- $sth=$dbh->do("insert into $firsttable values ($i,'This is entry $i','')") || die "Got error on insert: $Mysql::db_errstr\n";
- $sth=0;
- }
- $dbh->disconnect; $dbh=0;
- print "Test_insert: Inserted $i rows\n";
- exit(0);
-}
-
-sub test_delete
-{
- my ($dbh,$i,$sth,@row);
-
- $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
- $opt_user, $opt_password,
- { PrintError => 0}) || die $DBI::errstr;
- for ($i=0 ; $i < $opt_loop_count ; $i++)
- {
- sleep(5);
- if ($opt_lock_tables)
- {
- $sth=$dbh->do("lock tables $firsttable WRITE") || die "Got error on lock tables $firsttable: $Mysql::db_errstr\n";
- }
- $sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on select from $firsttable: $dbh->errstr\n";
- $sth->execute || die $dbh->errstr;
- if ((@row = $sth->fetchrow_array()))
- {
- last if (!$row[0]); # Insert thread is probably ready
- }
- $sth=$dbh->do("delete from $firsttable") || die "Got error on delete from $firsttable: $dbh->errstr;\n";
- }
- $sth=0;
- $dbh->disconnect; $dbh=0;
- print "Test_delete: Deleted all rows $i times\n";
- exit(0);
-}
-
-
-#
-# select records
-#
-
-sub test_select
-{
- my ($dbh,$i,$sth,@row);
-
- $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
- $opt_user, $opt_password,
- { PrintError => 0}) || die $DBI::errstr;
- for ($i=0 ; $i < $opt_loop_count ; $i++)
- {
- $sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on select from $firsttable: $dbh->errstr;\n";
- $sth->execute || die $dbh->errstr;
- @row = $sth->fetchrow_array();
- $sth=0;
- }
- $dbh->disconnect; $dbh=0;
- print "Test_select: ok\n";
- exit(0);
-}
-
-sub repair_and_check
-{
- my ($dbh,$row,$found1,$last_found1,$i,$type, $table);
- $found1=0; $last_found1= -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 ; $i++)
- {
- $type=($i & 2) ? "repair" : "check";
- $table=$firsttable;
- $last_found1=$found1;
- $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();
- $found1= $row[0];
- $sth->finish;
- sleep(3);
- }
- $dbh->disconnect; $dbh=0;
- print "check/repair: Did $i repair/checks\n";
- exit(0);
-}
diff --git a/tests/fork_big.pl b/tests/fork_big.pl
new file mode 100755
index 00000000000..1644fdc5fab
--- /dev/null
+++ b/tests/fork_big.pl
@@ -0,0 +1,449 @@
+#!/usr/bin/perl -w
+#
+# This is a test with uses many processes to test a MySQL server.
+#
+# Tested a lot with: --threads=30
+
+$opt_loop_count=200000; # 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_threads=5;
+$opt_host=""; $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","threads=i") || die "Aborted";
+$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
+
+print "Test of multiple connections that test the following things:\n";
+print "insert, select, delete, update, check, repair and flush\n";
+
+@testtables = ( ["bench_f31", ""],
+ ["bench_f32", "row_format=fixed"],
+ ["bench_f33", "delay_key_write=1"],
+ ["bench_f34", "checksum=1"],
+ ["bench_f35", "delay_key_write=1"]);
+$abort_table="bench_f39";
+
+$numtables = $#testtables+1;
+srand 100; # Make random numbers repeatable
+####
+#### Start timeing and start test
+####
+
+$start_time=new Benchmark;
+$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+if (!$opt_skip_create)
+{
+ my $table_def;
+ foreach $table_def (@testtables)
+ {
+ my ($table,$extra)= ($table_def->[0], $table_def->[1]);
+ print "Creating table $table in database $opt_db\n";
+ $dbh->do("drop table if exists $table");
+ $dbh->do("create table $table".
+ " (id int(6) not null auto_increment,".
+ " info varchar(32)," .
+ " marker timestamp," .
+ " flag int not null," .
+ " primary key(id)) $extra")
+
+ or die $DBI::errstr;
+ # One row in the table will make future tests easier
+ $dbh->do("insert into $table (id) values (null)")
+ or die $DBI::errstr;
+ }
+ # Create the table we use to signal that we should end the test
+ $dbh->do("drop table if exists $abort_table");
+ $dbh->do("create table $abort_table (id int(6) not null) type=heap") ||
+ die $DBI::errstr;
+}
+
+$dbh->do("delete from $abort_table");
+$dbh->disconnect; $dbh=0; # Close handler
+$|= 1; # Autoflush
+
+####
+#### Start the tests
+####
+
+for ($i=0 ; $i < $opt_threads ; $i ++)
+{
+ test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
+}
+for ($i=0 ; $i < $numtables ; $i ++)
+{
+ test_insert($i,$i) if (($pid=fork()) == 0); $work{$pid}="insert_one";
+}
+for ($i=0 ; $i < $opt_threads ; $i ++)
+{
+ test_select() if (($pid=fork()) == 0); $work{$pid}="select_key";
+}
+test_delete() if (($pid=fork()) == 0); $work{$pid}="delete";
+test_update() if (($pid=fork()) == 0); $work{$pid}="update";
+test_flush() if (($pid=fork()) == 0); $work{$pid}= "flush";
+test_check() if (($pid=fork()) == 0); $work{$pid}="check";
+test_repair() if (($pid=fork()) == 0); $work{$pid}="repair";
+
+print "Started " . ($opt_threads*2+4) . " threads\n";
+
+$errors=0;
+$running_insert_threads=$opt_threads+$numtables;
+while (($pid=wait()) != -1)
+{
+ $ret=$?/256;
+ print "thread '" . $work{$pid} . "' finnished with exit code $ret\n";
+ if ($work{$pid} =~ /^insert/)
+ {
+ if (!--$running_insert_threads)
+ {
+ # Time to stop other threads
+ signal_abort();
+ }
+ }
+ $errors++ if ($ret != 0);
+}
+
+#
+# Cleanup
+#
+
+if (!$opt_skip_delete && !$errors)
+{
+ my $table_def;
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $dbh->do("drop table $abort_table");
+ foreach $table_def (@testtables)
+ {
+ $dbh->do("drop table " . $table_def->[0]);
+ }
+ $dbh->disconnect; $dbh=0; # Close handler
+}
+
+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 table
+#
+
+sub test_insert
+{
+ my ($from_table,$to_table)= @_;
+ my ($dbh,$i,$j,$count,$table_def,$table);
+
+ if (!defined($from_table))
+ {
+ $from_table=0; $to_table=$numtables-1;
+ }
+
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ for ($i=$count=0 ; $i < $opt_loop_count; $i++)
+ {
+ for ($j= $from_table ; $j <= $to_table ; $j++)
+ {
+ my ($table)= ($testtables[$j]->[0]);
+ $dbh->do("insert into $table values (NULL,'This is entry $i','',0)") || die "Got error on insert: $DBI::errstr\n";
+ $count++;
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "Test_insert: Inserted $count rows\n";
+ exit(0);
+}
+
+
+#
+# select records
+# Do continously select over all tables as long as there is changed
+# rows in the table
+#
+
+sub test_select
+{
+ my ($dbh, $i, $j, $count, $loop);
+
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $count_query=make_count_query($numtables);
+ $count=0;
+ $loop=9999;
+
+ $i=0;
+ while (($i++ % 100) || !test_if_abort($dbh))
+ {
+ if ($loop++ >= 100)
+ {
+ $loop=0;
+ $row_counts=simple_query($dbh, $count_query);
+ }
+ for ($j=0 ; $j < $numtables ; $j++)
+ {
+ my ($id)= int rand $row_counts->[$j];
+ my ($table)= $testtables[$j]->[0];
+ simple_query($dbh, "select id,info from $table where id=$id");
+ $count++;
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "Test_select: Executed $count selects\n";
+ exit(0);
+}
+
+#
+# Delete 1-5 rows from the first 2 tables.
+# Test ends when the number of rows for table 3 didn't change during
+# one loop
+#
+
+sub test_delete
+{
+ my ($dbh, $i,$j, $row_counts, $count_query, $table_count, $count);
+
+ $table_count=2;
+ $count=0;
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $count_query=make_count_query($table_count+1);
+
+ sleep(5); # Give time to insert some rows
+ $i=0;
+ while (($i++ % 10) || !test_if_abort($dbh))
+ {
+ sleep(1);
+ $row_counts=simple_query($dbh, $count_query);
+
+ for ($j=0 ; $j < $table_count ; $j++)
+ {
+ my ($id)= int rand $row_counts->[$j];
+ my ($table)= $testtables[$j]->[0];
+ $dbh->do("delete from $table where id >= $id-2 and id <= $id +2") || die "Got error on delete from $table: $DBI::errstr\n";
+ $count++;
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "Test_delete: Executed $count deletes\n";
+ exit(0);
+}
+
+#
+# Update the flag for table 2 and 3
+# Will abort after a while when table1 doesn't change max value
+#
+
+sub test_update
+{
+ my ($dbh, $i, $j, $row_counts, $count_query, $count, $loop);
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $count_query=make_count_query(3);
+ $loop=9999;
+ $count=0;
+
+ sleep(5); # Give time to insert some rows
+ $i=0;
+ while (($i++ % 100) || !test_if_abort($dbh))
+ {
+ if ($loop++ >= 100)
+ {
+ $loop=0;
+ $row_counts=simple_query($dbh, $count_query);
+ }
+
+ for ($j=1 ; $j <= 2 ; $j++)
+ {
+ my ($id)= int rand $row_counts->[$j];
+ my ($table)= $testtables[$j]->[0];
+ # Fix to not change the same rows as the above delete
+ $id= ($id + $count) % $row_counts->[$j];
+
+ $dbh->do("update $table set flag=flag+1 where id >= $id-2 and id <= $id +2") || die "Got error on update of $table: $DBI::errstr\n";
+ $count++;
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "Test_update: Executed $count updates\n";
+ exit(0);
+}
+
+
+#
+# Run a check on all tables except the last one
+# (The last one is not checked to put pressure on the key cache)
+#
+
+sub test_check
+{
+ my ($dbh, $row, $i, $j, $type, $table);
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $type= "check";
+ for ($i=$j=0 ; !test_if_abort($dbh) ; $i++)
+ {
+ sleep(60);
+ $table=$testtables[$j]->[0];
+ $sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $DBI::errstr\n";
+ $sth->execute || die $DBI::errstr;
+
+ while (($row=$sth->fetchrow_arrayref))
+ {
+ if ($row->[3] ne "OK")
+ {
+ print "Got error " . $row->[3] . " when doing $type on $table\n";
+ exit(1);
+ }
+ }
+ if (++$j == $numtables-1)
+ {
+ $j=0;
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "test_check: Executed $i checks\n";
+ exit(0);
+}
+
+
+#
+# Do a repair on the first table once in a while
+#
+
+sub test_repair
+{
+ my ($dbh, $row, $i, $type, $table);
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $type= "repair";
+ for ($i=0 ; !test_if_abort($dbh) ; $i++)
+ {
+ sleep(95);
+ $table=$testtables[0]->[0];
+ $sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $DBI::errstr\n";
+ $sth->execute || die $DBI::errstr;
+
+ while (($row=$sth->fetchrow_arrayref))
+ {
+ if ($row->[3] ne "OK")
+ {
+ print "Got error " . $row->[3] . " when doing $type on $table\n";
+ exit(1);
+ }
+ }
+ }
+ $dbh->disconnect; $dbh=0;
+ print "test_repair: Executed $i repairs\n";
+ exit(0);
+}
+
+#
+# Do a flush tables on table 3 and 4 once in a while
+#
+
+sub test_flush
+{
+ my ($dbh,$count,$tables);
+
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $tables=$testtables[2]->[0] . "," . $testtables[3]->[0];
+
+ $count=0;
+ while (!test_if_abort($dbh))
+ {
+ sleep(60);
+ $dbh->do("flush tables $tables") ||
+ die "Got error on flush $DBI::errstr\n";
+ $count++;
+ }
+ $dbh->disconnect; $dbh=0;
+ print "flush: Executed $count flushs\n";
+ exit(0);
+}
+
+#
+# Help functions
+#
+
+sub signal_abort
+{
+ my ($dbh);
+ $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
+ $opt_user, $opt_password,
+ { PrintError => 0}) || die $DBI::errstr;
+
+ $dbh->do("insert into $abort_table values(1)") || die $DBI::errstr;
+ $dbh->disconnect; $dbh=0;
+ exit(0);
+}
+
+
+sub test_if_abort()
+{
+ my ($dbh)=@_;
+ $row=simple_query($dbh,"select * from $abort_table");
+ return (defined($row) && defined($row->[0]) != 0) ? 1 : 0;
+}
+
+
+sub make_count_query
+{
+ my ($table_count)= @_;
+ my ($tables, $count_query, $i, $tables_def);
+ $tables="";
+ $count_query="select high_priority ";
+ $table_count--;
+ for ($i=0 ; $i < $table_count ; $i++)
+ {
+ my ($table_def)= $testtables[$i];
+ $tables.=$table_def->[0] . ",";
+ $count_query.= "max(" . $table_def->[0] . ".id),";
+ }
+ $table_def=$testtables[$table_count];
+ $tables.=$table_def->[0];
+ $count_query.= "max(" . $table_def->[0] . ".id) from $tables";
+ return $count_query;
+}
+
+sub simple_query()
+{
+ my ($dbh, $query)= @_;
+ my ($sth,$row);
+
+ $sth=$dbh->prepare($query) || die "Got error on '$query': $DBI::errstr\n";
+ $sth->execute || die "Got error on '$query': $dbh->errstr\n";
+ $row= $sth->fetchrow_arrayref();
+ $sth=0;
+ return $row;
+}
diff --git a/tests/fork_test.pl b/tests/fork_test.pl
deleted file mode 100755
index 26c614a364a..00000000000
--- a/tests/fork_test.pl
+++ /dev/null
@@ -1,247 +0,0 @@
-#!/usr/bin/perl -w
-
-# This is a test with uses 5 processes to insert, update and select from
-# two tables.
-# One inserts records in the tables, one updates some record in it and
-# the last 3 does different selects on the tables.
-#
-
-$opt_loop_count=10000; # Change this to make test harder/easier
-
-##################### Standard benchmark inits ##############################
-
-use Mysql;
-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_db="test";
-
-GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in",
- "skip-delete","verbose","fast-insert","lock-tables","debug","fast",
- "force") || die "Aborted";
-$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$Mysql::db_errstr=$opt_force=undef; # Ignore warnings from these
-
-print "Testing 5 multiple connections to a server with 1 insert, 1 update\n";
-print "and 3 select connections.\n";
-
-
-$firsttable = "bench_f1";
-$secondtable = "bench_f2";
-
-####
-#### Start timeing and start test
-####
-
-$start_time=new Benchmark;
-if (!$opt_skip_create)
-{
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $Mysql::QUIET = 1;
- $dbh->Query("drop table $firsttable");
- $dbh->Query("drop table $secondtable");
- $Mysql::QUIET = 0;
-
- print "Creating tables $firsttable and $secondtable in database $opt_db\n";
- $dbh->Query("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") or die $Mysql::db_errstr;
- $dbh->Query("create table $secondtable (id int(6) not null, row int(3) not null,value double, primary key(id,row))") or die $Mysql::db_errstr;
-
- $dbh=0; # Close handler
-}
-$|= 1; # Autoflush
-
-####
-#### Start the tests
-####
-
-test_1() if (($pid=fork()) == 0); $work{$pid}="insert";
-test_2() if (($pid=fork()) == 0); $work{$pid}="update";
-test_3() if (($pid=fork()) == 0); $work{$pid}="select1";
-test_4() if (($pid=fork()) == 0); $work{$pid}="select2";
-test_5() if (($pid=fork()) == 0); $work{$pid}="select3";
-
-$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 = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $dbh->Query("drop table $firsttable");
- $dbh->Query("drop table $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 test_1
-{
- my ($dbh,$tmpvar,$rows,$found,$i);
-
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $tmpvar=1;
- $rows=$found=0;
- for ($i=0 ; $i < $opt_loop_count; $i++)
- {
- $tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
- $sth=$dbh->Query("insert into $firsttable values ($i,'This is entry $i','')") || die "Got error on insert: $Mysql::db_errstr\n";
- $row_count=($i % 7)+1;
- $rows+=1+$row_count;
- for ($j=0 ; $j < $row_count; $j++)
- {
- $sth=$dbh->Query("insert into $secondtable values ($i,$j,0)") || die "Got error on insert: $Mysql::db_errstr\n";
- }
- if (($tmpvar % 10) == 0)
- {
- $sth=$dbh->Query("select max(info) from $firsttable") || die "Got error on select max(info): $Mysql::db_errstr\n";
- $sth=$dbh->Query("select max(value) from $secondtable") || die "Got error on select max(info): $Mysql::db_errstr\n";
- $found+=2;
- }
- }
- $dbh=0;
- print "Test_1: Inserted $rows rows, found $found rows\n";
- exit(0);
-}
-
-#
-# Update records in both tables
-#
-
-sub test_2
-{
- my ($dbh,$id,$tmpvar,$rows,$found,$i,$max_id,$tmp);
-
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $tmpvar=111111;
- $rows=$found=$max_id=$id=0;
- for ($i=0 ; $i < $opt_loop_count ; $i++)
- {
- $tmp=(($tmpvar + 63) + $i)*3;
- $tmp=$tmp-int($tmp/100000)*100000;
- $tmpvar^= $tmp;
- $tmp=$tmpvar - int($tmpvar/10)*10;
- if ($max_id < 2 || $tmp == 0)
- {
- $max_id=0;
- $sth=$dbh->Query("select max(id) from $firsttable where marker=''") || die "Got error select max: $Mysql::db_errstr\n";
- if ((@row = $sth->FetchRow()) && defined($row[0]))
- {
- $found++;
- $max_id=$id=$row[0];
- }
- }
- else
- {
- $id= $tmpvar % ($max_id-1)+1;
- }
- if ($id)
- {
- $sth=$dbh->Query("update $firsttable set marker='x' where id=$id") || die "Got error update $firsttable: $Mysql::db_errstr\n";
- $rows+=$sth->affected_rows;
- if ($sth->affected_rows)
- {
- $sth=$dbh->Query("update $secondtable set value=$i where id=$id") || die "Got error update $firsttable: $Mysql::db_errstr\n";
- $rows+=$sth->affected_rows;
- }
- }
- }
- $dbh=0;
- print "Test_2: Found $found rows, Updated $rows rows\n";
- exit(0);
-}
-
-
-#
-# select records
-#
-
-sub test_3
-{
- my ($dbh,$id,$tmpvar,$rows,$i);
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $tmpvar=222222;
- $rows=0;
- for ($i=0 ; $i < $opt_loop_count ; $i++)
- {
- $tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
- $id=$tmpvar % $opt_loop_count;
- $sth=$dbh->Query("select id from $firsttable where id=$id") || die "Got error on select from $firsttable: $Mysql::db_errstr\n";
- $rows+=$sth->numrows;
- }
- $dbh=0;
- print "Test_3: Found $rows rows\n";
- exit(0);
-}
-
-
-#
-# Note that this uses row=1 and in some cases won't find any matching
-# records
-#
-
-sub test_4
-{
- my ($dbh,$id,$tmpvar,$rows,$i);
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $tmpvar=333333;
- $rows=0;
- for ($i=0 ; $i < $opt_loop_count; $i++)
- {
- $tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
- $id=$tmpvar % $opt_loop_count;
- $sth=$dbh->Query("select id from $secondtable where id=$id") || die "Got error on select form $secondtable: $Mysql::db_errstr\n";
- $rows+=$sth->numrows;
- }
- $dbh=0;
- print "Test_4: Found $rows rows\n";
- exit(0);
-}
-
-
-sub test_5
-{
- my ($dbh,$id,$tmpvar,$rows,$i,$max_id);
- $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
- $tmpvar=444444;
- $rows=$max_id=0;
- for ($i=0 ; $i < $opt_loop_count ; $i++)
- {
- $tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
- if ($max_id == 0 || ($tmpvar % 10 == 0))
- {
- $sth=$dbh->Query("select max(id) from $firsttable") || die "Got error select max: $Mysql::db_errstr\n";
- if ((@row = $sth->FetchRow()) && defined($row[0]))
- {
- $max_id=$id=$row[0];
- }
- else
- {
- $id=0;
- }
- }
- else
- {
- $id= $tmpvar % $max_id;
- }
- $sth=$dbh->Query("select value from $firsttable,$secondtable where $firsttable.id=$id and $secondtable.id=$firsttable.id") || die "Got error on select form $secondtable: $Mysql::db_errstr\n";
- $rows+=$sth->numrows;
- }
- $dbh=0;
- print "Test_5: Found $rows rows\n";
- exit(0);
-}