2
# Copyright (C) 2001, 2003 MySQL AB
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
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.
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,
19
# AS3AP single-user benchmark.
22
##################### Standard benchmark inits ##############################
28
$pwd = cwd(); $pwd = "." if ($pwd eq '');
29
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
35
$dbh = $server->connect();
38
$sth = $dbh->do("drop table uniques");
39
$sth = $dbh->do("drop table updates");
40
$sth = $dbh->do("drop table hundred");
41
$sth = $dbh->do("drop table tenpct");
42
$sth = $dbh->do("drop table tiny");
45
$sth = $dbh->do("drop table saveupdates");
47
@fields=("col_key int not null",
48
"col_int int not null",
49
"col_signed int not null",
50
"col_float float not null",
51
"col_double float not null",
52
"col_decim numeric(18,2) not null",
53
"col_date char(20) not null",
54
"col_code char(10) not null",
55
"col_name char(20) not null",
56
"col_address varchar(80) not null");
58
do_many($dbh,$server->create("uniques",\@fields,[]));
59
do_many($dbh,$server->create("updates",\@fields,[]));
60
do_many($dbh,$server->create("hundred",\@fields,[]));
61
do_many($dbh,$server->create("tenpct",\@fields,[]));
62
do_many($dbh,$server->create("tiny",["col_key int not null"],[]));
64
print "Start AS3AP benchmark\n\n";
66
$start_time=new Benchmark;
71
@table_names=("uniques","updates","hundred","tenpct","tiny");
73
$loop_time=new Benchmark;
75
if ($opt_fast && $server->{'limits'}->{'load_data_infile'})
77
for ($ti = 0; $ti <= $#table_names; $ti++)
79
my $table_name = $table_names[$ti];
80
my $file = "$pwd/Data/AS3AP/${table_name}\.new";
81
print "$table_name - $file\n" if ($opt_debug);
82
$row_count += $server->insert_file($table_name,$file,$dbh);
87
for ($ti = 0; $ti <= $#table_names; $ti++)
89
my $table_name = $table_names[$ti];
90
print "$table_name - $file\n" if ($opt_debug);
91
my $insert_start = "insert into $table_name values (";
92
open(DATA, "$pwd/Data/AS3AP/${table_name}\.new") || die "Can't open text file: $pwd/Data/AS3AP/${table_name}\.new\n";
96
next unless ( $_ =~ /\w/ ); # skip blank lines
97
$command = $insert_start."$_".")";
98
$command =~ $server->fix_to_insert($command);
99
print "$command\n" if ($opt_debug);
100
$sth = $dbh->do($command) or die "Got error: $DBI::errstr when executing '$command'\n";
107
$end_time=new Benchmark;
108
print "Time for Load Data - " . "($row_count): " .
109
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
112
print "Create Index\n";
114
test_command("create_idx_uniques_key_bt",
115
"time for create_idx_uniques_key_bt",
116
"create unique index uniques_key_bt on uniques (col_key)",$dbh,$opt_loop_count);
118
test_command("create_idx_updates_key_bt",
119
"time for create_idx_updates_key_bt",
120
"create unique index updates_key_bt on updates (col_key)",$dbh,$opt_loop_count);
122
test_command("create_idx_hundred_key_bt",
123
"time for create_idx_hundred_key_bt",
124
"create unique index hundred_key_bt on hundred (col_key)",
125
$dbh,$opt_loop_count);
127
test_command("create_idx_tenpct_key_bt",
128
"time for create_idx_tenpct_key_bt",
129
"create unique index tenpct_key_bt on tenpct (col_key)",$dbh,$opt_loop_count);
131
test_command("create_idx_tenpct_key_code_bt",
132
"time for create_idx_tenpct_key_code_bt",
133
"create index tenpct_key_code_bt on tenpct (col_key,col_code)",
134
$dbh,$opt_loop_count);
136
test_command("create_idx_tiny_key_bt",
137
"time for create_idx_tiny_key_bt",
138
"create index tiny_key_bt on tiny (col_key)",$dbh,$opt_loop_count);
140
test_command("create_idx_tenpct_int_bt",
141
"time for create_idx_tenpct_int_bt",
142
"create index tenpct_int_bt on tenpct (col_int)",$dbh,$opt_loop_count);
144
test_command("create_idx_tenpct_signed_bt",
145
"time for create_idx_tenpct_signed_bt",
146
"create index tenpct_signed_bt on tenpct (col_signed)",$dbh,$opt_loop_count);
148
test_command("create_idx_uniques_code_h",
149
"time for create_idx_uniques_code_h",
150
"create index uniques_code_h on uniques (col_code)",$dbh,$opt_loop_count);
152
test_command("create_idx_tenpct_double_bt",
153
"time for create_idx_tenpct_double_bt",
154
"create index tenpct_double_bt on tenpct (col_double)",$dbh,$opt_loop_count);
157
test_command("create_idx_updates_decim_bt",
158
"time for create_idx_updates_decim_bt",
159
"create index updates_decim_bt on updates (col_decim)",$dbh,$opt_loop_count);
161
test_command("create_idx_tenpct_float_bt",
162
"time for create_idx_tenpct_float_bt",
163
"create index tenpct_float_bt on tenpct (col_float)",$dbh,$opt_loop_count);
165
test_command("create_idx_updates_int_bt",
166
"time for create_idx_updates_int_bt",
167
"create index updates_int_bt on updates (col_int)",$dbh,$opt_loop_count);
169
test_command("create_idx_tenpct_decim_bt",
170
"time for create_idx_tenpct_decim_bt",
171
"create index tenpct_decim_bt on tenpct (col_decim)",$dbh,$opt_loop_count);
173
test_command("create_idx_hundred_code_h",
174
"time for create_idx_hundred_code_h",
175
"create index hundred_code_h on hundred (col_code)",$dbh,$opt_loop_count);
177
test_command("create_idx_tenpct_name_h",
178
"time for create_idx_tenpct_name_h",
179
"create index tenpct_name_h on tenpct (col_name)",$dbh,$opt_loop_count);
181
test_command("create_idx_updates_code_h",
182
"time for create_idx_updates_code_h",
183
"create index updates_code_h on updates (col_code)",$dbh,$opt_loop_count);
185
test_command("create_idx_tenpct_code_h",
186
"time for create_idx_tenpct_code_h",
187
"create index tenpct_code_h on tenpct (col_code)",$dbh,$opt_loop_count);
189
test_command("create_idx_updates_double_bt",
190
"time for create_idx_updates_double_bt",
191
"create index updates_double_bt on updates (col_double)",$dbh,$opt_loop_count);
193
test_command("create_idx_hundred_foreign",
194
"time for create_idx_hundred_foreign",
195
"alter table hundred add constraint fk_hundred_updates foreign key (col_signed)
196
references updates (col_key)",$dbh,$opt_loop_count);
198
test_query("sel_1_cl",
200
"select col_key, col_int, col_signed, col_code, col_double, col_name
201
from updates where col_key = 1000",$dbh,$opt_loop_count);
203
test_query("join_3_cl",
205
"select uniques.col_signed, uniques.col_date,
206
hundred.col_signed, hundred.col_date,
207
tenpct.col_signed, tenpct.col_date
208
from uniques, hundred, tenpct
209
where uniques.col_key = hundred.col_key
210
and uniques.col_key = tenpct.col_key
211
and uniques.col_key = 1000",$dbh,$opt_loop_count);
213
test_query("sel_100_ncl",
214
"Time to sel_100_ncl",
215
"select col_key, col_int, col_signed, col_code,col_double, col_name
216
from updates where col_int <= 100",$dbh,$opt_loop_count);
218
test_query("table_scan",
219
"Time to table_scan",
220
"select * from uniques where col_int = 1",$dbh,$opt_loop_count);
222
test_query("agg_func",
224
"select min(col_key) from hundred group by col_name",$dbh,$opt_loop_count);
226
test_query("agg_scal",
228
"select min(col_key) from uniques",$dbh,$opt_loop_count);
230
test_query("sel_100_cl",
231
"Time for sel_100_cl",
232
"select col_key, col_int, col_signed, col_code,
234
from updates where col_key <= 100",$dbh,$opt_loop_count);
236
test_query("join_3_ncl",
237
"Time for join_3_ncl",
238
"select uniques.col_signed, uniques.col_date,
239
hundred.col_signed, hundred.col_date,
240
tenpct.col_signed, tenpct.col_date
241
from uniques, hundred, tenpct
242
where uniques.col_code = hundred.col_code
243
and uniques.col_code = tenpct.col_code
244
and uniques.col_code = 'BENCHMARKS'",$dbh,$opt_loop_count);
246
test_query("sel_10pct_ncl",
247
"Time for sel_10pct_ncl",
248
"select col_key, col_int, col_signed, col_code,
251
where col_name = 'THE+ASAP+BENCHMARKS+'",$dbh,$opt_loop_count);
253
if ($limits->{'subqueries'}){
254
test_query("agg_simple_report",
255
"Time for agg_simple_report",
256
"select avg(updates.col_decim)
258
where updates.col_key in
259
(select updates.col_key
260
from updates, hundred
261
where hundred.col_key = updates.col_key
262
and updates.col_decim > 980000000)",$dbh,$opt_loop_count);
264
print "agg_simple_report - Failed\n\n";
267
test_query("agg_info_retrieval",
268
"Time for agg_info_retrieval",
269
"select count(col_key)
271
where col_name = 'THE+ASAP+BENCHMARKS'
272
and col_int <= 100000000
273
and col_signed between 1 and 99999999
274
and not (col_float between -450000000 and 450000000)
275
and col_double > 600000000
276
and col_decim < -600000000",$dbh,$opt_loop_count);
278
if ($limits->{'views'}){
279
test_query("agg_create_view",
280
"Time for agg_create_view",
282
reportview(col_key,col_signed,col_date,col_decim,
283
col_name,col_code,col_int) as
284
select updates.col_key, updates.col_signed,
285
updates.col_date, updates.col_decim,
286
hundred.col_name, hundred.col_code,
288
from updates, hundred
289
where updates.col_key = hundred.col_key",$dbh,$opt_loop_count);
291
test_query("agg_subtotal_report",
292
"Time for agg_subtotal_report",
293
"select avg(col_signed), min(col_signed), max(col_signed),
294
max(col_date), min(col_date),
295
count(distinct col_name), count(col_name),
298
where col_decim >980000000
299
group by col_code, col_int",$dbh,$opt_loop_count);
302
test_query("agg_total_report",
303
"Time for agg_total_report",
304
"select avg(col_signed), min(col_signed), max(col_signed),
305
max(col_date), min(col_date),
306
count(distinct col_name), count(col_name),
307
count(col_code), count(col_int)
309
where col_decim >980000000",$dbh,$opt_loop_count);
311
print "agg_create_view - Failed\n\n";
312
print "agg_subtotal_report - Failed\n\n";
313
print "agg_total_report - Failed\n\n";
317
test_query("join_2_cl",
318
"Time for join_2_cl",
319
"select uniques.col_signed, uniques.col_name,
320
hundred.col_signed, hundred.col_name
321
from uniques, hundred
322
where uniques.col_key = hundred.col_key
323
and uniques.col_key =1000"
324
,$dbh,$opt_loop_count);
328
"select uniques.col_signed, uniques.col_name,
329
hundred.col_signed, hundred.col_name
330
from uniques, hundred
331
where uniques.col_address = hundred.col_address
332
and uniques.col_address = 'SILICON VALLEY'"
333
,$dbh,$opt_loop_count);
335
test_query("sel_variable_select_low",
336
"Time for sel_variable_select_low",
337
"select col_key, col_int, col_signed, col_code,
340
where col_signed < -500000000"
341
,$dbh,$opt_loop_count);
343
test_query("sel_variable_select_high",
344
"Time for sel_variable_select_high",
345
"select col_key, col_int, col_signed, col_code,
348
where col_signed < -250000000"
349
,$dbh,$opt_loop_count);
351
test_query("join_4_cl",
352
"Time for join_4_cl",
353
"select uniques.col_date, hundred.col_date,
354
tenpct.col_date, updates.col_date
355
from uniques, hundred, tenpct, updates
356
where uniques.col_key = hundred.col_key
357
and uniques.col_key = tenpct.col_key
358
and uniques.col_key = updates.col_key
359
and uniques.col_key = 1000"
360
,$dbh,$opt_loop_count);
362
test_query("proj_100",
364
"select distinct col_address, col_signed from hundred"
365
,$dbh,$opt_loop_count);
367
test_query("join_4_ncl",
368
"Time for join_4_ncl",
369
"select uniques.col_date, hundred.col_date,
370
tenpct.col_date, updates.col_date
371
from uniques, hundred, tenpct, updates
372
where uniques.col_code = hundred.col_code
373
and uniques.col_code = tenpct.col_code
374
and uniques.col_code = updates.col_code
375
and uniques.col_code = 'BENCHMARKS'"
376
,$dbh,$opt_loop_count);
378
test_query("proj_10pct",
379
"Time for proj_10pct",
380
"select distinct col_signed from tenpct"
381
,$dbh,$opt_loop_count);
383
test_query("sel_1_ncl",
384
"Time for sel_1_ncl",
385
"select col_key, col_int, col_signed, col_code,
387
from updates where col_code = 'BENCHMARKS'"
388
,$dbh,$opt_loop_count);
390
test_query("join_2_ncl",
391
"Time for join_2_ncl",
392
"select uniques.col_signed, uniques.col_name,
393
hundred.col_signed, hundred.col_name
394
from uniques, hundred
395
where uniques.col_code = hundred.col_code
396
and uniques.col_code = 'BENCHMARKS'"
397
,$dbh,$opt_loop_count);
399
if ($limits->{'foreign_key'}){
400
do_many($dbh,$server->create("integrity_temp",\@fields,[]));
402
test_query("integrity_test_1",
403
"Time for integrity_test",
404
"insert into integrity_temp select *
405
from hundred where col_int=0",$dbh,$opt_loop_count);
407
test_query("integrity_test_2",
408
"Time for integrity_test",
409
"update hundred set col_signed = '-500000000'
410
where col_int = 0",$dbh,$opt_loop_count);
412
test_query("integrity_test_3",
413
"Time for integrity_test",
414
"update hundred set col_signed = '-500000000'
415
where col_int = 0",$dbh,$opt_loop_count);
419
print "integrity_test - Failed\n\n";
422
push @drop_seq_command,$server->drop_index("updates","updates_int_bt");
423
push @drop_seq_command,$server->drop_index("updates","updates_double_bt");
424
push @drop_seq_command,$server->drop_index("updates","updates_decim_bt");
425
push @drop_seq_command,$server->drop_index("updates","updates_code_h");
427
test_many_command("Drop updates keys",
428
"Time for drop_updates_keys",
429
\@drop_seq_command,$dbh,$opt_loop_count);
431
do_many($dbh,$server->create("saveupdates",\@fields,[]));
433
test_command("bulk_save",
434
"Time for bulk_save",
435
"insert into saveupdates select *
436
from updates where col_key between 5000 and 5999"
437
,$dbh,$opt_loop_count);
439
test_command("bulk_modify",
440
"Time for bulk_modify",
442
set col_key = col_key - 100000
443
where col_key between 5000 and 5999"
444
,$dbh,$opt_loop_count);
446
safe_command("upd_append_duplicate",
447
"Time for upd_append_duplicate",
449
values (6000, 0, 60000, 39997.90,
451
'11/10/1985', 'CONTROLLER',
452
'ALICE IN WONDERLAND',
453
'UNIVERSITY OF ILLINOIS AT CHICAGO')"
454
,$dbh,$opt_loop_count);
456
test_command("upd_remove_duplicate",
457
"Time for upd_remove_duplicate",
458
"delete from updates where col_key = 6000 and col_int = 0"
459
,$dbh,$opt_loop_count);
461
test_command("upd_app_t_mid",
462
"Time for upd_app_t_mid",
464
values (5005, 5005, 50005, 50005.00, 50005.00,
465
50005.00, '1/1/1988', 'CONTROLLER',
466
'ALICE IN WONDERLAND',
467
'UNIVERSITY OF ILLINOIS AT CHICAGO')"
468
,$dbh,$opt_loop_count);
470
test_command("upd_mod_t_mid",
471
"Time for upd_mod_t_mid",
472
"update updates set col_key = '-5000'
473
where col_key = 5005"
474
,$dbh,$opt_loop_count);
476
test_command("upd_del_t_mid",
477
"Time for upd_del_t_mid",
479
where (col_key='5005') or (col_key='-5000')"
480
,$dbh,$opt_loop_count);
482
test_command("upd_app_t_end",
483
"Time for upd_app_t_end",
485
where (col_key='5005') or (col_key='-5000')"
486
,$dbh,$opt_loop_count);
488
test_command("upd_mod_t_end",
489
"Time for upd_mod_t_end",
492
where col_key = 1000000001"
493
,$dbh,$opt_loop_count);
495
test_command("upd_del_t_end",
496
"Time for upd_del_t_end",
497
"delete from updates where col_key = -1000"
498
,$dbh,$opt_loop_count);
500
test_command("create_idx_updates_code_h",
501
"time for create_idx_updates_code_h",
502
"create index updates_code_h on updates (col_code)",
503
$dbh,$opt_loop_count);
505
test_command("upd_app_t_mid",
506
"Time for upd_app_t_mid",
508
values (5005, 5005, 50005, 50005.00, 50005.00,
509
50005.00, '1/1/1988', 'CONTROLLER',
510
'ALICE IN WONDERLAND',
511
'UNIVERSITY OF ILLINOIS AT CHICAGO')"
512
,$dbh,$opt_loop_count);
514
test_command("upd_mod_t_cod",
515
"Time for upd_mod_t_cod",
517
set col_code = 'SQL+GROUPS'
518
where col_key = 5005"
519
,$dbh,$opt_loop_count);
521
test_command("upd_del_t_mid",
522
"Time for upd_del_t_mid",
524
where (col_key='5005') or (col_key='-5000')"
525
,$dbh,$opt_loop_count);
527
test_command("create_idx_updates_int_bt",
528
"time for create_idx_updates_int_bt",
529
"create index updates_int_bt on updates (col_int)",
530
$dbh,$opt_loop_count);
532
test_command("upd_app_t_mid",
533
"Time for upd_app_t_mid",
535
values (5005, 5005, 50005, 50005.00, 50005.00,
536
50005.00, '1/1/1988', 'CONTROLLER',
537
'ALICE IN WONDERLAND',
538
'UNIVERSITY OF ILLINOIS AT CHICAGO')"
539
,$dbh,$opt_loop_count);
541
test_command("upd_mod_t_int",
542
"Time for upd_mod_t_int",
543
"update updates set col_int = 50015 where col_key = 5005"
544
,$dbh,$opt_loop_count);
546
test_command("upd_del_t_mid",
547
"Time for upd_del_t_mid",
549
where (col_key='5005') or (col_key='-5000')"
550
,$dbh,$opt_loop_count);
552
test_command("bulk_append",
553
"Time for bulk_append",
554
"insert into updates select * from saveupdates"
555
,$dbh,$opt_loop_count);
557
test_command("bulk_delete",
558
"Time for bulk_delete",
559
"delete from updates where col_key < 0"
560
,$dbh,$opt_loop_count);
562
################################ END ###################################
564
#### End of the test...Finally print time used to execute the
569
end_benchmark($start_time);
571
############################ HELP FUNCTIONS ##############################
575
my($test_text,$result_text,$query,$dbh,$count)=@_;
576
my($i,$loop_time,$end_time);
578
print $test_text . "\n";
579
$loop_time=new Benchmark;
580
for ($i=0 ; $i < $count ; $i++)
582
defined(fetch_all_rows($dbh,$query)) or warn $DBI::errstr;
584
$end_time=new Benchmark;
585
print $result_text . "($count): " .
586
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
592
my($test_text,$result_text,$query,$dbh,$count)=@_;
593
my($i,$loop_time,$end_time);
595
print $test_text . "\n";
596
$loop_time=new Benchmark;
597
for ($i=0 ; $i < $count ; $i++)
599
$dbh->do($query) or die $DBI::errstr;
601
$end_time=new Benchmark;
602
print $result_text . "($count): " .
603
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
608
my($test_text,$result_text,$query,$dbh,$count)=@_;
609
my($i,$loop_time,$end_time);
611
print $test_text . "\n";
612
$loop_time=new Benchmark;
613
for ($i=0 ; $i < $count ; $i++)
615
safe_do_many($dbh,$query);
617
$end_time=new Benchmark;
618
print $result_text . "($count): " .
619
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
622
sub test_many_command
624
my($test_text,$result_text,$query,$dbh,$count)=@_;
625
my($i,$loop_time,$end_time);
627
$loop_time=new Benchmark;
628
for ($i=0 ; $i < $count ; $i++)
630
safe_do_many($dbh, @$query);
632
$end_time=new Benchmark;
633
print $result_text . "($count): " .
634
timestr(timediff($end_time, $loop_time),"all") . "\n\n";