假设我在 SQLite 中有以下查询:
SELECT * FROM mytable ORDER BY product ASC
我希望最终用户能够以可滚动的方式查看数据(例如,就像 Excel 中当前可查看的数据)。如果用户向下滚动 100 个结果,而不是执行以下操作:
SELECT * FROM mytable ORDER BY product ASC LIMIT 50 OFFSET 100
我想确保返回给他们的结果在 25 毫秒左右,而不是让他们等待每次超出可视范围时执行查询所需的时间。
最好的方法是什么?在伪代码中,我的思路如下:
-- 1st time query is run
SELECT * FROM mytable ORDER BY product ASC LIMIT 50 -- in main thread
INSERT INTO queryset_cache -- in background thread
SELECT rowid, * FROM mytable ORDER BY product ASC
-- 2nd time query is run, offset 84,500 (user scrolls down to that position
SELECT * FROM queryset_cache ORDER BY rowid LIMIT 50 OFFSET 84500
这会是完成我想要做的事情的最佳方式吗?或者是否有一种标准化的方法可以在 SQLite 中执行上述操作?如果是这样,最好的方法是什么?