Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching SQL execution plans

I know SQL server 2005 does some amount of execution plan caching, but would that be enough to create a difference of hours between the same query being run twice? The first time it takes 3 hours the next time it takes 1 min? Is that even possible?

like image 209
Bmw Avatar asked Jun 30 '26 19:06

Bmw


1 Answers

SQL Server will not just cache the execution plan but also the data

if you do

SET STATISTICS IO ON

and look at the output you will see logical reads and physical reads, logical reads are from RAM, physical reads are from disk. So the first time you will see a number for physical reads while if you run it again you should see a value for logical reads

3 hours seems long, could also be because of blocking/locking, stale stats etc

like image 170
SQLMenace Avatar answered Jul 02 '26 08:07

SQLMenace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!