Avatar of Mike Eghtebas
Mike Eghtebas
Flag for United States of America asked on

Client Statistics Explanations...

The attached image shows Execution Plan/ Client Statistics for this query:
select distinct AnalyteCode, Analyte
from LabAnalyteData
Order By AnalyteCode

Open in new window

Q1: What indexes would you recommend to be added to improve its performance?

Maybe: CREATE INDEX index_Analyte_LabAnalyteData ON LabAnalyteData (Analyte);

But what if I add the following index; is there still a need to add additional indexes?
CREATE INDEX index_FK_IDinAccess_LabAnalyteData ONLabAnalyteData (IDinAccess, AnalyteCode, Analyte, ConcentrationLevelUnit);

Q2: On the Client Statistics, what do Trial 1, Trial 2, and Trial 3 mean?
Client-Statistics.png
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
Vitor Montalvão

Q1: What indexes would you recommend to be added to improve its performance?
CREATE INDEX index_Analyte_LabAnalyteData ON LabAnalyteData (AnalyteCode, Analyte);

Q2: On the Client Statistics, what do Trial 1, Trial 2, and Trial 3 mean?
Means how many times you ran the query. Trial 2 used the cache since data still accessible from Trial 1.
Mike Eghtebas

ASKER
Vitor,

But what if I add the following index; is there still a need to add additional indexes?
CREATE INDEX index_FK_IDinAccess_LabAnalyteData ONLabAnalyteData (IDinAccess, AnalyteCode, Analyte, ConcentrationLevelUnit);

Do we still need:
CREATE INDEX index_Analyte_LabAnalyteData ON LabAnalyteData (AnalyteCode, Analyte);
Vitor Montalvão

You should add only the strictly necessary columns. Why add columns that aren't used by the query?
Also, I'm commenting only based on the query you posted. I don't know the schema of your table and also don't know the rest of the queries that table are part of.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike Eghtebas

ASKER
To better state what I have. Assuming I already have:

CREATE INDEX index_FK_IDinAccess_LabAnalyteData ONLabAnalyteData (IDinAccess, AnalyteCode, Analyte, ConcentrationLevelUnit);

Is it still necessary to have:
CREATE INDEX index_Analyte_LabAnalyteData ON LabAnalyteData (AnalyteCode, Analyte);
ASKER CERTIFIED SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Arifhusen Ansari

what i think is, if you are not providing any criteria in where clause.
Query execution plan will use clustered index by default because at the it need to get all the row.
So it's better to scan clustered index.
And in your case index_FK_IDinAccess_LabAnalyteData might not be clustered index and in fact "PK_labAnalyteID" is clustered.
Even if you create CREATE INDEX index_Analyte_LabAnalyteData ON LabAnalyteData (Analyte) and do not provided any where clause. It will use that "PK_labAnalyteID" index.


Vitor Montalvão please have some comment on this.
Vitor Montalvão

It depends. The engine will always calculate and chose the operation with less cost. If you increase exponentially the number of records the engine may chose another index. Usually with very few records a scan is chosen instead of seek and this could be the case.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.