2 # Copyright (c) 2000, 2001, 2003, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
3 # Use is subject to license terms.
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
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.
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,
22 ##################### Standard benchmark inits ##############################
28 $opt_start_field_count=8; # start with this many fields
29 $opt_loop_count=100; # How many tests to do
30 $opt_row_count=1000; # Rows in the table
31 $opt_field_count=1000; # Add until this many fields.
32 $opt_time_limit=10*60; # Don't wait more than 10 min for some tests
34 $pwd = cwd
(); $pwd = "." if ($pwd eq '');
35 require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
37 $opt_field_count=min
($opt_field_count,$limits->{'max_columns'},
38 ($limits->{'query_size'}-30)/14);
39 $opt_start_field_count=min
($opt_start_field_count,$limits->{'max_index'});
47 if (!$limits->{'alter_table'})
49 print("Some of the servers given with --cmp or --server doesn't support ALTER TABLE\nTest aborted\n\n");
50 $start_time=new Benchmark
;
51 end_benchmark
($start_time);
55 print "Testing of ALTER TABLE\n";
56 print "Testing with $opt_field_count columns and $opt_row_count rows in $opt_loop_count steps\n";
59 #### Create a table and fill it with data
62 $dbh = $server->connect();
65 push(@fields,"i1 int not null");
66 for ($i=2 ; $i <= $opt_start_field_count ; $i++)
68 push(@fields,"i${i} int not null");
70 $field_count= $opt_start_field_count;
72 $start_time=new Benchmark
;
74 $dbh->do("drop table bench" . $server->{'drop_attr'});
75 do_many
($dbh,$server->create("bench",\
@fields,\
@index));
77 print "Insert data into the table\n";
79 $loop_time=new Benchmark
;
81 if ($opt_fast && $server->{transactions
})
83 $dbh->{AutoCommit
} = 0;
84 print "Transactions enabled\n" if ($opt_debug);
87 for ($i=0 ; $i < $opt_row_count ; $i++)
89 $query="insert into bench values ( " . ("$i," x
($opt_start_field_count-1)) . "$i)";
90 $dbh->do($query) or die $DBI::errstr
;
93 if ($opt_fast && $server->{transactions
})
96 $dbh->{AutoCommit
} = 1;
99 $end_time=new Benchmark
;
101 print "Time for insert ($opt_row_count)",
102 timestr
(timediff
($end_time, $loop_time),"all") . "\n\n";
106 #### Add fields to the table.
109 $loop_time=new Benchmark
;
110 $add= int(($opt_field_count-$opt_start_field_count)/$opt_loop_count)+1;
112 $multi_add=$server->{'limits'}->{'alter_add_multi_col'} == 1;
115 $add=1 if (!$server->{'limits'}->{'alter_add_multi_col'});
119 $add=1 if (!$limits->{'alter_add_multi_col'});
123 while ($field_count < $opt_field_count)
126 $end=min
($field_count+$add,$opt_field_count);
129 while ($field_count < $end)
132 $fields.=",$tmp i${field_count} integer";
133 $tmp="" if (!$multi_add); # Adabas
135 do_query
($dbh,"ALTER TABLE bench " . substr($fields,1));
136 $end_time=new Benchmark
;
137 last if ($estimated=predict_query_time
($loop_time,$end_time,\
$count,$count,
138 $opt_field_count/$add+1));
141 $end_time=new Benchmark
;
143 { print "Estimated time"; }
146 print " for alter_table_add ($count): " .
147 timestr
(timediff
($end_time, $loop_time),"all") . "\n\n";
150 # If estimated, fix table to have known number of fields
152 if ($estimated && $field_count < $opt_field_count)
156 while ($field_count < $opt_field_count)
159 $fields.=",$tmp i${field_count} integer";
160 $tmp="" if (!$multi_add); # Adabas
162 do_query
($dbh,"ALTER TABLE bench " . substr($fields,1));
166 #### Test adding and deleting index on the first $opt_start_fields
169 $loop_time=new Benchmark
;
172 for ($i=1; $i <= $opt_start_field_count ; $i++)
174 $dbh->do("CREATE INDEX bench_ind$i ON bench (i${i})") || die $DBI::errstr
;
177 $end_time=new Benchmark
;
178 print "Time for create_index ($opt_start_field_count): " .
179 timestr
(timediff
($end_time, $loop_time),"all") . "\n\n";
181 $loop_time=new Benchmark
;
182 for ($i=1; $i <= $opt_start_field_count ; $i++)
184 $dbh->do($server->drop_index("bench","bench_ind$i")) || die $DBI::errstr
;
187 $end_time=new Benchmark
;
188 print "Time for drop_index ($opt_start_field_count): " .
189 timestr
(timediff
($end_time, $loop_time),"all") . "\n\n";
192 #### Delete fields from the table
195 goto skip_dropcol
if (!$limits->{'alter_table_dropcol'});
197 $loop_time=new Benchmark
;
200 while ($field_count > $opt_start_field_count)
203 $end=max
($field_count-$add,$opt_start_field_count);
205 while(--$field_count >= $end)
207 $fields.=",DROP i${field_count}";
209 $dbh->do("ALTER TABLE bench " . substr($fields,1) . $server->{'drop_attr'})
211 $end_time=new Benchmark
;
212 last if ($estimated=predict_query_time
($loop_time,$end_time,\
$count,$count,
213 $opt_field_count/$add+1));
216 $end_time=new Benchmark
;
218 { print "Estimated time"; }
221 print " for alter_table_drop ($count): " .
222 timestr
(timediff
($end_time, $loop_time),"all") . "\n\n";
226 ################################ END ###################################
228 #### End of the test...Finally print time used to execute the
231 $dbh->do("drop table bench" . $server->{'drop_attr'});
235 end_benchmark
($start_time);