How to avoid "Seq Scans"?

From: Vincenzo Romano <vincenzo(dot)romano(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to avoid "Seq Scans"?
Date: 2007-08-29 09:15:21
Message-ID: 200708291115.21976.vincenzo.romano@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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]

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2007-08-29 09:16:23 documentation patch for LDAP service lookup
Previous Message Hannes Dorbath 2007-08-29 07:23:52 Re: Install on 32 or 64 bit Linux?