Repository navigation
fix(postgresql): shape typed filters' null checks as EF Core does - #126
Merged
Merged
Conversation
#68 gave typed filters C#'s answer for null operands, in two shapes EF Core does not write for the same lambda: a computed operand was tested itself (lower("Name") IS NULL where EF Core tests "Name" IS NULL; coalesce(a, b) IS NULL where EF Core tests a IS NULL AND b IS NULL), and a negated ordering comparison over a nullable operand became a disjunction ("Maybe" <= 5 OR "Maybe" IS NULL) where EF Core writes CASE WHEN "Maybe" > 5 THEN FALSE ELSE TRUE END. The rows were the same, but a partial index is provably usable by a query only in the query's shape. Null checks are now written over the operand's nullable columns (every function the translator accepts is strict; a coalesce is null only when all its inputs are), and the negation is EF Core's CASE. Both shapes are new in 5.5.0, so no released filter changes. Verified with the change reverted: the parity sweep fails 300 rows (this removes the #118 block from waivers.txt) and three filter tests fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CaffeinatedCoder
force-pushed
the
fix/117-substring-captured-start
branch
from
October 20, 2026 06:35
9f23cec to
8f592d5
Compare
CaffeinatedCoder
force-pushed
the
fix/118-null-check-shapes
branch
from
October 20, 2026 06:35
c6b7c37 to
0f329ec
Compare
CaffeinatedCoder
changed the base branch from
fix/117-substring-captured-start
to
main
October 20, 2026 07:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #118
Stacked on #124 (#117) → #123 (#94) → #122 (#80) → #121 (#101); merge those first.
Problem
#68 gave typed filters C#'s answer for null operands, in two shapes EF Core does not write for the same lambda. The rows were the same, but a partial index is provably usable by EF Core's query only when its predicate has the query's shape, and the parity sweep had to waive 300 rows for it:
x.Name.ToLower() != "a"(string?)(lower("Name") <> 'a' OR lower("Name") IS NULL)(lower("Name") <> 'a' OR "Name" IS NULL)(x.Name ?? x.Kind) != "a"(coalesce(…) <> 'a' OR coalesce(…) IS NULL)(coalesce(…) <> 'a' OR ("Name" IS NULL AND "Kind" IS NULL))!(x.Maybe > 5)(int?)("Maybe" <= 5 OR "Maybe" IS NULL)CASE WHEN "Maybe" > 5 THEN FALSE ELSE TRUE ENDChange
NpgsqlLinqIndexTranslator:NullCheckwrites a null test over the operand's nullable columns: a strict function through its nullable inputs (ORed, ANDed forIS NOT NULL), a coalesce through all of its inputs (never null if one cannot be), a concatenation andHasValuenever. Equality compensation,== nulland!= nulluse it. A negated<,<=,>,>=over a nullable operand is EF Core'sCASE; over operands that cannot be null the complement stays.docs/upgrading.md(the Typed filters use SQL null semantics: != and ! on a nullable operand drop NULL rows, a captured null renders = NULL #68 entry) anddocs/postgresql-indexes.mdshow the new shapes.waivers.txt: the Typed filters: null checks over a computed operand and negated nullable comparisons are shaped unlike EF Core's #118 block is gone.PostgresCanonicalForm: the planner rewrites now reach inside aCASE, solength(x)::intin EF Core'sCASEmatches.Tests
NpgsqlTypedFilterTests: computed operands are null-checked through their columns; a negated nullable comparison is aCASE, alone and inside a pushed-down negation. The Typed filters use SQL null semantics: != and ! on a nullable operand drop NULL rows, a captured null renders = NULL #68 expectation for!(x.Maybe > 5)changes to theCASE.🤖 Generated with Claude Code