patternsqlMinor
Does a dual key or single key lookup perform better on a table with a lot of data?
Viewed 0 times
withbetterlotsingleperformdoesduallookupdatatable
Problem
We have table where rows unique between 3 columns. GroupA, GroupB, ProductID.
GroupA & GroupB are used in combinations to Group sets of ProductIDs and will always be used to lookup sets of productIDs. Sometimes a ProductID will be used in in the query also.
I wasnt sure if there would be any performance gains from combining GroupA and GroupB into the same column so that the index is clustered.
Dual group method above OR Single group method below.
GroupA & GroupB are used in combinations to Group sets of ProductIDs and will always be used to lookup sets of productIDs. Sometimes a ProductID will be used in in the query also.
I wasnt sure if there would be any performance gains from combining GroupA and GroupB into the same column so that the index is clustered.
GroupA | GroupB | ProductID
----------------------------
A1 | B1 | 1
A1 | B1 | 99
A1 | B2 | 1
A1 | B2 | 99
A2 | B1 | 1
A2 | B1 | 99
A2 | B2 | 1
A2 | B2 | 99Dual group method above OR Single group method below.
GroupAB | ProductID
--------------------
A1-B1 | 1
A1-B1 | 99
A1-B2 | 1
A1-B2 | 99
A2-B1 | 1
A2-B1 | 99
A2-B2 | 1
A2-B2 | 99
GroupA | GroupB | GroupAB
----------------------------
A1 | B1 | A1-B1
A1 | B2 | A1-B2
A2 | B1 | A2-B1
A2 | B2 | A2-B2Solution
I don't think it would really matter. You can cluster on both without concatenating them:
Which will accomplish the same thing but not require you to modify your data.
CREATE CLUSTERED INDEX ixc_MyIndexName ON MyTable (GroupA, GroupB)Which will accomplish the same thing but not require you to modify your data.
Code Snippets
CREATE CLUSTERED INDEX ixc_MyIndexName ON MyTable (GroupA, GroupB)Context
StackExchange Database Administrators Q#18364, answer score: 2
Revisions (0)
No revisions yet.