X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 92C3111F6BFF for ; Tue, 18 Apr 2006 23:19:48 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.128 X-Spam-Level: X-Spam-Status: No, score=0.128 required=5 tests=[AWL=0.128] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id KMl+j7GdYWdt for ; Tue, 18 Apr 2006 23:19:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 45A8411F6B90 for ; Tue, 18 Apr 2006 23:19:44 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k3J2JirE020958; Tue, 18 Apr 2006 22:19:44 -0400 (EDT) To: "patrick keshishian" cc: pgsql-performance@postgresql.org Subject: Re: Planner doesn't chose Index - (slow select) In-reply-to: <53b425b00604181802v2cc259e1r59f9043b2cea3324@mail.gmail.com> References: <53b425b00604181802v2cc259e1r59f9043b2cea3324@mail.gmail.com> Comments: In-reply-to "patrick keshishian" message dated "Tue, 18 Apr 2006 18:02:27 -0700" Date: Tue, 18 Apr 2006 22:19:44 -0400 Message-ID: <20957.1145413184@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200604/412 X-Sequence-Number: 18496 "patrick keshishian" writes: > I've been struggling with some performance issues with certain > SQL queries. I was prepping a long-ish overview of my problem > to submit, but I think I'll start out with a simple case of the > problem first, hopefully answers I receive will help me solve > my initial issue. Have you ANALYZEd this table lately? > db=# select count(*) from pk_c2 b0 where b0.offer_id=7141; > count > ------- > 1 > (1 row) The planner is evidently estimating that there are 12109 such rows, not 1, which is the reason for its reluctance to use an indexscan. Generally the only reason for it to be off that far on such a simple statistical issue is if you haven't updated the stats in a long time. (If you've got a really skewed data distribution for offer_id, you might need to raise the statistics target for it.) > The table has indexes for both 'offer_id' and '(pending=true)': > Indexes: > "pk_boidx" btree (offer_id) > "pk_bpidx" btree (((pending = true))) The expression index on (pending = true) won't do you any good, unless you spell your query in a weird way like ... WHERE (pending = true) = true I'd suggest a plain index on "pending" instead. > db=# select version(); > PostgreSQL 7.4.12 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.6 You might want to think about an update, too. 7.4 is pretty long in the tooth. regards, tom lane