Fix:22477 any all schema error#22915
Open
HairstonE wants to merge 3 commits into
Open
Conversation
alamb
reviewed
Jun 11, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
Thank you for this PR @HairstonE
| @@ -764,12 +780,12 @@ fn split_join_requirements( | |||
| // The mark column is synthetic (produced by the join itself), | |||
| // so discard it and route only to the left child. | |||
| let (left_indices, _mark) = indices.split_off(left_len); | |||
| (left_indices, RequiredIndices::new()) | |||
| (left_indices, RequiredIndices::new().append(&[0])) | |||
Contributor
There was a problem hiding this comment.
Looks like this code was added in #21265 from @buraksenn
@buraksenn do you have some time to help review this proposed change?
I think it would help if we can also document in comments why [0] is being appended
Contributor
There was a problem hiding this comment.
It seems like we only need to add the column in some cases -- why does this code add it unconditionally?
| @@ -1660,6 +1598,25 @@ logical_plan | |||
| 21)----------Projection: column1 AS v | |||
| 22)------------Values: (Int64(5)), (Int64(NULL)) | |||
|
|
|||
| # same-table `= ANY` / `<> ALL` must plan without | |||
Contributor
There was a problem hiding this comment.
without the code change in this PR, this test fails as expected
cargo test --profile=ci --test sqllogictests
...
Completed 475 test files in 9 seconds External error: 2 errors in file /Users/andrewlamb/Software/datafusion3/datafusion/sqllogictest/test_files/subquery.slt
1. query failed: DataFusion error: Optimizer rule 'optimize_projections' failed
caused by
Schema error: Schema contains duplicate unqualified field name mark
[SQL] select id from set_cmp_self where age = any(select age from set_cmp_self);
at /Users/andrewlamb/Software/datafusion3/datafusion/sqllogictest/test_files/subquery.slt:1606
2. query failed: DataFusion error: Optimizer rule 'optimize_projections' failed
caused by
Schema error: Schema contains duplicate unqualified field name mark
[SQL] select id from set_cmp_self where age <> all(select age from set_cmp_self);
at /Users/andrewlamb/Software/datafusion3/datafusion/sqllogictest/test_files/subquery.slt:1613
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
= ANY/<> ALLsubquery fails to plan:Schema contains duplicate unqualified field name mark#22477.Rationale for this change
= ANY (SELECT ...)and<> ALL (SELECT ...)decorrelate into stacked mark joins. The optimizer was pruning each mark join's right child to zero columns, which dropped its table reference. Without a qualifier, every mark column came out named justmark, resulting in the schema error.What changes are included in this PR?
Mark joins now keep one column from the right child instead of pruning it down to nothing. The right child holds onto its table reference, the mark now stays qualified.
Are these changes tested?
A unit test builds three stacked mark joins and checks the plan optimizes without the schema error. An sqllogictest runs
= ANYand<> ALLend-to-end against a small table.Are there any user-facing changes?
No.