Received: from shire.ontko.com (shire.ontko.com [199.164.165.1]) by postgresql.org (Postfix) with ESMTP id AE4FB476447 for ; Wed, 13 Mar 2002 14:52:13 -0500 (EST) Received: from nick (bilbo.ontko.com [199.164.165.101]) by shire.ontko.com (8.9.3/8.9.3/Debian 8.9.3-21) with SMTP id OAA04065; Wed, 13 Mar 2002 14:52:09 -0500 X-Authentication-Warning: shire.ontko.com: Host bilbo.ontko.com [199.164.165.101] claimed to be nick Reply-To: From: "Nick Fankhauser" To: "Stephan Szabo" Cc: "pgsql-admin" Subject: Re: Optimizing a condition based on an a very unequally distributed value. Date: Wed, 13 Mar 2002 14:47:42 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Importance: Normal In-Reply-To: <20020313113933.M85167-100000@megazone23.bigpanda.com> X-Archive-Number: 200203/192 X-Sequence-Number: 3726 Thanks for the answer! ...but now I have more questions: Is it true that if I use this condition in a join that further constrains the results, this might use the index? Does PGSQL know that few or many rows will be returned because of data gathered from the last vacuum? What do you mean by "tuple validity?" can't this query be resolved entirely based on the index? -Nick > -----Original Message Snips:----- > > So my question in general is why does PGSQL opt to use the index when > > looking for the single field row, and not use it when looking > for the other > > 23768 rows? > > Because in many cases the sequence scan will be faster than an index scan > when you're trying to get most of the rows of the table. Since the tuple > validity is in the table row and not the index, it's still got to check > the table which would involve lots of random reads into that file, so > you're doing even more disk operations and less efficient ones. >