get_hg_execution_plan
Analyze SQL query performance in Hologres by retrieving execution plans with runtime statistics to identify optimization opportunities.
Instructions
Get actual execution plan with runtime statistics for a SQL query in Hologres database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL query to analyze in Hologres database |
Implementation Reference
- src/hologres_mcp_server/server.py:436-449 (registration)Registration of the get_hg_execution_plan tool, including its schema definition.Tool( name="get_hg_execution_plan", description="Get actual execution plan with runtime statistics for a SQL query in Hologres database", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The SQL query to analyze in Hologres database" } }, "required": ["query"] } ),
- Input schema for the get_hg_execution_plan tool.inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The SQL query to analyze in Hologres database" } }, "required": ["query"] }
- Specific handler dispatch in call_tool function that wraps the input query with 'EXPLAIN ANALYZE' for execution plan.query = f"EXPLAIN ANALYZE {query}" elif name == "call_hg_procedure": procedure_name = arguments.get("procedure_name") arguments_list = arguments.get("arguments") if not procedure_name:
- Generic helper function that connects to the database, executes the prepared query (EXPLAIN ANALYZE), fetches results, and formats the execution plan output.def handle_call_tool(tool_name, query, serverless = False): """Handle callTool method.""" config = get_db_config() try: with connect_with_retry() as conn: with conn.cursor() as cursor: # 特殊处理 serverless computing 查询 if serverless: cursor.execute("set hg_computing_resource='serverless'") # Execute the query cursor.execute(query) # 特殊处理 ANALYZE 命令 if tool_name == "gather_hg_table_statistics": return f"Successfully {query}" # 处理其他有返回结果的查询 if cursor.description: # SELECT query columns = [desc[0] for desc in cursor.description] rows = cursor.fetchall() result = [",".join(map(str, row)) for row in rows] return "\n".join([",".join(columns)] + result) elif tool_name == "execute_dml_sql": # Non-SELECT query row_count = cursor.rowcount return f"Query executed successfully. {row_count} rows affected." else: return "Query executed successfully" except Exception as e: return f"Error executing query: {str(e)}"