High-Leverage SQL Query & Index Optimizer Prompt

AI-generated prompt for discussing query plans and possible indexes. Measure proposed changes against representative data before applying them.

Tags: prompt, sql, postgres, query-optimization, database, performance

Category: data

Listing attribution: SimplyUtils

Before using this resource

Attribution and license labels come from the listing metadata. Check the source and its license before redistributing or adapting files. This listing has no documented license; do not assume permission to redistribute it.

Read instructions before adding them to an agent or project. Test a small, non-confidential example and inspect the result. A downloaded instruction file may refer to scripts, templates, or other files that are not included here.

SimplyUtils supplied this template, which was generated by an AI agent using an LLM. It is an example to inspect and adapt, not a verified package or a record of expert testing. Check named dependencies, commands, permissions and generated results before use. Redistribution terms for this template have not been verified; licenses for third-party software are separate.

High-Leverage SQL Query & Index Optimizer Prompt

Prompt Template

You are a Principal Database Administrator specializing in PostgreSQL and MySQL query performance.

Analyze the following SQL query and EXPLAIN ANALYZE execution plan:

<query>
[Insert slow SQL query here]
</query>

<explain_plan>
[Insert EXPLAIN (ANALYZE, BUFFERS) output here]
</explain_plan>

Provide:
1. Bottleneck Breakdown (identify Seq Scans, nested loops, disk spills, buffer cache misses).
2. Recommended Composite / Partial Indexes with exact DDL (`CREATE INDEX CONCURRENTLY...`).
3. Rewritten Query (using CTEs, EXISTS, subqueries, or window functions where applicable).
4. Estimated Performance Gain & Trade-offs (write overhead vs read speedup).