Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 - About
The Index Scans is a access path used by the query optimizer to produce the best Oracle Database
- (Execution|Query) 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 :
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:
Although the index clustering factor is a property of the index, the index clustering factor actually
relates to the spread of similar indexed column values within data blocks in the table.
A lower clustering factor indicates that the individual rows are concentrated within fewer blocks
in the table. Conversely, a high clustering factor indicates that the individual rows are scattered
more randomly across blocks in the table. Therefore, a high clustering factor means that it costs
more to use a range scan to fetch rows by rowid, because more blocks in the table need to be
visited to return the data.
Case 1: The index clustering factor is low for the rows as they are arranged in the following
diagram.
Block 1
------A A A
Block 2
------B B B
Block 3
-------C C C
This is because the rows that have the same indexed column values for c1 are located within the
same physical blocks in the table. The cost of using a range scan to return all of the rows that
have the value A is low, because only one block in the table needs to be read.
Case 2: If the same rows in the table are rearranged so that the index values are scattered across
the table blocks (rather than collocated), then the index clustering factor is higher.
Block 1
------A B C
Block 2
------A B C
Block 3
-------A B C
This is because all three blocks in the table must be read in order to retrieve all rows with the
value A in col1.
Example :
----------------------------------------------------------------------------------| Id | Operation
| Name
3 | 189 |
10 (10)|
| 1 | NESTED LOOPS
3 | 189 |
10 (10)|
| 2 | NESTED LOOPS
3 | 141 |
7 (15)|
|* 3 |
| 4|
|* 5 |
| EMPLOYEES
| JOB_ID_PK
3|
|
19 | 513 |
1|
| DEPT_ID_PK |
60 |
1|
4 (25)|
2 (50)|
|
27 | 432 |
|
2 (50)|
-----------------------------------------------------------------------------------
An index scan is performed on the jobs and departments tables, using the job_id_pk and
dept_id_pk indexes respectively.
4.1 - 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.
SELECT order_status, order_id
FROM orders
WHERE order_date = :b1;
--------------------------------------------------------------------------------------| Id | Operation
| Name
1|
20 |
|
| ORD_ORDER_DATE_IX |
1|
1|
3 (34)|
20 |
3 (34)|
2 (50)|
---------------------------------------------------------------------------------------
This should be a highly selective query, and you should see the query 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.
col1 = :b1
col1 < :b1
col1 > :b1
AND combination of the preceding conditions for leading columns in the index
col1 like 'ASD%' wild-card searches should not be in a leading position otherwise the
condition col1 like '%ASD' does not result in a range scan.
Range scans can use unique or non-unique indexes. Range scans avoid sorting when index columns
constitute the ORDER BY/GROUP BY clause.
6.1 - Example
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 subindexes, one for
M and one for F.
For this example, suppose you have the following index data:
('F',98)
('F',100)
('F',102)
('F',104)
('M',101)
('M',103)
('M',105)
A complete scan of the index is not performed, but the subindex with the value F is searched first,
followed by a search of the subindex with the value M.
7 - Full Scans
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:
o All of the columns in the ORDER BY clause must be in the index.
o 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:
o All of the columns referenced in the query must be in the index.
o 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.
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.
9 - Index 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 no table 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.
You can specify an index join with the INDEX_JOIN hint.
10 - Bitmap 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