Skip to content

Query: improve null conditional simplification #16050

@maumar

Description

@maumar

In NullCheckRemovingExpressionVisitor we have logic to simplify expressions like:

a == null ? null : a.Foo

into simple property access when on relational (null propagation is automatic)
However for some complex cases we miss the optimization and produce overly complicated.

e.g.:

ctx.Points.Select(
                    e => new
                    {
                        e.Id,
                        Distance = e.Point == null ? (double?)null : new Point(0, 1).Distance(e.Point)
                    })

produces:

SELECT ""p"".""Id"", CASE
    WHEN ""p"".""Point"" IS NULL THEN NULL
    ELSE Distance(GeomFromText('POINT (0 1)'), ""p"".""Point"")
END AS ""Distance""
FROM ""PointEntity"" AS ""p""

rather than expected:

SELECT ""e"".""Id"", Distance(GeomFromText('POINT (0 1)'), ""e"".""Point"") AS ""Distance""
FROM ""PointEntity"" AS ""e""

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions