From: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
---|---|
To: | Kohei KaiGai <kaigai(at)heterodb(dot)com> |
Cc: | Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Kazutaka Onishi <onishi(at)heterodb(dot)com>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, Ibrar Ahmed <ibrar(dot)ahmad(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> |
Subject: | Re: TRUNCATE on foreign table |
Date: | 2021-04-13 12:03:29 |
Message-ID: | CALj2ACVuygqS7rMGHGs-W_JGx6pjdAFitTZuNfWdV2QaBaOc+A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Apr 13, 2021 at 2:37 PM Kohei KaiGai <kaigai(at)heterodb(dot)com> wrote:
> Here are two points to discuss.
>
> Regarding to the FDW-APIs, yes, nobody can deny someone want to implement
> their own FDW module that adds special handling when its foreign table
> is specified
> with ONLY-clause, even if we usually ignore.
>
>
> On the other hand, when we consider a foreign table is an abstraction
> of an external
> data source, at least, the current postgres_fdw's behavior is not consistent.
>
> When a foreign table by postgres_fdw that maps a remote parent table,
> has a local
> child table,
>
> This command shows all the rows from both of local and remote.
>
> postgres=# select * from f_table ;
> id | v
> ----+-----------------------------
> 1 | remote table t_parent id=1
> 2 | remote table t_parent id=2
> 3 | remote table t_parent id=3
> 10 | remote table t_child1 id=10
> 11 | remote table t_child1 id=11
> 12 | remote table t_child1 id=12
> 20 | remote table t_child2 id=20
> 21 | remote table t_child2 id=21
> 22 | remote table t_child2 id=22
> 50 | it is l_child id=50
> 51 | it is l_child id=51
> 52 | it is l_child id=52
> 53 | it is l_child id=53
> (13 rows)
>
> If f_table is specified with "ONLY", it picks up only the parent table
> (f_table),
> however, ONLY-clause is not push down to the remote side.
>
> postgres=# select * from only f_table ;
> id | v
> ----+-----------------------------
> 1 | remote table t_parent id=1
> 2 | remote table t_parent id=2
> 3 | remote table t_parent id=3
> 10 | remote table t_child1 id=10
> 11 | remote table t_child1 id=11
> 12 | remote table t_child1 id=12
> 20 | remote table t_child2 id=20
> 21 | remote table t_child2 id=21
> 22 | remote table t_child2 id=22
> (9 rows)
>
> On the other hands, TRUNCATE ONLY f_table works as follows...
>
> postgres=# truncate only f_table;
> TRUNCATE TABLE
> postgres=# select * from f_table ;
> id | v
> ----+-----------------------------
> 10 | remote table t_child1 id=10
> 11 | remote table t_child1 id=11
> 12 | remote table t_child1 id=12
> 20 | remote table t_child2 id=20
> 21 | remote table t_child2 id=21
> 22 | remote table t_child2 id=22
> 50 | it is l_child id=50
> 51 | it is l_child id=51
> 52 | it is l_child id=52
> 53 | it is l_child id=53
> (10 rows)
>
> It eliminates the rows only from the remote parent table although it
> is a part of the foreign table.
>
> My expectation at the above command shows rows from the local child
> table (id=50...53).
Yeah, ONLY clause is not pushed to the remote server in case of SELECT
commands. This is also true for DELETE and UPDATE commands on foreign
tables. I'm not sure if it wasn't thought necessary or if there is an
issue to push it or I may be missing something here. I think we can
start a separate thread to see other hackers' opinions on this.
I'm not sure whether all the clauses that are possible for
SELECT/UPDATE/DELETE/INSERT with local tables are pushed to the remote
server by postgres_fdw.
Well, now foreign TRUNCATE pushes the ONLY clause to the remote server
which is inconsistent when compared to SELECT/UPDATE/DELETE commands.
If we were to keep it consistent across all foreign commands that
ONLY clause is not pushed to remote server, then we can restrict for
TRUNCATE too and even if "TRUNCATE ONLY foreign_tbl" is specified,
just pass "TRUNCATE foreign_tbl" to remote server. Having said that, I
don't see any real problem in pushing the ONLY clause, at least in
case of TRUNCATE.
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Justin Pryzby | 2021-04-13 12:31:39 | Re: [PATCH] force_parallel_mode and GUC categories |
Previous Message | Justin Pryzby | 2021-04-13 11:58:33 | Re: Old Postgresql version on i7-1165g7 |