xudong963 commented on code in PR #15822: URL: https://github.com/apache/datafusion/pull/15822#discussion_r2055810839
########## datafusion/physical-optimizer/src/enforce_sorting/replace_with_order_preserving_variants.rs: ########## @@ -137,6 +137,12 @@ fn plan_with_order_preserving_variants( return Ok(sort_input); } else if is_coalesce_partitions(&sort_input.plan) && is_spm_better { let child = &sort_input.children[0].plan; + let mut fetch = fetch; + // Also need to check if the coalesce node has a fetch + if let Some(coalesce_fetch) = sort_input.plan.fetch() { + // Get the min fetch between the `fetch` and the coalesce's fetch: + fetch = Some(coalesce_fetch.min(fetch.unwrap_or(usize::MAX))) Review Comment: ``` Sort: topk(10) CoalesceExec: fetch=5 .... ``` Though it looks a bit weird, we can't guarantee the case won't happen, such as some user has the custom physical optimizer which inserts a `fetch` to `CoalesceExec` or directly a `CoalesceExec` with a fetch. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org