Re: Statistical aggregate functions are not working with PARTIALaggregation - Mailing list pgsql-hackers

From Kyotaro HORIGUCHI
Subject Re: Statistical aggregate functions are not working with PARTIALaggregation
Date
Msg-id 20190507.210624.72264416.horiguchi.kyotaro@lab.ntt.co.jp
Whole thread Raw
In response to Statistical aggregate functions are not working with PARTIAL aggregation  (Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>)
List pgsql-hackers
Hello.

At Tue, 7 May 2019 14:39:55 +0530, Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com> wrote in
<CAKcux6=YBMCntcafSs_22dS1ab6mGay_QUaHx-nvg+_FVPMg3Q@mail.gmail.com>
> Hi,
> As this issue is reproducible without partition-wise aggregate also,
> changing email subject from "Statistical aggregate functions are not
> working with partitionwise aggregate " to "Statistical aggregate functions
> are not working with PARTIAL aggregation".
> 
> original reported test case and discussion can be found at below link.
> https://www.postgresql.org/message-id/flat/CAKcux6%3DuZEyWyLw0N7HtR9OBc-sWEFeByEZC7t-KDf15FKxVew%40mail.gmail.com

The immediate reason for the behavior seems that
EEOP_AGG_STRICT_INPUT_CHECK_ARGS regards the non-existent second
argument as null.

The invalid deserialfn_oid case in ExecBuildAggTrans, it
initializes args[1] using the second argument of the functoin
(int8pl() in the case) so the correct numTransInputs here is 1,
not 2.

The attached patch makes at least the test case work correctly
and this seems to be the alone instance of the same issue.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center


diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 0fb31f5c3d..9f83dbe51e 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -3009,8 +3009,9 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
             {
                 /*
                  * Start from 1, since the 0th arg will be the transition
-                 * value
+                 * value. Exclude it from numTransInputs.
                  */
+                pertrans->numTransInputs--;
                 ExecInitExprRec(source_tle->expr, state,
                                 &trans_fcinfo->args[argno + 1].value,
                                 &trans_fcinfo->args[argno + 1].isnull);

pgsql-hackers by date:

Previous
From: Rajkumar Raghuwanshi
Date:
Subject: Statistical aggregate functions are not working with PARTIAL aggregation
Next
From: Daniel Gustafsson
Date:
Subject: Typos and wording in jsonpath-exec.c