* Read the next tuple. We might fetch a tuple from one of the tuple queues * using gather_readnext, or if no tuple queue contains a tuple and the * single_copy flag is not set, we might generate one locally instead. */
| 261 | * single_copy flag is not set, we might generate one locally instead. |
| 262 | */ |
| 263 | static TupleTableSlot * |
| 264 | gather_getnext(GatherState *gatherstate) |
| 265 | { |
| 266 | PlanState *outerPlan = outerPlanState(gatherstate); |
| 267 | TupleTableSlot *outerTupleSlot; |
| 268 | TupleTableSlot *fslot = gatherstate->funnel_slot; |
| 269 | MinimalTuple tup; |
| 270 | |
| 271 | while (gatherstate->nreaders > 0 || gatherstate->need_to_scan_locally) |
| 272 | { |
| 273 | CHECK_FOR_INTERRUPTS(); |
| 274 | |
| 275 | if (gatherstate->nreaders > 0) |
| 276 | { |
| 277 | tup = gather_readnext(gatherstate); |
| 278 | |
| 279 | if (HeapTupleIsValid(tup)) |
| 280 | { |
| 281 | ExecStoreMinimalTuple(tup, /* tuple to store */ |
| 282 | fslot, /* slot to store the tuple */ |
| 283 | false); /* don't pfree tuple */ |
| 284 | return fslot; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | if (gatherstate->need_to_scan_locally) |
| 289 | { |
| 290 | EState *estate = gatherstate->ps.state; |
| 291 | |
| 292 | /* Install our DSA area while executing the plan. */ |
| 293 | estate->es_query_dsa = |
| 294 | gatherstate->pei ? gatherstate->pei->area : NULL; |
| 295 | outerTupleSlot = ExecProcNode(outerPlan); |
| 296 | estate->es_query_dsa = NULL; |
| 297 | |
| 298 | if (!TupIsNull(outerTupleSlot)) |
| 299 | return outerTupleSlot; |
| 300 | |
| 301 | gatherstate->need_to_scan_locally = false; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return ExecClearTuple(fslot); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Attempt to read a tuple from one of our parallel workers. |
no test coverage detected