---
name: sql-query-optimizer
description: "Optimize slow SQL queries and get suggestions for better indexing and performance. Use when the user wants help with SQL Query Optimizer. Related topics: sql, database, performance."
---

# SQL Query Optimizer

Optimize slow SQL queries and get suggestions for better indexing and performance.

## How to use this skill

1. Ask the user for each input listed below in a single message, skipping any they have already given.
2. Where options are listed, offer them, but accept other answers too.
3. Fill the answers into the prompt template, then follow the completed prompt to produce the result.

## Inputs

- **Database Engine** (choose one: PostgreSQL, MySQL, SQL Server, SQLite, Oracle)
- **Query Type** (choose one: SELECT, INSERT, UPDATE, DELETE, Complex JOIN)
- **Paste the slow query here** (longer free text)
- **Approximate number of rows in main table** (number from 1000 to 100000000)
- **Describe the table schema/indexes** (longer free text)
- **Main bottlenecks to check** (choose any: Missing Indexes, Subqueries, JOIN optimization, N+1 problem)
- **Explain the execution plan changes?** (choose one: Yes, No)

## Prompt template

## Introduction
Improve the execution speed of your SQL queries.

## Database Information
- Database Engine: {{Database Engine}}
- Query Type: {{Query Type}}

## The Query
- Paste your SQL Query:
{{Paste the slow query here}}

## Context & Performance
- Approximate number of rows in main table: {{Approximate number of rows in main table}}
- Describe the table schema/indexes: {{Describe the table schema/indexes}}
- Main bottlenecks to check: {{Main bottlenecks to check}}

## Output Preferences
- Explain the execution plan changes? {{Explain the execution plan changes?}}

---
**Goal**: Provide an optimized version of the query with a detailed explanation of why it is faster.

---

Source: [SQL Query Optimizer on PromptBuild](https://promptbuild.io/prompt/mTVbthgfBwzZezspbTzV/sql-query-optimizer)
