Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3vok-000376-Uz for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 03:11:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e3vok-0005ZO-Bx for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 03:11:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3voj-0005Wk-F8 for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 03:11:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3vof-0002PS-C2 for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 03:11:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v9G3BBpC011028; Sun, 15 Oct 2017 23:11:11 -0400 From: Tom Lane To: David Rowley cc: Heikki Linnakangas , Lukas Eder , PostgreSQL mailing lists Subject: Re: Combination of ordered-set aggregate function terminates JDBC connection on PostgreSQL 9.6.5 In-reply-to: <29149.1507826092@sss.pgh.pa.us> References: <23270.1507751492@sss.pgh.pa.us> <3802.1507775225@sss.pgh.pa.us> <748.1507820150@sss.pgh.pa.us> <29149.1507826092@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 12 Oct 2017 12:34:52 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <11008.1508123436.0@sss.pgh.pa.us> Date: Sun, 15 Oct 2017 23:11:11 -0400 Message-ID: <11027.1508123471@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11008.1508123436.1@sss.pgh.pa.us> I wrote: > BTW ... I was quite surprised to notice that the aggdirectargs > are treated as a property that has to be matched in order to > combine transition states. They aren't used during the transition > phase, so this seems like a pointless constraint. We could move > the aggdirectargs ExprState list to AggStatePerAggData and treat > the aggdirectargs as part of the finalfn-related data, instead. Here's a pretty-lightly-tested patch for that. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="direct-args-are-not-transition-state.patch"; charset="us-ascii" Content-ID: <11008.1508123436.2@sss.pgh.pa.us> Content-Description: direct-args-are-not-transition-state.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 807822b..8f5f7f1 100644 *** a/src/backend/executor/nodeAgg.c --- b/src/backend/executor/nodeAgg.c *************** typedef struct AggStatePerTransData *** 260,272 **** bool aggshared; =20=20 /* - * Nominal number of arguments for aggregate function. For plain aggs, - * this excludes any ORDER BY expressions. For ordered-set aggs, this - * counts both the direct and aggregated (ORDER BY) arguments. - */ - int numArguments; -=20 - /* * Number of aggregated input columns. This includes ORDER BY expressio= ns * in both the plain-agg and ordered-set cases. Ordered-set direct args * are not counted, though. --- 260,265 ---- *************** typedef struct AggStatePerTransData *** 300,308 **** /* Oid of state value's datatype */ Oid aggtranstype; =20=20 ! /* ExprStates of the FILTER and argument expressions. */ ! ExprState *aggfilter; /* state of FILTER expression, if any */ ! List *aggdirectargs; /* states of direct-argument expressions */ =20=20 /* * fmgr lookup data for transition function or combine function. Note in --- 293,300 ---- /* Oid of state value's datatype */ Oid aggtranstype; =20=20 ! /* ExprState for the FILTER expression, if any. */ ! ExprState *aggfilter; =20=20 /* * fmgr lookup data for transition function or combine function. Note in *************** typedef struct AggStatePerAggData *** 442,447 **** --- 434,442 ---- */ int numFinalArgs; =20=20 + /* ExprStates for any direct-argument expressions */ + List *aggdirectargs; +=20 /* * We need the len and byval info for the agg's result data type in order * to know how to copy/delete values. *************** finalize_aggregate(AggState *aggstate, *** 1526,1532 **** * for the transition state value. */ i =3D 1; ! foreach(lc, pertrans->aggdirectargs) { ExprState *expr =3D (ExprState *) lfirst(lc); =20=20 --- 1521,1527 ---- * for the transition state value. */ i =3D 1; ! foreach(lc, peragg->aggdirectargs) { ExprState *expr =3D (ExprState *) lfirst(lc); =20=20 *************** ExecInitAgg(Agg *node, EState *estate, i *** 3293,3298 **** --- 3288,3297 ---- else peragg->numFinalArgs =3D numDirectArgs + 1; =20=20 + /* Initialize any direct-argument expressions */ + peragg->aggdirectargs =3D ExecInitExprList(aggref->aggdirectargs, + (PlanState *) aggstate); +=20 /* * build expression trees using actual argument & result types for the * finalfn, if it exists and is required. *************** build_pertrans_for_aggref(AggStatePerTra *** 3605,3615 **** =20=20 } =20=20 ! /* Initialize the input and FILTER expressions */ pertrans->aggfilter =3D ExecInitExpr(aggref->aggfilter, (PlanState *) aggstate); - pertrans->aggdirectargs =3D ExecInitExprList(aggref->aggdirectargs, - (PlanState *) aggstate); =20=20 /* * If we're doing either DISTINCT or ORDER BY for a plain agg, then we --- 3604,3612 ---- =20=20 } =20=20 ! /* Initialize the FILTER expression */ pertrans->aggfilter =3D ExecInitExpr(aggref->aggfilter, (PlanState *) aggstate); =20=20 /* * If we're doing either DISTINCT or ORDER BY for a plain agg, then we *************** find_compatible_peragg(Aggref *newagg, A *** 3793,3799 **** newagg->aggstar !=3D existingRef->aggstar || newagg->aggvariadic !=3D existingRef->aggvariadic || newagg->aggkind !=3D existingRef->aggkind || - !equal(newagg->aggdirectargs, existingRef->aggdirectargs) || !equal(newagg->args, existingRef->args) || !equal(newagg->aggorder, existingRef->aggorder) || !equal(newagg->aggdistinct, existingRef->aggdistinct) || --- 3790,3795 ---- *************** find_compatible_peragg(Aggref *newagg, A *** 3803,3809 **** /* if it's the same aggregate function then report exact match */ if (newagg->aggfnoid =3D=3D existingRef->aggfnoid && newagg->aggtype =3D=3D existingRef->aggtype && ! newagg->aggcollid =3D=3D existingRef->aggcollid) { list_free(*same_input_transnos); *same_input_transnos =3D NIL; --- 3799,3806 ---- /* if it's the same aggregate function then report exact match */ if (newagg->aggfnoid =3D=3D existingRef->aggfnoid && newagg->aggtype =3D=3D existingRef->aggtype && ! newagg->aggcollid =3D=3D existingRef->aggcollid && ! equal(newagg->aggdirectargs, existingRef->aggdirectargs)) { list_free(*same_input_transnos); *same_input_transnos =3D NIL; ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--