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


«««45678»»

Introduction to Indexes Expand / Collapse
Author
Message
Posted Thursday, November 19, 2009 1:41 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 7:04 AM
Points: 1,775, Visits: 2,432
GilaMonster (11/19/2009)
Do you have queries that filter on the combination of SSN + MyDataID or City + MyDataID?

p.s. That's a poor choice for a clustered index. See part 2 of this indexing series.


Not sure you can make that statement without knowing the data access patterns of the system. Yes it carries overhead on NC indexes and can have fragmentation issues, etc, but if the vast majority of their queries could benefit from a CI on LastName then it could be optimal despite some obvious drawbacks.



Best,

TheSQLGuru
SQL Server MVP
Post #821928
Posted Thursday, November 19, 2009 1:41 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 1:02 PM
Points: 105, Visits: 143
Gail,

I'm pretty sure you haven't answered my question.

The question is, not is it necessary to have the primary key specified in indexes, but is it redundant?

Doug
Post #821929
Posted Thursday, November 19, 2009 1:49 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 29, 2009 11:57 AM
Points: 24, Visits: 66
I believe the primary key is redundant in those indexes.
If you were to join tables using this primary key with a where clause using the lastname I would expect the optimizer to use the internal clustered key from the primary key. not the primary key field in the second column of your index.
Post #821936
Posted Thursday, November 19, 2009 2:17 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 7:04 AM
Points: 1,775, Visits: 2,432
Douglas Osborne-456728 (11/19/2009)
Gail,

I'm pretty sure you haven't answered my question.

The question is, not is it necessary to have the primary key specified in indexes, but is it redundant?

Doug


My vote (although I am not certain and don't have time to gen up a test) is that it is not redundant to include the PK CI column as a column in a NC index. I think if you have NC index on lastname, PKID you can get a seek without lookup on a select lastname, PKID where clause of lastname = 'asdf' and PKID between 1 and 5 but you would not get a seek on same if you just had index of lastname without the PKID. Something is just tickling the back of my memory that I have run into that exact same situation before and went "hmm, I didn't expect that behavior"...



Best,

TheSQLGuru
SQL Server MVP
Post #821961
Posted Friday, November 20, 2009 1:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:28 AM
Points: 16,983, Visits: 12,108
Douglas Osborne-456728 (11/19/2009)
The question is, not is it necessary to have the primary key specified in indexes, but is it redundant?


I'm obviously explaining badly.

What columns the primary key is on has absolutely nothing to do with redundant columns in indexes. What can be redundant when specified in indexes is the clustered index key (since it's present anyway). A primary key is not always clustered (though lots of people do think Primary Key = Clustered Index). In fact, in your case it is not.




Gail Shaw

We walk in the dark places no others will enter
We stand on the bridge and none may pass

Post #822151
Posted Friday, November 20, 2009 6:44 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 1:02 PM
Points: 105, Visits: 143
Gail,

Now I've got - only if the primary key is clustered is it present in all of the other keys.

I won't even tell you how many of the PKs here are Clustered Primary Key GUIDs - lol.

Thanks for taking your valuable time to beat this into my head.

Doug
Post #822338
Posted Tuesday, December 08, 2009 1:45 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 03, 2010 12:36 PM
Points: 1, Visits: 26
Amazing article Gail .... This clarified a lot of things ... Thanks a lot ...
Post #830996
Posted Wednesday, December 23, 2009 12:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 06, 2010 1:36 AM
Points: 6, Visits: 22
Nice article..
Thanks gail...
Post #838384
Posted Friday, February 05, 2010 12:36 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, March 05, 2010 2:32 AM
Points: 51, Visits: 141
Thanks Gail ...

Please elobrate more on Index Scan Properties.
Post #860203
Posted Friday, February 05, 2010 4:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:28 AM
Points: 16,983, Visits: 12,108
What more are you looking for?

http://sqlinthewild.co.za/index.php/2007/11/15/execution-plan-operations-scans-and-seeks/
http://sqlinthewild.co.za/index.php/2008/04/23/execution-plans-important-properties/



Gail Shaw

We walk in the dark places no others will enter
We stand on the bridge and none may pass

Post #860310
« Prev Topic | Next Topic »

«««45678»»

Permissions Expand / Collapse