Skip to content

Commit 343f615

Browse files
committed
ExecEndAppend() neglected to close indices on appended result rels,
and improperly prevented the main result rel from being closed if it wasn't one of the Append's own result rels. Per report from Hiroshi.
1 parent 5cbbdd2 commit 343f615

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/backend/executor/nodeAppend.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.36 2000/10/05 19:11:26 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.37 2000/11/09 18:12:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -493,27 +493,32 @@ ExecEndAppend(Append *node)
493493

494494
/* ----------------
495495
* close out the different result relations
496+
*
497+
* NB: this must agree with what EndPlan() does to close a result rel
496498
* ----------------
497499
*/
498500
resultRelationInfoList = appendstate->as_result_relation_info_list;
499501
while (resultRelationInfoList != NIL)
500502
{
501503
RelationInfo *resultRelationInfo;
502-
Relation resultRelationDesc;
503504

504505
resultRelationInfo = (RelationInfo *) lfirst(resultRelationInfoList);
505-
resultRelationDesc = resultRelationInfo->ri_RelationDesc;
506-
heap_close(resultRelationDesc, NoLock);
506+
507+
heap_close(resultRelationInfo->ri_RelationDesc, NoLock);
508+
/* close indices on the result relation, too */
509+
ExecCloseIndices(resultRelationInfo);
510+
511+
/*
512+
* estate may (or may not) be pointing at one of my result relations.
513+
* If so, make sure EndPlan() doesn't try to close it again!
514+
*/
515+
if (estate->es_result_relation_info == resultRelationInfo)
516+
estate->es_result_relation_info = NULL;
517+
507518
pfree(resultRelationInfo);
508519
resultRelationInfoList = lnext(resultRelationInfoList);
509520
}
510521
appendstate->as_result_relation_info_list = NIL;
511-
/*
512-
* This next step is critical to prevent EndPlan() from trying to close
513-
* an already-closed-and-deleted RelationInfo --- es_result_relation_info
514-
* is pointing at one of the nodes we just zapped above.
515-
*/
516-
estate->es_result_relation_info = NULL;
517522

518523
/*
519524
* XXX should free appendstate->as_junkfilter_list here

0 commit comments

Comments
 (0)