Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ejaHp-00029D-DI for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2018 00:42:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejaHo-0001bs-BP for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2018 00:42:00 +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 1ejaHo-0001bc-4b for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2018 00:42:00 +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.89) (envelope-from ) id 1ejaHg-00033i-EG for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2018 00:41:59 +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 w180fm2F010698; Wed, 7 Feb 2018 19:41:49 -0500 From: Tom Lane To: Peter Geoghegan cc: Aleksandr Parfenov , PostgreSQL Hackers Subject: Re: PostgreSQL crashes with SIGSEGV In-reply-to: References: <1512661638.9720.34.camel@oopsware.de> <151608914608.25640.2144132915573008595.pgcf@coridan.postgresql.org> <14267.1516216998@sss.pgh.pa.us> <4977.1516221082@sss.pgh.pa.us> <6358.1516222816@sss.pgh.pa.us> Comments: In-reply-to Peter Geoghegan message dated "Tue, 06 Feb 2018 14:27:47 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10696.1518050508.1@sss.pgh.pa.us> Date: Wed, 07 Feb 2018 19:41:48 -0500 Message-ID: <10697.1518050508@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan writes: > On Wed, Jan 17, 2018 at 2:23 PM, Peter Geoghegan wrote: >> A complicating factor for this fix of mine is that mode_final() seems >> to have its own ideas about tuple memory lifetime, over and above what >> tuplesort_getdatum() explicitly promises, as can be seen here: >> /* >> * Note: we *cannot* clean up the tuplesort object here, because the value >> * to be returned is allocated inside its sortcontext. We could use >> * datumCopy to copy it out of there, but it doesn't seem worth the >> * trouble, since the cleanup callback will clear the tuplesort later. >> */ >> ISTM that either grouping sets or mode_final() must necessarily be >> wrong, because each oversteps, and infers a different contract from >> tuplesort tuple fetching routines (different assumptions about memory >> contexts are made in each case). Only one can be right, unless it's >> okay to have one rule for tuplesort_getdatum() and another for >> tuplesort_gettupleslot() (which seems questionable to me). I still >> think that grouping sets is right (and that mode_final() is wrong). Do >> you? > It would be nice to get an opinion on this mode_final() + tuplesort > memory lifetime business from you, Tom. I'm fairly sure that that bit in mode_final() was just a hack to make it work. If there's a better, more principled way, let's go for it. > Note that you removed the quoted comment within be0ebb65, back in October. There were multiple instances of basically that same comment before. AFAICS I just consolidated them into one place, in the header comment for ordered_set_shutdown. regards, tom lane