Обсуждение: FDW oddity

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

FDW oddity

От
Andrew Dunstan
Дата:
I have just noticed something slightly odd. The traces (obtained by 
setting client_min_messages to debug1) from the blackhole FDW show that 
the handler function is called each time an INSERT is performed. This is 
not the case for SELECT, UPDATE or DELETE. It looks at first glance like 
a buglet. Can anyone suggest why this should be so?

cheers

andrerw



Re: FDW oddity

От
Tom Lane
Дата:
Andrew Dunstan <andrew@dunslane.net> writes:
> I have just noticed something slightly odd. The traces (obtained by 
> setting client_min_messages to debug1) from the blackhole FDW show that 
> the handler function is called each time an INSERT is performed. This is 
> not the case for SELECT, UPDATE or DELETE. It looks at first glance like 
> a buglet. Can anyone suggest why this should be so?

What do you mean by "the handler function", and for that matter what do
you define as "each time"?  The ExecForeignInsert method certainly ought
to be called once per row inserted, but the same is true of
ExecForeignUpdate and ExecForeignDelete.  The setup methods such as
BeginForeignModify should only be called once per query though.
        regards, tom lane



Re: FDW oddity

От
Andrew Dunstan
Дата:
On 04/11/2015 05:10 PM, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
>> I have just noticed something slightly odd. The traces (obtained by
>> setting client_min_messages to debug1) from the blackhole FDW show that
>> the handler function is called each time an INSERT is performed. This is
>> not the case for SELECT, UPDATE or DELETE. It looks at first glance like
>> a buglet. Can anyone suggest why this should be so?
> What do you mean by "the handler function", and for that matter what do
> you define as "each time"?  The ExecForeignInsert method certainly ought
> to be called once per row inserted, but the same is true of
> ExecForeignUpdate and ExecForeignDelete.  The setup methods such as
> BeginForeignModify should only be called once per query though.


I mean this function:
   Datum   blackhole_fdw_handler(PG_FUNCTION_ARGS)   {        FdwRoutine *fdwroutine = makeNode(FdwRoutine);
        elog(DEBUG1,"entering function %s",__func__);
        /* assign the handlers for the FDW */
     ...   }

And it is called at the beginning of every INSERT statement, before 
blackholePlanForeignModify() is called

cheers

andrew



Re: FDW oddity

От
Andrew Dunstan
Дата:
On 04/11/2015 07:30 PM, Andrew Dunstan wrote:
>
> On 04/11/2015 05:10 PM, Tom Lane wrote:
>> Andrew Dunstan <andrew@dunslane.net> writes:
>>> I have just noticed something slightly odd. The traces (obtained by
>>> setting client_min_messages to debug1) from the blackhole FDW show that
>>> the handler function is called each time an INSERT is performed. 
>>> This is
>>> not the case for SELECT, UPDATE or DELETE. It looks at first glance 
>>> like
>>> a buglet. Can anyone suggest why this should be so?
>> What do you mean by "the handler function", and for that matter what do
>> you define as "each time"?  The ExecForeignInsert method certainly ought
>> to be called once per row inserted, but the same is true of
>> ExecForeignUpdate and ExecForeignDelete.  The setup methods such as
>> BeginForeignModify should only be called once per query though.
>
>
> I mean this function:
>
>    Datum
>    blackhole_fdw_handler(PG_FUNCTION_ARGS)
>    {
>         FdwRoutine *fdwroutine = makeNode(FdwRoutine);
>
>         elog(DEBUG1,"entering function %s",__func__);
>
>         /* assign the handlers for the FDW */
>
>      ...
>    }
>
> And it is called at the beginning of every INSERT statement, before 
> blackholePlanForeignModify() is called


FYI, The FDW is available here: 
<https://bitbucket.org/adunstan/blackhole_fdw>

And here are the traces (notice the second call to blackhole_fdw_handler):
   [andrew@emma inst.bhtest.5709]$ bin/psql   psql (9.5devel)   Type "help" for help.
   andrew=# create extension blackhole_fdw;   CREATE EXTENSION   andrew=# create server blackhole foreign data wrapper
blackhole_fdw;  CREATE SERVER   andrew=# create foreign table bh(a text, b int) server blackhole;   CREATE FOREIGN
TABLE  andrew=# set client_min_messages = debug1;   SET   andrew=# insert into bh select 'a',x from
generate_series(1,5)x;   DEBUG:  entering function blackhole_fdw_handler   DEBUG:  entering function
blackholePlanForeignModify  DEBUG:  entering function blackhole_fdw_handler   DEBUG:  entering function
blackholeBeginForeignModify  DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeExecForeignInsert  DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeExecForeignInsert  DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeEndForeignModify  INSERT 0 5   andrew=# insert into bh select 'a',x from generate_series(1,5) x;   DEBUG:
enteringfunction blackhole_fdw_handler   DEBUG:  entering function blackholePlanForeignModify   DEBUG:  entering
functionblackholeBeginForeignModify   DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeExecForeignInsert  DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeExecForeignInsert  DEBUG:  entering function blackholeExecForeignInsert   DEBUG:  entering function
blackholeEndForeignModify  INSERT 0 5   andrew=#
 

cheers

andrew





Re: FDW oddity

От
Andrew Dunstan
Дата:
On 04/11/2015 07:30 PM, Andrew Dunstan wrote:
>
> On 04/11/2015 05:10 PM, Tom Lane wrote:
>> Andrew Dunstan <andrew@dunslane.net> writes:
>>> I have just noticed something slightly odd. The traces (obtained by
>>> setting client_min_messages to debug1) from the blackhole FDW show that
>>> the handler function is called each time an INSERT is performed. 
>>> This is
>>> not the case for SELECT, UPDATE or DELETE. It looks at first glance 
>>> like
>>> a buglet. Can anyone suggest why this should be so?
>> What do you mean by "the handler function", and for that matter what do
>> you define as "each time"?  The ExecForeignInsert method certainly ought
>> to be called once per row inserted, but the same is true of
>> ExecForeignUpdate and ExecForeignDelete.  The setup methods such as
>> BeginForeignModify should only be called once per query though.
>
>
> I mean this function:
>
>    Datum
>    blackhole_fdw_handler(PG_FUNCTION_ARGS)
>    {
>         FdwRoutine *fdwroutine = makeNode(FdwRoutine);
>
>         elog(DEBUG1,"entering function %s",__func__);
>
>         /* assign the handlers for the FDW */
>
>      ...
>    }
>
> And it is called at the beginning of every INSERT statement, before 
> blackholePlanForeignModify() is called




Seems to be explained by this comment in createplan.c:
        /*         * If possible, we want to get the FdwRoutine from our 
RelOptInfo for         * the table.  But sometimes we don't have a RelOptInfo and 
must get         * it the hard way.  (In INSERT, the target relation is not 
scanned,         * so it's not a baserel; and there are also corner cases for         * updatable views where the
targetrel isn't a baserel.)         */
 

cheers

andrew