How to avoid "Seq Scans"? - Mailing list pgsql-general

From Vincenzo Romano
Subject How to avoid "Seq Scans"?
Date
Msg-id 200708291115.21976.vincenzo.romano@gmail.com
Whole thread Raw
Responses Re: How to avoid "Seq Scans"?  (Richard Huxton <dev@archonet.com>)
Re: How to avoid "Seq Scans"?  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: How to avoid "Seq Scans"?  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Hi all.

In PG 8.2.4 I have a 4+M rows table like this:

create table t (
  f1 bigint,
  f2 text,
  f3 text
);

create index i_t_1 on t( f1 );
create index i_t_2 on t( f2 );
create index i_t_2 on t( f3 );

I'd need to write a stored function that should do the
following:

for rec in select * from t order by f2,f2 loop
...
end loop;

This loop is increadibly slow. Infact the friendly explain tells me
that:

test=# explain select * from t order by f2,f3;
                                   QUERY PLAN
---------------------------------------------------------------------------------
 Sort  (cost=958786.20..970734.55 rows=4779338 width=28)
   Sort Key: f2,f3
   ->  Seq Scan on t  (cost=0.00..85501.38 rows=4779338 width=28)

I'd like to know a hint about a technicque to avoid the sequential
scan!

Thanks.

--
Vincenzo Romano
--
Maybe Computer will never become as intelligent as Humans.
For sure they won't ever become so stupid. [VR-1988]

pgsql-general by date:

Previous
From: Hannes Dorbath
Date:
Subject: Re: Install on 32 or 64 bit Linux?
Next
From: Richard Huxton
Date:
Subject: Re: How to avoid "Seq Scans"?