Query: allow providers to easily override null compensation and provide simpler translations instead

Open
#10,514 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp, sql

Research direction

Start by tracing EF Core's query translation and null-compensation logic, then compare how provider-specific translations could be selected. The issue provides no file, test, or entry point, so first identify the relevant query translation components and existing provider overrides. Done means providers can choose simpler or alternative null-equality translations without breaking LINQ semantics.

Written by the indexing model from the issue text.

Description

area-query

We have pretty heavy logic in query that allows translating two-value logic expressions into SQL, which does three-value logic natively. Many popular relational databases besides SQL Server implement alternative patterns to perform equality comparisons with in-memory semantics, e.g. x == y in a LINQ expression could be translated to

Translation Supported by
x is y SQLite
x <=> y MySQL and MariaDB
decode(x, y, 0, 1) = 0 DB2 and Oracle
EXISTS (SELECT x INTERSECT SELECT y) PostgreSQL, SQLite, SQL Server (as search condition)
EXISTS (VALUES(x) INTERSECT VALUES(y)) DB2, PostgreSQL, SQL Server
x IS NOT DISTINCT FROM y ANSI SQL:2003, PostgreSQL (apparently not sargable)

This article presents an excellent survey of all the alternatives: http://modern-sql.com/feature/is-distinct-from.

For cases in which we know if either x or y are non-nullable, we can probably produce a more concise translation, but in more complex cases, the options above could lead to better SQL, even for SQL Server.

In any case, it should be possible for a provider to pick the best translation.

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.