jayzhan211 commented on code in PR #15822: URL: https://github.com/apache/datafusion/pull/15822#discussion_r2057129418
########## 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(5) CoalesceExec: fetch=10 .... ``` but for this case, I think 5 would be reasonable, maybe we should check the outer one is always lesser than or equal -- 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