How to compare two queries?

SET STATISTICS IO ON
SET STATISTICS TIME ON

Run the queries and compare logical reads for the various tables and execution times.


As already mentioned, check the execution plans.

Importantly, compare the 2 queries fairly by clearing the cache down between each run, just to make sure you're not seeing skewed results due to the effect of data already being cached (don't run on production server):

DBCC DROPCLEANBUFFERS -- clear data cache
DBCC FREEPROCCACHE -- clear proc plan cache

Then what I usually do is check the Reads, Writes, CPU and Duration for a comparison.

It's very important that you test with production-level data volumes (and ideally greater to see how it will scale). It's at those volumes that you'll really see any performance difference. Testing with small data volumes could leave you open to problems later on.


Have you examined the query plans? If the queries are returning the same data and are taking the same amount of time to execute, my guess is that the query plans will be nearly identical meaning that there is no meaningful difference between the two queries.

Also, have you taken into account that queries perform differently as the database size changes?

I'm wondering if you are prematurely optimizing the code. In my mind, if I have a query that works and is understandable, I can address performance issues through indexes. And that is usually easier than changing the queries to improve performance.