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

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/util/simplify-sporadic.pl

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
#
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
# General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
16
# USA
 
17
 
 
18
use strict;
 
19
use DBI;
 
20
use lib 'lib';
 
21
use lib '../lib';
 
22
 
 
23
$| = 1;
 
24
require GenTest::Simplifier::SQL;
 
25
 
 
26
#
 
27
# This script demonstrates the simplification of queries that fail sporadically. In order to account for the sporadicity,
 
28
# we define an oracle() that runs every query 5000 times, and reports that the problem is gone only if all 5000 instances
 
29
# returned the same number of rows. Otherwise, it reports that the problem remains, and the Simplifier will use this information
 
30
# to further quide the simplification process. More information is available at:
 
31
#
 
32
# http://forge.mysql.com/wiki/RandomQueryGeneratorSimplification
 
33
#
 
34
 
 
35
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 ";
 
36
my $trials = 1000;
 
37
 
 
38
my $dsn = 'dbi:mysql:host=127.0.0.1:port=19306:user=root:database=test';
 
39
my $dbh = DBI->connect($dsn);
 
40
 
 
41
my $simplifier = GenTest::Simplifier::SQL->new(
 
42
        oracle => sub {
 
43
                my $query = shift;
 
44
                print "testing $query\n";
 
45
                my %outcomes;
 
46
                foreach my $trial (1..$trials) {
 
47
                        my $sth = $dbh->prepare($query);
 
48
                        $sth->execute();
 
49
                        return 0 if $sth->err() > 0;
 
50
                        $outcomes{$sth->rows()}++;
 
51
                        print "*";
 
52
                        return 1 if scalar(keys %outcomes) > 1;
 
53
                }
 
54
                return 0;
 
55
        }
 
56
);
 
57
my $simplified = $simplifier->simplify($query);
 
58
 
 
59
print "Simplified query:\n$simplified;\n";