0.67.1
by Philip Stoev
initial import from internal tree |
1 |
use strict; |
2 |
use DBI; |
|
3 |
use lib 'lib'; |
|
4 |
use lib '../lib'; |
|
5 |
||
6 |
$| = 1; |
|
7 |
require GenTest::Simplifier::SQL; |
|
8 |
||
9 |
#
|
|
10 |
# This script demonstrates the simplification of queries that fail sporadically. In order to account for the sporadicity,
|
|
11 |
# we define an oracle() that runs every query 5000 times, and reports that the problem is gone only if all 5000 instances
|
|
12 |
# returned the same number of rows. Otherwise, it reports that the problem remains, and the Simplifier will use this information
|
|
13 |
# to further quide the simplification process. More information is available at:
|
|
14 |
#
|
|
15 |
# http://forge.mysql.com/wiki/RandomQueryGeneratorSimplification
|
|
16 |
#
|
|
17 |
||
18 |
my $query = " SELECT table3 .`date_key` field1 FROM B table1 LEFT JOIN B JOIN ( B table3 JOIN ( AA table4 JOIN ( C table6 JOIN A table7 ON table6 .`varchar_nokey` ) ON table6 .`int_key` ) ON table6 .`int_nokey` ) ON table6 .`varchar_nokey` ON table6 .`date_key` WHERE NOT ( ( NOT ( NOT ( NOT ( NOT table7 .`int_key` >= table1 .`varchar_key` OR table3 .`time_nokey` <> table1 .`pk` ) AND table4 .`date_key` >= table1 .`date_key` ) OR table3 .`time_key` > '2005-07-24 11:06:03' ) AND table1 .`datetime_key` <= 8 ) AND table7 .`pk` < 6 ) GROUP BY field1 ORDER BY field1 , field1 , field1 , field1 LIMIT 7 "; |
|
0.67.9
by Philip Stoev
merge from internal tree |
19 |
my $trials = 1000; |
0.67.1
by Philip Stoev
initial import from internal tree |
20 |
|
21 |
my $dsn = 'dbi:mysql:host=127.0.0.1:port=19306:user=root:database=test'; |
|
22 |
my $dbh = DBI->connect($dsn); |
|
23 |
||
24 |
my $simplifier = GenTest::Simplifier::SQL->new( |
|
25 |
oracle => sub { |
|
26 |
my $query = shift; |
|
27 |
print "testing $query\n"; |
|
28 |
my %outcomes; |
|
0.67.9
by Philip Stoev
merge from internal tree |
29 |
foreach my $trial (1..$trials) { |
0.67.1
by Philip Stoev
initial import from internal tree |
30 |
my $sth = $dbh->prepare($query); |
31 |
$sth->execute(); |
|
32 |
return 0 if $sth->err() > 0; |
|
33 |
$outcomes{$sth->rows()}++; |
|
34 |
print "*"; |
|
35 |
return 1 if scalar(keys %outcomes) > 1; |
|
36 |
}
|
|
37 |
return 0; |
|
38 |
}
|
|
39 |
);
|
|
40 |
my $simplified = $simplifier->simplify($query); |
|
41 |
||
42 |
print "Simplified query:\n$simplified;\n"; |