~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/lib/GenTest/Transform/DisableJoinCache.pm

  • 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
# This program is free software; you can redistribute it and/or modify
 
2
# it under the terms of the GNU General Public License as published by
 
3
# the Free Software Foundation; version 2 of the License.
 
4
#
 
5
# This program is distributed in the hope that it will be useful, but
 
6
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
7
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
8
# General Public License for more details.
 
9
#
 
10
# You should have received a copy of the GNU General Public License
 
11
# along with this program; if not, write to the Free Software
 
12
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
13
# USA
 
14
 
 
15
package GenTest::Transform::DisableJoinCache;
 
16
 
 
17
require Exporter;
 
18
@ISA = qw(GenTest GenTest::Transform);
 
19
 
 
20
use strict;
 
21
use lib 'lib';
 
22
use GenTest;
 
23
use GenTest::Transform;
 
24
use GenTest::Constants;
 
25
use Data::Dumper;
 
26
 
 
27
my @explain2switch = (
 
28
        [ 'join buffer'         => "join_cache_level=0" ]
 
29
);
 
30
 
 
31
my $available_switches;
 
32
 
 
33
sub transform {
 
34
        my ($class, $original_query, $executor) = @_;
 
35
 
 
36
        if (not defined $available_switches) {
 
37
                my $optimizer_switches = $executor->dbh()->selectrow_array('SELECT @@optimizer_switch');
 
38
                my @optimizer_switches = split(',', $optimizer_switches);
 
39
                foreach my $optimizer_switch (@optimizer_switches) {
 
40
                        my ($switch_name, $switch_value) = split('=', $optimizer_switch);
 
41
                        $available_switches->{"optimizer_switch='$switch_name=off'"}++;
 
42
                }
 
43
 
 
44
                if ($executor->dbh()->selectrow_array('SELECT @@optimizer_use_mrr')) {
 
45
                        $available_switches->{"optimizer_use_mrr='disable'"}++;
 
46
                }
 
47
 
 
48
                if ($executor->dbh()->selectrow_array('SELECT @@join_cache_level')) {
 
49
                        $available_switches->{"join_cache_level=0"}++;
 
50
                }
 
51
 
 
52
                if ($executor->dbh()->selectrow_array('SELECT @@optimizer_join_cache_level')) {
 
53
                        $available_switches->{"optimizer_join_cache_level=0"}++;
 
54
                }
 
55
        }
 
56
 
 
57
        return STATUS_WONT_HANDLE if $original_query !~ m{^\s*SELECT}sio;
 
58
 
 
59
        my $original_explain = $executor->execute("EXPLAIN EXTENDED $original_query");
 
60
 
 
61
        if ($original_explain->status() == STATUS_SERVER_CRASHED) {
 
62
                return STATUS_SERVER_CRASHED;
 
63
        } elsif ($original_explain->status() ne STATUS_OK) {
 
64
                return STATUS_ENVIRONMENT_FAILURE;
 
65
        }
 
66
 
 
67
        my $original_explain_string = Dumper($original_explain->data())."\n".Dumper($original_explain->warnings());
 
68
 
 
69
        my @transformed_queries;
 
70
        foreach my $explain2switch (@explain2switch) {
 
71
                my ($explain_fragment, $optimizer_switch) = ($explain2switch->[0], $explain2switch->[1]);
 
72
                next if not exists $available_switches->{$optimizer_switch};
 
73
                if ($original_explain_string =~ m{$explain_fragment}si) {
 
74
                        my ($switch_name) = $optimizer_switch =~ m{^(.*?)=}sgio;
 
75
                        push @transformed_queries, (
 
76
                                'SET @switch_saved = @@'.$switch_name.';',
 
77
                                "SET SESSION $optimizer_switch;",
 
78
                                "$original_query /* TRANSFORM_OUTCOME_UNORDERED_MATCH */ ;",
 
79
                                'SET SESSION '.$switch_name.'=@switch_saved'
 
80
                        );
 
81
                        last;
 
82
                }
 
83
        }
 
84
 
 
85
        if ($#transformed_queries > -1) {
 
86
                return \@transformed_queries;
 
87
        } else {
 
88
                return STATUS_WONT_HANDLE;
 
89
        }
 
90
}
 
91
 
 
92
1;