Skip to content
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

Do not push down Sorts if it violates the sort requirements #11678

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jul 26, 2024

Which issue does this PR close?

Closes #11675
Closes #11493

Rationale for this change

See #11675 -- the PushDown sort optimizer was incorrectly pushing down sorts in certain cases

This change fixes a problem we were seeing in our tests downstream in influxdb iox

What changes are included in this PR?

  1. Don't push down sorts if doing so would violate the ordering requirements
  2. Add tests

Are these changes tested?

Yes, new unit tests are added

Are there any user-facing changes?

Bug fix

@@ -176,6 +176,7 @@ fn pushdown_requirement_to_children(
|| plan.as_any().is::<ProjectionExec>()
|| is_limit(plan)
|| plan.as_any().is::<HashJoinExec>()
|| pushdown_would_violate_requirements(parent_required, plan.as_ref())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it would be great to avoid these explicit checks for types over time in favor of functions on the ExecutionPlan nodes

let plan = sort_exec(sort_exprs_b, plan);

let expected_input = [
"SortExec: expr=[b@1 ASC], preserve_partitioning=[false]",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on main -- specifically the SortExec is pushed below the RequiredInputOrderingExec so its input is sorted on b which violates its input requirements that it is sorted on a

@alamb alamb marked this pull request as ready for review July 31, 2024 18:21
@alamb alamb requested a review from mustafasrepo July 31, 2024 18:21
@alamb alamb self-assigned this Jul 31, 2024
Copy link
Contributor

@mustafasrepo mustafasrepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!. thanks @alamb for this fix.

@alamb
Copy link
Contributor Author

alamb commented Aug 1, 2024

Thank you for the review @mustafasrepo

@alamb alamb merged commit 9dd2cfc into apache:main Aug 1, 2024
26 checks passed
@alamb alamb deleted the alamb/sort_pushdown_not branch August 1, 2024 10:35
wiedld pushed a commit to wiedld/arrow-datafusion that referenced this pull request Aug 8, 2024
…1678)

* Do not push down Sorts if it violates the sort requirements

* Test for pushing through orders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pushdown_sorts pushes a SortExec through a node in violation of its stated input ordering requirements
2 participants