X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BDE118B9CCB for ; Thu, 3 Feb 2005 06:52:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94153-05 for ; Thu, 3 Feb 2005 06:52:49 +0000 (GMT) Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82]) by svr1.postgresql.org (Postfix) with ESMTP id B88A48B9BCC for ; Thu, 3 Feb 2005 06:52:48 +0000 (GMT) Received: from localhost (mailbox.samurai.com [205.207.28.82]) by mailbox.samurai.com (Postfix) with ESMTP id 734ED18CD18; Thu, 3 Feb 2005 01:52:53 -0500 (EST) Received: from mailbox.samurai.com ([205.207.28.82]) by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new, port 10024) with LMTP id 52257-01-4; Thu, 3 Feb 2005 01:52:52 -0500 (EST) Received: from fjgateway (unknown [61.88.101.19]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by mailbox.samurai.com (Postfix) with ESMTP id CA9C418CC63; Thu, 3 Feb 2005 01:52:51 -0500 (EST) Subject: Re: planner stats From: Neil Conway To: Roman Neuhauser Cc: pgsql-docs@postgresql.org In-Reply-To: <20050202100246.GA1859@isis.wad.cz> References: <20050202100246.GA1859@isis.wad.cz> Content-Type: text/plain Date: Thu, 03 Feb 2005 17:52:24 +1100 Message-Id: <1107413544.26960.74.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.026 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/10 X-Sequence-Number: 2843 On Wed, 2005-02-02 at 11:02 +0100, Roman Neuhauser wrote: > the SET STATISTICS description under ALTER TABLE doesn't explain how > to choose the right target (is there a formula?) There's no simple formula; in particular, it's not merely a matter of raising the target for the columns of a large table. The more irregular the distribution of the data in a particular column, the higher the target should be (as the docs state, and as I've quoted below). I would guess most people figure out how to set per-column stats by trial and error, by looking at how accurate the planner's estimates are for queries involving the column in question. > it says "For more information on the use of statistics by the PostgreSQL > query planner, refer to Section 13.2.", but that section *doesn't* talk > about "the use of statistics by the query planner"; it doesn't hint > a method to choose a good target either I disagree: The amount of information stored in pg_statistic, in particular the maximum number of entries in the most_common_vals and histogram_bounds arrays for each column, can be set on a column-by-column basis using the ALTER TABLE SET STATISTICS command, or globally by setting the default_statistics_target configuration variable. The default limit is presently 10 entries. Raising the limit may allow more accurate planner estimates to be made, particularly for columns with irregular data distributions, at the price of consuming more space in pg_statistic and slightly more time to compute the estimates. Conversely, a lower limit may be appropriate for columns with simple data distributions. Suggestions for specific improvements are welcome (a patch against the SGML is easiest). -Neil