More than likely you are suffering from an affliction known as type 
mismatch.  This is listed as tip 9 here on the performance list (funny, it 
was sent at the bottom of your reply :-)

What happens is that when you do:

select * from some_table where id=123;

where id is a bigint the query planner assumes you must want 123 
cast to int4, which doesn't match int8 (aka bigint) and uses a sequential 
scan to access that row.  I.e. it reads the whole table in.

You can force the planner to do the right thing here in a couple of ways:

select * from some_table where id=123::bigint;

-- OR --

select * from some_table where id='123';

On Wed, 13 Aug 2003, ingrid martinez wrote:

> the primary key is   flidload
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to