Skip to content

Commit

Permalink
Fix(optimizer): dont simplify parens with multiple predicates closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Aug 31, 2023
1 parent 632ad59 commit 999a950
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlglot/optimizer/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ def simplify_parens(expression):

if not isinstance(this, exp.Select) and (
not isinstance(parent, (exp.Condition, exp.Binary))
or isinstance(this, exp.Predicate)
or isinstance(parent, exp.Paren)
or not isinstance(this, exp.Binary)
or (isinstance(this, exp.Predicate) and not isinstance(parent, exp.Predicate))
or (isinstance(this, exp.Add) and isinstance(parent, exp.Add))
or (isinstance(this, exp.Mul) and isinstance(parent, exp.Mul))
or (isinstance(this, exp.Mul) and isinstance(parent, (exp.Add, exp.Sub)))
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/optimizer/simplify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ x = y AND z;
x * (1 - y);
x * (1 - y);

(((x % 20) = 0) = TRUE);
((x % 20) = 0) = TRUE;

--------------------------------------
-- Literals
--------------------------------------
Expand Down

0 comments on commit 999a950

Please sign in to comment.