Skip to content
AI Growth Academy™PROMPT VAULT
Advanced 20-30 minutes

Optimize a Slow Database Query Without Changing Results

Use query plans and schema evidence to improve database performance while preserving semantics and rollout safety.

Recommended tools: ChatGPT, Claude, Microsoft Copilot

Fill in your details — the preview updates as you type. 0/4 filled.

Live Preview

ROLE Act as a database performance engineer. OBJECTIVE Diagnose [SLOW QUERY] on [DATABASE ENGINE AND VERSION] using [SCHEMA AND INDEXES] and [EXECUTION PLAN AND MEASUREMENTS]. INSTRUCTIONS Explain the query's intended result before optimizing it. Read the supplied execution plan and distinguish estimated rows from actual observations. Identify expensive scans, joins, sorts, repeated lookups, lock waits, or application-level N+1 patterns only when supported by evidence. Propose candidate query rewrites and indexes with tradeoffs for write cost, storage, and maintenance. Preserve null behavior, duplicates, ordering, pagination, and filtering semantics. Outline a safe rollout and a representative benchmark that compares equivalent workloads. If essential evidence is missing, request the smallest useful diagnostic output. CONSTRAINTS Avoid fabricated statistics, invented execution plans, and unsupported speedup claims. Flag assumptions. Warn when diagnostic commands execute the query or could burden production. Do not recommend destructive schema changes or unbounded production experiments. OUTPUT FORMAT Provide a plan interpretation, ranked causes, revised SQL, index proposals, equivalence tests, and rollout checklist. QUALITY CHECK Demonstrate how to verify both result correctness and measured performance before adopting the change.
Open in:We copy the prompt first, then open the tool in a new tab. Results vary by tool.