Attean
view release on metacpan or search on metacpan
lib/Attean/API/QueryPlanner.pm view on Meta::CPAN
my @todo = (0 .. $#args); # initialize the todo list to all elements
my $next_symbol = 'a'; # when we start batching together sub-plans, we'll rename them with letters (e.g. elements 1, 2, and 4 might become 'a', and then 3, 5, and 'a' become 'b')
# until we've joined all the elements in todo and are left with a set of plans for the join of all elements
while (scalar(@todo) > 1) {
$k = ($k < scalar(@todo)) ? $k : scalar(@todo); # in case we're joining fewer than the batch size
foreach my $i (2 .. $k) { # we've already initialized plans for evaluating single elements; now consider plans for groups of elements (with group sizes 2, 3, ..., $k)
foreach my $s (subsets(\@todo, $i)) { # pick a subset of size $i of the elements that need to be planned
my $s_key = join('.', sort @$s);
$optPlan{$s_key} = [];
foreach my $o (subsets($s)) { # partition the subset s into two (o and not_o)
next if (scalar(@$o) == 0); # only consider proper, non-empty subsets
next if (scalar(@$o) == scalar(@$s)); # only consider proper, non-empty subsets
my $o_key = join('.', sort @$o);
my %o = map { $_ => 1 } @$o;
my $not_o_key = join('.', sort grep { not exists $o{$_} } @$s);
my $lhs = $optPlan{$o_key}; # get the plans for evaluating o
my $rhs = $optPlan{$not_o_key}; # get the plans for evaluating not_o
# compute and store all the possible ways to evaluate s (o â not_o)
push(@{ $optPlan{$s_key} }, $self->join_plans($model, $active_graphs, $default_graphs, $lhs, $rhs, 'inner'));
$optPlan{$s_key} = [$self->prune_plans($model, $interesting, $optPlan{$s_key})];
}
}
}
# find the minimum cost plan $p that computes the join over $k elements (the elements end up in @v)
my %min_plans;
foreach my $w (subsets(\@todo, $k)) {
my $w_key = join('.', sort @$w);
( run in 0.573 second using v1.01-cache-2.11-cpan-0a987023a57 )