diff options
author | Fujii Masao <fujii@postgresql.org> | 2021-04-27 14:41:27 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2021-04-27 14:41:27 +0900 |
commit | 8e9ea08bae93a754d5075b7bc9c0b2bc71958bfd (patch) | |
tree | 317013f67abe8af08f2fae54493f8e45b49e0822 /src/backend/commands/tablecmds.c | |
parent | 3fa17d37716f978f80dfcdab4e7c73f3a24e7a48 (diff) | |
download | postgresql-8e9ea08bae93a754d5075b7bc9c0b2bc71958bfd.tar.gz postgresql-8e9ea08bae93a754d5075b7bc9c0b2bc71958bfd.zip |
Don't pass "ONLY" options specified in TRUNCATE to foreign data wrapper.
Commit 8ff1c94649 allowed TRUNCATE command to truncate foreign tables.
Previously the information about "ONLY" options specified in TRUNCATE
command were passed to the foreign data wrapper. Then postgres_fdw
constructed the TRUNCATE command to issue the remote server and
included "ONLY" options in it based on the passed information.
On the other hand, "ONLY" options specified in SELECT, UPDATE or DELETE
have no effect when accessing or modifying the remote table, i.e.,
are not passed to the foreign data wrapper. So it's inconsistent to
make only TRUNCATE command pass the "ONLY" options to the foreign data
wrapper. Therefore this commit changes the TRUNCATE command so that
it doesn't pass the "ONLY" options to the foreign data wrapper,
for the consistency with other statements. Also this commit changes
postgres_fdw so that it always doesn't include "ONLY" options in
the TRUNCATE command that it constructs.
Author: Fujii Masao
Reviewed-by: Bharath Rupireddy, Kyotaro Horiguchi, Justin Pryzby, Zhihong Yu
Discussion: https://postgr.es/m/551ed8c1-f531-818b-664a-2cecdab99cd8@oss.nttdata.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7d00f4eb256..8e717ada28d 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); } |