Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 6D81A632F87 for ; Wed, 24 Feb 2010 10:55:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 47230-01 for ; Wed, 24 Feb 2010 14:55:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by mail.postgresql.org (Postfix) with ESMTP id 4E375632387 for ; Wed, 24 Feb 2010 10:55:45 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0Ll1qT-1N9rIq1Hoj-00aez7; Wed, 24 Feb 2010 15:55:37 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1NkIeG-0007ul-00 for pgsql-performance@postgresql.org; Wed, 24 Feb 2010 15:55:36 +0100 Date: Wed, 24 Feb 2010 15:55:36 +0100 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: partitioned tables query not using indexes Message-ID: <20100224145536.GM22249@a-kretschmer.de> References: <201002240736.36341.kevink@consistentstate.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201002240736.36341.kevink@consistentstate.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1/j672MbM02+sWlI3L0BZ8PZT5zWjkLc5mjlgF J0SvvzuP3eE0HJTRKGdGAqO8y5vZmy6lSUxo16TuYAoRSbvUyC gy29BZ1i5TmC3g/lIhQfQ== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.993 tagged_above=-10 required=5 tests=AWL=-0.409, BAYES_20=-0.74, SUBJECT_FUZZY_TION=0.156 X-Spam-Level: X-Archive-Number: 201002/342 X-Sequence-Number: 37763 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