Re: modifying the tbale function

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, Islam Hegazy <islheg(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: modifying the tbale function
Date: 2007-03-19 14:25:27
Message-ID: 45FE9D57.7080207@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas wrote:
> Tom Lane wrote:
>> Neil Conway <neilc(at)samurai(dot)com> writes:
>>> Returning control to the backend for every row returned would likely
>>> be excessive, but you could return once every k rows and get most of
>>> the benefits of both approaches (k might be on the order of 1000).
>>
>> However, this still leaves us with no idea how to persuade perl, tcl,
>> python, et al to cooperate.
>
> It seem like a useful optimization for C-functions, though. I was
> caught by surprise a while ago when I realized that the way I've been
> using to create simple test data quickly:
>
>

Actually, I think we could teach the PLs to do it - just not
transparently, so we'd need to mark which functions used the new
protocol. Such functions would get a state object as an implied first
argument, so in plperl it might work like this (for a
generate_series-like function):

my $state = shift;
my $low = shift;
my $high = shift;
if ($state->{callstatus} eq 'firstcall')
{
$state->{counter} = $low;
}
elseif ($state->{callstatus} eq 'cleanup')
{
# do cleanup here
$state->{return_status} = 'cleaned';
return;
}
my $next = $state->{counter}++;
$state->{return_status} = $next < $high ? 'result' : 'last_result';
return $next;

To support this I think we'd need to do something like:

create function mygs(int, int)
returns setof int
language plperl
with srfstate
as $$ ... $$;

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2007-03-19 14:26:21 Re: CREATE INDEX and HOT (was Question: pg_classattributes and race conditions ?)
Previous Message Gregory Stark 2007-03-19 14:15:23 Re: Buildfarm feature request: some way to track/classify failures