Left join with a WHERE
condition falsely marks columns as non-nullable
#3539
Labels
WHERE
condition falsely marks columns as non-nullable
#3539
Bug Description
When there's a
WHERE
condition in a left join query, non-null columns from the right table is always marked as non-nullable (in left joins, they should always be nullable).Minimal Reproduction
The schema:
With a simple left join, everything works fine:
But things goes awry when you introduce a
WHERE
condition:The issue doesn't occur if you use
AND
instead:The full reproduction repo can be found here: https://github.com/musjj/sqlx-join-bug
Execution plans of all relevant queries:
EXPLAIN (VERBOSE, FORMAT JSON) SELECT foo.id, bar.foo_id FROM foo LEFT JOIN bar ON bar.foo_id = foo.id;
EXPLAIN (VERBOSE, FORMAT JSON) SELECT foo.id, bar.foo_id FROM foo LEFT JOIN bar ON bar.foo_id = foo.id WHERE foo.id = 123;
EXPLAIN (VERBOSE, FORMAT JSON) SELECT foo.id, bar.foo_id FROM foo LEFT JOIN bar ON bar.foo_id = foo.id AND foo.id = 123;
Info
0.8.2
[ "postgres", "runtime-tokio", "tls-native-tls" ]
rustc --version
:rustc 1.83.0-nightly (363ae4188 2024-09-24)
The text was updated successfully, but these errors were encountered: