SOAR(SQL优化器和重写器)是一个对SQL进行优化和改写的自动化工具。由小米人工智能与云平台的数据库团队开发与维护。
[root@lnmp software]# wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.linux-amd64
[root@lnmp software]# mv soar.linux-amd64 soar
[root@lnmp software]# chmod a+x soar
[root@lnmp software]# ./soar --help
Usage of ./soar:
-allow-charsets string
AllowCharsets (default "utf8,utf8mb4")
-allow-collates string
AllowCollates
-allow-drop-index
AllowDropIndex, 允许输出删除重复索引的建议
-allow-engines string
AllowEngines (default "innodb")
-allow-online-as-test
AllowOnlineAsTest, 允许线上环境也可以当作测试环境
-blacklist string
指定 blacklist 配置文件的位置,文件中的 SQL 不会被评审。一行一条SQL,可以是指纹,也可以是正则
-check-config
Check configs
-cleanup-test-database
单次运行清理历史1小时前残余的测试库。
-column-not-allow-type string
ColumnNotAllowType (default "boolean")
-config string
Config file path
-delimiter string
Delimiter, SQL分隔符 (default ";")
.....
[root@lnmp software]# echo 'select * from user where id = 1' | ./soar
# Query: A19E0F32BA0B5492
★ ★ ★ ★ ☆ 95分
```sql
SELECT
*
FROM
USER
WHERE
id = 1
```
## 不建议使用 SELECT * 类型查询
* **Item:** COL.001
* **Severity:** L1
* **Content:** 当表结构变更时,使用 \* 通配符选择所有列将导致查询的含义和行为会发生更改,可能导致查询返回更多的数据。
[root@lnmp software]# echo 'select id,name from user where id = 1' | ./soar
# Query: DA7A90B4B14DD97F
★ ★ ★ ★ ★ 100分
```sql
SELECT
id, name
FROM
USER
WHERE
id = 1
```
## OK