Description:

            A full index scan is where Oracle reads the data from the index, and the index is in the order required by the query. A fast full index scan is similar to a full index scan. This type of scan happens when the data in the index is in no particular order.

Full Table Scan (FTS)

²FTS scans the entire table to fetch the results i.e., reads the every row of the table to find all records meeting the given requirements

²Even if the query selects just a few rows from the table, all rows in the entire table will be examined

²Table scan on larger tables take an excessive amount of time and cause performance problem

Following are the situations where optimizer chooses Full Table Scans:-

lLack of Index.

lThe query predicate applies a function to the indexed column.

lSelect COUNT(*) with B-Tree indexes & Nulls.

lLarge Amount of Data

lSmall Table

lHigh Degree of Parallelism

lFTS Hint

lThe table statistics are stale.

lThe query predicate does not use the leading edge of a B-tree index.

lThe query is unselective.

Pros:

lThe cost is predictable, as every time the database system needs to scan full table row by row.

lWhen table is less than 2 percent of database block buffer; then full scan table is quicker.

Cons:

lFull table scan occurs when there is no index or index is not being used by SQL. And the result of the full scan table is usually slower than index table scan. The situation is that: the larger the table, the slower the data returns.

lUnnecessary full-table scan will lead to a huge amount of unnecessary I/O with a process burden on the entire database.

Index Scan

²The Index Scans is an access path used by the query optimizer to produce the best Sql Engine – (Physical|Execution) Plan.

²In this method, a row is retrieved by traversing the index, using the indexed column values specified by the statement

²An index scan retrieves data from an index based on the value of one or more columns in the index.

²To perform an index scan; Oracle searches the index for the indexed column values accessed by the statement

²If the statement accesses only columns of the index, then Oracle reads the indexed column values directly from the index rather than from the table.

The index contains :

not only the indexed value,

but also the rowids of rows in the table having that value.

Therefore, if the statement accesses other columns in addition to the indexed columns, then Oracle can find the rows in the table by using either a table access by rowid or a Cluster Scan/Access.

An index scan can be one of the following types:

nIndex Unique Scans

This scan returns, at most, a single rowid. Oracle performs a unique scan if a statement contains a UNIQUE or a PRIMARY KEY constraint that guarantees that only a single row is accessed.

Example

An index scan is performed on the jobs and department tables, using the job_id_pk  and dept_id_pk indexes, respectively.

nIndex Range Scans

An index range scan is a common operation for accessing selective data.  It can be bounded (bounded on both sides) or unbounded (on one or both sides). Data is returned in the ascending order of index columns. Multiple rows with identical values are sorted in ascending order by rowid.

If data must be sorted by order, then use the ORDER BY clause, and do not rely on an index. If an index can be used to satisfy an ORDER BY clause, then the optimizer uses this option and avoids a sort.

Example 

In this example, the order has been imported from a legacy system, and you are querying the order by the reference used in the legacy system. Assume this reference is the order_date.

This should be a highly selective query, and you should see the question using the index on the column to retrieve the desired rows. The data returned is sorted in ascending order by the rowids for the order_date. Because the index column order_date is identical for the selected rows here, the data is sorted by rowid.

nIndex Range Scans Descending

An index range scan descending is identical to an index range scan, except that the data is returned in descending order. Indexes, by default, are stored in ascending order. Usually, this scan is used when ordering data in a descending order to return the most recent data first, or when seeking a value less than a specified value.

nIndex Skip Scans

Index skip scans improve index scans by non-prefix columns. Often,   scanning index blocks is faster than scanning table data blocks.

Skip scanning lets a composite index be split logically into smaller sub-indexes. In skip scanning, the initial column of the composite index is not specified in the query. In other words, it is skipped.

The number of logical sub-indexes is determined by the number of distinct values in the initial column. Skip scanning is advantageous if there are few different values in the leading column of the composite index and many distinct values in the non-leading key of the index.

