| 1 | 11 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | package AtteanX::QueryPlanner::Cache; | ||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Class::Method::Modifiers; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 11 | our $AUTHORITY = 'cpan:KJETILK'; | |||||||||||||||||||||||||||||||
| 10 | 11 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Types::Standard qw(InstanceOf); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Attean::RDF qw(triplepattern variable iri); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use AtteanX::Plan::SPARQLBGP; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 11 | extends 'Attean::QueryPlanner'; | |||||||||||||||||||||||||||||||
| 19 | 11 | with 'Attean::API::NaiveJoinPlanner', 'Attean::API::SimpleCostPlanner'; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 11 | with 'AtteanX::API::JoinRotatingPlanner', 'MooX::Log::Any'; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 11 | with 'AtteanX::Query::AccessPlan::SingleQuadBGP', 'AtteanX::Query::AccessPlan::Cache'; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | # Only allow rotation on joins who have one child matching: - Either a | ||||||||||||||||||||||||||||||||
| 26 | # Attean::Plan::Quad or AtteanX::Plan::SPARQLBGP and the | ||||||||||||||||||||||||||||||||
| 27 | # other child being a join | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 852 | ▶ | sub allow_join_rotation { | ||||||||||||||||||||||||||||||
|
Subroutine
allow_join_rotation: called CC=11 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 30 | 852 | my $self = shift; | |||||||||||||||||||||||||||||||
| 31 | 852 | my $join = shift; | |||||||||||||||||||||||||||||||
| 32 | 852 | my $quads = 0; | |||||||||||||||||||||||||||||||
| 33 | 852 | my $joins = 0; | |||||||||||||||||||||||||||||||
| 34 | 852 | my @grandchildren; | |||||||||||||||||||||||||||||||
| 35 | 852 | $self->log->trace("Seeking to rotate:\n" . $join->as_string); | |||||||||||||||||||||||||||||||
| 36 | 852 | foreach my $p (@{ $join->children }) { | |||||||||||||||||||||||||||||||
| 37 | 1704 | ▶ | $quads++ if ($p->isa('Attean::Plan::Quad')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 1704 | ▶ | $quads++ if ($p->isa('AtteanX::Plan::SPARQLBGP')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 1704 | ▶ | if ($p->does('Attean::API::Plan::Join')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 848 | $joins++; | |||||||||||||||||||||||||||||||
| 41 | 848 | push(@grandchildren, @{ $p->children }); | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 852 | ▶ | return 0 unless ($joins == 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 848 | ▶ | return 0 unless ($quads == 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 848 | foreach my $p (@grandchildren) { | |||||||||||||||||||||||||||||||
| 47 | 1696 | ▶ | $quads++ if ($p->isa('Attean::Plan::Quad')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 1696 | ▶ | $quads++ if ($p->isa('AtteanX::Plan::SPARQLBGP')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 848 | ▶ | if ($quads >= 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 848 | $self->log->debug("Allowing rotation for $quads quads."); | |||||||||||||||||||||||||||||||
| 53 | 848 | return 1; | |||||||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||||||
| 55 | 0 | $self->log->debug("Disallowing rotation, just $quads quad."); | |||||||||||||||||||||||||||||||
| 56 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 3312 | ▶ | sub coalesce_rotated_join { | ||||||||||||||||||||||||||||||
|
Subroutine
coalesce_rotated_join: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 61 | 3312 | my $self = shift; | |||||||||||||||||||||||||||||||
| 62 | 3312 | my $p = shift; | |||||||||||||||||||||||||||||||
| 63 | 3312 | my @quads; | |||||||||||||||||||||||||||||||
| 64 | 3312 | my ($lhs, $rhs) = @{ $p->children }; | |||||||||||||||||||||||||||||||
| 65 | 3312 | my @join_vars = $self->_join_vars($lhs, $rhs); | |||||||||||||||||||||||||||||||
| 66 | 3312 | ▶ | if (scalar(@join_vars)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 3232 | foreach my $q ($lhs, $rhs) { | |||||||||||||||||||||||||||||||
| 68 | 5632 | ▶ | if ($q->isa('Attean::Plan::Quad')) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 69 | 0 | push(@quads, $q); | |||||||||||||||||||||||||||||||
| 70 | } elsif ($q->isa('AtteanX::Plan::SPARQLBGP')) { | ||||||||||||||||||||||||||||||||
| 71 | 3968 | push(@quads, @{ $q->children }); | |||||||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||||||
| 73 | 1664 | return $p; # bail-out | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | 1568 | my $count = scalar(@quads); | |||||||||||||||||||||||||||||||
| 77 | 1568 | my $c = AtteanX::Plan::SPARQLBGP->new(children => \@quads, distinct => 0); | |||||||||||||||||||||||||||||||
| 78 | 1568 | ▶ | if ($self->log->is_debug && $count >= 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->log->is_debug and $count >= 2
MC/DC0%0/2
$self->log->is_debug and $count >= 2
$self->log->is_debug
$count >= 2
Truth table33%1/3
A and B
A= $self->log->is_debugB= $count >= 2
| |||||||||||||||||||||||||||||||||
| 79 | 0 | $self->log->debug("Coalescing $lhs and $rhs into BGP with $count quads"); | |||||||||||||||||||||||||||||||
| 80 | 0 | $self->log->trace($c->as_string); | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | 1568 | return $c; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | 80 | return $p; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | # Gather patterns into larger BGPs | ||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | around 'join_plans' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=27.2
| |||||||||||||||||||||||||||||||||
| 89 | 3 | my $orig = shift; | |||||||||||||||||||||||||||||||
| 90 | 3 | my @params = @_; | |||||||||||||||||||||||||||||||
| 91 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 92 | 3 | my $model = shift; | |||||||||||||||||||||||||||||||
| 93 | 3 | my $active_graphs = shift; | |||||||||||||||||||||||||||||||
| 94 | 3 | my $default_graphs = shift; | |||||||||||||||||||||||||||||||
| 95 | 3 | my $lplans = shift; | |||||||||||||||||||||||||||||||
| 96 | 3 | my $rplans = shift; | |||||||||||||||||||||||||||||||
| 97 | 3 | my @restargs = @_; | |||||||||||||||||||||||||||||||
| 98 | 3 | my @plans; | |||||||||||||||||||||||||||||||
| 99 | 3 | foreach my $lhs (@{ $lplans }) { | |||||||||||||||||||||||||||||||
| 100 | 216 | $self->log->trace("BGP Constructing Left:\n" . $lhs->as_string); | |||||||||||||||||||||||||||||||
| 101 | 216 | foreach my $rhs (@{ $rplans }) { | |||||||||||||||||||||||||||||||
| 102 | 216 | $self->log->trace("BGP Constructing Right:\n" . $rhs->as_string); | |||||||||||||||||||||||||||||||
| 103 | 216 | my @join_vars = $self->_join_vars($lhs, $rhs); | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 216 | ▶ | if ($lhs->isa('Attean::Plan::Iterator') && ($rhs->isa('Attean::Plan::Iterator'))) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$lhs->isa("Attean::Plan::Iterator") and $rhs->isa("Attean::Plan::Iterator")
MC/DC0%0/2
$lhs->isa("Attean::Plan::Iterator") and $rhs->isa("Attean::Plan::Iterator")
$lhs->isa("Attean::Plan::Iterator")
$rhs->isa("Attean::Plan::Iterator")
Truth table66%2/3
A and B
A= $lhs->isa("Attean::Plan::Iterator")B= $rhs->isa("Attean::Plan::Iterator")
| |||||||||||||||||||||||||||||||||
| 106 | # push(@plans, $orig->($self, $model, $active_graphs, $default_graphs, [$rhs], [$lhs], @restargs)); # Most general solution | ||||||||||||||||||||||||||||||||
| 107 | # Best known solution for now: | ||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if (scalar(@join_vars) > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 0 | return Attean::Plan::HashJoin->new(children => [$lhs, $rhs], join_variables => \@join_vars, distinct => 0, ordered => []); | |||||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||||||
| 111 | 0 | return Attean::Plan::NestedLoopJoin->new(children => [$lhs, $rhs], join_variables => \@join_vars, distinct => 0, ordered => []); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | ▶ | } elsif ($rhs->isa('AtteanX::Plan::SPARQLBGP') && | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$rhs->isa("AtteanX::Plan::SPARQLBGP") and $lhs->isa("AtteanX::Plan::SPARQLBGP")
MC/DC50%1/2
$rhs->isa("AtteanX::Plan::SPARQLBGP") and $lhs->isa("AtteanX::Plan::SPARQLBGP")
$rhs->isa("AtteanX::Plan::SPARQLBGP")
$lhs->isa("AtteanX::Plan::SPARQLBGP")
Truth table66%2/3
A and B
A= $rhs->isa("AtteanX::Plan::SPARQLBGP")B= $lhs->isa("AtteanX::Plan::SPARQLBGP")
| |||||||||||||||||||||||||||||||||
| 114 | $lhs->isa('AtteanX::Plan::SPARQLBGP')) { | ||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | if (scalar(@join_vars)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | push(@plans, AtteanX::Plan::SPARQLBGP->new(children => [@{ $lhs->children || []} , @{ $rhs->children || []} ], distinct => 0, ordered => [])); | ||||||||||||||||||||||||||||||
|
Condition50%2/4
$lhs->children || []
$rhs->children || []
MC/DC0%0/1
$lhs->children || []
$lhs->children
MC/DC0%0/1
$rhs->children || []
$rhs->children
Truth table50%1/2
A
A= $lhs->children
Truth table50%1/2
A
A= $rhs->children
| |||||||||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||||||
| 118 | 0 | push(@plans, $orig->($self, $model, $active_graphs, $default_graphs, [$lhs], [$rhs], @restargs)); | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||||||
| 121 | 213 | push(@plans, $orig->($self, $model, $active_graphs, $default_graphs, [$lhs], [$rhs], @restargs)); | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | unless (@plans) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | @plans = $orig->(@params); | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | 3 | return @plans; | |||||||||||||||||||||||||||||||
| 131 | 11 | }; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 11 | 1; | |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||||||