|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:54 AM
Points: 263,
Visits: 504
|
|
Hi Probly a quick on to answer
Is it the more times you run a query the faster it gets? or is the query plan cached once after the first run and so the query speed should be fairly consitent from the 2nd run onwards?
this probably could have been worded better.
Thanks in advance
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 1:49 AM
Points: 3,123,
Visits: 4,310
|
|
When a query is run for the first time, the plan needs to be generated and cached, taking a bit of time. Thereafter any execution will use the existing cache, provided it has not been flushed. Thus the next execution will be faster than the first, but roughly the same for each execution thereafter
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:54 AM
Points: 263,
Visits: 504
|
|
| thanks for clearing that up :)
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 12:59 PM
Points: 37,640,
Visits: 29,895
|
|
The latter, assuming that the query continues to process the same number of rows each time.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:54 AM
Points: 263,
Visits: 504
|
|
that is unlikely
rows are added continually through out the day to several of the tables involved in the query in question
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:54 AM
Points: 263,
Visits: 504
|
|
just to clarify
will the query plan only be cached when the data in the query is consitent? so each time the data changes the query needs to recache?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 12:59 PM
Points: 37,640,
Visits: 29,895
|
|
No. Only when the data changes are sufficient to trigger a statistics update, as stats updates invalidate cached plans.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 5:55 AM
Points: 1,034,
Visits: 7,660
|
|
It depends. You save on compile time after the first run (which is relatively small for most queries), but the majority of variation in CPU/IO time is more likely to be due to whether the pages to satisfy the query are in the buffer pool or not, which will depend on the amount of memory, the frequency that query is executed, other workloads on the system and the runtime parameters.
Elapsed time can obviously be much more variable based on other load on the server, concurrency,locking etc.
|
|
|
|