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


Add to briefcase

Indexing Question Expand / Collapse
Author
Message
Posted Wednesday, August 20, 2014 11:16 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 12:52 PM
Points: 128, Visits: 565
My MailingAddress table currently has a Non Clustered index on the ProcessID column. Using a Missing Indexes query I have, it is recommending that I add the following:

CREATE INDEX [IX_MailingAddress_ProcessID_PrintFlag] ON [DB1].[dbo].[MailingAddress] ([ProcessID], [PrintFlag]) INCLUDE ([RunNum])

I am under the impression that I should either delete the existing index on ProcessID and add this one or should I add the suggested index while keeping the index only on ProcessID as well?

Thanks for the help!!
Post #1605537
Posted Wednesday, August 20, 2014 11:24 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:09 AM
Points: 10,342, Visits: 13,352
Neither is another option.

When working on indexing you need to consider the all the ways a table will be queried to come up with the best indexes. In your one example, the recommended index is probably better than the single column index because it is highly unlikely that you will only be returning ProcessID in your query, so you'll require a lookup (key or rid) to retrieve the rest of the columns used in the query. The issue with the recommended index is that there might be other queries that would use the same key values but return columns other than RunNum, so an index without an INCLUDE might be the best way for the table or an index with and INCLUDE that has more than the just the RowNum column.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

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
Post #1605541
Posted Wednesday, August 20, 2014 11:30 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 12:52 PM
Points: 128, Visits: 565
Thanks Jack for the response.

I have another question, I just started at this job and I am seeing tables that do not have a PK or a Clustered Index on them. I have a feeling that I should be finding a good column to create a clustered index on and get it done. I am wondering what if any negative side effects this could have??? Can you shed some light on this for me?
Post #1605545
Posted Wednesday, August 20, 2014 11:47 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:09 AM
Points: 10,342, Visits: 13,352
GBeezy (8/20/2014)
Thanks Jack for the response.

I have another question, I just started at this job and I am seeing tables that do not have a PK or a Clustered Index on them. I have a feeling that I should be finding a good column to create a clustered index on and get it done. I am wondering what if any negative side effects this could have??? Can you shed some light on this for me?


First, don't confuse Primary Keys and Clustered Indexes as they are different things and serve different purposes. A Primary Key is something that defines a unique entity, by default, SQL Server does create a clustered index when creating a Primary Key, but you don't have to do that. A Clustered Index defines the logical order the data in the table is stored in. A primary key can be a business key or a surrogate key (should always be backed up with a business key) and if it is a business key it often is not the best candidate for clustering.

SQL Server does tend to work better with tables that have a clustered index than with heaps, with the caveat that you have chosen the right column(s) for the clustering key. I'd start by reading all the posts by Kimberly Tripp on clustered indexes. This one has links to all of them. She explains things much better than I could.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

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
Post #1605552
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse