pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-performance@postgresql.org
Subject: Re: partitioned tables query not using indexes
Date: Wed, 24 Feb 2010 15:55:36 +0100
Message-ID: <20100224145536.GM22249@a-kretschmer.de> (raw)
In-Reply-To: <201002240736.36341.kevink@consistentstate.com>
References: <201002240736.36341.kevink@consistentstate.com>

In response to Kevin Kempter :
> Hi All;
> 
> I have a table that has daily partitions. 
> 
> The check constraints look like this:
> CHECK (timezone('EST'::text, insert_dt) >= '2010-01-01'::date 
> AND timezone('EST'::text, insert_dt) < '2010-01-02'::date)
> 
> each partition has this index:
>     "fact_idx1_20100101_on_cust_id" btree (cust_id)
> 
> If I run an explain hitting an individual partition I get an index scan:
> 
> explain select distinct cust_id from children.fact_20100101;
> 
>               QUERY PLAN                                                      
> --------------------------------------------------------------------------------------------------------------
>  Unique  (cost=0.00..136891.18 rows=70296 width=38)
>    ->  Index Scan using fact_idx1_20100101_on_cust_id on fact_20100101  
> (cost=0.00..133112.0
> 
> 
> 
> 
> 
> However the same query against the base table when specifying the check 
> constraint key in the where clause produces sequential scans:

Have you set constraint_exclusion = on?



> 
> 
> explain  select distinct cust_id from fact 
> where timezone('EST'::text, insert_dt) between  '2010-01-01'::date 
> and '2010-01-02'::date;

Can you show the table definition? I'm not sure about the
timezone()-function and index...

Maybe you should try to rewrite your code to:

between  '2010-01-01 00:00'::timestamp and ...


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99



view thread (6+ messages)  latest in thread

Message-ID: <20100224145536.GM22249@a-kretschmer.de>
Permalink:  ../20100224145536.GM22249@a-kretschmer.de/
Also on:    postgresql.org/message-id/20100224145536.GM22249@a-kretschmer.de

 · 

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: andreas.kretschmer@schollglas.com
  Subject: Re: partitioned tables query not using indexes
  In-Reply-To: <20100224145536.GM22249@a-kretschmer.de>

* 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