Re: TRUNCATE on foreign table

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
Cc: Kohei KaiGai <kaigai(at)heterodb(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-22 00:39:21
Message-ID: CALj2ACVSCpLyzoCp10EpuvpbRwh2er56B4Dw42Gyp7EYdNxYew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 21, 2021 at 8:31 PM Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com> wrote:
> Applied. Attached is the updated version of the patch
> (truncate_foreign_table_dont_pass_only_clause_v2.patch).
> This patch includes the patch that Horiguchi-san posted upthead.
> I'm thinking to commit this patch at first.

+1.

> > 2) Instead of
> > on foreign tables. <literal>rels</literal> is the list of
> > <structname>Relation</structname> data structure that indicates
> > a foreign table to truncate.
> >
> > I think it is better with:
> > on foreign tables. <literal>rels</literal> is the list of
> > <structname>Relation</structname> data structures, where each
> > entry indicates a foreign table to truncate.
>
> Justin posted the patch that improves the documents including
> this description. I think that we should revisit that patch.
> Attached is the updated version of that patch.
> (truncate_foreign_table_docs_v1.patch)

One comment on truncate_foreign_table_docs_v1.patch:
1) I think it is "to be truncated"
+ <literal>rels</literal> is a list of <structname>Relation</structname>
+ data structures for each foreign table to truncated.
How about a slightly changed phrasing like below?
+ <literal>rels</literal> is a list of <structname>Relation</structname>
+ data structures of foreign tables to truncate.

Other than above, the patch LGTM.

> > 3) How about adding an extra para(after below para in
> > postgres_fdw.sgml) on WHY we don't push "ONLY" to foreign tables while
> > truncating? We could add to the same para for other options if at all
> > we don't choose to push them.
> > <command>DELETE</command>, or <command>TRUNCATE</command>.
> > (Of course, the remote user you have specified in your user mapping must
> > have privileges to do these things.)
>
> I agree to document the behavior that ONLY option is always ignored
> for foreign tables. But I'm not sure if we can document WHY.
> Because I could not find the past discussion about why ONLY option is
> ignored on SELECT, etc... Maybe it's enough to document the behavior?

+1 to specify in the documentation about ONLY option is always
ignored. But can we specify the WHY part within deparseTruncateSql, it
will be there for developer reference? I feel it's better if this
change goes with truncate_foreign_table_dont_pass_only_clause_v2.patch

> > 4) Isn't it better to mention the "ONLY" option is not pushed to remote
> > -- truncate with ONLY clause
> > TRUNCATE ONLY tru_ftable_parent;
> >
> > TRUNCATE ONLY tru_ftable; -- truncate both parent and child
> > SELECT count(*) FROM tru_ftable; -- 0
> >
> > 5) I may be missing something here, why is even after ONLY is ignored
> > in the below truncate command, the sum is 126? Shouldn't it truncate
> > both tru_ftable_parent and
> > -- truncate with ONLY clause
> > TRUNCATE ONLY tru_ftable_parent;
> > SELECT sum(id) FROM tru_ftable_parent; -- 126
>
> Because TRUNCATE ONLY command doesn't truncate tru_ftable_child talbe
> that inehrits tru_ftable_parent. No?

I get it. tru_ftable_child is a local child so ONLY doesn't truncate it.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2021-04-22 00:55:29 Re: PATCH: Add GSSAPI ccache_name option to libpq
Previous Message Tom Lane 2021-04-22 00:37:11 Re: problem with RETURNING and update row movement