Skip to content

Commit

Permalink
expression rewriting: clean up CNF limits
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 21, 2023
1 parent 719cdf3 commit 1fd2587
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion go/vt/sqlparser/predicate_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"vitess.io/vitess/go/vt/log"
)

// This is the number of OR expressions in a predicate that will disable the CNF
// rewrite because we don't want to send large queries to MySQL
const CNFOrLimit = 5

// RewritePredicate walks the input AST and rewrites any boolean logic into a simpler form
// This simpler form is CNF plus logic for extracting predicates from OR, plus logic for turning ORs into IN
// Note: In order to re-plan, we need to empty the accumulated metadata in the AST,
Expand All @@ -34,7 +38,7 @@ func RewritePredicate(ast SQLNode) SQLNode {
return true, nil
}, ast)

allowCNF := count < 4
allowCNF := count < CNFOrLimit

for {
printExpr(ast)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/predicate_rewriting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestExtractINFromOR(in *testing.T) {
in: "(a in (1, 5) and B or C and a in (5, 7))",
expected: "a in (1, 5, 7)",
}, {
in: "(a = 1 and b = 41) or (a = 2 and b = 42) or (a = 3 and b = 43) or (a = 4 and b = 44)",
in: "(a = 5 and b = 1 or b = 2 and a = 6 or b = 3 and a = 4)",
expected: "<nil>",
}}

Expand Down

0 comments on commit 1fd2587

Please sign in to comment.