All posts

Engineering

8 min read

How we built find_slow_queries

How we built find_slow_queries

A look inside our newest tool: reading pg_stat_statements, ranking by real cost and drafting indexes an agent can explain.

Priya Natarajan

Engineer, query planner

Article cover

Ask an engineer why a page is slow and the first thing they open is pg_stat_statements. We wanted agents to start in the same place.

Ranking by real cost

Mean time alone is misleading. A query that takes 2 seconds once a day matters less than one that takes 40 milliseconds ten thousand times an hour. We rank by total time, then show calls and rows so the agent can explain the trade-off.

Drafting indexes

For each statement we read the plan, look for sequential scans on large tables and draft a matching index. The estimate comes from the planner, not a guess.

Keeping it safe

The tool never creates an index itself. It returns a draft, and creating it goes through the same approval flow as any other write.

Create a free website with Framer, the website builder loved by startups, designers and agencies.