diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-07-19 12:29:37 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-07-19 12:29:37 -0400 |
commit | d6a3aeb9a37bdbb5aa8ed03a9f95e2b1a1b44ba7 (patch) | |
tree | 3a10100442b306e8c206bf6378015bd0a61c1a59 /src/backend/optimizer | |
parent | e2f6c307c02924e6ee1667890b56280ab1960d2e (diff) | |
download | postgresql-d6a3aeb9a37bdbb5aa8ed03a9f95e2b1a1b44ba7.tar.gz postgresql-d6a3aeb9a37bdbb5aa8ed03a9f95e2b1a1b44ba7.zip |
Convert planner's AggInfo and AggTransInfo structs to proper Nodes.
This is mostly just to get outfuncs.c support for them, so that
the agginfos and aggtransinfos lists can be dumped when dumping
the contents of PlannerInfo.
While here, improve some related comments; notably, clean up
obsolete comments left over from when preprocess_minmax_aggregates
had to make its own scan of the query tree.
Discussion: https://postgr.es/m/742479.1658160504@sss.pgh.pa.us
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r-- | src/backend/optimizer/plan/planagg.c | 20 | ||||
-rw-r--r-- | src/backend/optimizer/prep/prepagg.c | 16 |
2 files changed, 19 insertions, 17 deletions
diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c index 9330908cbf1..e0e357960f2 100644 --- a/src/backend/optimizer/plan/planagg.c +++ b/src/backend/optimizer/plan/planagg.c @@ -137,8 +137,8 @@ preprocess_minmax_aggregates(PlannerInfo *root) return; /* - * Scan the tlist and HAVING qual to find all the aggregates and verify - * all are MIN/MAX aggregates. Stop as soon as we find one that isn't. + * Examine all the aggregates and verify all are MIN/MAX aggregates. Stop + * as soon as we find one that isn't. */ aggs_list = NIL; if (!can_minmax_aggs(root, &aggs_list)) @@ -227,24 +227,24 @@ preprocess_minmax_aggregates(PlannerInfo *root) /* * can_minmax_aggs - * Walk through all the aggregates in the query, and check - * if they are all MIN/MAX aggregates. If so, build a list of the - * distinct aggregate calls in the tree. + * Examine all the aggregates in the query, and check if they are + * all MIN/MAX aggregates. If so, build a list of MinMaxAggInfo + * nodes for them. * * Returns false if a non-MIN/MAX aggregate is found, true otherwise. - * - * This does not descend into subqueries, and so should be used only after - * reduction of sublinks to subplans. There mustn't be outer-aggregate - * references either. */ static bool can_minmax_aggs(PlannerInfo *root, List **context) { ListCell *lc; + /* + * This function used to have to scan the query for itself, but now we can + * just thumb through the AggInfo list made by preprocess_aggrefs. + */ foreach(lc, root->agginfos) { - AggInfo *agginfo = (AggInfo *) lfirst(lc); + AggInfo *agginfo = lfirst_node(AggInfo, lc); Aggref *aggref = agginfo->representative_aggref; Oid aggsortop; TargetEntry *curTarget; diff --git a/src/backend/optimizer/prep/prepagg.c b/src/backend/optimizer/prep/prepagg.c index 404a5f1dac8..5b12937eada 100644 --- a/src/backend/optimizer/prep/prepagg.c +++ b/src/backend/optimizer/prep/prepagg.c @@ -223,13 +223,13 @@ preprocess_aggref(Aggref *aggref, PlannerInfo *root) aggno = find_compatible_agg(root, aggref, &same_input_transnos); if (aggno != -1) { - AggInfo *agginfo = list_nth(root->agginfos, aggno); + AggInfo *agginfo = list_nth_node(AggInfo, root->agginfos, aggno); transno = agginfo->transno; } else { - AggInfo *agginfo = palloc(sizeof(AggInfo)); + AggInfo *agginfo = makeNode(AggInfo); agginfo->finalfn_oid = aggfinalfn; agginfo->representative_aggref = aggref; @@ -266,7 +266,7 @@ preprocess_aggref(Aggref *aggref, PlannerInfo *root) same_input_transnos); if (transno == -1) { - AggTransInfo *transinfo = palloc(sizeof(AggTransInfo)); + AggTransInfo *transinfo = makeNode(AggTransInfo); transinfo->args = aggref->args; transinfo->aggfilter = aggref->aggfilter; @@ -381,7 +381,7 @@ find_compatible_agg(PlannerInfo *root, Aggref *newagg, aggno = -1; foreach(lc, root->agginfos) { - AggInfo *agginfo = (AggInfo *) lfirst(lc); + AggInfo *agginfo = lfirst_node(AggInfo, lc); Aggref *existingRef; aggno++; @@ -452,7 +452,9 @@ find_compatible_trans(PlannerInfo *root, Aggref *newagg, bool shareable, foreach(lc, transnos) { int transno = lfirst_int(lc); - AggTransInfo *pertrans = (AggTransInfo *) list_nth(root->aggtransinfos, transno); + AggTransInfo *pertrans = list_nth_node(AggTransInfo, + root->aggtransinfos, + transno); /* * if the transfns or transition state types are not the same then the @@ -541,7 +543,7 @@ get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs foreach(lc, root->aggtransinfos) { - AggTransInfo *transinfo = (AggTransInfo *) lfirst(lc); + AggTransInfo *transinfo = lfirst_node(AggTransInfo, lc); /* * Add the appropriate component function execution costs to @@ -645,7 +647,7 @@ get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs foreach(lc, root->agginfos) { - AggInfo *agginfo = (AggInfo *) lfirst(lc); + AggInfo *agginfo = lfirst_node(AggInfo, lc); Aggref *aggref = agginfo->representative_aggref; /* |