Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3DC4F1337B8C for ; Sat, 4 Dec 2010 18:40:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 28608-06 for ; Sat, 4 Dec 2010 22:40:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E96191337B47 for ; Sat, 4 Dec 2010 18:40:00 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oB4Me0Eb013160; Sat, 4 Dec 2010 17:40:00 -0500 (EST) To: John Papandriopoulos cc: pgsql-performance@postgresql.org Subject: Re: Query-plan for partitioned UPDATE/DELETE slow and swaps vmem compared to SELECT In-reply-to: References: <14012.1291443654@sss.pgh.pa.us> <23792.1291480923@sss.pgh.pa.us> Comments: In-reply-to John Papandriopoulos message dated "Sat, 04 Dec 2010 13:34:28 -0800" Date: Sat, 04 Dec 2010 17:40:00 -0500 Message-ID: <13159.1291502400@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/45 X-Sequence-Number: 41497 John Papandriopoulos writes: > I set up my schema using a machine generated SQL file [1] that simply > creates a table > create table ptest ( id integer ); > and N = 0..4095 inherited children > create table ptest_N ( > check ( (id >= N_min) and (id <= N_max) ) > ) inherits (ptest); > that split the desired id::integer range into N buckets, one for each of > the N partitions. > I then immediately run a query-plan using EXPLAIN that exhibits the > described behavior: super-fast plan for a SELECT statement, without > swapping, and memory intensive (swapping) plans for DELETE and UPDATE. [ 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. It's difficult to do much better than that in the general case where the children might have different rowtypes from the parent: you need a distinct targetlist for each target relation. I expect that we can be a lot smarter when we have true partitioning support (which among other things is going to have to enforce that all the children have identical column sets). But the inheritance mechanism was never intended to scale to anything like this number of children. I remain of the opinion that you're using far too many child tables. Please note the statement at the bottom of http://www.postgresql.org/docs/9.0/static/ddl-partitioning.html: Partitioning using these techniques will work well with up to perhaps a hundred partitions; don't try to use many thousands of partitions. regards, tom lane