SQL Query Plan EXPLAIN Optimizer & Bottleneck Diagnostics
analyze_query_planAnalyzes SQL EXPLAIN execution plans to detect sequential table scans, high-cost cartesian joins, and buffer memory bottlenecks. Use when diagnosing slow queries, optimizing database performance, or evaluating query cost; for getting index recommendations, use recommend_database_indexes instead. Stateless read-only edge call (max 32 KB, 60 RPM): accepts 'explain_plan_or_query' ('optimization_target' defaults to 'eliminate_seq_scans'), supports '?demo=true' or L402 (15 sats), and returns HTTP 400 if invalid.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"explain_plan_or_query": "<explain_plan_or_query>"
},
"name": "analyze_query_plan"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database_engine | No | Database engine name (e.g., 'postgres', 'mysql', 'sqlite'). | |
| optimization_target | No | Optimization goal: eliminate sequential scans, reduce memory buffers, or minimize join costs. | |
| explain_plan_or_query | Yes | Raw text or JSON output of EXPLAIN / EXPLAIN ANALYZE or the candidate SQL query. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bottlenecks_detected | Yes | Identified query execution bottlenecks (e.g., Seq Scan on large table, Nested Loop join). | |
| recommended_rewrites | Yes | Specific SQL query rewrites and predicate adjustments to improve performance. | |
| estimated_cost_reduction_pct | Yes | Estimated potential query cost reduction percentage with recommended optimizations. |