Content-Length: 289205 | pFad | http://github.com/postgrespro/postgres/commit/6997f226f5de7e02b6afd2d8ff67cf40f20e878b

E2 Fix ExecOpenScanRelation to take a lock on a ROW_MARK_COPY relation. · postgrespro/postgres@6997f22 · GitHub
Skip to content

Commit 6997f22

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 40b0c10 commit 6997f22

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
@@ -704,6 +704,10 @@ InitPlan(QueryDesc *queryDesc, int eflags)
704704
if (rc->isParent)
705705
continue;
706706

707+
/*
708+
* If you change the conditions under which rel locks are acquired
709+
* here, be sure to adjust ExecOpenScanRelation to match.
710+
*/
707711
switch (rc->markType)
708712
{
709713
case ROW_MARK_EXCLUSIVE:

src/backend/executor/execUtils.c

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

819-
if (erm->rti == scanrelid)
819+
/* Keep this check in sync with InitPlan! */
820+
if (erm->rti == scanrelid &&
821+
erm->relation != NULL)
820822
{
821823
lockmode = NoLock;
822824
break;

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/6997f226f5de7e02b6afd2d8ff67cf40f20e878b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy