~ubuntu-branches/ubuntu/trusty/drizzle/trusty-updates

1.1.4 by Tobias Frost
Import upstream version 7.1.32-rc
1
#!/usr/bin/perl
2
# Copyright (C) 2000-2001, 2003 MySQL 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; version 2
7
# of the License.
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
20
use Cwd;
21
use DBI;
22
use Benchmark;
23
24
$opt_loop_count=10;
25
26
$pwd = cwd(); $pwd = "." if ($pwd eq '');
27
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
28
29
$into_table = "";
30
31
if ($opt_small_test)
32
{
33
  $opt_loop_count/=5;
34
}
35
36
####
37
####  Connect and start timeing
38
####
39
40
$dbh = $server->connect();
41
$dbh->do('SET SQL_BIG_SELECTS=1');
42
43
$start_time=new Benchmark;
44
45
####
46
#### Create needed tables
47
####
48
49
init_data();
50
init_query();
51
52
print "Wisconsin benchmark test\n\n";
53
54
if ($opt_skip_create)
55
{
56
  if ($opt_lock_tables)
57
  {
58
    @tmp=@table_names; push(@tmp,@extra_names);
59
    $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
60
      die $DBI::errstr;
61
  }
62
  goto start_benchmark;
63
}
64
65
$loop_time= new Benchmark;
66
for($ti = 0; $ti <= $#table_names; $ti++)
67
{
68
  my $table_name = $table_names[$ti];
69
  my $array_ref = $tables[$ti];
70
  
71
  # This may fail if we have no table so do not check answer
72
  $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
73
  print "Creating table $table_name\n" if ($opt_verbose);
74
  do_many($dbh,@$array_ref);
75
}
76
$end_time=new Benchmark;
77
print "Time for create_table ($#tables): " .
78
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";
79
80
if ($opt_fast && defined($server->{vacuum}))
81
{
82
  $server->vacuum(1,\$dbh);
83
}
84
85
86
####
87
#### Insert data
88
####
89
90
print "Inserting data\n";
91
$loop_time= new Benchmark;
92
$row_count=0;
93
if ($opt_lock_tables)
94
{
95
  @tmp=@table_names; push(@tmp,@extra_names);
96
  $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
97
    die $DBI::errstr;
98
}
99
100
if ($opt_fast && $server->{'limits'}->{'load_data_infile'})
101
{
102
  for ($ti = 0; $ti <= $#table_names; $ti++)
103
  {
104
    my $table_name = $table_names[$ti];
105
    if ($table_name =~ /tenk|Bprime/i) {
106
      $filename = "$pwd/Data/Wisconsin/tenk.data";
107
    } else {
108
      $filename = "$pwd/Data/Wisconsin/$table_name.data";
109
    }
110
    $row_count+=$server->insert_file($table_name,$filename,$dbh);
111
  }
112
}
113
else
114
{
115
  if ($opt_fast && $server->{transactions})
116
  {
117
    $dbh->{AutoCommit} = 0;
118
  }
119
120
  for ($ti = 0; $ti <= $#table_names; $ti++)
121
  {
122
    my $table_name = $table_names[$ti];
123
    my $array_ref = $tables[$ti];
124
    my @table = @$array_ref;
125
    my $insert_start = "insert into $table_name values (";
126
127
    if ($table_name =~ /tenk|Bprime/i) {
128
      $filename = "$pwd/Data/Wisconsin/tenk.data";
129
    } else {
130
      $filename = "$pwd/Data/Wisconsin/$table_name.data";
131
    }
132
    open(DATA, "$filename") || die "Can't open text file: $filename\n";
133
    while(<DATA>)
134
    {
135
      chomp;
136
      $command = $insert_start . $_ . ")";
137
      print "$command\n" if ($opt_debug);
138
      $sth = $dbh->do($command) or die $DBI::errstr;
139
      $row_count++;
140
    }
141
  }
142
  close(DATA);
143
}
144
145
if ($opt_lock_tables)
146
{
147
  do_query($dbh,"UNLOCK TABLES");
148
}
149
if ($opt_fast && $server->{transactions})
150
{
151
  $dbh->commit;
152
  $dbh->{AutoCommit} = 1;
153
}
154
155
$end_time=new Benchmark;
156
print "Time to insert ($row_count): " .
157
  timestr(timediff($end_time, $loop_time),"all") . "\n";
158
159
## Oracle runs out of rollback segments here if using the default "small"
160
## configuration so disconnect and reconnect to use a new segment
161
if ($server->small_rollback_segment())
162
{
163
  $dbh->disconnect;				# close connection
164
  $dbh=$server->connect();
165
}
166
167
if ($opt_fast && defined($server->{vacuum}))
168
{
169
  $server->vacuum(0,\$dbh,@table_names);
170
}
171
172
if ($opt_lock_tables)
173
{
174
  @tmp=@table_names; push(@tmp,@extra_names);
175
  $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
176
  die $DBI::errstr;
177
}
178
179
$loop_time= $end_time;
180
print "Delete from Bprime where unique2 >= 1000\n" if ($opt_debug);
181
$sth = $dbh->do("delete from Bprime where Bprime.unique2 >= 1000") or
182
  die $DBI::errstr;
183
$end_time=new Benchmark;
184
print "Time to delete_big (1): " .
185
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";
186
187
if ($opt_fast && defined($server->{vacuum}))
188
{
189
  $server->vacuum(0,\$dbh);
190
}
191
192
####
193
#### Running the benchmark
194
####
195
196
start_benchmark:
197
198
print "Running the actual benchmark\n";
199
200
$loop_time= new Benchmark;
201
$count=0;
202
for ($i = 0; $i <= $#query; $i+=2)
203
{
204
  if ($query[$i+1])				# If the server can handle it
205
  {
206
    $loop_count = 1;
207
    $loop_count = $opt_loop_count if ($query[$i] =~ /^select/i);
208
    $query[$i] =~ s/\sAS\s+[^\s,]+//ig if (!$limits->{'column_alias'});
209
    timeit($loop_count, "fetch_all_rows(\$dbh,\"$query[$i]\")");
210
    $count+=$loop_count;
211
  }
212
}
213
214
$end_time=new Benchmark;
215
print "Time for wisc_benchmark ($count): " .
216
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";
217
218
if (!$opt_skip_delete)
219
{
220
  for ($ti = 0; $ti <= $#table_names; $ti++)
221
  {
222
    my $table_name = $table_names[$ti];
223
    $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
224
  }
225
}
226
227
if ($opt_fast && defined($server->{vacuum}))
228
{
229
  $server->vacuum(0,\$dbh);
230
}
231
232
####
233
#### The END
234
####
235
236
$dbh->disconnect;                               # close connection
237
end_benchmark($start_time);
238
239
240
################################
241
###### subroutine for database structure
242
################################
243
244
sub init_data
245
{
246
  @onek=
247
    $server->create("onek",
248
		    ["unique1 int(5) NOT NULL",
249
		     "unique2 int(4) NOT NULL",
250
		     "two int(4)",
251
		     "four int(4)",
252
		     "ten int(4)",
253
		     "twenty int(4)",
254
		     "hundred int(4) NOT NULL",
255
		     "thousand int(4)",
256
		     "twothousand int(4)",
257
		     "fivethous int(4)",
258
		     "tenthous int(4)",
259
		     "odd int(4)",
260
		     "even int(4)",
261
		     "stringu1 char(16)",
262
		     "stringu2 char(16)",
263
		     "string4 char(16)"],
264
		    ["UNIQUE (unique1)",
265
		     "UNIQUE (unique2)",
266
		     "INDEX hundred1 (hundred)"]);
267
268
  @tenk1=
269
    $server->create("tenk1",
270
		    ["unique1 int(4) NOT NULL",
271
		     "unique2 int(4) NOT NULL",
272
		     "two int(4)",
273
		     "four int(4)",
274
		     "ten int(4)",
275
		     "twenty int(4)",
276
		     "hundred int(4) NOT NULL",
277
		     "thousand int(4)",
278
		     "twothousand int(4)",
279
		     "fivethous int(4)",
280
		     "tenthous int(4)",
281
		     "odd int(4)",
282
		     "even int(4)",
283
		     "stringu1 char(16)",
284
		     "stringu2 char(16)",
285
		     "string4 char(16)"],
286
		    ["UNIQUE (unique1)",
287
		     "UNIQUE (unique2)",
288
		     "INDEX hundred2 (hundred)"]);
289
290
  @tenk2=
291
    $server->create("tenk2",
292
		    ["unique1 int(4) NOT NULL",
293
		     "unique2 int(4) NOT NULL",
294
		     "two int(4)",
295
		     "four int(4)",
296
		     "ten int(4)",
297
		     "twenty int(4)",
298
		     "hundred int(4) NOT NULL",
299
		     "thousand int(4)",
300
		     "twothousand int(4)",
301
		     "fivethous int(4)",
302
		     "tenthous int(4)",
303
		     "odd int(4)",
304
		     "even int(4)",
305
		     "stringu1 char(16)",
306
		     "stringu2 char(16)",
307
		     "string4 char(16)"],
308
		    ["UNIQUE (unique1)",
309
		     "UNIQUE (unique2)",
310
		     "INDEX hundred3 (hundred)"]);
311
312
  @Bprime=
313
    $server->create("Bprime",
314
		    ["unique1 int(4) NOT NULL",
315
		     "unique2 int(4) NOT NULL",
316
		     "two int(4)",
317
		     "four int(4)",
318
		     "ten int(4)",
319
		     "twenty int(4)",
320
		     "hundred int(4) NOT NULL",
321
		     "thousand int(4)",
322
		     "twothousand int(4)",
323
		     "fivethous int(4)",
324
		     "tenthous int(4)",
325
		     "odd int(4)",
326
		     "even int(4)",
327
		     "stringu1 char(16)",
328
		     "stringu2 char(16)",
329
		     "string4 char(16)"],
330
		    ["UNIQUE (unique1)",
331
		     "UNIQUE (unique2)",
332
		     "INDEX hundred4 (hundred)"]);
333
334
  @tables =
335
    (\@onek, \@tenk1, \@tenk2, \@Bprime);
336
337
  @table_names =
338
    ("onek", "tenk1", "tenk2", "Bprime");
339
340
# Alias used in joins
341
  @extra_names=
342
    ("tenk1 as t", "tenk1 as t1","tenk1 as t2", "Bprime as B","onek as o");
343
}
344
345
346
sub init_query
347
{
348
  @query=
349
    ("select * $into_table from tenk1 where (unique2 > 301) and (unique2 < 402)",1,
350
     "select * $into_table from tenk1 where (unique1 > 647) and (unique1 < 1648)",1,
351
     "select * from tenk1 where unique2 = 2001",1,
352
     "select * from tenk1 where (unique2 > 301) and (unique2 < 402)",1,
353
     "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'},
354
     "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'},
355
     "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'},
356
     "select two, four, ten, twenty, hundred, string4 $into_table from tenk1",1,
357
     "select * $into_table from onek",1,
358
     "select MIN(unique2) as x $into_table from tenk1",$limits->{'group_functions'},
359
     "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,
360
     "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,
361
     "delete from tenk1 where tenk1.unique2 = 877",1,
362
     "delete from tenk1 where tenk1.unique2 = 876",1,
363
     "update tenk1 set unique2 = 10001 where tenk1.unique2 =1491",1,
364
     "update tenk1 set unique2 = 10023 where tenk1.unique2 =1480",1,
365
     "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,
366
     "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,
367
     "delete from tenk1 where tenk1.unique2 = 10001",1,
368
     "delete from tenk1 where tenk1.unique2 = 900",1,
369
     "update tenk1 set unique2 = 10088 where tenk1.unique2 =187",1,
370
     "update tenk1 set unique2 = 10003 where tenk1.unique2 =2000",1,
371
     "update tenk1 set unique2 = 10020 where tenk1.unique2 =1974",1,
372
     "update tenk1 set unique2 = 16001 where tenk1.unique2 =1140",1,
373
     );
374
}