Skip to content

Commit 3fbfd5d

Browse files
committed
Fix ExecOpenScanRelation to take a lock on a ROW_MARK_COPY relation.
ExecOpenScanRelation assumed that any relation listed in the ExecRowMark list has been locked by InitPlan; but this is not true if the rel's markType is ROW_MARK_COPY, which is possible if it's a foreign table. In most (possibly all) cases, failure to acquire a lock here isn't really problematic because the parser, planner, or plancache would have taken the appropriate lock already. In principle though it might leave us vulnerable to working with a relation that we hold no lock on, and in any case if the executor isn't depending on previously-taken locks otherwise then it should not do so for ROW_MARK_COPY relations. Noted by Etsuro Fujita. Back-patch to all active versions, since the inconsistency has been there a long time. (It's almost certainly irrelevant in 9.0, since that predates foreign tables, but the code's still wrong on its own terms.)
1 parent 8582ae7 commit 3fbfd5d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/backend/executor/execMain.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ InitPlan(QueryDesc *queryDesc, int eflags)
804804
if (rc->isParent)
805805
continue;
806806

807+
/*
808+
* If you change the conditions under which rel locks are acquired
809+
* here, be sure to adjust ExecOpenScanRelation to match.
810+
*/
807811
switch (rc->markType)
808812
{
809813
case ROW_MARK_EXCLUSIVE:

src/backend/executor/execUtils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,9 @@ ExecOpenScanRelation(EState *estate, Index scanrelid)
819819
{
820820
ExecRowMark *erm = lfirst(l);
821821

822-
if (erm->rti == scanrelid)
822+
/* Keep this check in sync with InitPlan! */
823+
if (erm->rti == scanrelid &&
824+
erm->relation != NULL)
823825
{
824826
lockmode = NoLock;
825827
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy