Junior Track Roadmap

AI: SQL plan & optimization

This course reads PostgreSQL execution plans captured from a Rails app's development database. It covers the difference between EXPLAIN and EXPLAIN ANALYZE, and how to read cost estimates against measured times and rows. Three of the app's queries follow: a sequential scan with a sort, a bitmap index scan that still sorts, and a CTE feeding a window function. A wrong row estimate is traced to missing table statistics and fixed with ANALYZE. The last lessons cover prompting an AI tool to read a plan and checking its suggested fix.

What you'll learn

  • ✓The difference between EXPLAIN and EXPLAIN ANALYZE, and why ANALYZE on a write performs it
  • ✓Reading plan nodes such as Seq Scan, Bitmap Heap Scan, Sort, HashAggregate and WindowAgg
  • ✓Why a used index can still leave a separate Sort step
  • ✓How missing table statistics produce wrong row estimates, and how ANALYZE corrects them
  • ✓Prompting an AI tool with a full plan and checking its answer against the plan and schema
Free preview · Lesson 1 3 min read

What EXPLAIN and EXPLAIN ANALYZE show

"ActiveRecord querying: N+1 detection" taught reading this app's log/development.log for a burst of repeated queries: one label appearing dozens of times, identical except for one varying id. That's a pattern across many queries. This course starts one level down, at what a single query's execution…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...