|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 11:41 AM
Points: 38,089,
Visits: 30,383
|
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 10:45 AM
Points: 10,613,
Visits: 11,957
|
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, February 04, 2011 7:20 AM
Points: 977,
Visits: 1,499
|
|
Thanks Gail,
Well written. I read all 3 and learned a few things.
Tom Garth Vertical Solutions
"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 2:46 PM
Points: 2,561,
Visits: 18,910
|
|
Asking what is probably an obvious question, but from what I understand:
Adding a clustered index that covers multiple columns within a table is not necessarily advantageous, because it will expand all of the non-clustered indexes as well. (from part II)
Therefore, the clustered index should be as narrow as possible, and the non-clustered index should be created as a composite key to assist with querying?
So if I have a heap that only has a unique value by combining three separate columns, I should create a new column with a unique value (using newsequentialid() or some such) and make that the clustered index, but use the composite non-clustered index to help my queries against the table?
--------------------------------------------------------- How best to post your question How to post performance problems Tally Table:What it is and how it replaces a loop
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 11:41 AM
Points: 38,089,
Visits: 30,383
|
|
jcrawf02 (11/18/2009) Adding a clustered index that covers multiple columns within a table is not necessarily advantageous, because it will expand all of the non-clustered indexes as well. (from part II)
Yes
Therefore, the clustered index should be as narrow as possible, and the non-clustered index should be created as a composite key to assist with querying?
Yes.
So if I have a heap that only has a unique value by combining three separate columns, I should create a new column with a unique value (using newsequentialid() or some such) and make that the clustered index, but use the composite non-clustered index to help my queries against the table?
Maybe.
Remember that clustered index != primary key. While it is a good idea to put the cluster on a unique column, it's not obligatory. SQL can make the clustered index unique (by adding an int behind the scenes) if the column it's defined on is not. Look at what columns exist. Are any of them fairly good candidates for the cluster? Are any reasonably good?
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 2:46 PM
Points: 2,561,
Visits: 18,910
|
|
ok, so if I have a system generated UID from a different table, but the values are not entirely unique, only a few duplicates in my heap, I could/should use that, as the system would make the clustered index unique in the backend? That was my first instinct, but got derailed when I saw duplicates.
--------------------------------------------------------- How best to post your question How to post performance problems Tally Table:What it is and how it replaces a loop
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 11:41 AM
Points: 38,089,
Visits: 30,383
|
|
jcrawf02 (11/18/2009) ok, so if I have a system generated UID from a different table, but the values are not entirely unique, only a few duplicates in my heap, I could/should use that, as the system would make the clustered index unique in the backend? That was my first instinct, but got derailed when I saw duplicates.
Maybe. How well does it fit the other guidelines for the clustered index? Narrow, unchanging, ever-increasing? I've often used a 'date inserted' type column for the cluster. Not quite unique, fairly narrow, unchanging, ever-increasing. It's all about what tradeoffs you're willing to make.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 2:46 PM
Points: 2,561,
Visits: 18,910
|
|
Thanks, food for thought. Narrow (15 character static IDs), unchanging (check), ever-increasing (not sure, ID has leading alpha characters and is not consistently assigned). In short, not sure that's my best choice, but I'll go back and re-evaluate.
Great series, I'll be reading and re-reading these for a long time.
--------------------------------------------------------- How best to post your question How to post performance problems Tally Table:What it is and how it replaces a loop
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 11:56 AM
Points: 772,
Visits: 1,828
|
|
Great article - All three parts.
In the column order I get that as this is how the index is sorted. When talking about included columns one would guess that the order is no more or less important than the column order in the table itself.
ATB
Charles Kincaid
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 2:31 PM
Points: 3,418,
Visits: 3,438
|
|
| I agree, a great series of articles explained in a way that is easy to understand. Gail, thanks for taking the time to put this together.
|
|
|
|