X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 202929FA4A8 for ; Fri, 21 Jul 2006 18:29:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 71213-01 for ; Fri, 21 Jul 2006 21:29:55 +0000 (UTC) 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 034C99FA43C for ; Fri, 21 Jul 2006 18:29:54 -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 k6LLTrE5008074; Fri, 21 Jul 2006 17:29:53 -0400 (EDT) To: "Kevin McArthur" cc: pgsql-performance@postgresql.org Subject: Re: Bad Planner Statistics for Uneven distribution. In-reply-to: <003b01c6acf1$a66d8910$0701a8c0@kdesktop> References: <003b01c6acf1$a66d8910$0701a8c0@kdesktop> Comments: In-reply-to "Kevin McArthur" message dated "Fri, 21 Jul 2006 12:15:28 -0600" Date: Fri, 21 Jul 2006 17:29:53 -0400 Message-ID: <8073.1153517393@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/216 X-Sequence-Number: 20076 "Kevin McArthur" writes: > -> Seq Scan on models_brands (cost=0.00..6411.89 rows=369489 width=4) (actual time=0.040..1352.997 rows=369489 loops=1) > ... > -> Index Scan using models_brands_brand on models_brands (cost=0.00..862236.96 rows=369489 width=4) (actual time=0.122..1440.809 rows=369489 loops=1) > Picks the wrong plan here. Should pick the index with seqscanning enabled. It's really not possible for a full-table indexscan to be faster than a seqscan, and not very credible for it even to be approximately as fast. I suspect your second query here is the beneficiary of the first query having fetched all the pages into cache. In general, if you want to optimize for a mostly-cached database, you need to reduce random_page_cost below its default value ... regards, tom lane