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 1hUBBa-0000Y3-Ne for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2019 14:28:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hUBBZ-0001jp-DJ for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2019 14:28:41 +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 1hUBBZ-0001jN-4r for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2019 14:28:41 +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 1hUBBW-0002v5-TJ for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2019 14:28:40 +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 x4OESNk2006015; Fri, 24 May 2019 10:28:23 -0400 From: Tom Lane To: Joe Conway cc: David Rowley , Amit Langote , 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> Comments: In-reply-to Joe Conway message dated "Fri, 24 May 2019 10:17:21 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6013.1558708103.1@sss.pgh.pa.us> Date: Fri, 24 May 2019 10:28:23 -0400 Message-ID: <6014.1558708103@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Joe Conway writes: > On 5/24/19 9:33 AM, David Rowley wrote: >> For it to have regressed it would have had to once have been better, >> but where was that mentioned? The only thing I saw was >> non-partitioned tables compared to partitioned tables, but you can't >> really say it's a regression if you're comparing apples to oranges. > I have very successfully used multiple hundreds and even low thousands > of partitions without running out of memory under the older inheritance > based "partitioning", and declarative partitioning is supposed to be > (and we have advertised it to be) better, not worse, isn't it? Have you done the exact thing described in the test case? I think that's going to be quite unpleasantly memory-intensive in any version. The real issue here is that we have designed around the assumption that MessageContext will be used to parse and plan one single statement before being reset. The described usage breaks that assumption. No matter how memory-efficient any one statement is or isn't, if you throw enough of them at the backend without giving it a chance to reset MessageContext, it won't end well. So my thought, if we want to do something about this, is not "find some things we can pfree at the end of planning" but "find a way to use a separate context for each statement in the query string". Maybe multi-query strings could be handled by setting up a child context of MessageContext (after we've done the raw parsing there and determined that indeed there are multiple queries), running parse analysis and planning in that context, and resetting that context after each query. regards, tom lane