3
# This is a test for a key cache bug (bug #10167)
4
# To expose the bug mysqld should be started with --key-buffer-size=64K
7
$opt_loop_count=100000; # Change this to make test harder/easier
9
##################### Standard benchmark inits ##############################
17
$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert=
18
$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0;
19
$opt_host=$opt_user=$opt_password=""; $opt_db="test";
21
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in",
22
"skip-delete","verbose","fast-insert","lock-tables","debug","fast",
23
"force","user=s","password=s") || die "Aborted";
24
$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
26
$firsttable = "bench_f1";
27
$secondtable = "bench_f2";
28
$kill_file= "/tmp/mysqltest_index_corrupt.$$";
31
#### Start timeing and start test
34
$start_time=new Benchmark;
35
if (!$opt_skip_create)
37
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
38
$opt_user, $opt_password,
39
{ PrintError => 0}) || die $DBI::errstr;
40
$dbh->do("drop table if exists $firsttable, $secondtable");
42
print "Creating tables in $opt_db\n";
43
$dbh->do("create table $firsttable (
44
c_pollid INTEGER NOT NULL,
45
c_time BIGINT NOT NULL,
46
c_data DOUBLE NOT NULL,
47
c_error INTEGER NOT NULL,
48
c_warning INTEGER NOT NULL,
49
c_okay INTEGER NOT NULL,
50
c_unknown INTEGER NOT NULL,
51
c_rolled_up BIT NOT NULL,
52
INDEX t_mgmt_hist_r_i1 (c_pollid),
53
INDEX t_mgmt_hist_r_i2 (c_time),
54
INDEX t_mgmt_hist_r_i3 (c_rolled_up))") or die $DBI::errstr;
56
$dbh->do("create table $secondtable (
57
c_pollid INTEGER NOT NULL,
58
c_min_time BIGINT NOT NULL,
59
c_max_time BIGINT NOT NULL,
60
c_min_data DOUBLE NOT NULL,
61
c_max_data DOUBLE NOT NULL,
62
c_avg_data DOUBLE NOT NULL,
63
c_error INTEGER NOT NULL,
64
c_warning INTEGER NOT NULL,
65
c_okay INTEGER NOT NULL,
66
c_unknown INTEGER NOT NULL,
67
c_rolled_up BIT NOT NULL,
68
INDEX t_mgmt_hist_d_i1 (c_pollid),
69
INDEX t_mgmt_hist_d_i2 (c_min_time),
70
INDEX t_mgmt_hist_d_i3 (c_max_time),
71
INDEX t_mgmt_hist_d_i4 (c_rolled_up))") or die $DBI::errstr;
74
$dbh->disconnect; $dbh=0; # Close handler
82
print "Running tests\n";
83
insert_in_bench() if (($pid=fork()) == 0); $work{$pid}="insert";
84
select_from_bench() if (($pid=fork()) == 0); $work{$pid}="insert-select;
85
delete_from_bench() if (($pid=fork()) == 0); $work{$pid}="delete";
88
while (($pid=wait()) != -1)
91
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
92
$errors++ if ($ret != 0);
95
if (!$opt_skip_delete && !$errors)
97
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
98
$opt_user, $opt_password,
99
{ PrintError => 0}) || die $DBI::errstr;
100
$dbh->do("drop table $firsttable, $secondtable");
102
print ($errors ? "Test failed\n" :"Test ok\n");
104
$end_time=new Benchmark;
105
print "Total time: " .
106
timestr(timediff($end_time, $start_time),"noc") . "\n";
113
# Insert records in the two tables
118
my ($dbh,$rows,$found,$i);
120
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
121
$opt_user, $opt_password,
122
{ PrintError => 0}) || die $DBI::errstr;
123
for ($rows= 1; $rows <= $opt_loop_count ; $rows++)
125
$c_pollid = sprintf("%d",rand 1000);
126
$c_time = sprintf("%d",rand 100000);
127
$c_data = rand 1000000;
135
} elsif ($test <.9) {
137
} elsif ($test <.95) {
142
$statement = "INSERT INTO $firsttable (c_pollid, c_time, c_data, c_error
143
, c_warning, c_okay, c_unknown, c_rolled_up) ".
144
"VALUES ($c_pollid,$c_time,$c_data,$c_error,$c_warning,$c_okay,$c_unknown,0)";
145
$cursor = $dbh->prepare($statement);
150
$dbh->disconnect; $dbh=0;
151
print "insert_in_bench: Inserted $rows rows\n";
154
open(KILLFILE, "> $kill_file");
161
sub select_from_bench
163
my ($dbh,$rows,$cursor);
165
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
166
$opt_user, $opt_password,
167
{ PrintError => 0}) || die $DBI::errstr;
168
for ($rows= 1; $rows < $opt_loop_count ; $rows++)
170
$t_value = rand 100000;
171
$t_value2 = $t_value+10000;
172
$statement = "INSERT INTO $secondtable (c_pollid, c_min_time, c_max_time
173
, c_min_data, c_max_data, c_avg_data, c_error, c_warning, c_okay, c_unknown, c_rolled_up) SELECT c_pollid, MIN(c_time), MAX(c_time), MIN(c_data), MAX(c_data), AVG(c_data), SUM(c_error), SUM(c_warning), SUM(c_okay), SUM(c_unknown), 0 FROM $firsttable WHERE (c_time>=$t_value) AND (c_time<$t_value2) AND (c_rolled_up=0) GROUP BY c_pollid";
174
$cursor = $dbh->prepare($statement);
183
print "select_from_bench: insert-select executed $rows times\n";
188
sub delete_from_bench
190
my ($dbh,$row, $t_value, $t2_value, $statement, $cursor);
192
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
193
$opt_user, $opt_password,
194
{ PrintError => 0}) || die $DBI::errstr;
196
for ($rows= 1; $rows < $opt_loop_count ; $rows++)
198
$t_value = rand 50000;
199
$t2_value = $t_value + 50001;
200
$statement = "DELETE FROM $firsttable WHERE (c_time>$t_value) AND (c_time<$t2_value)";
201
$cursor = $dbh->prepare($statement);
210
print "delete: delete executed $rows times\n";