1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

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
This commit is contained in:
Fujii Masao
2021-04-27 14:41:27 +09:00
parent 3fa17d3771
commit 8e9ea08bae
11 changed files with 60 additions and 83 deletions

View File

@ -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>
@ -1111,6 +1099,15 @@ ExecForeignTruncate(List *rels, List *rels_extra,
if <literal>CONTINUE IDENTITY</literal> option is specified.
</para>
<para>
Note that the <literal>ONLY</literal> options specified
in the original <command>TRUNCATE</command> command are not passed to
<function>ExecForeignTruncate</function>. This behavior is similar to
the callback functions of <command>SELECT</command>,
<command>UPDATE</command> and <command>DELETE</command> on
a foreign table.
</para>
<para>
<command>TRUNCATE</command> invokes
<function>ExecForeignTruncate</function> once per foreign server

View File

@ -69,6 +69,13 @@
have privileges to do these things.)
</para>
<para>
Note that the <literal>ONLY</literal> option specified in
<command>SELECT</command>, <command>UPDATE</command>,
<command>DELETE</command> or <command>TRUNCATE</command>
has no effect when accessing or modifying the remote table.
</para>
<para>
Note that <filename>postgres_fdw</filename> currently lacks support for
<command>INSERT</command> statements with an <literal>ON CONFLICT DO