-
Notifications
You must be signed in to change notification settings - Fork 303
feat: execute uncorrelated scalar subqueries first instead of rewriting to a join #1912
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
d82988d
b63d0c5
7484314
7959c70
85805db
b9ca7eb
0c9c715
e24f1ac
4c4f79e
878532f
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 |
|---|---|---|
|
|
@@ -20,8 +20,8 @@ mod common; | |
| mod supported { | ||
|
|
||
| use crate::common::{ | ||
| remote_context, remote_context_with_state, standalone_context, | ||
| standalone_context_with_state, | ||
| remote_context, remote_context_with_aqe, remote_context_with_state, | ||
| standalone_context, standalone_context_with_aqe, standalone_context_with_state, | ||
| }; | ||
| use ballista_core::config::BallistaConfig; | ||
|
|
||
|
|
@@ -77,6 +77,53 @@ mod supported { | |
| Ok(()) | ||
| } | ||
|
|
||
| // An uncorrelated scalar subquery is executed first and its value inlined | ||
| // into the outer plan (rather than decorrelated to a join), so the outer | ||
| // query distributes without a `ScalarSubqueryExec`. Runs with the adaptive | ||
| // (AQE) planner both off (default) and on. See #1910. | ||
| #[rstest] | ||
| #[case::standalone(standalone_context())] | ||
| #[case::remote(remote_context())] | ||
| #[case::standalone_aqe(standalone_context_with_aqe())] | ||
| #[case::remote_aqe(remote_context_with_aqe())] | ||
| #[tokio::test] | ||
| async fn should_execute_uncorrelated_scalar_subquery( | ||
| #[future(awt)] | ||
| #[case] | ||
| ctx: SessionContext, | ||
| test_data: String, | ||
| ) -> datafusion::error::Result<()> { | ||
| ctx.register_parquet( | ||
| "test", | ||
| &format!("{test_data}/alltypes_plain.parquet"), | ||
| Default::default(), | ||
| ) | ||
| .await?; | ||
|
|
||
| // The optimizer is left free to plan a physical scalar subquery (this is | ||
| // the DataFusion default; #1909 disabled it as a workaround, and #1910 | ||
| // reverted that). Set it explicitly so the test states what it covers. | ||
| ctx.sql( | ||
| "SET datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery = true", | ||
| ) | ||
| .await? | ||
| .collect() | ||
| .await?; | ||
|
|
||
| // Exactly the row holding the maximum id matches the inlined subquery | ||
| // value, so the count is 1. | ||
| let result = ctx | ||
| .sql("select count(*) as cnt from test where id = (select max(id) from test)") | ||
| .await? | ||
| .collect() | ||
| .await?; | ||
| let expected = ["+-----+", "| cnt |", "+-----+", "| 1 |", "+-----+"]; | ||
|
|
||
| assert_batches_eq!(expected, &result); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
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. can we also add check with AQE enabled, if it works, if not a jira issue or a test in "unsupported" file?
Member
Author
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. Added |
||
| // tests if client will collect statistics for | ||
| // collect/show operation | ||
| #[rstest] | ||
|
|
||
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.
can we explicitly disable
SET datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery = true, it would give additional context to the test.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.
Done — the test now runs
SET datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery = truebefore the query, so it states that it covers the case where the optimizer is free to plan a physical scalar subquery.