To avoid fetching all data at once, which will cause out of memory, we are implementing paging in our app, by using limit & offset.
Each time, our app will only display 1 page.
Page 0 : select * from note order by order_id limit 10000 offset 0;
Page 1 : select * from note order by order_id limit 10000 offset 10000;
Page 2 : select * from note order by order_id limit 10000 offset 20000;
Page 3 : select * from note order by order_id limit 10000 offset 30000;
...
Whenever user adds a new data, we know the search criteria to locate data from SQLite.
select * from note where uuid = '1234-5678-9ABC';
However, we need to reload our app with the correct page.
But, we have no idea, how to have a good speed performance, to find out which page (which offset), the new data belongs to.
We can have the following brute force way to find out which offset the data belongs to
select * from (select * from note order by order_id limit 10000 offset 0) where uuid = '1234-5678-9ABC';
select * from (select * from note order by order_id limit 10000 offset 10000) where uuid = '1234-5678-9ABC';
select * from (select * from note order by order_id limit 10000 offset 20000) where uuid = '1234-5678-9ABC';
select * from (select * from note order by order_id limit 10000 offset 30000) where uuid = '1234-5678-9ABC';
...
But, that is highly inefficient.
Is there any "smart" way, so that we can have a good speed performance, to locate the right offset for a given data?
Thanks.