diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 10faf3db8..976f24cb7 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -684,16 +684,27 @@ ExecuteDistributedDDLJob(DDLJob *ddlJob) EnsureCoordinator(); - if (ddlJob->targetRelationId != InvalidOid) + Oid targetRelationId = ddlJob->targetRelationId; + + if (OidIsValid(targetRelationId)) { /* - * Only for ddlJobs that are targetting a relation (table) we want to sync its - * metadata and verify some properties around the table. + * Only for ddlJobs that are targetting a relation (table) we want to sync + * its metadata and verify some properties around the table. */ - shouldSyncMetadata = ShouldSyncTableMetadata(ddlJob->targetRelationId); - EnsurePartitionTableNotReplicated(ddlJob->targetRelationId); + shouldSyncMetadata = ShouldSyncTableMetadata(targetRelationId); + EnsurePartitionTableNotReplicated(targetRelationId); } + /* + * If it is a local placement of a distributed table or a reference table, + * then execute the DDL command locally. + * Here we set localExecutionSupported to true regardless of whether the + * DDL command is run for/on a distributed table as + * ExecuteUtilityTaskListWithoutResults would already identify those + * DDL tasks not accessing any of the local placements. + */ + bool localExecutionSupported = true; if (!ddlJob->concurrentIndexCmd) { @@ -715,9 +726,6 @@ ExecuteDistributedDDLJob(DDLJob *ddlJob) SendCommandToWorkersWithMetadata((char *) ddlJob->commandString); } - /* local execution is not implemented for this code path */ - bool tryLocalExecution = false; - ExecuteUtilityTaskListWithoutResults(ddlJob->taskList, localExecutionSupported); } else @@ -729,9 +737,6 @@ ExecuteDistributedDDLJob(DDLJob *ddlJob) PG_TRY(); { - /* local execution is not implemented for this code path */ - bool tryLocalExecution = false; - ExecuteUtilityTaskListWithoutResults(ddlJob->taskList, localExecutionSupported);