Oracle Full Table Scan Tips: Full Scan I/O Is Cheaper Than Index I/O
Oracle Full Table Scan Tips: Full Scan I/O Is Cheaper Than Index I/O
This is an excerpt from my latest book "Oracle Tuning: The Definitive Reference".
Remember, for small tables, a full-table scan is better than a full-scan, but a large-
table full-table scan should always be examined as a “possible” problem.
When Oracle reads a table front to back in a full-table scan, we save a great deal of
disk latency. Remember, 95% of the disk latency is the time required for the read-
write head to move itself under the proper cylinder. Once there, the read-write
head sits idle and the platter spins beneath it, and Oracle can read-in data blocks as
fast as the disk platter can spin, a processed called the “db file scattered read”.
Oracle data files that are using Automatic Storage Management (ASM) have
implemented the SAME principle (stripe and mirror everywhere), a RAID-10
combination of disk striping and mirroring. Even though a data file is striped
across many disk spindles, it’s the “stripe size” that mandates how many adjacent
data block reside on disk, and the average latency for full-scan I/O will be
noticeably faster than index access, which Oracle calls “db file sequential read”
operations.
While we see that full-table scans are not evil, they do indeed signal a “possible”
tuning opportunity. Unnecessary large table full-table scans can cause a huge
amount of unnecessary I/O, placing a processing burden on the entire database.
But how to we tell when a large-table full-table scan is evil? One measure is to
compare the number of data block touches (consistent_gets) with the number of
rows returned by the SQL.
Whenever a SQL has a small number of rows are returned, you can compare the
number of rows in the table to the number of rows returned to get a general idea of
the efficiency of a query. Anytime that you see a large-table full-table scan that
fetches less than 20% of the rows in the table, you should investigate further to see
if the full-scan is legitimate, or whether you have a missing index.
Note: These scripts below will only track SQL that you have directed
Oracle to capture via your top SQL settings in AWR or STATSPACK, and
STATSPACK and AWR will not collect "transient SQL" that did not appear
in v$sql at snapshot time.
Hence, not all SQL will appear in these reports. See my notes here on adjusting the SQL
capture thresholds and What SQL is included in AWR/STATSPACK tables?
Figure 15.27: Plot of full scans
With this knowledge, the DBA can anticipate the changes in processing from index access
to LTFTS access by adjusting instance configurations.
Whenever the database changes into a mode dominated by LTFTS, the data buffer sizes,
such as db_cache_size and db_nk_cache_size, can be decreased. Since parallel LTFTS
bypass the data buffers, the intermediate rows are kept in
the pga_aggregate_target region. Hence, it may be desirable to use dbms_scheduler to
anticipate this change and resize the SGA just in time to accommodate the regularly
repeating change in access patterns.
One important use for the AWR tables is tracking table join methods over time.
The Ion tool is also excellent for identifying SQL to tune and it can show SQL
execution over time with stunning SQL graphics.