Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Column Order in an Index


Column Order in an Index

Author
Message
dg1407
dg1407
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 82
I agree with the "spend a little more time with the article" focus.When i first read the topic, i got interested, and it was an interesting read, but i do think it also was a little bit shallow and with some lack of research, even more if you consider you're talking about, i think, one of the more complex topics on database development.

It's just constructive criticism.

Regards
DG
sandippani
sandippani
Mr or Mrs. 500
Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)

Group: General Forum Members
Points: 551 Visits: 227
Nice attempt. Here in this article you should explain why SQL server does like this. I'm referring to the Index Statistitics. You can also mention in the article that if all of the columns are used as predicate, order doesn't matter more precisly it is about the leading column of the index matters not the order.
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47133 Visits: 44346
sandippani (5/11/2013)
Nice attempt. Here in this article you should explain why SQL server does like this. I'm referring to the Index Statistitics.


It's not due to statistics. It's due to the fact that you can only seek on a left-based subset of the index key.

You can also mention in the article that if all of the columns are used as predicate, order doesn't matter more precisly it is about the leading column of the index matters not the order.


The order still matters, especially if some of the predicates are inequalities.


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


pdanes
pdanes
SSC-Addicted
SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)

Group: General Forum Members
Points: 440 Visits: 1350
I'm getting a little tired of all the jerkoffs who immediately jump in with comments like "You shouldn't be writing SQL code." Do you suppose anyone believes you were born with the ability to write perfect code? That's how people learn - try, make mistakes, try again, read, ask questions, post comments, listen to advice, tune your skills, swap ideas. If nobody did anything until they were perfect at it, nothing would ever get done, anywhere, by anybody.

Get over yourselves - you've made mistakes and written garbage code too, we all have. The trick is to learn from it, and if you're prepared for possible admission to the human race, help others learn as well.

Good manners are a nice plus, but if you can't post something that's at least helpful, go troll under someone else's bridge.
pdanes
pdanes
SSC-Addicted
SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)

Group: General Forum Members
Points: 440 Visits: 1350
One thing I didn't see anyone mention is size. An index is likely (not necessarily, of course) smaller than the table, so even in the worst case of a full scan of the index, the amount of data passed around from the disk subsystem should be smaller. Seems like that should be worth something.
Jim_K
Jim_K
SSC-Enthusiastic
SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)SSC-Enthusiastic (130 reputation)

Group: General Forum Members
Points: 130 Visits: 1808
David Walker-278941 (11/23/2010)
"This does not mean that the index 'NonClust_Contact_Name' was not useful. It's still much better than the Clustered scan."

*WHAT* is still much better than the clustered scan? I'm confused by that last sentence.


I'm confused about this comment as well....

Since we aren't shown a table definition with details about the clustered index, the only thing I could come up with is a scenario where the clustered index is "wider" (contains more data) than the non-clustered index. Thus the non-clustered index would be smaller and therefore preferred from an efficiency perspective. Maybe. If this was a heap would the RID be smaller, and the optimizer prefer a table scan? I don't know...
Steven Willis
Steven Willis
SSC-Addicted
SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)

Group: General Forum Members
Points: 477 Visits: 1721
pdanes (7/5/2013)
I'm getting a little tired of all the jerkoffs who immediately jump in with comments like "You shouldn't be writing SQL code." Do you suppose anyone believes you were born with the ability to write perfect code? That's how people learn - try, make mistakes, try again, read, ask questions, post comments, listen to advice, tune your skills, swap ideas. If nobody did anything until they were perfect at it, nothing would ever get done, anywhere, by anybody.

Get over yourselves - you've made mistakes and written garbage code too, we all have. The trick is to learn from it, and if you're prepared for possible admission to the human race, help others learn as well.

Good manners are a nice plus, but if you can't post something that's at least helpful, go troll under someone else's bridge.


+1

Anyone posting an article or script to be published for the entire community to benefit from (or to be nit picked incessantly) deserves to be treated with respect. Even if an author gets it quite wrong, if the follow-up discussion is professional and without personal attacks on a persons character or education then we can still learn something.

For anyone who thinks writing a submissible article or script is easy, I can say from experience that it's not. So to Sarvesh Singh I say keep trying and don't get discouraged!

 
materials.jai
materials.jai
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 12
On what scenarios we find this Index? Will it reduce time complexity if we use it?

Please provide some more examples?
etheral1980
etheral1980
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 211
GilaMonster (11/24/2010)
gosh (11/24/2010)
I expected proof that there was a performance difference between the order of columns in a composite index or a performance difference in the order of columns in the where-clause.


You won't find that because the order of columns in a where clause is utterly irrelevant. It makes no difference what order you specify the where clause predicates.

The order of columns in an index is very important, not so much for a single query, but for when you're trying to get as few indexes as possible to support as many queries as possible.

Several links to my blog posts on this have already been posted here, so I won't post again. Go and read over them.

I still think that the title is misleading. Maybe something along the lines: 'Primary Column in a Composite Index is the most Important'.


It's not. The order of columns (all of them) is important. Maybe the leading column is the most important, but the order of the rest of the columns in the index is important too.


Order of columns in where clause has performance impact in multiple predicates, even if you will see the same nice index seek for all of them. There are several great articles on this subject.
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