Skip to content

fix: preserve DISTINCT semantics in lateral decorrelation - #26060

Draft
mikamikasuki wants to merge 2 commits into
apache:mainfrom
mikamikasuki:fix/25808-lateral-distinct-decorrelation
Draft

mikamikasuki wants to merge 2 commits into
apache:mainfrom
mikamikasuki:fix/25808-lateral-distinct-decorrelation

Conversation

@mikamikasuki

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The query in #25808 returns the same (outer key, distinct value) row more than once. Moving a correlated filter above DISTINCT makes rows that differ only in the filtered inner column appear distinct, even though that column is not part of the visible result.

What changes are included in this PR?

For the supported INNER LATERAL shape, apply the correlated filter before the DISTINCT aggregation. A unique row number on each outer input row preserves bag semantics when the outer input itself contains duplicates. Unsupported plan shapes continue through the existing decorrelation path.

What is the testing strategy for this PR?

Added lateral_join.slt regression cases for the issue query, duplicate outer rows, and explicit JOIN LATERAL ... ON TRUE. The issue case fails on the base commit and passes with this change. The optimizer unit and integration tests, focused lateral join sqllogictests, the extended workspace test suite, strict optimizer clippy, formatting, and git diff --check passed.

Are there any user-facing changes?

The affected LATERAL DISTINCT query now returns the expected distinct rows.

@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong results: LATERAL with SELECT DISTINCT and a non-equality correlated filter returns duplicate rows

1 participant