You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dbGetQueryArrow() is several times slower than dbGetQuery() and does not stream #651
Fetching one million rows of (int, text, numeric) with dbGetQueryArrow() takes about three times as long as dbGetQuery() and yields 3907 batches of 256 rows. All batches are fetched before the stream is returned, so memory use is that of the whole result and nothing is streamed. The returned stream is also detached from the result set and stays readable after dbClearResult().
Location: DBI default methods. dbFetchArrowChunk() fetches 256 rows per chunk through dbFetch() and converts each data frame with nanoarrow, and dbFetchArrow() collects every chunk into a list before wrapping it in basic_array_stream().
Reprex against the CRAN release (main at 41cd4be gives comparable timings: 0.73 s and 2.41 s elapsed):
Sys.setenv(PGHOST="localhost", PGPORT="5432", PGUSER="runner", PGPASSWORD="test123", PGDATABASE="testdb")
library(DBI)
con<- dbConnect(RPostgres::Postgres())
q<-"SELECT i, i::text AS s, i * 1.5 AS f FROM generate_series(1, 1000000) i"
system.time(dbGetQuery(con, q))
#> user system elapsed #> 0.608 0.049 0.707
system.time(s<- dbGetQueryArrow(con, q))
#> user system elapsed #> 2.164 0.042 2.256# Expected: comparable to dbGetQuery()k<-0while (!is.null(s$get_next())) k<-k+1k#> [1] 3907# Expected: a few large batches, produced while the stream is consumed
dbGetQuery(con, "SHOW server_version")
#> server_version#> 1 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)
dbDisconnect(con)
as.data.frame(sessioninfo::package_info(c("RPostgres", "DBI", "nanoarrow"), dependencies=FALSE))[c("package", "ondiskversion", "source")]
#> package ondiskversion source#> DBI DBI 1.3.0 RSPM#> nanoarrow nanoarrow 0.9.0 RSPM#> RPostgres RPostgres 1.4.10 RSPM (R 4.5.0)
decide the lifetime of the returned stream relative to the result set
Severity: medium (proposed, Kirill may change). Performance and memory.
Native Arrow support is coordinated in #631 and is expected to fix this by construction, since the native fetch builds Arrow batches directly from libpq results; the stream lifetime is an open question there.
Activity
krlmlr commentedon Nov 29, 2026
Closed to keep the issue tracker for issues reported by others; the work here is still open and tracked with the
status: openlabel.Generated by Claude Code