The goal is to answer one question: what is Postgres actually doing? Start with a baseline plan, then change one variable at a time.
The minimal checklist
- Is the query using indexes?
- Are rows being filtered early?
- Do we see huge sort or hash nodes?
EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM events WHERE workspace_id = $1 ORDER BY created_at DESC LIMIT 50;
A small habit
Write the query, capture the plan, then save the plan next to the code. Future you will thank you.