Re: Faster methods for getting SPI results

From: Jim Nasby <jim(dot)nasby(at)openscg(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Joe Conway <mail(at)joeconway(dot)com>
Subject: Re: Faster methods for getting SPI results
Date: 2017-03-05 21:07:07
Message-ID: 3f9f86c3-9daa-553f-27ea-86ef0dc72655@openscg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 3/2/17 8:03 AM, Peter Eisentraut wrote:
> On 12/20/16 23:14, Jim Nasby wrote:
>> I've been looking at the performance of SPI calls within plpython.
>> There's a roughly 1.5x difference from equivalent python code just in
>> pulling data out of the SPI tuplestore. Some of that is due to an
>> inefficiency in how plpython is creating result dictionaries, but fixing
>> that is ultimately a dead-end: if you're dealing with a lot of results
>> in python, you want a tuple of arrays, not an array of tuples.
>
> There is nothing that requires us to materialize the results into an
> actual list of actual rows. We could wrap the SPI_tuptable into a
> Python object and implement __getitem__ or __iter__ to emulate sequence
> or mapping access.

Would it be possible to have that just pull tuples directly from the
executor? The overhead of populating the tuplestore just to drain it
again can become quite significant, and AFAICT it's completely unnecessary.

Unfortunately, I think adding support for that would be even more
invasive, which is why I haven't attempted it. On the flip side, I
believe that kind of an interface would be usable by plpgsql, whereas
the DestReceiver approach is not (AFAICT).
--
Jim Nasby, Chief Data Architect, OpenSCG

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2017-03-05 21:09:44 Re: Faster methods for getting SPI results (460% improvement)
Previous Message Robert Haas 2017-03-05 18:56:55 Re: REINDEX CONCURRENTLY 2.0