diff --git a/advisor/heuristic.go b/advisor/heuristic.go index 20c25b05fcc7546a265a05106cbe1fc004ebc9f7..baf27ce9e9b1b2a4bda9b86332ac186bde1b6763 100644 --- a/advisor/heuristic.go +++ b/advisor/heuristic.go @@ -1228,6 +1228,17 @@ func (q *Query4Audit) RuleImpossibleWhere() Rule { // RuleMeaninglessWhere RES.007 func (q *Query4Audit) RuleMeaninglessWhere() Rule { var rule = q.RuleOK() + // SELECT * FROM tb WHERE 1 + switch n := q.Stmt.(type) { + case *sqlparser.Select: + if n.Where != nil { + switch n.Where.Expr.(type) { + case *sqlparser.SQLVal: + rule = HeuristicRules["RES.007"] + return rule + } + } + } // 1=1, 0=0 err := sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { switch n := node.(type) { @@ -1266,7 +1277,6 @@ func (q *Query4Audit) RuleMeaninglessWhere() Rule { } return false, nil } - return true, nil }, q.Stmt) common.LogIfError(err, "") diff --git a/advisor/heuristic_test.go b/advisor/heuristic_test.go index be14632c888bc3dc6661da719a9cda7459e29678..2ebcf399f25d7c5be85bf9b48be91330e4ce8093 100644 --- a/advisor/heuristic_test.go +++ b/advisor/heuristic_test.go @@ -854,6 +854,10 @@ func TestRuleMeaninglessWhere(t *testing.T) { "select * from tbl where 1 = 1;", "select * from tbl where 'a' = 'a';", "select * from tbl where 'a' != 1;", + "select * from tbl where 'a';", + "select * from tbl where 'a' limit 1;", + "select * from tbl where 1;", + "select * from tbl where 1 limit 1;", }, { "select * from tbl where 2 = 1;",