my $core_limit = $self->QueryParser->core_limit || 25000;
+ my $flat_where = $$flat_plan{where};
+ if ($flat_where eq '()') {
+ $flat_where = '';
+ } else {
+ $flat_where = "AND $flat_where";
+ }
+
my $sql = <<SQL;
SELECT $key AS id,
ARRAY_ACCUM(DISTINCT m.source) AS records,
$during
$between
$combined_dyn_filters
- AND $$flat_plan{where}
+ $flat_where
GROUP BY 1
ORDER BY 4 $desc NULLS LAST, 5 DESC NULLS LAST, 3 DESC
LIMIT $core_limit
}
- $struct = undef if (scalar(@{$struct->query_nodes}) == 0);
+ $struct = undef if (scalar(@{$struct->query_nodes}) == 0 && !$struct->top_plan);
return $struct if !wantarray;
return ($struct, $remainder);