Re: TRUNCATE on foreign tables

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Kohei KaiGai <kaigai(at)heterodb(dot)com>
Cc: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: TRUNCATE on foreign tables
Date: 2020-01-20 13:50:21
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 20, 2020 at 11:30:34AM +0900, Kohei KaiGai wrote:
> Sorry, it was a midnight job on Friday.

Should I be, err, worried about that? ;)

> Please check the attached patch.

+ switch (behavior)
+ {
+ appendStringInfoString(buf, " RESTRICT");
+ break;
+ appendStringInfoString(buf, " CASCADE");
+ break;
+ default:
+ elog(ERROR, "Bug? unexpected DropBehavior (%d)",
+ break;
+ }
Here, you can actually remove the default clause. By doing so,
compilation would generate a warning if a new value is added to
DropBehavior if it is not listed. So anybody adding a new value to
the enum will need to think about this code path.

+ ereport(ERROR,
+ errmsg("foreign data wrapper \"%s\" on behalf of the
foreign table \"%s\" does not support TRUNCATE",
+ fdw->fdwname, relname)));
I see two problems here:
- The error message is too complicated. I would just use "cannot
truncate foreign table \"%s\"".
- The error code should be ERRCODE_FEATURE_NOT_SUPPORTED.

The docs for the FDW description can be improved. I found that a
large portion of it used rather unclear English, and that things were
not clear enough regarding the use of a list of relations, when an
error is raised because ExecForeignTruncate is NULL, etc. I have also
cut the last paragraph which is actually implementation-specific
(think for example about callbacks at xact commit/abort time).

Documentation needs to be added to postgres_fdw about the truncation
support. Particularly, providing details about the possibility to do
truncates in our shot for a set of relations so as dependencies are
automatically handled is an advantage to mention.

There is no need to include the truncate routine in
ForeignTruncateInfo, as the server OID can be used to find it.

Another thing is that I would prefer splitting the patch into two
separate commits, so attached are two patches:
- 0001 for the addition of the in-core API
- 0002 for the addition of support in postgres_fdw.

I have spent a good amount of time polishing 0001, tweaking the docs,
comments, error messages and a bit its logic. I am getting
comfortable with it, but it still needs an extra lookup, an indent run
which has some noise and I lacked of time today. 0002 has some of its
issues fixed and I have not reviewed it fully yet. There are still
some places not adapted in it (why do you use "Bug?" in all your
elog() messages by the way?), so the postgres_fdw part needs more
attention. Could you think about some docs for it by the way?

Attachment Content-Type Size
0001-Add-FDW-callback-for-support-of-TRUNCATE.patch text/x-diff 9.6 KB
0002-Add-support-for-TRUNCATE-in-postgres_fdw.patch text/x-diff 13.0 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message a.kondratov 2020-01-20 14:50:06 Re: Physical replication slot advance is not persistent
Previous Message Peter Eisentraut 2020-01-20 13:34:29 Re: [HACKERS] kqueue