efcore
efcore copied to clipboard
Query: optimize CASE statement - remove conditions that are never hit
trafficstars
CASE
WHEN CAST(0 AS bit) THEN x
ELSE y
END
we can simply remove the WHEN block since it's condition is never met so the result would be just y
If all the WHEN blocks have been removed and there is no ELSE condition we can return NULL
@maumar - Is this already done?
Yes, this should already be optimized by https://github.com/dotnet/efcore/blob/ecd6104d7db803a976116a49d5855bce85634051/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs#L525-L532
EDIT: clauses whose test is NULL instead of FALSE are currently left in; I'm working on it.