Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 65643B5DC29 for ; Wed, 21 Sep 2011 23:09:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 54473-04 for ; Thu, 22 Sep 2011 02:09:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id A874AB5DC1A for ; Wed, 21 Sep 2011 23:09:23 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8M29LRu006769; Wed, 21 Sep 2011 22:09:21 -0400 (EDT) To: Greg Smith cc: pgsql-performance@postgresql.org Subject: Re: Query optimization using order by and limit In-reply-to: <4E7A93F9.1050301@2ndQuadrant.com> References: <4E7A93F9.1050301@2ndQuadrant.com> Comments: In-reply-to Greg Smith message dated "Wed, 21 Sep 2011 21:48:41 -0400" Date: Wed, 21 Sep 2011 22:09:21 -0400 Message-ID: <6768.1316657361@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/341 X-Sequence-Number: 45117 Greg Smith writes: > That weird casting can't be helping. I'm not sure if it's your problem > here, but the constraint exclusion code is pretty picky about matching > the thing you're looking for against the CHECK constraint, and this is a > messy one. The bigint conversion in the middle there isn't doing > anything useful for you anyway; you really should simplify this to just > look like this: > firstloadtime >= 129604464000000000::numeric I have a more aggressive suggestion: change all the numeric(20,0) fields to bigint. Unless the OP actually needs values wider than 64 bits, the choice to use numeric is a significant performance penalty for nothing. regards, tom lane