Fix:22477 any all schema error#22915
Conversation
alamb
left a comment
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])) | |||
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
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?
There was a problem hiding this comment.
I traced the error there and that change guaranteed the column would be non-empty. Typing that out makes me think I shouldn't assume they are empty? So I should only deal with the empty case.
| @@ -1660,6 +1598,25 @@ logical_plan | |||
| 21)----------Projection: column1 AS v | |||
| 22)------------Values: (Int64(5)), (Int64(NULL)) | |||
|
|
|||
| # same-table `= ANY` / `<> ALL` must plan without | |||
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
…er unconditional addition of that column
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.