Re: Odd behavior in foreign table modification (Was: Re: Optimization for updating foreign tables in Postgres FDW)

From: Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Odd behavior in foreign table modification (Was: Re: Optimization for updating foreign tables in Postgres FDW)
Date: 2016-01-21 09:55:01
Message-ID: 56A0AAF5.6040406@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2016/01/19 19:04, Thom Brown wrote:
> On 12 January 2016 at 11:49, Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
>> On 2016/01/12 20:36, Thom Brown wrote:

>>> On 8 January 2016 at 05:08, Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>
>>> wrote:

>>>>> On 2016/01/06 20:37, Thom Brown wrote:
>>>>>>
>>>>>> I've run into an issue:
>>>>>>
>>>>>> *# UPDATE master_customers SET id = 22 WHERE id = 16 RETURNING
>>>>>> tableoid::regclass;
>>>>>> ERROR:
>>>>>> CONTEXT: Remote SQL command: UPDATE public.customers SET id = 22
>>>>>> WHERE ((id = 16)) RETURNING NULL

>>>> While working on this, I noticed that the existing postgres_fdw system
>>>> shows
>>>> similar behavior, so I changed the subject.
>>>>
>>>> IIUC, the reason for that is when the local query specifies "RETURNING
>>>> tableoid::regclass", the FDW has fmstate->has_returning=false while the
>>>> remote query executed at ModifyTable has "RETURNING NULL", as shown in
>>>> the
>>>> above example; that would cause an abnormal exit in executing the remote
>>>> query in postgresExecForeignUpdate, since that the FDW would get
>>>> PGRES_TUPLES_OK as a result of the query while the FDW would think that
>>>> the
>>>> right result to get should be PGRES_COMMAND_OK, from the flag
>>>> fmstate->has_returning=false.

>>>> Attached is a patch to fix that.

>>> I can't apply this patch in tandem with FDW DML pushdown patch (either
>>> v2 or v3).

>> That patch is for fixing the similar issue in the existing postgres_fdw
>> system. So, please apply that patch without the DML pushdown patch. If
>> that patch is reasonable as a fix for the issue, I'll update the DML
>> pushdown patch (v3) on top of that patch.

> The patch seems to work for me:
>
> Before:
>
> *# UPDATE master_customers SET id = 22 WHERE id = 1 RETURNING
> tableoid::regclass;
> ERROR:
> CONTEXT: Remote SQL command: UPDATE public.customers SET id = $2
> WHERE ctid = $1 RETURNING NULL
>
> After:
>
> *# UPDATE master_customers SET id = 22 WHERE id = 1 RETURNING
> tableoid::regclass;
> tableoid
> ------------------
> remote.customers
> (1 row)
>
> UPDATE 1

Thanks for the testing!

I updated the DML pushdown patch on top of Robert's version of this
bugfix patch. Please see

http://www.postgresql.org/message-id/56A0A9F0.9090304@lab.ntt.co.jp

Best regards,
Etsuro Fujita

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2016-01-21 10:09:19 Re: [PoC] Asynchronous execution again (which is not parallel)
Previous Message Etsuro Fujita 2016-01-21 09:50:40 Re: Optimization for updating foreign tables in Postgres FDW