-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: preserve required ordering in limit pushdown #24231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cd7d651
c48afbf
90126f4
7614aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,12 +62,11 @@ use datafusion_common::tree_node::{ | |
| }; | ||
| use datafusion_physical_plan::SortOrderPushdownResult; | ||
| use datafusion_physical_plan::buffer::BufferExec; | ||
| use datafusion_physical_plan::limit::{GlobalLimitExec, LocalLimitExec}; | ||
| use datafusion_physical_plan::limit::GlobalLimitExec; | ||
| use datafusion_physical_plan::sorts::sort::SortExec; | ||
| use datafusion_physical_plan::sorts::sort_preserving_merge::SortPreservingMergeExec; | ||
| use datafusion_physical_plan::{ExecutionPlan, ExecutionPlanProperties}; | ||
| use std::sync::Arc; | ||
|
|
||
| /// A PhysicalOptimizerRule that attempts to push down sort requirements to data sources. | ||
| /// | ||
| /// See module-level documentation for details. | ||
|
|
@@ -111,7 +110,12 @@ impl PhysicalOptimizerRule for PushdownSort { | |
| // Use LocalLimitExec (not Global) since input is multi-partition. | ||
| let inner = if let Some(fetch) = sort_child.fetch() { | ||
| inner.with_fetch(Some(fetch)).unwrap_or_else(|| { | ||
| Arc::new(LocalLimitExec::new(inner, fetch)) | ||
| let mut limit = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this remain a |
||
| GlobalLimitExec::new(inner, 0, Some(fetch)); | ||
| limit.set_required_ordering(Some( | ||
| sort_child.expr().clone(), | ||
| )); | ||
| Arc::new(limit) | ||
| }) | ||
| } else { | ||
| inner | ||
|
|
@@ -171,7 +175,9 @@ impl PhysicalOptimizerRule for PushdownSort { | |
| // wrapping with GlobalLimitExec. | ||
| if let Some(fetch) = sort_exec.fetch() { | ||
| let inner = inner.with_fetch(Some(fetch)).unwrap_or_else(|| { | ||
| Arc::new(GlobalLimitExec::new(inner, 0, Some(fetch))) | ||
| let mut limit = GlobalLimitExec::new(inner, 0, Some(fetch)); | ||
| limit.set_required_ordering(Some(sort_exec.expr().clone())); | ||
| Arc::new(limit) | ||
| }); | ||
| Ok(Transformed::yes(inner)) | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlobalRequirementsis public, and replacing theboolwithOption<LexOrdering>removes itsUnwindSafeandRefUnwindSafeauto-trait implementations according to cargo-semver-checks. Is this compatibility break a concern here, or should ordering state be carried without changing those public auto traits?