Skip to content

Views with underyling indicies are not used in translation #3829

Description

@michael-celani

I cannot configure a View to use an underlying existing GIN index, hamstringing its contains operators.

For the following query:

        var xQuery = db.DeckSearchView
            .AsNoTracking()
            .Where(d => d.DeckTags.Contains("x"))
            .ToQueryString();

View Configuration

        modelBuilder.Entity<DeckSearchView>()
            .ToView("DeckSearchView", "public")
            .Metadata.SetIsTableExcludedFromMigrations(true);

        modelBuilder.Entity<DeckSearchView>()
            .HasIndex(e => e.CardIds)
            .HasMethod("gin");

        modelBuilder.Entity<DeckSearchView>()
            .HasIndex(e => e.DeckTags)
            .HasMethod("gin");
SELECT ...
FROM public."DeckSearchView" AS d
WHERE 'x' = ANY (d."DeckTags")

Nonview Configuration (Underlying View in PG):

        modelBuilder.Entity<DeckSearchView>()
            //.ToView("DeckSearchView", "public") Required to use GIN index
            .Metadata.SetIsTableExcludedFromMigrations(true);

        modelBuilder.Entity<DeckSearchView>()
            .HasIndex(e => e.CardIds)
            .HasMethod("gin");

        modelBuilder.Entity<DeckSearchView>()
            .HasIndex(e => e.DeckTags)
            .HasMethod("gin");
SELECT ...
FROM public."DeckSearchView" AS d
WHERE d."DeckTags" @> ARRAY['x']::text[]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions