Seamless SQL optimization
summary
Two complementary workflows: macro analysis with pg_stat_statements and log tools (pgBadger, sampled logging in PostgreSQL 12) finds high-impact groups — the demo query hits ~1,000,000 rows and shows max 42s and huge buffer reads — then micro analysis with explain analyze with BUFFERS reveals per-plan I/O (and explains why an expression index helps: mean drops from ~10s to ~1s for some params but some parameter values still force a seq scan). Auto_explain, pg_stat_kcache, pg_qualstats, PF2/explain.dalibo.com, FlameGraphs and a built Database Lab (ZFS/LVM thin clones) let teams test full-size explains safely; note explain logging can add large overhead (reports up to 700x).
AI-written summary · about
chapters (17)
- 0:00Introduction and speaker background
- 4:21Seamless scale optimization methodology
- 8:21Anti-methodologies in SQL optimization
- 12:10SRE methods and problem statement
- 14:13Identifying slow queries in practice
- 19:57Macro vs micro analysis split
- 28:50Macro analysis tools and metrics
- 44:13Practical exercise on Catacoda
- 55:59Analyzing pg_stat_statements metrics
- 1:06:36Micro analysis with EXPLAIN
- 1:13:23Observability problems in analysis
- 1:24:04Visualization tools for EXPLAIN
- 1:33:03Optimizing the slow query
- 1:48:27Switching between macro and micro levels
- 1:53:04Database Lab for disposable environments
- 2:00:27Summary and final thoughts
- 2:15:00Q&A session
