| 1 | # RDF::Query::Plan::ThresholdUnion | ||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | RDF::Query::Plan::ThresholdUnion - Executable query plan for unions. | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | This document describes RDF::Query::Plan::ThresholdUnion version 2.919. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 METHODS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||||||||||||||||||
| 15 | L<RDF::Query::Plan> class. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =over 4 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package RDF::Query::Plan::ThresholdUnion; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 35 | ▶ | use base qw(RDF::Query::Plan); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 35 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 35 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 35 | ▶ | use RDF::Query::ExecutionContext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | ###################################################################### | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 35 | our ($VERSION); | |||||||||||||||||||||||||||
| 35 | 35 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 35 | $VERSION = '2.919'; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | ###################################################################### | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =item C<< new ( $time, @plans ) >> | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 47 | 0 | my $time = shift; | |||||||||||||||||||||||||||
| 48 | 0 | my @plans = @_; | |||||||||||||||||||||||||||
| 49 | 0 | my $self = $class->SUPER::new( $time, \@plans ); | |||||||||||||||||||||||||||
| 50 | 0 | my %vars; | |||||||||||||||||||||||||||
| 51 | 0 | foreach my $plan (@plans) { | |||||||||||||||||||||||||||
| 52 | 0 | foreach my $v ($plan->referenced_variables) { | |||||||||||||||||||||||||||
| 53 | 0 | $vars{ $v }++; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | $self->[0]{referenced_variables} = [ keys %vars ]; | |||||||||||||||||||||||||||
| 57 | 0 | return $self; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item C<< execute ( $execution_context ) >> | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub execute ($) { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 0 | my $context = shift; | |||||||||||||||||||||||||||
| 67 | 0 | $self->[0]{delegate} = $context->delegate; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | throw RDF::Query::Error::ExecutionError -text => "ThresholdUnion plan can't be executed while already open"; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $l = Log::Log4perl->get_logger("rdf.query.plan.thresholdunion"); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | my $iter = $self->[2][0]; | |||||||||||||||||||||||||||
| 75 | 0 | $l->trace("threshold union initialized with first sub-plan: " . $iter->sse); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $iter->execute( $context ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($iter->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $self->[0]{iter} = $iter; | |||||||||||||||||||||||||||
| 81 | 0 | $self->[0]{idx} = 0; | |||||||||||||||||||||||||||
| 82 | 0 | $self->[0]{context} = $context; | |||||||||||||||||||||||||||
| 83 | 0 | $self->[0]{start_time} = time; | |||||||||||||||||||||||||||
| 84 | 0 | $self->state( $self->OPEN ); | |||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 0 | warn "no iterator in execute()"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | $self; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item C<< next >> | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open ThresholdUnion"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | my $iter = $self->[0]{iter}; | |||||||||||||||||||||||||||
| 101 | 0 | my $row = $iter->next; | |||||||||||||||||||||||||||
| 102 | 0 | my $l = Log::Log4perl->get_logger("rdf.query.plan.thresholdunion"); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($row) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (my $d = $self->delegate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $d->log_result( $self, $row ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | return $row; | |||||||||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||||||||||
| 109 | 0 | $l->trace("thresholdunion sub-plan finished"); | |||||||||||||||||||||||||||
| 110 | 0 | delete $self->[0]{iter}; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | return undef unless ($self->[0]{idx} < $#{ $self->[2] }); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $iter->close(); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | my $iter; | |||||||||||||||||||||||||||
| 115 | my $index; | ||||||||||||||||||||||||||||
| 116 | 0 | my $threshold = $self->threshold_time; | |||||||||||||||||||||||||||
| 117 | 0 | my $elapsed = time - $self->[0]{start_time}; | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (($threshold == 0) or ($elapsed < $threshold)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$threshold == 0 or $elapsed < $threshold
MC/DC0%0/2
$threshold == 0 or $elapsed < $threshold
$threshold == 0
$elapsed < $threshold
Truth table0%0/3
A or B
A= $threshold == 0B= $elapsed < $threshold
| |||||||||||||||||||||||||||||
| 119 | # we haven't passed the threshold of execution time, so go on | ||||||||||||||||||||||||||||
| 120 | # to the next optimistic plan: | ||||||||||||||||||||||||||||
| 121 | 0 | $l->trace("the elapsed time ($elapsed) hasn't passed the threshold time ($threshold); continuing to next plan"); | |||||||||||||||||||||||||||
| 122 | 0 | $index = ++$self->[0]{idx}; | |||||||||||||||||||||||||||
| 123 | 0 | $iter = $self->[2][ $index ]; | |||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||
| 125 | # the elapsed time has passed the threshold time, so jump straight to the default plan | ||||||||||||||||||||||||||||
| 126 | 0 | $l->trace("the elapsed time ($elapsed) has passed the threshold time ($threshold); jumping to the default plan"); | |||||||||||||||||||||||||||
| 127 | 0 | $index = ($self->[0]{idx} = $#{ $self->[2] }); | |||||||||||||||||||||||||||
| 128 | 0 | $iter = $self->[2][ $index ]; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | $l->trace("threshold union executing next sub-plan: " . $iter->sse); | |||||||||||||||||||||||||||
| 132 | 0 | $iter->execute( $self->[0]{context} ); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($iter->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | $self->[0]{iter} = $iter; | |||||||||||||||||||||||||||
| 135 | 0 | my $bindings = $self->next; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (my $d = $self->delegate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | $d->log_result( $self, $bindings ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 0 | return $bindings; | |||||||||||||||||||||||||||
| 140 | } else { | ||||||||||||||||||||||||||||
| 141 | 0 | throw RDF::Query::Error::ExecutionError -text => "execute() on child [${index}] of UNION failed during next()"; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =item C<< close >> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open ThresholdUnion"; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($self->[0]{iter}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | $self->[0]{iter}->close(); | |||||||||||||||||||||||||||
| 157 | 0 | delete $self->[0]{iter}; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | 0 | $self->SUPER::close(); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item C<< children >> | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub children { | ||||||||||||||||||||||||||
|
Subroutine
children: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 168 | 0 | return @{ $self->[2] }; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =item C<< threshold_time >> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub threshold_time { | ||||||||||||||||||||||||||
|
Subroutine
threshold_time: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 177 | 0 | return $self->[1]; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =item C<< optimistic >> | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub optimistic { | ||||||||||||||||||||||||||
|
Subroutine
optimistic: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 186 | 0 | return @{ $self->[2] }[ 0 .. $#{ $self->[2] } - 1 ]; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =item C<< default >> | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub default { | ||||||||||||||||||||||||||
|
Subroutine
default: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 195 | 0 | return $self->[2][ $#{ $self->[2] } ]; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =item C<< distinct >> | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Returns true if the pattern is guaranteed to return distinct results. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =cut | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub distinct { | ||||||||||||||||||||||||||
|
Subroutine
distinct: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 0 | return 0; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =item C<< ordered >> | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Returns true if the pattern is guaranteed to return ordered results. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub ordered { | ||||||||||||||||||||||||||
|
Subroutine
ordered: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 0 | return []; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =item C<< plan_node_name >> | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Returns the string name of this plan node, suitable for use in serialization. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub plan_node_name { | ||||||||||||||||||||||||||
|
Subroutine
plan_node_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 0 | return 'threshold-union'; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =item C<< plan_prototype >> | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | Returns a list of scalar identifiers for the type of the content (children) | ||||||||||||||||||||||||||||
| 231 | nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable | ||||||||||||||||||||||||||||
| 232 | identifiers. | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =cut | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub plan_prototype { | ||||||||||||||||||||||||||
|
Subroutine
plan_prototype: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 237 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 238 | 0 | return qw(i *P); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =item C<< plan_node_data >> | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | Returns the data for this plan node that corresponds to the values described by | ||||||||||||||||||||||||||||
| 244 | the signature returned by C<< plan_prototype >>. | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =cut | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub plan_node_data { | ||||||||||||||||||||||||||
|
Subroutine
plan_node_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 249 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 250 | 0 | my $exprs = $self->[2]; | |||||||||||||||||||||||||||
| 251 | 0 | return ($self->threshold_time, $self->children); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =item C<< graph ( $g ) >> | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =cut | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub graph { | ||||||||||||||||||||||||||
|
Subroutine
graph: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 259 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 260 | 0 | my $g = shift; | |||||||||||||||||||||||||||
| 261 | 0 | my (@children) = map { $_->graph( $g ) } ($self->children); | |||||||||||||||||||||||||||
| 262 | 0 | $g->add_node( "$self", label => "Threshold Union" . $self->graph_labels ); | |||||||||||||||||||||||||||
| 263 | 0 | $g->add_edge( "$self", $_ ) for (@children); | |||||||||||||||||||||||||||
| 264 | 0 | return "$self"; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 35 | 1; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | __END__ | ||||||||||||||||||||||||||||