@@ -347,55 +347,7 @@ rum_tuplesort_begin_rumitem(int workMem, FmgrInfo *cmp)
347347void
348348rum_tuplesort_end (RumTuplesortstate * state )
349349{
350- /* context swap probably not needed, but let's be safe */
351- MemoryContext oldcontext = MemoryContextSwitchTo (state -> sortcontext );
352-
353- #ifdef TRACE_SORT
354- long spaceUsed ;
355-
356- if (state -> tapeset )
357- spaceUsed = LogicalTapeSetBlocks (state -> tapeset );
358- else
359- spaceUsed = (state -> allowedMem - state -> availMem + 1023 ) /1024 ;
360- #endif
361-
362- /*
363- * Delete temporary "tape" files, if any.
364- *
365- * Note: want to include this in reported total cost of sort, hence need
366- * for two #ifdef TRACE_SORT sections.
367- */
368- if (state -> tapeset )
369- LogicalTapeSetClose (state -> tapeset );
370-
371- #ifdef TRACE_SORT
372- if (trace_sort )
373- {
374- if (state -> tapeset )
375- elog (LOG ,"external sort ended, %ld disk blocks used: %s" ,
376- spaceUsed ,pg_rusage_show (& state -> ru_start ));
377- else
378- elog (LOG ,"internal sort ended, %ld KB used: %s" ,
379- spaceUsed ,pg_rusage_show (& state -> ru_start ));
380- }
381- #endif
382-
383- /* Free any execution state created for CLUSTER case */
384- if (state -> estate != NULL )
385- {
386- ExprContext * econtext = GetPerTupleExprContext (state -> estate );
387-
388- ExecDropSingleTupleTableSlot (econtext -> ecxt_scantuple );
389- FreeExecutorState (state -> estate );
390- }
391-
392- MemoryContextSwitchTo (oldcontext );
393-
394- /*
395- * Free the per-sort memory context, thereby releasing all working memory,
396- * including the Tuplesortstate struct itself.
397- */
398- MemoryContextDelete (state -> sortcontext );
350+ tuplesort_free (state );
399351}
400352
401353/*