Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DDEEC64FFFC for ; Thu, 7 Aug 2008 20:55:46 -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 10429-02 for ; Thu, 7 Aug 2008 20:55:39 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by postgresql.org (Postfix) with ESMTP id 0B34A64FFB8 for ; Thu, 7 Aug 2008 20:55:43 -0300 (ADT) Received: by fg-out-1718.google.com with SMTP id 16so557146fgg.23 for ; Thu, 07 Aug 2008 16:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=M00+O2fMFLjLjggD9GI79qcNJs+HGel+o8jy2dKiNqc=; b=ONKNdawvpa9L1oTHAZaaZapluw6/EWciT0jryq1bV04vEEGHbuEVMBqdyAIZHFcgOw LsnyGAf/+6VfOicPWBpnaiSwMYV/4yhJMv6WoJ73DmVBue8gC+P1OlqUYea1aJ9xQ+OU sp8YBtu+4+knMA2Q9RpBWRKs65Azpxa4JE/JM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=EKLaRrwcgBn8U/sImloc+aMMrARfnaiODscsMgPQ+vGazt1OJ3Qr+KM1RekjwNifGg niJ58rN5eOqeV5agYxsDx4Vf4JJaZYIyk2lrwILow7RcO8mZO4Konkr1Q/r4yWep0Pap z2V2StXn3rn5+V94O5f3vYpVdH7LVUAjpzkqk= Received: by 10.86.26.11 with SMTP id 11mr2197655fgz.71.1218153342214; Thu, 07 Aug 2008 16:55:42 -0700 (PDT) Received: by 10.86.2.11 with HTTP; Thu, 7 Aug 2008 16:55:42 -0700 (PDT) Message-ID: <84f0acdb0808071655s79d0644o21df6b397b3616c0@mail.gmail.com> Date: Thu, 7 Aug 2008 18:55:42 -0500 From: "Joshua Shanks" To: "Tom Lane" Subject: Re: query planner not using the correct index Cc: "Craig Ringer" , pgsql-performance@postgresql.org In-Reply-To: <29507.1218152891@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <84f0acdb0808061435q5ebb607cjc311f1eb4da841a@mail.gmail.com> <489A623A.4090400@postnewspapers.com.au> <84f0acdb0808062014p29cf7482ied332225a0a92c63@mail.gmail.com> <489A6AF5.50908@postnewspapers.com.au> <84f0acdb0808070811l43a3da9eq240d272f8ddd105c@mail.gmail.com> <27696.1218143560@sss.pgh.pa.us> <84f0acdb0808071501n15b0182ga7eca7b1be37d705@mail.gmail.com> <29507.1218152891@sss.pgh.pa.us> 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: 200808/63 X-Sequence-Number: 30944 Yeah with default_statistics_target at 500 most_common_vals had 4 values with the fourth having a frequency of 1.5% and distinct have 250+ in it. How do I increase the stats target for just one column? On Thu, Aug 7, 2008 at 6:48 PM, Tom Lane wrote: > "Joshua Shanks" writes: >> SELECT null_frac, n_distinct, most_common_vals, most_common_freqs FROM >> pg_stats WHERE tablename = 'bars' AND attname='bars_id'; >> null_frac | n_distinct | most_common_vals | most_common_freqs >> -----------+------------+----------------------+--------------------------- >> 0 | 14 | {145823,47063,24895} | {0.484667,0.257333,0.242} > >> Those 3 values in reality and in the stats account for 98% of the >> rows. actual distinct values are around 350 > > So you need to increase the stats target for this column. With those > numbers the planner is going to assume that any value that's not one > of the big three appears about (1 - (0.484667+0.257333+0.242)) / 11 > of the time, or several hundred times in 300K rows. If n_distinct were > up around 350 it would be estimating just a dozen or so occurrences, > which should push the join plan into the shape you want. It's likely > that it won't bother to include any more entries in most_common_vals > no matter how much you raise the target; but a larger sample should > definitely give it a better clue about n_distinct. > > regards, tom lane >