Consider, for example, a table employees (sex, employee_id, address) with a  composite index on (sex, employee_id). Splitting this composite index would result in two logical sub-indexes, one for M and one for F.

For this example, suppose you have the following index data:

The index is split logically into the following two sub-indexes:

lThe first sub-index has the keys with the value F.

lThe second sub-index has the keys with the value M.

lThe column sex is skipped in the following query:

A complete scan of the index is not performed, but the sub-index with the value F is searched first, followed by a search of the sub-index with the value M.

nFull Index Scan

A full index scan eliminates a sort operation, because the data is ordered by the index key. It reads the blocks singly. A full scan is used in any of the   following situations:

An ORDER BY clause that meets the following requirements is present in the  query:

All of the columns in the ORDER BY clause must be in the index.

The order of the columns in the ORDER BY clause must match the order of the leading index columns.

The ORDER BY clause can contain all of the columns in the index or a subset of the columns in the index.

The query requires a sort-merge join. A full index scan can be done instead  of doing a full table scan followed by a sort if the query meets the following  requirements:

All of the columns referenced in the query must be in the index.

The order of the columns referenced in the query must match the order of the leading index columns.

The query can contain all of the columns in the index or a subset of the columns in the index.

A GROUP BY clause is present in the query, and the columns in the GROUP  BY clause are present in the index. The columns do not need to be in the same order in the index and the GROUP BY clause. The GROUP BY clause can contain all of the columns in the index or a subset of the columns in the index.

nFast Full Index Scans

Fast full index scans are an alternative to a full table scan when the index contains all the columns that are needed for the query, and at least one column in the index key has the NOT NULL constraint. A fast full scan accesses the data in the index itself, without accessing the table. It cannot be used to eliminate a sort operation, because the data is not ordered by the index key. It reads the entire index using multiblock reads, unlike a full index scan, and can be parallelized.

Fast full index scans cannot be performed against bitmap indexes.

A fast full scan is faster than a normal full index scan in that it can :

use multiblock I/O

and be parallelized, just like a table scan.

Note: Setting PARALLEL for indexes will not impact the cost calculation.

You can specify fast full index scans with the initialization parameter OPTIMIZER_FEATURES_ENABLE or the INDEX_FFS hint.

nIndex Joins

An index join is a hash join of several indexes that together contain all the table columns that are referenced in the query. If an index join is used, then notable access is needed, because all the relevant column values can be retrieved from the indexes. An index join cannot be used to eliminate a sort operation.

nBitmap Indexes

A bitmap join uses a bitmap for key values and a mapping function that converts each bit position to a rowid. Bitmaps can efficiently merge indexes that correspond to several conditions in a WHERE clause, using Boolean operations to resolve AND and OR conditions.

Partition Range Scan

²Oracle optimizes partitioned queries differently than regular queries.

²Oracle tries to pick the fastest elapsed time to the data, not the lowest cost.

²The Optimizer typically scans partitions first

²Scans only relevant partitions (called pruning)

²Try to avoid functions on partitioning key values in WHERE clauses

²Try to avoid subqueries on partitioning key values

²Maybe avoid indexes on partitioning keys (Oracle uses efficient multi-block scans with fewer I/O than using indexes and single block reads)

²Want to avoid “long ops” operations

²Oracle Parallel Server and RAC instances can break a SQL up across processors and return the pieces for a much faster response time on larger objects.

²Consider where your data is in the partitioned object. If the selected rows are across the partition, it might be considerably faster to do a full-table scan (using multi-block read-ahead, of course) than to do single block reads, even on a local-partitioned index.

Summary:

Overview. In a database, a query that is not indexed results in a full table scan, where the database processes each record of the table to find all records meeting the given requirements. Even if the query selects just a few rows from the table, all rows in the entire table will be examined.

Queries?

Do drop a note by writing us at doyen.ebiz@gmail.com or use the comment section below to ask your questions.

Recent Posts

Start typing and press Enter to search