SOAR

SOAR(SQL Optimizer And Rewriter)是一个对SQL进行优化和改写的自动化工具。 由小米人工智能与云平台的数据库团队开发与维护。

功能特点跨平台支持(支持Linux, Mac环境,Windows环境理论上也支持,不过未全面测试)

目前只支持 MySQL 语法族协议的SQL优化

支持基于启发式算法的语句优化

支持复杂查询的多列索引优化(UPDATE, INSERT, DELETE, SELECT)

支持EXPLAIN信息丰富解读

支持SQL指纹、压缩和美化

支持同一张表多条ALTER请求合并

支持自定义规则的SQL改写

使用方法下载 https://github.com/XiaoMi/soar/releases  soar.windows-amd64 并修改文件名为 soar.exe,,放在soar文件夹

进入soar目录,cmd命令行输入,soar -version,输出如下信息,则安装成功

3.输入soar -h 获取帮助信息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, 允许线上环境也可以当作测试环境 (default true)

-alsologtostderr

log to standard error as well as files

-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 ";")

-drop-test-temporary

DropTestTemporary, 是否清理测试环境产生的临时库表 (default true)

-dry-run

是否在预演环境执行 (default true)

-explain

Explain, 是否开启Explain执行计划分析 (default true)

-explain-format string

ExplainFormat [json, traditional] (default "traditional")

-explain-max-filtered float

ExplainMaxFiltered, filtered大于该配置给出警告 (default 100)

-explain-max-keys int

ExplainMaxKeyLength, 最大key_len (default 3)

-explain-max-rows int

ExplainMaxRows, 最大扫描行数警告 (default 10000)

-explain-min-keys int

ExplainMinPossibleKeys, 最小possible_keys警告

-explain-sql-report-type string

ExplainSQLReportType [pretty, sample, fingerprint] (default "pretty")

-explain-type string

ExplainType [extended, partitions, traditional] (default "extended")

-explain-warn-access-type string

ExplainWarnAccessType, 哪些access type不建议使用 (default "ALL")

-explain-warn-extra string

ExplainWarnExtra, 哪些extra信息会给警告 (default "Using temporary,Using filesort")

-explain-warn-scalability string

ExplainWarnScalability, 复杂度警告名单, 支持O(n),O(log n),O(1),O(?) (default "O(n)")

-explain-warn-select-type string

ExplainWarnSelectType, 哪些select_type不建议使用

-ignore-rules string

IgnoreRules, 忽略的优化建议规则 (default "COL.011")

-index-prefix string

IdxPrefix (default "idx_")

-list-heuristic-rules

ListHeuristicRules, 打印支持的评审规则列表

-list-report-types

ListReportTypes, 打印支持的报告输出类型

-list-rewrite-rules

ListRewriteRules, 打印支持的重写规则列表

-list-test-sqls

ListTestSqls, 打印测试case用于测试

-log-level int

LogLevel, 日志级别, [0:Emergency, 1:Alert, 2:Critical, 3:Error, 4:Warning, 5:Notice, 6

:Informational, 7:Debug] (default 7)

-log-output string

LogOutput, 日志输出位置 (default "C:\\dev\\soar\\log\\soar.log")

-log_backtrace_at value

when logging hits line file:N, emit a stack trace

-log_dir string

If non-empty, write log files in this directory

-log_rotate_max_size uint

size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800)

-logtostderr

log to standard error instead of files

-markdown-extensions int

MarkdownExtensions, markdown 转 html支持的扩展包, 参考blackfriday (default 94)

-markdown-html-flags int

MarkdownHTMLFlags, markdown 转 html 支持的 flag, 参考blackfriday

-max-column-count int

MaxColCount, 单表允许的最大列数 (default 40)

-max-distinct-count int

MaxDistinctCount, 单条 SQL 中 Distinct 的最大数量 (default 5)

-max-group-by-cols-count int

MaxGroupByColsCount, 单条 SQL 中 GroupBy 包含列的最大数量 (default 5)

-max-in-count int

MaxInCount, IN()最大数量 (default 10)

-max-index-bytes int

MaxIdxBytes, 索引总长度限制 (default 3072)

-max-index-bytes-percolumn int

