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

update soar ARG.003 check rules

	string -> int can use index
上级 54e106ca
...@@ -261,7 +261,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule { ...@@ -261,7 +261,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
common.Log.Debug("DataType: `%s`.`%s` (%s) VS `%s`.`%s` (%s)", common.Log.Debug("DataType: `%s`.`%s` (%s) VS `%s`.`%s` (%s)",
colList[0].Table, colList[0].Name, type1, colList[0].Table, colList[0].Name, type1,
colList[1].Table, colList[1].Name, type2) colList[1].Table, colList[1].Name, type2)
if strings.ToLower(type1) != strings.ToLower(type2) { // case-insensitive check type1, type2
if !strings.EqualFold(type1, type2) {
content = append(content, fmt.Sprintf("`%s`.`%s` (%s) VS `%s`.`%s` (%s) datatype not match", content = append(content, fmt.Sprintf("`%s`.`%s` (%s) VS `%s`.`%s` (%s) datatype not match",
colList[0].Table, colList[0].Name, type1, colList[0].Table, colList[0].Name, type1,
colList[1].Table, colList[1].Name, type2)) colList[1].Table, colList[1].Name, type2))
...@@ -296,6 +297,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule { ...@@ -296,6 +297,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
sqlparser.StrVal: { sqlparser.StrVal: {
"char", "varchar", "tinytext", "text", "mediumtext", "longtext", "char", "varchar", "tinytext", "text", "mediumtext", "longtext",
"date", "time", "datetime", "timestamp", "year", "date", "time", "datetime", "timestamp", "year",
"tinyint", "smallint", "mediumint", "int", "integer", "bigint",
"float", "double", "real", "decimal",
}, },
sqlparser.IntVal: { sqlparser.IntVal: {
"tinyint", "smallint", "mediumint", "int", "integer", "bigint", "tinyint", "smallint", "mediumint", "int", "integer", "bigint",
......
...@@ -83,6 +83,7 @@ func TestRuleImplicitConversion(t *testing.T) { ...@@ -83,6 +83,7 @@ func TestRuleImplicitConversion(t *testing.T) {
} }
sqls := [][]string{ sqls := [][]string{
// ARG.003
{ {
"SELECT * FROM t1 WHERE title >= 60;", "SELECT * FROM t1 WHERE title >= 60;",
"SELECT * FROM t1, t2 WHERE t1.title = t2.title;", "SELECT * FROM t1, t2 WHERE t1.title = t2.title;",
...@@ -90,11 +91,13 @@ func TestRuleImplicitConversion(t *testing.T) { ...@@ -90,11 +91,13 @@ func TestRuleImplicitConversion(t *testing.T) {
"SELECT * FROM t1 WHERE title in (60, '60');", "SELECT * FROM t1 WHERE title in (60, '60');",
"SELECT * FROM t1 WHERE title in (60);", "SELECT * FROM t1 WHERE title in (60);",
"SELECT * FROM t1 WHERE title in (60, 60);", "SELECT * FROM t1 WHERE title in (60, 60);",
"SELECT * FROM t4 WHERE col = '1'", "SELECT * FROM t1 WHERE title = 1",
}, },
// OK
{ {
// https://github.com/XiaoMi/soar/issues/151 "SELECT * FROM t1 WHERE id = '1'", // string -> int can use index
"SELECT * FROM t4 WHERE col = 1", "SELECT * FROM t1 WHERE id = 1",
"SELECT * FROM t4 WHERE col = 1", // https://github.com/XiaoMi/soar/issues/151
"SELECT * FROM sakila.film WHERE rental_rate > 1", "SELECT * FROM sakila.film WHERE rental_rate > 1",
}, },
} }
...@@ -114,7 +117,7 @@ func TestRuleImplicitConversion(t *testing.T) { ...@@ -114,7 +117,7 @@ func TestRuleImplicitConversion(t *testing.T) {
if idxAdvisor != nil { if idxAdvisor != nil {
rule := idxAdvisor.RuleImplicitConversion() rule := idxAdvisor.RuleImplicitConversion()
if rule.Item != "ARG.003" { if rule.Item != "ARG.003" {
t.Error("Rule not match:", rule, "Expect : ARG.003, SQL:", sql) t.Error("Rule not match:", rule.Item, "Expect : ARG.003, SQL:", sql)
} }
} }
} }
...@@ -134,7 +137,7 @@ func TestRuleImplicitConversion(t *testing.T) { ...@@ -134,7 +137,7 @@ func TestRuleImplicitConversion(t *testing.T) {
if idxAdvisor != nil { if idxAdvisor != nil {
rule := idxAdvisor.RuleImplicitConversion() rule := idxAdvisor.RuleImplicitConversion()
if rule.Item != "OK" { if rule.Item != "OK" {
t.Error("Rule not match:", rule, "Expect : OK, SQL:", sql) t.Error("Rule not match:", rule.Item, "Expect : OK, SQL:", sql)
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册