Skip to content

Commit

Permalink
update soar ARG.003 check rules
Browse files Browse the repository at this point in the history
	string -> int can use index
  • Loading branch information
martianzhang committed May 17, 2021
1 parent 54e106c commit cb63ad7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion advisor/heuristic.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
common.Log.Debug("DataType: `%s`.`%s` (%s) VS `%s`.`%s` (%s)",
colList[0].Table, colList[0].Name, type1,
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",
colList[0].Table, colList[0].Name, type1,
colList[1].Table, colList[1].Name, type2))
Expand Down Expand Up @@ -296,6 +297,8 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule {
sqlparser.StrVal: {
"char", "varchar", "tinytext", "text", "mediumtext", "longtext",
"date", "time", "datetime", "timestamp", "year",
"tinyint", "smallint", "mediumint", "int", "integer", "bigint",
"float", "double", "real", "decimal",
},
sqlparser.IntVal: {
"tinyint", "smallint", "mediumint", "int", "integer", "bigint",
Expand Down
13 changes: 8 additions & 5 deletions advisor/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ func TestRuleImplicitConversion(t *testing.T) {
}

sqls := [][]string{
// ARG.003
{
"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 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 t4 WHERE col = 1",
"SELECT * FROM t1 WHERE id = '1'", // string -> int can use index
"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",
},
}
Expand All @@ -114,7 +117,7 @@ func TestRuleImplicitConversion(t *testing.T) {
if idxAdvisor != nil {
rule := idxAdvisor.RuleImplicitConversion()
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)
}
}
}
Expand All @@ -134,7 +137,7 @@ func TestRuleImplicitConversion(t *testing.T) {
if idxAdvisor != nil {
rule := idxAdvisor.RuleImplicitConversion()
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)
}
}
}
Expand Down

0 comments on commit cb63ad7

Please sign in to comment.