Questions about the internal of fastpath function call

Поиск
Список
Период
Сортировка
Искать

Questions about the internal of fastpath function call

От:
lee Richard <clipper.kenyon@gmail.com>
Дата:
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.

Thanks a lot.

Clipper
 
 

Re: Questions about the internal of fastpath function call

От:
Merlin Moncure <mmoncure@gmail.com>
Дата:
On Sun, May 8, 2011 at 8:01 AM, lee Richard  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

От:
lee Richard <clipper.kenyon@gmail.com>
Дата:
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

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
lee Richard  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

От:
lee Richard <clipper.kenyon@gmail.com>
Дата:
Tom,

Thanks a lot.

The part I cant understand is I cant see where SendFunctionResult construct the return 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:

00159             getTypeOutputInfo(rettype, &typoutput, &typisvarlena);
00160             outputstr = OidOutputFunctionCall(typoutput, retval);
00161             pq_sendcountedtext(&buf, outputstr, strlen(outputstr), false);
00162             pfree(outputstr);
I think it should copy the real result in OidOutputFunctionCall, but unfortunately I can only find it call FunctionCall1() again. Do I miss something?

If I copy the tuples returnned from pl module here, is it possible to send a vector result from fastpath function call?

2011/5/9 Tom Lane <tgl@sss.pgh.pa.us>
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

FAQ