Re: Excessive memory usage in multi-statement queries w/ partitioning - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Excessive memory usage in multi-statement queries w/ partitioning
Date
Msg-id 6014.1558708103@sss.pgh.pa.us
Whole thread Raw
In response to Re: Excessive memory usage in multi-statement queries w/ partitioning  (Joe Conway <mail@joeconway.com>)
Responses Re: Excessive memory usage in multi-statement queries w/ partitioning  (Joe Conway <mail@joeconway.com>)
Re: Excessive memory usage in multi-statement queries w/ partitioning  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
List pgsql-hackers
Joe Conway <mail@joeconway.com> 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



pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: initdb recommendations
Next
From: Peter Eisentraut
Date:
Subject: Re: [HACKERS] Runtime Partition Pruning