mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +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:
parent
3fa17d3771
commit
8e9ea08bae
@ -2179,24 +2179,19 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
|
|||||||
void
|
void
|
||||||
deparseTruncateSql(StringInfo buf,
|
deparseTruncateSql(StringInfo buf,
|
||||||
List *rels,
|
List *rels,
|
||||||
List *rels_extra,
|
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs)
|
bool restart_seqs)
|
||||||
{
|
{
|
||||||
ListCell *lc1,
|
ListCell *cell;
|
||||||
*lc2;
|
|
||||||
|
|
||||||
appendStringInfoString(buf, "TRUNCATE ");
|
appendStringInfoString(buf, "TRUNCATE ");
|
||||||
|
|
||||||
forboth(lc1, rels, lc2, rels_extra)
|
foreach(cell, rels)
|
||||||
{
|
{
|
||||||
Relation rel = lfirst(lc1);
|
Relation rel = lfirst(cell);
|
||||||
int extra = lfirst_int(lc2);
|
|
||||||
|
|
||||||
if (lc1 != list_head(rels))
|
if (cell != list_head(rels))
|
||||||
appendStringInfoString(buf, ", ");
|
appendStringInfoString(buf, ", ");
|
||||||
if (extra & TRUNCATE_REL_CONTEXT_ONLY)
|
|
||||||
appendStringInfoString(buf, "ONLY ");
|
|
||||||
|
|
||||||
deparseRelation(buf, rel);
|
deparseRelation(buf, rel);
|
||||||
}
|
}
|
||||||
|
@ -8218,13 +8218,13 @@ drop table loc3;
|
|||||||
-- test for TRUNCATE
|
-- test for TRUNCATE
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
CREATE TABLE tru_rtable0 (id int primary key);
|
CREATE TABLE tru_rtable0 (id int primary key);
|
||||||
CREATE TABLE tru_rtable1 (id int primary key);
|
|
||||||
CREATE FOREIGN TABLE tru_ftable (id int)
|
CREATE FOREIGN TABLE tru_ftable (id int)
|
||||||
SERVER loopback OPTIONS (table_name 'tru_rtable0');
|
SERVER loopback OPTIONS (table_name 'tru_rtable0');
|
||||||
INSERT INTO tru_rtable0 (SELECT x FROM generate_series(1,10) x);
|
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 (id int) PARTITION BY HASH(id);
|
||||||
CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable
|
CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable
|
||||||
FOR VALUES WITH (MODULUS 2, REMAINDER 0);
|
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
|
CREATE FOREIGN TABLE tru_ftable__p1 PARTITION OF tru_ptable
|
||||||
FOR VALUES WITH (MODULUS 2, REMAINDER 1)
|
FOR VALUES WITH (MODULUS 2, REMAINDER 1)
|
||||||
SERVER loopback OPTIONS (table_name 'tru_rtable1');
|
SERVER loopback OPTIONS (table_name 'tru_rtable1');
|
||||||
@ -8364,6 +8364,8 @@ SELECT count(*) from tru_pk_ftable; -- 0
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- truncate with ONLY clause
|
-- truncate with ONLY clause
|
||||||
|
-- Since ONLY is specified, the table tru_ftable_child that inherits
|
||||||
|
-- tru_ftable_parent locally is not truncated.
|
||||||
TRUNCATE ONLY tru_ftable_parent;
|
TRUNCATE ONLY tru_ftable_parent;
|
||||||
SELECT sum(id) FROM tru_ftable_parent; -- 126
|
SELECT sum(id) FROM tru_ftable_parent; -- 126
|
||||||
sum
|
sum
|
||||||
@ -8388,22 +8390,26 @@ SELECT sum(id) FROM tru_ftable; -- 95
|
|||||||
95
|
95
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
TRUNCATE ONLY tru_ftable; -- truncate only parent portion
|
-- Both parent and child tables in the foreign server are truncated
|
||||||
SELECT sum(id) FROM tru_ftable; -- 60
|
-- even though ONLY is specified because ONLY has no effect
|
||||||
sum
|
-- when truncating a foreign table.
|
||||||
-----
|
TRUNCATE ONLY tru_ftable;
|
||||||
60
|
SELECT count(*) FROM tru_ftable; -- 0
|
||||||
|
count
|
||||||
|
-------
|
||||||
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
INSERT INTO tru_rtable0 (SELECT x FROM generate_series(21,25) x);
|
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
|
sum
|
||||||
-----
|
-----
|
||||||
175
|
255
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
TRUNCATE tru_ftable; -- truncate both of parent and child
|
TRUNCATE tru_ftable; -- truncate both of parent and child
|
||||||
SELECT count(*) FROM tru_ftable; -- empty
|
SELECT count(*) FROM tru_ftable; -- 0
|
||||||
count
|
count
|
||||||
-------
|
-------
|
||||||
0
|
0
|
||||||
|
@ -401,7 +401,6 @@ static void postgresExplainForeignModify(ModifyTableState *mtstate,
|
|||||||
static void postgresExplainDirectModify(ForeignScanState *node,
|
static void postgresExplainDirectModify(ForeignScanState *node,
|
||||||
ExplainState *es);
|
ExplainState *es);
|
||||||
static void postgresExecForeignTruncate(List *rels,
|
static void postgresExecForeignTruncate(List *rels,
|
||||||
List *rels_extra,
|
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs);
|
bool restart_seqs);
|
||||||
static bool postgresAnalyzeForeignTable(Relation relation,
|
static bool postgresAnalyzeForeignTable(Relation relation,
|
||||||
@ -2881,7 +2880,6 @@ postgresExplainDirectModify(ForeignScanState *node, ExplainState *es)
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
postgresExecForeignTruncate(List *rels,
|
postgresExecForeignTruncate(List *rels,
|
||||||
List *rels_extra,
|
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs)
|
bool restart_seqs)
|
||||||
{
|
{
|
||||||
@ -2964,7 +2962,7 @@ postgresExecForeignTruncate(List *rels,
|
|||||||
|
|
||||||
/* Construct the TRUNCATE command string */
|
/* Construct the TRUNCATE command string */
|
||||||
initStringInfo(&sql);
|
initStringInfo(&sql);
|
||||||
deparseTruncateSql(&sql, rels, rels_extra, behavior, restart_seqs);
|
deparseTruncateSql(&sql, rels, behavior, restart_seqs);
|
||||||
|
|
||||||
/* Issue the TRUNCATE command to remote server */
|
/* Issue the TRUNCATE command to remote server */
|
||||||
do_sql_command(conn, sql.data);
|
do_sql_command(conn, sql.data);
|
||||||
|
@ -209,7 +209,6 @@ extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
|
|||||||
List **retrieved_attrs);
|
List **retrieved_attrs);
|
||||||
extern void deparseTruncateSql(StringInfo buf,
|
extern void deparseTruncateSql(StringInfo buf,
|
||||||
List *rels,
|
List *rels,
|
||||||
List *rels_extra,
|
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs);
|
bool restart_seqs);
|
||||||
extern void deparseStringLiteral(StringInfo buf, const char *val);
|
extern void deparseStringLiteral(StringInfo buf, const char *val);
|
||||||
|
@ -2355,7 +2355,6 @@ drop table loc3;
|
|||||||
-- test for TRUNCATE
|
-- test for TRUNCATE
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
CREATE TABLE tru_rtable0 (id int primary key);
|
CREATE TABLE tru_rtable0 (id int primary key);
|
||||||
CREATE TABLE tru_rtable1 (id int primary key);
|
|
||||||
CREATE FOREIGN TABLE tru_ftable (id int)
|
CREATE FOREIGN TABLE tru_ftable (id int)
|
||||||
SERVER loopback OPTIONS (table_name 'tru_rtable0');
|
SERVER loopback OPTIONS (table_name 'tru_rtable0');
|
||||||
INSERT INTO tru_rtable0 (SELECT x FROM generate_series(1,10) x);
|
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 (id int) PARTITION BY HASH(id);
|
||||||
CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable
|
CREATE TABLE tru_ptable__p0 PARTITION OF tru_ptable
|
||||||
FOR VALUES WITH (MODULUS 2, REMAINDER 0);
|
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
|
CREATE FOREIGN TABLE tru_ftable__p1 PARTITION OF tru_ptable
|
||||||
FOR VALUES WITH (MODULUS 2, REMAINDER 1)
|
FOR VALUES WITH (MODULUS 2, REMAINDER 1)
|
||||||
SERVER loopback OPTIONS (table_name 'tru_rtable1');
|
SERVER loopback OPTIONS (table_name 'tru_rtable1');
|
||||||
@ -2428,6 +2428,8 @@ SELECT count(*) from tru_ftable; -- 0
|
|||||||
SELECT count(*) from tru_pk_ftable; -- 0
|
SELECT count(*) from tru_pk_ftable; -- 0
|
||||||
|
|
||||||
-- truncate with ONLY clause
|
-- truncate with ONLY clause
|
||||||
|
-- Since ONLY is specified, the table tru_ftable_child that inherits
|
||||||
|
-- tru_ftable_parent locally is not truncated.
|
||||||
TRUNCATE ONLY tru_ftable_parent;
|
TRUNCATE ONLY tru_ftable_parent;
|
||||||
SELECT sum(id) FROM tru_ftable_parent; -- 126
|
SELECT sum(id) FROM tru_ftable_parent; -- 126
|
||||||
TRUNCATE tru_ftable_parent;
|
TRUNCATE tru_ftable_parent;
|
||||||
@ -2439,13 +2441,17 @@ 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);
|
INSERT INTO tru_rtable0_child (SELECT x FROM generate_series(10,14) x);
|
||||||
SELECT sum(id) FROM tru_ftable; -- 95
|
SELECT sum(id) FROM tru_ftable; -- 95
|
||||||
|
|
||||||
TRUNCATE ONLY tru_ftable; -- truncate only parent portion
|
-- Both parent and child tables in the foreign server are truncated
|
||||||
SELECT sum(id) FROM tru_ftable; -- 60
|
-- even though ONLY is specified because ONLY has no effect
|
||||||
|
-- when truncating a foreign table.
|
||||||
|
TRUNCATE ONLY tru_ftable;
|
||||||
|
SELECT count(*) FROM tru_ftable; -- 0
|
||||||
|
|
||||||
INSERT INTO tru_rtable0 (SELECT x FROM generate_series(21,25) x);
|
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
|
TRUNCATE tru_ftable; -- truncate both of parent and child
|
||||||
SELECT count(*) FROM tru_ftable; -- empty
|
SELECT count(*) FROM tru_ftable; -- 0
|
||||||
|
|
||||||
-- cleanup
|
-- cleanup
|
||||||
DROP FOREIGN TABLE tru_ftable_parent, tru_ftable_child, tru_pk_ftable,tru_ftable__p1,tru_ftable;
|
DROP FOREIGN TABLE tru_ftable_parent, tru_ftable_child, tru_pk_ftable,tru_ftable__p1,tru_ftable;
|
||||||
|
@ -1071,28 +1071,16 @@ EndDirectModify(ForeignScanState *node);
|
|||||||
<para>
|
<para>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
void
|
void
|
||||||
ExecForeignTruncate(List *rels, List *rels_extra,
|
ExecForeignTruncate(List *rels,
|
||||||
DropBehavior behavior, bool restart_seqs);
|
DropBehavior behavior,
|
||||||
|
bool restart_seqs);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
Truncate a set of foreign tables specified in <literal>rels</literal>.
|
Truncate a set of foreign tables specified in <literal>rels</literal>.
|
||||||
This function is called when <xref linkend="sql-truncate"/> is executed
|
This function is called when <xref linkend="sql-truncate"/> is executed
|
||||||
on foreign tables. <literal>rels</literal> is the list of
|
on foreign tables. <literal>rels</literal> is the list of
|
||||||
<structname>Relation</structname> data structure that indicates
|
<structname>Relation</structname> data structure that indicates
|
||||||
a foreign table to truncate. <literal>rels_extra</literal> the list of
|
a foreign table to truncate.
|
||||||
<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.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -1111,6 +1099,15 @@ ExecForeignTruncate(List *rels, List *rels_extra,
|
|||||||
if <literal>CONTINUE IDENTITY</literal> option is specified.
|
if <literal>CONTINUE IDENTITY</literal> option is specified.
|
||||||
</para>
|
</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>
|
<para>
|
||||||
<command>TRUNCATE</command> invokes
|
<command>TRUNCATE</command> invokes
|
||||||
<function>ExecForeignTruncate</function> once per foreign server
|
<function>ExecForeignTruncate</function> once per foreign server
|
||||||
|
@ -69,6 +69,13 @@
|
|||||||
have privileges to do these things.)
|
have privileges to do these things.)
|
||||||
</para>
|
</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>
|
<para>
|
||||||
Note that <filename>postgres_fdw</filename> currently lacks support for
|
Note that <filename>postgres_fdw</filename> currently lacks support for
|
||||||
<command>INSERT</command> statements with an <literal>ON CONFLICT DO
|
<command>INSERT</command> statements with an <literal>ON CONFLICT DO
|
||||||
|
@ -323,7 +323,6 @@ typedef struct ForeignTruncateInfo
|
|||||||
{
|
{
|
||||||
Oid serverid;
|
Oid serverid;
|
||||||
List *rels;
|
List *rels;
|
||||||
List *rels_extra;
|
|
||||||
} ForeignTruncateInfo;
|
} ForeignTruncateInfo;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1620,7 +1619,6 @@ ExecuteTruncate(TruncateStmt *stmt)
|
|||||||
{
|
{
|
||||||
List *rels = NIL;
|
List *rels = NIL;
|
||||||
List *relids = NIL;
|
List *relids = NIL;
|
||||||
List *relids_extra = NIL;
|
|
||||||
List *relids_logged = NIL;
|
List *relids_logged = NIL;
|
||||||
ListCell *cell;
|
ListCell *cell;
|
||||||
|
|
||||||
@ -1654,9 +1652,7 @@ ExecuteTruncate(TruncateStmt *stmt)
|
|||||||
|
|
||||||
rels = lappend(rels, rel);
|
rels = lappend(rels, rel);
|
||||||
relids = lappend_oid(relids, myrelid);
|
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 */
|
/* Log this relation only if needed for logical decoding */
|
||||||
if (RelationIsLogicallyLogged(rel))
|
if (RelationIsLogicallyLogged(rel))
|
||||||
relids_logged = lappend_oid(relids_logged, myrelid);
|
relids_logged = lappend_oid(relids_logged, myrelid);
|
||||||
@ -1704,8 +1700,7 @@ ExecuteTruncate(TruncateStmt *stmt)
|
|||||||
|
|
||||||
rels = lappend(rels, rel);
|
rels = lappend(rels, rel);
|
||||||
relids = lappend_oid(relids, childrelid);
|
relids = lappend_oid(relids, childrelid);
|
||||||
relids_extra = lappend_int(relids_extra,
|
|
||||||
TRUNCATE_REL_CONTEXT_CASCADING);
|
|
||||||
/* Log this relation only if needed for logical decoding */
|
/* Log this relation only if needed for logical decoding */
|
||||||
if (RelationIsLogicallyLogged(rel))
|
if (RelationIsLogicallyLogged(rel))
|
||||||
relids_logged = lappend_oid(relids_logged, childrelid);
|
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.")));
|
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);
|
stmt->behavior, stmt->restart_seqs);
|
||||||
|
|
||||||
/* And close the rels */
|
/* And close the rels */
|
||||||
@ -1739,15 +1734,13 @@ ExecuteTruncate(TruncateStmt *stmt)
|
|||||||
*
|
*
|
||||||
* explicit_rels is the list of Relations to truncate that the command
|
* explicit_rels is the list of Relations to truncate that the command
|
||||||
* specified. relids is the list of Oids corresponding to explicit_rels.
|
* specified. relids is the list of Oids corresponding to explicit_rels.
|
||||||
* relids_extra is the list of integer values that deliver extra information
|
* relids_logged is the list of Oids (a subset of relids) that require
|
||||||
* about relations in explicit_rels. relids_logged is the list of Oids
|
* WAL-logging. This is all a bit redundant, but the existing callers have
|
||||||
* (a subset of relids) that require WAL-logging. This is all a bit redundant,
|
* this information handy in this form.
|
||||||
* but the existing callers have this information handy in this form.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ExecuteTruncateGuts(List *explicit_rels,
|
ExecuteTruncateGuts(List *explicit_rels,
|
||||||
List *relids,
|
List *relids,
|
||||||
List *relids_extra,
|
|
||||||
List *relids_logged,
|
List *relids_logged,
|
||||||
DropBehavior behavior, bool restart_seqs)
|
DropBehavior behavior, bool restart_seqs)
|
||||||
{
|
{
|
||||||
@ -1760,8 +1753,6 @@ ExecuteTruncateGuts(List *explicit_rels,
|
|||||||
ResultRelInfo *resultRelInfo;
|
ResultRelInfo *resultRelInfo;
|
||||||
SubTransactionId mySubid;
|
SubTransactionId mySubid;
|
||||||
ListCell *cell;
|
ListCell *cell;
|
||||||
ListCell *lc1,
|
|
||||||
*lc2;
|
|
||||||
Oid *logrelids;
|
Oid *logrelids;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1799,8 +1790,7 @@ ExecuteTruncateGuts(List *explicit_rels,
|
|||||||
truncate_check_activity(rel);
|
truncate_check_activity(rel);
|
||||||
rels = lappend(rels, rel);
|
rels = lappend(rels, rel);
|
||||||
relids = lappend_oid(relids, relid);
|
relids = lappend_oid(relids, relid);
|
||||||
relids_extra = lappend_int(relids_extra,
|
|
||||||
TRUNCATE_REL_CONTEXT_CASCADING);
|
|
||||||
/* Log this relation only if needed for logical decoding */
|
/* Log this relation only if needed for logical decoding */
|
||||||
if (RelationIsLogicallyLogged(rel))
|
if (RelationIsLogicallyLogged(rel))
|
||||||
relids_logged = lappend_oid(relids_logged, relid);
|
relids_logged = lappend_oid(relids_logged, relid);
|
||||||
@ -1901,11 +1891,9 @@ ExecuteTruncateGuts(List *explicit_rels,
|
|||||||
*/
|
*/
|
||||||
mySubid = GetCurrentSubTransactionId();
|
mySubid = GetCurrentSubTransactionId();
|
||||||
|
|
||||||
Assert(list_length(rels) == list_length(relids_extra));
|
foreach(cell, rels)
|
||||||
forboth(lc1, rels, lc2, relids_extra)
|
|
||||||
{
|
{
|
||||||
Relation rel = (Relation) lfirst(lc1);
|
Relation rel = (Relation) lfirst(cell);
|
||||||
int extra = lfirst_int(lc2);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save OID of partitioned tables for later; nothing else to do for
|
* 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->serverid = serverid;
|
||||||
ft_info->rels = NIL;
|
ft_info->rels = NIL;
|
||||||
ft_info->rels_extra = NIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1960,7 +1947,6 @@ ExecuteTruncateGuts(List *explicit_rels,
|
|||||||
* foreign table belongs to.
|
* foreign table belongs to.
|
||||||
*/
|
*/
|
||||||
ft_info->rels = lappend(ft_info->rels, rel);
|
ft_info->rels = lappend(ft_info->rels, rel);
|
||||||
ft_info->rels_extra = lappend_int(ft_info->rels_extra, extra);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2044,7 +2030,6 @@ ExecuteTruncateGuts(List *explicit_rels,
|
|||||||
Assert(routine->ExecForeignTruncate != NULL);
|
Assert(routine->ExecForeignTruncate != NULL);
|
||||||
|
|
||||||
routine->ExecForeignTruncate(ft_info->rels,
|
routine->ExecForeignTruncate(ft_info->rels,
|
||||||
ft_info->rels_extra,
|
|
||||||
behavior,
|
behavior,
|
||||||
restart_seqs);
|
restart_seqs);
|
||||||
}
|
}
|
||||||
|
@ -1816,7 +1816,6 @@ apply_handle_truncate(StringInfo s)
|
|||||||
List *rels = NIL;
|
List *rels = NIL;
|
||||||
List *part_rels = NIL;
|
List *part_rels = NIL;
|
||||||
List *relids = NIL;
|
List *relids = NIL;
|
||||||
List *relids_extra = NIL;
|
|
||||||
List *relids_logged = NIL;
|
List *relids_logged = NIL;
|
||||||
ListCell *lc;
|
ListCell *lc;
|
||||||
|
|
||||||
@ -1846,7 +1845,6 @@ apply_handle_truncate(StringInfo s)
|
|||||||
remote_rels = lappend(remote_rels, rel);
|
remote_rels = lappend(remote_rels, rel);
|
||||||
rels = lappend(rels, rel->localrel);
|
rels = lappend(rels, rel->localrel);
|
||||||
relids = lappend_oid(relids, rel->localreloid);
|
relids = lappend_oid(relids, rel->localreloid);
|
||||||
relids_extra = lappend_int(relids_extra, TRUNCATE_REL_CONTEXT_NORMAL);
|
|
||||||
if (RelationIsLogicallyLogged(rel->localrel))
|
if (RelationIsLogicallyLogged(rel->localrel))
|
||||||
relids_logged = lappend_oid(relids_logged, rel->localreloid);
|
relids_logged = lappend_oid(relids_logged, rel->localreloid);
|
||||||
|
|
||||||
@ -1885,7 +1883,6 @@ apply_handle_truncate(StringInfo s)
|
|||||||
rels = lappend(rels, childrel);
|
rels = lappend(rels, childrel);
|
||||||
part_rels = lappend(part_rels, childrel);
|
part_rels = lappend(part_rels, childrel);
|
||||||
relids = lappend_oid(relids, childrelid);
|
relids = lappend_oid(relids, childrelid);
|
||||||
relids_extra = lappend_int(relids_extra, TRUNCATE_REL_CONTEXT_CASCADING);
|
|
||||||
/* Log this relation only if needed for logical decoding */
|
/* Log this relation only if needed for logical decoding */
|
||||||
if (RelationIsLogicallyLogged(childrel))
|
if (RelationIsLogicallyLogged(childrel))
|
||||||
relids_logged = lappend_oid(relids_logged, childrelid);
|
relids_logged = lappend_oid(relids_logged, childrelid);
|
||||||
@ -1900,7 +1897,6 @@ apply_handle_truncate(StringInfo s)
|
|||||||
*/
|
*/
|
||||||
ExecuteTruncateGuts(rels,
|
ExecuteTruncateGuts(rels,
|
||||||
relids,
|
relids,
|
||||||
relids_extra,
|
|
||||||
relids_logged,
|
relids_logged,
|
||||||
DROP_RESTRICT,
|
DROP_RESTRICT,
|
||||||
restart_seqs);
|
restart_seqs);
|
||||||
|
@ -21,16 +21,6 @@
|
|||||||
#include "storage/lock.h"
|
#include "storage/lock.h"
|
||||||
#include "utils/relcache.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 */
|
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 ExecuteTruncate(TruncateStmt *stmt);
|
||||||
extern void ExecuteTruncateGuts(List *explicit_rels,
|
extern void ExecuteTruncateGuts(List *explicit_rels,
|
||||||
List *relids,
|
List *relids,
|
||||||
List *relids_extra,
|
|
||||||
List *relids_logged,
|
List *relids_logged,
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs);
|
bool restart_seqs);
|
||||||
|
@ -161,7 +161,6 @@ typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt,
|
|||||||
Oid serverOid);
|
Oid serverOid);
|
||||||
|
|
||||||
typedef void (*ExecForeignTruncate_function) (List *rels,
|
typedef void (*ExecForeignTruncate_function) (List *rels,
|
||||||
List *rels_extra,
|
|
||||||
DropBehavior behavior,
|
DropBehavior behavior,
|
||||||
bool restart_seqs);
|
bool restart_seqs);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user