explain_query
Analyze a SQL query's execution plan to understand how the database runs it and get cost estimates. Optionally run the query for actual statistics or simulate hypothetical indexes.
Instructions
Explains the execution plan for a SQL query, showing how the database will execute it and provides detailed cost estimates.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to explain | |
| analyze | No | When True, actually runs the query to show real execution statistics instead of estimates. Takes longer but provides more accurate information. | |
| hypothetical_indexes | No | A list of hypothetical indexes to simulate. Each index must be a dictionary with these keys: - 'table': The table name to add the index to (e.g., 'users') - 'columns': List of column names to include in the index (e.g., ['email'] or ['last_name', 'first_name']) - 'using': Optional index method (default: 'btree', other options include 'hash', 'gist', etc.) Examples: [ {"table": "users", "columns": ["email"], "using": "btree"}, {"table": "orders", "columns": ["user_id", "created_at"]} ] If there is no hypothetical index, you can pass an empty list. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |