Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Lots of Key Lookups vs. UniqueIdentifier Clustered Index Expand / Collapse
Author
Message
Posted Wednesday, November 14, 2012 4:08 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 11:16 AM
Points: 53, Visits: 181
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
Post #1384915
Posted Thursday, November 15, 2012 10:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:12 AM
Points: 7,135, Visits: 12,746
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
Post #1385271
Posted Friday, November 16, 2012 12:10 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 11:16 AM
Points: 53, Visits: 181
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!
Post #1385821
Posted Friday, November 16, 2012 1:31 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:12 AM
Points: 7,135, Visits: 12,746
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
Post #1385846
Posted Saturday, November 17, 2012 7:38 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:11 PM
Points: 35,578, Visits: 32,170
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1385940
Posted Saturday, November 17, 2012 7:49 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:11 PM
Points: 35,578, Visits: 32,170
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1385941
Posted Saturday, November 17, 2012 7:51 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:12 AM
Points: 7,135, Visits: 12,746
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
Post #1385942
Posted Saturday, November 17, 2012 4:36 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:11 PM
Points: 35,578, Visits: 32,170
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1386016
Posted Sunday, November 18, 2012 10:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:47 AM
Points: 7,855, Visits: 9,603
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
Post #1386071
Posted Sunday, November 18, 2012 1:32 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:11 PM
Points: 35,578, Visits: 32,170
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1386097
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse