home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win.exe / DATA1.CAB / Benchmark_Files / bench / test-create < prev    next >
Text File  |  2000-11-22  |  7KB  |  260 lines

  1. #!/my/gnu/bin/perl5
  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. # This test is for testing how long it takes to create tables,
  20. # make a count(*) from them and finally drop the tables. These
  21. # commands will be done in different ways in this test.
  22. # Using option --fast will drop all the tables in the end
  23. # of this test with one command instead of making own
  24. # 'drop' command for each and every table.
  25. # By changing the variable '$table_amount' value you can make
  26. # this test a lot harder/easier for your computer to drive.
  27. # Note that when using value bigger than 64 for this variable
  28. # will do 'drop table'-command    in totally different way because of that
  29. # how MySQL handles these commands.
  30.  
  31. ##################### Standard benchmark inits ##############################
  32.  
  33. use DBI;
  34. use Benchmark;
  35.  
  36. $opt_loop_count=10000; # Change this to make test harder/easier
  37. # This is the default value for the amount of tables used in this test.
  38.  
  39. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  40. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  41.  
  42. if ($opt_small_test)
  43. {
  44.   $opt_loop_count/=100;
  45. }
  46.  
  47. $max_tables=min($limits->{'max_tables'},$opt_loop_count);
  48.  
  49. print "Testing the speed of creating and droping tables\n";
  50. print "Testing with $max_tables tables and $opt_loop_count loop count\n\n";
  51.  
  52. ####
  53. ####  Connect and start timeing
  54. ####
  55.  
  56. $dbh = $server->connect();
  57.  
  58. ### Test how the database can handle many tables
  59. ### Create $max_tables ; Access all off them with a simple query
  60. ### and then drop the tables
  61.  
  62. if ($opt_force) # If tables used in this test exist, drop 'em
  63. {
  64.   print "Okay..Let's make sure that our tables don't exist yet.\n\n";
  65.   for ($i=1 ; $i <= $max_tables ; $i++)
  66.   {
  67.     $dbh->do("drop table bench_$i");
  68.   }
  69. }
  70.  
  71. if ($opt_fast && defined($server->{vacuum}))
  72. {
  73.   $server->vacuum(1,\$dbh);
  74. }
  75.  
  76. print "Testing create of tables\n";
  77.  
  78. $loop_time=$start_time=new Benchmark;
  79.  
  80. for ($i=1 ; $i <= $max_tables ; $i++)
  81. {
  82.   if (do_many($dbh,$server->create("bench_$i",
  83.                    ["i int NOT NULL",
  84.                     "d double",
  85.                     "f float",
  86.                     "s char(10)",
  87.                     "v varchar(100)"],
  88.                    ["primary key (i)"])))
  89.   {
  90.     # Got an error; Do cleanup
  91.     for ($i=1 ; $i <= $max_tables ; $i++)
  92.     {
  93.       $dbh->do("drop table bench_$i");
  94.     }
  95.     die "Test aborted";
  96.   }
  97. }
  98.  
  99. $end_time=new Benchmark;
  100. print "Time for create_MANY_tables ($max_tables): " .
  101.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  102.  
  103. if ($opt_fast && defined($server->{vacuum}))
  104. {
  105.   $server->vacuum(1,\$dbh);
  106. }
  107.  
  108. #### Here comes $max_tables couples of cont(*) to the tables.
  109. #### We'll check how long it will take...
  110. ####
  111.  
  112. print "Accessing tables\n";
  113.  
  114. if ($limits->{'group_functions'})
  115. {
  116.   $query="select count(*) from ";
  117.   $type="select_group_when_MANY_tables";
  118. }
  119. else
  120. {
  121.   $query="select * from ";
  122.   $type="select_when_MANY_tables";
  123. }
  124.  
  125. $loop_time=new Benchmark;
  126. for ($i=1 ; $i <= $max_tables ; $i++)
  127. {
  128.   $sth = $dbh->do("$query bench_$i") or die $DBI::errstr;
  129. }
  130.  
  131. $end_time=new Benchmark;
  132. print "Time to $type ($max_tables): " .
  133.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  134.  
  135. ####
  136. #### Now we are going to drop $max_tables tables;
  137. ####
  138.  
  139. print "Testing drop\n";
  140.  
  141. $loop_time=new Benchmark;
  142.  
  143. if ($opt_fast && $server->{'limits'}->{'multi_drop'} &&
  144.     $server->{'limits'}->{'query_size'} > 11+$max_tables*10)
  145. {
  146.   my $query="drop table bench_1";
  147.   for ($i=2 ; $i <= $max_tables ; $i++)
  148.   {
  149.     $query.=",bench_$i";
  150.   }
  151.   $sth = $dbh->do($query) or die $DBI::errstr;
  152. }
  153. else
  154. {
  155.   for ($i=1 ; $i <= $max_tables ; $i++)
  156.   {
  157.     $sth = $dbh->do("drop table bench_$i")
  158.       or die $DBI::errstr;
  159.   }
  160. }
  161.  
  162.  
  163. $end_time=new Benchmark;
  164. print "Time for drop_table_when_MANY_tables ($max_tables): " .
  165.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  166.  
  167. if ($opt_fast && defined($server->{vacuum}))
  168. {
  169.   $server->vacuum(1,\$dbh);
  170. }
  171.  
  172. #### We'll do first one 'create table' and then we'll drop it
  173. #### away immediately. This loop shall be executed $opt_loop_count
  174. #### times.
  175.  
  176. print "Testing create+drop\n";
  177.  
  178. $loop_time=new Benchmark;
  179.  
  180. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  181. {
  182.   do_many($dbh,$server->create("bench_$i",
  183.                    ["i int NOT NULL",
  184.                 "d double",
  185.                 "f float",
  186.                 "s char(10)",
  187.                 "v varchar(100)"],
  188.                    ["primary key (i)"]));
  189.   $sth = $dbh->do("drop table bench_$i") or die $DBI::errstr;
  190. }
  191.  
  192. $end_time=new Benchmark;
  193. print "Time for create+drop ($opt_loop_count): " .
  194.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  195.  
  196. if ($opt_fast && defined($server->{vacuum}))
  197. {
  198.   $server->vacuum(1,\$dbh);
  199. }
  200.  
  201. #
  202. # Same test, but with a table with many keys
  203. #
  204.  
  205. my @fields=(); my @keys=();
  206. $keys=min($limits->{'max_index'},16);        # 16 is more than enough
  207. $seg= min($limits->{'max_index_parts'},$keys,16);    # 16 is more than enough
  208.  
  209. # Make keys on the most important types
  210. @types=(0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1);    # A 1 for each char field
  211. push(@fields,"field1 tinyint not null");
  212. push(@fields,"field2 mediumint not null");
  213. push(@fields,"field3 smallint not null");
  214. push(@fields,"field4 char(16) not null");
  215. push(@fields,"field5 integer not null");
  216. push(@fields,"field6 float not null");
  217. push(@fields,"field7 double not null");
  218. for ($i=8 ; $i <= $keys ; $i++)
  219. {
  220.   push(@fields,"field$i char(5) not null");    # Should be relatively fair
  221. }
  222.  
  223. # Let first key contain many segments
  224. my $query="primary key (";
  225. for ($i= 1 ; $i <= $seg ; $i++)
  226. {
  227.   $query.= "field$i,";
  228. }
  229. substr($query,-1)=")";
  230. push (@keys,$query);
  231.  
  232. #Create other keys
  233. for ($i=2 ; $i <= $keys ; $i++)
  234. {
  235.   push(@keys,"index index$i (field$i)");
  236. }
  237.  
  238. $loop_time=new Benchmark;
  239. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  240. {
  241.   do_many($dbh,$server->create("bench_$i", \@fields, \@index));
  242.   $dbh->do("drop table bench_$i") or die $DBI::errstr;
  243. }
  244.  
  245. $end_time=new Benchmark;
  246. print "Time for create_key+drop ($opt_loop_count): " .
  247.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  248.  
  249. if ($opt_fast && defined($server->{vacuum}))
  250. {
  251.   $server->vacuum(1,\$dbh);
  252. }
  253.  
  254. ####
  255. #### End of benchmark
  256. ####
  257.  
  258. $dbh->disconnect;                # close connection
  259. end_benchmark($start_time);
  260.