/*
* If we didn't get the lock ourselves, assert that caller holds one,
* except in bootstrap mode where no locks are used.
+ *
+ * Also, parallel workers currently assume that their parent holds locks
+ * for tables used in the parallel query (a mighty shaky assumption).
*/
Assert(lockmode != NoLock ||
IsBootstrapProcessingMode() ||
+ IsParallelWorker() ||
CheckRelationLockedByMe(r, AccessShareLock, true));
/* Make note that we've accessed a temporary relation */
Relation resultRelation;
resultRelationOid = getrelid(resultRelationIndex, rangeTable);
- Assert(rt_fetch(resultRelationIndex, rangeTable)->rellockmode == RowExclusiveLock);
- resultRelation = heap_open(resultRelationOid, RowExclusiveLock);
+ resultRelation = heap_open(resultRelationOid, NoLock);
+ Assert(CheckRelationLockedByMe(resultRelation, RowExclusiveLock, true));
InitResultRelInfo(resultRelInfo,
resultRelation,
Relation resultRelDesc;
resultRelOid = getrelid(resultRelIndex, rangeTable);
- Assert(rt_fetch(resultRelIndex, rangeTable)->rellockmode == RowExclusiveLock);
- resultRelDesc = heap_open(resultRelOid, RowExclusiveLock);
+ resultRelDesc = heap_open(resultRelOid, NoLock);
+ Assert(CheckRelationLockedByMe(resultRelDesc, RowExclusiveLock, true));
InitResultRelInfo(resultRelInfo,
resultRelDesc,
lfirst_int(l),
estate->es_root_result_relations = resultRelInfos;
estate->es_num_root_result_relations = num_roots;
- /* Simply lock the rest of them. */
+ /* Simply check the rest of them are locked. */
+#ifdef USE_ASSERT_CHECKING
foreach(l, plannedstmt->nonleafResultRelations)
{
Index resultRelIndex = lfirst_int(l);
if (!list_member_int(plannedstmt->rootResultRelations,
resultRelIndex))
{
- Assert(rt_fetch(resultRelIndex, rangeTable)->rellockmode == RowExclusiveLock);
- LockRelationOid(getrelid(resultRelIndex, rangeTable),
- RowExclusiveLock);
+ Relation resultRelDesc;
+
+ resultRelDesc = heap_open(getrelid(resultRelIndex, rangeTable),
+ NoLock);
+ Assert(CheckRelationLockedByMe(resultRelDesc, RowExclusiveLock, true));
+ heap_close(resultRelDesc, NoLock);
}
}
+#endif
}
}
else
{
PlanRowMark *rc = (PlanRowMark *) lfirst(l);
Oid relid;
- LOCKMODE rellockmode;
Relation relation;
ExecRowMark *erm;
case ROW_MARK_SHARE:
case ROW_MARK_KEYSHARE:
case ROW_MARK_REFERENCE:
- rellockmode = rt_fetch(rc->rti, rangeTable)->rellockmode;
- relation = heap_open(relid, rellockmode);
+ relation = heap_open(relid, NoLock);
+ Assert(CheckRelationLockedByMe(relation,
+ rt_fetch(rc->rti, rangeTable)->rellockmode,
+ true));
break;
case ROW_MARK_COPY:
/* no physical table access is required */
#include "postgres.h"
+#include "access/parallel.h"
#include "access/relscan.h"
#include "access/transam.h"
#include "executor/executor.h"
{
Relation rel;
Oid reloid;
- LOCKMODE lockmode;
- /* Open the relation and acquire lock as needed */
+ /* Open the relation and verify lock was obtained upstream */
reloid = getrelid(scanrelid, estate->es_range_table);
- lockmode = rt_fetch(scanrelid, estate->es_range_table)->rellockmode;
- rel = heap_open(reloid, lockmode);
+ rel = heap_open(reloid, NoLock);
+ Assert(IsParallelWorker() ||
+ CheckRelationLockedByMe(rel,
+ rt_fetch(scanrelid, estate->es_range_table)->rellockmode,
+ true));
/*
* Complain if we're attempting a scan of an unscannable relation, except