Skip to content

sql: fix wrong results for JOIN ... USING (col) AS t with RIGHT/FULL joins#36606

Open
ggevay wants to merge 1 commit into
MaterializeInc:mainfrom
ggevay:fix-plan_using_constraint-alias
Open

sql: fix wrong results for JOIN ... USING (col) AS t with RIGHT/FULL joins#36606
ggevay wants to merge 1 commit into
MaterializeInc:mainfrom
ggevay:fix-plan_using_constraint-alias

Conversation

@ggevay
Copy link
Copy Markdown
Contributor

@ggevay ggevay commented May 18, 2026

Fixes SQL-279

@ggevay ggevay requested a review from a team as a code owner May 18, 2026 14:00
@ggevay ggevay added the A-ADAPTER Topics related to the ADAPTER layer label May 18, 2026
…joins

In plan_using_constraint, when an AS alias is present on a USING clause,
the qualified reference t.col was unconditionally bound to the LHS
column's value. For RIGHT and FULL OUTER joins, rows with no LHS match
have a NULL LHS, so t.col returned NULL instead of the joined value.

Choose the source of the aliased column based on JoinKind, matching the
choice already made for the unaliased join output column a few lines
above:

  - INNER / LEFT  -> lhs
  - RIGHT         -> rhs
  - FULL OUTER    -> COALESCE(lhs, rhs)

Fixes a regression introduced in MaterializeInc#18793.

Co-authored-by: Junie <junie@jetbrains.com>
@ggevay ggevay force-pushed the fix-plan_using_constraint-alias branch from 07adf7c to 82fd9e2 Compare May 18, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ADAPTER Topics related to the ADAPTER layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant