You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement null semantics properly for PG-specific operations #1142
We have all kinds of PostgreSQL-specific operations, but haven't really attempted to implement correct null semantics for them.
In some cases we simply ignore null semantics and translate as-is (e.g. array-related methods in NpgsqlSqlTranslatingExpressionVisitor.VisitArrayMethodCall)
In other cases we implement null semantics but don't allow opt-out with the relational nulls context option (e.g. the Contains to ANY translation in NpgsqlArrayMethodTranslator.Translator).
Null semantics is currently being refactored on the EF Core side, with provider extensibility in mind. When that's done we should do a pass on our side and see what to do.
Specific cases:
GREATEST/LEAST: need special handling since they don't propagate nulls, but return null if only nulls are present. WIP in https://github.com/roji/efcore.pg/tree/GreatestLeast, but blocking on lack of way to set _nullable in VisitSqlFunction. This is necessary even thought Math.{Min,Max} accept only non-nullable int, because we propagate nulls through optional navigations (C.NullNavigation.IntProperty).
ComplexNavigationsQueryTestBase.Accessing_optional_property_inside_result_operator_subquery. Our null semantics is probably wrong there.
WHERE COALESCE(i.id= ANY(ARRAY[10, 22, 33, 44, 55]), FALSE)
Now, this is terrible. This is beyond terrible. My queries which regularly take 0.010 seconds to execute, are taking 15 seconds. The reason is that PostgreSQL is not going to be able to optimize a COALESCE(i.id = ANY($1)).
As solution I have had to rollback.
If this is the wrong issue to notify this, please let me know. I just tracked down the issue locally and found a reference to this issue on it. Thank you.
I have tried with 3.1.1 and 3.1.1.1, the issue seems to persist (ensured by checking the Npgsql.EntityFrameworkCore.PostgreSQL.dll version on /Debug folder).
Reopening to take another look for when relational semantics is activated. As @maumar pointed out, the current code returns nullable=false in some incorrect cases where it should be true.
Activity
KinoshitaShimizu commentedon Feb 3, 2020
I'd like to comment, I am having a terrible issue related to this.
I have the following snippet of C# code:
Which generates the following WHERE SQL:
Now, this is terrible. This is beyond terrible. My queries which regularly take 0.010 seconds to execute, are taking 15 seconds. The reason is that PostgreSQL is not going to be able to optimize a COALESCE(i.id = ANY($1)).
As solution I have had to rollback.
If this is the wrong issue to notify this, please let me know. I just tracked down the issue locally and found a reference to this issue on it. Thank you.
roji commentedon Feb 3, 2020
@KinoshitaShimizu have you tried 3.1.1 which was released a couple days ago? Because that should be gone there (see #1152).
KinoshitaShimizu commentedon Feb 3, 2020
@roji Thank you very much for your reply.
I have tried with 3.1.1 and 3.1.1.1, the issue seems to persist (ensured by checking the Npgsql.EntityFrameworkCore.PostgreSQL.dll version on /Debug folder).
roji commentedon Feb 3, 2020
Can you please open a new issue for this, with the coffee sample? I'll look into it.
KinoshitaShimizu commentedon Feb 3, 2020
@roji Created the issue #1254.
I do not know what the "coffee sample" is, although I looked it up. Made a simple project to reproduce, logger set to output generated query.
If I should correct, please let me know.
Thank you very much for your hard work.
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
Implement nullability processor and general expression refactor
roji commentedon Jun 7, 2020
Reopening to take another look for when relational semantics is activated. As @maumar pointed out, the current code returns nullable=false in some incorrect cases where it should be true.
roji commentedon Aug 29, 2020
Closing for now, will investigate based on user reports.