Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9E9B0632D4D for ; Wed, 7 Jul 2010 18:22:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 34975-02 for ; Wed, 7 Jul 2010 21:22:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 06413632311 for ; Wed, 7 Jul 2010 18:22:02 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o67LM0Hx016025; Wed, 7 Jul 2010 17:22:01 -0400 (EDT) To: Jerry Gamache cc: pgsql-performance@postgresql.org Subject: Re: Logarithmic data frequency distributions and the query planner In-reply-to: <4C34E998.3020000@idilia.com> References: <4C34E998.3020000@idilia.com> Comments: In-reply-to Jerry Gamache message dated "Wed, 07 Jul 2010 16:54:48 -0400" Date: Wed, 07 Jul 2010 17:22:00 -0400 Message-ID: <16024.1278537720@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/97 X-Sequence-Number: 39486 Jerry Gamache writes: > On 8.1, I have a very interesting database where the distributions of > some values in a multi-million rows table is logarithmic (i.e. the most > frequent value is an order of magnitude more frequent than the next > ones). If I analyze the table, the statistics become extremely skewed > towards the most frequent values and this prevents the planner from > giving any good results on queries that do not target these entries. Highly skewed distributions are hardly unusual, and I'm not aware that the planner is totally incapable of dealing with them. You do need a large enough stats target to get down into the tail of the distribution (the default target for 8.1 is probably too small for you). It might be that there have been some other relevant improvements since 8.1, too ... regards, tom lane