Skip to content

Commit

Permalink
fix #38
Browse files Browse the repository at this point in the history
  RES.007 select * from tbl where 1;
  • Loading branch information
martianzhang committed Nov 7, 2018
1 parent fd276eb commit ee770b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion advisor/heuristic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1266,7 +1277,6 @@ func (q *Query4Audit) RuleMeaninglessWhere() Rule {
}
return false, nil
}

return true, nil
}, q.Stmt)
common.LogIfError(err, "")
Expand Down
4 changes: 4 additions & 0 deletions advisor/heuristic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down

0 comments on commit ee770b4

Please sign in to comment.