Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buavH-0006Cw-PF for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Oct 2016 07:59:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1buavH-00033a-38 for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Oct 2016 07:59:27 +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 1buavG-000331-4C for pgsql-bugs@postgresql.org; Thu, 13 Oct 2016 07:59:26 +0000 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1buavC-0006xo-Gy for pgsql-bugs@postgresql.org; Thu, 13 Oct 2016 07:59:24 +0000 Received: by mail-lf0-x234.google.com with SMTP id x79so125818215lff.0 for ; Thu, 13 Oct 2016 00:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=oemDNAuFL6FVQAYJUWJlptyMH/QxH/5drYI1PV9velI=; b=bLZ02veHx0iBaIV/jJWTzi0dRpnSeUPztsOkv40L7qdS/HPqW4kDVeeOiPP5IaGQiv 1oTdf4vE1DJYhRzg211uaWNnheTsQpVqsno1C/KayICFlllgYZEvWAJ1GvE2B52HnB+W F3ga6FxMXHxTQN1EfQkfkc3yDmY8dEY0d7mPR1hB5hHBUbG0dcf5fT7K2yBIeXuu3EQD XEtJI+tJAfS/Wm1ZmsRIZdYYtg5zTznKr+HGN+YC3pITiljJPBjri2k41l8FOjT9oHbO sZABKWKCy4DujI2FGTMAfWI2mQSbvvnbfEVYNgxruxU0yP2p45v6s69J80sOCW8pq7Mn LzVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=oemDNAuFL6FVQAYJUWJlptyMH/QxH/5drYI1PV9velI=; b=Z/QDWuVE1firEk8e1wg4c85JlMS86Pxsvzy3vAHILrmse32tmqoSTOodTZ/MpByDxo BdLA6YextIBxI/deSqVAvv/aAGNVhAu0FTRUz/q7yhVj+otqblTR/HF2VxpxDofVyrSK AMsqkmqQ+RvNc8hoWbKRXC5md4pKDDkXtcqKLNzYKzZzKJVUza4bky0KDmhSNFbSvPNw grOqObDVGsZku++HEyuJk3w5jvmg8TLEdL5siS/wGwvnbXPiirkV3EBtX51NTNrHz2r3 nUu67H3lS6VsjeRQ9k2dxv/xy76cabb7gfm/AJLgOvy58sUOIyteF66WzPvMTY9vVfWg DNNA== X-Gm-Message-State: AA6/9RnY6juacfj1S3xXfwIYP+pkDCKv3vK+Aca6iHYeuX+3e29VYy3ljO0dFECh0pa5UQ== X-Received: by 10.25.221.20 with SMTP id u20mr7752757lfg.1.1476345561372; Thu, 13 Oct 2016 00:59:21 -0700 (PDT) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id 102sm3235982lft.33.2016.10.13.00.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Oct 2016 00:59:20 -0700 (PDT) Subject: Re: BUG #14344: string_agg(DISTINCT ..) crash To: Peter Geoghegan References: <20160929035538.20224.39628@wrigleys.postgresql.org> <22270.1475163646@sss.pgh.pa.us> Cc: Tom Lane , David Rowley , Michael Paquier , Robert Haas , Regina Obe , PostgreSQL mailing lists From: Heikki Linnakangas Message-ID: <5b2d9da9-d2a9-ee53-aab4-1112f8dcf072@iki.fi> Date: Thu, 13 Oct 2016 10:59:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 On 10/13/2016 03:02 AM, Peter Geoghegan wrote: > On Wed, Oct 12, 2016 at 4:36 PM, Peter Geoghegan wrote: >> This fix has us copy the MinimalTuple into sortcontext palloc() memory >> within tuplesort_gettupleslot() (based on commit 25bf7f8b). This still >> differs a little from tuplestore_gettupleslot(), which explicitly uses >> current context of caller, but we've always done things that way for >> tuplesort.c. > > Actually, it's only true that tuplesort sortcontext context is used > when copy isn't needed, which is not predictable to caller, so the new > comment is a bit inaccurate. The inconsistency seems inconsequential, > since we've always assume that caller tuples allocated within > sortcontext may be "owned" by caller (when should_free = true), > despite not being in caller's own memory context. > > Attached is revision with tiny tweak to relevant comment. Hmm. That also adds a copy to the sorted-in-mem case. That's safe, but should we be worried about performance. Or is the extra copy so cheap that it doesn't matter? We could easily also check for TSS_SORTEDINMEM, if that matters. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs