Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
268d9aee
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看板
未验证
提交
268d9aee
编写于
12月 11, 2018
作者:
martianzhang
提交者:
GitHub
12月 11, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #152 from liipx/master
add COL.007 RuleMaxTextColsCount & update ARG.003 rule content
上级
1bdc431a
952239fb
变更
24
展开全部
隐藏空白更改
内联
并排
Showing
24 changed file
with
6656 addition
and
6336 deletion
+6656
-6336
advisor/heuristic.go
advisor/heuristic.go
+79
-1
advisor/heuristic_test.go
advisor/heuristic_test.go
+68
-0
advisor/index.go
advisor/index.go
+9
-4
advisor/rules.go
advisor/rules.go
+8
-0
advisor/testdata/TestListHeuristicRules.golden
advisor/testdata/TestListHeuristicRules.golden
+10
-0
advisor/testdata/TestMergeConflictHeuristicRules.golden
advisor/testdata/TestMergeConflictHeuristicRules.golden
+1
-0
ast/testdata/TestTokenizer.golden
ast/testdata/TestTokenizer.golden
+1
-1
common/config.go
common/config.go
+4
-0
common/logger.go
common/logger.go
+6
-6
common/testdata/TestPrintConfiguration.golden
common/testdata/TestPrintConfiguration.golden
+1
-0
doc/heuristic.md
doc/heuristic.md
+10
-0
vendor/github.com/pingcap/parser/ast/ddl.go
vendor/github.com/pingcap/parser/ast/ddl.go
+2
-0
vendor/github.com/pingcap/parser/ast/expressions.go
vendor/github.com/pingcap/parser/ast/expressions.go
+2
-1
vendor/github.com/pingcap/parser/charset/charset.go
vendor/github.com/pingcap/parser/charset/charset.go
+1
-0
vendor/github.com/pingcap/parser/model/ddl.go
vendor/github.com/pingcap/parser/model/ddl.go
+47
-43
vendor/github.com/pingcap/parser/parser.go
vendor/github.com/pingcap/parser/parser.go
+3317
-3296
vendor/github.com/pingcap/parser/parser.y
vendor/github.com/pingcap/parser/parser.y
+16
-4
vendor/github.com/pingcap/tidb/sessionctx/stmtctx/stmtctx.go
vendor/github.com/pingcap/tidb/sessionctx/stmtctx/stmtctx.go
+10
-0
vendor/github.com/pingcap/tidb/types/field_type.go
vendor/github.com/pingcap/tidb/types/field_type.go
+10
-1
vendor/vendor.json
vendor/vendor.json
+61
-61
vendor/vitess.io/vitess/go/vt/sqlparser/ast.go
vendor/vitess.io/vitess/go/vt/sqlparser/ast.go
+21
-12
vendor/vitess.io/vitess/go/vt/sqlparser/sql.go
vendor/vitess.io/vitess/go/vt/sqlparser/sql.go
+2917
-2867
vendor/vitess.io/vitess/go/vt/sqlparser/sql.y
vendor/vitess.io/vitess/go/vt/sqlparser/sql.y
+54
-39
vendor/vitess.io/vitess/go/vt/sqlparser/token.go
vendor/vitess.io/vitess/go/vt/sqlparser/token.go
+1
-0
未找到文件。
advisor/heuristic.go
浏览文件 @
268d9aee
...
...
@@ -328,7 +328,7 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
continue
}
c
:=
fmt
.
Sprintf
(
"%s
.%s definition is %s not
%s"
,
c
:=
fmt
.
Sprintf
(
"%s
表中列%s的定义是 %s 而不是
%s"
,
colList
[
0
]
.
Table
,
colList
[
0
]
.
Name
,
colList
[
0
]
.
DataType
,
typNameMap
[
val
.
Type
])
common
.
Log
.
Debug
(
"Implicit data type conversion: %s"
,
c
)
...
...
@@ -3246,6 +3246,84 @@ func (q *Query4Audit) RuleTooManyFields() Rule {
return
rule
}
// RuleMaxTextColsCount COL.007
func
(
q
*
Query4Audit
)
RuleMaxTextColsCount
()
Rule
{
var
textColsCount
int
var
rule
=
q
.
RuleOK
()
switch
q
.
Stmt
.
(
type
)
{
case
*
sqlparser
.
DDL
:
for
_
,
tiStmt
:=
range
q
.
TiStmt
{
switch
node
:=
tiStmt
.
(
type
)
{
case
*
tidb
.
CreateTableStmt
:
for
_
,
col
:=
range
node
.
Cols
{
switch
col
.
Tp
.
Tp
{
case
mysql
.
TypeBlob
,
mysql
.
TypeLongBlob
,
mysql
.
TypeMediumBlob
,
mysql
.
TypeTinyBlob
:
textColsCount
++
}
}
}
}
}
if
textColsCount
>
common
.
Config
.
MaxTextColsCount
{
rule
=
HeuristicRules
[
"COL.007"
]
}
return
rule
}
// RuleMaxTextColsCount COL.007 checking for existed table
func
(
idxAdv
*
IndexAdvisor
)
RuleMaxTextColsCount
()
Rule
{
rule
:=
HeuristicRules
[
"OK"
]
// 未开启测试环境不进行检查
if
common
.
Config
.
TestDSN
.
Disable
{
return
rule
}
err
:=
sqlparser
.
Walk
(
func
(
node
sqlparser
.
SQLNode
)
(
kontinue
bool
,
err
error
)
{
switch
stmt
:=
node
.
(
type
)
{
case
*
sqlparser
.
DDL
:
if
stmt
.
Action
!=
"alter"
{
return
true
,
nil
}
tb
:=
stmt
.
Table
// 此处的检查需要在测试环境中的临时数据库中进行检查
// 需要将测试环境 DSN 的数据库暂时指向临时数据库
// 为了防止影响切换数据库环境会影响接下来的测试,需要在检查完后将原配置还原
dbTmp
:=
idxAdv
.
vEnv
.
Database
idxAdv
.
vEnv
.
Database
=
idxAdv
.
vEnv
.
DBRef
[
idxAdv
.
vEnv
.
Database
]
defer
func
()
{
idxAdv
.
vEnv
.
Database
=
dbTmp
}()
// 添加字段的语句会在初始化环境的时候被执行
// 只需要获取该标的 CREAET 语句,后再对该语句进行检查即可
ddl
,
err
:=
idxAdv
.
vEnv
.
ShowCreateTable
(
tb
.
Name
.
String
())
if
err
!=
nil
{
common
.
Log
.
Error
(
"RuleMaxTextColsCount create statement got failed: %s"
,
err
.
Error
())
return
false
,
err
}
q
,
err
:=
NewQuery4Audit
(
ddl
)
if
err
!=
nil
{
return
false
,
err
}
r
:=
q
.
RuleMaxTextColsCount
()
if
r
.
Item
!=
"OK"
{
rule
=
r
return
false
,
nil
}
}
return
true
,
nil
},
idxAdv
.
Ast
)
common
.
LogIfError
(
err
,
""
)
return
rule
}
// RuleAllowEngine TBL.002
func
(
q
*
Query4Audit
)
RuleAllowEngine
()
Rule
{
var
rule
=
q
.
RuleOK
()
...
...
advisor/heuristic_test.go
浏览文件 @
268d9aee
...
...
@@ -19,11 +19,14 @@ package advisor
import
(
"errors"
"sort"
"strings"
"testing"
"github.com/XiaoMi/soar/common"
"github.com/XiaoMi/soar/env"
"github.com/kr/pretty"
"vitess.io/vitess/go/vt/sqlparser"
)
// ALI.001
...
...
@@ -3091,6 +3094,71 @@ func TestRuleTooManyFields(t *testing.T) {
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
// COL.007
func
TestRuleMaxTextColsCount
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
sqls
:=
[]
string
{
"create table tbl (a int, b text, c blob, d text);"
,
}
common
.
Config
.
MaxColCount
=
0
for
_
,
sql
:=
range
sqls
{
q
,
err
:=
NewQuery4Audit
(
sql
)
if
err
==
nil
{
rule
:=
q
.
RuleMaxTextColsCount
()
if
rule
.
Item
!=
"COL.007"
{
t
.
Error
(
"Rule not match:"
,
rule
.
Item
,
"Expect : COL.007"
)
}
}
else
{
t
.
Error
(
"sqlparser.Parse Error:"
,
err
)
}
}
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
}
// COL.007
func
TestRuleMaxTextColsCountWithEnv
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
dsn
:=
common
.
Config
.
OnlineDSN
common
.
Config
.
OnlineDSN
=
common
.
Config
.
TestDSN
vEnv
,
rEnv
:=
env
.
BuildEnv
()
defer
vEnv
.
CleanUp
()
initSQLs
:=
[]
string
{
`CREATE TABLE t1 (id int, title text, content blob);`
,
"alter table t1 add column other text;"
,
}
for
_
,
sql
:=
range
initSQLs
{
vEnv
.
BuildVirtualEnv
(
rEnv
,
sql
)
if
!
strings
.
HasPrefix
(
strings
.
ToLower
(
sql
),
"alter"
)
{
continue
}
stmt
,
syntaxErr
:=
sqlparser
.
Parse
(
sql
)
if
syntaxErr
!=
nil
{
common
.
Log
.
Critical
(
"Syntax Error: %v, SQL: %s"
,
syntaxErr
,
sql
)
}
q
:=
&
Query4Audit
{
Query
:
sql
,
Stmt
:
stmt
}
idxAdvisor
,
err
:=
NewAdvisor
(
vEnv
,
*
rEnv
,
*
q
)
if
err
!=
nil
{
t
.
Error
(
"NewAdvisor Error: "
,
err
,
"SQL: "
,
sql
)
}
if
idxAdvisor
!=
nil
{
rule
:=
idxAdvisor
.
RuleMaxTextColsCount
()
if
rule
.
Item
!=
"COL.007"
{
t
.
Error
(
"Rule not match:"
,
rule
,
"Expect : COL.007, SQL:"
,
sql
)
}
}
}
common
.
Log
.
Debug
(
"Exiting function: %s"
,
common
.
GetFunctionName
())
common
.
Config
.
OnlineDSN
=
dsn
}
// TBL.002
func
TestRuleAllowEngine
(
t
*
testing
.
T
)
{
common
.
Log
.
Debug
(
"Entering function: %s"
,
common
.
GetFunctionName
())
...
...
advisor/index.go
浏览文件 @
268d9aee
...
...
@@ -111,7 +111,11 @@ func NewAdvisor(env *env.VirtualEnv, rEnv database.Connector, q Query4Audit) (*I
}
}
return
nil
,
nil
return
&
IndexAdvisor
{
vEnv
:
env
,
rEnv
:
rEnv
,
Ast
:
q
.
Stmt
,
},
nil
case
*
sqlparser
.
DBDDL
:
// 忽略建库语句
...
...
@@ -1011,11 +1015,12 @@ func (idxAdv *IndexAdvisor) HeuristicCheck(q Query4Audit) map[string]Rule {
}
ruleFuncs
:=
[]
func
(
*
IndexAdvisor
)
Rule
{
(
*
IndexAdvisor
)
.
RuleMaxTextColsCount
,
// COL.007
(
*
IndexAdvisor
)
.
RuleImplicitConversion
,
// ARG.003
(
*
IndexAdvisor
)
.
RuleGroupByConst
,
// CLA.004
(
*
IndexAdvisor
)
.
RuleOrderByConst
,
// CLA.005
(
*
IndexAdvisor
)
.
RuleUpdatePrimaryKey
,
// CLA.016
// (*IndexAdvisor).RuleImpossibleOuterJoin, // TODO: JOI.003, JOI.004
(
*
IndexAdvisor
)
.
RuleGroupByConst
,
// CLA.004
(
*
IndexAdvisor
)
.
RuleOrderByConst
,
// CLA.005
(
*
IndexAdvisor
)
.
RuleUpdatePrimaryKey
,
// CLA.016
}
for
_
,
f
:=
range
ruleFuncs
{
...
...
advisor/rules.go
浏览文件 @
268d9aee
...
...
@@ -471,6 +471,14 @@ func init() {
Case
:
"CREATE TABLE tbl ( cols ....);"
,
Func
:
(
*
Query4Audit
)
.
RuleTooManyFields
,
},
"COL.007"
:
{
Item
:
"COL.007"
,
Severity
:
"L3"
,
Summary
:
"表中包含有太多的 text/blob 列"
,
Content
:
fmt
.
Sprintf
(
`表中包含超过%d个的 text/blob 列`
,
common
.
Config
.
MaxTextColsCount
),
Case
:
"CREATE TABLE tbl ( cols ....);"
,
Func
:
(
*
Query4Audit
)
.
RuleTooManyFields
,
},
"COL.008"
:
{
Item
:
"COL.008"
,
Severity
:
"L1"
,
...
...
advisor/testdata/TestListHeuristicRules.golden
浏览文件 @
268d9aee
...
...
@@ -409,6 +409,16 @@ CREATE TABLE tbl (col int) ENGINE=InnoDB;
* **Content**:表中包含有太多的列
* **Case**:
```sql
CREATE TABLE tbl ( cols ....);
```
## 表中包含有太多的 text/blob 列
* **Item**:COL.007
* **Severity**:L3
* **Content**:表中包含超过2个的 text/blob 列
* **Case**:
```sql
CREATE TABLE tbl ( cols ....);
```
...
...
advisor/testdata/TestMergeConflictHeuristicRules.golden
浏览文件 @
268d9aee
...
...
@@ -38,6 +38,7 @@ advisor.Rule{Item:"COL.003", Severity:"L2", Summary:"建议修改自增 ID 为
advisor.Rule{Item:"COL.004", Severity:"L1", Summary:"请为列添加默认值", Content:"请为列添加默认值,如果是 ALTER 操作,请不要忘记将原字段的默认值写上。字段无默认值,当表较大时无法在线变更表结构。", Case:"CREATE TABLE tbl (col int) ENGINE=InnoDB;", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.005", Severity:"L1", Summary:"列未添加注释", Content:"建议对表中每个列添加注释,来明确每个列在表中的含义及作用。", Case:"CREATE TABLE tbl (col int) ENGINE=InnoDB;", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.006", Severity:"L3", Summary:"表中包含有太多的列", Content:"表中包含有太多的列", Case:"CREATE TABLE tbl ( cols ....);", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.007", Severity:"L3", Summary:"表中包含有太多的 text/blob 列", Content:"表中包含超过2个的 text/blob 列", Case:"CREATE TABLE tbl ( cols ....);", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.008", Severity:"L1", Summary:"可使用 VARCHAR 代替 CHAR, VARBINARY 代替 BINARY", Content:"为首先变长字段存储空间小,可以节省存储空间。其次对于查询来说,在一个相对较小的字段内搜索效率显然要高些。", Case:"create table t1(id int,name char(20),last_time date)", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.009", Severity:"L2", Summary:"建议使用精确的数据类型", Content:"实际上,任何使用 FLOAT, REAL 或 DOUBLE PRECISION 数据类型的设计都有可能是反模式。大多数应用程序使用的浮点数的取值范围并不需要达到IEEE 754标准所定义的最大/最小区间。在计算总量时,非精确浮点数所积累的影响是严重的。使用 SQL 中的 NUMERIC 或 DECIMAL 类型来代替 FLOAT 及其类似的数据类型进行固定精度的小数存储。这些数据类型精确地根据您定义这一列时指定的精度来存储数据。尽可能不要使用浮点数。", Case:"CREATE TABLE tab2 (p_id BIGINT UNSIGNED NOT NULL,a_id BIGINT UNSIGNED NOT NULL,hours float not null,PRIMARY KEY (p_id, a_id))", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
advisor.Rule{Item:"COL.010", Severity:"L2", Summary:"不建议使用 ENUM 数据类型", Content:"ENUM 定义了列中值的类型,使用字符串表示 ENUM 里的值时,实际存储在列中的数据是这些值在定义时的序数。因此,这列的数据是字节对齐的,当您进行一次排序查询时,结果是按照实际存储的序数值排序的,而不是按字符串值的字母顺序排序的。这可能不是您所希望的。没有什么语法支持从 ENUM 或者 check 约束中添加或删除一个值;您只能使用一个新的集合重新定义这一列。如果您打算废弃一个选项,您可能会为历史数据而烦恼。作为一种策略,改变元数据——也就是说,改变表和列的定义——应该是不常见的,并且要注意测试和质量保证。有一个更好的解决方案来约束一列中的可选值:创建一张检查表,每一行包含一个允许在列中出现的候选值;然后在引用新表的旧表上声明一个外键约束。", Case:"create table tab1(status ENUM('new','in progress','fixed'))", Position:0, Func:func(*advisor.Query4Audit) advisor.Rule {...}}
...
...
ast/testdata/TestTokenizer.golden
浏览文件 @
268d9aee
...
...
@@ -210,7 +210,7 @@
}
[]ast.Token{
{Type:57348, Val:"select", i:0},
{Type:575
89
, Val:"sql_calc_found_rows", i:0},
{Type:575
90
, Val:"sql_calc_found_rows", i:0},
{Type:57396, Val:"col", i:0},
{Type:57353, Val:"from", i:0},
{Type:57396, Val:"tbl", i:0},
...
...
common/config.go
浏览文件 @
268d9aee
...
...
@@ -91,6 +91,7 @@ type Configuration struct {
MaxGroupByColsCount
int
`yaml:"max-group-by-cols-count"`
// 单条 SQL 中 GroupBy 包含列的最大数量
MaxDistinctCount
int
`yaml:"max-distinct-count"`
// 单条 SQL 中 Distinct 的最大数量
MaxIdxColsCount
int
`yaml:"max-index-cols-count"`
// 复合索引中包含列的最大数量
MaxTextColsCount
int
`yaml:"max-text-cols-count"`
// 表中含有的 text/blob 列的最大数量
MaxTotalRows
int64
`yaml:"max-total-rows"`
// 计算散粒度时,当数据行数大于 MaxTotalRows 即开启数据库保护模式,散粒度返回结果可信度下降
MaxQueryCost
int64
`yaml:"max-query-cost"`
// last_query_cost 超过该值时将给予警告
SpaghettiQueryLength
int
`yaml:"spaghetti-query-length"`
// SQL最大长度警告,超过该长度会给警告
...
...
@@ -167,6 +168,7 @@ var Config = &Configuration{
MaxGroupByColsCount
:
5
,
MaxDistinctCount
:
5
,
MaxIdxColsCount
:
5
,
MaxTextColsCount
:
2
,
MaxIdxBytesPerColumn
:
767
,
MaxIdxBytes
:
3072
,
MaxTotalRows
:
9999999
,
...
...
@@ -528,6 +530,7 @@ func readCmdFlags() error {
maxGroupByColsCount
:=
flag
.
Int
(
"max-group-by-cols-count"
,
Config
.
MaxGroupByColsCount
,
"MaxGroupByColsCount, 单条 SQL 中 GroupBy 包含列的最大数量"
)
maxDistinctCount
:=
flag
.
Int
(
"max-distinct-count"
,
Config
.
MaxDistinctCount
,
"MaxDistinctCount, 单条 SQL 中 Distinct 的最大数量"
)
maxIdxColsCount
:=
flag
.
Int
(
"max-index-cols-count"
,
Config
.
MaxIdxColsCount
,
"MaxIdxColsCount, 复合索引中包含列的最大数量"
)
maxTextColsCount
:=
flag
.
Int
(
"max-texst-cols-count"
,
Config
.
MaxTextColsCount
,
"MaxTextColsCount, 表中含有的 text/blob 列的最大数量"
)
maxTotalRows
:=
flag
.
Int64
(
"max-total-rows"
,
Config
.
MaxTotalRows
,
"MaxTotalRows, 计算散粒度时,当数据行数大于MaxTotalRows即开启数据库保护模式,不计算散粒度"
)
maxQueryCost
:=
flag
.
Int64
(
"max-query-cost"
,
Config
.
MaxQueryCost
,
"MaxQueryCost, last_query_cost 超过该值时将给予警告"
)
spaghettiQueryLength
:=
flag
.
Int
(
"spaghetti-query-length"
,
Config
.
SpaghettiQueryLength
,
"SpaghettiQueryLength, SQL最大长度警告,超过该长度会给警告"
)
...
...
@@ -626,6 +629,7 @@ func readCmdFlags() error {
Config
.
MaxIdxColsCount
=
16
}
Config
.
MaxTextColsCount
=
*
maxTextColsCount
Config
.
MaxIdxBytesPerColumn
=
*
maxIdxBytesPerColumn
Config
.
MaxIdxBytes
=
*
maxIdxBytes
if
*
allowCharsets
!=
""
{
...
...
common/logger.go
浏览文件 @
268d9aee
...
...
@@ -43,14 +43,14 @@ func LoggerInit() {
func
()
{
_
=
Log
.
DelLogger
(
logs
.
AdapterFile
)
}()
logConfig
:=
map
[
string
]
interface
{}{
"filename"
:
Config
.
LogOutput
,
"level"
:
7
,
"level"
:
7
,
"maxlines"
:
0
,
"maxsize"
:
0
,
"daily"
:
false
,
"maxdays"
:
0
,
"maxsize"
:
0
,
"daily"
:
false
,
"maxdays"
:
0
,
}
logConfigJ
son
,
_
:=
json
.
Marshal
(
logConfig
)
err
:=
Log
.
SetLogger
(
logs
.
AdapterFile
,
fmt
.
Sprintf
(
string
(
logConfigJson
)
))
logConfigJ
SON
,
_
:=
json
.
Marshal
(
logConfig
)
err
:=
Log
.
SetLogger
(
logs
.
AdapterFile
,
string
(
logConfigJSON
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
...
...
common/testdata/TestPrintConfiguration.golden
浏览文件 @
268d9aee
...
...
@@ -48,6 +48,7 @@ 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
...
...
doc/heuristic.md
浏览文件 @
268d9aee
...
...
@@ -409,6 +409,16 @@ CREATE TABLE tbl (col int) ENGINE=InnoDB;
*
**Content**
:表中包含有太多的列
*
**Case**
:
```
sql
CREATE
TABLE
tbl
(
cols
....);
```
## 表中包含有太多的 text/blob 列
*
**Item**
:COL.007
*
**Severity**
:L3
*
**Content**
:表中包含超过2个的 text/blob 列
*
**Case**
:
```
sql
CREATE
TABLE
tbl
(
cols
....);
```
...
...
vendor/github.com/pingcap/parser/ast/ddl.go
浏览文件 @
268d9aee
...
...
@@ -550,6 +550,7 @@ type DropTableStmt struct {
IfExists
bool
Tables
[]
*
TableName
IsView
bool
}
// Restore implements Recoverable interface.
...
...
@@ -887,6 +888,7 @@ const (
AlterTableAddPartitions
AlterTableCoalescePartitions
AlterTableDropPartition
AlterTableTruncatePartition
// TODO: Add more actions
)
...
...
vendor/github.com/pingcap/parser/ast/expressions.go
浏览文件 @
268d9aee
...
...
@@ -605,7 +605,8 @@ type IsNullExpr struct {
// Restore implements Recoverable interface.
func
(
n
*
IsNullExpr
)
Restore
(
sb
*
strings
.
Builder
)
error
{
return
errors
.
New
(
"Not implemented"
)
n
.
Format
(
sb
)
return
nil
}
// Format the ExprNode into a Writer.
...
...
vendor/github.com/pingcap/parser/charset/charset.go
浏览文件 @
268d9aee
...
...
@@ -94,6 +94,7 @@ func ValidCharsetAndCollation(cs string, co string) bool {
if
co
==
""
{
return
true
}
co
=
strings
.
ToLower
(
co
)
_
,
ok
=
c
.
Collations
[
co
]
if
!
ok
{
return
false
...
...
vendor/github.com/pingcap/parser/model/ddl.go
浏览文件 @
268d9aee
...
...
@@ -29,55 +29,59 @@ type ActionType byte
// List DDL actions.
const
(
ActionNone
ActionType
=
0
ActionCreateSchema
ActionType
=
1
ActionDropSchema
ActionType
=
2
ActionCreateTable
ActionType
=
3
ActionDropTable
ActionType
=
4
ActionAddColumn
ActionType
=
5
ActionDropColumn
ActionType
=
6
ActionAddIndex
ActionType
=
7
ActionDropIndex
ActionType
=
8
ActionAddForeignKey
ActionType
=
9
ActionDropForeignKey
ActionType
=
10
ActionTruncateTable
ActionType
=
11
ActionModifyColumn
ActionType
=
12
ActionRebaseAutoID
ActionType
=
13
ActionRenameTable
ActionType
=
14
ActionSetDefaultValue
ActionType
=
15
ActionShardRowID
ActionType
=
16
ActionModifyTableComment
ActionType
=
17
ActionRenameIndex
ActionType
=
18
ActionAddTablePartition
ActionType
=
19
ActionDropTablePartition
ActionType
=
20
ActionCreateView
ActionType
=
21
ActionNone
ActionType
=
0
ActionCreateSchema
ActionType
=
1
ActionDropSchema
ActionType
=
2
ActionCreateTable
ActionType
=
3
ActionDropTable
ActionType
=
4
ActionAddColumn
ActionType
=
5
ActionDropColumn
ActionType
=
6
ActionAddIndex
ActionType
=
7
ActionDropIndex
ActionType
=
8
ActionAddForeignKey
ActionType
=
9
ActionDropForeignKey
ActionType
=
10
ActionTruncateTable
ActionType
=
11
ActionModifyColumn
ActionType
=
12
ActionRebaseAutoID
ActionType
=
13
ActionRenameTable
ActionType
=
14
ActionSetDefaultValue
ActionType
=
15
ActionShardRowID
ActionType
=
16
ActionModifyTableComment
ActionType
=
17
ActionRenameIndex
ActionType
=
18
ActionAddTablePartition
ActionType
=
19
ActionDropTablePartition
ActionType
=
20
ActionCreateView
ActionType
=
21
ActionModifyTableCharsetAndCollate
ActionType
=
22
ActionTruncateTablePartition
ActionType
=
23
)
// AddIndexStr is a string related to the operation of "add index".
const
AddIndexStr
=
"add index"
var
actionMap
=
map
[
ActionType
]
string
{
ActionCreateSchema
:
"create schema"
,
ActionDropSchema
:
"drop schema"
,
ActionCreateTable
:
"create table"
,
ActionDropTable
:
"drop table"
,
ActionAddColumn
:
"add column"
,
ActionDropColumn
:
"drop column"
,
ActionAddIndex
:
AddIndexStr
,
ActionDropIndex
:
"drop index"
,
ActionAddForeignKey
:
"add foreign key"
,
ActionDropForeignKey
:
"drop foreign key"
,
ActionTruncateTable
:
"truncate table"
,
ActionModifyColumn
:
"modify column"
,
ActionRebaseAutoID
:
"rebase auto_increment ID"
,
ActionRenameTable
:
"rename table"
,
ActionSetDefaultValue
:
"set default value"
,
ActionShardRowID
:
"shard row ID"
,
ActionModifyTableComment
:
"modify table comment"
,
ActionRenameIndex
:
"rename index"
,
ActionAddTablePartition
:
"add partition"
,
ActionDropTablePartition
:
"drop table partition"
,
ActionCreateView
:
"create view"
,
ActionCreateSchema
:
"create schema"
,
ActionDropSchema
:
"drop schema"
,
ActionCreateTable
:
"create table"
,
ActionDropTable
:
"drop table"
,
ActionAddColumn
:
"add column"
,
ActionDropColumn
:
"drop column"
,
ActionAddIndex
:
AddIndexStr
,
ActionDropIndex
:
"drop index"
,
ActionAddForeignKey
:
"add foreign key"
,
ActionDropForeignKey
:
"drop foreign key"
,
ActionTruncateTable
:
"truncate table"
,
ActionModifyColumn
:
"modify column"
,
ActionRebaseAutoID
:
"rebase auto_increment ID"
,
ActionRenameTable
:
"rename table"
,
ActionSetDefaultValue
:
"set default value"
,
ActionShardRowID
:
"shard row ID"
,
ActionModifyTableComment
:
"modify table comment"
,
ActionRenameIndex
:
"rename index"
,
ActionAddTablePartition
:
"add partition"
,
ActionDropTablePartition
:
"drop partition"
,
ActionCreateView
:
"create view"
,
ActionModifyTableCharsetAndCollate
:
"modify table charset and collate"
,
ActionTruncateTablePartition
:
"truncate partition"
,
}
// String return current ddl action in string
...
...
vendor/github.com/pingcap/parser/parser.go
浏览文件 @
268d9aee
此差异已折叠。
点击以展开。
vendor/github.com/pingcap/parser/parser.y
浏览文件 @
268d9aee
...
...
@@ -1084,6 +1084,13 @@ AlterTableSpec:
Name
:
$
3
,
}
}
|
"TRUNCATE"
"PARTITION"
Identifier
{
$$
=
&
ast
.
AlterTableSpec
{
Tp
:
ast
.
AlterTableTruncatePartition
,
Name
:
$
3
,
}
}
|
"DROP"
KeyOrIndex
Identifier
{
$$
=
&
ast
.
AlterTableSpec
{
...
...
@@ -2349,17 +2356,22 @@ DropIndexStmt:
DropTableStmt
:
"DROP"
TableOrTables
TableNameList
RestrictOrCascadeOpt
{
$$
=
&
ast
.
DropTableStmt
{
Tables
:
$
3.
([]*
ast
.
TableName
)}
$$
=
&
ast
.
DropTableStmt
{
Tables
:
$
3.
([]*
ast
.
TableName
)
,
IsView
:
false
}
}
|
"DROP"
TableOrTables
"IF"
"EXISTS"
TableNameList
RestrictOrCascadeOpt
{
$$
=
&
ast
.
DropTableStmt
{
IfExists
:
true
,
Tables
:
$
5.
([]*
ast
.
TableName
)}
$$
=
&
ast
.
DropTableStmt
{
IfExists
:
true
,
Tables
:
$
5.
([]*
ast
.
TableName
)
,
IsView
:
false
}
}
DropViewStmt
:
"DROP"
"VIEW"
"IF"
"EXISTS"
TableNameList
"DROP"
"VIEW"
TableNameList
RestrictOrCascadeOpt
{
$$
=
&
ast
.
DropTableStmt
{
Tables
:
$
3.
([]*
ast
.
TableName
),
IsView
:
true
}
}
|
"DROP"
"VIEW"
"IF"
"EXISTS"
TableNameList
RestrictOrCascadeOpt
{
$$
=
&
ast
.
D
oStmt
{
}
$$
=
&
ast
.
D
ropTableStmt
{
IfExists
:
true
,
Tables
:
$
5.
([]*
ast
.
TableName
),
IsView
:
true
}
}
DropUserStmt
:
...
...
vendor/github.com/pingcap/tidb/sessionctx/stmtctx/stmtctx.go
浏览文件 @
268d9aee
...
...
@@ -71,6 +71,14 @@ type StatementContext struct {
histogramsNotLoad
bool
execDetails
execdetails
.
ExecDetails
}
// PrevAffectedRows is the affected-rows value(DDL is 0, DML is the number of affected rows).
PrevAffectedRows
int64
// PrevLastInsertID is the last insert ID of previous statement.
PrevLastInsertID
uint64
// LastInsertID is the auto-generated ID in the current statement.
LastInsertID
uint64
// InsertID is the given insert ID of an auto_increment column.
InsertID
uint64
// Copied from SessionVars.TimeZone.
TimeZone
*
time
.
Location
...
...
@@ -241,6 +249,8 @@ func (sc *StatementContext) ResetForRetry() {
sc
.
mu
.
foundRows
=
0
sc
.
mu
.
warnings
=
nil
sc
.
mu
.
Unlock
()
sc
.
TableIDs
=
sc
.
TableIDs
[
:
0
]
sc
.
IndexIDs
=
sc
.
IndexIDs
[
:
0
]
}
// MergeExecDetails merges a single region execution details into self, used to print
...
...
vendor/github.com/pingcap/tidb/types/field_type.go
浏览文件 @
268d9aee
...
...
@@ -40,6 +40,12 @@ func NewFieldType(tp byte) *FieldType {
}
}
// CloneFieldType clones the given FieldType.
func
CloneFieldType
(
src
*
FieldType
)
*
FieldType
{
ft
:=
*
src
return
&
ft
}
// AggFieldType aggregates field types for a multi-argument function like `IF`, `IFNULL`, `COALESCE`
// whose return type is determined by the arguments' FieldTypes.
// Aggregation is performed by MergeFieldType function.
...
...
@@ -123,11 +129,14 @@ func setTypeFlag(flag *uint, flagItem uint, on bool) {
func
DefaultParamTypeForValue
(
value
interface
{},
tp
*
FieldType
)
{
switch
value
.
(
type
)
{
case
nil
:
tp
.
Tp
=
mysql
.
Type
Unspecified
tp
.
Tp
=
mysql
.
Type
VarString
tp
.
Flen
=
UnspecifiedLength
tp
.
Decimal
=
UnspecifiedLength
default
:
DefaultTypeForValue
(
value
,
tp
)
if
tp
.
Tp
==
mysql
.
TypeUnspecified
{
tp
.
Tp
=
mysql
.
TypeVarString
}
}
}
...
...
vendor/vendor.json
浏览文件 @
268d9aee
...
...
@@ -105,106 +105,106 @@
"revisionTime"
:
"2018-10-24T15:10:47Z"
},
{
"checksumSHA1"
:
"
V/4P8kb4QDozn9w++U8G+Kvt0+g
="
,
"checksumSHA1"
:
"
xbV0lm0Qw8rFC82Dttxbf5ypBjA
="
,
"path"
:
"github.com/pingcap/parser"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"
Fj3tju6yXL0IHhhu6pYwvU5xzJo
="
,
"checksumSHA1"
:
"
zrZ2JfaxdfwpArtuyiPjgH9GKeY
="
,
"path"
:
"github.com/pingcap/parser/ast"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"skWGV4FNvD3vr+5olepaPPnylUw="
,
"path"
:
"github.com/pingcap/parser/auth"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"
grkBf/zf8cTJRtI64P1jV6B+p/4
="
,
"checksumSHA1"
:
"
t4UHo966WzU9Z0IJkyGHRp0loOk
="
,
"path"
:
"github.com/pingcap/parser/charset"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"SInoXbsRe0tnBwmatmtZYfSFbdk="
,
"path"
:
"github.com/pingcap/parser/format"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"
+rJd1MX+3A1gwbrFZHFWbC8l8ao
="
,
"checksumSHA1"
:
"
reRV2qecd6NpB7tIW3JeK46K/sk
="
,
"path"
:
"github.com/pingcap/parser/model"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"QBa9yiMDQNl2cLLwqlRoNTpCPNg="
,
"path"
:
"github.com/pingcap/parser/mysql"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"oNBCSwJRykKuzIKgPCttatB9hAo="
,
"path"
:
"github.com/pingcap/parser/opcode"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"XvnUllvwMYd6HrMvMiKnn4cGN2M="
,
"path"
:
"github.com/pingcap/parser/terror"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"s96v2EoeGKcWHO3mpMOQk/z2iaI="
,
"path"
:
"github.com/pingcap/parser/types"
,
"revision"
:
"
c563561800a23fd1edeae4a592400cc2d0b47f5f
"
,
"revisionTime"
:
"2018-12-
05T02:39:5
0Z"
"revision"
:
"
4e6d047fcaae221376638de5f44c07cb6bf3eb44
"
,
"revisionTime"
:
"2018-12-
11T02:45:4
0Z"
},
{
"checksumSHA1"
:
"
kO63T5plq+V7HWnkzB9WlOnp9Iw
="
,
"checksumSHA1"
:
"
fWqL/7jTYOiqDNmiUcQi3u45Hw0
="
,
"path"
:
"github.com/pingcap/tidb/sessionctx/stmtctx"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"
SH/wISM1ueh/ENPJhiq1KssPLDA
="
,
"checksumSHA1"
:
"
U/TFas5WBPWG2DARj51bcfoN0xQ
="
,
"path"
:
"github.com/pingcap/tidb/types"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"DWVD7+ygtT66IQ+cqXmMJ5OVqUk="
,
"path"
:
"github.com/pingcap/tidb/types/json"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"Zp5ME8OXNTmHnYTwJJUZlydN4/U="
,
"path"
:
"github.com/pingcap/tidb/types/parser_driver"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"s709bhSrG2Ec35406mGtrySid4s="
,
"path"
:
"github.com/pingcap/tidb/util/execdetails"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"nUC7zVoAMNR2a+z2iGqHoN2AkFE="
,
"path"
:
"github.com/pingcap/tidb/util/hack"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"xSyepiuqsoaaeDch7cXeumvVHKM="
,
"path"
:
"github.com/pingcap/tidb/util/memory"
,
"revision"
:
"
350a046975a1f86fa6f05f177e81ae838388f4b
b"
,
"revisionTime"
:
"2018-12-
04T14:10:08
Z"
"revision"
:
"
ef0ad26da8f99044a741fc0a781a0c4791446e8
b"
,
"revisionTime"
:
"2018-12-
10T15:48:53
Z"
},
{
"checksumSHA1"
:
"SmYeIK/fIYXNu8IKxD6HOVQVTuU="
,
...
...
@@ -401,62 +401,62 @@
{
"checksumSHA1"
:
"aKn1oKcY74N8TRLm3Ayt7Q4bbI4="
,
"path"
:
"vitess.io/vitess/go/bytes2"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"JVCEN4UGRmg3TofIBdzZMZ3G0Ww="
,
"path"
:
"vitess.io/vitess/go/hack"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"e1WJ7vCnVrlQQQlc6n/FewCDMso="
,
"path"
:
"vitess.io/vitess/go/sqltypes"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"ntFIQYkBS51G6y+FEkjFW40+HOU="
,
"path"
:
"vitess.io/vitess/go/vt/log"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"tPQFPwbMdjuX0qjNl4Zl8zc37JQ="
,
"path"
:
"vitess.io/vitess/go/vt/proto/query"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"o0tR/c7lgr0pLkxk7CdvjiNDAKU="
,
"path"
:
"vitess.io/vitess/go/vt/proto/topodata"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"77UojBqi0yyeQvR70j7C3kcKclQ="
,
"path"
:
"vitess.io/vitess/go/vt/proto/vtgate"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"QpWGhoVDwM+8+sgYLI/YU+95iGU="
,
"path"
:
"vitess.io/vitess/go/vt/proto/vtrpc"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"
CZ0WbR7TBTgF9HoY+aRxzOzVlSs
="
,
"checksumSHA1"
:
"
lENrUY/YyxwYFHYN+21TBH92P3U
="
,
"path"
:
"vitess.io/vitess/go/vt/sqlparser"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
},
{
"checksumSHA1"
:
"oF4XzuOzwvj1iduX/lYqNSyY/HM="
,
"path"
:
"vitess.io/vitess/go/vt/vterrors"
,
"revision"
:
"
5bec5a560c87897b5d973bbced81764f3cf0f330
"
,
"revisionTime"
:
"2018-12-
05T00:00:15
Z"
"revision"
:
"
be9745195a139422cd62fd32bdc3b7e0c28c9427
"
,
"revisionTime"
:
"2018-12-
10T16:22:31
Z"
}
],
"rootPath"
:
"github.com/XiaoMi/soar"
...
...
vendor/vitess.io/vitess/go/vt/sqlparser/ast.go
浏览文件 @
268d9aee
...
...
@@ -746,15 +746,18 @@ type DDL struct {
// DDL strings.
const
(
CreateStr
=
"create"
AlterStr
=
"alter"
DropStr
=
"drop"
RenameStr
=
"rename"
TruncateStr
=
"truncate"
FlushStr
=
"flush"
CreateVindexStr
=
"create vindex"
AddColVindexStr
=
"add vindex"
DropColVindexStr
=
"drop vindex"
CreateStr
=
"create"
AlterStr
=
"alter"
DropStr
=
"drop"
RenameStr
=
"rename"
TruncateStr
=
"truncate"
FlushStr
=
"flush"
CreateVindexStr
=
"create vindex"
DropVindexStr
=
"drop vindex"
AddVschemaTableStr
=
"add vschema table"
DropVschemaTableStr
=
"drop vschema table"
AddColVindexStr
=
"on table add vindex"
DropColVindexStr
=
"on table drop vindex"
// Vindex DDL param to specify the owner of a vindex
VindexOwnerStr
=
"owner"
...
...
@@ -791,9 +794,15 @@ func (node *DDL) Format(buf *TrackedBuffer) {
case
FlushStr
:
buf
.
Myprintf
(
"%s"
,
node
.
Action
)
case
CreateVindexStr
:
buf
.
Myprintf
(
"%s %v %v"
,
node
.
Action
,
node
.
VindexSpec
.
Name
,
node
.
VindexSpec
)
buf
.
Myprintf
(
"alter vschema create vindex %v %v"
,
node
.
VindexSpec
.
Name
,
node
.
VindexSpec
)
case
DropVindexStr
:
buf
.
Myprintf
(
"alter vschema drop vindex %v"
,
node
.
VindexSpec
.
Name
)
case
AddVschemaTableStr
:
buf
.
Myprintf
(
"alter vschema add table %v"
,
node
.
Table
)
case
DropVschemaTableStr
:
buf
.
Myprintf
(
"alter vschema drop table %v"
,
node
.
Table
)
case
AddColVindexStr
:
buf
.
Myprintf
(
"alter
table %v %s %v ("
,
node
.
Table
,
node
.
Action
,
node
.
VindexSpec
.
Name
)
buf
.
Myprintf
(
"alter
vschema on %v add vindex %v ("
,
node
.
Table
,
node
.
VindexSpec
.
Name
)
for
i
,
col
:=
range
node
.
VindexCols
{
if
i
!=
0
{
buf
.
Myprintf
(
", %v"
,
col
)
...
...
@@ -806,7 +815,7 @@ func (node *DDL) Format(buf *TrackedBuffer) {
buf
.
Myprintf
(
" %v"
,
node
.
VindexSpec
)
}
case
DropColVindexStr
:
buf
.
Myprintf
(
"alter
table %v %s %v"
,
node
.
Table
,
node
.
Action
,
node
.
VindexSpec
.
Name
)
buf
.
Myprintf
(
"alter
vschema on %v drop vindex %v"
,
node
.
Table
,
node
.
VindexSpec
.
Name
)
default
:
buf
.
Myprintf
(
"%s table %v"
,
node
.
Action
,
node
.
Table
)
}
...
...
vendor/vitess.io/vitess/go/vt/sqlparser/sql.go
浏览文件 @
268d9aee
此差异已折叠。
点击以展开。
vendor/vitess.io/vitess/go/vt/sqlparser/sql.y
浏览文件 @
268d9aee
...
...
@@ -180,7 +180,7 @@ func skipToEnd(yylex interface{}) {
%token <bytes> NULLX AUTO_INCREMENT APPROXNUM SIGNED UNSIGNED ZEROFILL
// Supported SHOW tokens
%token <bytes> COLLATION DATABASES TABLES VITESS_KEYSPACES VITESS_SHARDS VITESS_TABLETS VSCHEMA_TABLES VITESS_TARGET FULL PROCESSLIST COLUMNS FIELDS ENGINES PLUGINS
%token <bytes> COLLATION DATABASES TABLES VITESS_KEYSPACES VITESS_SHARDS VITESS_TABLETS VSCHEMA
VSCHEMA
_TABLES VITESS_TARGET FULL PROCESSLIST COLUMNS FIELDS ENGINES PLUGINS
// SET tokens
%token <bytes> NAMES CHARSET GLOBAL SESSION ISOLATION LEVEL READ WRITE ONLY REPEATABLE COMMITTED UNCOMMITTED SERIALIZABLE
...
...
@@ -570,14 +570,6 @@ create_statement:
{
$$ = &DDL{Action: CreateStr, Table: $5.ToViewName()}
}
| CREATE VINDEX sql_id vindex_type_opt vindex_params_opt
{
$$ = &DDL{Action: CreateVindexStr, VindexSpec: &VindexSpec{
Name: $3,
Type: $4,
Params: $5,
}}
}
| CREATE DATABASE not_exists_opt ID ddl_skip_to_end
{
$$ = &DBDDL{Action: CreateStr, DBName: string($4)}
...
...
@@ -1300,7 +1292,47 @@ alter_statement:
{
$$ = &DDL{Action: AlterStr, Table: $4}
}
| ALTER ignore_opt TABLE table_name ADD VINDEX sql_id '
(
' column_list '
)
' vindex_type_opt vindex_params_opt
| ALTER ignore_opt TABLE table_name RENAME to_opt table_name
{
// Change this to a rename statement
$$ = &DDL{Action: RenameStr, FromTables: TableNames{$4}, ToTables: TableNames{$7}}
}
| ALTER ignore_opt TABLE table_name RENAME index_opt skip_to_end
{
// Rename an index can just be an alter
$$ = &DDL{Action: AlterStr, Table: $4}
}
| ALTER VIEW table_name ddl_skip_to_end
{
$$ = &DDL{Action: AlterStr, Table: $3.ToViewName()}
}
| ALTER ignore_opt TABLE table_name partition_operation
{
$$ = &DDL{Action: AlterStr, Table: $4, PartitionSpec: $5}
}
| ALTER VSCHEMA CREATE VINDEX sql_id vindex_type_opt vindex_params_opt
{
$$ = &DDL{Action: CreateVindexStr, VindexSpec: &VindexSpec{
Name: $5,
Type: $6,
Params: $7,
}}
}
| ALTER VSCHEMA DROP VINDEX sql_id
{
$$ = &DDL{Action: DropVindexStr, VindexSpec: &VindexSpec{
Name: $5,
}}
}
| ALTER VSCHEMA ADD TABLE table_name
{
$$ = &DDL{Action: AddVschemaTableStr, Table: $5}
}
| ALTER VSCHEMA DROP TABLE table_name
{
$$ = &DDL{Action: DropVschemaTableStr, Table: $5}
}
| ALTER VSCHEMA ON table_name ADD VINDEX sql_id '
(
' column_list '
)
' vindex_type_opt vindex_params_opt
{
$$ = &DDL{
Action: AddColVindexStr,
...
...
@@ -1313,7 +1345,7 @@ alter_statement:
VindexCols: $9,
}
}
| ALTER
ignore_opt TABLE
table_name DROP VINDEX sql_id
| ALTER
VSCHEMA ON
table_name DROP VINDEX sql_id
{
$$ = &DDL{
Action: DropColVindexStr,
...
...
@@ -1323,24 +1355,6 @@ alter_statement:
},
}
}
| ALTER ignore_opt TABLE table_name RENAME to_opt table_name
{
// Change this to a rename statement
$$ = &DDL{Action: RenameStr, FromTables: TableNames{$4}, ToTables: TableNames{$7}}
}
| ALTER ignore_opt TABLE table_name RENAME index_opt skip_to_end
{
// Rename an index can just be an alter
$$ = &DDL{Action: AlterStr, Table: $4}
}
| ALTER VIEW table_name ddl_skip_to_end
{
$$ = &DDL{Action: AlterStr, Table: $3.ToViewName()}
}
| ALTER ignore_opt TABLE table_name partition_operation
{
$$ = &DDL{Action: AlterStr, Table: $4, PartitionSpec: $5}
}
alter_object_type:
COLUMN
...
...
@@ -1535,10 +1549,6 @@ show_statement:
{
$$
=
&
Show
{
Scope
:
$
2
,
Type
:
string
($
3
)}
}
|
SHOW
VINDEXES
{
$$
=
&
Show
{
Type
:
string
($
2
)}
}
|
SHOW
COLLATION
{
$$
=
&
Show
{
Type
:
string
($
2
)}
...
...
@@ -1549,10 +1559,6 @@ show_statement:
showCollationFilterOpt
:=
$
4
$$
=
&
Show
{
Type
:
string
($
2
),
ShowCollationFilterOpt
:
&
showCollationFilterOpt
}
}
|
SHOW
VINDEXES
ON
table_name
{
$$
=
&
Show
{
Type
:
string
($
2
),
OnTable
:
$
4
}
}
|
SHOW
VITESS_KEYSPACES
{
$$
=
&
Show
{
Type
:
string
($
2
)}
...
...
@@ -1569,9 +1575,17 @@ show_statement:
{
$$
=
&
Show
{
Type
:
string
($
2
)}
}
|
SHOW
VSCHEMA
_
TABLES
|
SHOW
VSCHEMA
TABLES
{
$$
=
&
Show
{
Type
:
string
($
2
)}
$$
=
&
Show
{
Type
:
string
($
2
)
+
" "
+
string
($
3
)}
}
|
SHOW
VSCHEMA
VINDEXES
{
$$
=
&
Show
{
Type
:
string
($
2
)
+
" "
+
string
($
3
)}
}
|
SHOW
VSCHEMA
VINDEXES
ON
table_name
{
$$
=
&
Show
{
Type
:
string
($
2
)
+
" "
+
string
($
3
),
OnTable
:
$
5
}
}
|
SHOW
WARNINGS
{
...
...
@@ -3351,6 +3365,7 @@ non_reserved_keyword:
| VITESS_KEYSPACES
| VITESS_SHARDS
| VITESS_TABLETS
| VSCHEMA
| VSCHEMA_TABLES
| VITESS_TARGET
| WARNINGS
...
...
vendor/vitess.io/vitess/go/vt/sqlparser/token.go
浏览文件 @
268d9aee
...
...
@@ -393,6 +393,7 @@ var keywords = map[string]int{
"vitess_shards"
:
VITESS_SHARDS
,
"vitess_tablets"
:
VITESS_TABLETS
,
"vitess_target"
:
VITESS_TARGET
,
"vschema"
:
VSCHEMA
,
"vschema_tables"
:
VSCHEMA_TABLES
,
"warnings"
:
WARNINGS
,
"when"
:
WHEN
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录