summaryrefslogtreecommitdiffstats
path: root/sqlglot/optimizer/simplify.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:44:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:44:58 +0000
commitbeba715b97dd2349e01dde9b077d2535680ebdca (patch)
tree0c54accb48c28eb54d2f48f88d149492717b30e5 /sqlglot/optimizer/simplify.py
parentReleasing debian version 11.7.1-1. (diff)
downloadsqlglot-beba715b97dd2349e01dde9b077d2535680ebdca.tar.xz
sqlglot-beba715b97dd2349e01dde9b077d2535680ebdca.zip
Merging upstream version 12.2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/optimizer/simplify.py')
-rw-r--r--sqlglot/optimizer/simplify.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/sqlglot/optimizer/simplify.py b/sqlglot/optimizer/simplify.py
index 4e6c910..0904189 100644
--- a/sqlglot/optimizer/simplify.py
+++ b/sqlglot/optimizer/simplify.py
@@ -60,6 +60,7 @@ def rewrite_between(expression: exp.Expression) -> exp.Expression:
return exp.and_(
exp.GTE(this=expression.this.copy(), expression=expression.args["low"]),
exp.LTE(this=expression.this.copy(), expression=expression.args["high"]),
+ copy=False,
)
return expression
@@ -76,9 +77,17 @@ def simplify_not(expression):
if isinstance(expression.this, exp.Paren):
condition = expression.this.unnest()
if isinstance(condition, exp.And):
- return exp.or_(exp.not_(condition.left), exp.not_(condition.right))
+ return exp.or_(
+ exp.not_(condition.left, copy=False),
+ exp.not_(condition.right, copy=False),
+ copy=False,
+ )
if isinstance(condition, exp.Or):
- return exp.and_(exp.not_(condition.left), exp.not_(condition.right))
+ return exp.and_(
+ exp.not_(condition.left, copy=False),
+ exp.not_(condition.right, copy=False),
+ copy=False,
+ )
if is_null(condition):
return exp.null()
if always_true(expression.this):
@@ -254,12 +263,12 @@ def uniq_sort(expression, cache=None, root=True):
# A AND C AND B -> A AND B AND C
for i, (sql, e) in enumerate(arr[1:]):
if sql < arr[i][0]:
- expression = result_func(*(e for _, e in sorted(arr)))
+ expression = result_func(*(e for _, e in sorted(arr)), copy=False)
break
else:
# we didn't have to sort but maybe we need to dedup
if len(deduped) < len(flattened):
- expression = result_func(*deduped.values())
+ expression = result_func(*deduped.values(), copy=False)
return expression