Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id AE8A51337B4F for ; Mon, 6 Dec 2010 01:23:59 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 36433-04 for ; Mon, 6 Dec 2010 05:23:52 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id 4CFDC1336FA7 for ; Mon, 6 Dec 2010 01:23:52 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id oB65NqO6043343 for ; Mon, 6 Dec 2010 01:23:52 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id oB650EYY096897 for pgsql-performance@postgresql.org; Mon, 6 Dec 2010 01:00:14 -0400 (AST) (envelope-from news) From: John Papandriopoulos X-Newsgroups: pgsql.performance Subject: Re: Query-plan for partitioned UPDATE/DELETE slow and swaps vmem compared to SELECT Date: Sun, 05 Dec 2010 21:00:13 -0800 Organization: Hub.Org Networking Services Lines: 71 Message-ID: References: <14012.1291443654@sss.pgh.pa.us> <23792.1291480923@sss.pgh.pa.us> <13159.1291502400@sss.pgh.pa.us> <26275.1291568163@sss.pgh.pa.us> <29662.1291580078@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 In-Reply-To: <29662.1291580078@sss.pgh.pa.us> To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201012/58 X-Sequence-Number: 41510 On 12/5/10 12:14 PM, Tom Lane wrote: > I wrote: >> 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 ...) > > That worked better than I thought it would --- see > http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=d1001a78ce612a16ea622b558f5fc2b68c45ab4c > I'm not intending to back-patch this, but it ought to apply cleanly to > 9.0.x if you want it badly enough to carry a local patch. Fantastic, Tom! Thank you kindly for taking the time to create the patch. The memory issue has indeed disappeared---there was no noticeable memory increase in the three queries below, with 4096 children. Inheritance planning overhead is around 20x for UPDATE/DELETE compared to SELECT; thankfully they are required much less frequently in my case. I am still wondering whether the inheritance_planner(...) can be avoided if the rowtypes of children are the same as the parent? (I'm not yet sufficiently familiar with the source to determine on my own.) If that's the case, is there a simple test (like cardinality of columns) that can be used to differentiate partitioning from general inheritance cases? Thanks again! John Simple partitioning test timing with 4096 children: > $ echo "explain select * from ptest where id = 34324234; \q" | time -p psql ptest > QUERY PLAN > ---------------------------------------------------------------------------- > Result (cost=0.00..80.00 rows=24 width=4) > -> Append (cost=0.00..80.00 rows=24 width=4) > -> Seq Scan on ptest (cost=0.00..40.00 rows=12 width=4) > Filter: (id = 34324234) > -> Seq Scan on ptest_65 ptest (cost=0.00..40.00 rows=12 width=4) > Filter: (id = 34324234) > (6 rows) > > real 0.55 > user 0.00 > sys 0.00 > $ echo "explain delete from ptest where id = 34324234; \q" | time -p psql ptest > QUERY PLAN > ---------------------------------------------------------------------- > Delete (cost=0.00..80.00 rows=24 width=6) > -> Seq Scan on ptest (cost=0.00..40.00 rows=12 width=6) > Filter: (id = 34324234) > -> Seq Scan on ptest_65 ptest (cost=0.00..40.00 rows=12 width=6) > Filter: (id = 34324234) > (5 rows) > > real 10.47 > user 0.00 > sys 0.00 > $ echo "explain update ptest set id = 34324235 where id = 34324234; \q" | time -p psql ptest > QUERY PLAN > ---------------------------------------------------------------------- > Update (cost=0.00..80.00 rows=24 width=6) > -> Seq Scan on ptest (cost=0.00..40.00 rows=12 width=6) > Filter: (id = 34324234) > -> Seq Scan on ptest_65 ptest (cost=0.00..40.00 rows=12 width=6) > Filter: (id = 34324234) > (5 rows) > > real 9.53 > user 0.00 > sys 0.00 > $