Performance value of COMB guids

前端 未结 3 1846
野性不改
野性不改 2020-12-17 17:43

Jimmy Nilsson discusses his COMB guid concept here. This concept is popular in NHibernate, among other circles, for its supposed performance value over standard GUIDs which

相关标签:
3条回答
  • 2020-12-17 18:03

    I second that you'll see differences only when you have indexes (PK, FK or other kind of indexes, clustered or not clustered) on the Guid colume, because cost of standard guid versus newguid or comb guid is due to the high cost of re-ordering the index data every time an insert is performed.

    See my question in which I corroborate this with some real life data from both SQL Server and Oracle.

    0 讨论(0)
  • 2020-12-17 18:06

    Your code for generating new GUIDs isn't correct. For each row, it's creating a very different number (you call NEWID() for each row). You need to keep most of the GUID the same.

    0 讨论(0)
  • 2020-12-17 18:26

    I'd suggest that you're not seeing the order benefit because the target table has no PK. So, it's the conversion overhead you're seeing. IF it has a PK, the 585k rows must still be sorted on insert. How does SQL know it's semi-sorted?

    Now, if it was 5,850 x 100 row inserts, then you may see some benefit because the new rows will go "at the end" not "in the middle" so reducing page splits and overhead.

    I'd go further and say that the article is dated 2002, and is for SQL 2000, and has been overtaken by real life.

    In SQL Server 2005 we have SEQUENTIAL GUIDs to allow strictly monotonic GUIDs to solve some issues. The GUID as PK has been done here too: recent example: INT vs Unique-Identifier for ID field in database with 3rd party links.

    If an ORM dictates GUID as a PK rather than a natural key or standard int-based surrogate key, that's a severe limitation of the ORM. And a case of the client tail wagging the database dog.

    0 讨论(0)
提交回复
热议问题