Skip to content

Commit

Permalink
Fix: remove side on condition simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 19, 2023
1 parent 2f43629 commit 6945b28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sqlglot/optimizer/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,14 @@ def remove_where_true(expression):
if always_true(where.this):
where.parent.set("where", None)
for join in expression.find_all(exp.Join):
if always_true(join.args.get("on")):
join.set("kind", "CROSS")
if (
always_true(join.args.get("on"))
and not join.args.get("using")
and not join.args.get("method")
):
join.set("on", None)
join.set("side", None)
join.set("kind", "CROSS")


def always_true(expression):
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/optimizer/simplify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ A AND B AND C;
SELECT x WHERE TRUE;
SELECT x;

SELECT x FROM y LEFT JOIN z ON TRUE;
SELECT x FROM y CROSS JOIN z;

SELECT x FROM y JOIN z USING (x);
SELECT x FROM y JOIN z USING (x);

--------------------------------------
-- Parenthesis removal
--------------------------------------
Expand Down

0 comments on commit 6945b28

Please sign in to comment.