X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 5D5A79FA65C for ; Fri, 7 Jul 2006 04:51:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 60841-04 for ; Fri, 7 Jul 2006 04:51:40 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.195]) by postgresql.org (Postfix) with ESMTP id AD2A29FA634 for ; Fri, 7 Jul 2006 04:51:40 -0300 (ADT) Received: by nz-out-0102.google.com with SMTP id z3so1006669nzf for ; Fri, 07 Jul 2006 00:51:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type; b=P/X2hgqh1rjmUfQGbOCsq+p5aDuuT1896ZDblpkdeCw1gtA9j77a+E3BFumAczcT2QoOSHqbfTAIAp7S9YWIh4WfGmDy2IzKAUyojOtDE1WYtuKjPK4yFk+UNYXUf+uQSPUlxOKTdtcboyd74+CNXsbQv/NpOuqjS1V7BEJ01oE= Received: by 10.65.249.3 with SMTP id b3mr1768899qbs; Fri, 07 Jul 2006 00:51:38 -0700 (PDT) Received: by 10.65.114.11 with HTTP; Fri, 7 Jul 2006 00:51:38 -0700 (PDT) Message-ID: <430d92a20607070051k514e5325q87f434ccc666c01d@mail.gmail.com> Date: Fri, 7 Jul 2006 03:51:38 -0400 From: Gene Reply-To: genekhart@gmail.com To: pgsql-performance@postgresql.org Subject: Update INSERT RULE while running for Partitioning MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_44462_22743121.1152258698188" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/60 X-Sequence-Number: 19920 ------=_Part_44462_22743121.1152258698188 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_44462_22743121.1152258698188 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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
------=_Part_44462_22743121.1152258698188--