Skip to content

Conversation

@jonathanc-n
Copy link
Contributor

@jonathanc-n jonathanc-n commented Sep 18, 2025

Which issue does this PR close?

Part of fix for #16488

Changes

During decorrelation of an exists subquery into a LeftMark join, the inner side still carries the literal from 'select 1'. The schema looks like this:

right = Projection: [Int64(1), x.b]

Projection Pushdown later drops the unused constant and rewrites the right child to just [x.b]. That “drop the first column” step shifts right-side column indices (from b@1 to b@0). During projection mapping it still assumes the old index (often doing “offset by left_width” and not accounting for the mark column), so when it re-indexes into the child it points at the wrong slot (which is what hit the error)

to fix this, I removed the projections when optimizer builds the join

Tests

The test is added to slt.

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) common Related to common crate physical-plan Changes to the physical-plan crate labels Sep 18, 2025
@jonathanc-n
Copy link
Contributor Author

jonathanc-n commented Sep 18, 2025

@comphead Decided to circle back to this after forgetting that this was reverted 😆 Are you able to run extended tests?

@comphead
Copy link
Contributor

I think we got something broken, you can still run extended tests on your fork, against your branch

@jonathanc-n jonathanc-n marked this pull request as draft September 18, 2025 21:43
@jonathanc-n jonathanc-n marked this pull request as ready for review September 19, 2025 01:37
@jonathanc-n
Copy link
Contributor Author

jonathanc-n commented Sep 19, 2025

@comphead It is passing on my end. I added the slt test that is the query that caused the error from the previous pull request.

@jonathanc-n
Copy link
Contributor Author

cc @comphead I believe this should be good for another look!

.partition_statistics(None)
.unwrap()
.total_byte_size,
Precision::Inexact(2097152)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this number be a reason of flaky test in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, i have copied this from the other previous join selection swapping testing and thos ehave been working fine.

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jonathanc-n I think the PR is good to go

@alamb alamb added this pull request to the merge queue Oct 1, 2025
Merged via the queue into apache:main with commit bd95a6b Oct 1, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants