Re: [BUG?] postgres_fdw incorrectly updates remote table if it has inherited children.

From: Kohei KaiGai <kaigai(at)heterodb(dot)com>
To: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUG?] postgres_fdw incorrectly updates remote table if it has inherited children.
Date: 2020-03-02 12:25:45
Message-ID: CAOP8fzajsUviPLMS9TmcejdpyFdH5wNcZSWwFG6J3H2yCh-xXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fujita-san,

> Unfortunately, I didn't have time to work on that (and won't in the
> development cycle for PG13.)
>
> > Indeed, it is not an ideal query plan to execute for each updated rows...
> >
> > postgres=# explain select * from rtable_parent where tableoid = 126397
> > and ctid = '(0,11)'::tid;
> > QUERY PLAN
> > -------------------------------------------------------------------------
> > Append (cost=0.00..5.18 rows=2 width=50)
> > -> Seq Scan on rtable_parent (cost=0.00..1.15 rows=1 width=31)
> > Filter: ((tableoid = '126397'::oid) AND (ctid = '(0,11)'::tid))
> > -> Tid Scan on rtable_child (cost=0.00..4.02 rows=1 width=68)
> > TID Cond: (ctid = '(0,11)'::tid)
> > Filter: (tableoid = '126397'::oid)
> > (6 rows)
>
> IIRC, I think one of Tom's concerns about the solution I proposed was
> that it added the tableoid restriction clause to the remote
> UPDATE/DELETE query even if the remote table is not an inheritance
> set. To add the clause only if the remote table is an inheritance
> set, what I have in mind is to 1) introduce a new postgres_fdw table
> option to indicate whether the remote table is an inheritance set or
> not, and 2) determine whether to add the clause or not, using the
> option.
>
I don't think the new options in postgres_fdw is a good solution because
remote table structure is flexible regardless of the local configuration in
foreign-table options. People may add inherited child tables after the
declaration of foreign-tables. It can make configuration mismatch.
Even if we always add tableoid=OID restriction on the remote query,
it shall be evaluated after the TidScan fetched the row pointed by ctid.
Its additional cost is limited.

And, one potential benefit is tableoid=OID restriction can be used to prune
unrelated partition leafs/inherited children at the planner stage.
Probably, it is a separated groundwork from postgres_fdw.
One planner considers the built-in rule for this kind of optimization,
enhancement at postgres_fdw will be quite simple, I guess.

How about your thought?

Best regards,
--
HeteroDB, Inc / The PG-Strom Project
KaiGai Kohei <kaigai(at)heterodb(dot)com>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2020-03-02 12:32:57 Re: Change atoi to strtol in same place
Previous Message Julien Rouhaud 2020-03-02 12:14:03 Re: Planning counters in pg_stat_statements (using pgss_store)