diff --git a/src/backend/distributed/executor/adaptive_executor.c b/src/backend/distributed/executor/adaptive_executor.c index bf0770d21..326b214c5 100644 --- a/src/backend/distributed/executor/adaptive_executor.c +++ b/src/backend/distributed/executor/adaptive_executor.c @@ -1603,7 +1603,7 @@ AcquireExecutorShardLocksForExecution(DistributedExecution *execution) */ int lockMode = ExclusiveLock; - if (!anyAnchorTableIsReplicated && IsCoordinator()) + if (!anyAnchorTableIsReplicated && !parallelExecutionNotPossible && IsCoordinator()) { /* * When all writes are commutative then we only need to prevent multi-shard @@ -1628,8 +1628,7 @@ AcquireExecutorShardLocksForExecution(DistributedExecution *execution) EnableDeadlockPrevention ? ShareUpdateExclusiveLock : RowExclusiveLock; } - if (AllModificationsCommutative || - (parallelExecutionNotPossible && modLevel < ROW_MODIFY_NONCOMMUTATIVE)) + if (AllModificationsCommutative) { /* * If either the user allows via a GUC or the commands are @@ -1639,6 +1638,10 @@ AcquireExecutorShardLocksForExecution(DistributedExecution *execution) */ lockMode = RowExclusiveLock; } + else if (parallelExecutionNotPossible && modLevel < ROW_MODIFY_NONCOMMUTATIVE) + { + lockMode = RowExclusiveLock; + } /* now, iterate on the tasks and acquire the executor locks on the shards */ Task *task = NULL;