
Database Query Optimization
Speeds up slow database queries by walking you through execution plan analysis, indexing strategies, and query rewrites. You'll use EXPLAIN ANALYZE to spot sequential scans that should be index scans, then apply fixes based on the specific bottleneck. Works well when you're debugging performance regressions or trying to reduce database CPU before scaling up hardware. The reference guides cover common patterns like avoiding N+1 queries and choosing between different index types. Honest take: this is solid for the 80% of query problems that come down to missing indexes or bad joins, but complex optimization still needs domain expertise.
- skills.sh installs
- 593
- GitHub stars
- 379
- last updated
- Aug 21, 2026
Install
$ npx -y skills add aj-geddes/useful-ai-prompts --skill database-query-optimization --agent claude-codeInstalls into .claude/skills of the current project.
Files
Database Query Optimization
Table of Contents
Overview
Slow database queries are a common performance bottleneck. Optimization through indexing, efficient queries, and caching dramatically improves application performance.
When to Use
- Slow response times
- High database CPU usage
- Performance regression
- New feature deployment
- Regular maintenance
Quick Start
Minimal working example:
-- Analyze query performance
EXPLAIN ANALYZE
SELECT users.id, users.name, COUNT(orders.id) as order_count
FROM users
LEFT JOIN orders ON users.id = orders.user_id
WHERE users.created_at > '2024-01-01'
GROUP BY users.id, users.name
ORDER BY order_count DESC;
-- Results show:
-- - Seq Scan (slow) vs Index Scan (fast)
-- - Rows: actual vs planned (high variance = bad)
-- - Execution time (milliseconds)
-- Key metrics:
-- - Sequential Scan: Full table read (slow)
-- - Index Scan: Uses index (fast)
-- - Nested Loop: Joins with loops
-- - Sort: In-memory or disk sort
Reference Guides
Sponsors
Details
- Repository
- github.com/aj-geddes/useful-ai-prompts
- Categories
- Backend & APIs, AI & Agent Building, Debugging, Productivity & Planning, Databases
- First seen
- Jun 3, 2026
More from aj-geddes/useful-ai-prompts
All 258- Memory Leak Detection589
- Database Backup Restore588
- Technical Roadmap Planning582
- Accessibility Testing580
- Push Notification Setup580
- Database Schema Documentation576
- App Store Deployment569
- Mobile App Debugging568
- Security Audit Logging568
- Bundle Size Optimization567
- Process Mapping563
- Oauth Implementation558
- Integration Testing557
- Memory Optimization552
- Semantic Versioning552
- Caching Strategy551
- Real Time Features548
- Web Performance Audit548
- Browser Debugging545
- Mobile Offline Support545
- Design System Creation543
- Gcp Cloud Run541
- Code Generation Template537
- Sql Injection Prevention533