libpq, PQexecPrepared, data size sent to FE vs. FETCH_COUNT

From: Alex Goncharov <alex-goncharov(at)comcast(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Alex Goncharov <alex-goncharov(at)comcast(dot)net>
Subject: libpq, PQexecPrepared, data size sent to FE vs. FETCH_COUNT
Date: 2010-05-24 16:25:18
Message-ID: E1OGaSs-000DrQ-AH@daland.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have some libpq-using application code, in which fetching the data
follows this logic (after a statement has been prepared):

----------------------------------------

PQexecPrepared(pg_result, pg_conn, pg_statement_name, input_param_cnt,
param_values, param_lengths, param_formats, result_format);

PQntuples(&rows_in_result, pg_result);

/* The application provides storage so that I can pass a certain number of rows
* (rows_to_pass_up) to the caller, and I repeat the following loop until
* many rows_to_pass_up cover all the rows_in_result (pg_row_num_base keeps the track
* of where I am in the process. */

for (int row_idx = 0; row_idx < rows_to_pass_up; ++row_idx) {
const int pg_row_number = row_idx + pg_row_num_base;

for (int pg_column_number = 0; pg_column_number < result_column_cnt_ ++pg_column_number) {
PQgetvalue(&value, pg_result, pg_row_number, pg_column_number);
PQgetlength(&length, pg_result, pg_row_number, pg_column_number);
}
}

----------------------------------------

My question is: am I doing the right thing from the "data size being
passed from BE to FE" perspective?

The code in `bin/psql' relies on the value of the FETCH_COUNT
parameter to build an appropriate

fetch forward FETCH_COUNT from _psql_cursor

command.

No equivalent of FETCH_COUNT is available at the libpq level, so I
assume that the interface I am using is smart enough not to send
gigabytes of data to FE.

Is that right? Is the logic I am using safe and good?

Where does the result set (GBs of data) reside after I call
PQexecPrepared? On BE, I hope?

Thanks,

-- Alex -- alex-goncharov(at)comcast(dot)net --

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2010-05-24 16:44:32 Re: Idea for getting rid of VACUUM FREEZE on cold pages
Previous Message Heikki Linnakangas 2010-05-24 16:18:43 Re: Synchronization levels in SR