Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1goQ30-0005lt-0X for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jan 2019 09:51:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1goQ2y-0002CW-Fg for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jan 2019 09:51:12 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1goQ2y-00029p-3j for pgsql-hackers@lists.postgresql.org; Tue, 29 Jan 2019 09:51:12 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1goQ2w-0007LF-7b for pgsql-hackers@lists.postgresql.org; Tue, 29 Jan 2019 09:51:11 +0000 Received: by mail-wr1-x442.google.com with SMTP id r10so21234325wrs.10 for ; Tue, 29 Jan 2019 01:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ugUcy1YResoUdSViuVYKOS7gzEi4GZ7W0lEI1FmU9RU=; b=bxXlcP/5Ck8yczZaQMeuyjNdEdpN1ZV3SB/Zy0jWJBwEVrFk0Ipw6oltLJJYQIf8Kn rOElyu4/wjsHlRUqcykoj4PaAYhvTp3f9Q6kCwEE7OxXvis3CgG6tVKTqUlSvVuFltzT NcdYQgbQbyQa09E4tNRBml5RMOa4VZ6TvjMCynEXQIkIwk/uY8P++/QDScMKc6PhVLpQ jgJPR2GtUcVaFRCA+2A2svq+laTkS60Qa/2Is/JbL1ajSSOlgVS2PQhHa2Hze1oMNJMN wQaRhVleaFSqzenFwcmekLm/DoplRXXIC5/tHM77vKR5Lf+4mwx7/NM16Ppci4i+VM0G LTMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ugUcy1YResoUdSViuVYKOS7gzEi4GZ7W0lEI1FmU9RU=; b=oHOm/Hfyb6HVtnI8jpnNY788YLhaU1gKQuc62/WOyfKjpBp9MNlTSnvRJYLugCIYFD bZNt6iQo0stT8ceLl3us4UOBGT2a2Xrxw0ufvsvwTKLFCZIep6f4/EiEmaDQV9HCryKO TuYUok64LJV27TczzAYLjVwHU5zkFzX8+IwCne4M5V9ooYOtqL3quUOdsnzP1IQQ9L5k 6MEkHufjB/miwXzWTyXivztobzt3lIhVBAjMHA0AJnjkyUqlYtyW04M9KdYPlNeybS+m iDTlawTnJYdqAI1mxo7UWY4aWulEu+UHaxYSPOYrvxLXZiLVfm8lnD+6BGCdKDvsY5wS HtAw== X-Gm-Message-State: AJcUukcRi5ZJxVjBJPxvwtk2cKPMdeU3FCcMHPrMDEw1+dFPhoBzVxBu i78POxSd2qC0c1kZrA/jSzyQnRxXoZpr+QKKBUJ5TwJCYSu8mlCfACW413XorwNBjM18VaW0qEj M70SEshuJZgYyfU5CBKHmYTnXOjFsualeFHjYocDt1tZNL+r5RRuDGRACj/t/2GnTqdzYgop2at MFLZbp3tmccgOPio+e3+A= X-Google-Smtp-Source: ALg8bN7f6ZUqNQnrVIaiekQWHSm2oN2UvyMDzK6/V8miUbrUWlwgKTc8R1tk5cBcbeC/zjRaGP3Amg== X-Received: by 2002:adf:ba05:: with SMTP id o5mr24468526wrg.325.1548755468156; Tue, 29 Jan 2019 01:51:08 -0800 (PST) Received: from [10.137.2.19] (ip-86-49-245-195.net.upcbroadband.cz. [86.49.245.195]) by smtp.gmail.com with ESMTPSA id k15sm150482983wru.8.2019.01.29.01.51.07 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 01:51:07 -0800 (PST) Subject: Re: COPY FROM WHEN condition To: David Rowley Cc: Andres Freund , Surafel Temesgen , Alvaro Herrera , Adam Berlin , PostgreSQL Hackers References: <3b2b1aac-5861-acd8-fda3-054c4e4da888@2ndquadrant.com> <20190121012405.633row4iw7nfxz7h@alap3.anarazel.de> <6e80b7c1-58cd-4212-41d3-7c519aed0500@2ndquadrant.com> <20190121020805.3kdscvwzwvijlees@alap3.anarazel.de> <20190121021220.7tbu3oizvydov5by@alap3.anarazel.de> <52b10375-aca3-ea9b-10a1-2e4e9a011665@2ndquadrant.com> <20190121185102.m7keci23l7q6byou@alap3.anarazel.de> <0a3d8cff-0b9d-ea2e-634b-5dcb8d0d5766@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Tue, 29 Jan 2019 10:51:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/29/19 8:18 AM, David Rowley wrote: > On Wed, 23 Jan 2019 at 06:35, Tomas Vondra wrote: >> It turned out to be a tad more complex due to partitioning, because when >> we find the partitions do not match, the tuple is already allocated in >> the "current" context (be it per-tuple or batch). So we can't just free >> the whole context at that point. The old code worked around this by >> alternating two contexts, but that seems a bit too cumbersome to me, so >> the patch simply copies the tuple to the new context. That allows us to >> reset the batch context always, right after emptying the buffer. I need >> to do some benchmarking to see if the extra copy causes any regression. > > I agree that fixing the problem mentioned by separating out tuple and > batch contexts is a good idea, but I disagree with removing the > alternating batch context idea. FWIW the reason the alternating > contexts went in wasn't just for fun, it was on performance grounds. > There's a lengthy discussion in [1] about not adding any new > performance regressions to COPY. To be more specific, Peter complains > about a regression of 5% in [2]. > > It's pretty disheartening to see the work there being partially undone. > Whoops :-( > Here are my performance tests of with and without your change to the > memory contexts (I missed where you posted your results). > > $ cat bench.pl > for (my $i=0; $i < 8912891; $i++) { > print "1\n1\n2\n2\n"; > } > 36a1281f86c: (with your change) > > postgres=# copy listp from program $$perl ~/bench.pl$$ delimiter '|'; > COPY 35651564 > Time: 26825.142 ms (00:26.825) > Time: 27202.117 ms (00:27.202) > Time: 26266.705 ms (00:26.267) > > 4be058fe9ec: (before your change) > > postgres=# copy listp from program $$perl ~/bench.pl$$ delimiter '|'; > COPY 35651564 > Time: 25645.460 ms (00:25.645) > Time: 25698.193 ms (00:25.698) > Time: 25737.251 ms (00:25.737) > > So looks like your change slows this code down 4% for this test case. > That's about twice as bad as the 2.2% regression that I had to solve > for the multi-insert partition patch (of which you've removed much of > the code from) > > I'd really like to see the alternating batch context code being put > back in to fix this. Of course, if you have a better idea, then we can > look into that, but just removing code that was carefully written and > benchmarked without any new benchmarks to prove that it's okay to do > so seems wrong to me. > Yeah, that's not very nice. Do you suggest to revert 36a1281f86c0f, or shall we try to massage it a bit first? ISTM we could simply create two batch memory contexts and alternate those, just like with the expression contexts before. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services