Skip to content

Improve index performance on Entity Framework persisters - #5881

Merged
rbev merged 4 commits into
masterfrom
missing-indexes
Sep 13, 2026
Merged

Improve index performance on Entity Framework persisters#5881
rbev merged 4 commits into
masterfrom
missing-indexes

Conversation

@rbev

@rbev rbev commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces new and optimized database indexes to both the SQL Server and PostgreSQL EF Core persistence layers, aiming to improve the performance of queries on failed messages and failure groups. The changes include adding covering indexes (with INCLUDE columns) for key aggregate queries, introducing new indexes to support sorting and filtering in the UI, and enforcing indexable column lengths for message types. These enhancements are reflected in both the migration files and the EF Core model configuration.

Database Indexing Improvements

  • Added covering indexes (with INCLUDE columns) to the Status, LastModified index on FailedMessages and the Type, GroupId index on FailedMessageGroups in both SQL Server and PostgreSQL providers, improving index-only scan performance for group aggregate queries. [1] [2] [3] [4] [5] [6] [7] [8]

  • Added new indexes to FailedMessages for (Status, LastTimeOfFailure) and (Status, MessageType, UniqueMessageId) to support efficient sorting and filtering in the failed messages UI. [1] [2] [3] [4] [5] [6] [7]

Schema and Model Changes

  • Updated the MessageType column on FailedMessages to have a maximum length of 450 characters (from unlimited text) to allow indexing and prevent issues on SQL Server and PostgreSQL. [1] [2] [3] [4] [5]

Documentation and Comments

  • Added detailed comments to the entity configurations explaining the purpose and provider-specific nature of the new and widened indexes, as well as rationale for column length restrictions. [1] [2] [3] [4] [5]

Query Logic Update

  • Updated the group retrieval logic in GroupsDataStore to use the new optimized method for fetching unresolved groups, aligning with the new index structures.

These changes collectively improve query performance for key recoverability and failed message scenarios, and ensure the schema is optimized for both SQL Server and PostgreSQL backends.

@rbev rbev changed the title Widen failure group indexes Improve index performance on Entity Framework persisters Sep 11, 2026
@rbev
rbev marked this pull request as ready for review September 11, 2026 04:15
@rbev
rbev enabled auto-merge September 11, 2026 08:04

@johnsimons johnsimons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of comments to consider

// ingestion rule. EnclosedMessageTypes' first comma token is a type's full name, so the cap can
// only ever bite on pathological generic names, where a truncated sort key still sorts and
// groups consistently.
static string? TruncateForColumn(string? value) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the truncate remove the first parts?
In other words, given the type name includes first the namespace, would it make sense to prioritise the class name, hence we start tirmming from left to right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a 450char type name is extremely unlikely, it's almost double the windows file path limit, but yes that's probably a better choice.

Comment on lines +56 to +57
public string Id { get; set; } = null!;
public string Type { get; set; } = null!;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be marked as required?

@rbev
rbev merged commit 3bf0c68 into master Sep 13, 2026
36 checks passed
@rbev
rbev deleted the missing-indexes branch September 13, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants