Skip to content

Commit ea970f5

Browse files
committed
Add additional fields to postgres indexes
1 parent 3bf0c68 commit ea970f5

15 files changed

Lines changed: 1144 additions & 162 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ServiceControl.Persistence.EFCore.EntityConfigurations;
2+
3+
using Entities;
4+
using MessageFailures;
5+
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
7+
8+
class FailedMessageConfiguration : IEntityTypeConfiguration<FailedMessageEntity>
9+
{
10+
public void Configure(EntityTypeBuilder<FailedMessageEntity> builder)
11+
{
12+
// Drives the retention sweep.
13+
// The index is restricted to the statuses the sweep deletes (Resolved and Archived)
14+
builder.HasIndex(e => e.StatusChangedAt)
15+
.HasFilter($"status IN ({(int)FailedMessageStatus.Resolved}, {(int)FailedMessageStatus.Archived})");
16+
17+
builder.HasIndex(e => new { e.Status, e.LastModified, e.UniqueMessageId })
18+
.IncludeProperties(nameof(FailedMessageEntity.FirstTimeOfFailure), nameof(FailedMessageEntity.LastTimeOfFailure));
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace ServiceControl.Persistence.EFCore.EntityConfigurations;
2+
3+
using Entities;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
6+
7+
class FailedMessageGroupConfiguration : IEntityTypeConfiguration<FailedMessageGroupEntity>
8+
{
9+
public void Configure(EntityTypeBuilder<FailedMessageGroupEntity> builder)
10+
{
11+
// Both the join column (FailedMessageUniqueId) and the per-group title lookup's column
12+
// (Title) have to be INCLUDEs. Without Title the lookup heap-fetches, and without
13+
// FailedMessageUniqueId step 1 of the aggregate cannot join index-only
14+
builder.HasIndex(e => new { e.Type, e.GroupId })
15+
.IncludeProperties(nameof(FailedMessageGroupEntity.FailedMessageUniqueId), nameof(FailedMessageGroupEntity.Title));
16+
}
17+
}

0 commit comments

Comments
 (0)