mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 03:51:50 +01:00
ee1c5226b9
Fixed memory leak in _db_set() (Bug#24497 Valgrind warning: get_one_option) Don't call net_clear() on COM_QUIT. This avoids a warning from net_clear() after shutdown: "skipped ## bytes from file" BUG#21428: skipped 9 bytes from file: socket (3)" on "mysqladmin shutdown" sql-bench/test-wisconsin.sh: Rename: BitKeeper/deleted/.del-test-wisconsin.sh~c0b86821b5f95f26 -> sql-bench/test-wisconsin.sh sql-bench/test-transactions.sh: Rename: BitKeeper/deleted/.del-test-transactions.sh~c1c892f10c40caf -> sql-bench/test-transactions.sh sql-bench/test-insert.sh: Rename: BitKeeper/deleted/.del-test-insert.sh~893bfac9dedb79a7 -> sql-bench/test-insert.sh sql-bench/test-select.sh: Rename: BitKeeper/deleted/.del-test-select.sh~6d5cc770acf11be6 -> sql-bench/test-select.sh sql-bench/test-create.sh: Rename: BitKeeper/deleted/.del-test-create.sh~f9a1ea38c191b17a -> sql-bench/test-create.sh sql-bench/test-big-tables.sh: Rename: BitKeeper/deleted/.del-test-big-tables.sh~5b1b0c5fb623565a -> sql-bench/test-big-tables.sh sql-bench/test-connect.sh: Rename: BitKeeper/deleted/.del-test-connect.sh~382a728c949ee075 -> sql-bench/test-connect.sh sql-bench/test-ATIS.sh: Rename: BitKeeper/deleted/.del-test-ATIS.sh~e8ebff7086c95773 -> sql-bench/test-ATIS.sh sql-bench/test-alter-table.sh: Rename: BitKeeper/deleted/.del-test-alter-table.sh~eba6cfa9972fcced -> sql-bench/test-alter-table.sh sql-bench/innotest2b.sh: Rename: BitKeeper/deleted/.del-innotest2b.sh~7b99ece835e8dff3 -> sql-bench/innotest2b.sh sql-bench/run-all-tests.sh: Rename: BitKeeper/deleted/.del-run-all-tests.sh~41d6da1cf211ee95 -> sql-bench/run-all-tests.sh sql-bench/innotest2.sh: Rename: BitKeeper/deleted/.del-innotest2.sh~9c14df528285603 -> sql-bench/innotest2.sh sql-bench/innotest2a.sh: Rename: BitKeeper/deleted/.del-innotest2a.sh~e01d016a7cafdc0b -> sql-bench/innotest2a.sh sql-bench/innotest1a.sh: Rename: BitKeeper/deleted/.del-innotest1a.sh~c64f4610ae1e26fe -> sql-bench/innotest1a.sh sql-bench/innotest1b.sh: Rename: BitKeeper/deleted/.del-innotest1b.sh~aafd0819ae84da7b -> sql-bench/innotest1b.sh sql-bench/innotest1.sh: Rename: BitKeeper/deleted/.del-innotest1.sh~aa36bce09ca783c7 -> sql-bench/innotest1.sh sql-bench/crash-me.sh: Rename: BitKeeper/deleted/.del-crash-me.sh~2fa881d0b40339c8 -> sql-bench/crash-me.sh sql-bench/graph-compare-results.sh: Rename: BitKeeper/deleted/.del-graph-compare-results.sh~7e4e28b3591b4542 -> sql-bench/graph-compare-results.sh sql-bench/copy-db.sh: Rename: BitKeeper/deleted/.del-copy-db.sh~e8116afb93144ccd -> sql-bench/copy-db.sh sql-bench/compare-results.sh: Rename: BitKeeper/deleted/.del-compare-results.sh~a9e26e2644c694b3 -> sql-bench/compare-results.sh sql-bench/bench-count-distinct.sh: Rename: BitKeeper/deleted/.del-bench-count-distinct.sh~a92f174271a831d7 -> sql-bench/bench-count-distinct.sh sql-bench/as3ap.sh: Rename: BitKeeper/deleted/.del-as3ap.sh~f54eebbd8d34c9b6 -> sql-bench/as3ap.sh sql-bench/Comments/Informix.crash-me: Rename: BitKeeper/deleted/.del-Informix.crash-me~51ab5b717cefe74 -> sql-bench/Comments/Informix.crash-me sql-bench/Comments/postgres.crash-me: Rename: BitKeeper/deleted/.del-postgres.crash-me~eacac145c3e30f17 -> sql-bench/Comments/postgres.crash-me sql-bench/Comments/Empress.crash-me: Rename: BitKeeper/deleted/.del-Empress.crash-me~bdaff0c68ce10f02 -> sql-bench/Comments/Empress.crash-me sql-bench/Comments/Adabas.crash-me: Rename: BitKeeper/deleted/.del-Adabas.crash-me~ce88ba1a540971ac -> sql-bench/Comments/Adabas.crash-me sql-bench/Comments/Access.crash-me: Rename: BitKeeper/deleted/.del-Access.crash-me~bb457ec282d939b6 -> sql-bench/Comments/Access.crash-me sql-bench/Comments/postgres.benchmark: Rename: BitKeeper/deleted/.del-postgres.benchmark~4d30890732b784a -> sql-bench/Comments/postgres.benchmark sql-bench/Comments/mysql.benchmark: Rename: BitKeeper/deleted/.del-mysql.benchmark~4d8729c0937456fc -> sql-bench/Comments/mysql.benchmark sql-bench/Comments/FrontBase.benchmark: Rename: BitKeeper/deleted/.del-FrontBase.benchmark~217041ef18274c2e -> sql-bench/Comments/FrontBase.benchmark sql-bench/Comments/interbase: Rename: BitKeeper/deleted/.del-interbase~cdad59622b4d6f3 -> sql-bench/Comments/interbase sql-bench/uname.bat: Rename: BitKeeper/deleted/.del-uname.bat~a6d933d2ee9314c -> sql-bench/uname.bat sql-bench/pwd.bat: Rename: BitKeeper/deleted/.del-pwd.bat~9b64050849abf51 -> sql-bench/pwd.bat sql-bench/example.bat: Rename: BitKeeper/deleted/.del-example.bat~22d0170bccf0f030 -> sql-bench/example.bat sql-bench/Makefile.am: Rename: BitKeeper/deleted/.del-Makefile.am~7b07da85b2e9375 -> sql-bench/Makefile.am sql-bench/Data/ATIS/transport.txt: Rename: BitKeeper/deleted/.del-transport.txt~fa4ca40735f8354c -> sql-bench/Data/ATIS/transport.txt sql-bench/Data/ATIS/time_zone.txt: Rename: BitKeeper/deleted/.del-time_zone.txt~4171f9ca732f65c0 -> sql-bench/Data/ATIS/time_zone.txt sql-bench/Data/Wisconsin/tenk.data: Rename: BitKeeper/deleted/.del-tenk.data~6aeaebdd534e458e -> sql-bench/Data/Wisconsin/tenk.data sql-bench/Data/Wisconsin/onek.data: Rename: BitKeeper/deleted/.del-onek.data~6cd1edaf596a7f7 -> sql-bench/Data/Wisconsin/onek.data sql-bench/Data/ATIS/stop1.txt: Rename: BitKeeper/deleted/.del-stop1.txt~f09ba164ad44a288 -> sql-bench/Data/ATIS/stop1.txt sql-bench/Data/ATIS/time_interval.txt: Rename: BitKeeper/deleted/.del-time_interval.txt~a1def62e267a59b2 -> sql-bench/Data/ATIS/time_interval.txt sql-bench/Data/ATIS/stop.txt: Rename: BitKeeper/deleted/.del-stop.txt~31fb564e1f415e34 -> sql-bench/Data/ATIS/stop.txt sql-bench/Data/ATIS/restriction.txt: Rename: BitKeeper/deleted/.del-restriction.txt~6ae208924617784a -> sql-bench/Data/ATIS/restriction.txt sql-bench/Data/ATIS/state.txt: Rename: BitKeeper/deleted/.del-state.txt~9dd470ce14075b90 -> sql-bench/Data/ATIS/state.txt sql-bench/Data/ATIS/restrict_class.txt: Rename: BitKeeper/deleted/.del-restrict_class.txt~2f741bf0ea498f84 -> sql-bench/Data/ATIS/restrict_class.txt sql-bench/Data/ATIS/month_name.txt: Rename: BitKeeper/deleted/.del-month_name.txt~4c44f7a323d57d92 -> sql-bench/Data/ATIS/month_name.txt sql-bench/Data/ATIS/restrict_carrier.txt: Rename: BitKeeper/deleted/.del-restrict_carrier.txt~925b5492f3f9cba3 -> sql-bench/Data/ATIS/restrict_carrier.txt sql-bench/Data/ATIS/ground_service.txt: Rename: BitKeeper/deleted/.del-ground_service.txt~1087e477e86e84c -> sql-bench/Data/ATIS/ground_service.txt sql-bench/Data/ATIS/food_service.txt: Rename: BitKeeper/deleted/.del-food_service.txt~66d95a150c28458 -> sql-bench/Data/ATIS/food_service.txt sql-bench/Data/ATIS/flight_day.txt: Rename: BitKeeper/deleted/.del-flight_day.txt~76868d6d265d441e -> sql-bench/Data/ATIS/flight_day.txt sql-bench/Data/ATIS/flight_fare.txt: Rename: BitKeeper/deleted/.del-flight_fare.txt~d7322593c8530487 -> sql-bench/Data/ATIS/flight_fare.txt sql-bench/Data/ATIS/flight_class.txt: Rename: BitKeeper/deleted/.del-flight_class.txt~1801101474c29098 -> sql-bench/Data/ATIS/flight_class.txt sql-bench/Data/ATIS/fconnection.txt: Rename: BitKeeper/deleted/.del-fconnection.txt~e0ef6a8b5560a713 -> sql-bench/Data/ATIS/fconnection.txt sql-bench/Data/ATIS/flight.txt: Rename: BitKeeper/deleted/.del-flight.txt~e5065423760e99eb -> sql-bench/Data/ATIS/flight.txt sql-bench/Data/ATIS/fare.txt: Rename: BitKeeper/deleted/.del-fare.txt~ea0652f490bc24a6 -> sql-bench/Data/ATIS/fare.txt sql-bench/Data/ATIS/day_name.txt: Rename: BitKeeper/deleted/.del-day_name.txt~f813b215955d894c -> sql-bench/Data/ATIS/day_name.txt sql-bench/Data/ATIS/dual_carrier.txt: Rename: BitKeeper/deleted/.del-dual_carrier.txt~a7dd776224fbd92b -> sql-bench/Data/ATIS/dual_carrier.txt sql-bench/Data/ATIS/date_day.txt: Rename: BitKeeper/deleted/.del-date_day.txt~4e9a282fcf54cfd8 -> sql-bench/Data/ATIS/date_day.txt sql-bench/Data/ATIS/compound_class.txt: Rename: BitKeeper/deleted/.del-compound_class.txt~d4a2f1b7f96340b9 -> sql-bench/Data/ATIS/compound_class.txt sql-bench/Data/ATIS/connect_leg.txt: Rename: BitKeeper/deleted/.del-connect_leg.txt~f97b6e94e108bb36 -> sql-bench/Data/ATIS/connect_leg.txt sql-bench/Data/ATIS/code_description.txt: Rename: BitKeeper/deleted/.del-code_description.txt~f9117373e438b0e2 -> sql-bench/Data/ATIS/code_description.txt sql-bench/Data/ATIS/city.txt: Rename: BitKeeper/deleted/.del-city.txt~d96dd6d073344d2e -> sql-bench/Data/ATIS/city.txt sql-bench/Data/ATIS/class_of_service.txt: Rename: BitKeeper/deleted/.del-class_of_service.txt~21f6b9848b8c76d -> sql-bench/Data/ATIS/class_of_service.txt sql-bench/Data/ATIS/airport_service.txt: Rename: BitKeeper/deleted/.del-airport_service.txt~6ee6d5b852b3e38 -> sql-bench/Data/ATIS/airport_service.txt sql-bench/Data/ATIS/airline.txt: Rename: BitKeeper/deleted/.del-airline.txt~a79f8eadf853f2c8 -> sql-bench/Data/ATIS/airline.txt sql-bench/Data/ATIS/airport.txt: Rename: BitKeeper/deleted/.del-airport.txt~59c78514130e1f45 -> sql-bench/Data/ATIS/airport.txt sql-bench/Data/ATIS/aircraft.txt: Rename: BitKeeper/deleted/.del-aircraft.txt~15e4de7ab37c92d3 -> sql-bench/Data/ATIS/aircraft.txt sql-bench/TODO: Rename: BitKeeper/deleted/.del-TODO~cac6d7a63c426ae5 -> sql-bench/TODO sql-bench/limits/sybase.cfg: Rename: BitKeeper/deleted/.del-sybase.cfg~c4636b12767b3f14 -> sql-bench/limits/sybase.cfg sql-bench/limits/solid-nt4.cfg: Rename: BitKeeper/deleted/.del-solid-nt4.cfg~cca779f0c9e29d31 -> sql-bench/limits/solid-nt4.cfg sql-bench/limits/solid.cfg: Rename: BitKeeper/deleted/.del-solid.cfg~5ae0e4342eadb0fb -> sql-bench/limits/solid.cfg sql-bench/limits/pg.cfg: Rename: BitKeeper/deleted/.del-pg.cfg~db59cf39a5d417be -> sql-bench/limits/pg.cfg sql-bench/limits/mysql.cfg: Rename: BitKeeper/deleted/.del-mysql.cfg~9cab20a8771b93cf -> sql-bench/limits/mysql.cfg sql-bench/limits/oracle.cfg: Rename: BitKeeper/deleted/.del-oracle.cfg~affab21af8f438fd -> sql-bench/limits/oracle.cfg sql-bench/limits/mysql-4.1.cfg: Rename: BitKeeper/deleted/.del-mysql-4.1.cfg~b6c5e74aefc99e3c -> sql-bench/limits/mysql-4.1.cfg sql-bench/limits/mysql-3.23.cfg: Rename: BitKeeper/deleted/.del-mysql-3.23.cfg~3cf9d6be54b77a3c -> sql-bench/limits/mysql-3.23.cfg sql-bench/limits/mysql-4.0.cfg: Rename: BitKeeper/deleted/.del-mysql-4.0.cfg~6c9d63c85b5ef574 -> sql-bench/limits/mysql-4.0.cfg sql-bench/limits/mysql-3.22.cfg: Rename: BitKeeper/deleted/.del-mysql-3.22.cfg~e706f26a161175cd -> sql-bench/limits/mysql-3.22.cfg sql-bench/limits/msql.cfg: Rename: BitKeeper/deleted/.del-msql.cfg~52710b12932cceb9 -> sql-bench/limits/msql.cfg sql-bench/limits/ms-sql65.cfg: Rename: BitKeeper/deleted/.del-ms-sql65.cfg~6b9bc3c460dbee05 -> sql-bench/limits/ms-sql65.cfg sql-bench/limits/mimer.cfg: Rename: BitKeeper/deleted/.del-mimer.cfg~234e6c1c3c47b612 -> sql-bench/limits/mimer.cfg sql-bench/limits/ms-sql.cfg: Rename: BitKeeper/deleted/.del-ms-sql.cfg~1907964264d2786a -> sql-bench/limits/ms-sql.cfg sql-bench/limits/interbase.cfg: Rename: BitKeeper/deleted/.del-interbase.cfg~c6951a0376cc6ff3 -> sql-bench/limits/interbase.cfg sql-bench/limits/interbase-dialect3.cfg: Rename: BitKeeper/deleted/.del-interbase-dialect3.cfg~46277bdfc74c667a -> sql-bench/limits/interbase-dialect3.cfg sql-bench/limits/interbase-superserver.cfg: Rename: BitKeeper/deleted/.del-interbase-superserver.cfg~22501198689243b0 -> sql-bench/limits/interbase-superserver.cfg sql-bench/limits/interbase-dialect1.cfg: Rename: BitKeeper/deleted/.del-interbase-dialect1.cfg~659206b5b9a11036 -> sql-bench/limits/interbase-dialect1.cfg sql-bench/limits/empress.cfg: Rename: BitKeeper/deleted/.del-empress.cfg~1f97f34d6560a499 -> sql-bench/limits/empress.cfg sql-bench/limits/frontbase.cfg: Rename: BitKeeper/deleted/.del-frontbase.cfg~71369e9c002696e -> sql-bench/limits/frontbase.cfg sql-bench/limits/db2.cfg: Rename: BitKeeper/deleted/.del-db2.cfg~711099b4d7906959 -> sql-bench/limits/db2.cfg sql-bench/limits/access.cfg: Rename: BitKeeper/deleted/.del-access.cfg~5239ea3655b7bba0 -> sql-bench/limits/access.cfg sql-bench/limits/access_odbc.cfg: Rename: BitKeeper/deleted/.del-access_odbc.cfg~34b4cf0eda56c4b1 -> sql-bench/limits/access_odbc.cfg sql-bench/limits/Informix.cfg: Rename: BitKeeper/deleted/.del-Informix.cfg~b94188e1ececb51b -> sql-bench/limits/Informix.cfg sql-bench/limits/Adabas.cfg: Rename: BitKeeper/deleted/.del-Adabas.cfg~343ed4e7f8b02111 -> sql-bench/limits/Adabas.cfg sql-bench/README: Rename: BitKeeper/deleted/.del-README~b1aa0c1bf9f5eb5e -> sql-bench/README BitKeeper/deleted/.del-create-pg_fast-Linux_2.2.14_my_SMP_i686-crashed: Delete: sql-bench/Results/create-pg_fast-Linux_2.2.14_my_SMP_i686-crashed Makefile.am: Added back sql-bench configure.in: Added back sql-bench dbug/dbug.c: Fixed memory leak in _db_set() This is not a complete fix as we can still get memory leaks if we do any of the following: mysqld --debug --debug CAll DBUG_SET or DBUG_SET_INITIAL more than once in a program Use SET @@global.debug=xxxx At some point we should fix the above, but this is not critical for normal operation (only for debugging) Bug #24497 Valgrind warning: get_one_option Note that all changes to _db_set_ is only a variable access change, and can be ignored while reviewing the bug fix. mysql-test/t/flush_read_lock_kill-master.opt: Added '+' to option, to be able to use this together with --debug mysql-test/valgrind.supp: Removed warning that is now fixed mysys/ptr_cmp.c: Fixed wrong pointer read (probably never used) scripts/make_binary_distribution.sh: Added back sql_bench sql/field.h: Removed class function that was identical in parent class sql/mysqld.cc: Removed some calls to my_thread_init() / my_thread_end() that was not needed. Only call DBUG_SET_INITAL, not DBUG_SET (Fixes memory leak in dbug) Mark some code as deadcode sql/net_serv.cc: Add information about from where error comes sql-bench/bench-init.pl.sh: Cleaned up help text sql-bench/server-cfg.sh: Don't write '/' after server name of no ssl version sql-common/client.c: Don't call net_clear() on COM_QUIT. This avoids a warning from net_clear() after shutdown: "skipped ## bytes from file" BUG#21428: skipped 9 bytes from file: socket (3)" on "mysqladmin shutdown" sql/sql_parse.cc: Added comment sql/table.h: Removed compiler warning
1801 lines
50 KiB
Bash
1801 lines
50 KiB
Bash
#!@PERL@
|
|
# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
#
|
|
# This library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Library General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2 of the License, or (at your option) any later version.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Library General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Library General Public
|
|
# License along with this library; if not, write to the Free
|
|
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
# MA 02111-1307, USA
|
|
#
|
|
# Test of creating a simple table and inserting $record_count records in it,
|
|
# $opt_loop_count rows in order, $opt_loop_count rows in reverse order and
|
|
# $opt_loop_count rows in random order
|
|
#
|
|
# changes made for Oracle compatibility
|
|
# - $limits->{'func_odbc_mod'} is OK from crash-me, but it fails here so set we
|
|
# set it to 0 in server-cfg
|
|
# - the default server config runs out of rollback segments, so we added a
|
|
# couple of disconnect/connects to reset
|
|
#
|
|
##################### Standard benchmark inits ##############################
|
|
|
|
use Cwd;
|
|
use DBI;
|
|
use Benchmark;
|
|
use Data::Dumper;
|
|
|
|
$opt_loop_count=100000; # number of rows/3
|
|
$small_loop_count=10; # Loop for full table retrieval
|
|
$range_loop_count=$small_loop_count*50;
|
|
$many_keys_loop_count=$opt_loop_count;
|
|
$opt_read_key_loop_count=$opt_loop_count;
|
|
|
|
$pwd = cwd(); $pwd = "." if ($pwd eq '');
|
|
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
|
|
|
|
if ($opt_small_test)
|
|
{
|
|
$opt_loop_count/=100;
|
|
$many_keys_loop_count=$opt_loop_count/10;
|
|
$range_loop_count=10;
|
|
$opt_read_key_loop_count=10;
|
|
}
|
|
elsif ($opt_small_tables)
|
|
{
|
|
$opt_loop_count=10000; # number of rows/3
|
|
$many_keys_loop_count=$opt_loop_count;
|
|
$opt_read_key_loop_count=10;
|
|
}
|
|
elsif ($opt_small_key_tables)
|
|
{
|
|
$many_keys_loop_count/=10;
|
|
}
|
|
|
|
if ($opt_loop_count < 100)
|
|
{
|
|
$opt_loop_count=100; # Some tests must have some data to work!
|
|
}
|
|
$range_loop_count=min($opt_loop_count,$range_loop_count);
|
|
|
|
|
|
print "Testing the speed of inserting data into 1 table and do some selects on it.\n";
|
|
print "The tests are done with a table that has $opt_loop_count rows.\n\n";
|
|
|
|
####
|
|
#### Generating random keys
|
|
####
|
|
|
|
print "Generating random keys\n";
|
|
$random[$opt_loop_count]=0;
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$random[$i]=$i+$opt_loop_count;
|
|
}
|
|
|
|
my $tmpvar=1;
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
|
|
$swap=$tmpvar % $opt_loop_count;
|
|
$tmp=$random[$i]; $random[$i]=$random[$swap]; $random[$swap]=$tmp;
|
|
}
|
|
|
|
$total_rows=$opt_loop_count*3;
|
|
|
|
####
|
|
#### Connect and start timeing
|
|
####
|
|
$start_time=new Benchmark;
|
|
$dbh = $server->connect();
|
|
####
|
|
#### Create needed tables
|
|
####
|
|
|
|
goto keys_test if ($opt_stage == 2);
|
|
goto select_test if ($opt_skip_create);
|
|
|
|
print "Creating tables\n";
|
|
$dbh->do("drop table bench1" . $server->{'drop_attr'});
|
|
$dbh->do("drop table bench2" . $server->{'drop_attr'});
|
|
$dbh->do("drop table bench3" . $server->{'drop_attr'});
|
|
do_many($dbh,$server->create("bench1",
|
|
["id int NOT NULL",
|
|
"id2 int NOT NULL",
|
|
"id3 int NOT NULL",
|
|
"dummy1 char(30)"],
|
|
["primary key (id,id2)",
|
|
"index ix_id3 (id3)"]));
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
|
|
####
|
|
#### Insert $total_rows records in order, in reverse order and random.
|
|
####
|
|
|
|
$loop_time=new Benchmark;
|
|
|
|
if ($opt_fast_insert)
|
|
{
|
|
$query="insert into bench1 values ";
|
|
}
|
|
else
|
|
{
|
|
$query="insert into bench1 (id,id2,id3,dummy1) values ";
|
|
}
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->{AutoCommit} = 0;
|
|
print "Transactions enabled\n" if ($opt_debug);
|
|
}
|
|
|
|
if (($opt_fast || $opt_fast_insert) && $server->{'limits'}->{'insert_multi_value'})
|
|
{
|
|
$query_size=$server->{'limits'}->{'query_size'};
|
|
|
|
print "Inserting $opt_loop_count multiple-value rows in order\n";
|
|
$res=$query;
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$tmp= "($i,$i,$i,'ABCDEFGHIJ'),";
|
|
if (length($tmp)+length($res) < $query_size)
|
|
{
|
|
$res.= $tmp;
|
|
}
|
|
else
|
|
{
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
$res=$query . $tmp;
|
|
}
|
|
}
|
|
print "Inserting $opt_loop_count multiple-value rows in reverse order\n";
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$tmp= "(" . ($total_rows-1-$i) . "," .($total_rows-1-$i) .
|
|
"," .($total_rows-1-$i) . ",'BCDEFGHIJK'),";
|
|
if (length($tmp)+length($res) < $query_size)
|
|
{
|
|
$res.= $tmp;
|
|
}
|
|
else
|
|
{
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
$res=$query . $tmp;
|
|
}
|
|
}
|
|
print "Inserting $opt_loop_count multiple-value rows in random order\n";
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$tmp= "(" . $random[$i] . "," . $random[$i] . "," . $random[$i] .
|
|
",'CDEFGHIJKL')," or die $DBI::errstr;
|
|
if (length($tmp)+length($res) < $query_size)
|
|
{
|
|
$res.= $tmp;
|
|
}
|
|
else
|
|
{
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
$res=$query . $tmp;
|
|
}
|
|
}
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
}
|
|
else
|
|
{
|
|
print "Inserting $opt_loop_count rows in order\n";
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$sth = $dbh->do($query . "($i,$i,$i,'ABCDEFGHIJ')") or die $DBI::errstr;
|
|
}
|
|
|
|
print "Inserting $opt_loop_count rows in reverse order\n";
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$sth = $dbh->do($query . "(" . ($total_rows-1-$i) . "," .
|
|
($total_rows-1-$i) . "," .
|
|
($total_rows-1-$i) . ",'BCDEFGHIJK')")
|
|
or die $DBI::errstr;
|
|
}
|
|
|
|
print "Inserting $opt_loop_count rows in random order\n";
|
|
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$sth = $dbh->do($query . "(". $random[$i] . "," . $random[$i] .
|
|
"," . $random[$i] . ",'CDEFGHIJKL')") or die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->commit;
|
|
$dbh->{AutoCommit} = 1;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for insert (" . ($total_rows) . "): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
}
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
|
|
####
|
|
#### insert $opt_loop_count records with duplicate id
|
|
####
|
|
|
|
if ($limits->{'unique_index'})
|
|
{
|
|
print "Testing insert of duplicates\n";
|
|
$loop_time=new Benchmark;
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->{AutoCommit} = 0;
|
|
}
|
|
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
$tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
|
|
$tmp=$tmpvar % ($total_rows);
|
|
$tmpquery = "$query ($tmp,$tmp,2,'D')";
|
|
if ($dbh->do($tmpquery))
|
|
{
|
|
die "Didn't get an error when inserting duplicate record $tmp\n";
|
|
}
|
|
}
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->commit;
|
|
$dbh->{AutoCommit} = 1;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for insert_duplicates (" . ($opt_loop_count) . "): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
}
|
|
|
|
|
|
####
|
|
#### Do some selects on the table
|
|
####
|
|
|
|
select_test:
|
|
|
|
# ----------------- prepared+executed/prepared*executed tests
|
|
|
|
print "Test of prepared+execute/once prepared many execute selects\n";
|
|
$loop_time=new Benchmark;
|
|
|
|
for ($i=1 ; $i <= $opt_loop_count ; $i++)
|
|
{
|
|
my ($key_value)=$random[$i];
|
|
my ($query)= "select * from bench1 where id=$key_value";
|
|
print "$query\n" if ($opt_debug);
|
|
$sth = $dbh->prepare($query);
|
|
if (! $sth)
|
|
{
|
|
die "error in prepare select with id = $key_value : $DBI::errstr";
|
|
};
|
|
if (! $sth->execute)
|
|
{
|
|
die "cannot execute prepare select with id = $key_value : $DBI::errstr";
|
|
}
|
|
while ($sth->fetchrow_arrayref) { };
|
|
$sth->finish;
|
|
};
|
|
$end_time=new Benchmark;
|
|
print "Time for prepared_select ($opt_loop_count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$query= "select * from bench1 where id=?";
|
|
$sth = $dbh->prepare($query);
|
|
if (! $sth)
|
|
{
|
|
die "cannot prepare select: $DBI::errstr";
|
|
};
|
|
|
|
for ($i=1 ; $i <= $opt_loop_count ; $i++)
|
|
{
|
|
my ($key_value)=$random[$i];
|
|
$sth->bind_param(1,$key_value);
|
|
print "$query , id = $key_value\n" if ($opt_debug);
|
|
if (! $sth->execute)
|
|
{
|
|
die "cannot execute prepare select with id = $key_value : $DBI::errstr";
|
|
}
|
|
while ($sth->fetchrow_arrayref) { };
|
|
};
|
|
$sth->finish;
|
|
$end_time=new Benchmark;
|
|
print "Time for once_prepared_select ($opt_loop_count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
print "Retrieving data from the table\n";
|
|
$loop_time=new Benchmark;
|
|
$error=0;
|
|
|
|
# It's really a small table, so we can try a select on everything
|
|
|
|
$count=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
if (($found_rows=fetch_all_rows($dbh,"select id from bench1")) !=
|
|
$total_rows)
|
|
{
|
|
if (!$error++)
|
|
{
|
|
print "Warning: Got $found_rows rows when selecting a whole table of " . ($total_rows) . " rows\nContact the database or DBD author!\n";
|
|
}
|
|
}
|
|
$count+=$found_rows;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for select_big ($small_loop_count:$count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
#
|
|
# Do a lot of different ORDER BY queries
|
|
#
|
|
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select id,id2 from bench1 order by id,id2",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big_key ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select id,id2 from bench1 order by id desc, id2 desc",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big_key_desc ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select id from bench1 order by id desc",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big_key_prefix ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select id3 from bench1 order by id3",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big_key2 ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$sel=$limits->{'order_by_unused'} ? "id2" : "*";
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select $sel from bench1 order by id3",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big_key_diff ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$sel=$limits->{'order_by_unused'} ? "id" : "*";
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$rows+=fetch_all_rows($dbh,"select $sel from bench1 order by id2,id3",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_big ($small_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
$sel=$limits->{'order_by_unused'} ? "dummy1" : "dummy1,id3";
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $range_loop_count ; $i++)
|
|
{
|
|
$start=$opt_loop_count/$range_loop_count*$i;
|
|
$end=$start+$i;
|
|
$rows+=fetch_all_rows($dbh,"select $sel from bench1 where id>=$start and id <= $end order by id3",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_range ($range_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$sel=$limits->{'order_by_unused'} ? "dummy1" : "dummy1,id";
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $range_loop_count ; $i++)
|
|
{
|
|
$start=$opt_loop_count/$range_loop_count*$i;
|
|
$end=$start+$i;
|
|
$rows+=fetch_all_rows($dbh,"select $sel from bench1 where id>=$start and id <= $end order by id",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_key_prefix ($range_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$sel=$limits->{'order_by_unused'} ? "id2" : "id2,id3";
|
|
$loop_time=new Benchmark;
|
|
$estimated=$rows=0;
|
|
for ($i=1 ; $i <= $range_loop_count ; $i++)
|
|
{
|
|
$start=$opt_loop_count/$range_loop_count*$i;
|
|
$end=$start+$range_loop_count;
|
|
$rows+=fetch_all_rows($dbh,"select $sel from bench1 where id3>=$start and id3 <= $end order by id3",1);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for order_by_key2_diff ($range_loop_count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
#
|
|
# Test of select on 2 different keys with or
|
|
# (In this case database can only use keys if they do an automatic union).
|
|
#
|
|
|
|
$loop_time=new Benchmark;
|
|
$estimated=0;
|
|
$rows=0;
|
|
$count=0;
|
|
for ($i=1 ; $i <= $range_loop_count ; $i++)
|
|
{
|
|
my $rnd=$i;
|
|
my $rnd2=$random[$i];
|
|
$rows+=fetch_all_rows($dbh,"select id2 from bench1 where id=$rnd or id3=$rnd2",1);
|
|
$count++;
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$count,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for select_diff_key ($count:$rows): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
# Test select that is very popular when using ODBC
|
|
|
|
check_or_range("id","select_range_prefix");
|
|
check_or_range("id3","select_range_key2");
|
|
|
|
# Check reading on direct key on id and id3
|
|
|
|
check_select_key("*","id","select_key_prefix");
|
|
check_select_key2("*","id","id2","select_key");
|
|
check_select_key2("id,id2","id","id2","select_key_return_key");
|
|
check_select_key("*","id3","select_key2");
|
|
check_select_key("id3","id3","select_key2_return_key");
|
|
check_select_key("id,id2","id3","select_key2_return_prim");
|
|
|
|
####
|
|
#### A lot of simple selects on ranges
|
|
####
|
|
|
|
@Q=("select * from bench1 where !id!=3 or !id!=2 or !id!=1 or !id!=4 or !id!=16 or !id!=10",
|
|
6,
|
|
"select * from bench1 where !id!>=" . ($total_rows-1) ." or !id!<1",
|
|
2,
|
|
"select * from bench1 where !id!>=1 and !id!<=2",
|
|
2,
|
|
"select * from bench1 where (!id!>=1 and !id!<=2) or (!id!>=1 and !id!<=2)",
|
|
2,
|
|
"select * from bench1 where !id!>=1 and !id!<=10 and !id!<=5",
|
|
5,
|
|
"select * from bench1 where (!id!>0 and !id!<2) or !id!>=" . ($total_rows-1),
|
|
2,
|
|
"select * from bench1 where (!id!>0 and !id!<2) or (!id!>= " . ($opt_loop_count/2) . " and !id! <= " . ($opt_loop_count/2+2) . ") or !id! = " . ($opt_loop_count/2-1),
|
|
5,
|
|
"select * from bench1 where (!id!>=5 and !id!<=10) or (!id!>=1 and !id!<=4)",
|
|
10,
|
|
"select * from bench1 where (!id!=1 or !id!=2) and (!id!=3 or !id!=4)",
|
|
0,
|
|
"select * from bench1 where (!id!=1 or !id!=2) and (!id!=2 or !id!=3)",
|
|
1,
|
|
"select * from bench1 where (!id!=1 or !id!=5 or !id!=20 or !id!=40) and (!id!=1 or !id!>=20 or !id!=4)",
|
|
3,
|
|
"select * from bench1 where ((!id!=1 or !id!=3) or (!id!>1 and !id!<3)) and !id!<=2",
|
|
2,
|
|
"select * from bench1 where (!id! >= 0 and !id! < 4) or (!id! >=4 and !id! < 6)",
|
|
6,
|
|
"select * from bench1 where !id! <= -1 or (!id! >= 0 and !id! <= 5) or (!id! >=4 and !id! < 6) or (!id! >=6 and !id! <=7) or (!id!>7 and !id! <= 8)",
|
|
9,
|
|
"select * from bench1 where (!id!>=1 and !id!<=2 or !id!>=4 and !id!<=5) or (!id!>=0 and !id! <=10)",
|
|
11,
|
|
"select * from bench1 where (!id!>=1 and !id!<=2 or !id!>=4 and !id!<=5) or (!id!>2 and !id! <=10)",
|
|
10,
|
|
"select * from bench1 where (!id!>1 or !id! <1) and !id!<=2",
|
|
2,
|
|
"select * from bench1 where !id! <= 2 and (!id!>1 or !id! <=1)",
|
|
3,
|
|
"select * from bench1 where (!id!>=1 or !id! <1) and !id!<=2",
|
|
3,
|
|
"select * from bench1 where (!id!>=1 or !id! <=2) and !id!<=2",
|
|
3
|
|
);
|
|
|
|
print "\nTest of compares with simple ranges\n";
|
|
check_select_range("id","select_range_prefix");
|
|
check_select_range("id3","select_range_key2");
|
|
|
|
####
|
|
#### Some group queries
|
|
####
|
|
|
|
if ($limits->{'group_functions'})
|
|
{
|
|
$loop_time=new Benchmark;
|
|
$count=1;
|
|
|
|
$estimated=0;
|
|
for ($tests=0 ; $tests < $small_loop_count ; $tests++)
|
|
{
|
|
$sth=$dbh->prepare($query="select count(*) from bench1") or die $DBI::errstr;
|
|
$sth->execute or die $sth->errstr;
|
|
if (($sth->fetchrow_array)[0] != $total_rows)
|
|
{
|
|
print "Warning: '$query' returned wrong result\n";
|
|
}
|
|
$sth->finish;
|
|
|
|
# min, max in keys are very normal
|
|
$count+=7;
|
|
fetch_all_rows($dbh,"select min(id) from bench1");
|
|
fetch_all_rows($dbh,"select max(id) from bench1");
|
|
fetch_all_rows($dbh,"select sum(id+0.0) from bench1");
|
|
fetch_all_rows($dbh,"select min(id3),max(id3),sum(id3-0.0) from bench1");
|
|
if ($limits->{'group_func_sql_min_str'})
|
|
{
|
|
fetch_all_rows($dbh,"select min(dummy1),max(dummy1) from bench1");
|
|
}
|
|
$count++;
|
|
$sth=$dbh->prepare($query="select count(*) from bench1 where id >= " .
|
|
($opt_loop_count*2)) or die $DBI::errstr;
|
|
$sth->execute or die $DBI::errstr;
|
|
if (($sth->fetchrow_array)[0] != $opt_loop_count)
|
|
{
|
|
print "Warning: '$query' returned wrong result\n";
|
|
}
|
|
$sth->finish;
|
|
|
|
$count++;
|
|
$sth=$dbh->prepare($query="select count(*),sum(id+0.0),min(id),max(id),avg(id-0.0) from bench1") or die $DBI::errstr;
|
|
$sth->execute or die $DBI::errstr;
|
|
@row=$sth->fetchrow_array;
|
|
if ($row[0] != $total_rows ||
|
|
int($row[1]+0.5) != int((($total_rows-1)/2*$total_rows)+0.5) ||
|
|
$row[2] != 0 ||
|
|
$row[3] != $total_rows-1 ||
|
|
1-$row[4]/(($total_rows-1)/2) > 0.001)
|
|
{
|
|
# PostgreSQL 6.3 fails here
|
|
print "Warning: '$query' returned wrong result: @row\n";
|
|
}
|
|
$sth->finish;
|
|
|
|
if ($limits->{'func_odbc_mod'})
|
|
{
|
|
$tmp="mod(id,10)";
|
|
if ($limits->{'func_extra_%'})
|
|
{
|
|
$tmp="id % 10"; # For postgreSQL
|
|
}
|
|
$count++;
|
|
if ($limits->{'group_by_alias'}) {
|
|
if (fetch_all_rows($dbh,$query=$server->query("select $tmp as last_digit,count(*) from bench1 group by last_digit")) != 10)
|
|
{
|
|
print "Warning: '$query' returned wrong number of rows\n";
|
|
}
|
|
} elsif ($limits->{'group_by_position'}) {
|
|
if (fetch_all_rows($dbh,$query=$server->query("select $tmp,count(*) from bench1 group by 1")) != 10)
|
|
{
|
|
print "Warning: '$query' returned wrong number of rows\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($limits->{'order_by_position'} && $limits->{'group_by_position'})
|
|
{
|
|
$count++;
|
|
if (fetch_all_rows($dbh, $query="select id,id3,dummy1 from bench1 where id < 100+$count-$count group by id,id3,dummy1 order by id desc,id3,dummy1") != 100)
|
|
{
|
|
print "Warning: '$query' returned wrong number of rows\n";
|
|
}
|
|
}
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
|
|
$small_loop_count));
|
|
}
|
|
print_time($estimated);
|
|
print " for select_group ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=$estimated=0;
|
|
for ($tests=1 ; $tests <= $range_loop_count*5 ; $tests++)
|
|
{
|
|
$count+=6;
|
|
fetch_all_rows($dbh,"select min(id) from bench1");
|
|
fetch_all_rows($dbh,"select max(id) from bench1");
|
|
fetch_all_rows($dbh,"select min(id2) from bench1 where id=$tests");
|
|
fetch_all_rows($dbh,"select max(id2) from bench1 where id=$tests");
|
|
if ($limits->{'group_func_sql_min_str'})
|
|
{
|
|
fetch_all_rows($dbh,"select min(dummy1) from bench1 where id=$tests");
|
|
fetch_all_rows($dbh,"select max(dummy1) from bench1 where id=$tests");
|
|
}
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
|
|
$range_loop_count*5));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for min_max_on_key ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=$estimated=0;
|
|
for ($tests=1 ; $tests <= $small_loop_count ; $tests++)
|
|
{
|
|
$count+=6;
|
|
fetch_all_rows($dbh,"select min(id2) from bench1");
|
|
fetch_all_rows($dbh,"select max(id2) from bench1");
|
|
fetch_all_rows($dbh,"select min(id3) from bench1 where id2=$tests");
|
|
fetch_all_rows($dbh,"select max(id3) from bench1 where id2=$tests");
|
|
if ($limits->{'group_func_sql_min_str'})
|
|
{
|
|
fetch_all_rows($dbh,"select min(dummy1) from bench1 where id2=$tests");
|
|
fetch_all_rows($dbh,"select max(dummy1) from bench1 where id2=$tests");
|
|
}
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for min_max ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
$total=$opt_loop_count*3;
|
|
for ($tests=0 ; $tests < $total ; $tests+=$total/100)
|
|
{
|
|
$count+=1;
|
|
fetch_all_rows($dbh,"select count(id) from bench1 where id < $tests");
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for count_on_key ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($tests=0 ; $tests < $total ; $tests+=$total/100)
|
|
{
|
|
$count+=1;
|
|
fetch_all_rows($dbh,"select count(dummy1) from bench1 where id2 < $tests");
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for count ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
if ($limits->{'group_distinct_functions'})
|
|
{
|
|
$loop_time=new Benchmark;
|
|
$count=$estimated=0;
|
|
for ($tests=1 ; $tests <= $small_loop_count ; $tests++)
|
|
{
|
|
$count+=2;
|
|
fetch_all_rows($dbh,"select count(distinct dummy1) from bench1");
|
|
fetch_all_rows($dbh,"select dummy1,count(distinct id) from bench1 group by dummy1");
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
|
|
$small_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for count_distinct_big ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
}
|
|
}
|
|
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
####
|
|
#### Some updates on the table
|
|
####
|
|
|
|
$loop_time=new Benchmark;
|
|
|
|
if ($limits->{'functions'})
|
|
{
|
|
print "\nTesting update of keys with functions\n";
|
|
my $update_loop_count=$opt_loop_count/2;
|
|
for ($i=0 ; $i < $update_loop_count ; $i++)
|
|
{
|
|
my $tmp=$opt_loop_count+$random[$i]; # $opt_loop_count*2 <= $tmp < $total_rows
|
|
$sth = $dbh->do("update bench1 set id3=-$tmp where id3=$tmp") or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for update_of_key ($update_loop_count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
do_query($dbh,"UNLOCK TABLES");
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
}
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
$step=int($opt_loop_count/$range_loop_count+1);
|
|
for ($i= 0 ; $i < $opt_loop_count ; $i+= $step)
|
|
{
|
|
$count++;
|
|
$sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= 0 and id3 <= $i") or die $DBI::errstr;
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
$count++;
|
|
$sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= 0 and id3 < $opt_loop_count") or die $DBI::errstr;
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
$count++;
|
|
$sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= $opt_loop_count and id3 < ". ($opt_loop_count*2)) or die $DBI::errstr;
|
|
|
|
#
|
|
# Check that everything was updated
|
|
# In principle we shouldn't time this in the update loop..
|
|
#
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
$row_count=0;
|
|
if (($sth=$dbh->prepare("select count(*) from bench1 where id3>=0"))
|
|
&& $sth->execute)
|
|
{
|
|
($row_count)=$sth->fetchrow;
|
|
}
|
|
$result=1 + $opt_loop_count-$update_loop_count;
|
|
if ($row_count != $result)
|
|
{
|
|
print "Warning: Update check returned $row_count instead of $result\n";
|
|
}
|
|
|
|
$sth->finish;
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
#restore id3 to 0 <= id3 < $total_rows/10 or 0<= id3 < $total_rows
|
|
|
|
my $func=($limits->{'func_odbc_floor'}) ? "floor((0-id3)/20)" : "0-id3";
|
|
$count++;
|
|
$sth=$dbh->do($query="update bench1 set id3=$func where id3<0") or die $DBI::errstr;
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for update_of_key_big ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
}
|
|
else
|
|
{
|
|
print "\nTesting update of keys in loops\n";
|
|
#
|
|
# This is for mSQL that doesn't have functions. Do we really need this ????
|
|
#
|
|
|
|
$sth=$dbh->prepare("select id3 from bench1 where id3 >= 0") or die $DBI::errstr;
|
|
$sth->execute or die $DBI::errstr;
|
|
$count=0;
|
|
while (@tmp = $sth->fetchrow_array)
|
|
{
|
|
my $tmp1 = "-$tmp[0]";
|
|
my $sth1 = $dbh->do("update bench1 set id3 = $tmp1 where id3 = $tmp[0]");
|
|
$count++;
|
|
$end_time=new Benchmark;
|
|
if (($end_time->[0] - $loop_time->[0]) > $opt_time_limit)
|
|
{
|
|
print "note: Aborting update loop because of timeout\n";
|
|
last;
|
|
}
|
|
}
|
|
$sth->finish;
|
|
# Check that everything except id3=0 was updated
|
|
# In principle we shouldn't time this in the update loop..
|
|
#
|
|
if (fetch_all_rows($dbh,$query="select * from bench1 where id3>=0") != 1)
|
|
{
|
|
if ($count == $total_rows)
|
|
{
|
|
print "Warning: Wrong information after update: Found '$row_count' rows, but should have been: 1\n";
|
|
}
|
|
}
|
|
#restore id3 to 0 <= id3 < $total_rows
|
|
$sth=$dbh->prepare("select id3 from bench1 where id3 < 0") or die $DBI::errstr;
|
|
$sth->execute or die $DBI::errstr;
|
|
while (@tmp = $sth->fetchrow_array)
|
|
{
|
|
$count++;
|
|
my $tmp1 = floor((0-$tmp[0])/10);
|
|
my $sth1 = $dbh->do("update bench1 set id3 = $tmp1 where id3 = $tmp[0]");
|
|
}
|
|
$sth->finish;
|
|
$end_time=new Benchmark;
|
|
$estimated=predict_query_time($loop_time,$end_time,\$count,$count,
|
|
$opt_loop_count*6);
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for update_of_key ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
}
|
|
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
do_query($dbh,"UNLOCK TABLES");
|
|
}
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
#
|
|
# Testing some simple updates
|
|
#
|
|
|
|
print "Testing update with key\n";
|
|
$loop_time=new Benchmark;
|
|
for ($i=0 ; $i < $opt_loop_count*3 ; $i++)
|
|
{
|
|
$sth = $dbh->do("update bench1 set dummy1='updated' where id=$i and id2=$i") or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for update_with_key (" . ($opt_loop_count*3) . "): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=1 ; $i < $opt_loop_count*3 ; $i+=3)
|
|
{
|
|
$sth = $dbh->do("update bench1 set dummy1='updated' where id=$i") or die $DBI::errstr;
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$tests,
|
|
$opt_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for update_with_key_prefix (" . ($opt_loop_count) . "): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
print "\nTesting update of all rows\n";
|
|
$loop_time=new Benchmark;
|
|
for ($i=0 ; $i < $small_loop_count ; $i++)
|
|
{
|
|
$sth = $dbh->do("update bench1 set dummy1='updated $i'") or die $DBI::errstr;
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for update_big ($small_loop_count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
|
|
#
|
|
# Testing left outer join
|
|
#
|
|
|
|
if ($limits->{'func_odbc_floor'} && $limits->{'left_outer_join'})
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 a READ, bench1 b READ") || die $DBI::errstr;
|
|
}
|
|
print "\nTesting left outer join\n";
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=0 ; $i < $small_loop_count ; $i++)
|
|
{
|
|
$count+=fetch_all_rows($dbh,"select count(*) from bench1 as a left outer join bench1 as b on (a.id2=b.id3)");
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for outer_join_on_key ($small_loop_count:$count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=0 ; $i < $small_loop_count ; $i++)
|
|
{
|
|
$count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3)");
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for outer_join ($small_loop_count:$count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$count=0;
|
|
$loop_time=new Benchmark;
|
|
for ($i=0 ; $i < $small_loop_count ; $i++)
|
|
{
|
|
$count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3) where b.id3 is not null");
|
|
}
|
|
$end_time=new Benchmark;
|
|
print "Time for outer_join_found ($small_loop_count:$count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
$count=$estimated=0;
|
|
$loop_time=new Benchmark;
|
|
for ($i=1 ; $i <= $small_loop_count ; $i++)
|
|
{
|
|
$count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3) where b.id3 is null");
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,
|
|
\$count,$i,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for outer_join_not_found ($range_loop_count:$count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
###
|
|
### Test speed of IN( value list)
|
|
###
|
|
|
|
if ($limits->{'left_outer_join'})
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
print "\n";
|
|
do_many($dbh,$server->create("bench2",
|
|
["id int NOT NULL"],
|
|
["primary key (id)"]));
|
|
|
|
$max_tests=min(($limits->{'query_size'}-50)/6, $opt_loop_count);
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 READ, bench2 WRITE") ||
|
|
die $DBI::errstr;
|
|
}
|
|
test_where_in("bench1","bench2","id",1,10);
|
|
test_where_in("bench1","bench2","id",11,min(100,$max_tests));
|
|
test_where_in("bench1","bench2","id",101,min(1000,$max_tests));
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
$sth = $dbh->do("DROP TABLE bench2" . $server->{'drop_attr'}) ||
|
|
die $DBI::errstr;
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
####
|
|
#### Test INSERT INTO ... SELECT
|
|
####
|
|
|
|
if ($limits->{'insert_select'})
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
print "\nTesting INSERT INTO ... SELECT\n";
|
|
do_many($dbh,$server->create("bench2",
|
|
["id int NOT NULL",
|
|
"id2 int NOT NULL",
|
|
"id3 int NOT NULL",
|
|
"dummy1 char(30)"],
|
|
["primary key (id,id2)"]));
|
|
do_many($dbh,$server->create("bench3",
|
|
["id int NOT NULL",
|
|
"id2 int NOT NULL",
|
|
"id3 int NOT NULL",
|
|
"dummy1 char(30)"],
|
|
["primary key (id,id2)",
|
|
"index index_id3 (id3)"]));
|
|
$loop_time=new Benchmark;
|
|
$sth = $dbh->do("INSERT INTO bench2 SELECT * from bench1") ||
|
|
die $DBI::errstr;
|
|
$end_time=new Benchmark;
|
|
print "Time for insert_select_1_key (1): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
$loop_time=new Benchmark;
|
|
$sth = $dbh->do("INSERT INTO bench3 SELECT * from bench1") ||
|
|
die $DBI::errstr;
|
|
$end_time=new Benchmark;
|
|
print "Time for insert_select_2_keys (1): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
$loop_time=new Benchmark;
|
|
$sth = $dbh->do("DROP TABLE bench2" . $server->{'drop_attr'}) ||
|
|
die $DBI::errstr;
|
|
$sth = $dbh->do("DROP TABLE bench3" . $server->{'drop_attr'}) ||
|
|
die $DBI::errstr;
|
|
$end_time=new Benchmark;
|
|
print "Time for drop table(2): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh);
|
|
}
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
####
|
|
#### Do some deletes on the table
|
|
####
|
|
|
|
if (!$opt_skip_delete)
|
|
{
|
|
print "\nTesting delete\n";
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=0 ; $i < $opt_loop_count ; $i+=10)
|
|
{
|
|
$count++;
|
|
$tmp=$opt_loop_count+$random[$i]; # $opt_loop_count*2 <= $tmp < $total_rows
|
|
$dbh->do("delete from bench1 where id3=$tmp") or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for delete_key ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
$count=0;
|
|
$loop_time=new Benchmark;
|
|
for ($i= 0 ; $i < $opt_loop_count ; $i+=$opt_loop_count/10)
|
|
{
|
|
$sth=$dbh->do("delete from bench1 where id3 >= 0 and id3 <= $i") or die $DBI::errstr;
|
|
$count++;
|
|
}
|
|
$count+=2;
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
$sth=$dbh->do("delete from bench1 where id3 >= 0 and id3 <= $opt_loop_count") or die $DBI::errstr;
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
$sth=$dbh->do("delete from bench1 where id >= $opt_loop_count and id <= " . ($opt_loop_count*2) ) or die $DBI::errstr;
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
if ($opt_fast)
|
|
{
|
|
$sth=$dbh->do("delete from bench1") or die $DBI::errstr;
|
|
}
|
|
else
|
|
{
|
|
$sth = $dbh->do("delete from bench1 where id3 < " . ($total_rows)) or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for delete_range ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh);
|
|
}
|
|
|
|
|
|
keys_test:
|
|
#
|
|
# Test of insert in table with many keys
|
|
# This test assumes that the server really create the keys!
|
|
#
|
|
|
|
my @fields=(); my @keys=();
|
|
$keys=min($limits->{'max_index'},16); # 16 is more than enough
|
|
$seg= min($limits->{'max_index_parts'},$keys,16); # 16 is more than enough
|
|
|
|
print "Insert into table with $keys keys and with a primary key with $seg parts\n";
|
|
|
|
# Make keys on the most important types
|
|
@types=(0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1); # A 1 for each char field
|
|
push(@fields,"field1 tinyint not null");
|
|
push(@fields,"field_search tinyint not null");
|
|
push(@fields,"field2 mediumint not null");
|
|
push(@fields,"field3 smallint not null");
|
|
push(@fields,"field4 char(16) not null");
|
|
push(@fields,"field5 integer not null");
|
|
push(@fields,"field6 float not null");
|
|
push(@fields,"field7 double not null");
|
|
for ($i=8 ; $i <= $keys ; $i++)
|
|
{
|
|
push(@fields,"field$i char(6) not null"); # Should be relatively fair
|
|
}
|
|
|
|
# First key contains many segments
|
|
$query="primary key (";
|
|
for ($i= 1 ; $i <= $seg ; $i++)
|
|
{
|
|
$query.= "field$i,";
|
|
}
|
|
substr($query,-1)=")";
|
|
push (@keys,$query);
|
|
push (@keys,"index index2 (field_search)");
|
|
|
|
#Create other keys
|
|
for ($i=3 ; $i <= $keys ; $i++)
|
|
{
|
|
push(@keys,"index index$i (field$i)");
|
|
}
|
|
|
|
do_many($dbh,$server->create("bench1",\@fields,\@keys));
|
|
if ($opt_lock_tables)
|
|
{
|
|
$dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
$loop_time=new Benchmark;
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->{AutoCommit} = 0;
|
|
}
|
|
|
|
$fields=$#fields;
|
|
if (($opt_fast || $opt_fast_insert) && $server->{'limits'}->{'insert_multi_value'})
|
|
{
|
|
$query_size=$server->{'limits'}->{'query_size'};
|
|
$query="insert into bench1 values ";
|
|
$res=$query;
|
|
for ($i=0; $i < $many_keys_loop_count; $i++)
|
|
{
|
|
$id= $i & 127;
|
|
$rand=$random[$i];
|
|
$tmp="($id,$id,$rand," . ($i & 32766) . ",'ABCDEF$rand',0,$rand,$rand.0,";
|
|
|
|
for ($j=8; $j <= $fields ; $j++)
|
|
{
|
|
$tmp.= ($types[$j] == 0) ? "$rand," : "'$rand',";
|
|
}
|
|
substr($tmp,-1)=")";
|
|
if (length($tmp)+length($res) < $query_size)
|
|
{
|
|
$res.= $tmp . ",";
|
|
}
|
|
else
|
|
{
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
$res=$query . $tmp . ",";
|
|
}
|
|
}
|
|
$sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
|
|
}
|
|
else
|
|
{
|
|
for ($i=0; $i < $many_keys_loop_count; $i++)
|
|
{
|
|
$id= $i & 127;
|
|
$rand=$random[$i];
|
|
$query="insert into bench1 values ($id,$id,$rand," . ($i & 32767) .
|
|
",'ABCDEF$rand',0,$rand,$rand.0,";
|
|
|
|
for ($j=8; $j <= $fields ; $j++)
|
|
{
|
|
$query.= ($types[$j] == 0) ? "$rand," : "'$rand',";
|
|
}
|
|
substr($query,-1)=")";
|
|
print "query1: $query\n" if ($opt_debug);
|
|
$dbh->do($query) or die "Got error $DBI::errstr with query: $query\n";
|
|
}
|
|
}
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->commit;
|
|
$dbh->{AutoCommit} = 1;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for insert_key ($many_keys_loop_count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
do_query($dbh,"UNLOCK TABLES");
|
|
}
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
#
|
|
# update one key of the above
|
|
#
|
|
|
|
print "Testing update of keys\n";
|
|
$loop_time=new Benchmark;
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->{AutoCommit} = 0;
|
|
}
|
|
|
|
for ($i=0 ; $i< 256; $i++)
|
|
{
|
|
$dbh->do("update bench1 set field5=1 where field_search=$i")
|
|
or die "Got error $DBI::errstr with query: update bench1 set field5=1 where field_search=$i\n";
|
|
}
|
|
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->commit;
|
|
$dbh->{AutoCommit} = 1;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for update_of_primary_key_many_keys (256): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
if ($opt_lock_tables)
|
|
{
|
|
do_query($dbh,"UNLOCK TABLES");
|
|
}
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
|
|
}
|
|
}
|
|
|
|
if ($server->small_rollback_segment())
|
|
{
|
|
$dbh->disconnect; # close connection
|
|
$dbh = $server->connect();
|
|
}
|
|
|
|
#
|
|
# Delete everything from table
|
|
#
|
|
|
|
print "Deleting rows from the table\n";
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
|
|
for ($i=0 ; $i < 128 ; $i++)
|
|
{
|
|
$count++;
|
|
$dbh->do("delete from bench1 where field_search = $i") or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for delete_big_many_keys ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
|
|
}
|
|
|
|
print "Deleting everything from table\n";
|
|
$count=1;
|
|
if ($opt_fast)
|
|
{
|
|
$query= ($limits->{'truncate_table'} ? "truncate table bench1" :
|
|
"delete from bench1");
|
|
$dbh->do($query) or die $DBI::errstr;
|
|
}
|
|
else
|
|
{
|
|
$dbh->do("delete from bench1 where field1 > 0") or die $DBI::errstr;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for delete_all_many_keys ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh);
|
|
}
|
|
|
|
#
|
|
# Test multi value inserts if the server supports it
|
|
#
|
|
|
|
if ($limits->{'insert_multi_value'})
|
|
{
|
|
$query_size=$limits->{'query_size'}; # Same limit for all databases
|
|
|
|
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
|
|
do_many($dbh,$server->create("bench1",
|
|
["id int NOT NULL",
|
|
"id2 int NOT NULL",
|
|
"id3 int NOT NULL",
|
|
"dummy1 char(30)"],
|
|
["primary key (id,id2)",
|
|
"index index_id3 (id3)"]));
|
|
|
|
$loop_time=new Benchmark;
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("LOCK TABLES bench1 write") || die $DBI::errstr;
|
|
}
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->{AutoCommit} = 0;
|
|
}
|
|
|
|
print "Inserting $opt_loop_count rows with multiple values\n";
|
|
$query="insert into bench1 values ";
|
|
$res=$query;
|
|
for ($i=0 ; $i < $opt_loop_count ; $i++)
|
|
{
|
|
my $tmp= "($i,$i,$i,'EFGHIJKLM'),";
|
|
if (length($i)+length($res) < $query_size)
|
|
{
|
|
$res.= $tmp;
|
|
}
|
|
else
|
|
{
|
|
do_query($dbh,substr($res,0,length($res)-1));
|
|
$res=$query .$tmp;
|
|
}
|
|
}
|
|
do_query($dbh,substr($res,0,length($res)-1));
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES ") || die $DBI::errstr;
|
|
}
|
|
if ($opt_fast && $server->{transactions})
|
|
{
|
|
$dbh->commit;
|
|
$dbh->{AutoCommit} = 1;
|
|
}
|
|
|
|
$end_time=new Benchmark;
|
|
print "Time for multiple_value_insert (" . ($opt_loop_count) . "): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
|
|
if ($opt_lock_tables)
|
|
{
|
|
$sth = $dbh->do("UNLOCK TABLES ") || die $DBI::errstr;
|
|
}
|
|
|
|
# A big table may take a while to drop
|
|
$loop_time=new Benchmark;
|
|
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
|
|
$end_time=new Benchmark;
|
|
print "Time for drop table(1): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
|
|
}
|
|
|
|
####
|
|
#### End of benchmark
|
|
####
|
|
|
|
$dbh->disconnect; # close connection
|
|
|
|
end_benchmark($start_time);
|
|
|
|
###
|
|
### Some help functions
|
|
###
|
|
|
|
|
|
# Do some sample selects on direct key
|
|
# First select finds a row, the second one doesn't find.
|
|
|
|
sub check_select_key
|
|
{
|
|
my ($sel_columns,$column,$check)= @_;
|
|
my ($loop_time,$end_time,$i,$tmp_var,$tmp,$count,$row_count,$estimated);
|
|
|
|
$estimated=0;
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=1 ; $i <= $opt_read_key_loop_count; $i++)
|
|
{
|
|
$count+=2;
|
|
$tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
|
|
$tmp=$tmpvar % ($total_rows);
|
|
fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp")
|
|
or die $DBI::errstr;
|
|
$tmp+=$total_rows;
|
|
defined($row_count=fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp")) or die $DBI::errstr;
|
|
die "Found $row_count rows on impossible id: $tmp\n" if ($row_count);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
|
|
$opt_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for $check ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
}
|
|
|
|
# Same as above, but select on 2 columns
|
|
|
|
sub check_select_key2
|
|
{
|
|
my ($sel_columns,$column,$column2,$check)= @_;
|
|
my ($loop_time,$end_time,$i,$tmp_var,$tmp,$count,$row_count,$estimated);
|
|
|
|
$estimated=0;
|
|
$loop_time=new Benchmark;
|
|
$count=0;
|
|
for ($i=1 ; $i <= $opt_read_key_loop_count; $i++)
|
|
{
|
|
$count+=2;
|
|
$tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
|
|
$tmp=$tmpvar % ($total_rows);
|
|
fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp and $column2=$tmp")
|
|
or die $DBI::errstr;
|
|
$tmp+=$total_rows;
|
|
defined($row_count=fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp and $column2=$tmp")) or die $DBI::errstr;
|
|
die "Found $row_count rows on impossible id: $tmp\n" if ($row_count);
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
|
|
$opt_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for $check ($count): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
}
|
|
|
|
#
|
|
# Search using some very simple queries
|
|
#
|
|
|
|
sub check_select_range
|
|
{
|
|
my ($column,$check)= @_;
|
|
my ($loop_time,$end_time,$i,$tmp_var,$tmp,$query,$rows,$estimated);
|
|
|
|
$estimated=0;
|
|
$loop_time=new Benchmark;
|
|
$found=$count=0;
|
|
for ($test=1 ; $test <= $range_loop_count; $test++)
|
|
{
|
|
$count+=$#Q+1;
|
|
for ($i=0 ; $i < $#Q ; $i+=2)
|
|
{
|
|
$query=$Q[$i];
|
|
$rows=$Q[$i+1];
|
|
$query =~ s/!id!/$column/g;
|
|
if (($row_count=fetch_all_rows($dbh,$query)) != $rows)
|
|
{
|
|
if ($row_count == undef())
|
|
{
|
|
die "Got error: $DBI::errstr when executing $query\n";
|
|
}
|
|
die "'$query' returned wrong number of rows: $row_count instead of $rows\n";
|
|
}
|
|
$found+=$row_count;
|
|
}
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$test,
|
|
$range_loop_count));
|
|
}
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for $check ($count:$found): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
}
|
|
|
|
|
|
#
|
|
# SELECT * from bench where col=x or col=x or col=x ...
|
|
|
|
|
|
sub check_or_range
|
|
{
|
|
my ($column,$check)= @_;
|
|
my ($loop_time,$end_time,$i,$tmp_var,$tmp,$columns,$estimated,$found,
|
|
$or_part,$count,$loop_count);
|
|
|
|
$columns=min($limits->{'max_columns'},50,($limits->{'query_size'}-50)/13);
|
|
$columns=$columns- ($columns % 4); # Make Divisible by 4
|
|
|
|
$estimated=0;
|
|
$loop_time=new Benchmark;
|
|
$found=0;
|
|
# The number of tests must be divisible by the following
|
|
$tmp= $limits->{'func_extra_in_num'} ? 15 : 10;
|
|
# We need to calculate the exact number of test to make 'Estimated' right
|
|
$loop_count=$range_loop_count*10+$tmp-1;
|
|
$loop_count=$loop_count- ($loop_count % $tmp);
|
|
|
|
for ($count=0 ; $count < $loop_count ; )
|
|
{
|
|
for ($rowcnt=0; $rowcnt <= $columns; $rowcnt+= $columns/4)
|
|
{
|
|
my $query="select * from bench1 where ";
|
|
my $or_part= "$column = 1";
|
|
$count+=2;
|
|
|
|
for ($i=1 ; $i < $rowcnt ; $i++)
|
|
{
|
|
$tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
|
|
$tmp=$tmpvar % ($opt_loop_count*4);
|
|
$or_part.=" or $column=$tmp";
|
|
}
|
|
print $query . $or_part . "\n" if ($opt_debug);
|
|
($rows=fetch_all_rows($dbh,$query . $or_part)) or die $DBI::errstr;
|
|
$found+=$rows;
|
|
|
|
if ($limits->{'func_extra_in_num'})
|
|
{
|
|
my $in_part=$or_part; # Same query, but use 'func_extra_in_num' instead.
|
|
$in_part=~ s/ = / IN \(/;
|
|
$in_part=~ s/ or $column=/,/g;
|
|
$in_part.= ")";
|
|
fetch_all_rows($dbh,$query . $in_part) or die $DBI::errstr;
|
|
$count++;
|
|
}
|
|
# Do it a little harder by setting a extra range
|
|
defined(($rows=fetch_all_rows($dbh,"$query($or_part) and $column < 10"))) or die $DBI::errstr;
|
|
$found+=$rows;
|
|
}
|
|
$end_time=new Benchmark;
|
|
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$count,
|
|
$loop_count));
|
|
}
|
|
|
|
if ($estimated)
|
|
{ print "Estimated time"; }
|
|
else
|
|
{ print "Time"; }
|
|
print " for $check ($count:$found): " .
|
|
timestr(timediff($end_time, $loop_time),"all") . "\n";
|
|
}
|
|
|
|
#
|
|
# General test of SELECT ... WHERE id in(value-list)
|
|
#
|
|
|
|
sub test_where_in
|
|
{
|
|
my ($t1,$t2,$id,$from,$to)= @_;
|
|
|
|
return if ($from >= $to);
|
|
|
|
$query="SELECT $t1.* FROM $t1 WHERE $id IN (";
|
|
for ($i=1 ; $i <= $to ; $i++)
|
|
{
|
|
$query.="$i,";
|
|
}
|
|
$query=substr($query,0,length($query)-1) . ")";
|
|
|
|
# Fill join table to have the same id's as 'query'
|
|
for ($i= $from ; $i <= $to ; $i++)
|
|
{
|
|
$dbh->do("insert into $t2 values($i)") or die $DBI::errstr;
|
|
}
|
|
if ($opt_fast && defined($server->{vacuum}))
|
|
{
|
|
$server->vacuum(1,\$dbh,"bench1");
|
|
}
|
|
|
|
time_fetch_all_rows("Testing SELECT ... WHERE id in ($to values)",
|
|
"select_in", $query, $dbh,
|
|
$range_loop_count);
|
|
time_fetch_all_rows(undef, "select_join_in",
|
|
"SELECT $t1.* FROM $t2 left outer join $t1 on ($t1.$id=$t2.$id)",
|
|
$dbh, $range_loop_count);
|
|
}
|