An oversight in ExecInitAgg for grouping sets
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2022-12-22T06:02:42Z
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
Commits
-
Adjust Valgrind macro usage to protect chunk headers
- 414d66220adb 16.0 landed
-
Fix typo in memutils_memorychunk.h
- b23837dde480 16.0 landed
-
Avoid reference to nonexistent array element in ExecInitAgg().
- fbed54fb3890 15.2 landed
- a02740e53fb7 14.7 landed
- 982b9b1eba8d 11.19 landed
- 92957ed98c5c 16.0 landed
- 19adcaf00f7d 13.10 landed
- 039567eb57ee 12.14 landed