EXPLAIN ANALYZE Cost Optimizer Lab
Interactive evaluation of Seq Scan, Index Scan, Index-Only Scan, and Bitmap Index Scan execution plans.
PostgreSQL Cost-Based Optimizer (CBO)
EXPLAIN (ANALYZE, BUFFERS) Plan Inspector
psql explain output100,000 Rows Table
Index Scan using idx_orders_user_id on orders (cost=0.42..8.45 rows=2 width=32) Index Cond: (user_id = 942) Buffers: shared hit=3 (B-Tree) read=1 (Heap) Planning Time: 0.110 ms Execution Time: 0.082 ms
Optimizer Decision Analysis:
B-Tree Index Scan + Table Heap Fetch
Traverses the 3-level B-Tree index in 0.05ms, then fetches the exact 2 matching rows from the heap data page.
CBO Cost Formula:
Cost = (pages * seq_page_cost) + (tuples * cpu_tuple_cost)