Replies: 2 comments
|
Short version: at the API level The part that's easy to get bitten by, and isn't really spelled out in the docs, is what happens underneath on Postgres. sqlx doesn't open a server-side cursor for you. Postgres sends the entire result set down the wire as soon as the query runs, and If you need a hard memory bound over a very large table on Postgres, use an explicit SQL cursor ( |
|
The One correction to the earlier reply: the stream borrows the connection; a returned PostgreSQL row doesn't borrow it. For PostgreSQL, the executor decodes and yields rows as it reads For your use case, processing each row and dropping it before advancing avoids collecting the entire result in your application. I'd describe that as incremental consumption, rather than a guarantee that exactly one row's worth of bytes is resident. Explicit cursor batches can control the number of rows requested per batch, but even those aren't a fixed byte limit without a bound on row size. Database-side query execution memory is separate again. |
Uh oh!
There was an error while loading. Please reload this page.
I can't find documentation for
Query::fetchwhich explains the exact memory impact one should expect when using it to stream individual items from the database (rather than fetching all at once). I expect it holds only one item in memory at a time, but this is not actually documented anywhere that I can find. Can anyone point me at the relevant docs? Many thanks!All reactions