pgsql: Fix rescan logic in nodeCtescan.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix rescan logic in nodeCtescan.
Date: 2012-08-15 23:02:54
Message-ID: E1T1mc2-00008L-Ag@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4c5316931f2ec6b47aa4b98e2c3ca704907aca24

Modified Files
--------------
src/backend/executor/nodeCtescan.c | 37 +++++++++--------
src/test/regress/expected/with.out | 75 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/with.sql | 56 +++++++++++++++++++++++++++
3 files changed, 151 insertions(+), 17 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2012-08-15 23:05:07 pgsql: In psql, if the is no connection object, e.g. due to a server cr
Previous Message Bruce Momjian 2012-08-15 22:30:40 Re: [COMMITTERS] pgsql: Clean up the #include mess a little.