home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / mysql-4.0.22-win / data1.cab / Development / sql-bench / test-big-tables < prev    next >
Encoding:
Text File  |  2004-10-28  |  4.3 KB  |  174 lines

  1. #!/usr/bin/perl
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # Test of extreme tables.
  20. #
  21.  
  22. ##################### Standard benchmark inits ##############################
  23.  
  24. use Cwd;
  25. use DBI;
  26. use Benchmark;
  27.  
  28. $opt_loop_count=1000; # Change this to make test harder/easier
  29. $opt_field_count=1000;
  30.  
  31. $pwd = cwd(); $pwd = "." if ($pwd eq '');
  32. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  33.  
  34. $opt_field_count=min($opt_field_count,$limits->{'max_columns'},
  35.              ($limits->{'query_size'}-30)/14);
  36.  
  37. $opt_loop_count*=10 if ($opt_field_count<100);    # mSQL has so few fields...
  38.  
  39. if ($opt_small_test)
  40. {
  41.   $opt_loop_count/=10;
  42.   $opt_field_count/=10;
  43. }
  44.  
  45.  
  46. print "Testing of some unusual tables\n";
  47. print "All tests are done $opt_loop_count times with $opt_field_count fields\n\n";
  48.  
  49.  
  50. ####
  51. ####  Testing many fields
  52. ####
  53.  
  54. $dbh = $server->connect();
  55. print "Testing table with $opt_field_count fields\n";
  56.  
  57. $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
  58.  
  59. my @fields=();
  60. my @index=();
  61. my $fields="i1";
  62. push(@fields,"$fields int");
  63. $values= "1," x ($opt_field_count-1) . "1";
  64. for ($i=2 ; $i <= $opt_field_count ; $i++)
  65. {
  66.   push(@fields,"i${i} int");
  67.   $fields.=",i${i}";
  68. }
  69.  
  70. $start_time=new Benchmark;
  71.  
  72. do_many($dbh,$server->create("bench1",\@fields,\@index));
  73. $sth = $dbh->do("insert into bench1 values ($values)") or die $DBI::errstr;
  74.  
  75. if ($opt_fast && defined($server->{vacuum}))
  76. {
  77.   $server->vacuum(0,\$dbh);
  78. }
  79.  
  80. test_query("Testing select * from table with 1 record",
  81.        "Time to select_many_fields",
  82.        "select * from bench1",
  83.        $dbh,$opt_loop_count);
  84.  
  85.  
  86. if ($limits->{'working_all_fields'})
  87. {
  88.   test_query("Testing select all_fields from table with 1 record",
  89.          "Time to select_many_fields",
  90.          "select $fields from bench1",
  91.          $dbh,$opt_loop_count);
  92. }
  93.  
  94. test_query("Testing insert VALUES()",
  95.        "Time to insert_many_fields",
  96.        "insert into bench1 values($values)",
  97.        $dbh,$opt_loop_count);
  98.  
  99. if ($opt_fast && defined($server->{vacuum}))
  100. {
  101.   $server->vacuum(0,\$dbh);
  102. }
  103.  
  104. test_command("Testing insert (all_fields) VALUES()",
  105.          "Time to insert_many_fields",
  106.          "insert into bench1 ($fields) values($values)",
  107.          $dbh,$opt_loop_count);
  108.  
  109. $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
  110.  
  111. if ($opt_fast && defined($server->{vacuum}))
  112. {
  113.   $server->vacuum(0,\$dbh);
  114. }
  115.  
  116. ################################ END ###################################
  117. ####
  118. #### End of the test...Finally print time used to execute the
  119. #### whole test.
  120.  
  121. $dbh->disconnect;
  122.  
  123. end_benchmark($start_time);
  124.  
  125.  
  126. ############################ HELP FUNCTIONS ##############################
  127.  
  128. sub test_query
  129. {
  130.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  131.   my($i,$loop_time,$end_time, $using_transactions);
  132.  
  133.   print $test_text . "\n";
  134.   $loop_time=new Benchmark;
  135.  
  136.   $using_transactions=0;
  137.   if ($opt_fast && server->{transactions} && $query=~ /^insert /i)
  138.   {
  139.     $using_transactions=1;
  140.     $dbh->{AutoCommit} = 0;
  141.     print "Transactions enabled\n" if ($opt_debug);
  142.   }
  143.   for ($i=0 ; $i < $count ; $i++)
  144.   {
  145.     defined(fetch_all_rows($dbh,$query)) or die $DBI::errstr;
  146.   }
  147.   if ($using_transactions)
  148.   {
  149.     $dbh->commit;
  150.     $dbh->{AutoCommit} = 1;
  151.   }
  152.  
  153.   $end_time=new Benchmark;
  154.   print $result_text . "($count): " .
  155.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  156. }
  157.  
  158.  
  159. sub test_command
  160. {
  161.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  162.   my($i,$loop_time,$end_time);
  163.  
  164.   print $test_text . "\n";
  165.   $loop_time=new Benchmark;
  166.   for ($i=0 ; $i < $count ; $i++)
  167.   {
  168.     $dbh->do($query) or die $DBI::errstr;
  169.   }
  170.   $end_time=new Benchmark;
  171.   print $result_text . "($count): " .
  172.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  173. }
  174.