/* ------------------------------------------------------------------ * ExecShareInputScan * Retrieve a tuple from the ShareInputScan * ------------------------------------------------------------------ */ TupleTableSlot * ExecShareInputScan(ShareInputScanState *node) { EState *estate; ScanDirection dir; bool forward; TupleTableSlot *slot; ShareInputScan * sisc = (ShareInputScan *) node->ss.ps.plan; ShareType share_type = sisc->share_type; /* * get state info from node */ estate = node->ss.ps.state; dir = estate->es_direction; forward = ScanDirectionIsForward(dir); /* if first time call, need to initialize the tuplestore state. */ if(node->ts_state == NULL) { elog(DEBUG1, "SISC (shareid=%d, slice=%d): No tuplestore yet, initializing tuplestore", sisc->share_id, currentSliceId); init_tuplestore_state(node); } slot = node->ss.ps.ps_ResultTupleSlot; while(1) { bool gotOK = false; if(share_type == SHARE_MATERIAL || share_type == SHARE_MATERIAL_XSLICE) { ntuplestore_acc_advance((NTupleStoreAccessor *) node->ts_pos, forward ? 1 : -1); gotOK = ntuplestore_acc_current_tupleslot((NTupleStoreAccessor *) node->ts_pos, slot); } else { gotOK = tuplesort_gettupleslot_pos(node->ts_state->sortstore, (TuplesortPos *)node->ts_pos, forward, slot, CurrentMemoryContext); } if(!gotOK) return NULL; SIMPLE_FAULT_INJECTOR(ExecShareInputNext); return slot; } Assert(!"should not be here"); return NULL; }
/* ------------------------------------------------------------------ * ShareInputNext * Retrieve a tuple from the ShareInputScan * ------------------------------------------------------------------ */ TupleTableSlot * ShareInputNext(ShareInputScanState *node) { EState *estate; ScanDirection dir; bool forward; TupleTableSlot *slot; ShareInputScan * sisc = (ShareInputScan *) node->ss.ps.plan; ShareType share_type = sisc->share_type; /* * get state info from node */ estate = node->ss.ps.state; dir = estate->es_direction; forward = ScanDirectionIsForward(dir); /* if first time call, need to initialize the tuplestore state. */ if(node->ts_state == NULL) { elog(DEBUG1, "SISC (shareid=%d, slice=%d): No tuplestore yet, initializing tuplestore", sisc->share_id, currentSliceId); init_tuplestore_state(node); } slot = node->ss.ps.ps_ResultTupleSlot; while(1) { bool gotOK = false; if(share_type == SHARE_MATERIAL || share_type == SHARE_MATERIAL_XSLICE) { ntuplestore_acc_advance((NTupleStoreAccessor *) node->ts_pos, forward ? 1 : -1); gotOK = ntuplestore_acc_current_tupleslot((NTupleStoreAccessor *) node->ts_pos, slot); } else { if(gp_enable_mk_sort) { gotOK = tuplesort_gettupleslot_pos_mk(node->ts_state->sortstore_mk, (TuplesortPos_mk *)node->ts_pos, forward, slot); } else { gotOK = tuplesort_gettupleslot_pos(node->ts_state->sortstore, (TuplesortPos *)node->ts_pos, forward, slot); } } if(!gotOK) return NULL; Gpmon_M_Incr_Rows_Out(GpmonPktFromShareInputState(node)); CheckSendPlanStateGpmonPkt(&node->ss.ps); return slot; } Assert(!"should not be here"); return NULL; }