Skip to main content
Glama

analyze_query_performance

Analyze SQL query performance and receive optimization suggestions to improve database efficiency and execution speed.

Instructions

Analyze query performance and provide optimization suggestions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSQL query to analyze for performance optimization
databaseNoDatabase name (optional)

Implementation Reference

  • Core implementation performing static analysis on SQL queries: calculates complexity score, detects bottlenecks, generates performance warnings and optimization suggestions using heuristic analysis.
    analyzeQuery(query, executionStats = {}, planData = {}) { // Input validation to prevent null pointer exceptions if (!query || typeof query !== 'string') { throw new Error('Query must be a non-empty string'); } try { const analysis = { query: query.trim(), query_type: this.determineQueryType(query), complexity_score: this.calculateComplexityScore(query), estimated_cost: planData.TotalSubtreeCost || 0, table_access_methods: this.extractTableAccessMethods(planData), join_algorithms: this.extractJoinAlgorithms(planData), operators: this.extractOperators(planData), bottlenecks: this.identifyBottlenecks(query, executionStats, planData), performance_warnings: this.generatePerformanceWarnings(query, executionStats), optimization_suggestions: this.generateOptimizationSuggestions( query, executionStats, planData ), is_modification_query: this.isModificationQuery(query) }; return analysis; } catch (error) { // Log the error and return a safe fallback analysis console.error('Error during query analysis:', error.message); return { query: query.trim(), query_type: 'UNKNOWN', complexity_score: 0, estimated_cost: 0, table_access_methods: [], join_algorithms: [], operators: [], bottlenecks: [], performance_warnings: ['Query analysis failed due to parsing error'], optimization_suggestions: [], is_modification_query: false, error: 'Query analysis failed' }; }
  • Tool schema definition including input validation schema with required 'query' parameter and optional 'database'.
    name: 'analyze_query_performance', description: 'Analyze query performance and provide optimization suggestions', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'SQL query to analyze for performance optimization' }, database: { type: 'string', description: 'Database name (optional)' } }, required: ['query'] } }
  • index.js:333-336 (registration)
    Tool registration in the main MCP tool call dispatcher switch statement.
    case 'analyze_query_performance': return { content: await this.analyzeQueryPerformance(args.query, args.database) };
  • MCP tool handler wrapper that delegates analysis to QueryOptimizer class and formats JSON response.
    async analyzeQueryPerformance(query, database) { const analysis = await this.queryOptimizer.analyzeQuery(query, database); return [ { type: 'text', text: JSON.stringify( { success: true, data: analysis }, null, 2 ) } ];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/egarcia74/warp-sql-server-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server