Skip to content

Query: optimize nested CASE blocks #18774

@maumar

Description

@maumar

Some nested CASE blocks, e.g.:

CASE 
    WHEN (condition1)
    THEN 
    CASE
        WHEN (condition2)
        THEN result1
        ELSE result2 
    END
    ELSE result2
END

can be optimized to:

CASE
    WHEN condition1 AND condition2
    THEN result1
    ELSE result2
END

In practice we get those kinds of chained CASE blocks in the following scenarios:

context.Set<Product>().OrderBy(p => p.UnitsInStock > 10 ? p.ProductID > 40 : p.ProductID <= 40)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions