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 1hkb4V-0000lr-Cj for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2019 21:21:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hkb4U-00063q-8L for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2019 21:21:14 +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 1hkb4T-00063X-V7 for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2019 21:21:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkb4N-0005Fi-Bn for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2019 21:21:13 +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 x68LKp2A003605; Mon, 8 Jul 2019 17:20:51 -0400 From: Tom Lane To: Amit Langote cc: Julien Rouhaud , Amit Langote , Joe Conway , David Rowley , Andreas Seltenreich , PostgreSQL Hackers Subject: Re: Excessive memory usage in multi-statement queries w/ partitioning In-reply-to: References: <87ftp6l2qr.fsf@credativ.de> <0e717312-3a02-781b-7dfc-e0cc395e92d8@joeconway.com> <6014.1558708103@sss.pgh.pa.us> <3ed13306-ba63-f2e8-1eeb-63b0e4f377e6@lab.ntt.co.jp> <65092.1558961789@sss.pgh.pa.us> <4bea720a-4310-36e9-b6ae-886669bceeef@lab.ntt.co.jp> Comments: In-reply-to Amit Langote message dated "Mon, 08 Jul 2019 17:52:20 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3603.1562620851.1@sss.pgh.pa.us> Date: Mon, 08 Jul 2019 17:20:51 -0400 Message-ID: <3604.1562620851@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > [ parse-plan-memcxt_v2.patch ] I got around to looking at this finally. I'm not at all happy with the fact that it's added a plantree copy step to the only execution path through exec_simple_query. That's a very significant overhead, in many use-cases, to solve something that nobody had complained about for a couple of decades before now. I don't see the need for any added copy step anyway. The only reason you're doing it AFAICS is so you can release the per-statement context a bit earlier, which is a completely unnecessary optimization. Just wait to release it till the bottom of the loop. Also, creating/deleting the sub-context is in itself an added overhead that accomplishes exactly nothing in the typical case where there's not multiple statements. I thought the idea was to do that only if there was more than one raw parsetree (or, maybe better, do it for all but the last parsetree). To show that this isn't an empty concern, I did a quick pgbench test. Using a single-client select-only test ("pgbench -S -T 60" in an -s 10 database), I got these numbers in three trials with HEAD: tps = 9593.818478 (excluding connections establishing) tps = 9570.189163 (excluding connections establishing) tps = 9596.579038 (excluding connections establishing) and these numbers after applying the patch: tps = 9411.918165 (excluding connections establishing) tps = 9389.279079 (excluding connections establishing) tps = 9409.350175 (excluding connections establishing) That's about a 2% dropoff. Now it's possible that that can be explained away as random variations from a slightly different layout of critical loops vs cacheline boundaries ... but I don't believe it. regards, tom lane