An oversight in ExecInitAgg for grouping sets

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: An oversight in ExecInitAgg for grouping sets
Date: 2022-12-22 06:02:42
Message-ID: CAMbWs4-vZuuPOZsKOYnSAaPYGKhmacxhki+vpOKk0O7rymccXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I happened to notice $subject. It happens when we build eqfunctions for
each grouping set.

/* for each grouping set */
for (int k = 0; k < phasedata->numsets; k++)
{
int length = phasedata->gset_lengths[k];

if (phasedata->eqfunctions[length - 1] != NULL)
continue;

phasedata->eqfunctions[length - 1] =
execTuplesMatchPrepare(scanDesc,
length,
aggnode->grpColIdx,
aggnode->grpOperators,
aggnode->grpCollations,
(PlanState *) aggstate);
}

If it is an empty grouping set, its length will be zero, and accessing
phasedata->eqfunctions[length - 1] is not right.

I think we can just skip building the eqfunctions for empty grouping
set.

--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -3494,6 +3494,10 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
{
int length = phasedata->gset_lengths[k];

+ /* skip empty grouping set */
+ if (length == 0)
+ continue;
+
if (phasedata->eqfunctions[length - 1] != NULL)
continue;

Thanks
Richard

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2022-12-22 06:08:59 Re: Perform streaming logical transactions by background workers and parallel apply
Previous Message Takamichi Osumi (Fujitsu) 2022-12-22 06:01:49 RE: Time delayed LR (WAS Re: logical replication restrictions)