On 28/12/2019 01:35, Jeff Davis wrote:
I've attached a new patch that adds some basic costing for disk during
hashagg.
This patch (hashagg-20191227.patch) doesn't compile:
nodeAgg.c:3379:7: error: ‘hashagg_mem_overflow’ undeclared (first use in
this function)
if (hashagg_mem_overflow)
^~~~~~~~~~~~~~~~~~~~
Looks like the new GUCs got lost somewhere between
hashagg-20191220.patch and hashagg-20191227.patch.
/*
* find_aggregated_cols
* Construct a bitmapset of the column numbers of aggregated Vars
* appearing in our targetlist and qual (HAVING clause)
*/
static Bitmapset *
find_aggregated_cols(AggState *aggstate)
{
Agg *node = (Agg *) aggstate->ss.ps.plan;
Bitmapset *colnos = NULL;
ListCell *temp;
/*
* We only want the columns used by aggregations in the targetlist or
qual
*/
if (node->plan.targetlist != NULL)
{
foreach(temp, (List *) node->plan.targetlist)
{
if (IsA(lfirst(temp), TargetEntry))
{
Node *node = (Node *)((TargetEntry
*)lfirst(temp))->expr;
if (IsA(node, Aggref) || IsA(node,
GroupingFunc))
find_aggregated_cols_walker(node,
&colnos);
}
}
}
This makes the assumption that all Aggrefs or GroupingFuncs are at the
top of the TargetEntry. That's not true, e.g.:
select 0+sum(a) from foo group by b;
I think find_aggregated_cols() and find_unaggregated_cols() should be
merged into one function that scans the targetlist once, and returns two
Bitmapsets. They're always used together, anyway.
- Heikki