I was asked to perform a performance test using SQL Server 2008. As part of this, I compare the IDENTITY column speed as a PC using INTs and BIGINT. I have a simple procedure for creating 100,000 rows for each type and insert time. The script looks like this:
SET NOCOUNT ON CREATE TABLE TestData ( PK INT IDENTITY PRIMARY KEY, Dummy INT ) DECLARE @Rows INT DECLARE @Start DATETIME SET @Rows = 100000 SET @Start = GETDATE() WHILE @Rows > 0 BEGIN INSERT INTO TestData (Dummy) VALUES (@Rows) SET @Rows = @Rows - 1 END SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE()) DROP TABLE TestData
To test the BIGINT IDs, I use a very slightly modified version:
SET NOCOUNT ON CREATE TABLE TestData ( PK BIGINT IDENTITY PRIMARY KEY, Dummy INT ) DECLARE @Rows INT DECLARE @Start DATETIME SET @Rows = 100000 SET @Start = GETDATE() WHILE @Rows > 0 BEGIN INSERT INTO TestData (Dummy) VALUES (@Rows) SET @Rows = @Rows - 1 END SELECT @Start, GETDATE(), DATEDIFF(MS, @Start, GETDATE()) DROP TABLE TestData
To my surprise, the BIGINT version is much faster than the INT version. The INT version on my test suite takes about 30 seconds, and BIGINT takes about 25 seconds. The provided test kit has a 64-bit processor. However, it works with 32-bit Windows and the 32-bit version of SQL Server 2008.
Can someone else recreate, reject, confirm or challenge the results or indicate if I missed something?
source share