From 26cec16b166738c73ce003b3fd1a76caf643c915 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Fri, 28 Feb 2020 19:01:20 +0300 Subject: [PATCH] enable local execution for DDL commands on distributed & reference tables --- .../distributed/commands/utility_hook.c | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) 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);