richardtallent / RT.Comb

Creating sequential GUIDs in C# for MSSQL or PostgreSql
203 stars 35 forks source link

test result show not sorted #9

Closed philiahe closed 6 years ago

philiahe commented 6 years ago

sort

richardtallent commented 6 years ago

Hi,

As mentioned in the documentation, creation of COMBs in very quick succession will result in the same embedded timestamp. COMBs with the same timestamp are sorted essentially randomly, since the sort algorithm of your RDBMS will start sorting on the other (non-timestamp) bits of the GUID.

This is sufficient for most needs, such as determining a primary key for a database table. If you need more of a guarantee that COMBs generated will always sort precisely in insertion order, please use UtcNoRepeatTimestampProvider, ideally with UnixDateTimeStrategy. You can see an example of this in the tests:

https://github.com/richardtallent/RT.Comb/blob/782bdadeaf055d46e580b7572d39649c80b5a45b/test/RT.Comb.Tests/RT.CombTests.cs