Re: index not used

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Enrico Weigelt <weigelt(at)metux(dot)de>
Cc: postgresql performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: index not used
Date: 2005-04-21 21:15:08
Message-ID: 20050421140958.Y59173@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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).

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Mischa Sandberg 2005-04-21 22:15:22 Re: Index bloat problem?
Previous Message Richard Plotkin 2005-04-21 21:01:36 Re: Disk filling, CPU filling, renegade inserts and deletes?