Repository navigation
Conversation
Replace the UQ_StreamName constraint with a unique index that includes Version, avoiding key lookups during appends and stream reads. Upgrade existing schemas during initialization and add regression tests for the upgrade, repeated initialization, and preserved data and uniqueness. Release note: This is a non-breaking schema optimization. Applications using InitializeDatabase=true receive the index upgrade on startup. Applications managing their schema separately must replace the UQ_StreamName constraint with a unique nonclustered index on StreamName that includes Version, retaining the UQ_StreamName name. Existing schemas remain compatible but do not receive the optimization until upgraded. Fixes Eventuous#617
Remove IDX_EventsStream, since UQ_StreamIdAndStreamPosition already supports filtering by StreamId. Drop the index during schema initialization for existing databases. Add regression tests for fresh schemas, upgrades, repeated initialization, and event payload preservation. Applications without InitializeDatabase enabled can apply: DROP INDEX IF EXISTS IDX_EventsStream ON eventuous.Messages; Replace eventuous with the configured schema name. Existing schemas remain compatible without this optimization. Fixes Eventuous#618
Use SCOPE_IDENTITY() to capture the last inserted GlobalPosition, removing the table variable, OUTPUT INTO, and MAX query. Add regression tests for empty, single-event, and multi-event batches on new and existing streams, including reused connections. Applications with InitializeDatabase disabled must deploy the updated append_events procedure to receive this optimization. Validated with all 46 SQL Server store tests, including concurrency tests. Fixes Eventuous#619
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce SQL Server index maintenance and intermediate writes on appends, and cover stream-name lookups without changing the event store API.
Version#617: Replace theUQ_StreamNameconstraint with a unique index includingVersion, covering the stream-name lookup used by appends and reads. Preserve the index name for duplicate-key handling. This adds index maintenance when the stream version changes.IDX_EventsStreamduplicatesUQ_StreamIdAndStreamPosition#618: RemoveIDX_EventsStream, sinceUQ_StreamIdAndStreamPositionalready starts withStreamId. KeepMessagesclustered onGlobalPosition: covering stream reads with JSON payloads would duplicate data, while changing the clustered key would shift payload lookups to global reads. Per-event payload lookups during stream reads remain.append_eventsdoes not need the@insertedtable variable #619: Replace the append position table variable,OUTPUT INTO, and finalMAXquery withSCOPE_IDENTITY()immediately after the insert. PreserveNULLpositions for empty batches.Upgrade notes
These are non-breaking optimizations. Existing databases remain compatible without applying them.
With
InitializeDatabase = true, startup applies the index changes and updatesappend_eventsthrough the existing transactional schema initializer. Repeated initialization is safe.With initialization disabled (the default), consumers must apply the changes through their database deployment process to receive the optimizations:
Streams.UQ_StreamNameunique constraint with a unique nonclustered index onStreamNameincludingVersion. Keep the nameUQ_StreamName, and perform the replacement in a transaction.Messages.IDX_EventsStreamif it exists.append_eventsprocedure fromScripts/2_AppendEvents.sql.Use the configured schema name when applying the SQL scripts. Alternatively, explicitly run
Schema.CreateSchema(...)from the upgraded package.Validation
Fixes #617
Fixes #618
Fixes #619