Answered by:
Merge with too many indexes.

Question
-
Hi experts,
I have a MERGE statement that it is taking too long… On the execution plan, this is 50% of the workload.
As you can see, I think the MERGE is taking long because it has to update every index… I created the indexes some time ago per requests of people complaining certain reports were slow… I created them as “test…” but never checked how much were they used.
How can I check if they are really used or they are wasting space/resources…?
I also noticed the difference between actual/estimated number of rows, but I don’t see outdated statistics, how come this happens???
Thanks in advance!!
Wednesday, July 20, 2016 10:18 AM
Answers
-
>How can I check if they are really used or they are wasting space/resources…?
sys.dm_db_index_usage_stats (Transact-SQL)
David
- Proposed as answer by Andrea Caldarone Wednesday, July 20, 2016 2:55 PM
- Marked as answer by Lin LengMicrosoft contingent staff Saturday, July 30, 2016 3:03 AM
Wednesday, July 20, 2016 1:21 PM -
Yes, maintaining indexes has a cost.
I guess I never look at update plans, I only look at the plans for the select/where that drives them, or I'd see some horror stories like yours, I have some tables with way too many indexes, because once you have them, yes, they have to be updated, and hope they don't cause you deadlocks as they are.
As to the estimated/actual rows, that tends to increase with the scale of your database, data is often "lumpy" or "spikey" and for some value combinations the statistics are just not fine-grained enough and mistakes are made. SQL Server just does the best it can with what it has. Sometimes an option(recompile) will improve the plan with a fresh "sniff" of the values and less concern about about other values it may encounter - but it can't do much about index updates.
Josh
- Proposed as answer by Lin LengMicrosoft contingent staff Saturday, July 30, 2016 3:03 AM
- Marked as answer by Lin LengMicrosoft contingent staff Sunday, July 31, 2016 3:20 PM
Wednesday, July 20, 2016 2:00 PM
All replies
-
hi, these indexes are very degragmented? did you run some rebuild/reorganize task on them?Wednesday, July 20, 2016 10:24 AM
-
They are not. None of them exceeds 10% of fragmentation...Wednesday, July 20, 2016 11:52 AM
-
>How can I check if they are really used or they are wasting space/resources…?
sys.dm_db_index_usage_stats (Transact-SQL)
David
- Proposed as answer by Andrea Caldarone Wednesday, July 20, 2016 2:55 PM
- Marked as answer by Lin LengMicrosoft contingent staff Saturday, July 30, 2016 3:03 AM
Wednesday, July 20, 2016 1:21 PM -
Yes, maintaining indexes has a cost.
I guess I never look at update plans, I only look at the plans for the select/where that drives them, or I'd see some horror stories like yours, I have some tables with way too many indexes, because once you have them, yes, they have to be updated, and hope they don't cause you deadlocks as they are.
As to the estimated/actual rows, that tends to increase with the scale of your database, data is often "lumpy" or "spikey" and for some value combinations the statistics are just not fine-grained enough and mistakes are made. SQL Server just does the best it can with what it has. Sometimes an option(recompile) will improve the plan with a fresh "sniff" of the values and less concern about about other values it may encounter - but it can't do much about index updates.
Josh
- Proposed as answer by Lin LengMicrosoft contingent staff Saturday, July 30, 2016 3:03 AM
- Marked as answer by Lin LengMicrosoft contingent staff Sunday, July 31, 2016 3:20 PM
Wednesday, July 20, 2016 2:00 PM -
Hello,
implementing the correct index strategy is a job, it can't be explained in a post. Generally speaking every index could help in read (and even in writes) operation but every index has to be mantained i.e. it should be updated when the indexed columns are updated.
sys.dm_db_index_usage_stats
gives you an overview of each index usage, you should take care of the "scan count" and "seek count" counters togheter with the "updates".
Wednesday, July 20, 2016 3:01 PM -
-