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 E3D589FA65C for ; Fri, 21 Jul 2006 19:00:08 -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 77851-01 for ; Fri, 21 Jul 2006 22:00:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.181]) by postgresql.org (Postfix) with ESMTP id BD8A79FA50D for ; Fri, 21 Jul 2006 19:00:02 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id b36so1354728pyb for ; Fri, 21 Jul 2006 15:00:01 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=skd80xfRCopj5HDRwNcVUrQ0QGvHXYXErvMQkDhzvzDDC11UNb2oUVc7PDTTmfZbFIDBQhTyZMhZbIp6PTZ3dC4O06rXgK6ZJ6x1VuAtmK1S2XkXarRi7jtqMQB4Uymjcs/7xL+llrwTxKxixbiJv7r+9KFt3GSl0U/gL92eeN0= Received: by 10.35.76.5 with SMTP id d5mr1988540pyl; Fri, 21 Jul 2006 15:00:01 -0700 (PDT) Received: by 10.35.53.5 with HTTP; Fri, 21 Jul 2006 15:00:01 -0700 (PDT) Message-ID: <1d4e0c10607211500t62be09f2v8284ceb5176b01bc@mail.gmail.com> Date: Sat, 22 Jul 2006 00:00:01 +0200 From: "Guillaume Smet" To: "Tom Lane" Subject: Re: Bad Planner Statistics for Uneven distribution. Cc: "Kevin McArthur" , pgsql-performance@postgresql.org In-Reply-To: <8073.1153517393@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <003b01c6acf1$a66d8910$0701a8c0@kdesktop> <8073.1153517393@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.478 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200607/217 X-Sequence-Number: 20077 Tom, On 7/21/06, Tom Lane wrote: > 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 ... We discussed this case on IRC and the problem was not the first set of queries but the second one: select brand_id from brands where exists (select 1 from models_brands where brand = brands.brand_id);). Isn't there any way to make PostgreSQL have a better estimation here: -> Index Scan using models_brands_brand on models_brands (cost=0.00..216410.97 rows=92372 width=0) (actual time=0.008..0.008 rows=0 loops=303) Index Cond: (brand = $0) I suppose it's because the planner estimates that there will be 92372 result rows that it chooses the seqscan instead of the index scan. ALTER STATISTICS didn't change anything. IIRC, there were already a few threads about the same sort of estimation problem and there wasn't any solution to solve this problem. Do you have any hint/ideas? -- Guillaume