feat: add AI query optimization feature#56
Merged
Conversation
- Add aiController with getQueryOptimization handler - Add queryOptimizationService to call OpenAI GPT-4o with query and metrics - Add schemaService to fetch table names and schema context from user DB - Add schemaUtils to format schema for GPT prompt - Add sqlParserUtils for AST column ref and alias extraction - Add validateQuery to ensure only SELECT queries are optimized - Add optimizationLimiter rate limiting middleware - Add POST /query/optimization route - Add openai, node-sql-parser, express-rate-limit dependencies
- Add isQueryLoaded prop to TestQueryForm to lock fields and disable submit when query is loaded - Add Optimize Query with AI button with loading state - Add OptimizationResultCard component to display suggested query, explanation, and load into tester - Add handleNewQuery to reset query state - Add auto-scroll to optimization result on load
… handling - Pre-compute rounded metric values to avoid repeated toFixed calls - Add color coding to performance summary (green/red/grey) - Handle equal metric values with No difference label - Improve query recommendation caption to show "Queries are equivalent" when metrics are equal
…trics - Add warmup run before EXPLAIN ANALYZE to reflect steady state cache performance - Fix shared hit/read blocks to read from Plan node instead of Planning node - removed queryAnalysisService
…ry is active - Add isQueryLoaded prop to make Query Name and Query fields read-only when loaded - Disable submit button when query is already loaded - Update tooltip to guide user to click New Query when fields are locked - Reduce bottom margin from mb:4 to mb:2
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
wmoew
approved these changes
May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an AI-powered query optimization feature that analyzes a user's SQL query alongside its performance metrics and database schema context to suggest an improved version. Improved the QueryComparisonPage with color coding, no-difference handling, and a performance bar chart.
Reproduction steps
Testing AI Optimization on a new query:
4. Enter your database URI, query name, and a SQL query, then click Fetch Metrics
5. Once metrics appear, click "Optimize Query with AI"
6. The AI will analyze your query and return a suggested optimized version with an explanation
7. Click "Load into Tester" to load the suggested query back into the form and re-run it
Testing AI Optimization on a past query:
8. Click Query History and load a previous query
9. Re-enter your database URI in the Database URI field (we don't save the URI for security)
10. The "Optimize Query with AI" button will now be clickable — click it to get an AI suggestion
Checklist