Skip to content

Commit 40055db

Browse files
committed
Repair relation refcount leakage caused by SELECT FOR UPDATE.
1 parent 31a8996 commit 40055db

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/backend/executor/execMain.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.107 2000/01/26 05:56:21 momjian Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.108 2000/02/03 00:02:58 tgl Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -596,19 +596,19 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
596596
estate->es_rowMark = NULL;
597597
if (parseTree->rowMark != NULL)
598598
{
599-
Relation relation;
600-
Oid relid;
601-
RowMark *rm;
602599
List *l;
603-
execRowMark *erm;
604600

605601
foreach(l, parseTree->rowMark)
606602
{
607-
rm = lfirst(l);
608-
relid = rt_fetch(rm->rti, rangeTable)->relid;
609-
relation = heap_open(relid, RowShareLock);
603+
RowMark *rm = lfirst(l);
604+
Oid relid;
605+
Relation relation;
606+
execRowMark *erm;
607+
610608
if (!(rm->info & ROW_MARK_FOR_UPDATE))
611609
continue;
610+
relid = rt_fetch(rm->rti, rangeTable)->relid;
611+
relation = heap_open(relid, RowShareLock);
612612
erm = (execRowMark *) palloc(sizeof(execRowMark));
613613
erm->relation = relation;
614614
erm->rti = rm->rti;
@@ -756,6 +756,7 @@ EndPlan(Plan *plan, EState *estate)
756756
{
757757
RelationInfo *resultRelationInfo;
758758
Relation intoRelationDesc;
759+
List *l;
759760

760761
/*
761762
* get information from state
@@ -796,10 +797,20 @@ EndPlan(Plan *plan, EState *estate)
796797
}
797798

798799
/*
799-
* close the "into" relation if necessary
800+
* close the "into" relation if necessary, again keeping lock
800801
*/
801802
if (intoRelationDesc != NULL)
802803
heap_close(intoRelationDesc, NoLock);
804+
805+
/*
806+
* close any relations selected FOR UPDATE, again keeping locks
807+
*/
808+
foreach(l, estate->es_rowMark)
809+
{
810+
execRowMark *erm = lfirst(l);
811+
812+
heap_close(erm->relation, NoLock);
813+
}
803814
}
804815

805816
/* ----------------------------------------------------------------
@@ -926,16 +937,16 @@ lnext: ;
926937
else if (estate->es_rowMark != NULL)
927938
{
928939
List *l;
929-
execRowMark *erm;
930-
Buffer buffer;
931-
HeapTupleData tuple;
932-
TupleTableSlot *newSlot;
933-
int test;
934940

935941
lmark: ;
936942
foreach(l, estate->es_rowMark)
937943
{
938-
erm = lfirst(l);
944+
execRowMark *erm = lfirst(l);
945+
Buffer buffer;
946+
HeapTupleData tuple;
947+
TupleTableSlot *newSlot;
948+
int test;
949+
939950
if (!ExecGetJunkAttribute(junkfilter,
940951
slot,
941952
erm->resname,

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