Re: Memory-Bounded Hash Aggregation

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Jeff Davis <pgsql(at)j-davis(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Taylor Vesely <tvesely(at)pivotal(dot)io>, Adam Lee <ali(at)pivotal(dot)io>, Melanie Plageman <mplageman(at)pivotal(dot)io>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Memory-Bounded Hash Aggregation
Date: 2020-01-08 10:38:18
Message-ID: 775d754c-9a61-5363-6998-f87d15f1b592@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2020-01-08 10:54:52 Re: adding partitioned tables to publications
Previous Message Heikki Linnakangas 2020-01-08 09:28:49 Re: Improve checking for pg_index.xmin