Re: libpq Alternate Row Processor

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Kyle Gearhart <kyle(dot)gearhart(at)indigohill(dot)io>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq Alternate Row Processor
Date: 2017-02-13 21:08:47
Message-ID: CAHyXU0z0tQ9OhiaN47gm6GfF93xUrmr0E+KDSyoiGmr1CT6dqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 13, 2017 at 8:46 AM, Kyle Gearhart
<kyle(dot)gearhart(at)indigohill(dot)io> wrote:
> On 2/9/17 7:15 PM, Jim Nasby wrote:
>> Can you run a trace to see where all the time is going in the single row case? I don't see an obvious time-suck with a quick look through the code. It'd be interesting to see how things change if you eliminate the filler column from the SELECT.
>
> Traces are attached, these are with callgrind.
>
> profile_nofiller.txt: single row without filler column
> profile_filler.txt: single row with filler column
> profile_filler_callback.txt: callback with filler column
>
> pqResultAlloc looks to hit malloc pretty hard. The callback reduces all of that to a single malloc for each row.

Couldn't that be optimized, say, by preserving malloc'd memory when in
single row mode and recycling it? (IIRC during the single row mode
discussion this optimization was voted down).

A barebones callback mode ISTM is a complete departure from the
classic PGresult interface. This code is pretty unpleasant IMO:
acct->abalance = *((int*)PQgetvalue(res, 0, i));
acct->abalance = __bswap_32(acct->abalance);

Your code is faster but foists a lot of the work on the user, so it's
kind of cheating in a way (although very carefully written
applications might be able to benefit).

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brad DeJong 2017-02-13 21:10:28 Re: Small improvement to parallel query docs
Previous Message Fabien COELHO 2017-02-13 21:06:53 Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)