Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
19a0bc41
S
soar
项目概览
Xiaomi
/
soar
9 个月 前同步成功
通知
373
Star
8512
Fork
1328
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
19a0bc41
编写于
12月 19, 2018
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix test case, compatible with mysql 8.0.13
上级
05030a65
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
154 addition
and
145 deletion
+154
-145
database/mysql.go
database/mysql.go
+5
-1
database/mysql_test.go
database/mysql_test.go
+2
-2
database/show.go
database/show.go
+49
-25
database/show_test.go
database/show_test.go
+1
-1
database/testdata/TestShowColumns.golden
database/testdata/TestShowColumns.golden
+12
-111
database/testdata/TestShowIndex.golden
database/testdata/TestShowIndex.golden
+85
-5
未找到文件。
database/mysql.go
浏览文件 @
19a0bc41
...
...
@@ -104,7 +104,7 @@ func (db *Connector) Version() (int, error) {
version
:=
99999
// 从数据库中获取版本信息
res
,
err
:=
db
.
Query
(
"select @@version"
)
if
err
!=
nil
{
if
err
!=
nil
{
common
.
Log
.
Warn
(
"(db *Connector) Version() Error: %v"
,
err
)
return
version
,
err
}
...
...
@@ -189,6 +189,10 @@ func (db *Connector) ColumnCardinality(tb, col string) float64 {
}
}
// 当table status元数据不准确时 rowTotal 可能远小于count(*),导致散粒度大于1
if
colNum
>
float64
(
rowTotal
)
{
return
1
}
// 散粒度区间:[0,1]
return
colNum
/
float64
(
rowTotal
)
}
...
...
database/mysql_test.go
浏览文件 @
19a0bc41
...
...
@@ -77,8 +77,8 @@ func TestColumnCardinality(t *testing.T) {
orgDatabase
:=
connTest
.
Database
connTest
.
Database
=
"sakila"
a
:=
connTest
.
ColumnCardinality
(
"actor"
,
"first_name"
)
if
a
>
=
1
||
a
<=
0
{
t
.
Error
(
"sakila.actor.first_name cardinality should in
(0, 1)
, now it's"
,
a
)
if
a
>
1
||
a
<=
0
{
t
.
Error
(
"sakila.actor.first_name cardinality should in
[0, 1]
, now it's"
,
a
)
}
connTest
.
Database
=
orgDatabase
}
...
...
database/show.go
浏览文件 @
19a0bc41
...
...
@@ -116,6 +116,7 @@ func (db *Connector) ShowTableStatus(tableName string) (*TableStatInfo, error) {
return
tbStatus
,
err
}
// columns info
ts
:=
tableStatusRow
{}
statusFields
:=
make
([]
interface
{},
0
)
fields
:=
map
[
string
]
interface
{}{
...
...
@@ -175,6 +176,7 @@ type TableIndexRow struct {
Comment
string
IndexComment
string
Visible
string
Expression
[]
byte
}
// NewTableIndexInfo 构造 TableIndexInfo
...
...
@@ -195,23 +197,34 @@ func (db *Connector) ShowIndex(tableName string) (*TableIndexInfo, error) {
return
nil
,
err
}
// columns info
ti
:=
TableIndexRow
{}
indexFields
:=
make
([]
interface
{},
0
)
fields
:=
map
[
string
]
interface
{}{
"Table"
:
&
ti
.
Table
,
"Non_unique"
:
&
ti
.
NonUnique
,
"Key_name"
:
&
ti
.
KeyName
,
"Seq_in_index"
:
&
ti
.
SeqInIndex
,
"Column_name"
:
&
ti
.
ColumnName
,
"Collation"
:
&
ti
.
Collation
,
"Cardinality"
:
&
ti
.
Cardinality
,
"Sub_part"
:
&
ti
.
SubPart
,
"Packed"
:
&
ti
.
Packed
,
"Null"
:
&
ti
.
Null
,
"Index_type"
:
&
ti
.
IndexType
,
"Comment"
:
&
ti
.
Comment
,
"Index_comment"
:
&
ti
.
IndexComment
,
"Visible"
:
&
ti
.
Visible
,
"Expression"
:
&
ti
.
Expression
,
}
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
for
_
,
col
:=
range
cols
{
indexFields
=
append
(
indexFields
,
fields
[
col
])
}
// 获取值
for
res
.
Rows
.
Next
()
{
var
ti
TableIndexRow
res
.
Rows
.
Scan
(
&
ti
.
Table
,
&
ti
.
NonUnique
,
&
ti
.
KeyName
,
&
ti
.
SeqInIndex
,
&
ti
.
ColumnName
,
&
ti
.
Collation
,
&
ti
.
Cardinality
,
&
ti
.
SubPart
,
&
ti
.
Packed
,
&
ti
.
Null
,
&
ti
.
IndexType
,
&
ti
.
Comment
,
&
ti
.
IndexComment
,
&
ti
.
Visible
)
res
.
Rows
.
Scan
(
indexFields
...
)
tbIndex
.
Rows
=
append
(
tbIndex
.
Rows
,
ti
)
}
return
tbIndex
,
err
...
...
@@ -314,18 +327,29 @@ func (db *Connector) ShowColumns(tableName string) (*TableDesc, error) {
return
nil
,
err
}
// columns info
tc
:=
TableDescValue
{}
columnFields
:=
make
([]
interface
{},
0
)
fields
:=
map
[
string
]
interface
{}{
"Field"
:
&
tc
.
Field
,
"Type"
:
&
tc
.
Type
,
"Collation"
:
&
tc
.
Collation
,
"Null"
:
&
tc
.
Null
,
"Key"
:
&
tc
.
Key
,
"Default"
:
&
tc
.
Default
,
"Extra"
:
&
tc
.
Extra
,
"Privileges"
:
&
tc
.
Privileges
,
"Comment"
:
&
tc
.
Comment
,
}
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
for
_
,
col
:=
range
cols
{
columnFields
=
append
(
columnFields
,
fields
[
col
])
}
// 获取值
for
res
.
Rows
.
Next
()
{
var
tc
TableDescValue
res
.
Rows
.
Scan
(
&
tc
.
Field
,
&
tc
.
Type
,
&
tc
.
Collation
,
&
tc
.
Null
,
&
tc
.
Key
,
&
tc
.
Default
,
&
tc
.
Extra
,
&
tc
.
Privileges
,
&
tc
.
Comment
)
res
.
Rows
.
Scan
(
columnFields
...
)
tbDesc
.
DescValues
=
append
(
tbDesc
.
DescValues
,
tc
)
}
return
tbDesc
,
err
...
...
database/show_test.go
浏览文件 @
19a0bc41
...
...
@@ -114,7 +114,7 @@ func TestShowIndex(t *testing.T) {
func
TestShowColumns
(
t
*
testing
.
T
)
{
orgDatabase
:=
connTest
.
Database
connTest
.
Database
=
"sakila"
ti
,
err
:=
connTest
.
ShowColumns
(
"
film
"
)
ti
,
err
:=
connTest
.
ShowColumns
(
"
actor_info
"
)
if
err
!=
nil
{
t
.
Error
(
"ShowColumns Error: "
,
err
)
}
...
...
database/testdata/TestShowColumns.golden
浏览文件 @
19a0bc41
&database.TableDesc{
Name: "
film
",
Name: "
actor_info
",
DescValues: {
{
Field: "
film
_id",
Field: "
actor
_id",
Type: "smallint(5) unsigned",
Collation: nil,
Null: "NO",
Key: "PRI",
Default: nil,
Extra: "auto_increment",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "title",
Type: "varchar(255)",
Collation: {0x75, 0x74, 0x66, 0x38, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x5f, 0x63, 0x69},
Null: "NO",
Key: "MUL",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "description",
Type: "text",
Collation: {0x75, 0x74, 0x66, 0x38, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x5f, 0x63, 0x69},
Null: "YES",
Key: "",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "release_year",
Type: "year(4)",
Collation: nil,
Null: "YES",
Key: "",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "language_id",
Type: "tinyint(3) unsigned",
Collation: nil,
Null: "NO",
Key: "MUL",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "original_language_id",
Type: "tinyint(3) unsigned",
Collation: nil,
Null: "YES",
Key: "MUL",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "rental_duration",
Type: "tinyint(3) unsigned",
Collation: nil,
Null: "NO",
Key: "",
Default: {0x3
3
},
Default: {0x3
0
},
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "
rental_rat
e",
Type: "
decimal(4,2
)",
Collation:
nil
,
Field: "
first_nam
e",
Type: "
varchar(45
)",
Collation:
{0x75, 0x74, 0x66, 0x38, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x5f, 0x63, 0x69}
,
Null: "NO",
Key: "",
Default: {0x34, 0x2e, 0x39, 0x39},
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "length",
Type: "smallint(5) unsigned",
Collation: nil,
Null: "YES",
Key: "",
Default: nil,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "replacement_cost",
Type: "decimal(5,2)",
Collation: nil,
Null: "NO",
Key: "",
Default: {0x31, 0x39, 0x2e, 0x39, 0x39},
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "rating",
Type: "enum('G','PG','PG-13','R','NC-17')",
Field: "last_name",
Type: "varchar(45)",
Collation: {0x75, 0x74, 0x66, 0x38, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x5f, 0x63, 0x69},
Null: "
YES
",
Null: "
NO
",
Key: "",
Default:
{0x47}
,
Default:
nil
,
Extra: "",
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "
special_features
",
Type: "
set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes')
",
Field: "
film_info
",
Type: "
text
",
Collation: {0x75, 0x74, 0x66, 0x38, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x5f, 0x63, 0x69},
Null: "YES",
Key: "",
...
...
@@ -133,16 +45,5 @@
Privileges: "select,insert,update,references",
Comment: "",
},
{
Field: "last_update",
Type: "timestamp",
Collation: nil,
Null: "NO",
Key: "",
Default: {0x43, 0x55, 0x52, 0x52, 0x45, 0x4e, 0x54, 0x5f, 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50},
Extra: "on update CURRENT_TIMESTAMP",
Privileges: "select,insert,update,references",
Comment: "",
},
},
}
database/testdata/TestShowIndex.golden
浏览文件 @
19a0bc41
&database.TableIndexInfo{
TableName: "film",
Rows: {
{Table:"film", NonUnique:0, KeyName:"PRIMARY", SeqInIndex:1, ColumnName:"film_id", Collation:"A", Cardinality:1000, SubPart:0, Packed:0, Null:"", IndexType:"", Comment:"", IndexComment:"", Visible:""},
{Table:"film", NonUnique:1, KeyName:"idx_title", SeqInIndex:1, ColumnName:"title", Collation:"A", Cardinality:1000, SubPart:0, Packed:0, Null:"", IndexType:"", Comment:"", IndexComment:"", Visible:""},
{Table:"film", NonUnique:1, KeyName:"idx_fk_language_id", SeqInIndex:1, ColumnName:"language_id", Collation:"A", Cardinality:1, SubPart:0, Packed:0, Null:"", IndexType:"", Comment:"", IndexComment:"", Visible:""},
{Table:"film", NonUnique:1, KeyName:"idx_fk_original_language_id", SeqInIndex:1, ColumnName:"original_language_id", Collation:"A", Cardinality:1, SubPart:0, Packed:0, Null:"", IndexType:"", Comment:"", IndexComment:"", Visible:""},
{
Table: "film",
NonUnique: 0,
KeyName: "PRIMARY",
SeqInIndex: 1,
ColumnName: "film_id",
Collation: "A",
Cardinality: 1000,
SubPart: 0,
Packed: 0,
Null: "",
IndexType: "",
Comment: "",
IndexComment: "",
Visible: "",
Expression: nil,
},
{
Table: "film",
NonUnique: 1,
KeyName: "idx_title",
SeqInIndex: 1,
ColumnName: "title",
Collation: "A",
Cardinality: 1000,
SubPart: 0,
Packed: 0,
Null: "",
IndexType: "",
Comment: "",
IndexComment: "",
Visible: "",
Expression: nil,
},
{
Table: "film",
NonUnique: 1,
KeyName: "idx_fk_language_id",
SeqInIndex: 1,
ColumnName: "language_id",
Collation: "A",
Cardinality: 1,
SubPart: 0,
Packed: 0,
Null: "",
IndexType: "",
Comment: "",
IndexComment: "",
Visible: "",
Expression: nil,
},
{
Table: "film",
NonUnique: 1,
KeyName: "idx_fk_original_language_id",
SeqInIndex: 1,
ColumnName: "original_language_id",
Collation: "A",
Cardinality: 1,
SubPart: 0,
Packed: 0,
Null: "",
IndexType: "",
Comment: "",
IndexComment: "",
Visible: "",
Expression: nil,
},
},
}
[]database.TableIndexRow{
{Table:"film", NonUnique:1, KeyName:"idx_title", SeqInIndex:1, ColumnName:"title", Collation:"A", Cardinality:1000, SubPart:0, Packed:0, Null:"", IndexType:"", Comment:"", IndexComment:"", Visible:""},
{
Table: "film",
NonUnique: 1,
KeyName: "idx_title",
SeqInIndex: 1,
ColumnName: "title",
Collation: "A",
Cardinality: 1000,
SubPart: 0,
Packed: 0,
Null: "",
IndexType: "",
Comment: "",
IndexComment: "",
Visible: "",
Expression: nil,
},
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录