]> 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:39 +0000 (19:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 Aug 2012 23:01:39 +0000 (19:01 -0400)
commitdda44070cc9c9bb3d0fedcca4e9610ea7ec8ee77
tree2812d8834225a8c38894b06564a076606ea7369e
parent1a36a773a6352de81d8b207f87b7259fbd756b16
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