When NESTED LOOPS Is Healthy
Optimal for OLTP queries where the outer row source returns few rows (e.g. 1 to 1,000) and the inner table has a selective B-Tree index on the join key.
When NESTED LOOPS Becomes a Production Bottleneck
Severe latency explosion when E-Rows is severely underestimated (e.g. E-Rows=5, A-Rows=50,000) causing tens of thousands of random index probes or repeated TABLE ACCESS FULL scans.
DBMS_XPLAN Tuning Checklist
- Always multiply Starts x E-Rows on the inner branch before comparing to A-Rows.
- Verify the inner child uses INDEX UNIQUE SCAN or selective INDEX RANGE SCAN, never TABLE ACCESS FULL.
- If A-Rows is in the tens of thousands, gather fresh table/extended statistics so Oracle chooses HASH JOIN.
Before (Slow Pattern)
-- Stale stats underestimate outer rows = 2, forcing Nested Loops SELECT c.name, l.amount FROM customers c JOIN payment_ledger l ON l.customer_id = c.id WHERE c.region = 'EU';
After (Tuned Pattern)
-- Refresh statistics (or verify join index exists) EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'CUSTOMERS', METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO');