X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B233ED1D9E9 for ; Wed, 3 Dec 2003 15:57:23 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 51604-02 for ; Wed, 3 Dec 2003 11:56:56 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id AFF38D1D92C for ; Wed, 3 Dec 2003 11:56:51 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 3346734FE1; Wed, 3 Dec 2003 07:56:41 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 31C8F34D5B; Wed, 3 Dec 2003 07:56:41 -0800 (PST) Date: Wed, 3 Dec 2003 07:56:41 -0800 (PST) From: Stephan Szabo To: Ferdinand Smit Cc: pgsql-admin@postgresql.org Subject: Re: Index problems In-Reply-To: <200312031154.48776.ferdinand@telegraafnet.nl> Message-ID: <20031203074800.T28610@megazone.bigpanda.com> References: <200312031154.48776.ferdinand@telegraafnet.nl> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/24 X-Sequence-Number: 11532 On Wed, 3 Dec 2003, Ferdinand Smit wrote: > Hi, > > When trying to explain a developer of our organisation the reson why the index > was'nt used, i was confused my self. > > The simple question is: Why does the analyzer only use the index when the There are a fiew things going on: First, the statistics are overestimating the number of matching rows (by say a factor of 3 in the first query). You may wish to increase the statistics target (alter table test alter column r set statistics ) for something greater than 10, try 20 or 100 and re-analyze the table and see if that lowers the estimated costs for the index scan. Second, it's also possible that on your system random_page_cost should be lower than 4. Lowering that value lowers the estimated cost for index scans. Finally, it's also possible that the table is reasonably grouped by values of r but that the statistics aren't realizing that fact. What does the row in pg_statistic for that column show?