How to Use Claude for Database Optimization
The exact prompt, setup, and codes to get great results.
The Problem
Slow queries kill user experience and server costs. Most developers know 'add an index' but don't know how to read query plans or restructure schemas for performance.
The Prompt (Copy & Paste)
Optimize this database query/schema. Database: [POSTGRES / MYSQL / MONGODB] Table sizes: [APPROXIMATE ROW COUNTS] Current query time: [HOW SLOW] Target query time: [WHAT'S ACCEPTABLE] Schema: ```sql [PASTE CREATE TABLE STATEMENTS OR SCHEMA] ``` Slow query: ```sql [PASTE THE QUERY] ``` EXPLAIN output (if available): ``` [PASTE EXPLAIN ANALYZE OUTPUT] ``` Analyze: 1. What's causing the slowness (sequential scan, missing index, bad join order, N+1)? 2. Show the optimized query 3. Suggest index additions (with CREATE INDEX statements) 4. Flag any schema changes that would help at scale 5. Estimate the improvement and any tradeoffs (write speed, storage)
Replace the [BRACKETED] placeholders with your specific details.
What You Get
A clear diagnosis of why your query is slow, with ready-to-run SQL for indexes and query rewrites. Includes tradeoff analysis so you understand the cost of each optimization.
Prompt Codes That Help
Add these prefix codes to the start of your prompt for even better results:
Click any code to see its before/after examples and learn how it works.
Want all 120+ prompt codes?
The Claude Prompt Cheat Sheet has every tested code with before/after examples, combo stacks, and 10 workflow playbooks for different roles.
More Software Development Tasks
Debugging React
React bugs are notoriously hard to debug β infinite re-renders, stale closures, hydration mismatches. Error messages point to the wrong component and stack traces are useless.
Debugging Python
Python's dynamic typing and silent failures make bugs hard to catch. A function returns None instead of a value, a dictionary key is missing, or an import fails at runtime.
Code Review
Thorough code reviews take time most teams don't have. Reviewers miss edge cases, security issues, and performance problems because they're scanning too quickly.
Writing Tests
Writing tests is tedious and most developers skip edge cases. Coverage reports show green but the tests don't actually catch real bugs because they only test the happy path.
Get new prompts + workflows weekly
Join developers and professionals getting tested Claude prompt codes, workflows, and real-world techniques. One email when thereβs something worth sharing.