diff --git a/advisor/heuristic.go b/advisor/heuristic.go index 4d7087b38e44e4c3c0480b36c5a5c72172043618..e03ef1145a8ab7702630cd55f79f4d2ef1cc4e7d 100644 --- a/advisor/heuristic.go +++ b/advisor/heuristic.go @@ -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)) @@ -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", diff --git a/advisor/index_test.go b/advisor/index_test.go index 6e755d843530f52c77b1fd8685806991dd3c3c19..53b061ed1bdee37c5c77bb6a4a9eb35aea1480b9 100644 --- a/advisor/index_test.go +++ b/advisor/index_test.go @@ -83,6 +83,7 @@ func TestRuleImplicitConversion(t *testing.T) { } sqls := [][]string{ + // ARG.003 { "SELECT * FROM t1 WHERE title >= 60;", "SELECT * FROM t1, t2 WHERE t1.title = t2.title;", @@ -90,11 +91,13 @@ func TestRuleImplicitConversion(t *testing.T) { "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", }, } @@ -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) } } } @@ -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) } } }