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


Introduction to Indexes: Part 3 – The nonclustered index


Introduction to Indexes: Part 3 – The nonclustered index

Author
Message
GilaMonster
GilaMonster
SSC Guru
SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)

Group: General Forum Members
Points: 465277 Visits: 47329
Comments posted to this topic are about the item Introduction to Indexes: Part 3 – The nonclustered index

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
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


Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87915 Visits: 14997
Great series Gail. Glad you mentioned the index intersection in this article, I've always had questions about that.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Tom Garth
Tom Garth
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3047 Visits: 1499
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

jcrawf02
jcrawf02
SSCrazy Eights
SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)

Group: General Forum Members
Points: 9100 Visits: 19324
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."
GilaMonster
GilaMonster
SSC Guru
SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)

Group: General Forum Members
Points: 465277 Visits: 47329
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, MVP, M.Sc (Comp Sci)
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


jcrawf02
jcrawf02
SSCrazy Eights
SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)

Group: General Forum Members
Points: 9100 Visits: 19324
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."
GilaMonster
GilaMonster
SSC Guru
SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)SSC Guru (465K reputation)

Group: General Forum Members
Points: 465277 Visits: 47329
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, MVP, M.Sc (Comp Sci)
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


jcrawf02
jcrawf02
SSCrazy Eights
SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)SSCrazy Eights (9.1K reputation)

Group: General Forum Members
Points: 9100 Visits: 19324
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. :-D

---------------------------------------------------------
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."
Charles Kincaid
Charles Kincaid
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5413 Visits: 2384
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.

ATBCharles Kincaid
Cliff Jones
Cliff Jones
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6357 Visits: 3648
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.
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