Tom Lane wrote:
> I do not buy that psql's FETCH_COUNT mode is a sufficient reason
> to add it. FETCH_COUNT mode is not something you'd use
> non-interactively
I should say that I've noticed significant latency improvements with
FETCH_COUNT retrieving large resultsets, such that it would benefit
non-interactive use cases.
For instance, with the current v7 patch, a query like the OP's initial
case and batches of 1000 rows:
$ cat fetchcount-test.sql
select repeat('a', 100) || '-' ||
i || '-' || repeat('b', 500) as total_pat
from generate_series(1, 5000000) as i
\g /dev/null
$ export TIMEFORMAT=%R
$ for s in $(seq 1 10); do time /usr/local/pgsql/bin/psql -At \
-v FETCH_COUNT=1000 -f fetchcount-test.sql; done
3.597
3.413
3.362
3.612
3.377
3.416
3.346
3.368
3.504
3.413
=> Average elapsed time = 3.44s
Now without FETCH_COUNT, fetching the 5 million rows in one resultset:
$ for s in $(seq 1 10); do time /usr/local/pgsql/bin/psql -At \
-f fetchcount-test.sql; done
4.200
4.178
4.200
4.169
4.195
4.217
4.197
4.234
4.225
4.242
=> Average elapsed time = 4.20s
By comparison the unpatched version (cursor-based method)
gives these execution times with FETCH_COUNT=1000:
4.458
4.448
4.476
4.455
4.450
4.466
4.395
4.429
4.387
4.473
=> Average elapsed time = 4.43s
Now that's just one test, but don't these numbers look good?
Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite