From 54ee93885ade6a8b5a4a07d044badb832044e622 Mon Sep 17 00:00:00 2001 From: Halil Ozan Akgul Date: Wed, 11 Aug 2021 16:02:14 +0300 Subject: [PATCH] Introduces getObjectTypeDescription_compat and getObjectIdentity_compat macros getObjectTypeDescription and getObjectIdentity functions now have a new bool missing_ok parameter These new macros give us the ability to use this new parameter for PG14 and they don't give the parameter for previous versions Currently all missing_ok parameters are set to false to keep current behavior Relevant PG commit: 2a10fdc4307a667883f7a3369cb93a721ade9680 --- src/backend/distributed/commands/dependencies.c | 2 +- src/backend/distributed/commands/function.c | 9 ++++++--- src/backend/distributed/commands/type.c | 3 ++- src/backend/distributed/metadata/distobject.c | 4 ++-- src/include/distributed/version_compat.h | 4 ++++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/backend/distributed/commands/dependencies.c b/src/backend/distributed/commands/dependencies.c index 0b19ee729..50e459512 100644 --- a/src/backend/distributed/commands/dependencies.c +++ b/src/backend/distributed/commands/dependencies.c @@ -251,7 +251,7 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency) */ Assert(false); ereport(ERROR, (errmsg("unsupported object %s for distribution by citus", - getObjectTypeDescription(dependency)), + getObjectTypeDescription_compat(dependency, /* missingOk: */ false)), errdetail( "citus tries to recreate an unsupported object on its workers"), errhint("please report a bug as this should not be happening"))); diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index 1f8a86e40..6aedce934 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -1613,7 +1613,8 @@ PreprocessAlterFunctionDependsStmt(Node *node, const char *queryString, * workers */ - const char *functionName = getObjectIdentity(&address); + const char *functionName = + getObjectIdentity_compat(&address, /* missingOk: */ false); ereport(ERROR, (errmsg("distrtibuted functions are not allowed to depend on an " "extension"), errdetail("Function \"%s\" is already distributed. Functions from " @@ -1932,8 +1933,10 @@ ErrorIfFunctionDependsOnExtension(const ObjectAddress *functionAddress) if (IsObjectAddressOwnedByExtension(functionAddress, &extensionAddress)) { - char *functionName = getObjectIdentity(functionAddress); - char *extensionName = getObjectIdentity(&extensionAddress); + char *functionName = + getObjectIdentity_compat(functionAddress, /* missingOk: */ false); + char *extensionName = + getObjectIdentity_compat(&extensionAddress, /* missingOk: */ false); ereport(ERROR, (errmsg("unable to create a distributed function from functions " "owned by an extension"), errdetail("Function \"%s\" has a dependency on extension \"%s\". " diff --git a/src/backend/distributed/commands/type.c b/src/backend/distributed/commands/type.c index b98d894a4..83cdc1a6b 100644 --- a/src/backend/distributed/commands/type.c +++ b/src/backend/distributed/commands/type.c @@ -973,7 +973,8 @@ CreateTypeDDLCommandsIdempotent(const ObjectAddress *typeAddress) /* add owner ship change so the creation command can be run as a different user */ const char *username = GetUserNameFromId(GetTypeOwner(typeAddress->objectId), false); initStringInfo(&buf); - appendStringInfo(&buf, ALTER_TYPE_OWNER_COMMAND, getObjectIdentity(typeAddress), + appendStringInfo(&buf, ALTER_TYPE_OWNER_COMMAND, + getObjectIdentity_compat(typeAddress, false), quote_identifier(username)); ddlCommands = lappend(ddlCommands, buf.data); diff --git a/src/backend/distributed/metadata/distobject.c b/src/backend/distributed/metadata/distobject.c index ef2adf641..b96db6ed0 100644 --- a/src/backend/distributed/metadata/distobject.c +++ b/src/backend/distributed/metadata/distobject.c @@ -75,8 +75,8 @@ citus_unmark_object_distributed(PG_FUNCTION_ARGS) { ereport(ERROR, (errmsg("object still exists"), errdetail("the %s \"%s\" still exists", - getObjectTypeDescription(&address), - getObjectIdentity(&address)), + getObjectTypeDescription_compat(&address, /* missingOk: */ false), + getObjectIdentity_compat(&address, /* missingOk: */ false)), errhint("drop the object via a DROP command"))); } diff --git a/src/include/distributed/version_compat.h b/src/include/distributed/version_compat.h index 9581d3804..aa438ad0e 100644 --- a/src/include/distributed/version_compat.h +++ b/src/include/distributed/version_compat.h @@ -35,11 +35,15 @@ #define F_NEXTVAL_COMPAT F_NEXTVAL #define ROLE_MONITOR_COMPAT ROLE_PG_MONITOR #define STATUS_WAITING_COMPAT PROC_WAIT_STATUS_WAITING +#define getObjectTypeDescription_compat(a, b) getObjectTypeDescription(a, b) +#define getObjectIdentity_compat(a, b) getObjectIdentity(a, b) #else #define AlterTableStmtObjType(a) ((a)->relkind) #define F_NEXTVAL_COMPAT F_NEXTVAL_OID #define ROLE_MONITOR_COMPAT DEFAULT_ROLE_MONITOR #define STATUS_WAITING_COMPAT STATUS_WAITING +#define getObjectTypeDescription_compat(a, b) getObjectTypeDescription(a) +#define getObjectIdentity_compat(a, b) getObjectIdentity(a) #endif #if PG_VERSION_NUM >= PG_VERSION_13