Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,12 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
return array switch
{
// For array columns which have a GIN index, we translate to array containment (with @>) which uses that index.
ColumnExpression { Column: IColumn column }
when column.Table.Indexes
.Any(i =>
i.Columns.Count > 0
&& i.Columns[0] == column
&& i.MappedIndexes.Any(mi => mi.GetMethod()?.Equals("GIN", StringComparison.OrdinalIgnoreCase) == true))
ColumnExpression { Column: IColumnBase column }
when column.PropertyMappings.Any(
m => m.Property.GetContainingIndexes().Any(
i => i.Properties.Count > 0
&& i.Properties[0] == m.Property
&& i.GetMethod()?.Equals("GIN", StringComparison.OrdinalIgnoreCase) == true))
=> BuildSimplifiedShapedQuery(
source,
_sqlExpressionFactory.Contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ LIMIT 2
""");
}

[ConditionalFact]
public virtual async Task View_column_collection_Contains_with_GIN_index_uses_containment()
{
var contextFactory = await InitializeAsync<TestContext>(
onModelCreating: mb => mb.Entity<TestEntity>()
.ToView("TestView")
.HasIndex(e => e.Ints)
.HasMethod("GIN"),
onConfiguring: b => b.ConfigureWarnings(w => w.Ignore(RelationalEventId.AllIndexPropertiesNotToMappedToAnyTable)));

await using var context = contextFactory.CreateContext();

Assert.Equal(
"""
SELECT t."Id", t."Ints"
FROM "TestView" AS t
WHERE t."Ints" @> ARRAY[4]::integer[]
""",
context.Set<TestEntity>().Where(c => c.Ints!.Contains(4)).ToQueryString());
}

[ConditionalFact]
public virtual async Task Column_collection_Contains_with_btree_index_does_not_use_containment()
{
Expand Down
Loading