queries running faster after cached in the query plan

  • 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

  • This was removed by the editor as SPAM

  • thanks for clearing that up 🙂

  • The latter, assuming that the query continues to process the same number of rows each time.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    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
  • that is unlikely

    rows are added continually through out the day to several of the tables involved in the query in question

  • 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?

  • 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, MVP, M.Sc (Comp Sci)
    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
  • 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.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply