]> granicus.if.org Git - postgresql/commit
Fix rescan logic in nodeCtescan.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 Aug 2012 23:01:16 +0000 (19:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 Aug 2012 23:02:33 +0000 (19:02 -0400)
commit4c5316931f2ec6b47aa4b98e2c3ca704907aca24
tree44db0b280cece3700c174d13104365932287ae4f
parent083b9133aa0e5e91d74ba46b530a74989223324d
Fix rescan logic in nodeCtescan.

The previous coding essentially assumed that nodes would be rescanned in
the same order they were initialized in; or at least that the "leader" of
a group of CTEscans would be rescanned before any others were required to
execute.  Unfortunately, that isn't even a little bit true.  It's possible
to devise queries in which the leader isn't rescanned until other CTEscans
on the same CTE have run to completion, or even in which the leader never
gets a rescan call at all.

The fix makes the leader specially responsible only for initial creation
and final destruction of the tuplestore; rescan resets are now a
symmetrically shared responsibility.  This means that we might reset the
tuplestore multiple times when restarting a plan subtree containing
multiple CTEscans; but resetting an already-empty tuplestore is cheap
enough that that doesn't seem like a problem.

Per report from Adam Mackler; the new regression test cases are based on
his example query.

Back-patch to 8.4 where CTE scans were introduced.
src/backend/executor/nodeCtescan.c
src/test/regress/expected/with.out
src/test/regress/sql/with.sql