Index scans & cache usage

  • Hi

    In SQL Server, are "index trees" also stored in the buffer cache? for example, if I ran a query and XYZ non-clustered index is used, I may get something like this:

    Table 'tc'. Scan count 1, logical reads 6, physical reads 6, read-ahead reads 0.

    If I run the query again (dont clean the buffers), I get:

    Table 'tc'. Scan count 1, logical reads 6, physical reads 0, read-ahead reads 0.

    So, as an index is a physical data structure, its also being read into the buffer cache including all its associated header, branch, and leaf node information. My questions are:

    a) Is the buffer cache the place it index resides?

    b) What I described above, is it correct?

    Cheers

    Chris


    Chris Kempster
    www.chriskempster.com
    Author of "SQL Server Backup, Recovery & Troubleshooting"
    Author of "SQL Server 2k for the Oracle DBA"

  • I beleive yes and yes, but I can't point you to a specific ref.

    Steve Jones

    steve@dkranch.net

  • Chris, one thing you can do is check syscacheobjects between the first and second times you run the query to see if an entry got added that is applicable. Something more to test with respect to caching...

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://qa.sqlservercentral.com/columnists/bkelley/

    Edited by - bkelley on 01/29/2002 12:16:44 PM

    K. Brian Kelley
    @kbriankelley

  • ill give it a look 🙂


    Chris Kempster
    www.chriskempster.com
    Author of "SQL Server Backup, Recovery & Troubleshooting"
    Author of "SQL Server 2k for the Oracle DBA"

  • Also keep in mind the way Microsoft uses query execution plans. They remain in memory until that have not been used recently and enough other changes have occurred (which it can tell by statistics and of course quires run more recently and often than the one in question). The query plan helps the stored query return faster after the first run, as it serves a guide map to the way to access the data. Just make a change to you query and the return to previous to see how it further changes the statistics.

  • The lazywriter process takes care of getting rid of old execution plans, but it doesn't get enacted unless it needs to reclaim the memory, either because another application starts up requiring the memory and the OS issues a request, or there has been enough activity such that SQL Server is forced to reclaim memory from the memory pool that it has. The lazywriter does this both for the procedure cache as well as the buffer cache since from SQL Server 7.0 on they share the same dynamic memory pool (along with connection settings, etc.)

    However, what Chris is getting at is the fact that SQL Server has read from disk the first time (the physical reads), and brought the information into cache. The second time the query is run, it then returns that it didn't execute a single physical read. Data is stored in the buffer cache, but what he's after is whether or not the index tree is as well.

    Chris, upon going back and looking at some things, you are indeed right, the index pages are in the buffer cache (which I think means you won't find any reference to it in syscacheobjects, silly me). From Inside SQL Server 2000:

    quote:


    The main memory component in SQL Server is the buffer pool; all memory not used by another memory component remains in the buffer pool. The buffer manager manages disk I/O functions for bringing data and index pages into the buffer pool so that data can be shared among users. When other components require memory, they can request a buffer from the buffer pool. A buffer is a page in memory that's the same size as a data or index page. You can think of it as a page frame that can hold one page from a database.


    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://qa.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • Hi all

    Thanks for the input, Ive picked up a few things already, is there a way of dumping the buffer cache contents? (probably a trace number).

    Cheers

    Chris


    Chris Kempster
    www.chriskempster.com
    Author of "SQL Server Backup, Recovery & Troubleshooting"
    Author of "SQL Server 2k for the Oracle DBA"

  • dbcc freebuffers or something like that. Search for it.

    Steve Jones

    steve@dkranch.net

  • Hi,

    HAs anyone managed to get this working? I have tried, but I don't get anything back! Just

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    No output. I set up a loop too select in a loop, and examine the buffer at the same time, but I still couldn't see anything.

    Any help would be much appreciated.

    R

  • Please ignore my posting. I've just realised I didn't set the trace.

    Sorry!!

Viewing 11 posts - 1 through 10 (of 10 total)

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