database-query-optimization▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
Slow database queries are a common performance bottleneck. Optimization through indexing, efficient queries, and caching dramatically improves application performance.
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
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Query Analysis | Query Analysis |
| Indexing Strategy | Indexing Strategy |
| Query Optimization Techniques | Query Optimization Techniques |
| Optimization Checklist | Optimization Checklist |
Best Practices
✅ DO
- Follow established patterns and conventions
- Write clean, maintainable code
- Add appropriate documentation
- Test thoroughly before deploying
❌ DON'T
- Skip testing or validation
- Ignore error handling
- Hard-code configuration values
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.8★★★★★32 reviews- ★★★★★Dhruvi Jain· Dec 20, 2024
Solid pick for teams standardizing on skills: database-query-optimization is focused, and the summary matches what you get after install.
- ★★★★★Ama Gill· Dec 8, 2024
Solid pick for teams standardizing on skills: database-query-optimization is focused, and the summary matches what you get after install.
- ★★★★★Arjun White· Dec 4, 2024
Registry listing for database-query-optimization matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Aisha Reddy· Dec 4, 2024
Keeps context tight: database-query-optimization is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Anaya Brown· Nov 27, 2024
We added database-query-optimization from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Arya Chawla· Nov 23, 2024
Useful defaults in database-query-optimization — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Oshnikdeep· Nov 11, 2024
We added database-query-optimization from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Naina Taylor· Nov 11, 2024
database-query-optimization reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Ama Thomas· Oct 18, 2024
database-query-optimization fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Arjun Srinivasan· Oct 14, 2024
I recommend database-query-optimization for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
showing 1-10 of 32