SQL Disk to Memory

  • Hi all

    I have a quick question regarding pages moving from disk into memory

    If I select * from a table, are all pages that make up the table and indexes moved into memory?

    So any subsequent query against that same table would not need to go to disk at all?

    Thanks

  • SQLSACT (9/25/2012)


    Hi all

    I have a quick question regarding pages moving from disk into memory

    If I select * from a table, are all pages that make up the table and indexes moved into memory?

    So any subsequent query against that same table would not need to go to disk at all?

    Thanks

    for select * there is no index and yes, all data pages would be cached into memory

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Perry Whittle (9/25/2012)


    SQLSACT (9/25/2012)


    Hi all

    I have a quick question regarding pages moving from disk into memory

    If I select * from a table, are all pages that make up the table and indexes moved into memory?

    So any subsequent query against that same table would not need to go to disk at all?

    Thanks

    for select * there is no index and yes, all data pages would be cached into memory

    Doesn't it depend on there being space for the whole table in cache?

  • laurie-789651 (9/25/2012)


    Perry Whittle (9/25/2012)


    SQLSACT (9/25/2012)


    Hi all

    I have a quick question regarding pages moving from disk into memory

    If I select * from a table, are all pages that make up the table and indexes moved into memory?

    So any subsequent query against that same table would not need to go to disk at all?

    Thanks

    for select * there is no index and yes, all data pages would be cached into memory

    Doesn't it depend on there being space for the whole table in cache?

    yes of course, otherwise spill will happen

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Perry Whittle (9/25/2012)


    laurie-789651 (9/25/2012)


    Perry Whittle (9/25/2012)


    SQLSACT (9/25/2012)


    Hi all

    I have a quick question regarding pages moving from disk into memory

    If I select * from a table, are all pages that make up the table and indexes moved into memory?

    So any subsequent query against that same table would not need to go to disk at all?

    Thanks

    for select * there is no index and yes, all data pages would be cached into memory

    Doesn't it depend on there being space for the whole table in cache?

    yes of course, otherwise spill will happen

    Thanks

    Spill?

  • to TempDB

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Perry Whittle (9/25/2012)


    to TempDB

    Thanks

    So if a query is submitted to SQL and the pages need to be brought into memory from disk and there is not enough memory to accomodate those pages, SQL pushes is into tempdb, right?

    Does is just push the pages that wouldn't fit in memory into tempdb or does it fulfill the entire transactions pages?

    Is this where memory pressure in SQL server comes from?

    Thanks

  • Perry Whittle (9/25/2012)


    to TempDB

    The buffer pool never spills to TempDB.

    If pages are read in from disk for a table and there's not space in the buffer pool, other pages will be removed from it, maybe even pages of the same table that have already been read by the query processor.

    What spills to tempDB are sorts, hashes, exchanges, spools (though they're temp structures anyway, so they can't exactly be said to spool).

    Temp tables will be written to TempDB if necessary

    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
  • SQLSACT (9/25/2012)


    So if a query is submitted to SQL and the pages need to be brought into memory from disk and there is not enough memory to accomodate those pages, SQL pushes is into tempdb, right?

    No. If pages are needed in memory and there's not enough space in the buffer pool, other data pages will be removed from the buffer pool to make space. The algorithm that is used to determine which pages to evict is roughly an LRU-2, but there are complexities and cases where pages can be removed from cache immediately after they are read in and used.

    It is entirely possible, for a scan of a large table on a server with little memory, for the pages of that table to be read in, the rows on those pages processed by the query processor and then those pages removed from memory to make space for more pages from the same table.

    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
  • thanks I stand corrected

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • GilaMonster (9/26/2012)


    SQLSACT (9/25/2012)


    So if a query is submitted to SQL and the pages need to be brought into memory from disk and there is not enough memory to accomodate those pages, SQL pushes is into tempdb, right?

    No. If pages are needed in memory and there's not enough space in the buffer pool, other data pages will be removed from the buffer pool to make space. The algorithm that is used to determine which pages to evict is roughly an LRU-2, but there are complexities and cases where pages can be removed from cache immediately after they are read in and used.

    It is entirely possible, for a scan of a large table on a server with little memory, for the pages of that table to be read in, the rows on those pages processed by the query processor and then those pages removed from memory to make space for more pages from the same table.

    Thanks

    If my buffer pool is never under pressure and there is sufficient memory for even my heaviest workload, is it safe to say that pages are never taken out of memory again, they'll just stay there until SQL is restarted?

    Thanks

  • Maybe, but maybe not. Older pages may still get tossed out.

    Unless you have buffer pool > total size of all DBs in use, you can't assume that there will be no page evictions. Also, data cache is not the only cache in the buffer pool, there are quite a few others, and then there's workspace memory needed for queries, etc

    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
  • GilaMonster (9/26/2012)


    Maybe, but maybe not. Older pages may still get tossed out.

    Unless you have buffer pool > total size of all DBs in use, you can't assume that there will be no page evictions. Also, data cache is not the only cache in the buffer pool, there are quite a few others, and then there's workspace memory needed for queries, etc

    Thanks

    This whole post is under the assumption that we're only querying data, we are not doing any Inserts, Updates or Deletes, right?

    The process would be different?

    Thanks

  • SQLSACT (9/26/2012)


    This whole post is under the assumption that we're only querying data, we are not doing any Inserts, Updates or Deletes, right?

    No, not really.

    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
  • SQLSACT (9/26/2012)


    GilaMonster (9/26/2012)


    Maybe, but maybe not. Older pages may still get tossed out.

    Unless you have buffer pool > total size of all DBs in use, you can't assume that there will be no page evictions. Also, data cache is not the only cache in the buffer pool, there are quite a few others, and then there's workspace memory needed for queries, etc

    Thanks

    This whole post is under the assumption that we're only querying data, we are not doing any Inserts, Updates or Deletes, right?

    The process would be different?

    Thanks

    For the scenario in which the whole table is in buffer i dont think there wont be much difference . Please correct me if wrong.

Viewing 15 posts - 1 through 15 (of 24 total)

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