Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-29-2008, 08:31 PM
dv @ nabble
 
Posts: n/a
Default SRF in SFRM_ValuePerCall mode

Hi all,

I am working on implementation of custom "C" SRF for our team. The SRF uses
SFRM_ValuePerCall mode. I know that sometimes even in SFRM_ValuePerCall mode
all the rows returned from SRF are "materialized" (for performing JOINs, for
example). But it looks like even in cases when SELECT is very simple and
it's obvious that no more rows will be read from the SRF, SRF is being
iterated till it returns SRF_RETURN_DONE(...). So, in case when the SRF
returns 1000 rows but the SELECT is querying only the first one (with LIMIT
1), all 1000 iterations will be performed and 999 rows will be created,
allocated, returned and thrown away.

Is there a way to avoid unnecessary calls of SRF in this case? Is it a
"feature"?

In the attachment you can find the simplest example of SRF function working
in SFRM_ValuePerCall mode.
I have created it while researching the issue. After building it, use the
following SQLs:

-- this creates the test function
CREATE OR REPLACE FUNCTION vpc() RETURNS setof record
AS 'plbsh.dll', 'vpc' LANGUAGE 'C';

-- this returns 10 rows
SELECT * FROM vpc() AS T(a INT, b TEXT);

-- this returns 1 row, but performs 10 calls
SELECT * FROM vpc() AS T(a INT, b TEXT) LIMIT 1;

Regards,
Denis


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-29-2008, 08:31 PM
Heikki Linnakangas
 
Posts: n/a
Default Re: SRF in SFRM_ValuePerCall mode

dv @ nabble wrote:
> I am working on implementation of custom "C" SRF for our team. The SRF uses
> SFRM_ValuePerCall mode. I know that sometimes even in SFRM_ValuePerCall
> mode
> all the rows returned from SRF are "materialized" (for performing JOINs,
> for
> example).


Yep, they are unfortunately always materialized. Back when set returning
functions were implemented, the original patch did actually support true
"value per call" mode, where the whole result set was not materialized.
However, it was dropped because of some issues I can't remember off the
top of my head. The value-per-call API was committed, so that it was
already in place when someone gets around to implement the backend
support for it.

However, no-one has bothered to do that to this date. Hannu Krosing
showed some interest in it recently, though:
http://archives.postgresql.org/pgsql...4/msg00345.php. I
would love to see it happen.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-29-2008, 08:31 PM
Tom Lane
 
Posts: n/a
Default Re: SRF in SFRM_ValuePerCall mode

"Heikki Linnakangas" <heikki@enterprisedb.com> writes:
> dv @ nabble wrote:
>> I am working on implementation of custom "C" SRF for our team. The SRF uses
>> SFRM_ValuePerCall mode. I know that sometimes even in SFRM_ValuePerCall
>> mode
>> all the rows returned from SRF are "materialized" (for performing JOINs,
>> for
>> example).


> Yep, they are unfortunately always materialized. Back when set returning
> functions were implemented, the original patch did actually support true
> "value per call" mode, where the whole result set was not materialized.
> However, it was dropped because of some issues I can't remember off the
> top of my head. The value-per-call API was committed, so that it was
> already in place when someone gets around to implement the backend
> support for it.


That's a rather revisionist view of history ;-) Value-per-call mode has
always been there, just not in nodeFunctionscan.c.

If you're not joining to the function result, and you don't need the
ability to determine its result type on the fly, you could declare it
as returning a specific rowtype and then call it in the targetlist:

select vpc();

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-29-2008, 08:31 PM
dv @ nabble
 
Posts: n/a
Default Re: SRF in SFRM_ValuePerCall mode

OK,

Thank you for the explanation, I hope this will be implemented in future.
We will try and find a workaround to this issue until then.

Denis


----- Original Message -----
From: "Heikki Linnakangas" <heikki@enterprisedb.com>
To: "dv @ nabble" <dvnabble@gmail.com>
Cc: "pgsql-hackers list" <pgsql-hackers@postgresql.org>
Sent: Monday, April 28, 2008 1:56 PM
Subject: Re: [HACKERS] SRF in SFRM_ValuePerCall mode


> dv @ nabble wrote:
>> I am working on implementation of custom "C" SRF for our team. The SRF
>> uses
>> SFRM_ValuePerCall mode. I know that sometimes even in SFRM_ValuePerCall
>> mode
>> all the rows returned from SRF are "materialized" (for performing JOINs,
>> for
>> example).

>
> Yep, they are unfortunately always materialized. Back when set returning
> functions were implemented, the original patch did actually support true
> "value per call" mode, where the whole result set was not materialized.
> However, it was dropped because of some issues I can't remember off the
> top of my head. The value-per-call API was committed, so that it was
> already in place when someone gets around to implement the backend support
> for it.
>
> However, no-one has bothered to do that to this date. Hannu Krosing showed
> some interest in it recently, though:
> http://archives.postgresql.org/pgsql...4/msg00345.php. I would
> love to see it happen.
>
> --
> Heikki Linnakangas
> EnterpriseDB http://www.enterprisedb.com



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-29-2008, 08:31 PM
dv @ nabble
 
Posts: n/a
Default Re: SRF in SFRM_ValuePerCall mode

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Heikki Linnakangas" <heikki@enterprisedb.com>
Cc: "dv @ nabble" <dvnabble@gmail.com>; "pgsql-hackers list"
<pgsql-hackers@postgresql.org>
Sent: Monday, April 28, 2008 5:07 PM
Subject: Re: [HACKERS] SRF in SFRM_ValuePerCall mode


> "Heikki Linnakangas" <heikki@enterprisedb.com> writes:
>> dv @ nabble wrote:
>>> I am working on implementation of custom "C" SRF for our team. The SRF
>>> uses
>>> SFRM_ValuePerCall mode. I know that sometimes even in SFRM_ValuePerCall
>>> mode
>>> all the rows returned from SRF are "materialized" (for performing JOINs,
>>> for
>>> example).

>
>> Yep, they are unfortunately always materialized. Back when set returning
>> functions were implemented, the original patch did actually support true
>> "value per call" mode, where the whole result set was not materialized.
>> However, it was dropped because of some issues I can't remember off the
>> top of my head. The value-per-call API was committed, so that it was
>> already in place when someone gets around to implement the backend
>> support for it.

>
> That's a rather revisionist view of history ;-) Value-per-call mode has
> always been there, just not in nodeFunctionscan.c.
>
> If you're not joining to the function result, and you don't need the
> ability to determine its result type on the fly, you could declare it
> as returning a specific rowtype and then call it in the targetlist:
>
> select vpc();


You mean make the function return the only row?
This is not the functionality we need. What we want is to create a SETOF
function that will
emulate a table and query this "table" with WHERE filter and LIMIT clauses
to limit the row
count we want to return. We might pass the filter and the limit to the
function, but we want to
implement it in more natural way.

Thanks,
Denis


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-29-2008, 08:31 PM
Tom Lane
 
Posts: n/a
Default Re: SRF in SFRM_ValuePerCall mode

"dv @ nabble" <dvnabble@gmail.com> writes:
> From: "Tom Lane" <tgl@sss.pgh.pa.us>
>> If you're not joining to the function result, and you don't need the
>> ability to determine its result type on the fly, you could declare it
>> as returning a specific rowtype and then call it in the targetlist:
>>
>> select vpc();


> You mean make the function return the only row?


No, I'm pointing out that ValuePerCall SRFs can be called from the
targetlist.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:41 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145