Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E5D07633D61 for ; Thu, 4 Mar 2010 18:40:14 -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 62056-10 for ; Thu, 4 Mar 2010 22:39:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158]) by mail.postgresql.org (Postfix) with ESMTP id 17655633D4E for ; Thu, 4 Mar 2010 18:40:03 -0400 (AST) Received: by fg-out-1718.google.com with SMTP id l26so920500fgb.1 for ; Thu, 04 Mar 2010 14:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=28h4QUWNcyxbDyfbbb3z5zQdbl4biHB43Cm4aTbO9cE=; b=mlgP810a59wSHoSvYypdLRIlHNJqobZqv+UH3DlG7v3B78yS4OQpm2VXU+KHHB2Ycf ZohjQkA0B1iJeqbEq8mu8WbYkbqzbCrcP7c8f1GJeWHcWXoqHMRLZd0z71KEfQzWn8dW 6p2dUV8qSLFr/qFmP5cTZDgJYePanZuYysE3Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=vLYNowYyN2HwQKjpNPyLukeSzefc3omWQKHPGVNaQ9GXtTdNLUapB0qC8RDVp+i3hw FnaXOvCFY9de47CkdRN9k28YkwTTBGyYT/m4h0oSHC1hYgp3Dx97NTg8d0ei2Mkektyd ioELIXYvDJodm+xsD6e/gWg+LlXdC74TM3Hxk= MIME-Version: 1.0 Received: by 10.239.135.78 with SMTP id c14mr991566hbc.9.1267742402311; Thu, 04 Mar 2010 14:40:02 -0800 (PST) In-Reply-To: References: Date: Thu, 4 Mar 2010 17:40:02 -0500 Message-ID: <603c8f071003041440r2ec69a9dw91153f35ab2b3d53@mail.gmail.com> Subject: Re: partition pruning From: Robert Haas To: Anj Adu Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.381 tagged_above=-10 required=5 tests=AWL=0.062, BAYES_00=-2.599, SUBJECT_FUZZY_TION=0.156 X-Spam-Level: X-Archive-Number: 201003/67 X-Sequence-Number: 37892 On Mon, Mar 1, 2010 at 2:29 PM, Anj Adu wrote: > When I use intervals in my query e.g =A0col1 between current_timestamp - > interval '10 days' and current_timestamp...the optimizer checks ALL > partitions =A0whereas if I use =A0 col1 between 2 hardcoded dates..only > the applicable partitions are scanned. Yep. This is one example of a more general principle: constant-folding happens before planning, but anything more complex has to wait until execution time. So the plan can't take into account the value of current_timestamp in forming the plan. Unfortunately I don't think there's really any easy way around this: you have to do select current_timestamp, current_timestamp - interval '10 days' first and then build & execute a new query. ...Robert