The overhead of a non-unique clustered index - Andrew Calvett

The overhead of a non-unique clustered index

Published 20 October 2008 00:21

So, we all know that if we create a clustered index that is not unique that we will incur a 4 byte overhead right? Well not always because as usual, it depends..... Geeked

When you create a non-unique clustered index SQL server must maintain uniqueness so it adds a hidden 4 byte column which is populated for each non-unique row (not every row) but what many people may not realise is that this is actually a variable length column so if your table has no variable length columns you have to incur another 4 bytes to maintain the variable offset data giving you a total of 8 bytes per row instead of 4 bytes.

A few bytes may not sound much but when dealing with multi billion row tables it soon adds up so its important to know how the space consumption breaks down.

Below is an extract from Books Online 2005 "Estimating the size of a clustered index"

"The uniqueifier is a nullable, variable-length column. It will be nonnull and 4 bytes in size in rows that have nonunique key values. This value is part of the index key and is required to make sure that every row has a unique key value."

Its great to see that this hidden column is now documented but a bit of additional clarity around its potential variable length property storage overhead would nice.

Finally I thought I would visual this hidden data overhead for you with a screen shot from Danny's awesome Internals Viewer

ole0

Update: Thanks to Christian Bolton for clarification that the overhead is for each non-unique row which i have now reflected in the post.

Comments

# Christian said on 21 October 2008 19:52

Hi Andrew,

Its probably worth re-iterating that the uniqueifier (you have to love the MS devs for inventing new words) is only applied to non-unique rows not EVERY row.

I didn't know about the variable offset though, good call!

Christian Bolton

sqlblogcasts.com/.../christian

# ACALVETT said on 22 October 2008 12:38

Hi Christian,

Thanks for your input. I've updated the post to make sure that its clear!

Cheers

Andrew

# Log Buffer #120: a Carnival of the Vanities for DBAs said on 24 October 2008 17:25

Pingback from  Log Buffer #120: a Carnival of the Vanities for DBAs