/* ------------------------------------------------------------------ * ExecReScanShareInputScan * ------------------------------------------------------------------ */ void ExecReScanShareInputScan(ShareInputScanState *node) { /* if first time call, need to initialize the tuplestore state */ if(node->ts_state == NULL) { init_tuplestore_state(node); } ShareInputScan *sisc = (ShareInputScan *) node->ss.ps.plan; ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); Assert(NULL != node->ts_pos); if(sisc->share_type == SHARE_MATERIAL || sisc->share_type == SHARE_MATERIAL_XSLICE) { Assert(NULL != node->ts_state->matstore); ntuplestore_acc_seek_bof((NTupleStoreAccessor *) node->ts_pos); } else if (sisc->share_type == SHARE_SORT || sisc->share_type == SHARE_SORT_XSLICE) { Assert(NULL != node->ts_state->sortstore); tuplesort_rescan_pos(node->ts_state->sortstore, (TuplesortPos *) node->ts_pos); } else { Assert(!"ExecShareInputScanReScan: invalid share type "); } }
/* ------------------------------------------------------------------ * ExecShareInputScanReScan * ------------------------------------------------------------------ */ void ExecShareInputScanReScan(ShareInputScanState *node, ExprContext *exprCtxt) { /* if first time call, need to initialize the tuplestore state */ if(node->ts_state == NULL) { init_tuplestore_state(node); } ShareInputScan *sisc = (ShareInputScan *) node->ss.ps.plan; ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); Assert(NULL != node->ts_pos); if(sisc->share_type == SHARE_MATERIAL || sisc->share_type == SHARE_MATERIAL_XSLICE) { Assert(NULL != node->ts_state->matstore); ntuplestore_acc_seek_bof((NTupleStoreAccessor *) node->ts_pos); } else if (sisc->share_type == SHARE_SORT || sisc->share_type == SHARE_SORT_XSLICE) { if(gp_enable_mk_sort) { Assert(NULL != node->ts_state->sortstore_mk); tuplesort_rescan_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk *) node->ts_pos); } else { Assert(NULL != node->ts_state->sortstore); tuplesort_rescan_pos(node->ts_state->sortstore, (TuplesortPos *) node->ts_pos); } } else { Assert(!"ExecShareInputScanReScan: invalid share type "); } Gpmon_M_Incr(GpmonPktFromShareInputState(node), GPMON_SHAREINPUT_RESCAN); CheckSendPlanStateGpmonPkt(&node->ss.ps); }
/* * init_tuplestore_state * Initialize the tuplestore state for the Shared node if the state * is not initialized. */ static void init_tuplestore_state(ShareInputScanState *node) { Assert(node->ts_state == NULL); EState *estate = node->ss.ps.state; ShareInputScan *sisc = (ShareInputScan *)node->ss.ps.plan; ShareNodeEntry *snEntry = ExecGetShareNodeEntry(estate, sisc->share_id, false); PlanState *snState = NULL; ShareType share_type = sisc->share_type; if(snEntry) { snState = (PlanState *) snEntry->shareState; if(snState) { ExecProcNode(snState); } else { Assert(share_type == SHARE_MATERIAL_XSLICE || share_type == SHARE_SORT_XSLICE); } } if(share_type == SHARE_MATERIAL_XSLICE) { char rwfile_prefix[100]; shareinput_create_bufname_prefix(rwfile_prefix, sizeof(rwfile_prefix), sisc->share_id); node->ts_state = palloc0(sizeof(GenericTupStore)); node->ts_state->matstore = ntuplestore_create_readerwriter(rwfile_prefix, 0, false); node->ts_pos = (void *) ntuplestore_create_accessor(node->ts_state->matstore, false); ntuplestore_acc_seek_bof((NTupleStoreAccessor *)node->ts_pos); } else if(share_type == SHARE_MATERIAL) { /* The materialstate->ts_state structure should have been initialized already, during init of material node */ node->ts_state = ((MaterialState *)snState)->ts_state; Assert(NULL != node->ts_state->matstore); node->ts_pos = (void *) ntuplestore_create_accessor(node->ts_state->matstore, false); ntuplestore_acc_seek_bof((NTupleStoreAccessor *)node->ts_pos); } else if(share_type == SHARE_SORT_XSLICE) { char rwfile_prefix[100]; shareinput_create_bufname_prefix(rwfile_prefix, sizeof(rwfile_prefix), sisc->share_id); node->ts_state = palloc0(sizeof(GenericTupStore)); if(gp_enable_mk_sort) { node->ts_state->sortstore_mk = tuplesort_begin_heap_file_readerwriter_mk( & node->ss, rwfile_prefix, false, NULL, 0, NULL, NULL, PlanStateOperatorMemKB((PlanState *) node), true); tuplesort_begin_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk **)(&node->ts_pos)); tuplesort_rescan_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk *)node->ts_pos); } else { node->ts_state->sortstore = tuplesort_begin_heap_file_readerwriter( rwfile_prefix, false, NULL, 0, NULL, NULL, PlanStateOperatorMemKB((PlanState *) node), true); tuplesort_begin_pos(node->ts_state->sortstore, (TuplesortPos **)(&node->ts_pos)); tuplesort_rescan_pos(node->ts_state->sortstore, (TuplesortPos *)node->ts_pos); } } else { Assert(sisc->share_type == SHARE_SORT); Assert(snState != NULL); if(gp_enable_mk_sort) { node->ts_state = ((SortState *)snState)->tuplesortstate; Assert(NULL != node->ts_state->sortstore_mk); tuplesort_begin_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk **)(&node->ts_pos)); tuplesort_rescan_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk *)node->ts_pos); } else { node->ts_state = ((SortState *)snState)->tuplesortstate; Assert(NULL != node->ts_state->sortstore); tuplesort_begin_pos(node->ts_state->sortstore, (TuplesortPos **)(&node->ts_pos)); tuplesort_rescan_pos(node->ts_state->sortstore, (TuplesortPos *)node->ts_pos); } } Assert(NULL != node->ts_state); Assert(NULL != node->ts_state->matstore || NULL != node->ts_state->sortstore || NULL != node->ts_state->sortstore_mk); }