From: Tom Lane <tgl@sss.pgh.pa.us>
To: John Papandriopoulos <dr.jpap@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query-plan for partitioned UPDATE/DELETE slow and swaps vmem compared to SELECT
Date: Sun, 05 Dec 2010 11:56:03 -0500
Message-ID: <26275.1291568163@sss.pgh.pa.us> (raw)
In-Reply-To: <idfrnv$2bc$1@news.hub.org>
References: <idbo6g$92r$1@news.hub.org>
<14012.1291443654@sss.pgh.pa.us>
<idd14l$a4u$1@news.hub.org>
<23792.1291480923@sss.pgh.pa.us>
<idec54$2hpd$1@news.hub.org>
<13159.1291502400@sss.pgh.pa.us>
<idfrnv$2bc$1@news.hub.org>
John Papandriopoulos <dr.jpap@gmail.com> writes:
> On 12/4/10 2:40 PM, Tom Lane wrote:
>> [ pokes at that for a bit ... ] Ah, I had forgotten that UPDATE/DELETE
>> go through inheritance_planner() while SELECT doesn't. And
>> inheritance_planner() makes a copy of the querytree, including the
>> already-expanded range table, for each target relation. So the memory
>> usage is O(N^2) in the number of child tables.
> Thanks for the pointer to the code and explanation.
> In inheritance_planner(...) I see the memcpy of the input query tree, but for my example constraint exclusion would only result in one child being included. Or is the O(N^2) memory usage from elsewhere?
It's copying the whole range table, even though any one child query only
needs one of the child table entries. There might be some way to
finesse that, but it's not clear how else to end up with a final plan
tree in which each child table has the correct RT index number.
You could get rid of the memory growth, at the cost of a lot of
tree-copying, by doing each child plan step in a discardable memory
context. I'm not sure that'd be a win for normal sizes of inheritance
trees though --- you'd need to copy the querytree in and then copy the
resulting plantree out again, for each child. (Hm, but we're doing the
front-end copy already ...)
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, dr.jpap@gmail.com
Subject: Re: Query-plan for partitioned UPDATE/DELETE slow and swaps vmem compared to SELECT
In-Reply-To: <26275.1291568163@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox