Skip site navigation (1) Skip section navigation (2)

Re: Incremental results from libpq

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: "Goulet, Dick" <DGoulet(at)vicr(dot)com>, Frank van Vugt <ftm(dot)van(dot)vugt(at)foxi(dot)nl>, Greg Stark <gsstark(at)mit(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Incremental results from libpq
Date: 2005-11-13 16:13:48
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:

> Postgres supports cursors too.  The Qt guys, and everyone else, could be
> using it to get incremental results right now, no libpq mods necessary.

Not really since the way Postgres supports cursors is at the SQL level. Users
of Qt and every other driver could be using cursors if their drivers support
them, but Qt can't really be reasonably expected to go into users' SQL and
modify them to use cursors.

Moreover cursors aren't really that great a substitute. With cursors you have
to manually fetch individual records. You're just trading off the
inefficiencies of batching up all the results for entirely different
inefficiencies. Now for every record you retrieve you need a network round
trip as well as a round trip down through your driver, the kernel layers on
both machines, and the backend as well.

The efficient approach as Oracle and other mature network layers implement is
to issue the query once, then pipeline the results back to the application
buffering a substantial amount in the driver. DBD::Oracle goes to some lengths
to ensure the number of records buffered is a reasonable multiple of the
default TCP mss of 1500 bytes. 

So even though the application only retrieves one record at a time it's just
pulling it out of an array that's already prefilled. When the array gets low
the next block of records is retrieved from the server (where they're probably
already buffered as well). The result is a constant flow of network traffic
that keeps the application and network as busy as possible.


In response to

pgsql-interfaces by date

Next:From: Goulet, DickDate: 2005-11-13 16:16:07
Subject: Re: Incremental results from libpq
Previous:From: Tom LaneDate: 2005-11-13 15:46:35
Subject: Re: Incremental results from libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group