Subject LIMIT record in SELECT query gets slow
Author jasperelzinga
Hello,

I'm trying to speed up a database application by limiting the amount
of records selected per query.

Original query:
>>> data = timeQuery("SELECT id FROM Instantie", [])
execute time: 0.0
fetchall time: 0.56200003624
total time: 0.56200003624

Limited query:
>>> data = timeQuery("SELECT FIRST 50 id FROM Instantie", [])
execute time: 0.0
fetchall time: 0.0
total time: 0.0

This speeds up a lot, and gives me only the first 50 records. But when
i select records that are more to the end, it gets slower and slower.

Record 3000-3050:
>>> data = timeQuery("SELECT FIRST 50 SKIP 3000 id FROM Instantie", [])
execute time: 0.0150001049042
fetchall time: 0.141000032425
total time: 0.156000137329

Last 50 records:
>>> data = timeQuery("SELECT FIRST 50 SKIP 9950 id FROM Instantie", [])
execute time: 0.0
fetchall time: 0.43700003624
total time: 0.43700003624

This is almost as slow as the original query. It looks like the
database does select (or something like that) the records it should
skip. Is this normal? Or is it a bug? Are there any other options?
Maybe using PLAN in my SELECT query..?

Thanks in advance,
Jasper Elzinga