Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, satheesh.

Asked: December 08, 2014 - 1:44 am UTC

Last updated: January 16, 2024 - 3:12 pm UTC

Version: 11.2

Viewed 10K+ times! This question is

You Asked

Hi Tom,
sorry for asking this dumb question.

This is about how blocks are placed in the buffer cache, Say a 50 GB table is accessed using Full table scan with buffer cache size 20 GB, Does Oracle bring all the blocks of the 50 GB to the buffer cache and produce the required results? Can you explain how this function works?

Thanks

and Tom said...

It depends. We have three basic ways to accomplish reading this table. 1) direct path read, 2) conventional path read using the buffer cache - but only using a small portion of it (since we cannot cache the entire table anyway) and 3) by a conventional path read into the buffer cache but attempting to cache everything we can (by getting rid of the other stuff in the cache)


We could choose the read the table into your PGA bypassing the SGA altogether. This is called a direct path read.

We could choose to read the table via the buffer cache. By default - a large table such as this will be loaded only into a small portion of the buffer cache and aged out quickly so as to not completely flush the buffer cache. So, we'll read a bit of the table, put it into the cache, access and process it from the cache - read another bit and do the same - and flush out some of the earlier bits we read to make room for more (instead of flushing out all of the other stuff we have cached)

You could "alter table t cache" (but probably shouldn't!!!) - and that would cause us to read as much of the table as possible into the buffer cache - flushing out the other blocks that were there. that would be unproductive in this case since only the last 20gb would be in the cache and the next full scan would flush out that 20gb to get the first 20gb of the table into the cache (and then flush that out to get the next 20 and so on)


In the most usual case - the table would be paged into the SGA a small bit at a time and aged out rapidly to make room for another bit of that table. In that fashion - we don't wipe all of the other good stuff out of the cache.

Rating

  (8 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

satheesh nagaraj, December 10, 2014 - 5:57 pm UTC

Thanks Tom for the excellent info.

"put it into the cache, access and process it from the cache - read another bit and do the same - and flush out some of the earlier bits"

Could you please eloborate more on this statement

After processing the first set of data blocks, Oracle will send the results to users and then processing remaining set of blocks in the cache after retrieving from disk? or there the required data will be internally stored and send to application/user after the entire set is processed.
Tom Kyte
December 11, 2014 - 7:28 am UTC

if you have access to Expert Oracle Database architecture, I go into great detail on this.


basically - instead of caching all of the blocks that we can from a large table full table scan - we only let a small portion of the table reside in the buffer cache. In that fashion, a large table full table scan won't have the side effet of "flushing the buffer cache" - removing all of the other tables cached information. We know the large table would consume a lot of the cache - so we do not let it.


the blocks are stored in the cache - they are accessed by any user process that wants them - but they are marked to age out fast since they came in from a full scan.

conventional path read using the buffer cache - but only using a small portion of it

Rajeshwaran Jeyabal, December 17, 2014 - 6:17 am UTC

Tom,

We are able to understand the direct path reads and able to create a testcase for the same
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:3931724600346905308

Can you help us to understand on

#1) which scenario or for which type of queries oracle will use "conventional path read using the buffer cache - but only using a small portion of it" (is that by doing single block IO's)

#2) Which wait events in Tkprof/AWR denotes the table is read by using "conventional path read using the buffer cache - but only using a small portion of it" ? (is that a db file sequential reads ?)
Tom Kyte
December 17, 2014 - 7:03 pm UTC

#1) that happens for all large table full table scans. https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:255215154182

unless you alter that behavior with alter table t cache


#2) db_file_scattered_reads is typically what you will see.

db_file_sequential_reads are single block IOs. db_file_scattered_reads are the multi-block reads we use in full scans.

A reader, December 19, 2014 - 2:53 pm UTC

I was interviewd on the sequential read and scattered read. Can you please explain
db_file_sequential_reads and db_file_scattered_reads
Tom Kyte
December 22, 2014 - 7:42 pm UTC

db file sequential read is a wait event caused by single block IOs. The name comes from the fact that it most often happens by reading a single block from an index sequentially followed by a single block from a table (then index then table then index then table and so on - in sequence)

db file scattered read is a wait event caused by multi-block IO, were we read (typically up to 1mb) a set of blocks at a time, not singly. The name comes from the fact that we read a bunch of blocks and then scatter them in the buffer cache by hashing their dba (data block address - file.block).

A reader, February 26, 2015 - 4:13 pm UTC

thanks. I am back into DBA work again after doing development work for short period of time

where is data stored after it's deletion from the buffer cache

Tom, March 04, 2015 - 10:06 am UTC

Hi Tom,

I'd like to ask the same question as the first reviewer. I understand that the table would be copied to (and removed from) the buffer cache by small chunks, but what we would like to know is what happens to that processed data before it's sent back to the user.
Is it stored somewhere else, or is it returned to the user by chunks too?

Thanks

forms9i

A reader, March 12, 2015 - 3:49 pm UTC

Is forms9i with patchsets compatible with oracle 11g database? Appreciate your help.

A reader, April 08, 2015 - 2:35 pm UTC

Can you please reply my question above? Thanks.

Db blocks in db buffer

Sagar, January 16, 2024 - 11:10 am UTC

When db blocks brought to buffer cache in small chunks from large table, how these data be delivered to the user? in chunks only or fully processed data?
Chris Saxon
January 16, 2024 - 3:12 pm UTC

I'm not sure what you're asking here - please clarify.