diff --git a/src/backend/distributed/commands/common.c b/src/backend/distributed/commands/common.c index de05efe45..10cef8308 100644 --- a/src/backend/distributed/commands/common.c +++ b/src/backend/distributed/commands/common.c @@ -19,6 +19,7 @@ #include "nodes/parsenodes.h" #include "tcop/utility.h" +#include "distributed/citus_depended_object.h" #include "distributed/commands.h" #include "distributed/commands/utility_hook.h" #include "distributed/deparser.h" @@ -63,6 +64,13 @@ PostprocessCreateDistributedObjectFromCatalogStmt(Node *stmt, const char *queryS return NIL; } + if (ops->qualify && DistOpsValidityState(stmt, ops) == + ShouldQualifyAfterLocalCreation) + { + /* qualify the statement after local creation */ + ops->qualify(stmt); + } + List *addresses = GetObjectAddressListFromParseTree(stmt, false, true); /* the code-path only supports a single object */ diff --git a/src/backend/distributed/utils/citus_depended_object.c b/src/backend/distributed/utils/citus_depended_object.c index 4492d8a07..2a35ee7b2 100644 --- a/src/backend/distributed/utils/citus_depended_object.c +++ b/src/backend/distributed/utils/citus_depended_object.c @@ -370,6 +370,20 @@ DistOpsValidityState(Node *node, const DistributeObjectOps *ops) { if (ops && ops->operationType == DIST_OPS_CREATE) { + /* + * We should beware of qualifying the CREATE statement too early. + */ + if (nodeTag(node) == T_CreateDomainStmt) + { + /* + * Create Domain statements should be qualified after local creation + * because in case of an error in creation, we don't want to print + * the error with the qualified name, as that would differ with + * vanilla Postgres error output. + */ + return ShouldQualifyAfterLocalCreation; + } + /* * We should not validate CREATE statements because no address exists * here yet. diff --git a/src/include/distributed/citus_depended_object.h b/src/include/distributed/citus_depended_object.h index 1efbe4e2a..1923ee08a 100644 --- a/src/include/distributed/citus_depended_object.h +++ b/src/include/distributed/citus_depended_object.h @@ -25,7 +25,8 @@ typedef enum DistOpsValidationState HasAtLeastOneValidObject, HasNoneValidObject, HasObjectWithInvalidOwnership, - NoAddressResolutionRequired + NoAddressResolutionRequired, + ShouldQualifyAfterLocalCreation } DistOpsValidationState; extern void SetLocalClientMinMessagesIfRunningPGTests(int