---------------------------------------------------------------- * ExecReScanCteScan * * Rescans the relation. * ---------------------------------------------------------------- */
| 317 | * ---------------------------------------------------------------- |
| 318 | */ |
| 319 | void |
| 320 | ExecReScanCteScan(CteScanState *node) |
| 321 | { |
| 322 | Tuplestorestate *tuplestorestate = node->leader->cte_table; |
| 323 | |
| 324 | if (node->ss.ps.ps_ResultTupleSlot) |
| 325 | ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); |
| 326 | |
| 327 | ExecScanReScan(&node->ss); |
| 328 | |
| 329 | /* |
| 330 | * Clear the tuplestore if a new scan of the underlying CTE is required. |
| 331 | * This implicitly resets all the tuplestore's read pointers. Note that |
| 332 | * multiple CTE nodes might redundantly clear the tuplestore; that's OK, |
| 333 | * and not unduly expensive. We'll stop taking this path as soon as |
| 334 | * somebody has attempted to read something from the underlying CTE |
| 335 | * (thereby causing its chgParam to be cleared). |
| 336 | */ |
| 337 | if (node->leader->cteplanstate->chgParam != NULL) |
| 338 | { |
| 339 | tuplestore_clear(tuplestorestate); |
| 340 | node->leader->eof_cte = false; |
| 341 | } |
| 342 | else |
| 343 | { |
| 344 | /* |
| 345 | * Else, just rewind my own pointer. Either the underlying CTE |
| 346 | * doesn't need a rescan (and we can re-read what's in the tuplestore |
| 347 | * now), or somebody else already took care of it. |
| 348 | */ |
| 349 | tuplestore_select_read_pointer(tuplestorestate, node->readptr); |
| 350 | tuplestore_rescan(tuplestorestate); |
| 351 | } |
| 352 | } |
no test coverage detected