-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
SqlServerSequenceValueGenerator inefficient #1540
Comments
Investigate as this isn't how it is supposed to work - if it is then we need to fix |
In HiLoValueGeneratorState we use the block size after we call GetNewHighValue()
If the block size is set to 1, we will get a new block every time we request a value, but otherwise it is only called once per block. It appears to me that we should rename GetNewHighValue to GetNewLowValue, as this function actually gets the next available value, then creates a block by adding the block size to that value. |
@cherrydev What type of values are you using for your keys when you see this behavior? |
Closing as no repro, will reopen if more information is posted |
Sorry I didn't follow up for this. I was just using integer keys:
With no other explicit configuration. While looking at the SQL logs, I was most definitely seeing one "NEXT VALUE FOR " for each entity that was being inserted when SaveChanges() was called on the entity. I did not have it configured explicitly for HiLoValueGenerator (nor do I actually know how to do that). |
the following test demonstrates the behavior of our batched key generator. For the first 5 keys we query the database for a new key block, but then we continue using those same 5 key blocks until we hit 50 entries. Then we repeat.
|
@ajcvickers I believe this one is ready to close. |
Because the value generator opens a connection to the database for every single sequence that it generates, and then ALSO fetches only a single value at a time, it is (even compared to identity columns) excruciatingly slow. The base class for SqlServerSequenceValueGenerator has a BlockSize property, but it's not being used when requesting a new sequence number. It makes sense to me that sp_sequence_get_range should be used instead of "SELECT NEXT VALUE FOR" since it allows for fetching an arbitrary number of values at the same time.
The text was updated successfully, but these errors were encountered: