Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make streamId a sql parameter of type SqlDbType.Char #197

Merged

Conversation

cheesebridge
Copy link

In our project we saw serious performance issues when having millions of streams.
This issue was caused by a CONVERT_IMPLICIT() function that was always executed when searching streams by streamId.
Our streamId was a regular Guid and the parameter type got translated to a nvarchar(36)
The result was an index scan on the streams table instead of an index seek.

In this PR, all streamId parameters are typed as SqlDbType.Char with length 42 because the streamid column on the streams table is declared as CHAR(42).
Now an index seek can be done.

image

Before
image

After
image

…onversion is done in MsSql when searching for a stream
@thefringeninja
Copy link
Member

Just waiting on CI now... I had b0rked the build but just fixed it

@thefringeninja
Copy link
Member

Wow, I can't say for sure but it looks like this PR has shaved a few seconds off of the CI build. Thanks!

@thefringeninja thefringeninja merged commit 3cd3929 into SQLStreamStore:master Oct 26, 2018
@damianh
Copy link
Member

damianh commented Oct 26, 2018

Great stuff

@damianh damianh added the bug label Oct 26, 2018
@damianh damianh added this to the v1.1.3 milestone Oct 26, 2018
@damianh
Copy link
Member

damianh commented Oct 26, 2018

I'm going to cherry pick this across to a 1.1.3 release branch.

@damianh damianh modified the milestones: v1.1.3, v1.2.0 Oct 26, 2018
damianh added a commit that referenced this pull request Oct 26, 2018
Make streamId a sql parameter of type SqlDbType.Char (cherrypicked from #197)
@damianh
Copy link
Member

damianh commented Oct 26, 2018

v1.1.3 is now on nuget.org.

@damianh damianh added enhancement and removed bug labels Oct 26, 2018
@damianh
Copy link
Member

damianh commented Oct 26, 2018

@cheesebridge awesome first PR. Many thanks!

@yreynhout
Copy link
Member

Good stuff! Not sure we can improve on this but Index Scan is generally not a good thing - we should strive for Index Seeks (but as said, I don't know whether that is possible here).

@cheesebridge
Copy link
Author

You're welcome. It's a great product 👍

@yreynhout Well this PR turns the index scan into an index seek as you can see in the 'after' screenshot of the query execution plan. ;-)

@yreynhout
Copy link
Member

My bad 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants