/* ----------------------------------------------------------------
 *		ExecEndMaterial
 * ----------------------------------------------------------------
 */
void
ExecEndMaterial(MaterialState *node)
{
	ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
	ExecClearTuple(node->ss.ss_ScanTupleSlot);

	ExecEagerFreeMaterial(node);

	/*
	 * Release tuplestore resources for cases where EagerFree doesn't do it
	 */
	if (node->ts_state->matstore != NULL)
	{
		Material   *ma = (Material *) node->ss.ps.plan;
		if (ma->share_type == SHARE_MATERIAL_XSLICE && node->share_lk_ctxt)
		{
			shareinput_writer_waitdone(node->share_lk_ctxt, ma->share_id, ma->nsharer_xslice);
		}
		Assert(node->ts_pos);

		DestroyTupleStore(node);
	}

	/*
	 * shut down the subplan
	 */
	ExecEndNode(outerPlanState(node));
	EndPlanStateGpmonPkt(&node->ss.ps);
}
Exemple #2
0
void
ExecEagerFreeSort(SortState *node)
{
	Sort	   *plan = (Sort *) node->ss.ps.plan;
	EState	   *estate = node->ss.ps.state;

	/*
	 * If we still have potential readers assocated with this node,
	 * we shouldn't free the tuplesort too early.  The eager-free message
	 * doesn't know about upper ShareInputScan nodes, but those nodes
	 * bumps up the reference count in their initializations and decrement
	 * it in either EagerFree or ExecEnd.
	 */
	Assert(SHARE_MATERIAL != plan->share_type && SHARE_MATERIAL_XSLICE != plan->share_type);
	if (SHARE_SORT == plan->share_type)
	{
		ShareNodeEntry	   *snEntry;

		snEntry = ExecGetShareNodeEntry(estate, plan->share_id, false);

		if (snEntry->refcount > 0)
		{
			return;
		}
	}

	/* clean out the tuple table */
	ExecClearTuple(node->ss.ss_ScanTupleSlot);

	/* must drop pointer to sort result tuple */
	ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);

	if (NULL != node->tuplesortstate->sortstore || NULL != node->tuplesortstate->sortstore_mk)
	{
		Sort *sort = (Sort *) node->ss.ps.plan;

		/* If this is a producer for a ShareScan, then wait for all consumers to be done */
		/* XXX gcaragea: In Materialize, we moved this to End instead of EF, since EF might be too early to do it */
		if(sort->share_type == SHARE_SORT_XSLICE && NULL != node->share_lk_ctxt)
		{
			shareinput_writer_waitdone(node->share_lk_ctxt, sort->share_id, sort->nsharer_xslice);
		}

		if(gp_enable_mk_sort)
		{
			tuplesort_end_mk(node->tuplesortstate->sortstore_mk);
			node->tuplesortstate->sortstore_mk = NULL;
		}
		else
		{
			tuplesort_end(node->tuplesortstate->sortstore);
			node->tuplesortstate->sortstore = NULL;

		}

		ExecSortResetWorkfileState(node);
	}
}