Refs #34717 -- Avoided computing aggregate refs twice.

This commit is contained in:
Simon Charette 2023-11-17 19:55:27 -05:00 committed by Mariusz Felisiak
parent 15cb3c262a
commit d7a9f006ed
1 changed files with 3 additions and 2 deletions

View File

@ -451,13 +451,14 @@ class Query(BaseExpression):
# Temporarily add aggregate to annotations to allow remaining # Temporarily add aggregate to annotations to allow remaining
# members of `aggregates` to resolve against each others. # members of `aggregates` to resolve against each others.
self.append_annotation_mask([alias]) self.append_annotation_mask([alias])
aggregate_refs = aggregate.get_refs()
refs_subquery |= any( refs_subquery |= any(
getattr(self.annotations[ref], "contains_subquery", False) getattr(self.annotations[ref], "contains_subquery", False)
for ref in aggregate.get_refs() for ref in aggregate_refs
) )
refs_window |= any( refs_window |= any(
getattr(self.annotations[ref], "contains_over_clause", True) getattr(self.annotations[ref], "contains_over_clause", True)
for ref in aggregate.get_refs() for ref in aggregate_refs
) )
aggregate = aggregate.replace_expressions(replacements) aggregate = aggregate.replace_expressions(replacements)
self.annotations[alias] = aggregate self.annotations[alias] = aggregate