I'm using jOOQ 3.4.2 to query a PostgreSQL database using Scala. I want to fetch small chunks of the result set at a time without loading the entire result set into memory, as the query could return many rows. I have the following code:
val query = context.selectFrom(table)
.where(conditions)
.orderBy(orderField)
.fetchSize(1)
val cursor = query.fetchLazy()
// Iterate through cursor using cursor.fetchOne()
It appears that jOOQ will load the entire result set (or at least a huge chunk of the result set) in memory when I call fetchLazy()
, before I even fetch the first row from the cursor (judging by the large number of recvfrom()
syscalls I'm seeing while fetchLazy()
is being called). Am I doing something wrong?