Slow query analysis and optimization
Slow Queries
23
Avg Time
34ms
P99 Time
892ms
SELECT u.*, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id ORDER BY ...
Seq Scan on orders → Hash Join → Sort → Aggregate
Add composite index on orders(user_id, id). Consider materializing the count in a summary table updated via triggers.
UPDATE products SET search_vector = to_tsvector('english', name || ' ' || description) WHERE updated_at > ...
SELECT * FROM events WHERE type = $1 AND created_at BETWEEN $2 AND $3 ORDER BY created_at DESC LIMIT 100
SELECT p.*, c.name AS category FROM products p JOIN categories c ON p.category_id = c.id WHERE p.status = ...
SELECT DISTINCT tag FROM product_tags WHERE product_id IN (SELECT id FROM products WHERE store_id = $1)