X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 552D5D1DAF3 for ; Fri, 16 Jan 2004 17:49:06 +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 52725-05 for ; Fri, 16 Jan 2004 13:48:35 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 666F4D1D8A9 for ; Fri, 16 Jan 2004 13:48:34 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 94F1C354F4; Fri, 16 Jan 2004 09:48:18 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 93730354D6; Fri, 16 Jan 2004 09:48:18 -0800 (PST) Date: Fri, 16 Jan 2004 09:48:18 -0800 (PST) From: Stephan Szabo To: CoL Cc: pgsql-performance@postgresql.org Subject: Re: subquery and table join, index not use for table In-Reply-To: Message-ID: <20040116094239.A66040@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/177 X-Sequence-Number: 5351 On Wed, 14 Jan 2004, CoL wrote: [plan1] > -> Seq Scan on menutable b (cost=0.00..13.01 rows=38 width=22) > (actual time=0.02..0.38 rows=38 loops=1) [plan2] > -> Index Scan using menutable_pkey on menutable b > (cost=0.00..29.36 rows=38 width=22) (actual time=0.02..0.12 rows=38 loops=1) It's estimating a cost of 13 for the sequence scan and 29 for the index scan so it's choosing the sequence scan. The value of random_page_cost may be too high for your system and especially so if the database is small and likely to fit in ram. In addition, if the table in question is small, you'll likely find that at some point for a larger data set that the system switches over to an index scan.