Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1EFAE636238 for ; Tue, 20 Jul 2010 12:55:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 49424-02 for ; Tue, 20 Jul 2010 15:55:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.afilias.info (outbound.afilias.info [69.46.124.26]) by mail.postgresql.org (Postfix) with ESMTP id BF70F636213 for ; Tue, 20 Jul 2010 12:55:32 -0300 (ADT) Received: from ms6.yyz2.afilias-ops.info ([10.50.129.112] helo=smtp.afilias.info) by outbound.afilias.info with esmtp (Exim 4.69) (envelope-from ) id 1ObFAJ-00068x-7M; Tue, 20 Jul 2010 15:55:31 +0000 Received: from tor-gateway.afilias.info ([199.15.87.4] helo=[10.10.46.12]) by smtp.afilias.info with esmtps (SSLv3:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1ObFAJ-00045z-6q; Tue, 20 Jul 2010 15:55:31 +0000 Subject: Re: dates and partitioning From: Brad Nicholson To: Kevin Kempter Cc: pgsql-performance@postgresql.org In-Reply-To: <201007200936.07736.cs_dba@consistentstate.com> References: <201007200936.07736.cs_dba@consistentstate.com> Content-Type: text/plain; charset="UTF-8" Date: Tue, 20 Jul 2010 11:55:30 -0400 Message-ID: <1279641330.15825.91.camel@bnicholson-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.311 tagged_above=-10 required=5 tests=BAYES_40=-0.001, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/290 X-Sequence-Number: 39679 On Tue, 2010-07-20 at 09:36 -0600, Kevin Kempter wrote: > Hi All; > > we have a table partitioned by day, the check constraint on the child tables > looks like this (this is the may 31st partition): > > CHECK > (stime >= '2010-05-30 00:00:00+00'::timestamp with time zone > AND stime <= '2010-05-30 23:59:59+00'::timestamp with time zone) > > > We have a python based app that creates code like this: > > select > * > from > table_a a, > table_b b, > table_d d > where a.id = b.id > and b.id = d.id > and stime >= timestamp %s at time zone \'UTC\' > and stime < timestamp %s at time zone \'UTC\' > and stime >= timestamp %s at time zone d.name > and stime < timestamp %s at time zone d.name > ... > > > so here's my questions: > > 1) the above app generated query pshows up like this in pg_stat_activity: > > and stime >= timestamp E'2010-07-17' at time zone 'UTC' > and stime < timestamp E'2010-07-21' at time zone 'UTC' > and stime >= timestamp E'2010-07-18' at time zone d.name > and stime < timestamp E'2010-07-19' at time zone d.name > > what's the E'date' from? and why does it show up this way? That's E is an escape character. Python is likely putting that in. See http://www.postgresql.org/docs/8.4/static/sql-syntax-lexical.html - section 4.1.2.2 > > 2) the above query creates a plan that does a sequential scan & filter on > every partition. Why won't it only hit the correct partitions? Is it due to > the way the date was specified? or maybe the "at time zone" syntax? Do you have constraint_exclusion turned on? -- Brad Nicholson 416-673-4106 Database Administrator, Afilias Canada Corp.