---------------------------------------------------------------- * ExecSort * * Sorts tuples from the outer subtree of the node using tuplesort, * which saves the results in a temporary file or memory. After the * initial call, returns a tuple from the file with each call. * * Conditions: * -- none. * * Initial States: * -- the outer child is prepared to return the first tup
| 46 | * ---------------------------------------------------------------- |
| 47 | */ |
| 48 | static TupleTableSlot * |
| 49 | ExecSort(PlanState *pstate) |
| 50 | { |
| 51 | SortState *node = castNode(SortState, pstate); |
| 52 | EState *estate; |
| 53 | ScanDirection dir; |
| 54 | Tuplesortstate *tuplesortstate; |
| 55 | TupleTableSlot *slot; |
| 56 | |
| 57 | CHECK_FOR_INTERRUPTS(); |
| 58 | |
| 59 | /* |
| 60 | * get state info from node |
| 61 | */ |
| 62 | SO1_printf("ExecSort: %s\n", |
| 63 | "entering routine"); |
| 64 | |
| 65 | estate = node->ss.ps.state; |
| 66 | dir = estate->es_direction; |
| 67 | tuplesortstate = (Tuplesortstate *) node->tuplesortstate; |
| 68 | |
| 69 | /* |
| 70 | * In Window node, we might need to call ExecSort again even when |
| 71 | * the last tuple in the Sort has been retrieved. Since we might |
| 72 | * eager free the tuplestore, the tuplestorestate could be NULL. |
| 73 | * We simply return NULL in this case. |
| 74 | */ |
| 75 | if (node->sort_Done && tuplesortstate == NULL) |
| 76 | { |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * If first time through, read all tuples from outer plan and pass them to |
| 82 | * tuplesort.c. Subsequent calls just fetch tuples from tuplesort. |
| 83 | */ |
| 84 | |
| 85 | if (!node->sort_Done) |
| 86 | { |
| 87 | Sort *plannode = (Sort *) node->ss.ps.plan; |
| 88 | PlanState *outerNode; |
| 89 | TupleDesc tupDesc; |
| 90 | |
| 91 | SO1_printf("ExecSort: %s\n", |
| 92 | "sorting subplan"); |
| 93 | |
| 94 | /* |
| 95 | * Want to scan subplan in the forward direction while creating the |
| 96 | * sorted data. |
| 97 | */ |
| 98 | estate->es_direction = ForwardScanDirection; |
| 99 | |
| 100 | /* |
| 101 | * Initialize tuplesort module. |
| 102 | */ |
| 103 | SO1_printf("ExecSort: %s\n", |
| 104 | "calling tuplesort_begin"); |
| 105 |
nothing calls this directly
no test coverage detected