| Lesson 7 | Monitoring and tuning Oracle indexes |
| Objective | Identify and repair poorly performing indexes |
Oracle B-tree indexes are not static structures. As DML activity accumulates, two forms of index degradation occur that require monitoring and periodic maintenance: height increase from splitting and spawning, and space waste from deleted leaf nodes. Understanding both patterns is the foundation for identifying and repairing poorly performing indexes.
The first sign of index change is splitting and spawning. As rows are inserted and updated, index leaf nodes fill and must split to accommodate new entries. A split at the same level redistributes entries across sibling nodes without increasing the tree height. When an entire level fills, part of the tree spawns a new level above it, increasing the index height by one.
An index that has grown to four or more levels requires more block reads per lookup than a well-maintained three-level index. Each additional level adds at least one block read to every index-driven row access, multiplying I/O cost across high-frequency queries.
Index splitting in the sense of restructuring a large monolithic index into partitioned segments is a technique for improving performance on heavily accessed indexes. Before splitting or rebuilding, confirm that the index is actually causing the problem. Three Oracle tools identify missing or poorly performing indexes:
DBMS_SQLTUNE or Oracle Enterprise
Manager.Two approaches identify opportunities for materialized views alongside missing index analysis:
DBMS_ADVISOR package (Materialized View Advisor) to analyze the workload and
recommend suitable materialized views.For large, heavily accessed indexes, partitioning distributes the index across multiple smaller segments. Three partitioning strategies apply:
Oracle 10g introduced online data reorganization capabilities that remain the foundation of current index maintenance practice. These features reduce the maintenance window required on active production databases:
DBMS_REDEFINITION)ALTER TABLE ... SHRINK SPACE)Despite these automated tools, the Oracle DBA must still perform routine index maintenance on highly active databases to keep performance at peak levels.
The second sign of index degradation is the accumulation of deleted leaf nodes. When rows are deleted, Oracle does not immediately reclaim the corresponding index leaf node space. To avoid restructuring the index tree during peak DML, Oracle flags the index entries as logically deleted and leaves them in place. These deleted leaf nodes remain in the index structure, consuming space and increasing the number of blocks Oracle must scan during range scans on the affected key range.
With frequent INSERT, UPDATE, and DELETE activity, an index may accumulate enough deleted leaf nodes to measurably degrade range scan performance. The solution is to rebuild the index, which creates a clean B-tree with no deleted entries and an optimal height.
Oracle provides index statistics for structural analysis. An Oracle index should be considered for rebuild when any of the following conditions is true:
BLEVEL > 3 in
DBA_INDEXES).DEL_LF_ROWS in INDEX_STATS).BLKS_GETS_PER_ACCESS value from INDEX_STATS is greater
than 5.Always rebuild rather than drop and re-create. ALTER INDEX ... REBUILD constructs the
new tree in temporary segments and replaces the original only after the new structure is fully validated,
making it safe for production use.
Oracle maintains index statistics in three data dictionary views: DBA_INDEXES,
USER_INDEXES, and ALL_INDEXES (IND is a synonym for
USER_INDEXES). Key statistics available:
BLEVEL)LEAF_BLOCKS)CLUSTERING_FACTOR)DISTINCT_KEYS)AVG_LEAF_BLOCKS_PER_KEY)AVG_DATA_BLOCKS_PER_KEY)DBA_INDEXES, USER_INDEXES, and ALL_INDEXES are the primary
views for querying index metadata. Their columns organize into four groups:
To populate INDEX_STATS with structural metrics for a specific index, run
ANALYZE INDEX ... VALIDATE STRUCTURE. INDEX_STATS holds data for only one
index at a time and is overwritten on each run — query it immediately after each execution.
ANALYZE INDEX demo VALIDATE STRUCTURE;
Key columns returned in INDEX_STATS:
Note: DBMS_STATS is the preferred tool for gathering optimizer
statistics in Oracle 10g and later. ANALYZE INDEX ... VALIDATE STRUCTURE remains the
correct method for populating INDEX_STATS for structural analysis — DBMS_STATS
does not populate INDEX_STATS.
To identify an out-of-balance index, run ANALYZE INDEX with
VALIDATE STRUCTURE, then query INDEX_STATS for the three key diagnostic
columns:
ANALYZE INDEX schema_name.index_name VALIDATE STRUCTURE;
SELECT height, del_lf_rows, blks_gets_per_access
FROM index_stats;
Interpret the results as follows:
Monitor index space efficiency at regular intervals by querying PCT_USED from
INDEX_STATS after each VALIDATE STRUCTURE run:
ANALYZE INDEX schema_name.index_name VALIDATE STRUCTURE;
SELECT pct_used
FROM index_stats
WHERE name = 'INDEX_NAME';
Build a history of average PCT_USED by repeating: analyze → validate → check
PCT_USED → rebuild or coalesce when usage drops below the historical average. The
following sequence establishes the monitoring baseline:
CREATE INDEX stores the timestamp of the most recent function used in a function-based
index. This timestamp is updated when the index is validated. If a tablespace point-in-time recovery
results in the function timestamp being newer than the timestamp stored in the index, Oracle marks the
index invalid. Use ANALYZE INDEX ... VALIDATE STRUCTURE to revalidate the index after
recovery.
Oracle 23ai continues to support ALTER INDEX ... REBUILD as the primary index rebuild
mechanism. The command is safe for production use because it constructs the new index tree in temporary
segments and replaces the original only after the new structure is fully validated.
-- Rebuild an index in its current tablespace
ALTER INDEX schema_name.index_name REBUILD;
-- Rebuild into a specific tablespace (recommended)
ALTER INDEX schema_name.index_name REBUILD TABLESPACE tablespace_name;
-- Rebuild online — no exclusive lock required
ALTER INDEX schema_name.index_name REBUILD ONLINE;
Always specify the TABLESPACE parameter when rebuilding. If omitted, Oracle rebuilds
the index in the user's default tablespace, which may not be the correct location. Use
REBUILD ONLINE on production tables where a DDL lock is not acceptable.
Oracle 23ai extends several capabilities that reduce the frequency and cost of manual index rebuilds:
DBMS_AUTO_INDEX.REPORT_ACTIVITY.DEL_LF_ROWS accumulation does not apply; rebuild thresholds based on deleted
leaf nodes are not relevant for these objects.ALTER INDEX mechanics but require awareness of view-layer
metadata caching behavior.For standard B-tree index maintenance in Oracle 23ai, the recommended workflow is: run
ANALYZE INDEX ... VALIDATE STRUCTURE → check HEIGHT, DEL_LF_ROWS, and
BLKS_GETS_PER_ACCESS in INDEX_STATS → rebuild with TABLESPACE and ONLINE clauses → re-gather
optimizer statistics with DBMS_STATS.GATHER_INDEX_STATS.
Index monitoring is an ongoing DBA responsibility. The two primary degradation patterns — height
increase from splitting and spawning, and space waste from deleted leaf nodes — are detected through
ANALYZE INDEX ... VALIDATE STRUCTURE and the INDEX_STATS view. The rebuild
threshold guidelines (HEIGHT > 3, DEL_LF_ROWS significant, BLKS_GETS_PER_ACCESS > 5) provide
actionable criteria for scheduling maintenance. Oracle 23ai's Automatic Indexing reduces the frequency
of manual intervention, but structural monitoring with INDEX_STATS remains the definitive
diagnostic for B-tree health.
The next lesson examines how the high water mark for a table affects the performance of full-table scans.