~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to tests/table_types.pl

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
 
 
4
use DBI;
 
5
use Benchmark;
 
6
 
 
7
$opt_loop_count=100000;         # number of rows/3
 
8
$small_loop_count=10;           # Loop for full table retrieval
 
9
$range_loop_count=$small_loop_count*50;
 
10
$many_keys_loop_count=$opt_loop_count;
 
11
 
 
12
chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
 
13
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
 
14
 
 
15
if ($opt_loop_count < 256)
 
16
{
 
17
  $opt_loop_count=256;          # Some tests must have some data to work!
 
18
}
 
19
 
 
20
if ($opt_small_test)
 
21
{
 
22
  $opt_loop_count/=100;
 
23
  $range_loop_count/=10;
 
24
  $many_keys_loop_count=$opt_loop_count/10;
 
25
}
 
26
elsif ($opt_small_tables)
 
27
{
 
28
  $opt_loop_count=10000;                # number of rows/3
 
29
  $many_keys_loop_count=$opt_loop_count;
 
30
}
 
31
elsif ($opt_small_key_tables)
 
32
{
 
33
  $many_keys_loop_count/=10;
 
34
}
 
35
 
 
36
print "Testing the speed difference between some table types\n";
 
37
 
 
38
####
 
39
#### Generating random keys
 
40
####
 
41
 
 
42
print "Generating random keys\n";
 
43
$random[$opt_loop_count]=0;
 
44
for ($i=0 ; $i < $opt_loop_count ; $i++)
 
45
{
 
46
  $random[$i]=$i+$opt_loop_count;
 
47
}
 
48
 
 
49
my $tmpvar=1;
 
50
for ($i=0 ; $i < $opt_loop_count ; $i++)
 
51
{
 
52
  $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
 
53
  $swap=$tmpvar % $opt_loop_count;
 
54
  $tmp=$random[$i]; $random[$i]=$random[$swap]; $random[$swap]=$tmp;
 
55
}
 
56
 
 
57
$total_rows=$opt_loop_count*3;
 
58
 
 
59
####
 
60
####  Connect and start timeing
 
61
####
 
62
$start_time=new Benchmark;
 
63
$dbh = $server->connect();
 
64
####
 
65
#### Create needed tables
 
66
####
 
67
 
 
68
$table_name="bench1";
 
69
test($table_name,"type=isam","char");
 
70
test($table_name,"type=myisam pack_keys=0","char");
 
71
test($table_name,"type=myisam pack_keys=0","char");
 
72
test($table_name,"type=myisam pack_keys=0 checksum=1","char");
 
73
test($table_name,"type=myisam pack_keys=1","char");
 
74
 
 
75
test($table_name,"type=isam","varchar");
 
76
test($table_name,"type=myisam pack_keys=1","varchar");
 
77
test($table_name,"type=myisam pack_keys=0","varchar");
 
78
test($table_name,"type=myisam pack_keys=0 checksum=1","varchar");
 
79
 
 
80
#test("type=heap","char"); # The default table sizes is a bit big for this one
 
81
 
 
82
$dbh->disconnect;
 
83
exit (0);
 
84
 
 
85
sub test {
 
86
  my ($name,$options,$chartype)=@_;
 
87
 
 
88
  print "\nTesting with options: '$options'\n";
 
89
  $dbh->do("drop table $name");
 
90
  do_many($dbh,$server->create("$name",
 
91
                               ["id int NOT NULL",
 
92
                                "id2 int NOT NULL",
 
93
                                "id3 int NOT NULL",
 
94
                                "dummy1 $chartype(30)"],
 
95
                               ["primary key (id,id2)",
 
96
                                "index index_id3 (id3)"],
 
97
                              $options));
 
98
 
 
99
  if ($opt_lock_tables)
 
100
  {
 
101
    $sth = $dbh->do("LOCK TABLES $name WRITE") || die $DBI::errstr;
 
102
  }
 
103
 
 
104
  if ($opt_fast && defined($server->{vacuum}))
 
105
  {
 
106
    $server->vacuum(\$dbh,1);
 
107
  }
 
108
 
 
109
  ####
 
110
  #### Insert $total_rows records in order, in reverse order and random.
 
111
  ####
 
112
 
 
113
  $loop_time=new Benchmark;
 
114
 
 
115
  if ($opt_fast_insert)
 
116
  {
 
117
    $query="insert into $name values ";
 
118
  }
 
119
  else
 
120
  {
 
121
    $query="insert into $name (id,id2,id3,dummy1) values ";
 
122
  }
 
123
 
 
124
  if (($opt_fast || $opt_fast_insert) && $limits->{'multi_value_insert'})
 
125
  {
 
126
    $query_size=$server->{'limits'}->{'query_size'};
 
127
 
 
128
    print "Inserting $opt_loop_count multiple-value rows in order\n";
 
129
    $res=$query;
 
130
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
131
    {
 
132
      $tmp= "($i,$i,$i,'ABCDEFGHIJ'),";
 
133
      if (length($tmp)+length($res) < $query_size)
 
134
      {
 
135
        $res.= $tmp;
 
136
      }
 
137
      else
 
138
      {
 
139
        $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
 
140
        $res=$query . $tmp;
 
141
      }
 
142
    }
 
143
    print "Inserting $opt_loop_count multiple-value rows in reverse order\n";
 
144
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
145
    {
 
146
      $tmp= "(" . ($total_rows-1-$i) . "," .($total_rows-1-$i) .
 
147
        "," .($total_rows-1-$i) . ",'BCDEFGHIJK'),";
 
148
      if (length($tmp)+length($res) < $query_size)
 
149
      {
 
150
        $res.= $tmp;
 
151
      }
 
152
      else
 
153
      {
 
154
        $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
 
155
        $res=$query . $tmp;
 
156
      }
 
157
    }
 
158
    print "Inserting $opt_loop_count multiple-value rows in random order\n";
 
159
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
160
    {
 
161
      $tmp= "(" . $random[$i] . "," . $random[$i] . "," . $random[$i] .
 
162
        ",'CDEFGHIJKL')," or die $DBI::errstr;
 
163
      if (length($tmp)+length($res) < $query_size)
 
164
      {
 
165
        $res.= $tmp;
 
166
      }
 
167
      else
 
168
      {
 
169
        $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
 
170
        $res=$query . $tmp;
 
171
      }
 
172
    }
 
173
    $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
 
174
  }
 
175
  else
 
176
  {
 
177
    print "Inserting $opt_loop_count rows in order\n";
 
178
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
179
    {
 
180
      $sth = $dbh->do($query . "($i,$i,$i,'ABCDEFGHIJ')") or die $DBI::errstr;
 
181
    }
 
182
 
 
183
    print "Inserting $opt_loop_count rows in reverse order\n";
 
184
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
185
    {
 
186
      $sth = $dbh->do($query . "(" . ($total_rows-1-$i) . "," .
 
187
                      ($total_rows-1-$i) . "," .
 
188
                      ($total_rows-1-$i) . ",'BCDEFGHIJK')")
 
189
        or die $DBI::errstr;
 
190
    }
 
191
 
 
192
    print "Inserting $opt_loop_count rows in random order\n";
 
193
 
 
194
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
195
    {
 
196
      $sth = $dbh->do($query . "(". $random[$i] . "," . $random[$i] .
 
197
                      "," . $random[$i] . ",'CDEFGHIJKL')") or die $DBI::errstr;
 
198
    }
 
199
  }
 
200
 
 
201
  $end_time=new Benchmark;
 
202
  print "Time for insert (" . ($total_rows) . "): " .
 
203
    timestr(timediff($end_time, $loop_time),"all") . "\n\n";
 
204
 
 
205
  if ($opt_fast && defined($server->{vacuum}))
 
206
  {
 
207
    $server->vacuum(\$dbh,1);
 
208
  }
 
209
 
 
210
  $sth=$dbh->prepare("show table status like '$name'");
 
211
  $sth->execute || die "Show table status returned error: $DBI::errstr\n";
 
212
  while (@row = $sth->fetchrow_array)
 
213
  {
 
214
    print join("|  ",@row) . " |\n";
 
215
  }
 
216
  $dbh->do("drop table $name") if (!$opt_skip_delete);
 
217
}