Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_67397764
soar
提交
a583e9d8
S
soar
项目概览
m0_67397764
/
soar
与 Fork 源项目一致
Fork自
Xiaomi / soar
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a583e9d8
编写于
12月 26, 2018
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix explain empty struct problem, null able column
上级
5d7071ab
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
15 deletion
+52
-15
database/explain.go
database/explain.go
+30
-15
database/mysql.go
database/mysql.go
+8
-0
database/mysql_test.go
database/mysql_test.go
+14
-0
未找到文件。
database/explain.go
浏览文件 @
a583e9d8
...
...
@@ -948,23 +948,31 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
return
exp
,
err
}
/*
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| 1 | SIMPLE | film | NULL | ALL | NULL | NULL | NULL | NULL | 1000 | 100.00 | NULL |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
*/
// Different MySQL version has different columns define
var
possibleKeys
string
var
selectType
,
table
,
partitions
,
accessType
,
possibleKeys
,
key
,
keyLen
,
ref
,
extra
[]
byte
expRow
:=
&
ExplainRow
{}
explainFields
:=
make
([]
interface
{},
0
)
fields
:=
map
[
string
]
interface
{}{
"id"
:
expRow
.
ID
,
"select_type"
:
expRow
.
S
electType
,
"table"
:
expRow
.
TableNam
e
,
"partitions"
:
expRow
.
P
artitions
,
"type"
:
expRow
.
A
ccessType
,
"id"
:
&
expRow
.
ID
,
"select_type"
:
&
s
electType
,
"table"
:
&
tabl
e
,
"partitions"
:
&
p
artitions
,
"type"
:
&
a
ccessType
,
"possible_keys"
:
&
possibleKeys
,
"key"
:
expRow
.
K
ey
,
"key_len"
:
expRow
.
K
eyLen
,
"ref"
:
expRow
.
R
ef
,
"rows"
:
expRow
.
Rows
,
"filtered"
:
expRow
.
Filtered
,
"
extra"
:
expRow
.
E
xtra
,
"key"
:
&
k
ey
,
"key_len"
:
&
k
eyLen
,
"ref"
:
&
r
ef
,
"rows"
:
&
expRow
.
Rows
,
"filtered"
:
&
expRow
.
Filtered
,
"
Extra"
:
&
e
xtra
,
}
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
...
...
@@ -980,13 +988,20 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
// 补全 ExplainRows
var
explainRows
[]
*
ExplainRow
for
res
.
Rows
.
Next
()
{
err
:=
res
.
Rows
.
Scan
(
explainFields
...
)
if
err
!=
nil
{
common
.
Log
.
Debug
(
err
.
Error
())
common
.
Log
.
Warn
(
err
.
Error
())
}
expRow
.
PossibleKeys
=
strings
.
Split
(
possibleKeys
,
","
)
expRow
.
SelectType
=
NullString
(
selectType
)
expRow
.
TableName
=
NullString
(
table
)
expRow
.
Partitions
=
NullString
(
partitions
)
expRow
.
AccessType
=
NullString
(
accessType
)
expRow
.
PossibleKeys
=
strings
.
Split
(
NullString
(
possibleKeys
),
","
)
expRow
.
Key
=
NullString
(
key
)
expRow
.
KeyLen
=
NullString
(
keyLen
)
expRow
.
Ref
=
strings
.
Split
(
NullString
(
ref
),
","
)
expRow
.
Extra
=
NullString
(
extra
)
// MySQL bug: https://bugs.mysql.com/bug.php?id=34124
if
expRow
.
Filtered
>
100.00
{
...
...
database/mysql.go
浏览文件 @
a583e9d8
...
...
@@ -311,3 +311,11 @@ func TimeString(t time.Time) string {
}
return
t
.
Format
(
TimeFormat
)
}
// NullString null able string
func
NullString
(
buf
[]
byte
)
string
{
if
buf
==
nil
{
return
"NULL"
}
return
string
(
buf
)
}
database/mysql_test.go
浏览文件 @
a583e9d8
...
...
@@ -184,3 +184,17 @@ func TestIsView(t *testing.T) {
connTest
.
Database
=
originalDatabase
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
func
TestNullString
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
cases
:=
[][]
byte
{
nil
,
[]
byte
(
"NULL"
),
}
for
_
,
buf
:=
range
cases
{
if
NullString
(
buf
)
!=
"NULL"
{
t
.
Errorf
(
"%s want NULL"
,
string
(
buf
))
}
}
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录