Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag 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
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

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.
Avatar of 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);
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.
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
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.