Skip to content

fix: optimize_projections failure after mark joins created by EXISTS OR EXISTS#21265

Open
buraksenn wants to merge 4 commits intoapache:mainfrom
buraksenn:fix-optimize-projections-fail
Open

fix: optimize_projections failure after mark joins created by EXISTS OR EXISTS#21265
buraksenn wants to merge 4 commits intoapache:mainfrom
buraksenn:fix-optimize-projections-fail

Conversation

@buraksenn
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Issue has details but main problem is mark columns from LeftMark joins leak into parent join schemas, causing optimize_projections optimizer to fail.

What changes are included in this PR?

Add a projection after embedded subquery decorrelation to strip mark columns, following the same pattern as scalar_subquery_to_join. I've seen this projection is merged in the final plan.

Are these changes tested?

Added test case for reported failure

Are there any user-facing changes?

No.

@github-actions github-actions bot added the optimizer Optimizer rules label Mar 30, 2026
Copy link
Copy Markdown
Contributor

@neilconway neilconway left a comment

Choose a reason for hiding this comment

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

Overall lgtm!

let result = optimizer.optimize(plan, &config, observe);
assert!(
result.is_ok(),
"Full optimizer should not fail with schema mismatch: {:?}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems a bit fragile to assume the assert fails with a schema mismatch, if it fails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a test for just make sure full optimizer runs successfully as a regression test instead of this. Moreover, I've modified the other test to use assert_optimized_plan_equal and check final plan.

// Verify no double projection — the projection we add to strip mark
// columns should be merged by optimize_projections, not left stacked.
assert!(
!plan_str.contains("Projection: a.a, a.b, a.c\n Projection:"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Testing for an expected plan via string containment seems a bit unfortunate. Can't we check for the plan shape we expect, e.g., via assert_optimized_plan_equal!?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a test for just make sure full optimizer runs successfully as a regression test instead of this. Moreover, I've modified the other test to use assert_optimized_plan_equal and check final plan.

replied above. Thanks it makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

optimize_projections fails after mark-join involved

2 participants