Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
06727ba7
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 搜索 >>
提交
06727ba7
编写于
5月 20, 2019
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #205 create index rewrite error
https://github.com/XiaoMi/soar/issues/205
上级
a2ac8f14
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
5 addition
and
2 deletion
+5
-2
ast/rewrite.go
ast/rewrite.go
+2
-2
ast/rewrite_test.go
ast/rewrite_test.go
+1
-0
ast/testdata/TestMergeAlterTables.golden
ast/testdata/TestMergeAlterTables.golden
+2
-0
未找到文件。
ast/rewrite.go
浏览文件 @
06727ba7
...
@@ -1688,7 +1688,6 @@ func MergeAlterTables(sqls ...string) map[string]string {
...
@@ -1688,7 +1688,6 @@ func MergeAlterTables(sqls ...string) map[string]string {
// CREATE [UNIQUE|FULLTEXT|SPATIAL|PRIMARY] [KEY|INDEX] idx_name ON tbl_name
// CREATE [UNIQUE|FULLTEXT|SPATIAL|PRIMARY] [KEY|INDEX] idx_name ON tbl_name
createIndexExp
:=
regexp
.
MustCompile
(
`(?i)create((unique)|(fulltext)|(spatial)|(primary)|(\s*)\s*)((index)|(key))\s*`
)
createIndexExp
:=
regexp
.
MustCompile
(
`(?i)create((unique)|(fulltext)|(spatial)|(primary)|(\s*)\s*)((index)|(key))\s*`
)
indexNameExp
:=
regexp
.
MustCompile
(
`(?i)(`
+
backTicks
+
`|([^\s]*))\s*`
)
indexNameExp
:=
regexp
.
MustCompile
(
`(?i)(`
+
backTicks
+
`|([^\s]*))\s*`
)
indexColsExp
:=
regexp
.
MustCompile
(
`(?i)(`
+
backTicks
+
`|([^\s]*))\s*on\s*(`
+
backTicks
+
`|([^\s]*))\s*`
)
for
_
,
sql
:=
range
sqls
{
for
_
,
sql
:=
range
sqls
{
sql
=
strings
.
Trim
(
sql
,
common
.
Config
.
Delimiter
)
sql
=
strings
.
Trim
(
sql
,
common
.
Config
.
Delimiter
)
...
@@ -1719,7 +1718,8 @@ func MergeAlterTables(sqls ...string) map[string]string {
...
@@ -1719,7 +1718,8 @@ func MergeAlterTables(sqls ...string) map[string]string {
}
else
if
createIndexExp
.
MatchString
(
sql
)
{
}
else
if
createIndexExp
.
MatchString
(
sql
)
{
buf
:=
createIndexExp
.
ReplaceAllString
(
sql
,
""
)
buf
:=
createIndexExp
.
ReplaceAllString
(
sql
,
""
)
idxName
:=
strings
.
TrimSpace
(
indexNameExp
.
FindString
(
buf
))
idxName
:=
strings
.
TrimSpace
(
indexNameExp
.
FindString
(
buf
))
buf
=
indexColsExp
.
ReplaceAllString
(
buf
,
""
)
buf
=
string
([]
byte
(
buf
)[
strings
.
Index
(
buf
,
"("
)
:
])
common
.
Log
.
Error
(
buf
)
common
.
Log
.
Debug
(
"alter createIndexExp: ALTER %v ADD INDEX %v %v"
,
tableName
,
"ADD INDEX"
,
idxName
,
buf
)
common
.
Log
.
Debug
(
"alter createIndexExp: ALTER %v ADD INDEX %v %v"
,
tableName
,
"ADD INDEX"
,
idxName
,
buf
)
alterSQL
=
fmt
.
Sprint
(
"ADD INDEX"
,
" "
+
idxName
+
" "
,
buf
)
alterSQL
=
fmt
.
Sprint
(
"ADD INDEX"
,
" "
+
idxName
+
" "
,
buf
)
}
}
...
...
ast/rewrite_test.go
浏览文件 @
06727ba7
...
@@ -631,6 +631,7 @@ func TestMergeAlterTables(t *testing.T) {
...
@@ -631,6 +631,7 @@ func TestMergeAlterTables(t *testing.T) {
// ADD|DROP INDEX
// ADD|DROP INDEX
// TODO: PRIMARY KEY, [UNIQUE|FULLTEXT|SPATIAL] INDEX
// TODO: PRIMARY KEY, [UNIQUE|FULLTEXT|SPATIAL] INDEX
"CREATE INDEX part_of_name ON customer (name(10));"
,
"CREATE INDEX part_of_name ON customer (name(10));"
,
"create index idx_test_cca on test_bb(test_cc);"
,
// https://github.com/XiaoMi/soar/issues/205
"alter table `sakila`.`t1` add index `idx_col`(`col`)"
,
"alter table `sakila`.`t1` add index `idx_col`(`col`)"
,
"alter table `sakila`.`t1` add UNIQUE index `idx_col`(`col`)"
,
"alter table `sakila`.`t1` add UNIQUE index `idx_col`(`col`)"
,
"alter table `sakila`.`t1` add index `idx_ID`(`ID`)"
,
"alter table `sakila`.`t1` add index `idx_ID`(`ID`)"
,
...
...
ast/testdata/TestMergeAlterTables.golden
浏览文件 @
06727ba7
...
@@ -8,3 +8,5 @@
...
@@ -8,3 +8,5 @@
`t3` : ALTER TABLE `t3` add index `idx_a`(a), drop index`idx_b`(b) ;
`t3` : ALTER TABLE `t3` add index `idx_a`(a), drop index`idx_b`(b) ;
`test_bb` : ALTER TABLE `test_bb` ADD INDEX idx_test_cca (test_cc) ;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录