Skip to content

perf(mssql): enable OPTIMIZE_FOR_SEQUENTIAL_KEY on primary keys for S… - #2

Merged
nmummau merged 1 commit into
devfrom
feat/mssql-optimize
Oct 8, 2025
Merged

perf(mssql): enable OPTIMIZE_FOR_SEQUENTIAL_KEY on primary keys for S…#2
nmummau merged 1 commit into
devfrom
feat/mssql-optimize

Conversation

@nmummau

@nmummau nmummau commented Oct 8, 2025

Copy link
Copy Markdown
Owner

perf(mssql): enable OPTIMIZE_FOR_SEQUENTIAL_KEY on primary keys for Streams and Messages

  • Added WITH (OPTIMIZE_FOR_SEQUENTIAL_KEY = ON) to clustered primary keys on schema.Streams (PK_Streams) and schema.Messages (PK_Events)
  • Improves insert throughput and reduces latch contention on identity-based keys
  • No changes to schema shape, constraints, or indexes beyond PK optimization

This improves concurrent insert performance under high write workloads by allowing SQL Server to better handle last-page insert contention on sequential identity keys.
See docs on OPTIMIZE_FOR_SEQUENTIAL_KEY: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-table-index-option-transact-sql?view=sql-server-ver17#optimize_for_sequential_key---on--off-

…treams and Messages

- Added WITH (OPTIMIZE_FOR_SEQUENTIAL_KEY = ON) to clustered primary keys on __schema__.Streams (PK_Streams) and __schema__.Messages (PK_Events)
- Improves insert throughput and reduces latch contention on identity-based keys
- No changes to schema shape, constraints, or indexes beyond PK optimization

This improves concurrent insert performance under high write workloads by allowing SQL Server to better handle last-page insert contention on sequential identity keys.
See docs on OPTIMIZE_FOR_SEQUENTIAL_KEY: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-table-index-option-transact-sql?view=sql-server-ver17#optimize_for_sequential_key---on--off-
@nmummau
nmummau merged commit 8463f8f into dev Oct 8, 2025
1 of 3 checks passed
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