Sequential prefetching
Reading several consecutive pages into the buffer pool using a single I/O operation can greatly reduce your application overhead.
SELECT NAME FROM EMPLOYEE
With smart data and smart index prefetching, both sequential and readahead prefetching is enabled, which is the default. Sequential detection prefetching is initially used until a threshold of non-prefetched pages is reached or, in some cases, if the MAXPAGES estimate made by the optimizer is exceeded. When the threshold of non-prefetched pages is reached or if the MAXPAGES estimate is exceeded, readahead prefetching is enabled.
Sequential detection
Sometimes, it is not immediately apparent that sequential prefetching will improve performance. In such cases, the database manager can monitor I/O and activate prefetching if sequential page reading is occurring. This type of sequential prefetching, known as sequential detection, applies to both index and data pages. Use the seqdetect database configuration parameter to control whether the database manager performs sequential detection or readahead prefetching.
SELECT NAME FROM EMPLOYEE
WHERE EMPNO BETWEEN 100 AND 3000
In this example, the
optimizer might have started to scan the table using an index on the
EMPNO column. If the table is highly clustered with respect to this
index, the data page reads will be almost sequential, and prefetching
might improve performance. Similarly, if many index pages must be
examined, and the database manager detects that sequential page reading
of the index pages is occurring, index page prefetching is likely.Implications of the PREFETCHSIZE option for table spaces
The PREFETCHSIZE clause on either the CREATE TABLESPACE or the ALTER TABLESPACE statement lets you specify the number of prefetched pages that will be read from the table space when data prefetching is being performed. The value that you specify (or 'AUTOMATIC') is stored in the PREFETCHSIZE column of the SYSCAT.TABLESPACES catalog view.
It is good practice to explicitly set the PREFETCHSIZE value as a multiple of the number of table space containers, the number of physical disks under each container (if a RAID device is used), and the EXTENTSIZE value (the number of pages that the database manager writes to a container before it uses a different container) for your table space. For example, if the extent size is 16 pages and the table space has two containers, you might set the prefetch size to 32 pages. If there are five physical disks per container, you might set the prefetch size to 160 pages.
The database manager monitors buffer pool usage to ensure that prefetching does not remove pages from the buffer pool if another unit of work needs them. To avoid problems, the database manager can limit the number of prefetched pages to be fewer than what was specified for the table space.
- There are I/O waits for your query, using monitoring tools that are available for your operating system
- Prefetching is occurring, by looking at the pool_async_data_reads (buffer pool asynchronous data reads) data element provided by the database system monitor
If there are I/O waits while a query is prefetching data, you can increase the value of PREFETCHSIZE. If the prefetcher is not the cause of these I/O waits, increasing the PREFETCHSIZE value will not improve the performance of your query.
In all types of prefetching, multiple I/O operations might be performed in parallel if the prefetch size is a multiple of the extent size for the table space, and the extents are in separate containers. For better performance, configure the containers to use separate physical devices.