Sorted receiver using binary heap */
| 430 | |
| 431 | /* Sorted receiver using binary heap */ |
| 432 | static TupleTableSlot * |
| 433 | execMotionSortedReceiver(MotionState *node) |
| 434 | { |
| 435 | TupleTableSlot *slot; |
| 436 | binaryheap *hp = node->tupleheap; |
| 437 | MinimalTuple inputTuple; |
| 438 | Motion *motion = (Motion *) node->ps.plan; |
| 439 | EState *estate = node->ps.state; |
| 440 | |
| 441 | AssertState(motion->motionType == MOTIONTYPE_GATHER && |
| 442 | motion->sendSorted && |
| 443 | hp != NULL); |
| 444 | |
| 445 | /* Notify senders and return EOS if caller doesn't want any more data. */ |
| 446 | if (node->stopRequested) |
| 447 | { |
| 448 | |
| 449 | SendStopMessage(node->ps.state->motionlayer_context, |
| 450 | node->ps.state->interconnect_context, |
| 451 | motion->motionID); |
| 452 | return NULL; |
| 453 | } |
| 454 | |
| 455 | if (estate->interconnect_context == NULL) |
| 456 | { |
| 457 | if (!estate->es_interconnect_is_setup && estate->dispatcherState && |
| 458 | !estate->es_got_eos) |
| 459 | { |
| 460 | /* |
| 461 | * We could only possibly get here in the following scenario: |
| 462 | * 1. We are QD gracefully aborting a transaction. |
| 463 | * 2. We have torn down the interconnect of the current slice. |
| 464 | * 3. Since an error has happened, we no longer need to finish fetching |
| 465 | * all the tuples, hence squelching the executor subtree. |
| 466 | * 4. We are in the process of ExecSquelchShareInputScan(), and the |
| 467 | * Shared Scan has this Motion below it. |
| 468 | * |
| 469 | * NB: if you need to change this, see also execMotionUnsortedReceiver() |
| 470 | */ |
| 471 | ereport(NOTICE, |
| 472 | (errmsg("An ERROR must have happened. Stopping a Shared Scan."))); |
| 473 | return NULL; |
| 474 | } |
| 475 | else |
| 476 | ereport(ERROR, (errmsg("Interconnect is down unexpectedly."))); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * On first call, fill the priority queue with each sender's first tuple. |
| 481 | */ |
| 482 | if (!node->tupleheapReady) |
| 483 | { |
| 484 | MinimalTuple inputTuple; |
| 485 | binaryheap *hp = node->tupleheap; |
| 486 | Motion *motion = (Motion *) node->ps.plan; |
| 487 | int iSegIdx; |
| 488 | ListCell *lcProcess; |
| 489 | ExecSlice *sendSlice = &node->ps.state->es_sliceTable->slices[motion->motionID]; |
no test coverage detected