1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
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.
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.
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
27
use GenTest::Constants;
28
use GenTest::Executor::MySQL;
29
use GenTest::Simplifier::Test;
30
use GenTest::Simplifier::SQL;
31
use GenTest::Comparator;
34
# This script demonstrates the simplification of queries. More information is available at
36
# http://forge.mysql.com/wiki/RandomQueryGeneratorSimplification
39
my $query = "SELECT 1 FROM DUAL";
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'
46
my $maximum_query_duration = 2;
47
my $performance_threshold = 1.25;
49
# End of user-editable part
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;
64
my $simplifier = GenTest::Simplifier::SQL->new(
66
my $oracle_query = shift;
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;
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];
89
($best_time / $worst_time >= $performance_threshold) &&
92
print "Repeatable with: $oracle_query\n\n";
93
return ORACLE_ISSUE_STILL_REPEATABLE;
95
return ORACLE_ISSUE_NO_LONGER_REPEATABLE;
100
my $simplified_query = $simplifier->simplify($query);
102
print "\nSimplified query:\n$simplified_query ;\n\n";
104
my @simplified_results;
106
foreach my $executor (@executors) {
107
my $simplified_result = $executor->execute($simplified_query);
108
push @simplified_results, $simplified_result;
112
my $simplifier_test = GenTest::Simplifier::Test->new(
113
executors => \@executors,
114
queries => [ $simplified_query, $query ],
115
results => [ \@simplified_results ]
118
my $test = $simplifier_test->simplify();
120
print "Simplified test:\n\n";