Database Query Timeout - Complex Queries Too Slow
Database queries timeout or take too long (>5 seconds). Complex queries with joins or aggregations are slow.
API endpoints that query database time out or users see loading spinners for too long.
Error Messages You Might See
Common Causes
- Missing database indexes on frequently queried columns
- N+1 queries - fetching parent then all children separately
- Fetching more data than needed (select * instead of specific columns)
- Complex joins without proper indexes
- Large result sets without pagination
How to Fix It
Add indexes: CREATE INDEX idx_user_email ON users(email)
Use eager loading: Prisma.findUnique({ include: { posts: true } }) instead of separate queries
Select specific fields: select { id: true, email: true } instead of full objects
Paginate large results: limit 100, offset (page-1)*100
Profile queries: explain analyze SELECT... in database
Cache frequently accessed data: use Redis for hot data
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I know if a query is slow?
Run EXPLAIN ANALYZE in database. Look for sequential scans (bad) vs index scans (good)
What's N+1 query problem?
Fetch 1 user (1 query), then fetch posts for each user (N queries). Use eager loading to do 2 queries total
Should I cache everything?
No, cache hot data. Use Redis for frequently accessed, slow-to-compute results. Set reasonable TTL