pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: Partitioned tables in queries
Date: Fri, 21 Jul 2006 12:34:34 -0700
Message-ID: <76447686-0EB2-4482-B6A5-C7003BCF8DCE@blighty.com> (raw)
In-Reply-To: <44C12852.1040909@borderware.com>
References: <44C12852.1040909@borderware.com>


On Jul 21, 2006, at 12:17 PM, Kevin Keith wrote:

> I have a case where I am partitioning tables based on a date range  
> in version 8.1.4. For example:
>
> table_with_millions_of_records
> interaction_id  char(16) primary key
> start_date   timestamp (without timezone) - indexed
> .. other columns
>
> child_1   start_date >= 2006-07-21 00:00:00
> child_2   start_date >= 2006-07-20 00:00:00 and start_date <  
> 2006-07-21 00:00:00
> ...
> child_5   start_date >= 2006-07-17 00:00:00 and start_date <  
> 2006-07-18 00:00:00
>
> with rules on the parent and child tables that redirect the data to  
> the appropriate child table based on the start_date.
>
> Because this table is going to grow very large (very quickly), and  
> will need to be purged daily, I created partitions, or child tables  
> to hold data for each day. I have done the same thing in Oracle in  
> the past, and the PostgreSQL solution works great. The archival  
> process is very simple - drop the expired child table. I am having  
> one problem.
>
> If I run a query on the full table (there are 5 child tables with  
> data for the last 5 days), and my where clause contains data for  
> the current day only:
> where start_date > date_trunc('day', now())
> all 5 child tables are scanned when I look at the output from  
> explain analyze.
>
> My question is - can I force the planner to only scan the relevant  
> child table - when the key related to the partitioned data it part  
> of the where clause?

Yes. You'll need non-overlapping check constraints in each child  
table and to set constraint_exclusion to "on" in postgresql.conf.

See http://www.postgresql.org/docs/8.1/static/ddl-partitioning.html  
for the gory details.

Cheers,
   Steve



view thread (4+ messages)  latest in thread

Message-ID: <76447686-0EB2-4482-B6A5-C7003BCF8DCE@blighty.com>
Permalink:  ../76447686-0EB2-4482-B6A5-C7003BCF8DCE@blighty.com/
Also on:    postgresql.org/message-id/76447686-0EB2-4482-B6A5-C7003BCF8DCE@blighty.com

 · 

reply

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: steve@blighty.com
  Subject: Re: Partitioned tables in queries
  In-Reply-To: <76447686-0EB2-4482-B6A5-C7003BCF8DCE@blighty.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