Skip to content

fix(compiler): propagate outer join nullability in isTableRequired - #4720

Open
amstedy wants to merge 1 commit into
sqlc-dev:mainfrom
amstedy:fix/compiler-join-nullability
Open

amstedy wants to merge 1 commit into
sqlc-dev:mainfrom
amstedy:fix/compiler-join-nullability

Conversation

@amstedy

@amstedy amstedy commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #4690

Cause

In internal/compiler/output_columns.go, isTableRequired(n, col, prior) discarded the inherited prior nullability when recursing into *ast.JoinExpr and passed tableRequired unconditionally for preserved join sides. As a result, any join nested under a nullable side of an outer join (e.g., a LEFT JOIN b RIGHT JOIN c, a INNER JOIN b FULL JOIN c, or a LEFT JOIN (b INNER JOIN c)) reset tableOptional back to tableRequired and generated non-nullable column types for tables that can be NULL.

Fix

Propagate prior instead of hardcoded tableRequired for preserved sides of ast.JoinExpr (JoinTypeLeft, JoinTypeRight, and JoinTypeInner/JoinTypeCross/JoinTypeComma), while keeping tableOptional for null-producing sides.

Tests

  • Added internal/endtoend/testdata/join_nested_outer/ covering chained and parenthesized outer/inner/cross join combinations across PostgreSQL (pgx/v5), MySQL, and SQLite.
  • Verified with go test -race ./internal/compiler/... and go test ./internal/endtoend -run 'TestReplay/base.join_nested_outer|TestFormat/join_nested_outer'.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A RIGHT or FULL JOIN doesn't make the joins to its left nullable

1 participant