February 25, 2014 at 4:00 pm
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!
February 25, 2014 at 4:29 pm
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
February 25, 2014 at 4:46 pm
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.
February 25, 2014 at 4:55 pm
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.
February 25, 2014 at 4:57 pm
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
February 25, 2014 at 5:35 pm
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
Change is inevitable... Change for the better is not.
February 26, 2014 at 10:26 am
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
February 26, 2014 at 11:46 am
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.
February 26, 2014 at 12:13 pm
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
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply