205
205
* The Param slot associated with the CTE query is used to hold a pointer
206
206
* to the CteState of the first CteScan node that initializes for this
207
207
* CTE. This node will be the one that holds the shared state for all the
208
* CTEs, particularly the shared tuplestore.
210
210
prmdata = &(estate->es_param_exec_vals[node->cteParam]);
211
211
Assert(prmdata->execPlan == NULL);
294
294
* If I am the leader, free the tuplestore.
296
296
if (node->leader == node)
297
298
tuplestore_end(node->cte_table);
299
node->cte_table = NULL;
300
303
/* ----------------------------------------------------------------
313
316
ExecScanReScan(&node->ss);
315
if (node->leader == node)
319
* Clear the tuplestore if a new scan of the underlying CTE is required.
320
* This implicitly resets all the tuplestore's read pointers. Note that
321
* multiple CTE nodes might redundantly clear the tuplestore; that's OK,
322
* and not unduly expensive. We'll stop taking this path as soon as
323
* somebody has attempted to read something from the underlying CTE
324
* (thereby causing its chgParam to be cleared).
326
if (node->leader->cteplanstate->chgParam != NULL)
328
tuplestore_clear(tuplestorestate);
329
node->leader->eof_cte = false;
318
* The leader is responsible for clearing the tuplestore if a new scan
319
* of the underlying CTE is required.
334
* Else, just rewind my own pointer. Either the underlying CTE
335
* doesn't need a rescan (and we can re-read what's in the tuplestore
336
* now), or somebody else already took care of it.
321
if (node->cteplanstate->chgParam != NULL)
323
tuplestore_clear(tuplestorestate);
324
node->eof_cte = false;
328
tuplestore_select_read_pointer(tuplestorestate, node->readptr);
329
tuplestore_rescan(tuplestorestate);
334
/* Not leader, so just rewind my own pointer */
335
338
tuplestore_select_read_pointer(tuplestorestate, node->readptr);
336
339
tuplestore_rescan(tuplestorestate);