SOFT CAT.ai
FIND SOMETHING USEFUL
← Prompt recipes

DATABASE / A WORKED STARTING POINT

Investigate a slow query with its plan

Use the actual database engine, schema and query plan to propose a testable optimisation without inventing a speed-up.

Template reviewed

WHEN TO USE IT

A query has a reproducible plan and you can test a small change safely.

Bring these inputs

{{engine}}
The database engine and version.
{{schema}}
Relevant table definitions and existing indexes.
{{query}}
The complete query, including ordering and limits.
{{plan}}
The actual EXPLAIN or equivalent output.

01 / THE PROMPT

A template you can inspect.

Review the query using the supplied engine, schema and plan.

Identify a specific source of unnecessary work supported by the plan. Propose the smallest candidate change, explain its trade-offs and define a before/after check for result equivalence and execution behaviour. Preserve ordering, ties, null handling and limits. Do not invent timings, claim a percentage speed-up or assume an index will be chosen without checking the new plan.

Engine:
{{engine}}

Schema:
{{schema}}

Query:
{{query}}

Current plan:
{{plan}}

Copying does not run the prompt. Workbench opens an editable draft with the example inputs. It does not save or send it.

02 / THE EXAMPLE TARGET

What a useful result should contain.

This is a target for the worked example, not a recorded model response. Equivalent wording can be valid where the task allows it.

Candidate: CREATE INDEX orders_customer_date ON orders (customer_id, created_at DESC, id DESC).
The review fixture then reported: SEARCH orders USING COVERING INDEX orders_customer_date (customer_id=?).
The same 20 result rows were returned in the same order. No latency improvement was measured. The index has storage and write-maintenance costs.

03 / JUDGE THE RESULT

Check the answer, not the confidence.

  • The proposed index follows the filter and both ordering terms.
  • The id tie-breaker and LIMIT 20 remain unchanged.
  • The response asks for a new plan and equivalent results rather than claiming an unmeasured speed-up.
Open the related workshop tool ↗

The worked example is a target to inspect, not a saved response from a model. Use the checks to judge an actual result.

This template was revised during the September prompt review. The earlier text remains in Git history.

Read the prompt collection review ↗