You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/07/26 19:24:28 UTC
[PR] Do not push down Sorts if it violates the sort requirements [datafusion]
alamb opened a new pull request, #11678:
URL: https://github.com/apache/datafusion/pull/11678
(Draft as I need to write tests for this)
## Which issue does this PR close?
Closes https://github.com/apache/datafusion/issues/11675
## Rationale for this change
See https://github.com/apache/datafusion/issues/11675 -- the PushDown sort optimizer was incorrectly pushing down sorts
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
## Are these changes tested?
TBD
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Do not push down Sorts if it violates the sort requirements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11678:
URL: https://github.com/apache/datafusion/pull/11678#issuecomment-2262710828
Thank you for the review @mustafasrepo
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Do not push down Sorts if it violates the sort requirements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11678:
URL: https://github.com/apache/datafusion/pull/11678#discussion_r1693499951
##########
datafusion/core/src/physical_optimizer/sort_pushdown.rs:
##########
@@ -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())
Review Comment:
In general it would be great to avoid these explicit checks for types over time in favor of functions on the ExecutionPlan nodes
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Do not push down Sorts if it violates the sort requirements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #11678:
URL: https://github.com/apache/datafusion/pull/11678
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Do not push down Sorts if it violates the sort requirements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11678:
URL: https://github.com/apache/datafusion/pull/11678#discussion_r1698854048
##########
datafusion/core/src/physical_optimizer/enforce_sorting.rs:
##########
@@ -2346,4 +2347,67 @@ mod tests {
assert_optimized!(expected_input, expected_no_change, physical_plan, true);
Ok(())
}
+
+ #[tokio::test]
+ async fn test_push_with_required_input_ordering_prohibited() -> Result<()> {
+ // SortExec: expr=[b] <-- can't push this down
+ // RequiredInputOrder expr=[a] <-- this requires input sorted by a, and preserves the input order
+ // SortExec: expr=[a]
+ // MemoryExec
+ let schema = create_test_schema3()?;
+ let sort_exprs_a = vec![sort_expr("a", &schema)];
+ let sort_exprs_b = vec![sort_expr("b", &schema)];
+ let plan = memory_exec(&schema);
+ let plan = sort_exec(sort_exprs_a.clone(), plan);
+ let plan = RequirementsTestExec::new(plan)
+ .with_required_input_ordering(sort_exprs_a)
+ .with_maintains_input_order(true)
+ .into_arc();
+ let plan = sort_exec(sort_exprs_b, plan);
+
+ let expected_input = [
+ "SortExec: expr=[b@1 ASC], preserve_partitioning=[false]",
Review Comment:
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`
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org