Re: BEFORE UPDATE trigger on postgres_fdw table not work
Etsuro Fujita <etsuro.fujita@gmail.com>
From: Etsuro Fujita <etsuro.fujita@gmail.com>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
Shohei Mochizuki <shohei.mochizuki@toshiba.co.jp>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2019-06-11T09:09:20Z
Lists: pgsql-hackers
Amit-san, On Tue, Jun 11, 2019 at 1:31 PM Amit Langote <amitlangote09@gmail.com> wrote: > > On Tue, Jun 11, 2019 at 10:51 AM Etsuro Fujita <etsuro.fujita@gmail.com> wrote: > > > Sorry, my explanation was not good; I should have said that in UPDATE, > > > we fetch columns not mentioned in the SQL query as well (even if the > > > target table doesn't have relevant triggers), so there would be no > > > hazard Tom mentioned above, IIUC. > > Sorry but I still don't understand. Sure, *some* columns of the table > not present in the UPDATE statement are fetched, but the column(s) > being assigned to are not fetched. > > -- before creating a trigger > explain verbose update rem1 set a = 1; > QUERY PLAN > ───────────────────────────────────────────────────────────────────────────── > Update on public.rem1 (cost=100.00..182.27 rows=2409 width=14) > Remote SQL: UPDATE public.loc1 SET a = $2, b = $3 WHERE ctid = $1 > -> Foreign Scan on public.rem1 (cost=100.00..182.27 rows=2409 width=14) > Output: 1, b, ctid > Remote SQL: SELECT b, ctid FROM public.loc1 FOR UPDATE > > In this case, column 'a' is not present in the rows that are fetched > to be updated, because it's only assigned to and not referenced > anywhere (such as in WHERE clauses). Which is understandable, because > fetching it would be pointless. Right, but what I'm saying here is what you call "some columns". For UPDATE, the planner adds any unassigned columns to the targetlist (see expand_targetlist()), so the reltarget for the target relation would include such columns, leading to fetching them from the remote in postgres_fdw even if the target table doesn't have relevant triggers. Best regards, Etsuro Fujita
Commits
-
postgres_fdw: Account for triggers in non-direct remote UPDATE planning.
- 1a3d9f62c1d1 9.4.23 landed
- eddb79705f65 9.5.18 landed
- 1ade21e7facc 9.6.14 landed
- 0f2b234263ef 10.9 landed
- 214460182161 11.4 landed
- 8b6da83d162c 12.0 landed
-
Offer triggers on foreign tables.
- 7cbe57c34dec 9.4.0 cited