From 26ad52713cba2dc247b8e2895f472c7795c900c0 Mon Sep 17 00:00:00 2001 From: Karina <55838532+Green-Chan@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:33:52 +0300 Subject: [PATCH] Check for Citus table in worker_copy_table_to_node (#7662) Fixes #6795 The `worker_copy_table_to_node` is not supposed to be called for Citus tables. When this function was initially introduced in #6098 , it had the respective check. But the check was omitted, since `worker_copy_table_to_node` called for Citus table finishes with error anyway: ``` ERROR: cannot execute a distributed query from a query on a shard DETAIL: Executing a distributed query in a function call that may be pushed to a remote node can lead to incorrect results. ``` It turns out that in some cases this error does not occur. See #6795 I suggest restoring that check. Co-authored-by: Karina Litskevich --- .../operations/worker_copy_table_to_node_udf.c | 9 +++++++++ src/test/regress/expected/worker_copy_table_to_node.out | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/operations/worker_copy_table_to_node_udf.c b/src/backend/distributed/operations/worker_copy_table_to_node_udf.c index c603de72a..43a405f1c 100644 --- a/src/backend/distributed/operations/worker_copy_table_to_node_udf.c +++ b/src/backend/distributed/operations/worker_copy_table_to_node_udf.c @@ -40,6 +40,15 @@ worker_copy_table_to_node(PG_FUNCTION_ARGS) Oid relationId = PG_GETARG_OID(0); uint32_t targetNodeId = PG_GETARG_INT32(1); + if (IsCitusTable(relationId)) + { + char *qualifiedRelationName = generate_qualified_relation_name(relationId); + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("table %s is a Citus table, only copies of " + "shards or regular postgres tables are supported", + qualifiedRelationName))); + } + Oid schemaOid = get_rel_namespace(relationId); char *relationSchemaName = get_namespace_name(schemaOid); char *relationName = get_rel_name(relationId); diff --git a/src/test/regress/expected/worker_copy_table_to_node.out b/src/test/regress/expected/worker_copy_table_to_node.out index 76f440189..931135613 100644 --- a/src/test/regress/expected/worker_copy_table_to_node.out +++ b/src/test/regress/expected/worker_copy_table_to_node.out @@ -37,11 +37,9 @@ CREATE TABLE t_62629600(a int); SET search_path TO worker_copy_table_to_node; -- Make sure that the UDF doesn't work on Citus tables SELECT worker_copy_table_to_node('t', :worker_1_node); -ERROR: cannot execute a distributed query from a query on a shard -DETAIL: Executing a distributed query in a function call that may be pushed to a remote node can lead to incorrect results. +ERROR: table worker_copy_table_to_node.t is a Citus table, only copies of shards or regular postgres tables are supported SELECT worker_copy_table_to_node('ref', :worker_1_node); -ERROR: cannot execute a distributed query from a query on a shard -DETAIL: Executing a distributed query in a function call that may be pushed to a remote node can lead to incorrect results. +ERROR: table worker_copy_table_to_node.ref is a Citus table, only copies of shards or regular postgres tables are supported -- It should work on shards SELECT worker_copy_table_to_node('t_62629600', :worker_1_node); worker_copy_table_to_node