diff options
Diffstat (limited to 'src/backend/executor/execUtils.c')
-rw-r--r-- | src/backend/executor/execUtils.c | 43 |
1 files changed, 8 insertions, 35 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index da84d5df442..a4058c0f61d 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -641,10 +641,6 @@ ExecRelationIsTargetRelation(EState *estate, Index scanrelid) * * Open the heap relation to be scanned by a base-level scan plan node. * This should be called during the node's ExecInit routine. - * - * By default, this acquires AccessShareLock on the relation. However, - * if the relation was already locked by InitPlan, we don't need to acquire - * any additional lock. This saves trips to the shared lock manager. * ---------------------------------------------------------------- */ Relation @@ -654,37 +650,9 @@ ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags) Oid reloid; LOCKMODE lockmode; - /* - * Determine the lock type we need. First, scan to see if target relation - * is a result relation. If not, check if it's a FOR UPDATE/FOR SHARE - * relation. - * - * Note: we may have already gotten the desired lock type, but for now - * don't try to optimize; this logic is going away soon anyhow. - */ - lockmode = AccessShareLock; - if (ExecRelationIsTargetRelation(estate, scanrelid)) - lockmode = RowExclusiveLock; - else - { - /* Keep this check in sync with InitPlan! */ - ExecRowMark *erm = ExecFindRowMark(estate, scanrelid, true); - - if (erm != NULL) - { - if (erm->markType == ROW_MARK_REFERENCE || - erm->markType == ROW_MARK_COPY) - lockmode = AccessShareLock; - else - lockmode = RowShareLock; - } - } - - /* lockmode per above logic must not be more than we previously acquired */ - Assert(lockmode <= rt_fetch(scanrelid, estate->es_range_table)->rellockmode); - /* Open the relation and acquire lock as needed */ reloid = getrelid(scanrelid, estate->es_range_table); + lockmode = rt_fetch(scanrelid, estate->es_range_table)->rellockmode; rel = heap_open(reloid, lockmode); /* @@ -912,6 +880,7 @@ ExecLockNonLeafAppendTables(List *partitioned_rels, EState *estate) if (!is_result_rel) { PlanRowMark *rc = NULL; + LOCKMODE lockmode; foreach(l, stmt->rowMarks) { @@ -923,9 +892,13 @@ ExecLockNonLeafAppendTables(List *partitioned_rels, EState *estate) } if (rc && RowMarkRequiresRowShareLock(rc->markType)) - LockRelationOid(relid, RowShareLock); + lockmode = RowShareLock; else - LockRelationOid(relid, AccessShareLock); + lockmode = AccessShareLock; + + Assert(lockmode == rt_fetch(rti, estate->es_range_table)->rellockmode); + + LockRelationOid(relid, lockmode); } } } |