I have 2 identical VM (16 vCPU,RAM:64GB) with the same database, same tables and views and same number of lines. View1 has 4.7M lines.
On VM1 (UAT) a SELECT TOP 1000 .. FROM View1
answers in less than 1 s.
On VM2 (PROD) the same query answers in 4 minutes.
I've checked properties of database, tables, view1 and didn't find any difference between VM1 and VM2. I've checked statistics but it shows that nothing has to be refeshed.
The plan of execution on VM2 shows:
- estimated number of executions : 1000
- number of executions : 4.2M
On VM1:
- estimated number of executions : 1000
- number of executions : 900
What could be the problem with VM2 (PROD) that is supposed to be exactly the same than VM1 (UAT)?
Here are the execution plans of "SELECT TOP 1000 .. FROM View1" on both VM :
Execution plans on both VM: UAT and PROD
They seem to be very similar.
Here are UAT vs PROD statistics :
What can explain the huge difference of numbers of logical reads (and read-ahead reads) between the 2 environments ???
By advance, thanks to help me to understand this "mystery".
Eventhough it is two different VM's with same configuration it has lots of differences:
Points 3 and 4 are vital for estimated and actual number of executions and their differences.
For point 3: You can execute below script:
Results UAT & PROD
Do Index rebuild or Reorganize as per below percentages:
avg_fragmentation_in_percent value Corrective statement
https://msdn.microsoft.com/en-us/library/ms189858.aspx
For point 4:
You can run below script:
Which will update your statistics. After that you can check the statistics histogram by using
It has even distribution in both servers which make Query optimizer to select optimal plan.
Considering that both the execution plans are similar. If you post both the execution plans we can find the exact difference.