diff options
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execMain.c | 14 | ||||
-rw-r--r-- | src/backend/executor/execUtils.c | 43 |
2 files changed, 10 insertions, 47 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index c28750e0753..c865032a80f 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -970,26 +970,16 @@ InitPlan(QueryDesc *queryDesc, int eflags) /* get relation's OID (will produce InvalidOid if subquery) */ relid = getrelid(rc->rti, rangeTable); - rellockmode = rt_fetch(rc->rti, rangeTable)->rellockmode; - /* - * If you change the conditions under which rel locks are acquired - * here, be sure to adjust ExecOpenScanRelation to match. - */ switch (rc->markType) { case ROW_MARK_EXCLUSIVE: case ROW_MARK_NOKEYEXCLUSIVE: case ROW_MARK_SHARE: case ROW_MARK_KEYSHARE: - Assert(rellockmode == RowShareLock); - relation = heap_open(relid, RowShareLock); - break; case ROW_MARK_REFERENCE: - /* RTE might be a query target table */ - Assert(rellockmode == AccessShareLock || - rellockmode == RowExclusiveLock); - relation = heap_open(relid, AccessShareLock); + rellockmode = rt_fetch(rc->rti, rangeTable)->rellockmode; + relation = heap_open(relid, rellockmode); break; case ROW_MARK_COPY: /* no physical table access is required */ 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); } } } |