Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: improve null conditional simplification #16050

Open
maumar opened this issue Jun 12, 2019 · 3 comments
Open

Query: improve null conditional simplification #16050

maumar opened this issue Jun 12, 2019 · 3 comments

Comments

@maumar
Copy link
Contributor

maumar commented Jun 12, 2019

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""
@ajcvickers ajcvickers added this to the Backlog milestone Jun 14, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.0.0 Jun 14, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@bricelam bricelam modified the milestones: Backlog, 3.1.0 Aug 21, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0, Backlog Sep 4, 2019
@bricelam bricelam removed their assignment Nov 5, 2019
@maumar
Copy link
Contributor Author

maumar commented Nov 5, 2019

related to #18555

@maumar
Copy link
Contributor Author

maumar commented Jan 21, 2020

note that some Sqlite functions don't propagate nullability (e.g. all spatial functions returning bool)

@smitpatel
Copy link
Contributor

@maumar - This is actually not possible to do easily.

  • It is not valid for all providers
  • It depends if the function is actually getting translated to server for given provider
  • If the server side translation actually propagates nulls.

May be best place to do so would be post translation in SQL where we can may be remove Case test if it is null check if the result is somehow null propagating.

The cost may not worth the value it would provide. (User can always write without null check and cast result to nullable type)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants