Explain SQL Query Plan
pg_explainShow the execution plan for a SQL query with EXPLAIN or EXPLAIN ANALYZE to analyze query performance. Get planned strategy or real execution stats including timing and row counts.
Instructions
Show the execution plan for a SQL query using EXPLAIN or EXPLAIN ANALYZE.
Use EXPLAIN to see the planned query strategy. Use EXPLAIN ANALYZE to actually execute the query and see real timing and row count statistics (costs real I/O).
Args:
sql: SQL query to explain (required, should be a SELECT)
analyze: Run EXPLAIN ANALYZE (executes the query, default: false)
buffers: Include buffer usage statistics — only with analyze:true (default: false)
format: Output format for the plan, 'text' or 'json' (default: text)
response_format: Response format
Returns: The query plan as text or JSON. Use 'json' format for programmatic parsing.
Warning: EXPLAIN ANALYZE actually executes the query, including any side effects.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to explain | |
| analyze | No | Run EXPLAIN ANALYZE (executes the query) | |
| buffers | No | Include buffer stats (only with analyze: true) | |
| format | No | Plan format: 'text' or 'json' | text |
| response_format | No | Output format: 'markdown' for human-readable, 'json' for machine-readable | markdown |