From: Gene <genekhart@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Update INSERT RULE while running for Partitioning
Date: Fri, 7 Jul 2006 03:51:38 -0400
Message-ID: <430d92a20607070051k514e5325q87f434ccc666c01d@mail.gmail.com> (raw)
I'm using PostgreSQL 8.1.4 in a Hibernate Application and I am attempting to
use partitioning via Inherited tables. At first I was going to create a rule
per sub-table based on a date range, but found out with multiple rules
postgres will only return the affected-row count on the last rule which
gives Hibernate problems. So now I'm thinking the way to do it is just have
one rule at a time and when I want to start appending data to a new
partition, just change the rule on the parent table and also update the
constraint on the last table to reflect the date ranges contained so that
constraint_exclusion will work. this should perform better also. For
instance
Starting off with:
Parent (Rule on insert instead insert into Child2)
Child1 (Constraint date <= somedate1)
Child2 (Constraint date > somedate1)
Now I want to create another Partition:
Create Table Child3
BEGIN
Update Parent Rule( instead insert into Child3)
somedate2 = max(date) from Child2
Update Child2 Constraint( date > somedate1 AND date <= somedate2 )
Set Constraint Child3 (date > somedate2)
END
Which ends up with:
Parent (Rule on insert instead insert into Child2)
Child1 (Constraint date <= somedate1)
Child2 (Constraint date > somedate1 AND date <= somedate2)
Child3 (Constraint date > somedate2)
Anyone else tried this or expect it to work consistently (without stopping
db)? Is it possible that there could be a race condition for the insertion
and constraints or will the transaction prevent that from occurring? I've
done some testing and it seems to work but I could just get lucky so far and
not lose any data :)
Thanks for any help,
Gene
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: genekhart@gmail.com
Subject: Re: Update INSERT RULE while running for Partitioning
In-Reply-To: <430d92a20607070051k514e5325q87f434ccc666c01d@mail.gmail.com>
* 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