mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / sql-bench / innotest2.sh
blobcfeb0527970f387b64789b86d6dbfdb6476b22f2
1 #!/usr/bin/perl
2 ############################################################################
3 # Stress test for MySQL/InnoDB combined database
4 # (c) 2002 Innobase Oy & MySQL AB
6 ############################################################################
8 use Cwd;
9 use DBI;
10 use Benchmark;
12 $opt_loop_count = 100000;
14 $pwd = cwd(); $pwd = "." if ($pwd eq '');
15 require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
17 print "Innotest2: MySQL/InnoDB stress test in Perl for FOREIGN keys\n";
18 print "------------------------------------------------------------\n";
19 print "This is a randomized stress test for concurrent inserts,\n";
20 print "updates, deletes, commits and rollbacks with foreign keys with\n";
21 print "the ON DELETE ... clause. The test will generate\n";
22 print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
23 print "\n";
24 print "You should run innotest2, innotest2a, and innotest2b concurrently.\n";
25 print "The thing to watch is that the server does not crash or does not\n";
26 print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
27 print "warnings about MySQL lock reservations can appear in the .err log.\n";
28 print "The test will run very long, even several hours. You can kill\n";
29 print "the perl processes running this test at any time and do CHECK\n";
30 print "TABLE on tables innotest2a, b, c, d in the 'test' database.\n";
31 print "\n";
32 print "Some of these stress tests will print a lot of SQL errors\n";
33 print "to the standard output. That is not to be worried about.\n";
34 print "You can direct the output to a file like this:\n";
35 print "perl innotest2 > out2\n\n";
37 print "Generating random keys\n";
38 $random[$opt_loop_count] = 0;
39 $rnd_str[$opt_loop_count] = "a";
41 for ($i = 0; $i < $opt_loop_count; $i++) {
43 $random[$i] = ($i * 63857) % $opt_loop_count;
45 if (0 == ($random[$i] % 3)) {
46 $rnd_str[$i] = "khD";
47 } else { if (1 == ($random[$i] % 3)) {
48 $rnd_str[$i] = "khd";
49 } else { if (2 == ($random[$i] % 3)) {
50 $rnd_str[$i] = "kHd";
51 }}}
53 for ($j = 0; $j < (($i * 764877) % 10); $j++) {
54 $rnd_str[$i] = $rnd_str[$i]."k";
58 ####
59 #### Connect
60 ####
62 $dbh = $server->connect()
63 || die $dbh->errstr;
65 $dbh->do("set autocommit = 0");
67 for ($i = 0; $i < 1; $i++) {
68 print "loop $i\n";
70 print "dropping table innotest2a\n";
71 $dbh->do("drop table innotest2a");
73 print "dropping table innotest2b\n";
74 $dbh->do("drop table innotest2b");
76 print "dropping table innotest2c\n";
77 $dbh->do("drop table innotest2c");
79 print "dropping table innotest2d\n";
80 $dbh->do("drop table innotest2d");
82 print "creating table innotest2b\n";
83 $dbh->do(
84 "create table innotest2b (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C)) TYPE = INNODB")
85 || die $dbh->errstr;
87 print "creating table innotest2a\n";
89 $dbh->do(
90 "create table innotest2a (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C), FOREIGN KEY (A, D) REFERENCES innotest2b (A, D) ON DELETE CASCADE) TYPE = INNODB")
91 || die $dbh->errstr;
93 print "creating table innotest2c\n";
95 $dbh->do(
96 "create table innotest2c (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C), FOREIGN KEY (A, D) REFERENCES innotest2a (A, D) ON DELETE CASCADE, FOREIGN KEY (B, C) REFERENCES innotest2a (B, C) ON DELETE CASCADE) TYPE = INNODB")
97 || die $dbh->errstr;
99 print "creating table innotest2d\n";
101 $dbh->do(
102 "create table innotest2d (A INT AUTO_INCREMENT, D INT, B VARCHAR(200), C VARCHAR(175), UNIQUE KEY (A, D, B), INDEX (B, C), INDEX (C), FOREIGN KEY (C) REFERENCES innotest2c (C) ON DELETE SET NULL, FOREIGN KEY (B, C) REFERENCES innotest2c (B, C) ON DELETE SET NULL) TYPE = INNODB")
103 || die $dbh->errstr;
104 print "created\n";
106 for ($j = 0; $j < $opt_loop_count - 10; $j = $j + 2) {
107 $dbh->do(
108 "insert into innotest2b (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
109 || print $dbh->errstr;
111 $dbh->do(
112 "insert into innotest2a (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
113 || print $dbh->errstr;
115 $dbh->do(
116 "insert into innotest2c (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
117 || print $dbh->errstr;
119 $dbh->do(
120 "insert into innotest2d (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
121 || print $dbh->errstr;
123 $dbh->do("delete from innotest2b where A = ".$random[$random[$j]])
124 || print $dbh->errstr;
126 if (0 == ($j % 10)) {
127 $dbh->do("commit");
130 if (0 == ($j % 39)) {
131 $dbh->do("rollback");
134 if (0 == ($j % 1000)) {
135 print "round $j\n";
137 if (0 == ($j % 20000)) {
138 print "Checking tables...\n";
139 $dbh->do("check table innotest2a");
140 $dbh->do("check table innotest2b");
141 $dbh->do("check table innotest2c");
142 $dbh->do("check table innotest2d");
143 print "Tables checked.\n";
147 $dbh->do("commit");
150 $dbh->disconnect; # close connection