dotnet / dotnet/efcore

Apply early SqlExpression optimizations (e.g. x AND true -> x) in VisitChildren

Open
#34,556 4 comments 2 reactions 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

We have been starting to apply certain optimizations early, at creation in SqlExpressionFactory; for example, if someone calls `SqlExpressionFactory.MakeBinary` with `x AND true`, `x` is returned.

We should do the same optimizations in e.g. SqlBinaryExpression.VisitChildren(), and possibly even in SqlBinaryExpression.Update(). This will ensure that arbitrary visitors that happen to simplify an operand of a binary expression would transparently get the whole binary expression optimized away.

Ideally, we'd factor things in a way that the same simplification code is used from both SqlExpressionFactory and from SqlBinaryExpression itself (probably have the code on SqlBinaryExpression and call it from SqlExpressionFactory).

(note that this applies to other expression types, not just SqlBinaryExpression)

/cc @ranma42

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.