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