1
0
Fork 0

Merging upstream version 11.3.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 15:42:13 +01:00
parent f223c02081
commit 1c10961499
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
62 changed files with 26499 additions and 24781 deletions
sqlglot/optimizer

View file

@ -314,13 +314,27 @@ def _merge_where(outer_scope, inner_scope, from_or_join):
if not where or not where.this:
return
expression = outer_scope.expression
if isinstance(from_or_join, exp.Join):
# Merge predicates from an outer join to the ON clause
from_or_join.on(where.this, copy=False)
from_or_join.set("on", simplify(from_or_join.args.get("on")))
else:
outer_scope.expression.where(where.this, copy=False)
outer_scope.expression.set("where", simplify(outer_scope.expression.args.get("where")))
# if it only has columns that are already joined
from_ = expression.args.get("from")
sources = {table.alias_or_name for table in from_.expressions} if from_ else {}
for join in expression.args["joins"]:
source = join.alias_or_name
sources.add(source)
if source == from_or_join.alias_or_name:
break
if set(exp.column_table_names(where.this)) <= sources:
from_or_join.on(where.this, copy=False)
from_or_join.set("on", simplify(from_or_join.args.get("on")))
return
expression.where(where.this, copy=False)
expression.set("where", simplify(expression.args.get("where")))
def _merge_order(outer_scope, inner_scope):