b014e2c5-1835-8d44-0f84-317a6823652eClaudeGPT-4Gemini

SQL Query Performance Optimizer

Use case: Optimizing database query execution time and performance

180 copies900 views37 words
VERIFIED SEO TEMPLATE
WHAT THIS PROMPT DOES
  • Designed to solve: Optimizing database query execution time and performance
  • Recommended engine compatibility: Runs best on Claude or GPT-4 or Gemini
  • Structure layout: Incorporates 1 custom input variable fields
  • Execution output target: Generates structured markdown lists and blocks

PROMPT SOURCE CODE

Analyze and optimize the following SQL query to reduce latency and improve execution cost on a PostgreSQL database:

```sql
{{raw_query}}
```

Explain the bottlenecks, propose structural fixes (e.g., using indexing, subqueries to CTEs, or joining on keys), and return the optimized query alongside execution plan tips.

This prompt has 1 variable(s):

EXAMPLE OUTPUT

### Bottlenecks Identified 1. Nested subquery is executing iteratively. Converting this to a standard `INNER JOIN` or a `Common Table Expression (CTE)` allows PostgreSQL to plan joins optimally. 2. Selecting all columns (`*`) blocks index-only scans. ### Optimized Query ```sql WITH user_subset AS ( SELECT id, username FROM users WHERE active = true ) SELECT o.id, o.amount, u.username FROM orders o INNER JOIN user_subset u ON o.user_id = u.id; ```
Generated using ClaudeOutputs may vary. Always review AI-generated content.

TEST THIS PROMPT LIVE

Live Console

Prompt Library

0 items
search
No prompts matching the filters were found.

Prompt Sandbox

Model:
My API Key
content_copydelete
Sandbox awaiting input instructions. Enter values and click "Run Prompt" to execute model outputs.
0 / 20 free runs today
Latency: 32ms | Status: Optimal

Related AI Prompts

INTEGRATED RECOMMENDATION

Accelerate your workflow with Feedalyze

AI churn detection for SaaS. Know which customers will leave before they do.

Free plan available · Connects to HubSpot, Intercom, Zendesk