How to compare two queries?

前端 未结 4 994
面向向阳花
面向向阳花 2021-01-30 14:07

How can I compare two queries X and Y and say that X is better than Y, when they both take almost the same time in small cases scenarios?

The problem is that I have two

4条回答
  •  庸人自扰
    2021-01-30 14:38

    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.

提交回复
热议问题