88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.29 2000/01/26 05:56:23 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.30 2000/03/02 04:06:39 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -86,7 +86,7 @@ ExecMaterial(Material *node)
8686estate -> es_direction = ForwardScanDirection ;
8787
8888/* ----------------
89- * if we couldn't create the tempor current relations then
89+ * if we couldn't create the temprelation then
9090 * we print a warning and return NULL.
9191 * ----------------
9292 */
@@ -97,13 +97,6 @@ ExecMaterial(Material *node)
9797return NULL ;
9898}
9999
100- currentRelation = matstate -> csstate .css_currentRelation ;
101- if (currentRelation == NULL )
102- {
103- elog (DEBUG ,"ExecMaterial: current relation is NULL! aborting..." );
104- return NULL ;
105- }
106-
107100/* ----------------
108101 * retrieve tuples from the subplan and
109102 * insert them in the temporary relation
@@ -121,7 +114,6 @@ ExecMaterial(Material *node)
121114
122115ExecClearTuple (slot );
123116}
124- currentRelation = tempRelation ;
125117
126118/* ----------------
127119 * restore to user specified direction
@@ -134,6 +126,7 @@ ExecMaterial(Material *node)
134126 * sorted relation and update the sortstate information
135127 * ----------------
136128 */
129+ currentRelation = tempRelation ;
137130currentScanDesc = heap_beginscan (currentRelation ,/* relation */
138131ScanDirectionIsBackward (dir ),
139132SnapshotSelf ,/* seeself */
@@ -265,15 +258,14 @@ ExecInitMaterial(Material *node, EState *estate, Plan *parent)
265258 *create the temporary relation
266259 * ----------------
267260 */
268- /* len = ExecTargetListLength(node->plan.targetlist); */
269261tempDesc = ExecCreatR (tupType ,_NONAME_RELATION_ID_ );
270262
271263/* ----------------
272264 *save the relation descriptor in the sortstate
273265 * ----------------
274266 */
275267matstate -> mat_TempRelation = tempDesc ;
276- matstate -> csstate .css_currentRelation = tempDesc ;
268+ matstate -> csstate .css_currentRelation = NULL ;
277269
278270/* ----------------
279271 *return relation oid of temporary relation in a list
@@ -312,12 +304,11 @@ ExecEndMaterial(Material *node)
312304matstate = node -> matstate ;
313305tempRelation = matstate -> mat_TempRelation ;
314306
315- heap_drop (tempRelation );
316-
317307/* ----------------
318- *close thetemp relation and shut down thescan.
308+ *shut down thescan, but don't close thetemp relation
319309 * ----------------
320310 */
311+ matstate -> csstate .css_currentRelation = NULL ;
321312ExecCloseR ((Plan * )node );
322313
323314/* ----------------
@@ -332,6 +323,13 @@ ExecEndMaterial(Material *node)
332323 * ----------------
333324 */
334325ExecClearTuple (matstate -> csstate .css_ScanTupleSlot );
326+
327+ /* ----------------
328+ *delete the temp relation
329+ * ----------------
330+ */
331+ if (tempRelation != NULL )
332+ heap_drop (tempRelation );
335333}
336334
337335/* ----------------------------------------------------------------