test-big-tables
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:4k
源码类别:

模拟服务器

开发平台:

C/C++

  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. ##################### Standard benchmark inits ##############################
  22. use DBI;
  23. use Benchmark;
  24. $opt_loop_count=1000; # Change this to make test harder/easier
  25. $opt_field_count=1000;
  26. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  27. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!n";
  28. $opt_field_count=min($opt_field_count,$limits->{'max_columns'},
  29.      ($limits->{'query_size'}-30)/14);
  30. $opt_loop_count*=10 if ($opt_field_count<100); # mSQL has so few fields...
  31. if ($opt_small_test)
  32. {
  33.   $opt_loop_count/=10;
  34.   $opt_field_count/=10;
  35. }
  36. print "Testing of some unusual tablesn";
  37. print "All tests are done $opt_loop_count times with $opt_field_count fieldsnn";
  38. ####
  39. ####  Testing many fields
  40. ####
  41. $dbh = $server->connect();
  42. print "Testing table with $opt_field_count fieldsn";
  43. $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
  44. my @fields=();
  45. my @index=();
  46. my $fields="i1";
  47. push(@fields,"$fields int");
  48. $values= "1," x ($opt_field_count-1) . "1";
  49. for ($i=2 ; $i <= $opt_field_count ; $i++)
  50. {
  51.   push(@fields,"i${i} int");
  52.   $fields.=",i${i}";
  53. }
  54. $start_time=new Benchmark;
  55. do_many($dbh,$server->create("bench1",@fields,@index));
  56. $sth = $dbh->do("insert into bench1 values ($values)") or die $DBI::errstr;
  57. if ($opt_fast && defined($server->{vacuum}))
  58. {
  59.   $server->vacuum(0,$dbh);
  60. }
  61. test_query("Testing select * from table with 1 record",
  62.    "Time to select_many_fields",
  63.    "select * from bench1",
  64.    $dbh,$opt_loop_count);
  65. if ($limits->{'working_all_fields'})
  66. {
  67.   test_query("Testing select all_fields from table with 1 record",
  68.      "Time to select_many_fields",
  69.      "select $fields from bench1",
  70.      $dbh,$opt_loop_count);
  71. }
  72. test_query("Testing insert VALUES()",
  73.    "Time to insert_many_fields",
  74.    "insert into bench1 values($values)",
  75.    $dbh,$opt_loop_count);
  76. if ($opt_fast && defined($server->{vacuum}))
  77. {
  78.   $server->vacuum(0,$dbh);
  79. }
  80. test_command("Testing insert (all_fields) VALUES()",
  81.      "Time to insert_many_fields",
  82.      "insert into bench1 ($fields) values($values)",
  83.      $dbh,$opt_loop_count);
  84. $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
  85. if ($opt_fast && defined($server->{vacuum}))
  86. {
  87.   $server->vacuum(0,$dbh);
  88. }
  89. ################################ END ###################################
  90. ####
  91. #### End of the test...Finally print time used to execute the
  92. #### whole test.
  93. $dbh->disconnect;
  94. end_benchmark($start_time);
  95. ############################ HELP FUNCTIONS ##############################
  96. sub test_query
  97. {
  98.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  99.   my($i,$loop_time,$end_time);
  100.   print $test_text . "n";
  101.   $loop_time=new Benchmark;
  102.   for ($i=0 ; $i < $count ; $i++)
  103.   {
  104.     defined(fetch_all_rows($dbh,$query)) or die $DBI::errstr;
  105.   }
  106.   $end_time=new Benchmark;
  107.   print $result_text . "($count): " .
  108.   timestr(timediff($end_time, $loop_time),"all") . "nn";
  109. }
  110. sub test_command
  111. {
  112.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  113.   my($i,$loop_time,$end_time);
  114.   print $test_text . "n";
  115.   $loop_time=new Benchmark;
  116.   for ($i=0 ; $i < $count ; $i++)
  117.   {
  118.     $dbh->do($query) or die $DBI::errstr;
  119.   }
  120.   $end_time=new Benchmark;
  121.   print $result_text . "($count): " .
  122.   timestr(timediff($end_time, $loop_time),"all") . "nn";
  123. }