pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sebastien FLAESCH <sf@4js.com>
To: pgsql-sql@lists.postgresql.org
Subject: libpq: How are result sets fetch behind the scene?
Date: Thu, 29 Aug 2019 18:32:44 +0200
Message-ID: <6f2f210b-53e6-f350-4850-83f49b2a1354@4js.com> (raw)

Hi all,

We are using libpq in our C program.

I was wondering how the client lib / protocol manage to fetch the result set to the client app memory.

Is there some optimization ?

Are rows fetched in sequence until the requested row?

I mean if I do a SELECT that produces a huge result set, and then call PQgetvalue() with a row_number = 5000, are all 5000 rows fetched from the 
server or is there some smart fast-forward done because I did not ask the 4999 previous rows?

We know about server cursors (declare + fetch forward), and we do already fetch blocks of rows with this.

But server cursors are slow (and certainly use more server resources), compared to direct SELECT execution.

So we are wondering what would be the impact in terms of resources on the client application.

Is there any doc link or blog that would explain best practices with libpq result set programming?

Thanks!
Seb





Message-ID: <6f2f210b-53e6-f350-4850-83f49b2a1354@4js.com>
Permalink:  ../6f2f210b-53e6-f350-4850-83f49b2a1354@4js.com/
Also on:    postgresql.org/message-id/6f2f210b-53e6-f350-4850-83f49b2a1354@4js.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sf@4js.com, pgsql-sql@lists.postgresql.org
  Subject: Re: libpq: How are result sets fetch behind the scene?
  In-Reply-To: <6f2f210b-53e6-f350-4850-83f49b2a1354@4js.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox