I have been asked to perform a performance test using SQL Server 2008. As part of this, I am comparing the speed of IDENTITY columns as PKs using INTs and BIGINTs. I have a simple routine to create 100,000 rows for each type and time the insert speed. 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
For testing BIGINT identities, 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 runs appreciably faster than the INT version. The INT version on my test kit takes about 30 seconds and the BIGINT about 25 seconds. Granted the test kit has a 64-bit processor. However, it is running 32-bit Windows and 32-bit SQL Server 2008.
Can anyone else recreate, deny, confirm or contest the results or point out if I have missed something?