Hi Guys,
how can i use the newsequentialid() for my guid keys? Currently i have my own mssql Connection Provider, where i override
GetSqlCreateColumnFullAttributes
and add
" DEFAULT (newsequentialid())";
to the key column. works fine so far. but now i Need to tell XPO to remove the key property from the insert statements, and retrive the guid after the insert from the SQL Server?
how to solve this?
Hi Noxe,
what is your reason to use newsequentialid() for guid keys?
If the reason is that you want "sequential" guids to avoid key fragmentation, then look into CombGuid (see NHibernate).
These are sequential and have the benefit that no extra roundtrip is necessary to retrieve the guid from server.
JM2€C, Robert
Hi Rob,
1
there would be no roundtrip if you set it as Default for the key column. i want to use it because of Performance. we are getting more and more Performance Problems, and it seems that there is a huge Problem if the Primary key is an guid, and this column has also an clustered index on it. because guids are random, fragmentation is nearly 100%. i tested a lot today, and it seems XpoDefault.NewGuid() is the badest Performance. i then tried XpoDefault.GuidGenerationMode = GuidGenerationMode.UuidCreateSequential - but here fragmentaion is also nearly 100%, Performance is slightly better - but still bad if you add many records. for test, i added 100.000 records, 50 times in a row - a simple class containing only the PK. after adding many rows, both methods will drop on Performance, sometimes (because of SQL Server?) there are gaps of 1-5 minutes where SQL servere is shifting? rows… normal times is with Default guid 10-12 seconds for 100.000 records, 6-7 with uuidcreatesequential.
now i found some other methods:
http://www.codeproject.com/Articles/388157/GUIDs-as-fast-primary-keys-under-multiple-database
http://www.jorriss.net/blog/archive/2008/04/24/unraveling-the-mysteries-of-newsequentialid
where the second one is the fastest, and index fragmentation is on 0,5 - 1% with this method, and insert performace is constant on 5-6 seconds with no gaps!
also interessting link: http://blogs.msdn.com/b/dbrowne/archive/2012/06/26/good-page-splits-and-sequential-guid-key-generation.aspx
So after Research, it seem it is too hard to use newsequentialid() because of the insertstatement Generator which would Need to exclude the OID column, and get the new inserted value back to the Client, so i think i will go with the second link i posted above!
Hi Noxe,
no, do NOT use the Guid from the second link!
This Guid has the MAC address encoded and will not be sequential if generated from more than one machine, so you will still get a lot of fragmentation.
What you need is a Guid generated with a TimeStamp - a so called Comb(ined) Guid aka CombGuid, like I already posted above.
I posted the code that I use in the solution below.
Thanks for posting about Comb GUIDs Robert - been doing some research on this and it looks very interesting.