From 9ee0e68882e60672b8a11885c9867b83491b84dd Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Thu, 14 Dec 2017 08:59:16 +0100 Subject: [PATCH] Do not take extra access exclusive lock partitioned tables --- .../executor/multi_router_executor.c | 46 +++++-------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/src/backend/distributed/executor/multi_router_executor.c b/src/backend/distributed/executor/multi_router_executor.c index 3963b2b93..795bb2fdc 100644 --- a/src/backend/distributed/executor/multi_router_executor.c +++ b/src/backend/distributed/executor/multi_router_executor.c @@ -100,7 +100,6 @@ static bool StoreQueryResult(CitusScanState *scanState, MultiConnection *connect bool failOnError, int64 *rows); static bool ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows); -static LOCKMODE LockModeForModifyTask(Task *task); /* @@ -752,12 +751,13 @@ ExecuteSingleModifyTask(CitusScanState *scanState, Task *task, bool multipleTask /* * If we are dealing with a partitioned table, we also need to lock its * partitions. + * + * For DDL commands, we already obtained the appropriate locks in + * ProcessUtility, so we only need to do this for DML commands. */ - if (PartitionedTable(relationId)) + if (PartitionedTable(relationId) && task->taskType == MODIFY_TASK) { - LOCKMODE lockMode = LockModeForModifyTask(task); - - LockPartitionRelations(relationId, lockMode); + LockPartitionRelations(relationId, RowExclusiveLock); } /* prevent replicas of the same shard from diverging */ @@ -1042,14 +1042,16 @@ ExecuteModifyTasks(List *taskList, bool expectResults, ParamListInfo paramListIn * In multi shard modification, we expect that all tasks operates on the * same relation, so it is enough to acquire a lock on the first task's * anchor relation's partitions. + * + * For DDL commands, we already obtained the appropriate locks in + * ProcessUtility, so we only need to do this for DML commands. */ firstTask = (Task *) linitial(taskList); firstShardInterval = LoadShardInterval(firstTask->anchorShardId); - if (PartitionedTable(firstShardInterval->relationId)) + if (PartitionedTable(firstShardInterval->relationId) && + firstTask->taskType == MODIFY_TASK) { - LOCKMODE lockMode = LockModeForModifyTask(firstTask); - - LockPartitionRelations(firstShardInterval->relationId, lockMode); + LockPartitionRelations(firstShardInterval->relationId, RowExclusiveLock); } /* ensure that there are no concurrent modifications on the same shards */ @@ -1559,29 +1561,3 @@ ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows) return gotResponse && !commandFailed; } - - -/* - * LockModeForRouterModifyTask returns appropriate LOCKMODE for given router - * modify task. - */ -static LOCKMODE -LockModeForModifyTask(Task *task) -{ - LOCKMODE lockMode = NoLock; - if (task->taskType == DDL_TASK) - { - lockMode = AccessExclusiveLock; - } - else if (task->taskType == MODIFY_TASK) - { - lockMode = RowExclusiveLock; - } - else - { - /* we do not allow any other task type in these code path */ - Assert(false); - } - - return lockMode; -}