From 7d787e3d5e556b8dd52e5b33bcaf688f476268a6 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Tue, 10 Mar 2020 18:24:20 +0100 Subject: [PATCH] Prevent create_distributed_function() from the workers As this could cause weird edge cases. --- src/backend/distributed/commands/function.c | 1 + .../expected/multi_mx_function_call_delegation.out | 8 ++++++++ .../regress/sql/multi_mx_function_call_delegation.sql | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index cfe3df42f..4bb868983 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -148,6 +148,7 @@ create_distributed_function(PG_FUNCTION_ARGS) colocateWithTableName = text_to_cstring(colocateWithText); } + EnsureCoordinator(); EnsureFunctionOwner(funcOid); ObjectAddressSet(functionAddress, ProcedureRelationId, funcOid); diff --git a/src/test/regress/expected/multi_mx_function_call_delegation.out b/src/test/regress/expected/multi_mx_function_call_delegation.out index 935a01770..a37eb52b5 100644 --- a/src/test/regress/expected/multi_mx_function_call_delegation.out +++ b/src/test/regress/expected/multi_mx_function_call_delegation.out @@ -692,6 +692,14 @@ DEBUG: pushing down the function call 28 (1 row) +\c - - - :worker_1_port +SET search_path TO multi_mx_function_call_delegation, public; +-- create_distributed_function is disallowed from worker nodes +select create_distributed_function('mx_call_func(int,int)'); +ERROR: operation is not allowed on this node +HINT: Connect to the coordinator and run it again. +\c - - - :master_port +SET search_path TO multi_mx_function_call_delegation, public; RESET client_min_messages; \set VERBOSITY terse DROP SCHEMA multi_mx_function_call_delegation CASCADE; diff --git a/src/test/regress/sql/multi_mx_function_call_delegation.sql b/src/test/regress/sql/multi_mx_function_call_delegation.sql index febc44363..c153087fd 100644 --- a/src/test/regress/sql/multi_mx_function_call_delegation.sql +++ b/src/test/regress/sql/multi_mx_function_call_delegation.sql @@ -83,6 +83,7 @@ select create_distributed_function('mx_call_func_bigint(bigint,bigint)'); select create_distributed_function('mx_call_func_custom_types(mx_call_enum,mx_call_enum)'); select create_distributed_function('squares(int)'); + -- We still don't route them to the workers, because they aren't -- colocated with any distributed tables. SET client_min_messages TO DEBUG1; @@ -259,6 +260,14 @@ EXECUTE call_plan(2, 0); EXECUTE call_plan(2, 0); EXECUTE call_plan(2, 0); +\c - - - :worker_1_port +SET search_path TO multi_mx_function_call_delegation, public; +-- create_distributed_function is disallowed from worker nodes +select create_distributed_function('mx_call_func(int,int)'); + +\c - - - :master_port +SET search_path TO multi_mx_function_call_delegation, public; + RESET client_min_messages; \set VERBOSITY terse DROP SCHEMA multi_mx_function_call_delegation CASCADE;