You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.3 KiB

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