diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseAggregateNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseAggregateNode.cs index bc1a930d..89f190a9 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseAggregateNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseAggregateNode.cs @@ -387,7 +387,11 @@ protected override RowCountEstimate EstimateRowsOutInternal(NodeCompilationConte if (GroupBy.Count == 0) return RowCountEstimateDefiniteRange.ExactlyOne; - var rows = Source.EstimateRowsOut(context).Value * 4 / 10; + var sourceRows = Source.EstimateRowsOut(context).Value; + var rows = sourceRows * 4 / 10; + + if (rows < 0) + rows = sourceRows / 10 * 4; return new RowCountEstimate(rows); }