Overview
Oracle supports B-tree, bitmap, function-based, index-organised tables and several special index types. Tables are heaps by default, so every index entry points to a ROWID. Theory is in indexing-theory; this note shows Oracle’s behaviour with measurements on 500,000 rows.
Core concepts
- B-tree (default): equality and range, composite (leftmost-prefix), unique, descending, compressed keys. A foreign key column should be indexed to avoid table-level locking issues and slow parent deletes.
- Function-based index:
CREATE INDEX i ON t (TRUNC(created)). Oracle creates a hidden virtual column (for exampleSYS_NC00007$) and indexes it; the query must use the same expression. - Bitmap index: one bitmap per distinct value; tiny for low-cardinality columns and good for combining predicates in data warehouses. Do not use on busy OLTP tables: a single DML locks a range of rows’ bitmap entries and blocks concurrent writers.
- Index-organised table (IOT): the table is a B-tree on the primary key (like SQL Server’s clustered index, sqlserver-indexes); no table segment.
- Reverse key, invisible indexes (test dropping an index safely:
ALTER INDEX i INVISIBLE), partial indexes on partitioned tables, local vs global indexes on partitions (oracle-partitioning). - Index skip scan can use a composite index without its leading column when that column has few distinct values; index fast full scan reads the whole index like a narrow table.
Worked example
CREATE INDEX orders_cust ON orders(customer_id);
-- point lookup, 47 rows:
-- TABLE ACCESS FULL 9,443 buffers -> INDEX RANGE SCAN + TABLE ACCESS BY INDEX ROWID BATCHED 50 buffersFunction on a column (WHERE TRUNC(created) = DATE '2025-03-01', 1,370 rows):
| Index | Plan | Buffers |
|---|---|---|
none on created | TABLE ACCESS FULL, filter TRUNC(INTERNAL_FUNCTION("CREATED"))=... | 9,444 |
CREATE INDEX ON orders(TRUNC(created)) | INDEX RANGE SCAN, access "ORDERS"."SYS_NC00007$"=TO_DATE(...) | small |
Index size for the low-cardinality column status (3 distinct values), same table:
| Index | Size |
|---|---|
B-tree on status | 10 MB |
Bitmap on status | 0.4 MB |
(ORA-01408: such column list already indexed appears if you create both on the same column list at once.) Other sizes: B-tree on customer_id 9 MB, the primary key index 8 MB.
Pitfalls and production notes
- A bitmap index plus concurrent
UPDATE/INSERTis a locking disaster; keep them for read-mostly reporting tables. - Comparing a
VARCHAR2column with a number (or the other way) causes an implicit conversion on the column and prevents the index; match types. - Indexes add redo and undo to every DML (oracle-redo-undo); drop unused ones (monitor with
DBA_INDEX_USAGEin 23ai/26ai orV$OBJECT_USAGEin older versions). - Rebuilding indexes on a schedule rarely helps; rebuild when you have measured a reason (
ALTER INDEX ... REBUILD ONLINE). NULLs are not stored in single-column B-tree indexes, soWHERE col IS NULLcannot use one; add a constant column to a composite index if you need it.
Practice questions
- Why is a bitmap index dangerous for an OLTP orders table?
- How do you make
WHERE TRUNC(created) = :dfast? - How does an IOT differ from a heap table plus a primary key index?
References
- Oracle Database Concepts, Indexes and Index-Organized Tables; SQL Tuning Guide, Application Tracing and Index Design
Related
indexing-theory · oracle-execution-plans · oracle-partitioning · pg-index-types · sqlserver-indexes