Repository navigation
tests(postgresql): sweep typed filters and expressions against EF Core's ToQueryString - #121
Merged
Merged
Conversation
This was referenced 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
force-pushed
the
tests/101-translator-parity-sweep
branch
from
October 20, 2026 06:35
5549f45 to
bf545be
Compare
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 #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 ofParityRow(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:charpromoted toint, lifted comparisons,string.Concat), renders each through the declaration and the Npgsql differ, and throughToQueryString()(Wherefor filters,Selectfor expressions, withOrderByto 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 wherewaivers.txtswitches them on with a reason. This replaces the earlier comparisons' parenthesis stripping, which could not tell(a OR b) AND cfroma 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) orunchecked:(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 everyrule:/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.csonly gainspartial.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.
charcompares render the code ("Chr" = 65);HasValue,.Value,DateTime.Yearpass the declaration and fail atmigrations addCOALESCESubstringstart renders(1 + 1)(PostgreSQL folds it)text < timestamptz)NOT (a = 5)vsa <> 5,x = TRUEvsx,length(x)vslength(x)::inttext || integer/text || charvs EF Core's::texttextanycat; the live check proves the index serves EF Core's queryx.Email.Value): EF Core cannot translate themx.Str + 5ul: EF Core writes5.0(numeric) and answersx5.0where C# saysx5Tests
dotnet test), the sweep in about 10 s.substr,btrim(x)) 76. Typed expression indexes: string concatenation with a nullable operand differs from EF Core (COALESCE) #94 is proven in its own PR, where its waiver is removed.ulongrow before it was moved fromsame:tounchecked:.Canonical_form_keeps_the_treeandRules_apply_only_when_switched_onpin the comparison itself, including the regroupings it must not equate.🤖 Generated with Claude Code