~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Validator/ExplainMatch.pm

merge from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Validator::ExplainMatch;
 
2
 
 
3
require Exporter;
 
4
@ISA = qw(GenTest::Validator GenTest);
 
5
 
 
6
use strict;
 
7
 
 
8
use GenTest;
 
9
use GenTest::Constants;
 
10
use GenTest::Result;
 
11
use GenTest::Validator;
 
12
use GenTest::Simplifier::Test;
 
13
use Data::Dumper;
 
14
 
 
15
my $match_string = 'unique row not found';
 
16
 
 
17
1;
 
18
 
 
19
sub validate {
 
20
        my ($validator, $executors, $results) = @_;
 
21
 
 
22
        my $executor = $executors->[0];
 
23
        my $query = $results->[0]->query();
 
24
 
 
25
        return STATUS_WONT_HANDLE if $query !~ m{^\s*SELECT}sio;
 
26
 
 
27
        my $explain_output = $executor->dbh()->selectall_arrayref("EXPLAIN $query");
 
28
 
 
29
        my $explain_string = Dumper $explain_output;
 
30
 
 
31
        if ($explain_string =~ m{$match_string}sio) {
 
32
                say("EXPLAIN $query matches $match_string");
 
33
                my $simplifier_test = GenTest::Simplifier::Test->new(
 
34
                        executors => [ $executor ],
 
35
                        queries => [ $query , "EXPLAIN $query" ]
 
36
                );
 
37
                my $simplified_test = $simplifier_test->simplify();
 
38
                say("Simplified test:");
 
39
                print $simplified_test;
 
40
                return STATUS_CUSTOM_OUTCOME;
 
41
        } else {
 
42
                return STATUS_OK;
 
43
        }
 
44
}
 
45
 
 
46
1;