Improve database query performance through indexing, query optimization, and execution plan analysis. Reduce response times and database load.
3f5182cSlow database queries are a common performance bottleneck. Optimization through indexing, efficient queries, and caching dramatically improves application performance.
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
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 |
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/database-query-optimization · pinned to the source commit
git clone https://github.com/aj-geddes/useful-ai-prompts.git
cd useful-ai-prompts
git checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills/database-query-optimization"
cp -r "skills/database-query-optimization" ".claude/skills/database-query-optimization"Review the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
Scanner static-checks@0.1.0 · commit 3f5182cfd739. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
No static rules matched. This is not a safety guarantee.