|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # RDF::Query::Plan::Sort  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # -----------------------------------------------------------------------------  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 RDF::Query::Plan::Sort - Executable query plan for Sorts.  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 VERSION  | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 This document describes RDF::Query::Plan::Sort version 2.918.  | 
| 
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::Sort;  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
142
 | 
 use strict;  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
851
 | 
    | 
| 
24
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
115
 | 
 use warnings;  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
46
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
806
 | 
    | 
| 
25
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
115
 | 
 use Scalar::Util qw(refaddr);  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
45
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1293
 | 
    | 
| 
26
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
123
 | 
 use base qw(RDF::Query::Plan);  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
37
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2433
 | 
    | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 ######################################################################  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our ($VERSION);  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 BEGIN {  | 
| 
32
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
6943
 | 
 	$VERSION	= '2.918';  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 ######################################################################  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< new ( $pattern, [ $expr1, $rev1 ], ... ) >>  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
43
 | 
12
 | 
 
 | 
 
 | 
  
12
  
 | 
  
1
  
 | 
18
 | 
 	my $class	= shift;  | 
| 
44
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
 	my $plan	= shift;  | 
| 
45
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
 	my @exprs	= @_;  | 
| 
46
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
 	foreach my $e (@exprs) {  | 
| 
47
 | 
12
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
58
 | 
 		$e->[1]	||= 0;  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
49
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
58
 | 
 	my $self	= $class->SUPER::new( $plan, \@exprs );  | 
| 
50
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
 	$self->[0]{referenced_variables}	= [ $plan->referenced_variables ];  | 
| 
51
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
 	return $self;  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< execute ( $execution_context ) >>  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub execute ($) {  | 
| 
59
 | 
12
 | 
 
 | 
 
 | 
  
12
  
 | 
  
1
  
 | 
17
 | 
 	my $self	= shift;  | 
| 
60
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
 	my $context	= shift;  | 
| 
61
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
 	$self->[0]{delegate}	= $context->delegate;  | 
| 
62
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
42
 | 
 	if ($self->state == $self->OPEN) {  | 
| 
63
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 		throw RDF::Query::Error::ExecutionError -text => "SORT plan can't be executed while already open";  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
65
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
 	my $plan	= $self->[1];  | 
| 
66
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
 	$plan->execute( $context );  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
68
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57
 | 
 	my $l		= Log::Log4perl->get_logger("rdf.query.plan.sort");  | 
| 
69
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1870
 | 
 	$l->trace("executing sort");  | 
| 
70
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
91
 | 
 	if ($plan->state == $self->OPEN) {  | 
| 
71
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
 		my $exprs	= $self->[2];  | 
| 
72
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
91
 | 
 		my @rows	= $plan->get_all;  | 
| 
73
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
45
 | 
 		if ($l->is_trace) {  | 
| 
74
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 			$l->trace("sorting result list:");  | 
| 
75
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 			$l->trace("- $_") foreach (@rows);  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		}  | 
| 
77
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
93
 | 
 		my $query	= $context->query;  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		  | 
| 
79
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
15508
 | 
 		use sort 'stable';  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14337
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
166
 | 
    | 
| 
80
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57
 | 
 		my @sorted	= sort { _cmp_rows( $context, $exprs, $a, $b ) } @rows;  | 
| 
 
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
69
 | 
    | 
| 
81
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
41
 | 
 		if ($l->is_trace) {  | 
| 
82
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 			$l->trace("sorted list:");  | 
| 
83
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 			$l->trace("- $_") foreach (@sorted);  | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		}  | 
| 
85
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
88
 | 
 		$self->[0]{rows}	= \@sorted;  | 
| 
86
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
 		$self->state( $self->OPEN );  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	} else {  | 
| 
88
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 		warn "could not execute plan in distinct";  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
90
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
 	$self;  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< next >>  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub next {  | 
| 
98
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
  
1
  
 | 
38
 | 
 	my $self	= shift;  | 
| 
99
 | 
32
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
71
 | 
 	unless ($self->state == $self->OPEN) {  | 
| 
100
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 		throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open SORT";  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
102
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
 	my $bindings	= shift(@{ $self->[0]{rows} });  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
72
 | 
    | 
| 
103
 | 
32
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
106
 | 
 	if (my $d = $self->delegate) {  | 
| 
104
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 		$d->log_result( $self, $bindings );  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
106
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
58
 | 
 	return $bindings;  | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
109
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< close >>  | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub close {  | 
| 
114
 | 
12
 | 
 
 | 
 
 | 
  
12
  
 | 
  
1
  
 | 
30
 | 
 	my $self	= shift;  | 
| 
115
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
31
 | 
 	unless ($self->state == $self->OPEN) {  | 
| 
116
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
 		throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open SORT";  | 
| 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
118
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
32
 | 
 	delete $self->[0]{rows};  | 
| 
119
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
50
 | 
 	$self->[1]->close();  | 
| 
120
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
45
 | 
 	$self->SUPER::close();  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _cmp_rows {  | 
| 
124
 | 
30
 | 
 
 | 
 
 | 
  
30
  
 | 
 
 | 
33
 | 
 	my $context	= shift;  | 
| 
125
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
35
 | 
 	my $exprs	= shift;  | 
| 
126
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22
 | 
 	my $a		= shift;  | 
| 
127
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
 	my $b		= shift;  | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
129
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
79
 | 
 	my $l		= Log::Log4perl->get_logger("rdf.query.plan.sort");  | 
| 
130
 | 
30
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
493
 | 
 	my $query	= $context->query || 'RDF::Query';  | 
| 
131
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
65
 | 
 	my $bridge	= $context->model;  | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
133
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
10333
 | 
 	no warnings 'numeric';  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
59
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1121
 | 
    | 
| 
134
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
133
 | 
 	no warnings 'uninitialized';  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16565
 | 
    | 
| 
135
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
52
 | 
 	foreach my $data (@$exprs) {  | 
| 
136
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
50
 | 
 		my ($expr, $rev)	= @$data;  | 
| 
137
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
100
 | 
 		my $a_val	= $query->var_or_expr_value( $a, $expr, $context );  | 
| 
138
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
125
 | 
 		my $b_val	= $query->var_or_expr_value( $b, $expr, $context );  | 
| 
139
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
74
 | 
 		local($RDF::Query::Node::Literal::LAZY_COMPARISONS)	= 1;  | 
| 
140
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
118
 | 
 		$l->trace("comparing $a_val <=> $b_val");  | 
| 
141
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
704
 | 
 		my $cmp		= $a_val <=> $b_val;  | 
| 
142
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
400
 | 
 		if ($cmp != 0) {  | 
| 
143
 | 
18
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
37
 | 
 			if ($rev) {  | 
| 
144
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
 				$cmp	*= -1;  | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			}  | 
| 
146
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
71
 | 
 			$l->trace("==> $cmp");  | 
| 
147
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
129
 | 
 			return $cmp;  | 
| 
148
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		} else {  | 
| 
149
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		}  | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
151
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
 	$l->trace("==> 0");  | 
| 
152
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
 	return 0;  | 
| 
153
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
154
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< pattern >>  | 
| 
156
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
157
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns the query plan that will be used to produce the data to be sorted.  | 
| 
158
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
159
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
160
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
161
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pattern {  | 
| 
162
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
  
1
  
 | 
11
 | 
 	my $self	= shift;  | 
| 
163
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
31
 | 
 	return $self->[1];  | 
| 
164
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
165
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
166
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< distinct >>  | 
| 
167
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
168
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns true if the pattern is guaranteed to return distinct results.  | 
| 
169
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
170
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
171
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
172
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub distinct {  | 
| 
173
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
  
1
  
 | 
12
 | 
 	my $self	= shift;  | 
| 
174
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
 	return $self->pattern->distinct;  | 
| 
175
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
176
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
177
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< ordered >>  | 
| 
178
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
179
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns true if the pattern is guaranteed to return ordered results.  | 
| 
180
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
181
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
182
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
183
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub ordered {  | 
| 
184
 | 
12
 | 
 
 | 
 
 | 
  
12
  
 | 
  
1
  
 | 
16
 | 
 	my $self	= shift;  | 
| 
185
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22
 | 
 	my $sort	= $self->[2];  | 
| 
186
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
187
 | 
12
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
25
 | 
 	return [ map { [ $_->[0], ($_->[1] ? 'DESC' : 'ASC') ] } @$sort ];  | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
96
 | 
    | 
| 
188
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
189
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
190
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< plan_node_name >>  | 
| 
191
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
192
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns the string name of this plan node, suitable for use in serialization.  | 
| 
193
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
194
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
195
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
196
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub plan_node_name {  | 
| 
197
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
 
 | 
 	return 'order';  | 
| 
198
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
199
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
200
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< plan_prototype >>  | 
| 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
202
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns a list of scalar identifiers for the type of the content (children)  | 
| 
203
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable  | 
| 
204
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 identifiers.  | 
| 
205
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
206
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
207
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub plan_prototype {  | 
| 
209
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
 
 | 
 	my $self	= shift;  | 
| 
210
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return qw(P *\wE);  | 
| 
211
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
212
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
213
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< plan_node_data >>  | 
| 
214
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
215
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns the data for this plan node that corresponds to the values described by  | 
| 
216
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 the signature returned by C<< plan_prototype >>.  | 
| 
217
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
218
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
219
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
220
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub plan_node_data {  | 
| 
221
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
 
 | 
 	my $self	= shift;  | 
| 
222
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $exprs	= $self->[2];  | 
| 
223
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return ($self->pattern, map { [ ($_->[1] == 0 ? 'asc' : 'desc'), $_->[0] ] } @$exprs);  | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
224
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
225
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
226
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< graph ( $g ) >>  | 
| 
227
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
228
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
229
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
230
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub graph {  | 
| 
231
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
 
 | 
 	my $self	= shift;  | 
| 
232
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $g		= shift;  | 
| 
233
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $c		= $self->pattern->graph( $g );  | 
| 
234
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $expr	= join(' ', map { $_->sse( {}, "" ) } @{ $self->[2] });  | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
235
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	$g->add_node( "$self", label => "Sort ($expr)" . $self->graph_labels );  | 
| 
236
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	$g->add_edge( "$self", $c );  | 
| 
237
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return "$self";  | 
| 
238
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
239
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
240
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item C<< explain >>  | 
| 
241
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
242
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns a string serialization of the plan appropriate for display on the  | 
| 
243
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 command line.  | 
| 
244
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
245
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
246
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
247
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub explain {  | 
| 
248
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
 
 | 
 	my $self	= shift;  | 
| 
249
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $s		= shift;  | 
| 
250
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $count	= shift;  | 
| 
251
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $indent	= $s x $count;  | 
| 
252
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $type	= $self->plan_node_name;  | 
| 
253
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $string	= sprintf("%s%s (0x%x)\n", $indent, $type, refaddr($self));  | 
| 
254
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	$string		.= "${indent}${s}sory by:\n";  | 
| 
255
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	my $exprs	= $self->[2];  | 
| 
256
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	foreach my $e (@$exprs) {  | 
| 
257
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		my $dir		= ($e->[1] == 0 ? 'asc  ' : 'desc ');  | 
| 
258
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		$string		.= "${indent}${s}${s}${dir}" . $e->[0] . "\n";  | 
| 
259
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
260
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	$string		.= $self->pattern->explain( $s, $count+1 );  | 
| 
261
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return $string;  | 
| 
262
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
263
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
264
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
265
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
266
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
267
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  | 
| 
268
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
269
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =back  | 
| 
270
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
271
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 AUTHOR  | 
| 
272
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
273
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  Gregory Todd Williams <gwilliams@cpan.org>  | 
| 
274
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
275
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  |