-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Gate new ScalarSubqueryExec node behind session property #22530
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
Open
LiaCastaneda
wants to merge
4
commits into
apache:main
Choose a base branch
from
LiaCastaneda:scalar-subquery-physical-exec-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8416100
Gate new ScalarSubqueryExec node behind session property
LiaCastaneda ec13296
Fix expected results in information_schema.slt
LiaCastaneda ddc20cd
Add test cases in subquery.slt with the flag set to false
LiaCastaneda d1b9dad
test tpch with flag turned off
LiaCastaneda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2091,6 +2091,95 @@ SELECT (SELECT v FROM (SELECT 1 AS v UNION ALL SELECT 2) AS t ORDER BY v LIMIT 1 | |
| ---- | ||
| 1 | ||
|
|
||
| ############# | ||
| ## End-to-end correctness coverage for the flag-off path. | ||
| ## When `datafusion.optimizer.physical_uncorrelated_scalar_subquery` is false, | ||
| ## uncorrelated scalar subqueries are rewritten to left joins by | ||
| ## `ScalarSubqueryToJoin` instead of executed by `ScalarSubqueryExec`. This | ||
| ## restores pre-PR-21240 behavior, which has three known shortcomings the | ||
|
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. I think you only list two known shortcomings? |
||
| ## physical-execution path was built to fix: multi-row subqueries silently | ||
| ## return wrong results, and uncorrelated scalar subqueries do not work in | ||
| ## ORDER BY / JOIN ON / aggregate-function arguments. Those cases are | ||
| ## intentionally not covered here; the queries below are the ones where both | ||
| ## paths agree. | ||
|
Comment on lines
+2098
to
+2104
Contributor
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. These were known limitations/bugs #21240 fixed |
||
| ############# | ||
|
|
||
| statement ok | ||
| set datafusion.optimizer.physical_uncorrelated_scalar_subquery = false; | ||
|
|
||
| # Scalar subquery returning exactly one row → success | ||
| query I | ||
| SELECT (SELECT v FROM sq_values LIMIT 1); | ||
| ---- | ||
| 1 | ||
|
|
||
| # Scalar subquery returning exactly one row in WHERE → success | ||
| query I rowsort | ||
| SELECT x FROM sq_main WHERE x > (SELECT v FROM sq_values LIMIT 1); | ||
| ---- | ||
| 10 | ||
| 20 | ||
|
|
||
| # Scalar subquery returning zero rows → NULL | ||
| query I | ||
| SELECT (SELECT v FROM sq_empty); | ||
| ---- | ||
| NULL | ||
|
|
||
| # Scalar subquery returning zero rows in arithmetic → NULL propagation | ||
| query I | ||
| SELECT x + (SELECT v FROM sq_empty) FROM sq_main; | ||
| ---- | ||
| NULL | ||
| NULL | ||
|
|
||
| # Scalar subquery returning zero rows in WHERE comparison → no matching rows | ||
| query I | ||
| SELECT x FROM sq_main WHERE x > (SELECT v FROM sq_empty); | ||
| ---- | ||
|
|
||
| # Aggregated subquery always returns one row, even on empty input → success | ||
| query I | ||
| SELECT (SELECT count(*) FROM sq_empty); | ||
| ---- | ||
| 0 | ||
|
|
||
| # Aggregated subquery on multi-row table → success | ||
| query I | ||
| SELECT (SELECT max(v) FROM sq_values); | ||
| ---- | ||
| 3 | ||
|
|
||
| # HAVING clause with uncorrelated scalar subquery | ||
| query II rowsort | ||
| SELECT x, count(*) AS cnt FROM sq_main GROUP BY x | ||
| HAVING count(*) > (SELECT min(v) FROM sq_values); | ||
| ---- | ||
|
|
||
| # CASE WHEN with uncorrelated scalar subquery as condition | ||
| query T rowsort | ||
| SELECT CASE WHEN x > (SELECT min(v) FROM sq_values) | ||
| THEN 'big' ELSE 'small' END AS label | ||
| FROM sq_main; | ||
| ---- | ||
| big | ||
| big | ||
|
|
||
| # Doubly-nested constant subquery | ||
| query I | ||
| SELECT (SELECT (SELECT 42)); | ||
| ---- | ||
| 42 | ||
|
|
||
| # NULL comparison semantics through subquery boundary | ||
| query B | ||
| SELECT 1 = (SELECT CAST(NULL AS INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| statement ok | ||
| RESET datafusion.optimizer.physical_uncorrelated_scalar_subquery; | ||
|
|
||
| statement count 0 | ||
| DROP TABLE sq_values; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The other similar config options use the phrasing
enable_...; we should probably adopt that for consistency.physical_uncorrelated_scalar_subqueryis also a mouthful, although I can't immediately think of a more concise name that is also accurate.