Re: BUG #16784: Server crash in ExecReScanAgg()

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org, Jeff Davis <pgsql@j-davis.com>
Date: 2020-12-21T19:26:06Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> The following query (borrowed from regression tests):
> ...
> leads to a server crash with the following stacktrace:

Duplicated here.

> The first bad commit is 2fd6a44a.

I suspect the culprit is 1f39bce02 (but it's still Jeff's fault ;-)).
What I see happening is that the second time through ExecReScanAgg
crashes here:

            MemSet(node->pergroups[setno], 0,
                   sizeof(AggStatePerGroupData) * node->numaggs);

because node->pergroups[0] is now NULL, which is the fault of
this bit in agg_refill_hash_table:

    /* there could be residual pergroup pointers; clear them */
    for (int setoff = 0;
         setoff < aggstate->maxsets + aggstate->num_hashes;
         setoff++)
        aggstate->all_pergroups[setoff] = NULL;

I suspect this is clearing the wrong subset of the all_pergroups
pointers, but the code is so underdocumented that I'm not very
sure.

			regards, tom lane



Commits

  1. Fix bug #16784 in Disk-based Hash Aggregation.