pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Kohei KaiGai <kaigai@heterodb.com>
Cc: Kazutaka Onishi <onishi@heterodb.com>
Cc: Zhihong Yu <zyu@yugabyte.com>
Cc: Amit Langote <amitlangote09@gmail.com>
Cc: Ibrar Ahmed <ibrar.ahmad@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Subject: Re: TRUNCATE on foreign table
Date: Thu, 22 Apr 2021 00:01:35 +0900
Message-ID: <94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com> (raw)
In-Reply-To: <CALj2ACUvuYrCi7G54Yov0oc_D9Zz6O157mtru72J-zxYYWf_3w@mail.gmail.com>
References: <CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com>
	<CAOP8fzaWkX7O3QmKtJ9DEtBfwaR5+OL2KfycnYNrxPC9zEG2QQ@mail.gmail.com>
	<eac9329f-f285-2044-1974-b3d0d0aa5950@oss.nttdata.com>
	<CAOP8fzYgM=bxsDgtnucx4k_QUdUknri4UEdPxr9bkkfqRYoRog@mail.gmail.com>
	<CAOP8fzZf+=RQFmwLRw5s1KKgApuXmYPC76nmUZGck4=e7AJj8Q@mail.gmail.com>
	<2209ecd8-0382-cbcb-5717-15da49535237@oss.nttdata.com>
	<CAOP8fzbCfju6TT4DYqw5KC9tgTN4UzpagJnY3WRXfiR9R58M1Q@mail.gmail.com>
	<CALj2ACVuygqS7rMGHGs-W_JGx6pjdAFitTZuNfWdV2QaBaOc+A@mail.gmail.com>
	<CAOP8fzYbU2g4wFJAcxJkaESWV1NxJL3LYf=jXti-JL3fcvPgxw@mail.gmail.com>
	<70310892-3572-f143-a692-e9aa4322a914@oss.nttdata.com>
	<CALj2ACX7UYyg9tsqqS7akc5eSiwBLevM-ZfX00haFrdZrq2tgg@mail.gmail.com>
	<a1975489-a32d-dc2b-c117-cd36495d82fa@oss.nttdata.com>
	<CALj2ACUvkyyEP0YM5WPGfgXtTqYTMBE2Jzy8C1oX6_DcHTxf=g@mail.gmail.com>
	<2ec345ad-9a7b-a21f-8a1b-04c0537ea9b8@oss.nttdata.com>
	<CALj2ACUvuYrCi7G54Yov0oc_D9Zz6O157mtru72J-zxYYWf_3w@mail.gmail.com>



On 2021/04/16 15:13, Bharath Rupireddy wrote:
> On Fri, Apr 16, 2021 at 8:24 AM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
>> We are still discussing whether RESTRICT option should be pushed down to
>> a foreign data wrapper. But ISTM at least we could reach the consensus about
>> the drop of extra information for each foreign table. So what about applying
>> the attached patch and remove the extra information at first?
> 
> Thanks for the patch, here are some comments:

Thanks for the review!

> 
> 1) Maybe new empty lines would be better so that the code doesn't look
> cluttered:
>          relids = lappend_oid(relids, myrelid);   --> a new line after this.
>          /* Log this relation only if needed for logical decoding */
>          if (RelationIsLogicallyLogged(rel))
> 
>          relids = lappend_oid(relids, childrelid);  --> a new line after this.
>          /* Log this relation only if needed for logical decoding */
> 
>          relids = lappend_oid(relids, relid);  --> a new line after this.
>          /* Log this relation only if needed for logical decoding */
>          if (RelationIsLogicallyLogged(rel))

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.



> 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)


> 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?


> 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?

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments: download all (2 files, .tar.gz)

