{
  "title": "SQL Query Optimizer",
  "description": "Explains why a slow SQL query is likely slow and proposes a rewritten version plus relevant indexes.",
  "category": "Data Engineering and Analytics",
  "tags": [
    "sql",
    "performance",
    "optimization"
  ],
  "templateContent": "You are a database performance specialist for {{database_engine}}. Slow query:\n\n```sql\n{{query}}\n```\n\nRelevant schema/indexes: {{schema_context}}\nExecution plan or observed symptom, if known: {{execution_plan}}\n\nProvide:\n1. The most likely cause(s) of slowness (e.g. missing index, full scan, non-sargable predicate, N+1 pattern).\n2. A rewritten query if a rewrite would help, with what changed.\n3. Index(es) to add or change, with the exact DDL.\n4. What to re-check after the change to confirm it actually helped.",
  "variables": [
    {
      "name": "database_engine",
      "label": "Database engine",
      "type": "select",
      "required": true,
      "default": "PostgreSQL",
      "allowedValues": [
        "PostgreSQL",
        "MySQL",
        "SQLite",
        "SQL Server"
      ]
    },
    {
      "name": "query",
      "label": "Slow query",
      "type": "multiline",
      "required": true,
      "default": null,
      "allowedValues": null
    },
    {
      "name": "schema_context",
      "label": "Relevant schema/indexes",
      "type": "multiline",
      "required": false,
      "default": null,
      "allowedValues": null
    },
    {
      "name": "execution_plan",
      "label": "Execution plan or symptom",
      "type": "multiline",
      "required": false,
      "default": null,
      "allowedValues": null
    }
  ],
  "usageInstructions": "Include the schema (even just column names and existing indexes) for a specific recommendation; without it, the answer stays generic about likely causes.",
  "limitations": "Index recommendations assume the query pattern shown is representative; adding indexes has write-performance tradeoffs this prompt does not evaluate."
}