MaxIdxBytesPerColumn, 索引中单列最大字节数 (default 767)

-max-index-cols-count int

MaxIdxColsCount, 复合索引中包含列的最大数量 (default 5)

-max-index-count int

MaxIdxCount, 单表最大索引个数 (default 10)

-max-join-table-count int

MaxJoinTableCount, 单条 SQL 中 JOIN 表的最大数量 (default 5)

-max-pretty-sql-length int

MaxPrettySQLLength, 超出该长度的SQL会转换成指纹输出 (default 1024)

-max-query-cost int

MaxQueryCost, last_query_cost 超过该值时将给予警告 (default 9999)

-max-subquery-depth int

MaxSubqueryDepth (default 5)

-max-text-cols-count int

MaxTextColsCount, 表中含有的 text/blob 列的最大数量 (default 2)

-max-total-rows uint

MaxTotalRows, 计算散粒度时,当数据行数大于MaxTotalRows即开启数据库保护模式,不计算散粒

度 (default 9999999)

-max-value-count int

MaxValueCount, INSERT/REPLACE 单次批量写入允许的行数 (default 100)

-max-varchar-length int

MaxVarcharLength (default 1024)

-min-cardinality float

MinCardinality,索引列散粒度最低阈值,散粒度低于该值的列不添加索引,建议范围0.0 ~ 100.

0

-online-dsn string