truncate_foreign_table_dont_pass_only_clause_v2.patch (text/plain, 15.4K) download diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index bdc4c3620d..7a798530e3 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -2179,24 +2179,19 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs) void deparseTruncateSql(StringInfo buf, List *rels, - List *rels_extra, DropBehavior behavior, bool restart_seqs) { - ListCell *lc1, - *lc2; + ListCell *cell; appendStringInfoString(buf, "TRUNCATE "); - forboth(lc1, rels, lc2, rels_extra) + foreach(cell, rels) { - Relation rel = lfirst(lc1); - int extra = lfirst_int(lc2); + Relation rel = lfirst(cell); - if (lc1 != list_head(rels)) + if (cell != list_head(rels)) appendStringInfoString(buf, ", "); - if (extra & TRUNCATE_REL_CONTEXT_ONLY) - appendStringInfoString(buf, "ONLY "); deparseRelation(buf, rel); } diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out index 5070d93239..d32f291089 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -8218,13 +8218,13 @@ drop table loc3; -- test for TRUNCATE -- =================================================================== CREATE TABLE tru_rtable0 (id int primary key); -CREATE TABLE tru_rtable1 (id int primary key); CREATE FOREIGN TABLE tru_ftable (id int) SERVER loopback OPTIONS (table_name 'tru_rtable0'); INSERT INTO tru_rtable0 (SELECT x FROM generate_series(1,10) x); CREATE TABLE tru_ptable (id int) PARTITION BY HASH(id); CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable FOR VALUES WITH (MODULUS 2, REMAINDER 0); +CREATE TABLE tru_rtable1 (id int primary key); CREATE FOREIGN TABLE tru_ftable__p1 PARTITION OF tru_ptable FOR VALUES WITH (MODULUS 2, REMAINDER 1) SERVER loopback OPTIONS (table_name 'tru_rtable1'); @@ -8388,22 +8388,23 @@ SELECT sum(id) FROM tru_ftable; -- 95 95 (1 row) -TRUNCATE ONLY tru_ftable; -- truncate only parent portion -SELECT sum(id) FROM tru_ftable; -- 60 - sum ------ - 60 +TRUNCATE ONLY tru_ftable; -- truncate both of parent and child +SELECT count(*) FROM tru_ftable; -- 0 + count +------- + 0 (1 row) INSERT INTO tru_rtable0 (SELECT x FROM generate_series(21,25) x); -SELECT sum(id) FROM tru_ftable; -- 175 +INSERT INTO tru_rtable0_child (SELECT x FROM generate_series(26,30) x); +SELECT sum(id) FROM tru_ftable; -- 255 sum ----- - 175 + 255 (1 row) TRUNCATE tru_ftable; -- truncate both of parent and child -SELECT count(*) FROM tru_ftable; -- empty +SELECT count(*) FROM tru_ftable; -- 0 count ------- 0 diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index c590f374c6..c521cba3fc 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -401,7 +401,6 @@ static void postgresExplainForeignModify(ModifyTableState *mtstate, static void postgresExplainDirectModify(ForeignScanState *node, ExplainState *es); static void postgresExecForeignTruncate(List *rels, - List *rels_extra, DropBehavior behavior, bool restart_seqs); static bool postgresAnalyzeForeignTable(Relation relation, @@ -2881,7 +2880,6 @@ postgresExplainDirectModify(ForeignScanState *node, ExplainState *es) */ static void postgresExecForeignTruncate(List *rels, - List *rels_extra, DropBehavior behavior, bool restart_seqs) { @@ -2964,7 +2962,7 @@ postgresExecForeignTruncate(List *rels, /* Construct the TRUNCATE command string */ initStringInfo(&sql); - deparseTruncateSql(&sql, rels, rels_extra, behavior, restart_seqs); + deparseTruncateSql(&sql, rels, behavior, restart_seqs); /* Issue the TRUNCATE command to remote server */ do_sql_command(conn, sql.data); diff --git a/contrib/postgres_fdw/postgres_fdw.h b/contrib/postgres_fdw/postgres_fdw.h index 5d44b75314..9591c0f6c2 100644 --- a/contrib/postgres_fdw/postgres_fdw.h +++ b/contrib/postgres_fdw/postgres_fdw.h @@ -209,7 +209,6 @@ extern void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs); extern void deparseTruncateSql(StringInfo buf, List *rels, - List *rels_extra, DropBehavior behavior, bool restart_seqs); extern void deparseStringLiteral(StringInfo buf, const char *val); diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index 74590089bd..65643e120d 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -2355,7 +2355,6 @@ drop table loc3; -- test for TRUNCATE -- =================================================================== CREATE TABLE tru_rtable0 (id int primary key); -CREATE TABLE tru_rtable1 (id int primary key); CREATE FOREIGN TABLE tru_ftable (id int) SERVER loopback OPTIONS (table_name 'tru_rtable0'); INSERT INTO tru_rtable0 (SELECT x FROM generate_series(1,10) x); @@ -2363,6 +2362,7 @@ INSERT INTO tru_rtable0 (SELECT x FROM generate_series(1,10) x); CREATE TABLE tru_ptable (id int) PARTITION BY HASH(id); CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable FOR VALUES WITH (MODULUS 2, REMAINDER 0); +CREATE TABLE tru_rtable1 (id int primary key); CREATE FOREIGN TABLE tru_ftable__p1 PARTITION OF tru_ptable FOR VALUES WITH (MODULUS 2, REMAINDER 1) SERVER loopback OPTIONS (table_name 'tru_rtable1'); @@ -2439,13 +2439,14 @@ INSERT INTO tru_rtable0 (SELECT x FROM generate_series(5,9) x); INSERT INTO tru_rtable0_child (SELECT x FROM generate_series(10,14) x); SELECT sum(id) FROM tru_ftable; -- 95 -TRUNCATE ONLY tru_ftable; -- truncate only parent portion -SELECT sum(id) FROM tru_ftable; -- 60 +TRUNCATE ONLY tru_ftable; -- truncate both of parent and child +SELECT count(*) FROM tru_ftable; -- 0 INSERT INTO tru_rtable0 (SELECT x FROM generate_series(21,25) x); -SELECT sum(id) FROM tru_ftable; -- 175 +INSERT INTO tru_rtable0_child (SELECT x FROM generate_series(26,30) x); +SELECT sum(id) FROM tru_ftable; -- 255 TRUNCATE tru_ftable; -- truncate both of parent and child -SELECT count(*) FROM tru_ftable; -- empty +SELECT count(*) FROM tru_ftable; -- 0 -- cleanup DROP FOREIGN TABLE tru_ftable_parent, tru_ftable_child, tru_pk_ftable,tru_ftable__p1,tru_ftable; diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index 98882ddab8..3fe373ef00 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -1071,28 +1071,16 @@ EndDirectModify(ForeignScanState *node); <para> <programlisting> void -ExecForeignTruncate(List *rels, List *rels_extra, - DropBehavior behavior, bool restart_seqs); +ExecForeignTruncate(List *rels, + DropBehavior behavior, + bool restart_seqs); </programlisting> Truncate a set of foreign tables specified in <literal>rels</literal>. This function is called when <xref linkend="sql-truncate"/> is executed on foreign tables. <literal>rels</literal> is the list of <structname>Relation</structname> data structure that indicates - a foreign table to truncate. <literal>rels_extra</literal> the list of - <literal>int</literal> value, which delivers extra information about - a foreign table to truncate. Possible values are - <literal>TRUNCATE_REL_CONTEXT_NORMAL</literal>, which means that - the foreign table is specified WITHOUT <literal>ONLY</literal> clause - in <command>TRUNCATE</command>, - <literal>TRUNCATE_REL_CONTEXT_ONLY</literal>, which means that - the foreign table is specified WITH <literal>ONLY</literal> clause, - and <literal>TRUNCATE_REL_CONTEXT_CASCADING</literal>, - which means that the foreign table is not specified explicitly, - but will be truncated due to dependency (for example, partition table). - There is one-to-one mapping between <literal>rels</literal> and - <literal>rels_extra</literal>. The number of entries is the same - between the two lists. + a foreign table to truncate. </para> <para> diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 096a6f2891..6e320f96ad 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -323,7 +323,6 @@ typedef struct ForeignTruncateInfo { Oid serverid; List *rels; - List *rels_extra; } ForeignTruncateInfo; /* @@ -1620,7 +1619,6 @@ ExecuteTruncate(TruncateStmt *stmt) { List *rels = NIL; List *relids = NIL; - List *relids_extra = NIL; List *relids_logged = NIL; ListCell *cell; @@ -1654,9 +1652,7 @@ ExecuteTruncate(TruncateStmt *stmt) rels = lappend(rels, rel); relids = lappend_oid(relids, myrelid); - relids_extra = lappend_int(relids_extra, (recurse ? - TRUNCATE_REL_CONTEXT_NORMAL : - TRUNCATE_REL_CONTEXT_ONLY)); + /* Log this relation only if needed for logical decoding */ if (RelationIsLogicallyLogged(rel)) relids_logged = lappend_oid(relids_logged, myrelid); @@ -1704,8 +1700,7 @@ ExecuteTruncate(TruncateStmt *stmt) rels = lappend(rels, rel); relids = lappend_oid(relids, childrelid); - relids_extra = lappend_int(relids_extra, - TRUNCATE_REL_CONTEXT_CASCADING); + /* Log this relation only if needed for logical decoding */ if (RelationIsLogicallyLogged(rel)) relids_logged = lappend_oid(relids_logged, childrelid); @@ -1718,7 +1713,7 @@ ExecuteTruncate(TruncateStmt *stmt) errhint("Do not specify the ONLY keyword, or use TRUNCATE ONLY on the partitions directly."))); } - ExecuteTruncateGuts(rels, relids, relids_extra, relids_logged, + ExecuteTruncateGuts(rels, relids, relids_logged, stmt->behavior, stmt->restart_seqs); /* And close the rels */ @@ -1739,15 +1734,13 @@ ExecuteTruncate(TruncateStmt *stmt) * * explicit_rels is the list of Relations to truncate that the command * specified. relids is the list of Oids corresponding to explicit_rels. - * relids_extra is the list of integer values that deliver extra information - * about relations in explicit_rels. relids_logged is the list of Oids - * (a subset of relids) that require WAL-logging. This is all a bit redundant, - * but the existing callers have this information handy in this form. + * relids_logged is the list of Oids (a subset of relids) that require + * WAL-logging. This is all a bit redundant, but the existing callers have + * this information handy in this form. */ void ExecuteTruncateGuts(List *explicit_rels, List *relids, - List *relids_extra, List *relids_logged, DropBehavior behavior, bool restart_seqs) { @@ -1760,8 +1753,6 @@ ExecuteTruncateGuts(List *explicit_rels, ResultRelInfo *resultRelInfo; SubTransactionId mySubid; ListCell *cell; - ListCell *lc1, - *lc2; Oid *logrelids; /* @@ -1799,8 +1790,7 @@ ExecuteTruncateGuts(List *explicit_rels, truncate_check_activity(rel); rels = lappend(rels, rel); relids = lappend_oid(relids, relid); - relids_extra = lappend_int(relids_extra, - TRUNCATE_REL_CONTEXT_CASCADING); + /* Log this relation only if needed for logical decoding */ if (RelationIsLogicallyLogged(rel)) relids_logged = lappend_oid(relids_logged, relid); @@ -1901,11 +1891,9 @@ ExecuteTruncateGuts(List *explicit_rels, */ mySubid = GetCurrentSubTransactionId(); - Assert(list_length(rels) == list_length(relids_extra)); - forboth(lc1, rels, lc2, relids_extra) + foreach(cell, rels) { - Relation rel = (Relation) lfirst(lc1); - int extra = lfirst_int(lc2); + Relation rel = (Relation) lfirst(cell); /* * Save OID of partitioned tables for later; nothing else to do for @@ -1952,7 +1940,6 @@ ExecuteTruncateGuts(List *explicit_rels, { ft_info->serverid = serverid; ft_info->rels = NIL; - ft_info->rels_extra = NIL; } /* @@ -1960,7 +1947,6 @@ ExecuteTruncateGuts(List *explicit_rels, * foreign table belongs to. */ ft_info->rels = lappend(ft_info->rels, rel); - ft_info->rels_extra = lappend_int(ft_info->rels_extra, extra); continue; } @@ -2044,7 +2030,6 @@ ExecuteTruncateGuts(List *explicit_rels, Assert(routine->ExecForeignTruncate != NULL); routine->ExecForeignTruncate(ft_info->rels, - ft_info->rels_extra, behavior, restart_seqs); } diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index fb3ba5c415..4dd869aaba 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1795,7 +1795,6 @@ apply_handle_truncate(StringInfo s) List *rels = NIL; List *part_rels = NIL; List *relids = NIL; - List *relids_extra = NIL; List *relids_logged = NIL; ListCell *lc; @@ -1825,7 +1824,6 @@ apply_handle_truncate(StringInfo s) remote_rels = lappend(remote_rels, rel); rels = lappend(rels, rel->localrel); relids = lappend_oid(relids, rel->localreloid); - relids_extra = lappend_int(relids_extra, TRUNCATE_REL_CONTEXT_NORMAL); if (RelationIsLogicallyLogged(rel->localrel)) relids_logged = lappend_oid(relids_logged, rel->localreloid); @@ -1864,7 +1862,6 @@ apply_handle_truncate(StringInfo s) rels = lappend(rels, childrel); part_rels = lappend(part_rels, childrel); relids = lappend_oid(relids, childrelid); - relids_extra = lappend_int(relids_extra, TRUNCATE_REL_CONTEXT_CASCADING); /* Log this relation only if needed for logical decoding */ if (RelationIsLogicallyLogged(childrel)) relids_logged = lappend_oid(relids_logged, childrelid); @@ -1879,7 +1876,6 @@ apply_handle_truncate(StringInfo s) */ ExecuteTruncateGuts(rels, relids, - relids_extra, relids_logged, DROP_RESTRICT, restart_seqs); diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index b808a07e46..14f4b4882f 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -21,16 +21,6 @@ #include "storage/lock.h" #include "utils/relcache.h" -/* - * These values indicate how a relation was specified as the target to - * truncate in TRUNCATE command. - */ -#define TRUNCATE_REL_CONTEXT_NORMAL 1 /* specified without ONLY clause */ -#define TRUNCATE_REL_CONTEXT_ONLY 2 /* specified with ONLY clause */ -#define TRUNCATE_REL_CONTEXT_CASCADING 3 /* not specified but truncated - * due to dependency (e.g., - * partition table) */ - struct AlterTableUtilityContext; /* avoid including tcop/utility.h here */ @@ -68,7 +58,6 @@ extern void CheckTableNotInUse(Relation rel, const char *stmt); extern void ExecuteTruncate(TruncateStmt *stmt); extern void ExecuteTruncateGuts(List *explicit_rels, List *relids, - List *relids_extra, List *relids_logged, DropBehavior behavior, bool restart_seqs); diff --git a/src/include/foreign/fdwapi.h b/src/include/foreign/fdwapi.h index 4ebbca6de9..4f17becbb8 100644 --- a/src/include/foreign/fdwapi.h +++ b/src/include/foreign/fdwapi.h @@ -161,7 +161,6 @@ typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt, Oid serverOid); typedef void (*ExecForeignTruncate_function) (List *rels, - List *rels_extra, DropBehavior behavior, bool restart_seqs);
truncate_foreign_table_docs_v1.patch (text/plain, 4.2K) download diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index 3fe373ef00..68737aee27 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -1076,35 +1076,32 @@ ExecForeignTruncate(List *rels, bool restart_seqs); </programlisting> - Truncate a set of foreign tables specified in <literal>rels</literal>. - This function is called when <xref linkend="sql-truncate"/> is executed - on foreign tables. <literal>rels</literal> is the list of - <structname>Relation</structname> data structure that indicates - a foreign table to truncate. + Truncate foreign tables. This function is called when + <xref linkend="sql-truncate"/> is executed on a foreign table. + <literal>rels</literal> is a list of <structname>Relation</structname> + data structures for each foreign table to truncated. </para> <para> - <literal>behavior</literal> defines how foreign tables should - be truncated, using as possible values <literal>DROP_RESTRICT</literal>, - which means that <literal>RESTRICT</literal> option is specified, - and <literal>DROP_CASCADE</literal>, which means that - <literal>CASCADE</literal> option is specified, in - <command>TRUNCATE</command> command. + <literal>behavior</literal> is either <literal>DROP_RESTRICT</literal> + or <literal>DROP_CASCADE</literal>, which indicates that the + <literal>RESTRICT</literal> or <literal>CASCADE</literal> option was + requested in the original <command>TRUNCATE</command> command, + respectively. </para> <para> - <literal>restart_seqs</literal> is set to <literal>true</literal> - if <literal>RESTART IDENTITY</literal> option is specified in - <command>TRUNCATE</command> command. It is <literal>false</literal> - if <literal>CONTINUE IDENTITY</literal> option is specified. + If <literal>restart_seqs</literal> is <literal>true</literal>, + the original <command>TRUNCATE</command> command requested the + <literal>RESTART IDENTITY</literal> option, otherwise + <literal>CONTINUE IDENTITY</literal> option. </para> <para> - <command>TRUNCATE</command> invokes - <function>ExecForeignTruncate</function> once per foreign server - that foreign tables to truncate belong to. This means that all foreign - tables included in <literal>rels</literal> must belong to the same - server. + <function>ExecForeignTruncate</function> is invoked once per + foreign server for which foreign tables are to be truncated. + This means that all foreign tables included in <literal>rels</literal> + must belong to the same server. </para> <para> diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml index 5320accf6f..31b96e9d2e 100644 --- a/doc/src/sgml/postgres-fdw.sgml +++ b/doc/src/sgml/postgres-fdw.sgml @@ -452,11 +452,17 @@ OPTIONS (ADD password_required 'false'); <listitem> <para> This option controls whether <filename>postgres_fdw</filename> allows - foreign tables to be truncated using <command>TRUNCATE</command> + foreign tables to be truncated using the <command>TRUNCATE</command> command. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is <literal>true</literal>. </para> + + <para> + Of course, if the remote table is not in fact truncatable, an error + would occur anyway. Use of this option primarily allows the error to + be thrown locally without querying the remote server. + </para> </listitem> </varlistentry> </variablelist> diff --git a/doc/src/sgml/ref/truncate.sgml b/doc/src/sgml/ref/truncate.sgml index acf3633be4..9d846f88c9 100644 --- a/doc/src/sgml/ref/truncate.sgml +++ b/doc/src/sgml/ref/truncate.sgml @@ -173,7 +173,7 @@ TRUNCATE [ TABLE ] [ ONLY ] <replaceable class="parameter">name</replaceable> [ <para> <command>TRUNCATE</command> can be used for foreign tables if - the foreign data wrapper supports, for instance, + supported by the foreign data wrapper, for instance, see <xref linkend="postgres-fdw"/>. </para> </refsect1>

view thread (117+ messages)  latest in thread

Message-ID: <94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com>
Permalink:  ../94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com/
Also on:    postgresql.org/message-id/94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: masao.fujii@oss.nttdata.com, bharath.rupireddyforpostgres@gmail.com, kaigai@heterodb.com, onishi@heterodb.com, zyu@yugabyte.com, amitlangote09@gmail.com, ibrar.ahmad@gmail.com, ashutosh.bapat.oss@gmail.com
  Subject: Re: TRUNCATE on foreign table
  In-Reply-To: <94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com>
  References: <CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com> <eac9329f-f285-2044-1974-b3d0d0aa5950@oss.nttdata.com> <CAOP8fzYgM=bxsDgtnucx4k_QUdUknri4UEdPxr9bkkfqRYoRog@mail.gmail.com> <CAOP8fzZf+=RQFmwLRw5s1KKgApuXmYPC76nmUZGck4=e7AJj8Q@mail.gmail.com> <2209ecd8-0382-cbcb-5717-15da49535237@oss.nttdata.com> <CAOP8fzbCfju6TT4DYqw5KC9tgTN4UzpagJnY3WRXfiR9R58M1Q@mail.gmail.com> <CALj2ACVuygqS7rMGHGs-W_JGx6pjdAFitTZuNfWdV2QaBaOc+A@mail.gmail.com> <CAOP8fzYbU2g4wFJAcxJkaESWV1NxJL3LYf=jXti-JL3fcvPgxw@mail.gmail.com> <70310892-3572-f143-a692-e9aa4322a914@oss.nttdata.com> <CALj2ACX7UYyg9tsqqS7akc5eSiwBLevM-ZfX00haFrdZrq2tgg@mail.gmail.com> <a1975489-a32d-dc2b-c117-cd36495d82fa@oss.nttdata.com> <CALj2ACUvkyyEP0YM5WPGfgXtTqYTMBE2Jzy8C1oX6_DcHTxf=g@mail.gmail.com> <2ec345ad-9a7b-a21f-8a1b-04c0537ea9b8@oss.nttdata.com> <CALj2ACUvuYrCi7G54Yov0oc_D9Zz6O157mtru72J-zxYYWf_3w@mail.gmail.com> <94c99273-4b06-1b13-98da-a716e0454cac@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox