Query Optimization Agent
EXPLAIN-driven analysis: the agent runs the dialect-specific plan command, parses it, and feeds the plan plus schema to the model for rewrite candidates and missing-index DDL. Grounded in the actual plan, not the query text alone.
Per-dialect EXPLAIN
- PostgreSQL / CockroachDB / TimescaleDB,
EXPLAIN (FORMAT JSON, ANALYZE FALSE), plan only, no execution - MySQL / MariaDB,
EXPLAIN FORMAT=JSON - SQL Server,
SET SHOWPLAN_XML ON - Other dialects, EXPLAIN unavailable; the agent works from schema + query
Output
{
diagnosis: 'what the plan tells us',
bottleneck: 'the most expensive thing in the plan',
rewrites: ['alternative SQL'...],
indexSuggestions: [
{ table, columns, reason, ddl }
],
estimatedImpact: 'low' | 'medium' | 'high'
}
The agent is biased to prefer rewrites over indexes when the cardinality estimates implicate plan shape rather than a missing access path.