TinyMurky commented on code in PR #25158:
URL: https://github.com/apache/datafusion/pull/25158#discussion_r3995637305


##########
datafusion/physical-plan/src/aggregates/single_stream.rs:
##########
@@ -449,6 +454,27 @@ impl SingleHashAggregateStream {
                     return Self::break_with_err(e);
                 }
 
+                // Soft limit optimization:
+                //
+                // Stop reading input once the in-memory table contains enough 
distinct
+                // groups to satisfy the soft limit.
+                //
+                // When a limit is present, AggregateExec routes only 
unordered,
+                // unfiltered DISTINCT aggregates to this stream.
+                //
+                // With no aggregate expressions, additional input can only 
match existing
+                // groups or add new ones; it cannot change any existing 
group's output.
+                // Since there is no ordering requirement and we already have 
enough
+                // distinct groups, we can finish reading as if the input were 
exhausted.
+                //
+                // Reuse the input-exhausted transition to merge any existing 
spills
+                // before producing output. The downstream limit operator 
enforces
+                // the exact output row count.
+                if self.hit_soft_group_limit(&hash_table) {

Review Comment:
   I added the skip of spilling.
   
   
https://github.com/apache/datafusion/blob/e92aee75ea5bf774d0dbd6be648849a124c7797e/datafusion/physical-plan/src/aggregates/single_stream.rs#L485-L498



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to