---------------------------------------------------------------- * ExecAppend * * Handles iteration over multiple subplans. * ---------------------------------------------------------------- */
| 298 | * ---------------------------------------------------------------- |
| 299 | */ |
| 300 | static TupleTableSlot * |
| 301 | ExecAppend(PlanState *pstate) |
| 302 | { |
| 303 | AppendState *node = castNode(AppendState, pstate); |
| 304 | TupleTableSlot *result; |
| 305 | |
| 306 | /* |
| 307 | * If this is the first call after Init or ReScan, we need to do the |
| 308 | * initialization work. |
| 309 | */ |
| 310 | if (!node->as_begun) |
| 311 | { |
| 312 | Assert(node->as_whichplan == INVALID_SUBPLAN_INDEX); |
| 313 | Assert(!node->as_syncdone); |
| 314 | |
| 315 | /* Nothing to do if there are no subplans */ |
| 316 | if (node->as_nplans == 0) |
| 317 | return ExecClearTuple(node->ps.ps_ResultTupleSlot); |
| 318 | |
| 319 | /* If there are any async subplans, begin executing them. */ |
| 320 | if (node->as_nasyncplans > 0) |
| 321 | ExecAppendAsyncBegin(node); |
| 322 | |
| 323 | /* |
| 324 | * If no sync subplan has been chosen, we must choose one before |
| 325 | * proceeding. |
| 326 | */ |
| 327 | if (!node->choose_next_subplan(node) && node->as_nasyncremain == 0) |
| 328 | return ExecClearTuple(node->ps.ps_ResultTupleSlot); |
| 329 | |
| 330 | Assert(node->as_syncdone || |
| 331 | (node->as_whichplan >= 0 && |
| 332 | node->as_whichplan < node->as_nplans)); |
| 333 | |
| 334 | /* And we're initialized. */ |
| 335 | node->as_begun = true; |
| 336 | } |
| 337 | |
| 338 | for (;;) |
| 339 | { |
| 340 | PlanState *subnode; |
| 341 | |
| 342 | CHECK_FOR_INTERRUPTS(); |
| 343 | |
| 344 | /* |
| 345 | * try to get a tuple from an async subplan if any |
| 346 | */ |
| 347 | if (node->as_syncdone || !bms_is_empty(node->as_needrequest)) |
| 348 | { |
| 349 | if (ExecAppendAsyncGetNext(node, &result)) |
| 350 | return result; |
| 351 | Assert(!node->as_syncdone); |
| 352 | Assert(bms_is_empty(node->as_needrequest)); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * figure out which sync subplan we are currently processing |
| 357 | */ |
nothing calls this directly
no test coverage detected