Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 7AC549F9B79 for ; Tue, 4 Sep 2007 11:40:11 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 82509-06 for ; Tue, 4 Sep 2007 11:40:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from outA.internet-mail-service.net (outA.internet-mail-service.net [216.240.47.224]) by postgresql.org (Postfix) with ESMTP id 375549F96D0 for ; Tue, 4 Sep 2007 11:40:07 -0300 (ADT) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Tue, 04 Sep 2007 07:40:05 -0700 Received: from [192.168.1.109] (adsl-71-135-174-255.dsl.pltn13.pacbell.net [71.135.174.255]) by idiom.com (Postfix) with ESMTP id 9B80C126286 for ; Tue, 4 Sep 2007 07:40:04 -0700 (PDT) Message-ID: <46DD6E44.4000505@obviously.com> Date: Tue, 04 Sep 2007 07:40:04 -0700 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061107 SUSE/1.1.2-1.1 SeaMonkey/1.1.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Partial index on boolean - Sometimes fails to index scan References: <46DCE263.6040207@obviously.com> <46DD0E81.2000901@obviously.com> In-Reply-To: <46DD0E81.2000901@obviously.com> Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.798 tagged_above=0 required=5 tests=AWL=-0.661, BAYES_50=0.001, HTML_MESSAGE=0.001, MIME_HTML_ONLY=1.457 X-Spam-Level: X-Archive-Number: 200709/35 X-Sequence-Number: 29248 Richard Huxton provided the answer: It's a prepared query-plan, which means it can't plan to use the index because the next EXECUTE might have reconciled=true.

Bryce Nesbitt wrote:
...Which is all good.  But the Hibernate version of query still takes several seconds, and still appears in my pg_log slow query log:

LOG:  duration: 2248.662 ms  statement: EXECUTE C_51443  [PREPARE:  select count(vehicleeve0_.VEHICLE_EVENT_ID) as x0_0_ from EG_VEHICLE_EVENT vehicleeve0_ where (vehicleeve0_.CSO_ID=$1 )and(vehicleeve0_.RECONCILED=$2 )]