Buffer cache and plan cache

Mario2286 441 Reputation points
2021-12-06T08:44:18.28+00:00

If I m execute a query for first time which is taking 10 seconds and its fetching 100 GB of data , SQL Server need to fetch from disk the pages and put into buffer cache before come out with results. My question is what will happen, if I m cancelling the query while its executing query within 5 seconds, so I believe few pages might be already in buffer cache ,do SQL Server will flush out the pages and plan which its already in the buffer cache and plan cache or it will remain there in cache although I have cancel the query

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Dan Guzman 9,401 Reputation points
    2021-12-06T12:26:41.403+00:00

    do SQL Server will flush out the pages and plan which its already in the buffer cache and plan cache or it will remain there in cache although I have cancel the query

    Pages will remain in the buffer cache even if the query is cancelled. These will be reused when the query is rerun (assuming they are still in cache) or by other queries needing the same pages.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2021-12-07T03:30:13.72+00:00

    Hi Mario2286-5314,

    Agree with DanGuzman.
    It will remain in the cache. And old and less used data will be cleared when the buffer cache fills up to make room for newer data. Please check Insight into the SQL Server buffer cache which might be helpful.

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.