limit /offset

From: "Pirtea Calin" <pcalin(at)rdsor(dot)ro>
To: "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: limit /offset
Date: 2002-03-16 10:13:41
Message-ID: 000b01c1ccd3$4ee830d0$0100a8c0@dizzy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

When i checkout the plan for this statement
select * from detail2 where id>125000 order by info1 limit 10
is:
Limit (cost=0.00..1.85 rows=10 width=52)
-> Index Scan using detail2_ind1 on detail2 (cost=0.00..61.50 rows=333
width=52)
and it takes less than a second to complete
but when i use offset in the same statement
select * from detail2 where id>125000 order by info1 limit 10 offset
10000
the plan changes
Limit (cost=36.47..36.47 rows=1 width=52)
-> Sort (cost=36.47..36.47 rows=333 width=52)
-> Seq Scan on detail2 (cost=0.00..22.50 rows=333 width=52)
and it takes almost 50 seconds to complete (42.890 sec)
Can anyone explain why offset doesn't use the index available?

the table is created as folows:

create table detail2
(id int8 not null primary key
,id_ref int8 references detail1 on delete cascade
,Info1 VarChar(15) not null
,Info2 VarChar(200)
,Info3 VarChar(200));
create index detail2_ind1 on detail2(Info1);
create index detail2_ind2 on detail2(Info2);
create index detail2_ind3 on detail2(Info3);

I think this query should use _detail2_in1_ in both cases.

Best regards,
Aplication Developer
Pirtea Calin Iancu
S.C. SoftScape S.R.L.
pcalin(at)rdsor(dot)ro

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cornelia Boenigk 2002-03-16 14:46:37 Question to CREATE TYPE
Previous Message Arsalan Zaidi 2002-03-16 10:03:07 Re: Back end dies...