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


Multiple Covering Indexes


Multiple Covering Indexes

Author
Message
Spork
Spork
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 247
After doing some performance research, it appears that covering index(es) may be beneficial for a couple transactional tables in my database.

My question is this:

Is there ever a benefit to create multiple indexes with different nonkey columns when the key columns are the same?

For instance, if I have the following scenario:

For table 123:
Index key column A
nonkey columns B,C,D,E,F,G,H

Would it ever make sense to:

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D)

CREATE INDEX IX_2
ON 123 (A)
INCLUDE (E,F,G,H)

vs one:

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D,E,F,G,H)

Thanks!
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10172 Visits: 5155
Hi
The total space of

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D)

and

CREATE INDEX IX_2
ON 123 (A)
INCLUDE (E,F,G,H)

will take more space than

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D,E,F,G,H)

The selectivity of each index is same. You don't need two indexes in this case.
My suggestion is to go with the second option, i.e. the index covering all columns (B,C,D,E,F,G,H).

Regards,
Igor

Igor Micev,
My blog: www.igormicev.com
EricEyster
EricEyster
Right there with Babe
Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)

Group: General Forum Members
Points: 728 Visits: 520
Is the query scanning or seeking on the index? The optimizer will always list the perfect index, but in many cases a close index is good enough. If you are selecting a single record, having the index with just the key column, no includes, will still perform well. Yes, it will do a second lookup to get all the other columns, but if this comes at a cost on in insert/updates as well.
dedicatedtosql
dedicatedtosql
SSC Veteran
SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)

Group: General Forum Members
Points: 269 Visits: 303
CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D,E,F,G,H)



Having one Index as quoted above will make much sense.
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10172 Visits: 5155
EricEyster (2/25/2014)
Is the query scanning or seeking on the index? The optimizer will always list the perfect index, but in many cases a close index is good enough. If you are selecting a single record, having the index with just the key column, no includes, will still perform well. Yes, it will do a second lookup to get all the other columns, but if this comes at a cost on in insert/updates as well.



In both cases in the execution plan you'll see indexes' seeks. The difference is: two seeks if you have the two indexes in cases when queries request columns from the both indexes, and then a merge join; and just one seek if you have one index.
Moreover for the insert/updates, only one index will be updated in the second case. Again the second option is better, depending on your situation, maybe slightly better, but better.

Igor Micev,
My blog: www.igormicev.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)

Group: General Forum Members
Points: 210039 Visits: 41973
Also remember that indexes are simply a sorted duplication of data that will affect nightly maintenance, backup times, backup sizes, restore times, insert times, delete times, and possibly update times. Make sure the index is actually worth it whether it's a covering index or not.

And, the index consolidation that Igor Micev posted should be strongly considered when making covering indexes.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
sqlbuddy123
sqlbuddy123
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5980 Visits: 2243
kimreyj (2/25/2014)
After doing some performance research, it appears that covering index(es) may be beneficial for a couple transactional tables in my database.

My question is this:

Is there ever a benefit to create multiple indexes with different nonkey columns when the key columns are the same?

For instance, if I have the following scenario:

For table 123:
Index key column A
nonkey columns B,C,D,E,F,G,H

Would it ever make sense to:

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D)

CREATE INDEX IX_2
ON 123 (A)
INCLUDE (E,F,G,H)

vs one:

CREATE INDEX IX_1
ON 123 (A)
INCLUDE (B,C,D,E,F,G,H)

Thanks!


Yeah, one index is better. But how did you come up with these indexes ..

Like do you have any slow running queries that are missing these indexes or did you just ran a generic missing indexes report and trying to create indexes that would improve the performance ..

--
SQLBuddy
Spork
Spork
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 247
sqlbuddy123 - I originally ran a report to get the suggested missing indexes.

At this point I am going to make the changes in our dev environment and test performance against a baseline (before indexes) to determine the impact, taking into consideration all the items that Jeff Moden mentioned above...

Thanks.
sqlbuddy123
sqlbuddy123
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5980 Visits: 2243
Yeah, I agree with Jeff and others. But make sure to discuss the same with your application team\developers.

When you run the generic report, you should be very careful in choosing the indexes. Otherwise it may add to the additional maintenance overhead and slow down the performance too ..

--
SQLBuddy
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