]> granicus.if.org Git - postgresql/commit
Be sure to rewind the tuplestore read pointer in non-leader CTEScan nodes.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Sep 2016 15:34:44 +0000 (11:34 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Sep 2016 15:34:44 +0000 (11:34 -0400)
commit8552f9b903a099d82763460cb7ca28715d0ad2bb
tree3e3473c120ab26009b01bbf8a0b6b4baf09c293a
parent775c5502a86ee4c599b8547809659c086dae1bc8
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>
src/backend/executor/nodeCtescan.c
src/test/isolation/expected/eval-plan-qual.out
src/test/isolation/specs/eval-plan-qual.spec