limit /offset - Mailing list pgsql-general

From Pirtea Calin
Subject limit /offset
Date
Msg-id 000b01c1ccd3$4ee830d0$0100a8c0@dizzy
Whole thread Raw
Responses Re: limit /offset
Re: limit /offset
List 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@rdsor.ro


pgsql-general by date:

Previous
From: John Gray
Date:
Subject: Re: Back end dies...
Next
From: "Arsalan Zaidi"
Date:
Subject: Re: Back end dies...