AI-Powered EXPLAIN Analysis
The Pattern: Use AI with database MCP servers to interpret complex execution plans and identify bottlenecks.
-- PRD: Query Performance Analysis-- Plan: Use database MCP for schema context
-- First, connect to database MCP"Connect to PostgreSQL MCP and get schema information for the relevant tables"
-- Then analyze the query"Using the schema context, analyze this query execution plan and identify performance issues:
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)SELECT c.customer_name, COUNT(o.order_id) as order_count, SUM(oi.quantity * oi.unit_price) as total_spentFROM customers cJOIN orders o ON c.customer_id = o.customer_idJOIN order_items oi ON o.order_id = oi.order_idWHERE o.order_date >= '2024-01-01'GROUP BY c.customer_id, c.customer_nameORDER BY total_spent DESCLIMIT 100;"
AI Analysis Provides:
- Identification of table scans vs index scans
- Buffer hit ratios and memory usage
- Join method recommendations
- Missing index suggestions
- Query rewrite opportunities