Re: Unexpected sequential scan on an indexed column - Mailing list pgsql-performance

From Dave Crooke
Subject Re: Unexpected sequential scan on an indexed column
Date
Msg-id ca24673e0911160944s1fa729f1x75abefb4eaf09de@mail.gmail.com
Whole thread Raw
In response to Re: Unexpected sequential scan on an indexed column  (Eddy Escardo-Raffo <eescardo@kikini.com>)
Responses Re: Unexpected sequential scan on an indexed column  (Eddy Escardo-Raffo <eescardo@kikini.com>)
List pgsql-performance
Hi Eddy

Perhaps a slightly naive suggestion .... have you considered
converting the query to a small stored procedure ('function' in
Postgres speak)? You can pull the location values, and then iterate
over a query like this:

select userid from users where location=:x

which is more-or-less guaranteed to use the index.


I had a somewhat similar situation recently, where I was passing in a
list of id's (from outwith Postgres) and it would on occasion avoid
the index in favour of a full table scan .... I changed this to
iterate over the id's with separate queries (in Java, but using a
function will achieve the same thing) and went from one 5 minute query
doing full table scan to a handful of queries doing sub-millisecond
direct index lookups.

Cheers
Dave

pgsql-performance by date:

Previous
From: Wayne Beaver
Date:
Subject: Re: Manual vacs 5x faster than autovacs?
Next
From: cb
Date:
Subject: Is Diskeeper Automatic Mode safe?