Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D629C64FCF9 for ; Fri, 19 Sep 2008 15:43:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 09550-10 for ; Fri, 19 Sep 2008 15:43:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.175]) by postgresql.org (Postfix) with ESMTP id B5E2764FCE8 for ; Fri, 19 Sep 2008 15:43:26 -0300 (ADT) Received: by wf-out-1314.google.com with SMTP id 25so622800wfc.28 for ; Fri, 19 Sep 2008 11:43:26 -0700 (PDT) Received: by 10.143.5.7 with SMTP id h7mr152526wfi.319.1221849805989; Fri, 19 Sep 2008 11:43:25 -0700 (PDT) Received: from ?10.10.30.141? ( [204.11.227.33]) by mx.google.com with ESMTPS id 9sm514996wfc.19.2008.09.19.11.43.25 (version=SSLv3 cipher=RC4-MD5); Fri, 19 Sep 2008 11:43:25 -0700 (PDT) Subject: Re: why does this use the wrong index? From: Jeff Davis To: Rainer Mager Cc: pgsql-performance@postgresql.org In-Reply-To: <1221848728.6194.292.camel@dell.linuxdev.us.dell.com> References: <000101c919ef$7c0b8e20$7422aa60$@com> <1221848728.6194.292.camel@dell.linuxdev.us.dell.com> Content-Type: text/plain Date: Fri, 19 Sep 2008 11:43:24 -0700 Message-Id: <1221849804.6194.297.camel@dell.linuxdev.us.dell.com> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/194 X-Sequence-Number: 31507 On Fri, 2008-09-19 at 11:25 -0700, Jeff Davis wrote: > What's the n_distinct for start_time? Actually, I take that back. Apparently, PostgreSQL can't change "x BETWEEN y AND y" into "x=y", so PostgreSQL can't use n_distinct at all. That's your problem. If it's one day only, change it to equality and it should be fine. Regards, Jeff Davis