OnlineDSN, 线上环境数据库配置, username:password@tcp(ip:port)/schema (default "root:ro

ot@tcp(127.0.0.1:3306)/chp?charset=utf8")

-only-syntax-check

OnlySyntaxCheck, 只做语法检查不输出优化建议

-print-config

Print configs

-profiling

Profiling, 开启数据采样的情况下在测试环境执行Profile (default true)

-query string

待评审的 SQL 或 SQL 文件,如 SQL 中包含特殊字符建议使用文件名。

-report-css string

ReportCSS, 当 ReportType 为 html 格式时使用的 css 风格,如不指定会提供一个默认风格。CS

S可以是本地文件,也可以是一个URL

-report-javascript string

ReportJavascript, 当 ReportType 为 html 格式时使用的javascript脚本,如不指定默认会加载

SQL pretty 使用的 javascript。像CSS一样可以是本地文件,也可以是一个URL

-report-title string

ReportTitle, 当 ReportType 为 html 格式时,HTML 的 title (default "SQL优化分析报告")

-report-type string

ReportType, 优化建议输出格式,目前支持: json, text, markdown, html等 (default "html")

-rewrite-rules string

RewriteRules, 生效的重写规则 (default "delimiter,orderbynull,groupbyconst,dmlorderby,h

aving,star2columns,insertcolumns,distinctstar")

-sampling

Sampling, 数据采样开关

-sampling-condition string

SamplingCondition, 数据采样条件,如: WHERE xxx LIMIT xxx

-sampling-statistic-target int

SamplingStatisticTarget, 数据采样因子,对应 PostgreSQL 的 default_statistics_target (d

efault 100)

-show-last-query-cost

ShowLastQueryCost

-show-warnings

ShowWarnings

-spaghetti-query-length int

SpaghettiQueryLength, SQL最大长度警告,超过该长度会给警告 (default 2048)

-sql-max-length-errors int

truncate queries in error logs to the given length (default unlimited)

-sql-max-length-ui int

truncate queries in debug UIs to the given length (default 512) (default 512)

-stderrthreshold value

logs at or above this threshold go to stderr

-test-dsn string

TestDSN, 测试环境数据库配置, username:password@tcp(ip:port)/schema (default "root:root

@tcp(127.0.0.1:3306)/chp?charset=utf8")

-trace

Trace, 开启数据采样的情况下在测试环境执行Trace (default true)

-unique-key-prefix string

UkPrefix (default "uk_")

-v value

log level for V logs

-verbose

Verbose

-version

Print version info

-vmodule value

comma-separated list of pattern=N settings for file-filtered logging

4.创建配置文件,在soar目录创建log目录存放日志,创建目录etc,创建文件soar.yaml

配置数据库等信息# 线上环境配置

online-dsn:

user: "root"

password: 'root'

net: tcp

addr: 127.0.0.1:3306

schema: "demo"

charset: utf8

collation: utf8_general_ci

loc: UTC

tls: ""

server-public-key: ""

maxallowedpacket: 4194304

params: {}

timeout: 0

read-timeout: 0

write-timeout: 0

allow-native-passwords: true

allow-old-passwords: false

disable: false

# 测试环境配置

test-dsn:

user: "root"

password: 'root'

net: tcp

addr: 127.0.0.1:3306

schema: "demo"

charset: utf8

collation: utf8_general_ci

loc: UTC

tls: ""

server-public-key: ""

maxallowedpacket: 4194304

params: {}

timeout: 0

read-timeout: 0

write-timeout: 0

allow-native-passwords: true

allow-old-passwords: false

disable: false

# 是否允许测试环境与线上环境配置相同

allow-online-as-test: true

# 是否清理测试时产生的临时文件

drop-test-temporary: true

cleanup-test-database: false

# 语法检查小工具

only-syntax-check: false

sampling-statistic-target: 100

sampling: false

sampling-condition: ""

profiling: true

trace: true

explain: true

delimiter: ;

# 日志级别,[0:Emergency, 1:Alert, 2:Critical, 3:Error, 4:Warning, 5:Notice, 6:Informational, 7:Debug]

log-level: 7

log-output: C:\dev\soar\log\soar.log

# 优化建议输出格式

report-type: html

report-css: ""

report-javascript: ""

report-title: SQL优化分析报告

markdown-extensions: 94

markdown-html-flags: 0

ignore-rules:

- COL.011

rewrite-rules:

- delimiter

- orderbynull

- groupbyconst

- dmlorderby

- having

- star2columns

- insertcolumns

- distinctstar

blacklist: ""

max-join-table-count: 5

max-group-by-cols-count: 5

max-distinct-count: 5

max-index-cols-count: 5

max-text-cols-count: 2

max-total-rows: 9999999

max-query-cost: 9999

spaghetti-query-length: 2048

allow-drop-index: false

max-in-count: 10

max-index-bytes-percolumn: 767

max-index-bytes: 3072

allow-charsets:

- utf8

- utf8mb4

allow-collates: []

allow-engines:

- innodb

max-index-count: 10

max-column-count: 40

max-value-count: 100

index-prefix: idx_

unique-key-prefix: uk_

max-subquery-depth: 5

max-varchar-length: 1024

column-not-allow-type:

- boolean

min-cardinality: 0

explain-sql-report-type: pretty

explain-type: extended

explain-format: traditional

explain-warn-select-type:

- ""

explain-warn-access-type:

- ALL

explain-max-keys: 3

explain-min-keys: 0

explain-max-rows: 10000

explain-warn-extra:

- Using temporary

- Using filesort

explain-max-filtered: 100

explain-warn-scalability:

- O(n)

show-warnings: false

show-last-query-cost: false

query: ""

list-heuristic-rules: false

list-rewrite-rules: false

list-test-sqls: false

list-report-types: false

verbose: false

dry-run: true

max-pretty-sql-length: 1024

测试配置是否成功,命令行输入soar -print-config,输出配置文件的内容则配置文件生效

5.在soar目录创建test.sql文件,写入sql语句,如select * from book where id>1 ;

select *,count(1) from book where id>1000 ;

6.命令行输入soar -query test.sql > ./index.html则结果以html文件输出

已配置软件下载:

soar mysql_小米开源的数据库SQL性能分析工具SOAR,windows版安装使用相关推荐

  1. SQL性能分析工具SOAR介绍及实践

    1.什么是soar? SOAR(SQL Optimizer And Rewriter) 是一个对 SQL 进行优化和改写的自动化工具. 由小米人工智能与云平台的数据库团队开发与维护. 2.它有哪些功能 ...

  2. mysql性能分析工具soar使用

    目录 soar介绍 安装 windows安装 工具使用 soar介绍 soar是小米开源的一个对 SQL 进行优化和改写的自动化工具. 跨平台支持(支持 Linux, Mac 环境,Windows 环 ...

  3. 【MySQL数据库 | 第十九篇】SQL性能分析工具

    目录 前言: SQL执行频率: 慢查询日志: profile: profile各个指令: 总结: 前言: 本篇我们将为大家讲解SQL性能的分析工具,而只有熟练的掌握了性能分析的工具,才可以更好的对SQ ...

  4. 达梦数据库SQL日志分析工具Dmlog的使用

    1.使用条件 运行环境预先安装Java环境:支持liunx和windows系统运行. 说明:推荐使用java1.8版本,linux最小化安装最少要安装打印服务组件,windows下不支持java1.6 ...

  5. windows下安装php性能分析工具XHProf(windows版本)

    一.安装扩展 下载XHProf扩展:http://dev.freshsite.pl/php-extensions/xhprof.html 放入扩展文件:下载后解压出.dll文件,拷贝它到php的ext ...

  6. Windows phone 7应用之代码性能分析工具——Profile.

    前端时间断断续续的写了几篇关于Windows phone 7本地数据库访问文章. 最近在Window phone 7 APPStore上注册Apphub账号看到很多很有意思的小应用, 也结识几个专职做 ...

  7. php轻量级的性能分析工具xhprof的安装使用

    之前一直使用基于Xdebug进行PHP的性能分析,对于本地开发环境来说是够用了,但如果是线上环境的话,xdebug消耗较大,配置也不够灵活,因此线上环境建议使用xhprof进行PHP性能追踪及分析. ...

  8. java 对比工具_Java几款性能分析工具的对比

    在给客户进行应用程序维护的过程中,我注意到一些关于高负载条件下的性能问题.理论上,增加对应用程序的负载会使性能有所下降,但是我认为性能下降的比率远远高于负载的增加,同时我也发现,性能可以通过改变应用程 ...

  9. Java几款性能分析工具的对比

    在给客户的应用程序维护的过程中,我注意到在高负载下的一些性能问题.理论上,增加对应用程序的负载会使性能等比率的下降.然而,我认为性能下降的比率远远高于负载的增加.我也发现,性能可以通过改变应用程序的逻 ...

最新文章

  1. 2022-2028年中国聚硫橡胶行业市场研究及前瞻分析报告
  2. 中国12个工科世界第一,网友:全是不吃香的|软科2021世界一流学科排名
  3. golang map 删除 清空
  4. loadrunner参数化excel数据
  5. linux 文档编辑器 word,linux下vi编辑器命令大全
  6. SpringBoot整合freemarker中自定义标签获取字典表的数据
  7. 地理空间数据Geometry在MySQL中使用(二)
  8. 用户 'sa' 登录失败。 连接SQL2000出现的问题。
  9. sqlyog证书秘钥(注册码)
  10. 任我行CRM8.4破解版,任我行破解版免费下载,v8.4完整破解稳定版【捡肥皂】
  11. typora 公式对齐_让 Markdown 写作更简单 Typora 完全使用指南
  12. 《pr2019》怎么加字幕
  13. python yield from用法
  14. 怎么锻炼java逻辑思维_托马斯逻辑训练板技高一筹,锻炼编程逻辑思维能力
  15. 电子计算机的指令是由什么和什么组成的,吴承亮问:计算机指令由两部分组成它们是 计算机指令由哪两个字段组成,各自的作用是什么?...
  16. 如何写出高分IB TOK Essay?
  17. 如何取消计算机上的公式,评估公式并从单元格中删除公式(Evaluate formula and remove formula from cell)...
  18. python开发工程师是什么级别_什么条件才能成为Python开发工程师
  19. 著名的软件系统开发公司有哪些公司
  20. 借记来帐,借记往账,贷记来帐,贷记往账

热门文章

  1. ffmpeg 视频格式转换和宽高转换 制作自己想要的数据格式
  2. 敏捷开发入门教程-----摘抄
  3. 国元证券给予广联达2022年目标价85.88,立足西南,辐射全国,业绩实现高速增长,施工业务快速扩张
  4. SIFT 特征点提取
  5. cms的html调用,浅谈CMSEasy企业网站内容调用经验
  6. 三国志战略版:Daniel_S2蜀智之深入分析
  7. Forsaken喜欢独一无二的树
  8. DW1000开发笔记(四)DW1000使用轮询方式发送数据
  9. 线性SVM与Softmax分类器
  10. css渐变 百分比的理解