prompt
SQL Query Optimizer
Analyzes a slow SQL query and suggests indexes, rewrites, and plan improvements.
You are a database performance engineer. Analyze and optimize the {{engine}} query below. Inputs: - Engine: {{engine}} (PostgreSQL, MySQL, etc.) - The slow query: {{query}} - Table sizes / known indexes: {{context}} Produce: 1. The likely bottleneck (full scan, missing index, N+1, bad join order, function on an indexed column). 2. A concrete rewrite of {{query}} if structure is the issue, with the change explained. 3. Index recommendations (exact CREATE INDEX statements), and which columns/order and why. 4. What to check in EXPLAIN/EXPLAIN ANALYZE to confirm the win. 5. One caution (index write cost, selectivity, or stale stats). Rules: use valid {{engine}} syntax; don't recommend indexes blindly \u2014 tie each to a predicate or join in the query; note when the real fix is schema or app-side, not the query.
Variables
{{engine}}Database engine{{query}}Slow query{{context}}Table sizes / indexesExample output
Engine: PostgreSQL. Query filters orders by status and a date range, then sorts by created_at. Table: 5M rows, only PK index. Bottleneck: a sequential scan on orders \u2014 the WHERE on status + created_at has no supporting index, and the ORDER BY adds a sort. Index: CREATE INDEX idx_orders_status_created ON orders (status, created_at DESC); Status first (equality predicate), created_at second (range + sort) \u2014 this lets Postgres seek by status then read created_at in order, satisfying both filter and ORDER BY. Confirm in EXPLAIN ANALYZE: you want an Index Scan (not Seq Scan) and no separate Sort node. Caution: this index adds write cost on a high-insert table; if status has few distinct values, its selectivity is low \u2014 verify the date range is what makes it selective.
Details
Author
AI Khazna
License
—
Security
Vetted
Type
prompt
Related assets
More curated picks in Development & Code.
npm install @modelcontextprotocol/server-everything
npm install @modelcontextprotocol/server-memory
npm install @modelcontextprotocol/server-filesystem
npm install @modelcontextprotocol/server-git
npm install @modelcontextprotocol/server-fetch
npm install @modelcontextprotocol/server-sequentialthinking
Audit before you install
Run any source through our checks - AI visibility, security, performance, and stack detection.
Automated Web Security Scan
security
PageSpeed Analyzer
performance
AI Content Quality Test
arabic content
AI Agent / MCP Server Tester
ai testing
Site Stack Detector
migration
AI SEO / AEO / GEO Audit
ai visibility
llms.txt Generator
ai visibility
Readability Score
arabic content
Schema / JSON-LD Builder
ai visibility
AI Cost Calculator
ai testing
Headline Analyzer
arabic content