]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix rescan logic in nodeCtescan.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 Aug 2012 23:01:23 +0000 (19:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 Aug 2012 23:01:23 +0000 (19:01 -0400)
commitcaf97eb72e2e08378aefdd8f75c10b73fd04172b
treef36913629aef7c866e00bad09d96c8064293c738
parent82634a88d1ba2fdc3308d589b0b8f3bfdbd880f1
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