Skip to content

tests(postgresql): sweep typed filters and expressions against EF Core's ToQueryString - #121

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
tests/101-translator-parity-sweep
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
tests/101-translator-parity-sweep

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #101

Problem

A typed filter or typed expression index is useful only if it renders the way EF Core's query translation renders the same lambda: PostgreSQL uses an expression index only for a query whose expression matches it, and a filter with other null semantics indexes other rows. #68, #70, #72 and #94 were each found by hand, one lambda at a time, and the existing ToQueryString() comparisons covered hand-picked lambdas.

Change

  • NpgsqlLinqIndexTranslator: the accepted constructs are now data its dispatch reads: StringMethods (by exact overload), ValueMembers, ValueOperators, ComparisonOperators, LogicalOperators, LiteralTypes. No rendering changes; the whole suite passes unchanged.
  • TranslatorParity/ParityCatalogue: derives the catalogue from those tables, crossed with every operand shape of ParityRow (non-nullable, nullable, ToJson() member of each store type, converter member) and each kind of right-hand side (constant on either side, captured value, captured null, literal null, another column), plus negation, boolean structure, and constructs EF Core translates that the translator does not claim (HasValue, StartsWith, arithmetic, …), which must be refused at the declaration. A new table entry is swept with no edit; a new operator or literal type without a C# spelling or sample fails loudly.
  • ParitySweep: compiles the rows with Roslyn (the compiler's real shapes: char promoted to int, lifted comparisons, string.Concat), renders each through the declaration and the Npgsql differ, and through ToQueryString() (Where for filters, Select for expressions, with OrderBy to tell server translation from client evaluation; captured values inlined as constants on both sides).
  • PostgresCanonicalForm: parses both sides with PostgreSQL's operator precedence and compares trees. Aliases, parentheses and cast spellings never count; a regrouping always does. Three planner rewrites (negator, boolean-equality, integer-length) apply only where waivers.txt switches them on with a reason. This replaces the earlier comparisons' parenthesis stripping, which could not tell (a OR b) AND c from a OR b AND c.
  • waivers.txt: every disagreement is listed under a block with its reason: rule: (a planner rewrite), same: (renders differently, answers alike; checked live) or unchecked: (cannot be compared, or an open defect with its issue). A listed row the sweep no longer finds fails it, so the file shrinks as the stacked fixes land.
  • PostgresIntegrationTests.Translator_parity_answers_alike_on_postgres: runs every agreeing and every rule:/same: row on PostgreSQL 18 over seeded rows where each nullable operand is both null and set, compares selected rows (filters) and values (expressions), and for each expression a waiver calls equivalent builds an index on the package's SQL and checks EF Core's query uses it. PostgresIntegrationTests.cs only gains partial.
  • CLAUDE.md: a paragraph on the sweep under Quality controls.

No changelog line: tests and an internal refactoring with no observable effect.

What the sweep found

3,873 rows: 1,253 agree, 1,339 are refused at the declaration, 1,281 disagree.

Finding Rows Disposition
char compares render the code ("Chr" = 65); HasValue, .Value, DateTime.Year pass the declaration and fail at migrations add 310 #80 (scope widened to members of scalar types), stacked PR
Concatenation with a nullable operand lacks COALESCE 91 #94, stacked PR
Null checks over computed operands and negated nullable comparisons shaped unlike EF Core's (same rows) 260 new #118, stacked PR
A captured Substring start renders (1 + 1) (PostgreSQL folds it) 24 new #117, stacked PR
A date/time JSON member compared with a column in a filter fails at apply (text < timestamptz) 24 new #119, in the differ's filter resolution, stacked PR #128
NOT (a = 5) vs a <> 5, x = TRUE vs x, length(x) vs length(x)::int 418 waived as planner rewrites
text || integer / text || char vs EF Core's ::text 31 waived: PostgreSQL inlines textanycat; the live check proves the index serves EF Core's query
Converter members (x.Email.Value): EF Core cannot translate them 121 waived
Date/time JSON member as an expression (text fallback, 5.4.0) 1 waived
x.Str + 5ul: EF Core writes 5.0 (numeric) and answers x5.0 where C# says x5 1 waived; found by the live check, which the canonical comparison alone had called equivalent

Tests

🤖 Generated with Claude Code

@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added tests Adds or changes tests only (harnesses, parity suites); no library code package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/indexes Complex-property, composite, unique and filtered indexes area/expression-indexes Expression, typed LINQ and JSON member indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints labels Oct 20, 2026
…e's ToQueryString (#101)

Each divergence of the typed translator from EF Core's query translation
(#68, #70, #72, #94) was found by hand, one lambda at a time. The sweep
compares every construct NpgsqlLinqIndexTranslator accepts, crossed with
every operand shape (non-nullable, nullable, ToJson() member, converter
member), with what Npgsql renders for the same lambda: Where for filters,
Select for expressions.

The translator's accepted constructs are now data (StringMethods,
ValueMembers, the operator sets, LiteralTypes) that its dispatch reads,
so the catalogue is derived from them and a construct added later is
swept with no edit. Rows are C# compiled by Roslyn, so the lambdas have
the compiler's shapes (char promoted to int, lifted comparisons,
string.Concat). Both renderings are parsed with PostgreSQL's precedence
and compared as trees: aliases, parentheses and cast spellings never
count, a regrouping always does. Planner rewrites (negate_clause,
simplify_boolean_equality, the cast of length() to integer) apply only
where waivers.txt switches them on with a reason.

3,873 rows. Every disagreement is fixed or listed in waivers.txt under a
block with its reason, a listed row the sweep no longer finds fails it,
and every construct in the translator's tables must reach a comparison.
Open defects are listed under their issues: #80, #94, #117, #118, #119.

PostgresIntegrationTests runs the same rows on PostgreSQL 18 over seeded
rows where every nullable operand is both null and set, and for each
expression a waiver calls equivalent builds an index on the package's
SQL and checks EF Core's query uses it. That found a ulong concatenation
EF Core writes as 5.0, which answers differently from C# and the package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder
CaffeinatedCoder merged commit 602c248 into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the tests/101-translator-parity-sweep branch October 20, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/expression-indexes Expression, typed LINQ and JSON member indexes area/indexes Complex-property, composite, unique and filtered indexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL tests Adds or changes tests only (harnesses, parity suites); no library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: sweep typed filters and typed expression indexes against EF Core's ToQueryString

1 participant