aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-09-22 11:34:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-09-22 11:34:44 -0400
commita88fe25f50ae9ce491fe10a90aeef2cbed6f2b9a (patch)
treeca1409f4b477afeebf8024b03da514cdc3817f53 /src/backend/executor
parentc925e6335e1da58aba3dd764bb9f97fa81d893b8 (diff)
downloadpostgresql-a88fe25f50ae9ce491fe10a90aeef2cbed6f2b9a.tar.gz
postgresql-a88fe25f50ae9ce491fe10a90aeef2cbed6f2b9a.zip
Be sure to rewind the tuplestore read pointer in non-leader CTEScan nodes.
ExecInitCteScan supposed that it didn't have to do anything to the extra tuplestore read pointer it gets from tuplestore_alloc_read_pointer. However, it needs this read pointer to be positioned at the start of the tuplestore, while tuplestore_alloc_read_pointer is actually defined as cloning the current position of read pointer 0. In normal situations that accidentally works because we initialize the whole plan tree at once, before anything gets read. But it fails in an EvalPlanQual recheck, as illustrated in bug #14328 from Dima Pavlov. To fix, just forcibly rewind the pointer after tuplestore_alloc_read_pointer. The cost of doing so is negligible unless the tuplestore is already in TSS_READFILE state, which wouldn't happen in normal cases. We could consider altering tuplestore's API to make that case cheaper, but that would make for a more invasive back-patch and it doesn't seem worth it. This has been broken probably for as long as we've had CTEs, so back-patch to all supported branches. Discussion: <32468.1474548308@sss.pgh.pa.us>
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/nodeCtescan.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/executor/nodeCtescan.c b/src/backend/executor/nodeCtescan.c
index 3c2f684a062..162650ad8ab 100644
--- a/src/backend/executor/nodeCtescan.c
+++ b/src/backend/executor/nodeCtescan.c
@@ -224,9 +224,13 @@ ExecInitCteScan(CteScan *node, EState *estate, int eflags)
{
/* Not the leader */
Assert(IsA(scanstate->leader, CteScanState));
+ /* Create my own read pointer, and ensure it is at start */
scanstate->readptr =
tuplestore_alloc_read_pointer(scanstate->leader->cte_table,
scanstate->eflags);
+ tuplestore_select_read_pointer(scanstate->leader->cte_table,
+ scanstate->readptr);
+ tuplestore_rescan(scanstate->leader->cte_table);
}
/*