SQL Query Plan EXPLAIN Optimizer & Bottleneck Diagnostics
analyze_query_planAnalyze SQL EXPLAIN plans to detect sequential scans, costly cartesian joins, and buffer bottlenecks when diagnosing slow queries or optimizing database performance.
Instructions
Analyzes 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.
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. |