Some Simple Code To Show The Difference Between Newid And Newsequentialid
In SQL Server 2000 we got the uniqueidentifier data type and the newid() function
Lots of people thought that newid() would be very handy to create some unique values across all databases.
Newid() is nice but it has a little side effect; it causes terrible page splits because it is a random value. SQL Server 2005 introduced newsequentialid() where each value generated by the function is always greater than the previous value.
Let's take a look
First we will create these two tables
Create these two clustered indexes
You will see that AvgerageFreeBytes is the same for both tables
What about the inserts themselves? Run this code below
The table with the Newsequentialid did the inserts about 40% faster.
Now we will insert 1000 rows in each table again
No we will look again what happened
Wow the first table uses 21 pages while the second one uses 12.
AvgerageFreeBytes is 3524 bytes per page in the first table and only 96 bytes per page in the second table. Obviously newsequentialid is the better choice.
Running the code below you will see that newid is still slower than newsequentialid by about 16% or so for batch 2
Now we will insert 10000 rows and then look at freespace and duration again
The first table uses 117 pages while the second one uses 80.
AvgerageFreeBytes is 2574 bytes per page in the first table and only 21 bytes per page in the second table.
Running the code below you will see that newid is still slower than newsequentialid by about 40% or so for batch 3
Clean up
DROP TABLE TestGuid2,TestGuid1
So that is all, do you use newid or newsequentialid and if you do use newid did you experience fragmentation or performance problems because of it?
Supporting Microsoft’s commitment to delivering world-class enterprise capabilities and to help customers take advantage of the latest innovations through Microsoft and SAP development, today Windows Server 2008 and SQL Server 2008 are certified to fully support SAP NetWeaver 7.0 and the newly released SAP Business Suite 7.
We see immense benefits for our customers to move to our platform with products like virtualization through Hyper-V, and data and backup compression in SQL Server 2008. This level of innovation, combined with the attractive price point, provides great value to our enterprise customers.
A few of our customers, such as Kimball International Inc and SABMiller RUS, are already experiencing the benefits of migrating to Microsoft platforms with SAP. Kimball International recognized up to 50 percent more processing power in using Windows Server and SQL Server over an Oracle/Unix-based environment, seeing a savings of $450K in just one year. Also, SABMiller RUS found that Windows Server 2008 Hyper-V helped to reduce infrastructure costs by almost 50 percent and expects 234 percent ROI. Two great examples of how Microsoft’s products can help our enterprise customers save money.
Tina Couch
Windows Server Marketing