]> granicus.if.org Git - postgresql/commitdiff
Fix ExecOpenScanRelation to take a lock on a ROW_MARK_COPY relation.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Mar 2015 19:53:06 +0000 (15:53 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 24 Mar 2015 19:53:06 +0000 (15:53 -0400)
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.)

src/backend/executor/execMain.c
src/backend/executor/execUtils.c

index df6af1b898cd1c179d35f1f0593e6e5af8259237..2c4b1ab77e3f13466fe4cd31646a6eaa45a0f795 100644 (file)
@@ -804,6 +804,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:
index e4e70c41b630e23c73d6545f42642153a8b39c6b..65e4904875a6331dc76e1358d437856bde4fa7a9 100644 (file)
@@ -819,7 +819,9 @@ ExecOpenScanRelation(EState *estate, Index scanrelid)
                {
                        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;