Re: Terminating a SETOF function call sequence

Lists: pgsql-hackers
From: Thomas Hallgren <thhal(at)mailblocks(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Terminating a SETOF function call sequence
Date: 2005-02-17 09:14:05
Message-ID: thhal-05vjvAvGSxicdUgw3oZ3y508WzP9lKS@mailblocks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Some SQL constructs will be satisfied before all rows of a set has been
examined. I'm thinking of for instance:

EXISTS(SELECT * FROM y WHERE y.a > 0)

If the first row of collection y fulfills the WHERE predicate, there's
no reason to continue perusing the rest of the rows. Now, what if 'y' is
a function returning SETOF something? I see only one possible way for a
C-function to detect that it doesn't need to return more rows and that
would be if the FuncCallContext call_cntr reaches max_calls.

My question is, what happens when the evaluator doesn't need more rows?
Will it:
a) call the function with call_cntr >= max_calls?
b) continue calling until the set is exhausted anyway?
c) simply stop calling?

a) seems unlikely since max_calls is set by the user, b) doesn't seem
very optimal, and c) would be very bad since it doesn't give me any
chance to release the resources that where used in order to produce the
rows.

Regards,
Thomas Hallgren


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Hallgren <thhal(at)mailblocks(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a SETOF function call sequence
Date: 2005-02-17 15:28:53
Message-ID: 7126.1108654133@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thomas Hallgren <thhal(at)mailblocks(dot)com> writes:
> My question is, what happens when the evaluator doesn't need more rows?
> Will it:
> a) call the function with call_cntr >= max_calls?
> b) continue calling until the set is exhausted anyway?
> c) simply stop calling?

(c)

> a) seems unlikely since max_calls is set by the user, b) doesn't seem
> very optimal, and c) would be very bad since it doesn't give me any
> chance to release the resources that where used in order to produce the
> rows.

This is what RegisterExprContextCallback is for.

regards, tom lane


From: Thomas Hallgren <thhal(at)mailblocks(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Terminating a SETOF function call sequence
Date: 2005-02-17 15:39:16
Message-ID: thhal-0KVPwApWVxicchSrHc3ZxJlQzn5JvSt@mailblocks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>Thomas Hallgren <thhal(at)mailblocks(dot)com> writes:
>
>
>>My question is, what happens when the evaluator doesn't need more rows?
>>Will it:
>>a) call the function with call_cntr >= max_calls?
>>b) continue calling until the set is exhausted anyway?
>>c) simply stop calling?
>>
>>
>
>(c)
>
>
>
>>a) seems unlikely since max_calls is set by the user, b) doesn't seem
>>very optimal, and c) would be very bad since it doesn't give me any
>>chance to release the resources that where used in order to produce the
>>rows.
>>
>>
>
>This is what RegisterExprContextCallback is for.
>
> regards, tom lane
>
>
Thanks Tom,
This is exactly what I need. I didn't know that such a callback existed.
Perhaps it should be mentioned in the documentation chapter that talks
about SETOF and C-functions?

Regards,
Thomas Hallgren