Types of index access
In some cases, the optimizer might find that all of the
data that a query requires can be retrieved from an index on the table.
In other cases, the optimizer might use more than one index to access
tables. In the case of range-clustered tables, data can be accessed
through a virtual
index, which computes the location of data
records.
Index-only access
INDEX IX1: NAME ASC,
DEPT ASC,
MGR DESC,
SALARY DESC,
YEARS ASC
The following query can be satisfied
by accessing only the index, without reading the base table: select name, dept, mgr, salary
from employee
where name = 'SMITH'
create unique index ix1 on employee
(name asc)
include (dept, mgr, salary, years)
This index enforces
the uniqueness of the NAME column and also stores and maintains data
for the DEPT, MGR, SALARY, and YEARS columns. In this way, the following
query can be satisfied by accessing only the index: select name, dept, mgr, salary
from employee
where name = 'SMITH'
Be sure to consider whether the additional storage space and maintenance costs of include columns are justified. If queries that exploit include columns are rarely executed, the costs might not be justified.
Multiple-index access
INDEX IX2: DEPT ASC
INDEX IX3: JOB ASC,
YEARS ASC
The following predicates can
be satisfied by using these two indexes: where
dept = :hv1 or
(job = :hv2 and
years >= :hv3)
Scanning index IX2 produces
a list of record IDs (RIDs) that satisfy the dept = :hv1
predicate.
Scanning index IX3 produces a list of RIDs that satisfy the job
= :hv2 and years >= :hv3
predicate. These two lists of
RIDs are combined, and duplicates are removed before the table is
accessed. This is known as index ORing.
where
dept in (:hv1, :hv2, :hv3)
INDEX IX4: SALARY ASC
INDEX IX5: COMM ASC
can be used to resolve the following
predicates: where
salary between 20000 and 30000 and
comm between 1000 and 3000
In this example,
scanning index IX4 produces a bitmap that satisfies the salary
between 20000 and 30000
predicate. Scanning IX5 and probing
the bitmap for IX4 produces a list of qualifying RIDs that satisfy
both predicates. This is known as dynamic bitmap ANDing.
It occurs only if the table has sufficient cardinality, its columns
have sufficient values within the qualifying range, or there is sufficient
duplication if equality predicates are used.
To realize the performance benefits of dynamic bitmaps when scanning multiple indexes, it might be necessary to change the value of the sortheap database configuration parameter and the sheapthres database manager configuration parameter. Additional sort heap space is required when dynamic bitmaps are used in access plans. When sheapthres is set to be relatively close to sortheap (that is, less than a factor of two or three times per concurrent query), dynamic bitmaps with multiple index access must work with much less memory than the optimizer anticipated. The solution is to increase the value of sheapthres relative to sortheap.
The optimizer does not combine index ANDing and index ORing when accessing a single table.
Index access in range-clustered tables
Unlike standard tables, a range-clustered table does not require a physical index (like a traditional B-tree index) that maps a key value to a row. Instead, it leverages the sequential nature of the column domain and uses a functional mapping to generate the location of a specific row in a table. In the simplest example of this type of mapping, the first key value in the range is the first row in the table, the second value in the range is the second row in the table, and so on.
The optimizer uses the range-clustered property of the table to generate access plans that are based on a perfectly clustered index whose only cost is computing the range clustering function. The clustering of rows within the table is guaranteed, because range-clustered tables retain their original key value order.
Index access in column-organized tables
The performance of a select, update, or delete operation that affects only one row in a column-organized table can be improved if the table has unique indexes, because the query optimizer can use an index scan instead of a full table scan.
- The index is defined as unique, and a predicate that equates to a constant value is applied to each key column in the index.
- The FETCH FIRST 1 ROW ONLY clause was specified in an SQL statement, and this option can be applied during the index scan.
- The table data is truly unique.
- Workloads against the table have frequent select, update, or delete operations on unique columns that affect only one row.
- No primary key constraints or unique constraints exist on the columns that are being referenced by select, update, or delete operations that affect only one row.
- No more than one row is produced by the index scan.
- No FETCH operation is necessary, meaning that access must be index-only access.
- The predicates that qualify the single row can all be applied as start or stop key values for the index search.
- The path from the index access to the update or delete operation must be unbroken; that is, the path cannot contain blocking operations such as TEMP, SORT, or HSJN.
delete from t1
where c1 = 99
Rows
RETURN
( 1)
Cost
I/O
|
1
DELETE
( 2)
16.3893
2
/----+-----\
1 1000
IXSCAN CO-TABLE: BLUUSER
( 3) T1
9.10425 Q1
|
1
1000
INDEX: BLUUSER
UK2
Q2