Skip to content

Commit

Permalink
Fix(optimizer): solve an infinite loop problem in simplify (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Aug 16, 2023
1 parent 3c01cbf commit 3c493e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sqlglot/optimizer/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def absorb_and_eliminate(expression, root=True):
def simplify_literals(expression, root=True):
if isinstance(expression, exp.Binary) and not isinstance(expression, exp.Connector):
return _flat_simplify(expression, _simplify_binary, root)
elif isinstance(expression, exp.Neg):

if isinstance(expression, exp.Neg):
this = expression.this
if this.is_number:
value = this.name
Expand Down Expand Up @@ -645,7 +646,7 @@ def _flat_simplify(expression, simplifier, root=True):
for b in queue:
result = simplifier(expression, a, b)

if result:
if result and result is not expression:
queue.remove(b)
queue.appendleft(result)
break
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 @@ -615,6 +615,9 @@ TRUE;
x = 2018 OR x <> 2018;
x <> 2018 OR x = 2018;

t0.x = t1.x AND t0.y < t1.y AND t0.y <= t1.y;
t0.x = t1.x AND t0.y < t1.y AND t0.y <= t1.y;

--------------------------------------
-- Coalesce
--------------------------------------
Expand Down

0 comments on commit 3c493e9

Please sign in to comment.