Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id D6F222E0073; Thu, 29 Nov 2007 16:23:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 79502-01; Thu, 29 Nov 2007 16:23:01 -0400 (AST) Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id 569892E367E; Thu, 29 Nov 2007 16:23:01 -0400 (AST) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1IxpuS-0001Pn-05; Thu, 29 Nov 2007 20:22:56 +0000 To: "Joshua D. Drake" Cc: "Tom Lane" , "Michael Paesold" , "NikhilS" , "David Fetter" , "Jonah H. Harris" , "PostgreSQL Docs" , "PostgreSQL Patches" Subject: Re: [DOCS] Partition: use triggers instead of rules In-Reply-To: <20071129095233.67f2b913@commandprompt.com> (Joshua D. Drake's message of "Thu\, 29 Nov 2007 09\:52\:33 -0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.patches" 3243) References: <20071128202615.GG24146@fetter.org> <21686.1196283184@sss.pgh.pa.us> <36e682920711281858x9a37039sa104036bf025de41@mail.gmail.com> <20071129031702.GU24146@fetter.org> <2854.1196315753@sss.pgh.pa.us> <20071128224154.06f950c9@commandprompt.com> <474EDAE2.3010705@gmx.at> <474EE25E.3080304@commandprompt.com> <14455.1196353045@sss.pgh.pa.us> <474EE992.2050209@commandprompt.com> <87zlwxj7xu.fsf@oxford.xeocode.com> <20071129091359.206fd8f2@commandprompt.com> <87ve7lj6y8.fsf@oxford.xeocode.com> <20071129095233.67f2b913@commandprompt.com> From: Gregory Stark Organization: EnterpriseDB Date: Thu, 29 Nov 2007 20:22:55 +0000 Message-ID: <87d4tser8g.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/300 X-Sequence-Number: 4541 "Joshua D. Drake" writes: > If you have lots of data it doesn't mean you are modifying lots of > data. It sure can. How do you modify lots of data if you *don't* have lots data in the first place? Certainly it doesn't mean you necessarily are, some databases are OLTP which do no large updates. But data warehouses with oodles of data also often have to do large updates or deletions. > I don't think anyone here (good lord I hope not) would say that firing > a trigger over 500k rows is fast. Instead you should likely just work the data > outside the partition and then move it directly into the target > partition. Well you don't even have to do that. You can issue the updates directly against the partitions. In fact, that's precisely what the rules effectively do... Rules rewrite the query to be a query directly against the partitions. Come to think of it I think there actually is a correct way to use rules which wouldn't suffer from the problems that have come up. Instead of putting a WHERE clause on the rule just expand deletes and updates to expand to deletes and updates against *all* partitions. Then let constraint_exclusion kick in to narrow down which partitions should actually receive the updates and deletes. I think triggers are the only solution for insert though. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support!