Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2TDW-0003HA-Fd for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 02:27:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e2TDW-0002ZM-2E for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 02:27:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2TDV-0002Sw-4I for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 02:27:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2TDS-00061d-GB for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 02:27:19 +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 v9C2R54P003803; Wed, 11 Oct 2017 22:27:05 -0400 From: Tom Lane To: David Rowley cc: Lukas Eder , PostgreSQL mailing lists , Heikki Linnakangas Subject: Re: Combination of ordered-set aggregate function terminates JDBC connection on PostgreSQL 9.6.5 In-reply-to: References: <23270.1507751492@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 12 Oct 2017 10:17:43 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3801.1507775225.1@sss.pgh.pa.us> Date: Wed, 11 Oct 2017 22:27:05 -0400 Message-ID: <3802.1507775225@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 David Rowley writes: > On 12 October 2017 at 08:51, Tom Lane wrote: >> However, in order to make use of tuplesort_rescan, we'd have had >> to pass randomAccess = true to tuplesort_begin_xxx, which would >> be rather an annoying overhead for the majority case where there >> isn't a potential for reuse. > Yeah maybe if core tracked the total number of references in > AggStatePerTrans, and finalize_aggregate() incremented another counter > to track how many times the final function had been called on this > state, then if there was some way to expose that information to the > final function, it would know if it was the first or the last final > function to use the state. That seems kind of irrelevant, at least for the existing OSAs. To know what value of randomAccess to pass to the tuplesort setup, we have to know *at the first transition-function call* whether there may be multiple final-function calls coming up. So what what I'm imagining is a simple boolean result "yes, there will be only one finalfn call, so it can destructively modify the transition state", or "there might be more than one finalfn call, so the finalfn(s) must preserve transition state". And this info has to be available throughout the aggregate run. >> This might be a bigger change than we want to push into the back >> branches. In that case probably a back-patchable fix is to hack >> nodeAgg.c so it will never combine input states for OSAs. > I've attached a patch which does this. Needs to reject plain OSAs too, not just hypotheticals. Pushed with that fix and some test cases. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs