diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 99f7a049930..315a555dcff 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -807,6 +807,10 @@ InitPlan(QueryDesc *queryDesc, int eflags) if (rc->isParent) continue; + /* + * 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: diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 8b341dae4ed..c4d048f4216 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -820,7 +820,9 @@ ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags) { ExecRowMark *erm = lfirst(l); - if (erm->rti == scanrelid) + /* Keep this check in sync with InitPlan! */ + if (erm->rti == scanrelid && + erm->relation != NULL) { lockmode = NoLock; break;