November 8, 2018 at 10:43 am
Jonathan AC Roberts - Thursday, November 8, 2018 10:36 AMJeff Moden - Thursday, November 8, 2018 10:25 AMJonathan AC Roberts - Thursday, November 8, 2018 10:15 AMJeff Moden - Thursday, November 8, 2018 10:12 AMAER - Thursday, November 8, 2018 10:05 AMThanks for all your replies.
I know that is not the simple question; that's why I was asking help from DBAs.I am myself is a production DBA and know what happens in theory but wanted some good practical advice on having 1 or 2 indexes in my case.
So when I mentioned that both queries are heavily used I really meant it. And when I mentioned the columns they are all used in the order that I placed them in my question.I have scripts to identify the needed indexes, but not sure if there are good scripts out there, that would tell you that any particular index degrades the performance.
That's why I was asking if I need both indexes.
I kind of agree with John's answer.
Any additional thoughts? Maybe anybody can point to the good script that will show the indexes that harm the database performance?Thank you, again
Yes... having scripts to identify the needed indexes sometimes don't tell the whole story. What does the ACTUAL EXCECUTION PLAN state for these two queries insofar as whether or not the indexes are being used effectively (that key lookup thing and seek/scan thing again) and what is the actual performance measurements for reads, CPU, writes, and, most importantly, duration?
You could run some test calls with the index with columns 1,2 existing and after dropping it.
Use this at the top of your code:SET STATISTICS IO, TIME ON
Then look at the results. It may well be that there is not enough of a performance difference to justify two indexes.Just don't use SET STATISTICS if any scalar or mTVF functions are involved. Either will cause SET STATISTICS to report absolute horror. Please see the following article for demonstrable proof of that.
http://www.sqlservercentral.com/articles/T-SQL/91724/I'm also not sure how any XML functionality will affect SET STATISTICS because I try to avoid XML like the plague.
Even if you have a scalar function or mTVF and you are comparing tests both with and without the index you should still see if there is a difference as they both would be slowed by the same amount by the set statistics.
The trouble is that SET STATISTICS skews things so badly that the differences will usually not be apparent.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 9, 2018 at 3:18 am
/* Indexing Queries
Nicked from Glenn Berry with minor mods.
If you want to study a particular group of tables,
enter their names in the INSERT statement and set @UseFilter = 1
*/
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 9, 2018 at 3:28 am
/*
ChrisM 2013-2016
Get stored procedure execution stats from sys.dm_exec_procedure_stats,
augment with useful information. Filters can be applied in two places
to reduce the size of the result set.
- see when something was last executed
- see how often something is executed
- find out how expensive something is
- identify the most expensive statements in a stored procedure
- check the plan for tuning opportunities
*/
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 9, 2018 at 8:44 am
To make the task a bit shorter, you could do the proverbial "Hail Mary" play... disable (not drop) the shorter index and simply see what happens. As they say, "One good test is worth a thousand expert opinions". Just make sure that it's not a UNIQUE index, which may have some other tentacles for other things.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 9, 2018 at 9:55 am
Everybody,
Thanks for your thorough and valid advices.
Your help is greatly appreciated.
Alex
November 9, 2018 at 4:43 pm
https://sqlinthewild.co.za/index.php/2009/01/19/index-columns-selectivity-and-equality-predicates/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 9, 2018 at 5:43 pm
AER - Thursday, November 8, 2018 10:05 AMThanks for all your replies.
I know that is not the simple question; that's why I was asking help from DBAs.I am myself is a production DBA and know what happens in theory but wanted some good practical advice on having 1 or 2 indexes in my case.
So when I mentioned that both queries are heavily used I really meant it. And when I mentioned the columns they are all used in the order that I placed them in my question.I have scripts to identify the needed indexes, but not sure if there are good scripts out there, that would tell you that any particular index degrades the performance.
That's why I was asking if I need both indexes.
I kind of agree with John's answer.
Any additional thoughts? Maybe anybody can point to the good script that will show the indexes that harm the database performance?Thank you, again
I see a lot of great suggestions over here!
I would also suggest you to use Brent Ozar's sp_BlitzCache https://www.brentozar.com/blitzcache/
it is supplying you heap of useful info including exec plans.
goodluck
November 12, 2018 at 5:52 am
Jeff Moden - Thursday, November 8, 2018 10:43 AMThe trouble is that SET STATISTICS skews things so badly that the differences will usually not be apparent.
100% agreement with Jeff on this. I only use SET STATISTICS IO when I'm worried about individual object IO behavior. Otherwise, I always use extended events to capture query performance. Based on lots and lots of experimentation, it has the lowest observer overhead (depending on what you're capturing, the system, the transactions, your filtering, etc.).
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 12, 2018 at 6:23 am
Grant Fritchey - Monday, November 12, 2018 5:52 AMJeff Moden - Thursday, November 8, 2018 10:43 AMThe trouble is that SET STATISTICS skews things so badly that the differences will usually not be apparent.
100% agreement with Jeff on this. I only use SET STATISTICS IO when I'm worried about individual object IO behavior. Otherwise, I always use extended events to capture query performance. Based on lots and lots of experimentation, it has the lowest observer overhead (depending on what you're capturing, the system, the transactions, your filtering, etc.).
Just to be clear, I've not given up on SET STATISTICS TIME, IO. It works great (especially for performance comparisons of two or more sets of code to compare) if you don't have the likes of Scalar or mTVF functions in the mix. There may be other things that also cause such a skew but I've not found them yet.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply