# make a new $rs selecting only the PKs (that's all we really need for the subq)
delete $attrs->{$_} for qw/select as collapse _related_results_construction/;
$attrs->{columns} = [ map { "$attrs->{alias}.$_" } @$idcols ];
- $attrs->{group_by} = \ ''; # FIXME - this is an evil hack, it causes the optimiser to kick in and throw away the LEFT joins
+
+ # this will be consumed by the pruner waaaaay down the stack
+ $attrs->{_force_prune_multiplying_joins} = 1;
+
my $subrs = (ref $self)->new($rsrc, $attrs);
if (@$idcols == 1) {
#
sub _prune_unused_joins {
my $self = shift;
- my ($from, $select, $where, $attrs, $ignore_multiplication) = @_;
+ my ($from, $select, $where, $attrs) = @_;
return $from unless $self->_use_join_optimizer;
# a grouped set will not be affected by amount of rows. Thus any
# {multiplying} joins can go
delete $aliastypes->{multiplying}
- if $ignore_multiplication or $attrs->{group_by};
+ if $attrs->{_force_prune_multiplying_joins} or $attrs->{group_by};
my @newfrom = $from->[0]; # FROM head is always present
local $self->{_use_join_optimizer} = 1;
# throw away multijoins since we def. do not care about those inside the subquery
- my $inner_from = $self->_prune_unused_joins ($from, $inner_select, $where, $inner_attrs, 'ignore_multiplication');
+ my $inner_from = $self->_prune_unused_joins ($from, $inner_select, $where, {
+ %$inner_attrs, _force_prune_multiplying_joins => 1
+ });
my $inner_aliastypes =
$self->_resolve_aliastypes_from_select_args( $inner_from, $inner_select, $where, $inner_attrs );