Chinese README / 中文说明 | Contributing Guide | Security Policy
This is an open-source SQL optimization agent for MySQL workloads, built with Spring Boot, LangChain4j, and an OpenAI-compatible API.
The project currently moves along one core workflow and one experimental workflow:
Optimization Analysisis the primary feature and the best place to start. It analyzes a single SQL statement, generates candidate optimization plans, validates them with system-side execution, and returns the best plan with evidence.Single-table multi-index designis still in testing. The current UI and API expose an experimental index recommendation workflow for grouped SQL statements, and it should still be treated as an evolving prototype rather than a stable flagship feature.
- English is the primary open-source entry point for prompts, architecture, and contributor-facing documentation.
- Chinese documentation is kept in README.zh-CN.md.
- The web UI is being upgraded toward bilingual switching for demo and community use.
Most LLM-based SQL tools stop at "advice". This project aims to go further:
- Evidence-first: start from
EXPLAIN, schema metadata, statistics, and execution traces. - System-validated: candidate plans are not only proposed by the model, but also executed, compared, and scored by the application.
- Demo-safe by default: destructive or mutation-style endpoints are disabled in the default open-source setup.
- Input SQL query and receive AI-powered optimization suggestions
- Real-time streaming of execution progress
- Before/after EXPLAIN plan comparison
- Candidate plan workbench with performance metrics
- Browse all tables in your database
- View table structure and existing indexes
- Analyze statistics and data distribution
- Multi-SQL workload analysis
- Index coverage and recommendation reasoning
- DDL suggestions for index optimization
This is the most polished workflow in the project today, and it is the part open-source users should try first.
In this workflow, the system:
- accepts a single
SELECT/WITHquery - lets the model generate 1 to 5 candidate optimization plans
- measures a baseline
- validates rewritten SQL and temporary index plans in a sandbox
- compares results for correctness
- scores candidates and selects the best one
- streams execution progress to the UI
- persists analysis history for replay
Core entry points:
- OptimizationController.java
- UnifiedOptimizationService.java
- PlanGenerator.java
- PlanExecutionEngine.java
- PlanEvaluator.java
The current /api/analyze/workload flow is best understood as the experimental foundation for future single-table multi-index design.
What is already there:
- Accepts multiple SQL statements
- Produces a recommended index set
- Shows coverage, reasoning, and suggested DDL
- Useful for demos and internal iteration
Why it is still experimental:
- It does not have the same system-side validation loop as the optimization analysis workflow
- It is still being shaped toward a more focused single-table index design and retirement assistant
- The front-end labels it as experimental because that better reflects its maturity
Related files:
- Single SQL optimization analysis
- Streaming execution timeline
- Explain comparison before and after optimization
- Candidate plan workbench
- Baseline measurement and result comparison
- History replay
- SQL input validation
- Schema inspection
- Table/index browsing
- Statistics and skew analysis
- Temporary index sandbox execution
- Grouped SQL index recommendation
- Early-stage exploration toward single-table multi-index design
Browser UI
-> REST / SSE Controllers
-> Optimization Services
-> LLM Agents + SQL Tools
-> Execution Engine + Sandbox + Evaluator
-> MySQL
Main modules:
controller: REST and SSE entry pointsservice: orchestration, history, response assembly, execution tracesagent: LangChain4j agent interfacestools: explain, ddl, execute, compare, statistics, covering index, data skew, index recommendationengine: candidate execution enginesandbox: temporary index lifecycle managementevaluator: candidate scoring and best-plan selectionstatic: front-end pages and components
The repository is configured for open-source usage first, not for direct production write access.
Default runtime flags:
SQL_AGENT_DEMO_READ_ONLY=trueSQL_AGENT_MUTATION_ENABLED=false
When mutation is disabled:
/api/apply-optimizationcannot create real indexes/api/index/dropcannot delete indexes- the UI hides or disables mutation-oriented actions
Runtime feature endpoint:
GET /api/features
- Copy the environment template:
cp .env.example .env- Edit
.envand provide at least:
SQL_AGENT_DB_URLSQL_AGENT_DB_USERNAMESQL_AGENT_DB_PASSWORDSQL_AGENT_MODEL_BASE_URLSQL_AGENT_MODEL_API_KEYSQL_AGENT_MODEL
- Start the stack:
docker compose up --build- Open:
http://localhost:8899
Notes:
- MySQL loads schema.sql on startup
- keep mutation disabled for open-source demos unless you are in a controlled local environment
- Copy the environment template:
cp .env.example .env-
Prepare a MySQL database and import schema.sql
-
Export the variables from
.envinto your shell -
Run:
mvn spring-boot:runImportant variables:
SQL_AGENT_DB_URLSQL_AGENT_DB_USERNAMESQL_AGENT_DB_PASSWORDSQL_AGENT_MODEL_BASE_URLSQL_AGENT_MODEL_API_KEYSQL_AGENT_MODELSQL_AGENT_AVAILABLE_MODELSSQL_AGENT_DEMO_READ_ONLYSQL_AGENT_MUTATION_ENABLED
See .env.example for a full example.
The project uses an OpenAI-compatible API contract.
That means you can plug in:
- OpenAI directly
- self-hosted gateways
- proxy services
- model providers that expose OpenAI-compatible chat completion endpoints
POST /api/optimizePOST /api/optimize/stream
POST /api/analyze/workload
GET /api/modelsGET /api/toolsGET /api/optimization-samplesGET /api/featuresPOST /api/sql/validateGET /api/healthGET /api/tablesGET /api/table/{tableName}/detail
GET /api/history/listGET /api/history/{id}DELETE /api/history/{id}
The UI intentionally reflects the current maturity of each workflow:
Optimization Analysisis presented as the main experience- the index-design page is explicitly marked as experimental / testing-stage
- table browsing remains read-only by default in open-source mode
Main front-end files:
Current automated coverage focuses on:
- SQL pattern detection
- SQL input validation
- response deserialization compatibility
- candidate scoring selection
Run tests with:
mvn test- improve the open-source onboarding experience
- add more integration tests
- provide demo data and repeatable benchmark cases
- document deployment profiles more clearly
- evolve the experimental workflow into a real single-table multi-index design assistant
- support keep/add/retire decisions for index sets
- add stronger system-side validation for index recommendations
- the experimental index workflow is not yet as rigorous as the optimization analysis workflow
- some recommendation logic is still heuristic and under active iteration
- the front-end still depends on external CDN/font resources
See CONTRIBUTING.md
MIT, see LICENSE


