From 067657af2690ae211350b94f58142c875adaf00a Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Wed, 23 Oct 2019 04:40:48 +0200 Subject: [PATCH] Disallow distributed functions with distribution arguments unless replication_model is streaming --- src/backend/distributed/commands/function.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index a02fd2e5d..2ffe30ec2 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -342,6 +342,8 @@ GetFunctionColocationId(Oid functionOid, char *colocateWithTableName, if (pg_strncasecmp(colocateWithTableName, "default", NAMEDATALEN) == 0) { + Oid colocatedTableId = InvalidOid; + /* check for default colocation group */ colocationId = ColocationId(ShardCount, ShardReplicationFactor, distributionArgumentOid); @@ -356,6 +358,22 @@ GetFunctionColocationId(Oid functionOid, char *colocateWithTableName, errhint("Provide a distributed table via \"colocate_with\" " "option to create_distributed_function()"))); } + + colocatedTableId = ColocatedTableId(colocationId); + if (colocatedTableId != InvalidOid) + { + EnsureFunctionCanBeColocatedWithTable(functionOid, distributionArgumentOid, + colocatedTableId); + } + else if (ReplicationModel == REPLICATION_MODEL_COORDINATOR) + { + /* streaming replication model is required for metadata syncing */ + ereport(ERROR, (errmsg("cannot create a function with a distribution " + "argument when citus.replication_model is " + "'statement'"), + errhint("Set citus.replication_model to 'streaming' " + "before creating distributed tables"))); + } } else { @@ -412,7 +430,7 @@ EnsureFunctionCanBeColocatedWithTable(Oid functionOid, Oid distributionColumnTyp "with distributed tables that are created using " "streaming replication model."), errhint("When distributing tables make sure that " - "\"citus.replication_model\" is set to \"streaming\""))); + "citus.replication_model = 'streaming'"))); } /*