SQL Practice Logo

SQLPractice Online

Execution Plans & EXPLAIN: Mistakes

Module: Query Optimization & Performance

Using default cost parameters on SSD storage

SET random_page_cost = 1.1 for SSD, 1.0 for NVMe

Default random_page_cost of 4.0 assumes spinning disks where random I/O is 4x slower than sequential. On SSDs, random and sequential I/O have similar performance. Setting random_page_cost to 1.1 makes the optimizer prefer index scans appropriately.

Tune cost parameters to match your hardware

High

Optimizer chooses table scans over indexes

Ignoring Workers Planned: 4, Workers Launched: 0

Investigate why parallel workers did not launch

When workers are planned but not launched, it indicates resource constraints (max_worker_processes reached, insufficient memory) or configuration issues. This can cause 4x slower execution than expected.

Monitor parallel worker launch success rate

High

Expected parallel execution but got serial

Accepting Buffers: hit=1000 read=9000 (10% cache hit)

Investigate why cache hit ratio is low, increase shared_buffers

Cache hit ratio below 95% indicates insufficient buffer cache or poor query patterns. Each disk read is 100-1000x slower than cache hit. Increase shared_buffers or optimize queries to reduce working set.

Target >95% buffer cache hit ratio

Critical

Excessive disk I/O due to poor caching

Not investigating plan changes after statistics update

Compare plans before and after ANALYZE, validate performance

Updating statistics can cause the optimizer to choose different plans. Sometimes the new plan is worse due to data skew or correlation. Always validate performance after statistics updates and be prepared to force the old plan if needed.

Monitor plan stability after statistics updates

Medium

Statistics update caused plan regression