AtteanX/API/JoinRotatingPlanner.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.7% 67 / 70 CC 8 SCAR 15.6
CC
8
Cov
95%
__ANON__
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
« Attean/Algebra.pm ↑ Summary Attean/API/Expression.pm »
1 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =encoding utf8
5  
6 =head1 NAME
7  
8 AtteanX::API::JoinRotatingPlanner - Query planning role to produce alternative join plans
9  
10 =head1 VERSION
11  
12 This document describes AtteanX::API::JoinRotatingPlanner version 0.040
13  
14 =head1 DESCRIPTION
15  
16 The AtteanX::API::JoinRotatingPlanner role, when used with L<Attean::QueryPlanner>,
17 produces alternatives for join query plans. Specifically, joins of the form
18 (A⋈B)⋈C are rotated to A⋈(B⋈C), with the ability to coalesce B⋈C (e.g. for
19 adjacent BGPs).
20  
21 =head1 REQUIRED METHODS
22  
23 =over 4
24  
25 =item C<< allow_join_rotation( $join_plan ) >>
26  
27 Returns true if join rotation should be attempted on the given join plan.
28  
29 =item C<< coalesce_rotated_join( $join_plan ) >>
30  
31 Given a L<Attean::API::Plan::Join> plan C<< $join_plan >>, returns a list of
32 equivalent plans. This is useful when the join can be reduced to a more
33 fundamental plan type, such as merging two adjacent BGP plans into a single
34 plan.
35  
36 =cut
37  
38 1 package AtteanX::API::JoinRotatingPlanner 0.040 {
39 # Rotate joins like (A⋈B)⋈C to A⋈(B⋈C), with the ability to coalesce B⋈C (e.g. for adjacent BGPs)
40 1 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 requires 'coalesce_rotated_join';
46 1 requires 'allow_join_rotation';
47
48 20 ▶ sub allow_join_rotation {
Subroutine allow_join_rotation: called CC=1 SCAR=0.0
Pod documented
49 20 return 1;
50 }
51
52 48 ▶ sub coalesce_rotated_join {
Subroutine coalesce_rotated_join: called CC=1 SCAR=0.0
Pod documented
53 48 my $self = shift;
54 48 my $plan = shift;
55 48 return $plan;
56 }
57
58 6 ▶ around 'join_plans' => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
59 6 my $orig = shift;
60 6 my $self = shift;
61 6 my $model = shift;
62 6 my $active_graphs = shift;
63 6 my $default_graphs = shift;
64 6 my $lplans = shift;
65 6 my $rplans = shift;
66 6 my $type = shift;
67 6 my @plans = $orig->($self, $model, $active_graphs, $default_graphs, $lplans, $rplans, $type, @_);
68 6 ▶ if ($type eq 'inner') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'inner') { } 6 0 6
69 6 my @rotated;
70 6 foreach my $p (@plans) {
71 60 ▶ if ($self->allow_join_rotation($p)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->allow_join_rotation($p)) 60 0 60
72 60 my ($lhs, $rhs) = @{ $p->children };
73 60 ▶ if ($lhs->does('Attean::API::Plan::Join')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lhs->does('Attean::API::Plan::Join')) { } 24 36 60
elsif ($rhs->does('Attean::API::Plan::Join')) { } 24 12 36
74 24 my ($a, $b) = @{ $lhs->children };
75 24 my $c = $rhs;
76 # (A⋈B)⋈C -> A⋈(B⋈C)
77 24 foreach my $q ($orig->($self, $model, $active_graphs, $default_graphs, [$b], [$c], $type, @_)) {
78 72 push(@rotated, $orig->($self, $model, $active_graphs, $default_graphs, [$a], [$self->coalesce_rotated_join($q)], $type, @_))
79 }
80 } elsif ($rhs->does('Attean::API::Plan::Join')) {
81 24 my $a = $lhs;
82 24 my ($b, $c) = @{ $rhs->children };
83 # A⋈(B⋈C) -> (A⋈B)⋈C
84 24 foreach my $q ($orig->($self, $model, $active_graphs, $default_graphs, [$a], [$b], $type, @_)) {
85 72 push(@rotated, $orig->($self, $model, $active_graphs, $default_graphs, [$self->coalesce_rotated_join($q)], [$c], $type, @_));
86 }
87 }
88 }
89 60 push(@rotated, $p);
90 }
91 6 return @rotated;
92 } else {
93 0 return @plans;
94 }
95 1 };
96 }
97  
98 1 1;
99  
100 __END__
« Attean/Algebra.pm ↑ Summary Attean/API/Expression.pm »