summaryrefslogtreecommitdiff
path: root/sql-bench/test-wisconsin.sh
blob: 10519694bf03d80f16b5380f7ff48b8aa1b75ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/perl
# Copyright (c) 2000, 2001, 2003, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
# Use is subject to license terms.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA
#

use Cwd;
use DBI;
use Benchmark;

$opt_loop_count=10;

$pwd = cwd(); $pwd = "." if ($pwd eq '');
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";

$into_table = "";

if ($opt_small_test)
{
  $opt_loop_count/=5;
}

####
####  Connect and start timeing
####

$dbh = $server->connect();
$start_time=new Benchmark;

####
#### Create needed tables
####

init_data();
init_query();

print "Wisconsin benchmark test\n\n";

if ($opt_skip_create)
{
  if ($opt_lock_tables)
  {
    @tmp=@table_names; push(@tmp,@extra_names);
    $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
      die $DBI::errstr;
  }
  goto start_benchmark;
}

$loop_time= new Benchmark;
for($ti = 0; $ti <= $#table_names; $ti++)
{
  my $table_name = $table_names[$ti];
  my $array_ref = $tables[$ti];
  
  # This may fail if we have no table so do not check answer
  $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
  print "Creating table $table_name\n" if ($opt_verbose);
  do_many($dbh,@$array_ref);
}
$end_time=new Benchmark;
print "Time for create_table ($#tables): " .
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";

if ($opt_fast && defined($server->{vacuum}))
{
  $server->vacuum(1,\$dbh);
}


####
#### Insert data
####

print "Inserting data\n";
$loop_time= new Benchmark;
$row_count=0;
if ($opt_lock_tables)
{
  @tmp=@table_names; push(@tmp,@extra_names);
  $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
    die $DBI::errstr;
}

if ($opt_fast && $server->{'limits'}->{'load_data_infile'})
{
  for ($ti = 0; $ti <= $#table_names; $ti++)
  {
    my $table_name = $table_names[$ti];
    if ($table_name =~ /tenk|Bprime/i) {
      $filename = "$pwd/Data/Wisconsin/tenk.data";
    } else {
      $filename = "$pwd/Data/Wisconsin/$table_name.data";
    }
    $row_count+=$server->insert_file($table_name,$filename,$dbh);
  }
}
else
{
  if ($opt_fast && $server->{transactions})
  {
    $dbh->{AutoCommit} = 0;
  }

  for ($ti = 0; $ti <= $#table_names; $ti++)
  {
    my $table_name = $table_names[$ti];
    my $array_ref = $tables[$ti];
    my @table = @$array_ref;
    my $insert_start = "insert into $table_name values (";

    if ($table_name =~ /tenk|Bprime/i) {
      $filename = "$pwd/Data/Wisconsin/tenk.data";
    } else {
      $filename = "$pwd/Data/Wisconsin/$table_name.data";
    }
    open(DATA, "$filename") || die "Can't open text file: $filename\n";
    while(<DATA>)
    {
      chomp;
      $command = $insert_start . $_ . ")";
      print "$command\n" if ($opt_debug);
      $sth = $dbh->do($command) or die $DBI::errstr;
      $row_count++;
    }
  }
  close(DATA);
}

if ($opt_lock_tables)
{
  do_query($dbh,"UNLOCK TABLES");
}
if ($opt_fast && $server->{transactions})
{
  $dbh->commit;
  $dbh->{AutoCommit} = 1;
}

$end_time=new Benchmark;
print "Time to insert ($row_count): " .
  timestr(timediff($end_time, $loop_time),"all") . "\n";

## Oracle runs out of rollback segments here if using the default "small"
## configuration so disconnect and reconnect to use a new segment
if ($server->small_rollback_segment())
{
  $dbh->disconnect;				# close connection
  $dbh=$server->connect();
}

if ($opt_fast && defined($server->{vacuum}))
{
  $server->vacuum(0,\$dbh,@table_names);
}

if ($opt_lock_tables)
{
  @tmp=@table_names; push(@tmp,@extra_names);
  $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
  die $DBI::errstr;
}

$loop_time= $end_time;
print "Delete from Bprime where unique2 >= 1000\n" if ($opt_debug);
$sth = $dbh->do("delete from Bprime where Bprime.unique2 >= 1000") or
  die $DBI::errstr;
$end_time=new Benchmark;
print "Time to delete_big (1): " .
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";

if ($opt_fast && defined($server->{vacuum}))
{
  $server->vacuum(0,\$dbh);
}

####
#### Running the benchmark
####

start_benchmark:

print "Running the actual benchmark\n";

$loop_time= new Benchmark;
$count=0;
for ($i = 0; $i <= $#query; $i+=2)
{
  if ($query[$i+1])				# If the server can handle it
  {
    $loop_count = 1;
    $loop_count = $opt_loop_count if ($query[$i] =~ /^select/i);
    $query[$i] =~ s/\sAS\s+[^\s,]+//ig if (!$limits->{'column_alias'});
    timeit($loop_count, "fetch_all_rows(\$dbh,\"$query[$i]\")");
    $count+=$loop_count;
  }
}

$end_time=new Benchmark;
print "Time for wisc_benchmark ($count): " .
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";

if (!$opt_skip_delete)
{
  for ($ti = 0; $ti <= $#table_names; $ti++)
  {
    my $table_name = $table_names[$ti];
    $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
  }
}

if ($opt_fast && defined($server->{vacuum}))
{
  $server->vacuum(0,\$dbh);
}

####
#### The END
####

$dbh->disconnect;                               # close connection
end_benchmark($start_time);


################################
###### subroutine for database structure
################################

sub init_data
{
  @onek=
    $server->create("onek",
		    ["unique1 int(5) NOT NULL",
		     "unique2 int(4) NOT NULL",
		     "two int(4)",
		     "four int(4)",
		     "ten int(4)",
		     "twenty int(4)",
		     "hundred int(4) NOT NULL",
		     "thousand int(4)",
		     "twothousand int(4)",
		     "fivethous int(4)",
		     "tenthous int(4)",
		     "odd int(4)",
		     "even int(4)",
		     "stringu1 char(16)",
		     "stringu2 char(16)",
		     "string4 char(16)"],
		    ["UNIQUE (unique1)",
		     "UNIQUE (unique2)",
		     "INDEX hundred1 (hundred)"]);

  @tenk1=
    $server->create("tenk1",
		    ["unique1 int(4) NOT NULL",
		     "unique2 int(4) NOT NULL",
		     "two int(4)",
		     "four int(4)",
		     "ten int(4)",
		     "twenty int(4)",
		     "hundred int(4) NOT NULL",
		     "thousand int(4)",
		     "twothousand int(4)",
		     "fivethous int(4)",
		     "tenthous int(4)",
		     "odd int(4)",
		     "even int(4)",
		     "stringu1 char(16)",
		     "stringu2 char(16)",
		     "string4 char(16)"],
		    ["UNIQUE (unique1)",
		     "UNIQUE (unique2)",
		     "INDEX hundred2 (hundred)"]);

  @tenk2=
    $server->create("tenk2",
		    ["unique1 int(4) NOT NULL",
		     "unique2 int(4) NOT NULL",
		     "two int(4)",
		     "four int(4)",
		     "ten int(4)",
		     "twenty int(4)",
		     "hundred int(4) NOT NULL",
		     "thousand int(4)",
		     "twothousand int(4)",
		     "fivethous int(4)",
		     "tenthous int(4)",
		     "odd int(4)",
		     "even int(4)",
		     "stringu1 char(16)",
		     "stringu2 char(16)",
		     "string4 char(16)"],
		    ["UNIQUE (unique1)",
		     "UNIQUE (unique2)",
		     "INDEX hundred3 (hundred)"]);

  @Bprime=
    $server->create("Bprime",
		    ["unique1 int(4) NOT NULL",
		     "unique2 int(4) NOT NULL",
		     "two int(4)",
		     "four int(4)",
		     "ten int(4)",
		     "twenty int(4)",
		     "hundred int(4) NOT NULL",
		     "thousand int(4)",
		     "twothousand int(4)",
		     "fivethous int(4)",
		     "tenthous int(4)",
		     "odd int(4)",
		     "even int(4)",
		     "stringu1 char(16)",
		     "stringu2 char(16)",
		     "string4 char(16)"],
		    ["UNIQUE (unique1)",
		     "UNIQUE (unique2)",
		     "INDEX hundred4 (hundred)"]);

  @tables =
    (\@onek, \@tenk1, \@tenk2, \@Bprime);

  @table_names =
    ("onek", "tenk1", "tenk2", "Bprime");

# Alias used in joins
  @extra_names=
    ("tenk1 as t", "tenk1 as t1","tenk1 as t2", "Bprime as B","onek as o");
}


sub init_query
{
  @query=
    ("select * $into_table from tenk1 where (unique2 > 301) and (unique2 < 402)",1,
     "select * $into_table from tenk1 where (unique1 > 647) and (unique1 < 1648)",1,
     "select * from tenk1 where unique2 = 2001",1,
     "select * from tenk1 where (unique2 > 301) and (unique2 < 402)",1,
     "select t1.*, t2.unique1 AS t2unique1, t2.unique2 AS t2unique2, t2.two AS t2two, t2.four AS t2four, t2.ten AS t2ten, t2.twenty AS t2twenty, t2.hundred AS t2hundred, t2.thousand AS t2thousand, t2.twothousand AS t2twothousand, t2.fivethous AS t2fivethous, t2.tenthous AS t2tenthous, t2.odd AS t2odd, t2.even AS t2even, t2.stringu1 AS t2stringu1, t2.stringu2 AS t2stringu2, t2.string4 AS t2string4 $into_table from tenk1 t1, tenk1 t2 where (t1.unique2 = t2.unique2) and (t2.unique2 < 1000)",$limits->{'table_wildcard'},
     "select t.*,B.unique1 AS Bunique1,B.unique2 AS Bunique2,B.two AS Btwo,B.four AS Bfour,B.ten AS Bten,B.twenty AS Btwenty,B.hundred AS Bhundred,B.thousand AS Bthousand,B.twothousand AS Btwothousand,B.fivethous AS Bfivethous,B.tenthous AS Btenthous,B.odd AS Bodd,B.even AS Beven,B.stringu1 AS Bstringu1,B.stringu2 AS Bstringu2,B.string4 AS Bstring4 $into_table from tenk1 t, Bprime B where t.unique2 = B.unique2",$limits->{'table_wildcard'},
     "select t1.*,o.unique1 AS ounique1,o.unique2 AS ounique2,o.two AS otwo,o.four AS ofour,o.ten AS oten,o.twenty AS otwenty,o.hundred AS ohundred,o.thousand AS othousand,o.twothousand AS otwothousand,o.fivethous AS ofivethous,o.tenthous AS otenthous,o.odd AS oodd, o.even AS oeven,o.stringu1 AS ostringu1,o.stringu2 AS ostringu2,o.string4 AS ostring4 $into_table from onek o, tenk1 t1, tenk1 t2 where (o.unique2 = t1.unique2) and (t1.unique2 = t2.unique2) and (t1.unique2 < 1000) and (t2.unique2 < 1000)",$limits->{'table_wildcard'},
     "select two, four, ten, twenty, hundred, string4 $into_table from tenk1",1,
     "select * $into_table from onek",1,
     "select MIN(unique2) as x $into_table from tenk1",$limits->{'group_functions'},
     "insert into tenk1 (unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even,stringu1,stringu2, string4) values (10001, 74001, 0, 2, 0, 10, 50, 688, 1950, 4950, 9950, 1, 100, 'ron may choi','jae kwang choi', 'u. c. berkeley')",1,
     "insert into tenk1 (unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even,stringu1,stringu2, string4) values (19991, 60001, 0, 2, 0, 10, 50, 688, 1950, 4950, 9950, 1, 100, 'ron may choi','jae kwang choi', 'u. c. berkeley')",1,
     "delete from tenk1 where tenk1.unique2 = 877",1,
     "delete from tenk1 where tenk1.unique2 = 876",1,
     "update tenk1 set unique2 = 10001 where tenk1.unique2 =1491",1,
     "update tenk1 set unique2 = 10023 where tenk1.unique2 =1480",1,
     "insert into tenk1 (unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even, stringu1, stringu2, string4) values (20002, 70002, 0, 2, 0, 10, 50, 688, 1950, 4950, 9950, 1, 100, 'ron may choi', 'jae kwang choi', 'u. c. berkeley')",1,
     "insert into tenk1 (unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even, stringu1, stringu2, string4) values (50002, 40002, 0, 2, 0, 10, 50, 688, 1950, 4950, 9950, 1, 100, 'ron may choi', 'jae kwang choi', 'u. c. berkeley')",1,
     "delete from tenk1 where tenk1.unique2 = 10001",1,
     "delete from tenk1 where tenk1.unique2 = 900",1,
     "update tenk1 set unique2 = 10088 where tenk1.unique2 =187",1,
     "update tenk1 set unique2 = 10003 where tenk1.unique2 =2000",1,
     "update tenk1 set unique2 = 10020 where tenk1.unique2 =1974",1,
     "update tenk1 set unique2 = 16001 where tenk1.unique2 =1140",1,
     );
}