| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Query::Plan::Join::NestedLoop |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Plan::Join::NestedLoop - Executable query plan for nested loop joins. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Plan::Join::NestedLoop version 2.916. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
|
15
|
|
|
|
|
|
|
L<RDF::Query::Plan::Join> class. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=over 4 |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package RDF::Query::Plan::Join::NestedLoop; |
|
22
|
|
|
|
|
|
|
|
|
23
|
35
|
|
|
35
|
|
188
|
use strict; |
|
|
35
|
|
|
|
|
76
|
|
|
|
35
|
|
|
|
|
11339
|
|
|
24
|
35
|
|
|
35
|
|
234
|
use warnings; |
|
|
35
|
|
|
|
|
125
|
|
|
|
35
|
|
|
|
|
1013
|
|
|
25
|
35
|
|
|
35
|
|
171
|
use base qw(RDF::Query::Plan::Join); |
|
|
35
|
|
|
|
|
65
|
|
|
|
35
|
|
|
|
|
20416
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
35
|
|
|
35
|
|
214
|
use Log::Log4perl; |
|
|
35
|
|
|
|
|
60
|
|
|
|
35
|
|
|
|
|
301
|
|
|
28
|
35
|
|
|
35
|
|
1916
|
use Scalar::Util qw(blessed); |
|
|
35
|
|
|
|
|
74
|
|
|
|
35
|
|
|
|
|
1816
|
|
|
29
|
35
|
|
|
35
|
|
190
|
use Time::HiRes qw(gettimeofday tv_interval); |
|
|
35
|
|
|
|
|
72
|
|
|
|
35
|
|
|
|
|
398
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
35
|
|
|
35
|
|
4359
|
use RDF::Query::Error qw(:try); |
|
|
35
|
|
|
|
|
69
|
|
|
|
35
|
|
|
|
|
253
|
|
|
32
|
35
|
|
|
35
|
|
4410
|
use RDF::Query::ExecutionContext; |
|
|
35
|
|
|
|
|
73
|
|
|
|
35
|
|
|
|
|
1829
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
###################################################################### |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our ($VERSION); |
|
37
|
|
|
|
|
|
|
BEGIN { |
|
38
|
35
|
|
|
35
|
|
99
|
$VERSION = '2.916'; |
|
39
|
35
|
|
|
|
|
44907
|
$RDF::Query::Plan::Join::JOIN_CLASSES{ 'RDF::Query::Plan::Join::NestedLoop' }++; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
###################################################################### |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item C<< new ( $lhs, $rhs, $opt, [ \%logging_keys ] ) >> |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
|
49
|
31
|
|
|
31
|
1
|
67
|
my $class = shift; |
|
50
|
31
|
|
|
|
|
64
|
my $lhs = shift; |
|
51
|
31
|
|
|
|
|
54
|
my $rhs = shift; |
|
52
|
31
|
|
|
|
|
62
|
my $opt = shift; |
|
53
|
31
|
|
|
|
|
61
|
my $keys = shift; |
|
54
|
31
|
100
|
|
|
|
91
|
if ($opt) { |
|
55
|
11
|
|
|
|
|
82
|
throw RDF::Query::Error::MethodInvocationError -text => "NestedLoop join does not support optional joins (use PushDownNestedLoop instead)"; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
20
|
|
|
|
|
105
|
my $self = $class->SUPER::new( $lhs, $rhs, $opt ); |
|
58
|
|
|
|
|
|
|
|
|
59
|
20
|
|
|
|
|
68
|
$self->[0]{logging_keys} = $keys; |
|
60
|
20
|
|
|
|
|
56
|
return $self; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item C<< execute ( $execution_context ) >> |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub execute ($) { |
|
68
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
69
|
1
|
|
|
|
|
3
|
my $context = shift; |
|
70
|
1
|
|
|
|
|
3
|
$self->[0]{delegate} = $context->delegate; |
|
71
|
1
|
50
|
|
|
|
9
|
if ($self->state == $self->OPEN) { |
|
72
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "NestedLoop join plan can't be executed while already open"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
6
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.join.nestedloop"); |
|
76
|
1
|
|
|
|
|
549
|
$self->[0]{start_time} = [gettimeofday]; |
|
77
|
|
|
|
|
|
|
# if ($self->optional) { |
|
78
|
|
|
|
|
|
|
# my (@inner, @outer); |
|
79
|
|
|
|
|
|
|
# $self->rhs->execute( $context ); |
|
80
|
|
|
|
|
|
|
# while (my $row = $self->rhs->next) { |
|
81
|
|
|
|
|
|
|
# $l->trace("loading inner row: " . $row); |
|
82
|
|
|
|
|
|
|
# push(@inner, $row); |
|
83
|
|
|
|
|
|
|
# } |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
# my @results; |
|
86
|
|
|
|
|
|
|
# $self->lhs->execute( $context ); |
|
87
|
|
|
|
|
|
|
# while (my $outer = $self->lhs->next) { |
|
88
|
|
|
|
|
|
|
# $l->trace("loading outer row: " . $outer); |
|
89
|
|
|
|
|
|
|
# my $count = 0; |
|
90
|
|
|
|
|
|
|
# foreach my $inner (@inner) { |
|
91
|
|
|
|
|
|
|
# if (my $joined = $inner->join( $outer )) { |
|
92
|
|
|
|
|
|
|
# $count++; |
|
93
|
|
|
|
|
|
|
# if ($l->is_trace) { |
|
94
|
|
|
|
|
|
|
# $l->trace("joined bindings: $outer â $inner"); |
|
95
|
|
|
|
|
|
|
# } |
|
96
|
|
|
|
|
|
|
# # warn "-> joined\n"; |
|
97
|
|
|
|
|
|
|
# $self->[0]{count}++; |
|
98
|
|
|
|
|
|
|
# push(@results, $joined); |
|
99
|
|
|
|
|
|
|
# } |
|
100
|
|
|
|
|
|
|
# } |
|
101
|
|
|
|
|
|
|
# if ($count == 0) { |
|
102
|
|
|
|
|
|
|
# # left-join branch |
|
103
|
|
|
|
|
|
|
# push(@results, $outer); |
|
104
|
|
|
|
|
|
|
# } |
|
105
|
|
|
|
|
|
|
# } |
|
106
|
|
|
|
|
|
|
# |
|
107
|
|
|
|
|
|
|
# warn Dumper(\@results); |
|
108
|
|
|
|
|
|
|
# |
|
109
|
|
|
|
|
|
|
# $self->[0]{results} = \@results; |
|
110
|
|
|
|
|
|
|
# } else { |
|
111
|
1
|
|
|
|
|
2
|
my @inner; |
|
112
|
1
|
|
|
|
|
8
|
$self->rhs->execute( $context ); |
|
113
|
1
|
|
|
|
|
5
|
while (my $row = $self->rhs->next) { |
|
114
|
2
|
|
|
|
|
8
|
$l->trace("loading inner row cache with: " . $row); |
|
115
|
2
|
|
|
|
|
59
|
push(@inner, $row); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
1
|
|
|
|
|
7
|
$self->lhs->execute( $context ); |
|
118
|
1
|
50
|
|
|
|
5
|
if ($self->lhs->state == $self->OPEN) { |
|
119
|
1
|
|
|
|
|
3
|
$self->[0]{inner} = \@inner; |
|
120
|
1
|
|
|
|
|
4
|
$self->[0]{outer} = $self->lhs; |
|
121
|
1
|
|
|
|
|
3
|
$self->[0]{inner_index} = 0; |
|
122
|
1
|
|
|
|
|
2
|
$self->[0]{needs_new_outer} = 1; |
|
123
|
1
|
|
|
|
|
4
|
$self->[0]{inner_count} = 0; |
|
124
|
1
|
|
|
|
|
3
|
$self->[0]{count} = 0; |
|
125
|
1
|
|
|
|
|
5
|
$self->[0]{logger} = $context->logger; |
|
126
|
1
|
|
|
|
|
7
|
$self->state( $self->OPEN ); |
|
127
|
|
|
|
|
|
|
} else { |
|
128
|
0
|
|
|
|
|
0
|
warn "no iterator in execute()"; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
# } |
|
131
|
|
|
|
|
|
|
# warn '########################################'; |
|
132
|
1
|
|
|
|
|
4
|
$self; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item C<< next >> |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub next { |
|
140
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
|
141
|
1
|
50
|
|
|
|
6
|
unless ($self->state == $self->OPEN) { |
|
142
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open NestedLoop join"; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# if ($self->optional) { |
|
146
|
|
|
|
|
|
|
# my $result = shift(@{ $self->[0]{results} }); |
|
147
|
|
|
|
|
|
|
# if (my $d = $self->delegate) { |
|
148
|
|
|
|
|
|
|
# $d->log_result( $self, $result ); |
|
149
|
|
|
|
|
|
|
# } |
|
150
|
|
|
|
|
|
|
# return $result; |
|
151
|
|
|
|
|
|
|
# } |
|
152
|
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
3
|
my $outer = $self->[0]{outer}; |
|
154
|
1
|
|
|
|
|
2
|
my $inner = $self->[0]{inner}; |
|
155
|
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
6
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.join.nestedloop"); |
|
157
|
1
|
|
|
|
|
20
|
while (1) { |
|
158
|
2
|
50
|
|
|
|
8
|
if ($self->[0]{needs_new_outer}) { |
|
159
|
2
|
|
|
|
|
8
|
$self->[0]{outer_row} = $outer->next; |
|
160
|
2
|
50
|
|
|
|
7
|
if (ref($self->[0]{outer_row})) { |
|
161
|
2
|
|
|
|
|
30
|
$self->[0]{needs_new_outer} = 0; |
|
162
|
2
|
|
|
|
|
5
|
$self->[0]{inner_index} = 0; |
|
163
|
2
|
|
|
|
|
4
|
$self->[0]{inner_count} = 0; |
|
164
|
|
|
|
|
|
|
# warn "got new outer row: " . Dumper($self->[0]{outer_row}); |
|
165
|
|
|
|
|
|
|
} else { |
|
166
|
|
|
|
|
|
|
# we've exhausted the outer iterator. we're now done. |
|
167
|
|
|
|
|
|
|
# warn "exhausted"; |
|
168
|
0
|
|
|
|
|
0
|
return undef; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
2
|
|
|
|
|
8
|
while ($self->[0]{inner_index} < scalar(@$inner)) { |
|
173
|
3
|
|
|
|
|
42
|
my $inner_row = $inner->[ $self->[0]{inner_index}++ ]; |
|
174
|
|
|
|
|
|
|
# warn "using inner row: " . Dumper($inner_row); |
|
175
|
3
|
100
|
|
|
|
11
|
if (my $joined = $inner_row->join( $self->[0]{outer_row} )) { |
|
176
|
1
|
50
|
|
|
|
5
|
if ($l->is_trace) { |
|
177
|
0
|
|
|
|
|
0
|
$l->trace("joined bindings: $inner_row â $self->[0]{outer_row}"); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
# warn "-> joined\n"; |
|
180
|
1
|
|
|
|
|
10
|
$self->[0]{inner_count}++; |
|
181
|
1
|
|
|
|
|
3
|
$self->[0]{count}++; |
|
182
|
1
|
50
|
|
|
|
7
|
if (my $d = $self->delegate) { |
|
183
|
0
|
|
|
|
|
0
|
$d->log_result( $self, $joined ); |
|
184
|
|
|
|
|
|
|
} |
|
185
|
1
|
|
|
|
|
4
|
return $joined; |
|
186
|
|
|
|
|
|
|
} else { |
|
187
|
2
|
|
|
|
|
54
|
$l->trace("failed to join bindings: $inner_row â $self->[0]{outer_row}"); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
1
|
|
|
|
|
27
|
$self->[0]{needs_new_outer} = 1; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item C<< close >> |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub close { |
|
200
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
201
|
1
|
50
|
|
|
|
5
|
unless ($self->state == $self->OPEN) { |
|
202
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open NestedLoop join"; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
1
|
|
|
|
|
5
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.join.nestedloop"); |
|
206
|
1
|
|
|
|
|
25
|
my $t0 = delete $self->[0]{start_time}; |
|
207
|
1
|
|
|
|
|
3
|
my $count = delete $self->[0]{count}; |
|
208
|
1
|
50
|
|
|
|
6
|
if (my $log = delete $self->[0]{logger}) { |
|
209
|
0
|
|
|
|
|
0
|
$l->debug("logging nestedloop join execution statistics"); |
|
210
|
0
|
|
|
|
|
0
|
my $elapsed = tv_interval ( $t0 ); |
|
211
|
0
|
0
|
|
|
|
0
|
if (my $sparql = $self->logging_keys->{sparql}) { |
|
212
|
0
|
0
|
|
|
|
0
|
if ($l->is_trace) { |
|
213
|
0
|
|
|
|
|
0
|
$l->trace("- SPARQL: $sparql"); |
|
214
|
0
|
|
|
|
|
0
|
$l->trace("- elapsed: $elapsed"); |
|
215
|
0
|
|
|
|
|
0
|
$l->trace("- count: $count"); |
|
216
|
|
|
|
|
|
|
} |
|
217
|
0
|
|
|
|
|
0
|
$log->push_key_value( 'execute_time-nestedloop', $sparql, $elapsed ); |
|
218
|
0
|
|
|
|
|
0
|
$log->push_key_value( 'cardinality-nestedloop', $sparql, $count ); |
|
219
|
|
|
|
|
|
|
} |
|
220
|
0
|
0
|
|
|
|
0
|
if (my $bf = $self->logging_keys->{bf}) { |
|
221
|
0
|
0
|
|
|
|
0
|
if ($l->is_trace) { |
|
222
|
0
|
|
|
|
|
0
|
$l->trace("- bf: $bf"); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
0
|
|
|
|
|
0
|
$log->push_key_value( 'cardinality-bf-nestedloop', $bf, $count ); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
} |
|
227
|
1
|
|
|
|
|
5
|
delete $self->[0]{inner}; |
|
228
|
1
|
|
|
|
|
14
|
delete $self->[0]{outer}; |
|
229
|
1
|
|
|
|
|
4
|
delete $self->[0]{inner_index}; |
|
230
|
1
|
|
|
|
|
2
|
delete $self->[0]{needs_new_outer}; |
|
231
|
1
|
|
|
|
|
2
|
delete $self->[0]{inner_count}; |
|
232
|
1
|
|
|
|
|
5
|
$self->lhs->close(); |
|
233
|
1
|
|
|
|
|
5
|
$self->rhs->close(); |
|
234
|
1
|
|
|
|
|
9
|
$self->SUPER::close(); |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item C<< plan_node_name >> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Returns the string name of this plan node, suitable for use in serialization. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub plan_node_name { |
|
244
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
245
|
0
|
0
|
|
|
|
|
my $jtype = $self->optional ? 'leftjoin' : 'join'; |
|
246
|
0
|
|
|
|
|
|
return "nestedloop-$jtype"; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item C<< graph ( $g ) >> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub graph { |
|
254
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
255
|
0
|
|
|
|
|
|
my $g = shift; |
|
256
|
0
|
0
|
|
|
|
|
my $jtype = $self->optional ? 'Left Join' : 'Join'; |
|
257
|
0
|
|
|
|
|
|
my ($l, $r) = map { $_->graph( $g ) } ($self->lhs, $self->rhs); |
|
|
0
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
$g->add_node( "$self", label => "$jtype (NL)" . $self->graph_labels ); |
|
259
|
0
|
|
|
|
|
|
$g->add_edge( "$self", $l ); |
|
260
|
0
|
|
|
|
|
|
$g->add_edge( "$self", $r ); |
|
261
|
0
|
|
|
|
|
|
return "$self"; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
package RDF::Query::Plan::Join::NestedLoop::Left; |
|
266
|
|
|
|
|
|
|
|
|
267
|
35
|
|
|
35
|
|
217
|
use strict; |
|
|
35
|
|
|
|
|
65
|
|
|
|
35
|
|
|
|
|
813
|
|
|
268
|
35
|
|
|
35
|
|
171
|
use warnings; |
|
|
35
|
|
|
|
|
84
|
|
|
|
35
|
|
|
|
|
1151
|
|
|
269
|
35
|
|
|
35
|
|
170
|
use base qw(RDF::Query::Plan::Join::NestedLoop); |
|
|
35
|
|
|
|
|
78
|
|
|
|
35
|
|
|
|
|
4282
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub new { |
|
272
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
273
|
0
|
|
|
|
|
|
my $lhs = shift; |
|
274
|
0
|
|
|
|
|
|
my $rhs = shift; |
|
275
|
0
|
|
|
|
|
|
return $class->SUPER::new( $lhs, $rhs, 1 ); |
|
276
|
|
|
|
|
|
|
} |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
1; |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
__END__ |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=back |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head1 AUTHOR |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=cut |