Skip site navigation (1) Skip section navigation (2)

Re: [DOCS] Partition: use triggers instead of rules

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Michael Paesold" <mpaesold(at)gmx(dot)at>, "NikhilS" <nikkhils(at)gmail(dot)com>, "David Fetter" <david(at)fetter(dot)org>, "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>, "PostgreSQL Docs" <pgsql-docs(at)postgresql(dot)org>, "PostgreSQL Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [DOCS] Partition: use triggers instead of rules
Date: 2007-11-29 20:22:55
Message-ID: 87d4tser8g.fsf@oxford.xeocode.com (view raw or flat)
Thread:
Lists: pgsql-docspgsql-patches
"Joshua D. Drake" <jd(at)commandprompt(dot)com> 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!

In response to

Responses

pgsql-docs by date

Next:From: NikhilSDate: 2007-11-30 07:04:05
Subject: Re: [DOCS] Partition: use triggers instead of rules
Previous:From: Simon RiggsDate: 2007-11-29 19:11:00
Subject: Re: PITR Doc clarifications

pgsql-patches by date

Next:From: Tom LaneDate: 2007-11-29 21:11:55
Subject: Re: [GENERAL] Empty arrays with ARRAY[]
Previous:From: Martijn van OosterhoutDate: 2007-11-29 19:48:16
Subject: Re: [GENERAL] Empty arrays with ARRAY[]

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group