Skip to content

Commit 2e5fe48

Browse files
committed
Repair optimization bug I introduced in a moment of brain fade back in
Nov 2002: when constant-expression simplification removes all the aggregate function calls from a query, that doesn't mean we can act as though there never were any aggregates. Per bug report from Gabor Szucs.
1 parent f884090 commit 2e5fe48

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.166 2004/02/03 17:34:03 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.167 2004/02/13 22:26:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -709,19 +709,18 @@ grouping_planner(Query *parse, double tuple_fraction)
709709

710710
/*
711711
* Will need actual number of aggregates for estimating costs.
712-
* Also, it's possible that optimization has eliminated all
713-
* aggregates, and we may as well check for that here.
714712
*
715713
* Note: we do not attempt to detect duplicate aggregates here; a
716714
* somewhat-overestimated count is okay for our present purposes.
715+
*
716+
* Note: think not that we can turn off hasAggs if we find no aggs.
717+
* It is possible for constant-expression simplification to remove
718+
* all explicit references to aggs, but we still have to follow the
719+
* aggregate semantics (eg, producing only one output row).
717720
*/
718721
if (parse->hasAggs)
719-
{
720722
numAggs = count_agg_clause((Node *) tlist) +
721723
count_agg_clause(parse->havingQual);
722-
if (numAggs == 0)
723-
parse->hasAggs = false;
724-
}
725724

726725
/*
727726
* Figure out whether we need a sorted result from query_planner.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy