alamb commented on code in PR #12174:
URL: https://github.com/apache/datafusion/pull/12174#discussion_r1740095136


##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -737,9 +738,30 @@ impl SortExec {
     /// This can reduce the memory pressure required by the sort
     /// operation since rows that are not going to be included
     /// can be dropped.
-    pub fn with_fetch(mut self, fetch: Option<usize>) -> Self {
-        self.fetch = fetch;
-        self
+    pub fn with_fetch(&self, fetch: Option<usize>) -> Self {
+        let mut cache = self.cache.clone();
+        if fetch.is_some() {
+            // When a theoretically unnecessary sort becomes a top-K (which

Review Comment:
   FWIW I think the comments help explain what is going on here well. Thank you



-- 
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