Sub-optimal query with unnecessary not null
See original GitHub issue FROM "Animals" AS "a"
WHERE ((
SELECT "t"."Value"
FROM "text_attributes" AS "t"
WHERE ("a"."Id" = "t"."AnimalId") AND (("t"."Name" = 'placeOfBirth') AND "t"."Name" IS NOT NULL)
LIMIT 1) = 'seattle') AND (
SELECT "t"."Value"
FROM "text_attributes" AS "t"
WHERE ("a"."Id" = "t"."AnimalId") AND (("t"."Name" = 'placeOfBirth') AND "t"."Name" IS NOT NULL)
LIMIT 1) IS NOT NULL
As far as understand the not null checks aren’t required in the above scenario, both in the predicate on testing Name, but also the whole redundant duplicate SQL statement. I understand the issue with database nulls, and if we were doing “not equals” and we would need to consider null values too, but when we are testing equality against a constant this overzealous approach seems inefficient. Is the query builder too generalized, this seems like a low hanging fruit win for performance?
The above is the result of:
var results = ctx.Animals
.Where(a => a.TextAttributes.FirstOrDefault(x => x.Name == "placeOfBirth").Value == "seattle").ToList()
Where Animals has a List<TextAttribute> where TextAttribute has Name/Value string properties.
tl;dr - not null checks aren’t required
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Queries really slow due to null checks · Issue #17543
We encountered a SQL Server 100% CPU utilization issue on Alibaba Cloud with many IS NOT NULL in SQL generated by EF Core...
Read more >Query Optimization Techniques in SQL Server: Parameter ...
In this blog post we will walk you through one of the SQL Query Optimization Techniques in SQL Server - Parameter Sniffing.
Read more >46717: Unnecessary joins are not optimized away
My request is that the query optimizer should detect these situations, and construct an execution plan that does not use tables which do...
Read more >Tune applications and databases for performance in Azure ...
Applications that have suboptimal queries. Applications that have poorly tuned queries might not benefit from a higher compute size.
Read more >NULL complexities – Part 1
This way you can avoid unnecessary bugs and pitfalls. This article is the first in a series about NULL complexities.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
By mistake when removing type-bug.
@smitpatel Why did you remove
customer-reported
from this issue?