Skip to content

Commit 6b7084d

Browse files
authored
Chore(optimizer): refactor costly scope walking loop in qualify tables (#6364)
1 parent 3aafca7 commit 6b7084d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

sqlglot/optimizer/qualify_tables.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,10 @@ def _qualify(table: exp.Table) -> None:
144144
for i in dialect.generate_values_aliases(udtf)
145145
]
146146
table_alias.set("columns", column_aliases)
147-
else:
148-
for node in scope.walk():
149-
if (
150-
isinstance(node, exp.Table)
151-
and not node.alias
152-
and isinstance(node.parent, (exp.From, exp.Join))
153-
):
154-
# Mutates the table by attaching an alias to it
155-
exp.alias_(node, node.name, copy=False, table=True)
147+
148+
for table in scope.tables:
149+
if not table.alias and isinstance(table.parent, (exp.From, exp.Join)):
150+
exp.alias_(table, table.name, copy=False, table=True)
156151

157152
for column in scope.columns:
158153
if column.db:

0 commit comments

Comments
 (0)