SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Lots of Key Lookups vs. UniqueIdentifier Clustered Index


Lots of Key Lookups vs. UniqueIdentifier Clustered Index

Author
Message
dave-L
dave-L
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 245
Hello.

I'm working on a system that was originally designed with UUID (uniqueIdentifier) clustered indexes.

Later the clustered indexes were rebuilt on an INT identity column to boost the performance of the index. Because the schema (and code base) reference the UUIDs as primary keys everywhere this was never changed.

I'm now concerned that we are doing an extraordinary number of key lookups. For example, when ever a table is joined on the UUID primary key, no additional data is in the index so it must be looked up using the new INT.

My question is: is it better to have all of these key lookups happening or would it be better to just build the clustered indexes on the UUIDs? Alternatively I could include an inordinate amount of columns making the primary key index wide, but at that point wouldn't it be similar to reorganizing my clustered index on the UUID?

Any thoughts would be appreciated.

Thanks, Dave
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15507 Visits: 14396
Just curious, is this another design where the UUIDs are generated in the app tier within disconnected memory-resident objects and then committed to the database when the user likes what they have created in the application?

For the database, there is no way to say which would be better without being able to study the differences in performance while a representative workload, before and after changes were made to the indexes in place.

Ideally the app would be rewritten to make use of clustered surrogate keys so the UUID columns could be sent on their way, i.e. dropped.

However, that would likely be cost prohibitive. Why not go back to clustering on the UUID and invest in SSD drives which in effect make index fragmentation a non-issue?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
dave-L
dave-L
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 245
Hi opc.three. Thanks for the reply.

Yeah, for the most part the UUIDs are generated in the app layer, though there is some default constraints in the dB.

As luck would have it, the dB I'm referring to is running on SSS (Fusion-IO). Do you think that on SSS it's a non-issue to have non-consecutive cluster index keys? Is the only issue index fragmentation? Any performance issues with the dB trying to "rebalance" the tree or is it just doing page splits and inserting the new keys?

Thanks!
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15507 Visits: 14396
You'll have to test because as usual, it will depend on your workload and data. Here is a great place to start:

Does Index Fragmentation Matter with SSD’s?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90305 Visits: 41146
opc.three (11/16/2012)
You'll have to test because as usual, it will depend on your workload and data. Here is a great place to start:

Does Index Fragmentation Matter with SSD’s?


Apologies... I don't understand. What do SSD's have to do with SSS?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90305 Visits: 41146
dave-L (11/14/2012)
Hello.

I'm working on a system that was originally designed with UUID (uniqueIdentifier) clustered indexes.

Later the clustered indexes were rebuilt on an INT identity column to boost the performance of the index. Because the schema (and code base) reference the UUIDs as primary keys everywhere this was never changed.

I'm now concerned that we are doing an extraordinary number of key lookups. For example, when ever a table is joined on the UUID primary key, no additional data is in the index so it must be looked up using the new INT.

My question is: is it better to have all of these key lookups happening or would it be better to just build the clustered indexes on the UUIDs? Alternatively I could include an inordinate amount of columns making the primary key index wide, but at that point wouldn't it be similar to reorganizing my clustered index on the UUID?

Any thoughts would be appreciated.

Thanks, Dave


You might be able to fix this. I haven't tested it but it might work.

{EDIT} My apologies for posting a guess instead of a tested solution. This "hack" doesn't work. Please see my post further down for the test code.

Make the clustered index on the IDENTITY and the GUID column and then change the criteria in the queries to be where SomeIdentityColumn > 0 AND SomeGuidColumn = SomeGuidValue (or whatever). It's a nasty hack but might work.

The advantage here is that the IDENTITY column is first in the index and would virtually eliminate page splits. The change in criteria I mention would cause the clustered index to still be used thereby eliminating the lookups even when you lookup a GUID.

Like I said, not sure it'll work but it seems very likely that it would.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15507 Visits: 14396
Jeff Moden (11/17/2012)
opc.three (11/16/2012)
You'll have to test because as usual, it will depend on your workload and data. Here is a great place to start:

Does Index Fragmentation Matter with SSD’s?


Apologies... I don't understand. What do SSD's have to do with SSS?

Fusion IO is a solid state solution. The ones I have used fit into a PCI Express slot. Therefore I assumed that SSS (sic) meant Solid State Storage which some people say in place of SSD, or Solid State Drives.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90305 Visits: 41146
opc.three (11/17/2012)
Jeff Moden (11/17/2012)
opc.three (11/16/2012)
You'll have to test because as usual, it will depend on your workload and data. Here is a great place to start:

Does Index Fragmentation Matter with SSD’s?


Apologies... I don't understand. What do SSD's have to do with SSS?

Fusion IO is a solid state solution. The ones I have used fit into a PCI Express slot. Therefore I assumed that SSS (sic) meant Solid State Storage which some people say in place of SSD, or Solid State Drives.


Ah... got it. Thanks, Orlando. I haven't had the pleasure of working with SSDs, yet.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Tom Thomson
Tom Thomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14772 Visits: 12238
Jeff Moden (11/17/2012)
You might be able to fix this. I haven't tested it but it might work.

Make the clustered index on the IDENTITY and the GUID column and then change the criteria in the queries to be where SomeIdentityColumn > 0 AND SomeGuidColumn = SomeGuidValue (or whatever). It's a nasty hack but might work.

The advantage here is that the IDENTITY column is first in the index and would virtually eliminate page splits. The change in criteria I mention would cause the clustered index to still be used thereby eliminating the lookups even when you lookup a GUID.

Like I said, not sure it'll work but it seems very likely that it would.

That should certainly eliminate the fragmentation, but wouldn't it always produce a CI can rather than a CI seek? Is that really less damaging than the fragmentation caused by just using the GUIDs?

Tom

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90305 Visits: 41146
You might be right, Tom. A CI Seek followed by a range scan starting at the first row will be no better than a CI scan. I need to check a bit more deeply.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search