Thread: Questions about the internal of fastpath function call

Questions about the internal of fastpath function call

From
lee Richard
Date:
Hi,<br /><br />I am reading the source code of fastpath to understand the internal of fastpath. I can not understand
howdoes it send result to the client, I hope somebody can help me on this.<br /><br />I see it call it invoke the
functionin <br /><br />HandleFunctionRequest()<br />  -> retval = FunctionCallInvoke(&fcinfo);<br />  ->
SendFunctionResult(retval,fcinfo.isnull, fip->rettype, rformat);<br />              ->OidOutputFunctionCall()  
<br/>                      -> OutputFunctionCall()<br />                                ->  result =
DatumGetCString(FunctionCall1(flinfo,val));<br />                                       -> result =
FunctionCallInvoke(&fcinfo);<br/><br />but I can not see in where it send the tuples to the client, instead it 
invokeFunctionCallInvoke again. Can anyone tell me how it copy the tuples and send it to the client.<br /><br />Thanks
alot.<br /><br />Clipper <br /> <br />  <br /> 

Re: Questions about the internal of fastpath function call

From
Merlin Moncure
Date:
On Sun, May 8, 2011 at 8:01 AM, lee Richard <clipper.kenyon@gmail.com> wrote:
> Hi,
>
> I am reading the source code of fastpath to understand the internal of
> fastpath. I can not understand how does it send result to the client, I hope
> somebody can help me on this.
>
> I see it call it invoke the function in
>
> HandleFunctionRequest()
>   -> retval = FunctionCallInvoke(&fcinfo);
>   -> SendFunctionResult(retval, fcinfo.isnull, fip->rettype, rformat);
>               ->OidOutputFunctionCall()
>                       -> OutputFunctionCall()
>                                ->  result =
> DatumGetCString(FunctionCall1(flinfo, val));
>                                        -> result =
> FunctionCallInvoke(&fcinfo);
>
> but I can not see in where it send the tuples to the client, instead it
> invoke FunctionCallInvoke again. Can anyone tell me how it copy the tuples
> and send it to the client.

It can't: the fastpath function can only return a scalar. See the
client side docs.  The whole system is a kludge more or less.

merlin


Re: Questions about the internal of fastpath function call

From
lee Richard
Date:
Merlin,

Oh, I didnt realized that it does not support to return scalar, thanks a lot.

When it returns a single value,  I see it use the following function,

  SendFunctionCall
     result = DatumGetByteaP(FunctionCall1(flinfo, val));

I still can not see how it return a single return value to the client, and why it call FunctionCall1() again when it want to send the result.

Regards
Clipper

2011/5/8 Merlin Moncure <mmoncure@gmail.com>
On Sun, May 8, 2011 at 8:01 AM, lee Richard <clipper.kenyon@gmail.com> wrote:
> Hi,
>
> I am reading the source code of fastpath to understand the internal of
> fastpath. I can not understand how does it send result to the client, I hope
> somebody can help me on this.
>
> I see it call it invoke the function in
>
> HandleFunctionRequest()
>   -> retval = FunctionCallInvoke(&fcinfo);
>   -> SendFunctionResult(retval, fcinfo.isnull, fip->rettype, rformat);
>               ->OidOutputFunctionCall()
>                       -> OutputFunctionCall()
>                                ->  result =
> DatumGetCString(FunctionCall1(flinfo, val));
>                                        -> result =
> FunctionCallInvoke(&fcinfo);
>
> but I can not see in where it send the tuples to the client, instead it
> invoke FunctionCallInvoke again. Can anyone tell me how it copy the tuples
> and send it to the client.

It can't: the fastpath function can only return a scalar. See the
client side docs.  The whole system is a kludge more or less.

merlin

Re: Questions about the internal of fastpath function call

From
Tom Lane
Date:
lee Richard <clipper.kenyon@gmail.com> writes:
> I still can not see how it return a single return value to the client, and
> why it call FunctionCall1() again when it want to send the result.

pq_endmessage is where the bytes actually get pushed out to the client,
if that's what you're looking for.  The rest of the activity in
SendFunctionResult is just concerned with constructing the message to be
sent within "buf".
        regards, tom lane


Re: Questions about the internal of fastpath function call

From
lee Richard
Date:
Tom,<br /><br />Thanks a lot.<br /><br />The part I cant understand is I cant see where SendFunctionResult construct
thereturn value into the buf. I expect it should copy something in retval to buf, but I cant find any of this in the
code,the main logic of SendFunctionResult is:<br /><br /><pre class="fragment">00159             <a class="code"
href="http://doxygen.postgresql.org/lsyscache_8c.html#48d637426d06bfdf607eb29da3be558a">getTypeOutputInfo</a>(<a
class="code"href="http://doxygen.postgresql.org/structfp__info.html#2b1f02caad79fae010cdc5836a2fcb83">rettype</a>,
&typoutput,&typisvarlena); 
<a name="l00160"></a>00160             outputstr = <a class="code"
href="http://doxygen.postgresql.org/fmgr_8c.html#9b747dd35f098ab369b44e94f4708210">OidOutputFunctionCall</a>(typoutput,
retval);
<a name="l00161"></a>00161             <a class="code"
href="http://doxygen.postgresql.org/pqformat_8c.html#e6acc43bbc9bee686de201de82a26db5">pq_sendcountedtext</a>(&buf,
outputstr,strlen(outputstr), <span class="keyword">false</span>); 
<a name="l00162"></a>00162             <a class="code"
href="http://doxygen.postgresql.org/mcxt_8c.html#4de9741ca04b2f01a82d3de16a1d6bf2">pfree</a>(outputstr);</pre>Ithink it
shouldcopy the real result in OidOutputFunctionCall, but unfortunately I can only find it call FunctionCall1() again.
DoI miss something?<br /><br />If I copy the tuples returnned from pl module here, is it possible to send a vector
resultfrom fastpath function call?<br /><br /><div class="gmail_quote">2011/5/9 Tom Lane <span dir="ltr"><<a
href="mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a>></span><br/><blockquote class="gmail_quote" style="margin:0 0
0.8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">lee Richard <<a
href="mailto:clipper.kenyon@gmail.com">clipper.kenyon@gmail.com</a>>writes:<br /> > I still can not see how it
returna single return value to the client, and<br /> > why it call FunctionCall1() again when it want to send the
result.<br/><br /></div>pq_endmessage is where the bytes actually get pushed out to the client,<br /> if that's what
you'relooking for.  The rest of the activity in<br /> SendFunctionResult is just concerned with constructing the
messageto be<br /> sent within "buf".<br /><br />                        regards, tom lane<br /></blockquote></div><br
/>