X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1E65E5425E for ; Thu, 21 Apr 2005 18:58:09 -0300 (ADT) 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 04995-01 for ; Thu, 21 Apr 2005 21:54:37 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id ABE5953B4E for ; Thu, 21 Apr 2005 18:15:10 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 27459357FE; Thu, 21 Apr 2005 14:15:08 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 25B3C356F2; Thu, 21 Apr 2005 14:15:08 -0700 (PDT) Date: Thu, 21 Apr 2005 14:15:08 -0700 (PDT) From: Stephan Szabo To: Enrico Weigelt Cc: postgresql performance list Subject: Re: index not used In-Reply-To: <20050421190543.GA16548@nibiru.borg.metux.de> Message-ID: <20050421140958.Y59173@megazone.bigpanda.com> References: <20050421190543.GA16548@nibiru.borg.metux.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/597 X-Sequence-Number: 11994 On Thu, 21 Apr 2005, Enrico Weigelt wrote: > I'm doing a simple lookup in a small table by an unique id, and I'm > wondering, why explains tells me seqscan is used instead the key. > > The table looks like: > > id bigint primary key, > a varchar, > b varchar, > c varchar > > and I'm quering: select * from foo where id = 2; > > I've got only 15 records in this table, but I wanna have it as > fast as possible since its used (as a map between IDs and names) > for larger queries. Two general things: For 15 records, an index scan may not be faster. For simple tests you can play with enable_seqscan to see, but for more complicated queries it's a little harder to tell. If you're using a version earlier than 8.0, you'll need to quote or cast the value you're searching for due to problems with cross-type comparisons (the 2 would be treated as int4).