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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

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 warnings;
19
 
use strict;
20
 
use DBI;
21
 
use Time::HiRes;
22
 
use lib 'lib';
23
 
use lib '../lib';
24
 
 
25
 
$| = 1;
26
 
 
27
 
use GenTest::Constants;
28
 
use GenTest::Executor::MySQL;
29
 
use GenTest::Simplifier::Test;
30
 
use GenTest::Simplifier::SQL;
31
 
use GenTest::Comparator;
32
 
 
33
 
#
34
 
# This script demonstrates the simplification of queries. More information is available at
35
 
#
36
 
# http://forge.mysql.com/wiki/RandomQueryGeneratorSimplification
37
 
#
38
 
 
39
 
my $query = "SELECT 1 FROM DUAL";
40
 
 
41
 
my @dsns = (
42
 
        'dbi:mysql:host=127.0.0.1:port=19300:user=root:database=test',
43
 
        'dbi:mysql:host=127.0.0.1:port=19302:user=root:database=test'
44
 
);
45
 
 
46
 
my $maximum_query_duration = 2;
47
 
my $performance_threshold = 1.25;
48
 
 
49
 
# End of user-editable part
50
 
 
51
 
my @executors;
52
 
my @connection_ids;
53
 
 
54
 
foreach my $dsn (@dsns) {
55
 
        my $executor = GenTest::Executor::MySQL->new( dsn => $dsn );
56
 
        my $init_status = $executor->init();
57
 
        exit ($init_status) if $init_status != STATUS_OK;
58
 
        push @connection_ids, $executor->dbh()->selectrow_array("SELECT CONNECTION_ID()");
59
 
        $executor->dbh()->do("SET GLOBAL EVENT_SCHEDULER=ON");
60
 
        push @executors, $executor;
61
 
}
62
 
 
63
 
 
64
 
my $simplifier = GenTest::Simplifier::SQL->new(
65
 
        oracle => sub {
66
 
                my $oracle_query = shift;
67
 
                print ".";
68
 
 
69
 
                my $outcome;
70
 
                my @oracle_results;
71
 
                my @oracle_times;
72
 
 
73
 
                foreach my $executor_id (0..$#executors) {
74
 
                        my $executor = $executors[$executor_id];
75
 
                        $executor->dbh()->do("CREATE EVENT timeout ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL $maximum_query_duration SECOND DO KILL QUERY ".$connection_ids[$executor_id]);
76
 
                        my $time_start = Time::HiRes::time();
77
 
                        my $oracle_result = $executor->execute($oracle_query);
78
 
                        my $duration = (Time::HiRes::time() - $time_start);
79
 
                        $executor->dbh()->do("DROP EVENT IF EXISTS timeout");
80
 
                        return ORACLE_ISSUE_NO_LONGER_REPEATABLE if $oracle_result->status() > STATUS_OK;
81
 
                        push @oracle_times, $duration;
82
 
                        push @oracle_results, $oracle_result;
83
 
                }
84
 
                
85
 
                my $best_time = $oracle_times[0] > $oracle_times[1] ? $oracle_times[0] : $oracle_times[1];
86
 
                my $worst_time = $oracle_times[0] < $oracle_times[1] ? $oracle_times[0] : $oracle_times[1];
87
 
 
88
 
                if (
89
 
                        ($best_time / $worst_time >= $performance_threshold) &&
90
 
                        ($worst_time > 1)
91
 
                ) {
92
 
                        print "Repeatable with: $oracle_query\n\n";
93
 
                        return ORACLE_ISSUE_STILL_REPEATABLE;
94
 
                } else {
95
 
                        return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
96
 
                }
97
 
        }
98
 
);
99
 
 
100
 
my $simplified_query = $simplifier->simplify($query);
101
 
 
102
 
print "\nSimplified query:\n$simplified_query ;\n\n";
103
 
 
104
 
my @simplified_results;
105
 
 
106
 
foreach my $executor (@executors) {
107
 
        my $simplified_result = $executor->execute($simplified_query);
108
 
        push @simplified_results, $simplified_result;
109
 
}
110
 
 
111
 
 
112
 
my $simplifier_test = GenTest::Simplifier::Test->new(
113
 
        executors => \@executors,
114
 
        queries => [ $simplified_query, $query ],
115
 
        results => [ \@simplified_results ]
116
 
);
117
 
 
118
 
my $test = $simplifier_test->simplify();
119
 
 
120
 
print "Simplified test:\n\n";
121
 
print $test;