提交 ccdfcb81 编写于 作者: martianzhang's avatar martianzhang

fix #151

  bit type not config as int, when two columns compare will
  give ARG.003 suggestion.

  fix #154, #157 by the way
上级 9579fa7c
......@@ -293,7 +293,7 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
"date", "time", "datetime", "timestamp", "year",
},
sqlparser.IntVal: {
"tinyint", "smallint", "mediumint", "int", "integer", "bigint", "timestamp", "year",
"tinyint", "smallint", "mediumint", "int", "integer", "bigint", "timestamp", "year", "bit",
},
sqlparser.FloatVal: {
"float", "double", "real", "decimal",
......
......@@ -59,19 +59,27 @@ func TestRuleImplicitConversion(t *testing.T) {
`CREATE TABLE t1 (id int, title varchar(255) CHARSET utf8 COLLATE utf8_general_ci);`,
`CREATE TABLE t2 (id int, title varchar(255) CHARSET utf8mb4);`,
`CREATE TABLE t3 (id int, title varchar(255) CHARSET utf8 COLLATE utf8_bin);`,
`CREATE TABLE t4 (id int, col bit(1));`,
}
for _, sql := range initSQLs {
vEnv.BuildVirtualEnv(rEnv, sql)
}
sqls := []string{
"SELECT * FROM t1 WHERE title >= 60;",
"SELECT * FROM t1, t2 WHERE t1.title = t2.title;",
"SELECT * FROM t1, t3 WHERE t1.title = t3.title;",
"SELECT * FROM t1 WHERE title in (60, '60');",
"SELECT * FROM t1 WHERE title in (60);",
sqls := [][]string{
{
"SELECT * FROM t1 WHERE title >= 60;",
"SELECT * FROM t1, t2 WHERE t1.title = t2.title;",
"SELECT * FROM t1, t3 WHERE t1.title = t3.title;",
"SELECT * FROM t1 WHERE title in (60, '60');",
"SELECT * FROM t1 WHERE title in (60);",
"SELECT * FROM t4 WHERE col = '1'",
},
{
// https://github.com/XiaoMi/soar/issues/151
"SELECT * FROM t4 WHERE col = 1",
},
}
for _, sql := range sqls {
for _, sql := range sqls[0] {
stmt, syntaxErr := sqlparser.Parse(sql)
if syntaxErr != nil {
common.Log.Critical("Syntax Error: %v, SQL: %s", syntaxErr, sql)
......@@ -91,6 +99,27 @@ func TestRuleImplicitConversion(t *testing.T) {
}
}
}
for _, sql := range sqls[1] {
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.RuleImplicitConversion()
if rule.Item != "OK" {
t.Error("Rule not match:", rule, "Expect : OK, SQL:", sql)
}
}
}
common.Log.Debug("Exiting function: %s", common.GetFunctionName())
common.Config.OnlineDSN = dsn
}
......
......@@ -515,7 +515,7 @@ func readCmdFlags() error {
// +++++++++++++++日志相关+++++++++++++++++
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, 日志输出位置")
reportType := flag.String("report-type", Config.ReportType, "ReportType, 化建议输出格式,目前支持: json, text, markdown, html等")
reportType := flag.String("report-type", Config.ReportType, "ReportType, 化建议输出格式,目前支持: json, text, markdown, html等")
reportCSS := flag.String("report-css", Config.ReportCSS, "ReportCSS, 当 ReportType 为 html 格式时使用的 css 风格,如不指定会提供一个默认风格。CSS可以是本地文件,也可以是一个URL")
reportJavascript := flag.String("report-javascript", Config.ReportJavascript, "ReportJavascript, 当 ReportType 为 html 格式时使用的javascript脚本,如不指定默认会加载SQL pretty 使用的 javascript。像CSS一样可以是本地文件,也可以是一个URL")
reportTitle := flag.String("report-title", Config.ReportTitle, "ReportTitle, 当 ReportType 为 html 格式时,HTML 的 title")
......
......@@ -91,11 +91,11 @@ func BuildEnv() (*VirtualEnv, *database.Connector) {
}
// 检查线上环境可用性版本
rEnvVersion, err := vEnv.Version()
rEnvVersion, err := conn.Version()
common.Config.OnlineDSN.Version = rEnvVersion
if err != nil {
common.Log.Warn("BuildEnv OnlineDSN: %s:********@%s/%s not available , Error: %s",
vEnv.User, vEnv.Addr, vEnv.Database, err.Error())
conn.User, conn.Addr, conn.Database, err.Error())
common.Config.TestDSN.Disable = true
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册