QueryDoctor

Workload

Which queries cost the most database time, and which proven index fixes recover it. Fix the top of the list first.

Recorded from a real local run: the demo traffic generator against the sample PostgreSQL database (40 s of traffic, 10 query shapes), then the product's own batch flow benchmarked the top queries in isolated clones. The per-day figure assumes that traffic rate continues around the clock; real workloads differ. Run locally to import your own pg_stat_statements.

Ranked Fix Queue

4 Benchmark-Validated indexes could recover approximately 6.7 hours of query execution time/day.

Estimated query execution time saved, not CPU time. Extrapolated from isolated sample benchmarks; combined indexes have not been benchmarked together.

  1. CREATE INDEX ON orders (customer_id, created_at DESC) INCLUDE (id, total_amount)

    Helps 1 query shape · 5.0 hours estimated/day

  2. CREATE INDEX ON orders (customer_id) INCLUDE (created_at)

    Helps 1 query shape · 1.2 hours estimated/day

  3. CREATE INDEX ON payments (order_id)

    Helps 1 query shape · 26.5 minutes estimated/day

  4. CREATE INDEX ON orders (status, id, customer_id, created_at)

    Helps 1 query shape · 3.0 minutes estimated/day

Ranked by total time

#QueryCallsMeanEstimated p95Total timeShare of totalActions
1SELECT id, customer_id, payload, created_at FROM events WHERE event_type = ? ORDER BY payloadevents45243 ms573 ms11 s
44.8%
2SELECT id, total_amount FROM orders WHERE customer_id = ? AND created_at >= ? ORDER BY created_at DESCorders1,5006 ms8 ms8.7 s
35.5%
3SELECT c.id, (SELECT MAX(o.created_at) FROM orders AS o WHERE o.customer_id = c.id) AS last_order FROM customers AS c WHERE c.segment = ? AND c.id <= ?customers, orders6336 ms419 ms2 s
8.2%
4SELECT o.id, p.amount, p.method FROM orders AS o JOIN payments AS p ON p.order_id = o.id WHERE o.customer_id = ?orders, payments10011 ms16 ms1.1 s
4.4%
5SELECT * FROM order_items AS i JOIN orders AS o ON o.id = i.order_id JOIN customers AS c ON c.id = o.customer_id JOIN products AS p ON p.id = i.product_id WHERE o.status = ? AND o.created_at >= ?customers, order_items, orders, products1534 ms45 ms511 ms
2.1%
6SELECT o.id, o.total_amount FROM orders AS o JOIN customers AS c ON c.id = o.customer_id WHERE c.country = ? AND o.currency = ?customers, orders4011 ms17 ms433 ms
1.8%
7SELECT id, customer_id, total_amount FROM orders WHERE status = ? AND created_at >= ? AND created_at < ?orders605 ms7 ms307 ms
1.3%
8SELECT id, email FROM customers WHERE LOWER(email) = ?customers1202 ms3 ms258 ms
1.1%
9SELECT id, status, total_amount FROM orders WHERE id = ?orders6,0000.02 ms0.04 ms104 ms
0.4%
10SELECT id, email, country FROM customers WHERE id = ?customers6,0000.02 ms0.18 ms101 ms
0.4%