Reading the Tea Leaves: Query Optimization with Postgres and AI
summary
Explains how Postgres uses cost estimates from PG stats to pick bitmap heap scans, index scans or sequential scans, and how EXPLAIN/ANALYZE/BUFFERS shows real vs estimated costs (example: 2.5M rows, 36k pages, optimizer estimating 22k matches for value 1990). Describes hypo_pg hypothetical indexes for safe experimentation and shows LLMs (Gemini/Claude) plus cloud code skills and agents that parse plans, propose indexes, emit create/rollback SQL, and run log-driven tuning while warning about overfitting and long concurrent index builds.
AI-written summary · about
chapters (19)
- 0:00Why query optimizers matter
- 2:58Brief history of optimizers
- 5:24Postgres query pipeline
- 7:16Single table access paths
- 8:22Understanding EXPLAIN
- 11:32Cost calculation in Postgres
- 14:03Postgres catalog and stats
- 16:50Row estimates and selectivity
- 19:16Join ordering fundamentals
- 21:03Postgres join methods
- 23:58Genetic query optimizer
- 25:22AI parsing query plans
- 26:45Introducing skills for AI
- 27:49HypoPG for hypothetical indexes
- 29:14Moving to AI agents
- 31:20Types of AI database agents
- 33:49Live query tuning demo
- 36:00Challenges with agents
- 36:43Building agent teams
