Re: Triggers on foreign tables - Mailing list pgsql-hackers

From Kohei KaiGai
Subject Re: Triggers on foreign tables
Date
Msg-id CADyhKSXU=ZMc+TOkZobOQ0QjauxSvtvDSRi-0KwC2gXkbr2AuA@mail.gmail.com
Whole thread Raw
In response to Re: Triggers on foreign tables  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Triggers on foreign tables  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
2013/10/15 Robert Haas <robertmhaas@gmail.com>:
> On Mon, Oct 14, 2013 at 5:24 PM, Kohei KaiGai <kaigai@kaigai.gr.jp> wrote:
>>>> And, I also want some comments from committers, not only from mine.
>>>
>>> +1
>>>
>> +1
>
> /me pokes head up.  I know I'm going to annoy people with this
> comment, but I feel like it's going to have to be made at some point
> by somebody, so here goes: I don't see the point of this feature.  If
> you want a trigger on a table, why not set it on the remote side?  A
> trigger on the foreign table won't be enforced consistently; it'll
> only work when the update is routed through the foreign table, not
> when people access the underlying table on the remote side through any
> other mechanism.  The number of useful things you can do this way
> seems fairly small.  Perhaps you could use a row-level trigger for
> RLS, to allow only certain rows on the foreign side to be updated, but
> even that seems like a slightly strange design: generally it'd be
> better to enforce the security as close to the target object as
> possible.
>
One reason we should support local triggers is that not all the data
source of FDW support remote trigger. It required FDW drivers to
have RDBMS as its backend, but no realistic assumption.
For example, file_fdw is unavailable to implement remote triggers.

One thing I'd like to know is, where is the goal of FDW feature.
It seems to me, FDW goes into a feature to manage external data
set as if regular tables. If it is right understanding, things we try to
support on foreign table is things we're supporting on regular tables,
such as triggers.

> There's another issue that concerns me here also: performance.  IIUC,
> an update of N tuples on the remote side currently requires N+1 server
> round-trips.  That is unspeakably awful, and we really oughta be
> looking for ways to make that number go down, by pushing the whole
> update to the remote side.  But obviously that won't be possible if
> there's a per-row trigger that has to be evaluated on the local side.
> Now, assuming somebody comes up with code that implements that
> optimization, we can just disable it when there are local-side
> triggers.  But, then you're back to having terrible performance.  So
> even if the use case for this seemed really broad, I tend to think
> performance concerns would sink most of the possible real-world uses.
>
We often have some case that we cannot apply fully optimized path
because of some reasons, like view has security-barrier, qualifier
contained volatile functions, and so on...
Trigger may be a factor to prevent fully optimized path, however,
it depends on the situation which one shall be prioritized; performance
or functionality.

Thanks,
-- 
KaiGai Kohei <kaigai@kaigai.gr.jp>



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Long paths for tablespace leads to uninterruptible hang in Windows
Next
From: Robert Haas
Date:
Subject: Re: Long paths for tablespace leads to uninterruptible hang in Windows