StructuredFor ProfessionalsCoding & Tech

Optimise a slow database query.

When a query is causing performance issues, slow page loads, or high database load

ChatGPT Β· Claude Β· GeminiΒ·IntermediateΒ·~1100 tokens
Curated by the AIPP team
Last updated 14 May 2026 Β· v3
optimise-a-slow-database-query.md Β· 1100 words
You are a senior {{role}} brought in to help a professional complete a {{use_case}} task.

# Context
- Category: Coding & Tech
- Use case: Optimise a slow database query
- Source task:
  - Analyse the following query for performance issues. I will provide the query and context.
  - Query: {{paste_sql_or_query_code}}.
  - Database: {{postgresql_mysql_sqlite_mongodb_other}}.
  - Table sizes (approximate): {{list_the_tables_involved_and_estimated_row_count}}.
  - Existing indexes: {{list_known_indexes_or_write_unknown}}.
  - Current execution time: {{if_known}}.
  - Expected volume: {{how_often_this_query_runs_and_how_many_rows_it_n}}.
  - Produce:
  - 1. What this query is doing : plain English description.
  - 2. The most likely performance bottleneck and why.
  - 3. Recommended query rewrite (if applicable).
  - 4. Indexes to add or modify.
  - 5. Any structural changes to the data model that would improve performance long-term.
  - 6. How to verify the improvement (EXPLAIN ANALYZE or equivalent).

# Goal
A query analysis with the bottleneck identified, a rewrite suggestion, index recommendations, and a verification method

# Constraints
- Produce a complete, usable first draft in one response.
- Avoid generic filler, vague advice, and corporate-sounding language.
- Make the output specific, practical, and ready to use.

# Output
A query analysis with the bottleneck identified, a rewrite suggestion, index recommendations, and a verification method

The variables to fill in

PlaceholderWhat to put thereExample
{{role}}Rolesenior database engineer
{{paste_sql_or_query_code}}Paste sql or query codequery code
{{postgresql_mysql_sqlite_mongodb_other}}Postgresql mysql sqlite mongodb otherPostgreSQL
{{list_the_tables_involved_and_estimated_row_count}}List the tables involved and estimated row countExample list the tables involved and estimated row count
{{list_known_indexes_or_write_unknown}}List known indexes or write unknownExample list known indexes or write unknown
{{if_known}}If knownif known
{{how_often_this_query_runs_and_how_many_rows_it_n}}How often this query runs and how many rows it nhow often this query runs and how many rows it needs to process
{{use_case}}Your specific valueoptimise a slow database query

How to customize this prompt

  1. Replace each {{double-curly}} with your real context.
  2. Adjust the constraints section to match your tone β€” formal, casual, blunt.
  3. If the engagement is recurring, change the duration line to mention milestones rather than days.
  4. Run it in your tool of choice. The output should be ready to paste with at most one small edit.

When to use

When a query is causing performance issues, slow page loads, or high database load

PRO TIP

Always run EXPLAIN ANALYZE before and after the change in a staging environment. Never optimise a production query without measuring the before state.

Related prompts

Structured

Blog Post Drafting Engine

Write a complete, SEO-optimised blog post on the given topic. Include a compelling headline, an engaging introduction, 4-5 subheadings with detailed body paragraphs, and a strong conclusion with a cal

Structured

Email Newsletter Writer

Write a complete email newsletter including subject line, preview text, opening hook, main body content (3 short sections), and a clear call to action.

Structured

YouTube Video Script Writer

Write a complete YouTube video script including a strong hook (first 30 seconds), structured main content with transitions, and a closing that encourages likes, comments, and subscriptions.

Structured

LinkedIn Article Builder

Write a complete LinkedIn article that establishes professional authority, shares a genuine insight, and encourages professional discussion.

β˜… EXPLORE MORE PROMPTS

More for Professionals

Browse all prompts built for Professionals β€” free and premium, ready to copy.

Browse more prompts β†’