Jewish SQL service shill on G4E

D

Deleted member 26407

Iron
Joined
Feb 11, 2023
Posts
59
Reputation
80
It's still somewhat useful, but they have flooded the internet with these articles

How to build indexes for slow first execution SQL​

You may suffer from SQL statements with a slow first execution time due to the long data cache process. The following SQL is simple that retrieves records from the EMPLOYEE table that if EMP_SALARY < 500000 and the result set is ordered by EMP_NAME.

Select emp_id,
emp_name,
emp_salary,
emp_address,
emp_telephone
from employee
where emp_salary < 500000
order by emp_name;

The following is the query plan that takes 9.51 seconds for the first execution and takes 0.99 seconds for the second execution without data cache.
[IMG]

The SQL cannot be tuned by SQL syntax rewrite or hints injection for both the first execution and the second execution, it is because SQL Server has selected the best query plan for this simple SQL statement. But the problem is that if the condition “where emp_salary < 500000” is changed; say from 500000 to 510000 or the EMPLOYEE data is flushed out from the memory, the execution time will then be prolonged up to 9.51 seconds.

Let’s see if we can build indexes to improve this situation. There is a common perception that a good index can help to improve both the first execution time and the second execution time. So, I use a tool to explore a lot of indexes configurations, but none of them can improve both executions’ performance. Here the following is the performance of the second execution with data cached for different indexes proposed by the tool. You can see the performance of “Index Set 1” is close to the original SQL performance with a little performance variation due to the system’s loading status and all other indexes sets are worse than the original SQL. Normally, we will give up the tuning of the SQL statement without even trying to see whether those recommended indexes are good for the first execution time.

[IMG]

I did a test for those recommended indexes to see whether they are helpful to improve the first execution time, it surprises me that the “Index Set 1” is tested with a significant improvement and improves the first execution time from 9.51 seconds to 0.65 seconds. It is a 14 times improvement that can make my database run more efficiently. So, you should be very careful to tune your SQL with new indexes that may not be good for your second execution with all data cached, but it may be very good for your first execution without data cached.
[IMG]
 
Do you mind to elaborate for us normies out there?
 

Similar threads

mogstars
Replies
2
Views
85
mrdouchebag
mrdouchebag
N
Replies
11
Views
582
Pakicel
P
BrahminBoss
Replies
9
Views
265
zyzzbrah1234
zyzzbrah1234
yandex99
Replies
16
Views
754
Greypiller
Greypiller
albanian_chad
Replies
29
Views
894
Funnyunenjoyer1
Funnyunenjoyer1

Users who are viewing this thread

Back
Top