Skip to content
Commit Detail

Commit 6f5fd8c

Author
Kenton Varda <kenton@cloudflare.com> 2024-10-22 11:35:12 -0500
Parents
1da3c7e
Tree
9966df1
SQLite: Optimization: Read one row ahead.

By always iterating the underlying query one row ahead of what has been returned, we can discover when the query is done and return it to the statement cache more proactively.

Without this optimization, statements very commonly don't get returned to the cache until the cursor is GC'd -- especially statements that return no results at all.

In theory this would inflate the "rows read" metric for an application that commonly creates cursors and doesn't iterate them to completion. But, that should be uncommon, and "buffering ahead" is hardly an unreasonable thing for the platform to be doing.

I verified this optimization works by checking how often sql-test.js is unable to reuse a cache entry because it's still "in use" (`isShared()` returns true). Before this, there were dozens of cases, but after, there are only two, and they are intentional cases of overlapping queries.

Files changed

3 files changed~3 modified