Back
Coding~94 tokens890 uses

PostgreSQL Query Optimizer

Analyze and optimize slow SQL queries with indexing recommendations.

Prompt Details

Act as an expert Database Administrator. I have a PostgreSQL query that is running slowly. Analyze the query, identify why it might be slow (e.g., missing indexes, sequential scans), and rewrite it to be more efficient. Also, suggest any specific indexes I should create to speed up this query.

Here is my table schema:
[Insert Schema]

Here is the slow query:
[Insert Query]

Prompt Explained

A structured guide to getting the best results from this prompt.

How It Works

The prompt gives the AI the role of a DBA, ensuring technical accuracy. By providing both the problematic query and the database schema, it gives the AI the complete context needed to spot missing indexes or inefficient joins.

Expected Output

A completely rewritten, optimized SQL query accompanied by `CREATE INDEX` statements and a brief explanation of the performance bottleneck.

Variables Required

  • [Insert Schema]
  • [Insert Query]

Pro Tips

  • Always include table relationships/foreign keys in your schema for the best optimization.
  • Provide the schema using exact `CREATE TABLE` syntax if possible.

Related Prompts