B-Tree, Bitmap & Specialized Indexes

B-Tree, Bitmap & Specialized Indexes in Oracle Database: Indexes are separate physical segments that accelerate data access paths.

Indexes are separate physical segments that accelerate data access paths. Choosing the right index architecture is the single most critical factor in database throughput.


Standard B-Tree Indexes

The default index structure in Oracle is the balanced tree (B-Tree). It is organized into:

  • Root Block: Entry point for branch navigation.
  • Branch Blocks: Direct search traversals toward target leaf blocks.
  • Leaf Blocks: Store the indexed column values in sorted order alongside the corresponding physical ROWID pointing directly to the datafile block.
                     [ Root Block ]
                     /            \
          [ Branch Block ]    [ Branch Block ]
          /              \    /              \
    [ Leaf Block ] [ Leaf Block ] [ Leaf Block ] [ Leaf Block ]
       |                 |             |             |
       +--> ROWID pointers directly to Datafile table rows

Use B-Trees for high-cardinality columns (columns with thousands or millions of distinct values, such as primary keys, emails, UUIDs, or timestamps).

-- Composite B-Tree index respecting the Leading-Edge rule
-- Queries filtering on (tenant_id) OR (tenant_id AND status) use this index efficiently.
CREATE INDEX idx_orders_tenant_status ON orders(tenant_id, order_status, order_date);

Bitmap Indexes for Data Warehousing

Bitmap indexes are engineered for low-cardinality columns (columns with very few distinct values, such as gender, marital_status, order_status, or country_code).

Instead of storing row pointers, Oracle creates a bit string (a sequence of 0s and 1s) for each distinct column value, where each bit corresponds to a physical row number:

RowID  | Status='PENDING' | Status='SHIPPED' | Status='CANCELLED'
-------+------------------+------------------+-------------------
Row 1  | 1                | 0                | 0
Row 2  | 0                | 1                | 0
Row 3  | 1                | 0                | 0
Row 4  | 0                | 0                | 1

Bitmap indexing allows the database engine to combine multiple index scans using high-speed hardware boolean operations (AND, OR, NOT) before touching the table.

CREATE BITMAP INDEX bidx_customers_region ON customers(region_code);
CREATE BITMAP INDEX bidx_customers_gender ON customers(gender);

CRITICAL PRODUCTION WARNING: Never use Bitmap indexes in OLTP (high-write) environments. Modifying a row in a bitmap index locks the entire bitmap segment (hundreds or thousands of related rows), completely destroying write concurrency. Use them exclusively for read-heavy reporting and analytics.


Function-Based Indexes

If a query wraps an indexed column inside a function, Oracle cannot use a standard B-Tree index because the values in the leaf nodes do not match the function result. A Function-Based Index indexes the evaluated result directly:

-- Without a function-based index, this triggers a full table scan:
SELECT * FROM users WHERE LOWER(email) = 'developer@codeacademix.dev';

-- Create the function-based index:
CREATE INDEX idx_users_lower_email ON users(LOWER(email));

-- Indexing a date truncation for daily reporting
CREATE INDEX idx_orders_created_day ON orders(TRUNC(created_at, 'DDD'));

Invisible Indexes for Safe Maintenance

Dropping an index in production is dangerous: if an unexpected query relied on it, response times can spike catastrophically. Oracle allows marking an index as INVISIBLE:

-- Make index invisible to the optimizer
ALTER INDEX idx_orders_tenant_status INVISIBLE;

-- Test query behavior in your session specifically:
ALTER SESSION SET OPTIMIZER_USE_INVISIBLE_INDEXES = TRUE;

-- If performance remains stable across the system, drop it safely:
DROP INDEX idx_orders_tenant_status;

Exercises

  1. Create a composite B-Tree index on a table shipments(carrier_code, status, ship_date) and explain which queries can leverage the leading edge.
  2. Build a function-based index that allows fast queries for WHERE UPPER(last_name) LIKE 'MC%'.
  3. Explain why updating a single row on a table with a Bitmap index can cause transaction deadlocks on unrelated rows.