soar
SQL Optimizer And Rewriter
Command-line tool from Xiaomi that analyzes MySQL SQL statements and automatically suggests performance improvements, index recommendations, and query rewrites without needing to manually read execution plans.
SOAR stands for SQL Optimizer And Rewriter. It is a command-line tool, built by Xiaomi's database team, that analyzes MySQL SQL statements and suggests or applies improvements automatically. It was designed to help developers and database administrators write better-performing queries without needing to manually trace every execution plan.
The tool works by examining submitted SQL and applying a set of heuristic optimization rules. For queries that could benefit from additional indexes, SOAR can suggest multi-column index structures covering SELECT, INSERT, UPDATE, and DELETE operations. It can also parse the output of MySQL's EXPLAIN command and translate the technical details into a more readable explanation, making it easier to understand why a query is running slowly.
Beyond optimization advice, SOAR can reformat and compress SQL for readability, generate a fingerprint (a normalized version of the statement with literal values removed), and merge multiple ALTER TABLE statements targeting the same table into one, which avoids the cost of repeated table locking during schema changes.
Custom rewrite rules are also supported, so teams can encode their own SQL conventions and have SOAR flag or automatically correct statements that violate them.
The README and most of the linked documentation are written in Chinese. A separate English README file is available in the repository. The tool runs on Linux and Mac, with Windows supported in principle though not fully tested. It is released under the Apache 2.0 license.
Where it fits
- Run a slow MySQL query through SOAR to get specific index recommendations and a plain-English EXPLAIN breakdown
- Use SOAR's SQL formatter to normalize and compress query strings in a codebase for readability
- Merge multiple ALTER TABLE statements targeting the same table into one command to avoid repeated table locks during schema changes