Skip to content

Translation of enums comparison in filters kills index performance #189

Closed
@alex-kulakov

Description

@alex-kulakov

Queries like

session.Query.All<SomeType>().Where(e => e.State == States.New)

have following filter in SQL if States has base type smaller than integer, e.g. byte

SELECT [a].[Id], 100 AS [TypeId], [a].[State] FROM [dbo].[SomeType] WHERE (CAST([a].[State]  AS integer) = 1)

Such SQL queries have poor performance even if State is indexed. This happens because C# compiler elevates left and right expressions up to int.

We could improve this case by applying cast to actual underlying type of enum.

Note that the problem is also appears in filtered indexes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions