slow_queryQuery exceeded configured slowQueryThresholdMs
This query took longer than expected based on your configured threshold and may impact request latency. Review query execution plan and consider adding indexes.
Common Causes
- —Missing indexes
- —Large result set without pagination
- —Complex aggregation without optimization
- —Network latency to database
How to Fix
- 1.Analyze with EXPLAIN/explain()
- 2.Add appropriate indexes
- 3.Optimize query structure
- 4.Implement caching for stable data
Threshold is configurable
The default
slowQueryThresholdMs is 100ms. Tune it per environment — stricter in production, relaxed in development.Example
typescript
// Diagnose with explain — Mongoose
const result = await User.findOne({ email }).explain('executionStats');
// Look for: COLLSCAN (bad) vs IXSCAN (good)
// Look for: totalDocsExamined >> nReturned (bad)
console.log(result.executionStats);
// Fix — add the missing index
await User.collection.createIndex({ email: 1 }, { unique: true });PostgreSQL
sql
-- Find the slow query plan
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'user@example.com';
-- If you see Seq Scan, add the index
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);