Eventuous / eventuous

Event Sourcing library for .NET
https://eventuous.dev
Apache License 2.0
442 stars 70 forks source link

SQL Server __schema__.Streams.StreamName is too big to be indexed #273

Closed Steve-OH closed 11 months ago

Steve-OH commented 11 months ago

Describe the bug

Invoking Schema.CreateSchema() using the SQL Server event store implementation results in the following warning:

Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'UQ_StreamName' has maximum length of 2000 bytes. For some combination of large values, the insert/update operation will fail.

To Reproduce

Note that the message is only a warning, rather than an error, so you'll never see it unless there is something else that raises an error at the same time.

First, create a schema the normal way:

var schema = new Schema("MySchema");
await schema.CreateSchema(getConnection);

Next, delete all of the newly created stuff, except for the __schema__.StreamMessage type:

drop procedure MySchema.append_events
go
drop procedure MySchema.check_stream
go
drop procedure MySchema.read_all_forwards
go
drop procedure MySchema.read_stream_forwards
go
drop procedure MySchema.read_stream_sub
go
drop table MySchema.Checkpoints
go
drop table MySchema.Messages
go
drop table MySchema.Streams
go

Finally, recreate the schema:

var schema = new Schema("MySchema");
await schema.CreateSchema(getConnection);

This time, you'll get an error (because the __schema__.StreamMessage type already exists — see #272), and you'll also see the warning.

Expected behavior

The warning should not occur. The obvious fix is to shorten the max length of the StreamName column to NVARCHAR(850), which seems plenty long, but I don't know if doing that might cause problems elsewhere.

Desktop (please complete the following information):