Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
eae358c4
S
soar
项目概览
Xiaomi
/
soar
大约 2 年 前同步成功
通知
467
Star
8513
Fork
1329
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
eae358c4
编写于
12月 15, 2018
作者:
martianzhang
提交者:
GitHub
12月 15, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #164 from liipx/master
fix #155 a new config arg 'min-cardinality' for index column selection
上级
d9d7627a
5041d85e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
2 deletion
+14
-2
advisor/index.go
advisor/index.go
+5
-1
advisor/index_test.go
advisor/index_test.go
+4
-1
common/config.go
common/config.go
+4
-0
common/testdata/TestPrintConfiguration.golden
common/testdata/TestPrintConfiguration.golden
+1
-0
未找到文件。
advisor/index.go
浏览文件 @
eae358c4
...
...
@@ -628,7 +628,6 @@ func (idxAdv *IndexAdvisor) buildJoinIndex(meta common.Meta) []IndexInfo {
indexColsList
:=
make
(
map
[
string
]
map
[
string
][]
*
common
.
Column
)
for
_
,
col
:=
range
IndexCols
{
mergeIndex
(
indexColsList
,
col
)
}
if
common
.
Config
.
TestDSN
.
Disable
||
common
.
Config
.
OnlineDSN
.
Disable
{
...
...
@@ -723,6 +722,11 @@ func (idxAdv *IndexAdvisor) buildIndexWithNoEnv(indexList map[string]map[string]
// mergeIndex 将索引用到的列去重后合并到一起
func
mergeIndex
(
idxList
map
[
string
]
map
[
string
][]
*
common
.
Column
,
column
*
common
.
Column
)
{
// 散粒度低于阈值将不会添加索引
if
common
.
Config
.
MinCardinality
/
100
>
column
.
Cardinality
{
return
}
db
:=
column
.
DB
tb
:=
column
.
Table
if
idxList
[
db
]
==
nil
{
...
...
advisor/index_test.go
浏览文件 @
eae358c4
...
...
@@ -357,6 +357,8 @@ func TestRuleUpdatePrimaryKey(t *testing.T) {
func
TestIndexAdvise
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
minCardinalityBak
:=
common
.
Config
.
MinCardinality
common
.
Config
.
MinCardinality
=
20
vEnv
,
rEnv
:=
env
.
BuildEnv
()
defer
vEnv
.
CleanUp
()
...
...
@@ -377,12 +379,13 @@ func TestIndexAdvise(t *testing.T) {
if
idxAdvisor
!=
nil
{
rule
:=
idxAdvisor
.
IndexAdvise
()
.
Format
()
if
len
(
rule
)
>
0
{
pretty
.
Println
(
rule
)
_
,
_
=
pretty
.
Println
(
rule
)
}
}
}
}
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
common
.
Config
.
MinCardinality
=
minCardinalityBak
}
func
TestIndexAdviseNoEnv
(
t
*
testing
.
T
)
{
...
...
common/config.go
浏览文件 @
eae358c4
...
...
@@ -110,6 +110,7 @@ type Configuration struct {
MaxSubqueryDepth
int
`yaml:"max-subquery-depth"`
// 子查询最大尝试
MaxVarcharLength
int
`yaml:"max-varchar-length"`
// varchar最大长度
ColumnNotAllowType
[]
string
`yaml:"column-not-allow-type"`
// 字段不允许使用的数据类型
MinCardinality
float64
`yaml:"min-cardinality"`
// 添加索引散粒度阈值,范围 0~100
// ++++++++++++++EXPLAIN检查项+++++++++++++
ExplainSQLReportType
string
`yaml:"explain-sql-report-type"`
// EXPLAIN markdown 格式输出 SQL 样式,支持 sample, fingerprint, pretty 等
...
...
@@ -163,6 +164,7 @@ var Config = &Configuration{
ConnTimeOut
:
3
,
QueryTimeOut
:
30
,
Delimiter
:
";"
,
MinCardinality
:
0
,
MaxJoinTableCount
:
5
,
MaxGroupByColsCount
:
5
,
...
...
@@ -512,6 +514,7 @@ func readCmdFlags() error {
connTimeOut
:=
flag
.
Int
(
"conn-time-out"
,
Config
.
ConnTimeOut
,
"ConnTimeOut, 数据库连接超时时间,单位秒"
)
queryTimeOut
:=
flag
.
Int
(
"query-time-out"
,
Config
.
QueryTimeOut
,
"QueryTimeOut, 数据库SQL执行超时时间,单位秒"
)
delimiter
:=
flag
.
String
(
"delimiter"
,
Config
.
Delimiter
,
"Delimiter, SQL分隔符"
)
minCardinality
:=
flag
.
Float64
(
"min-cardinality"
,
Config
.
MinCardinality
,
"MinCardinality,索引列散粒度最低阈值,散粒度低于该值的列不添加索引,建议范围0.0 ~ 100.0"
)
// +++++++++++++++日志相关+++++++++++++++++
logLevel
:=
flag
.
Int
(
"log-level"
,
Config
.
LogLevel
,
"LogLevel, 日志级别, [0:Emergency, 1:Alert, 2:Critical, 3:Error, 4:Warning, 5:Notice, 6:Informational, 7:Debug]"
)
logOutput
:=
flag
.
String
(
"log-output"
,
Config
.
LogOutput
,
"LogOutput, 日志输出位置"
)
...
...
@@ -612,6 +615,7 @@ func readCmdFlags() error {
Config
.
IgnoreRules
=
strings
.
Split
(
*
ignoreRules
,
","
)
Config
.
RewriteRules
=
strings
.
Split
(
*
rewriteRules
,
","
)
*
blackList
=
strings
.
TrimSpace
(
*
blackList
)
Config
.
MinCardinality
=
*
minCardinality
if
filepath
.
IsAbs
(
*
blackList
)
||
*
blackList
==
""
{
Config
.
BlackList
=
*
blackList
...
...
common/testdata/TestPrintConfiguration.golden
浏览文件 @
eae358c4
...
...
@@ -71,6 +71,7 @@ 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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录