Re: WITH RECUSIVE patches 0723 - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: WITH RECUSIVE patches 0723
Date
Msg-id 877ib6rq6q.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: WITH RECUSIVE patches 0723  (Tatsuo Ishii <ishii@postgresql.org>)
Responses Re: WITH RECUSIVE patches 0723  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
>>>>> "Tatsuo" == Tatsuo Ishii <ishii@postgresql.org> writes:
Tatsuo> Included patches from Yoshiyuki should fix 1) and 2). I alsoTatsuo> add your SQLs to the regression test.
Thanks.

I think it needs this change in addition; without it, incorrect
results are returned when you reference a recursive view from within
the recursive query, due to the RecursionScan nodes becoming linked to
the wrong tuplestores.

The testcase for this would be something like

create view v0 as with recursive t1(id) as (values (1)                           union all select id+1 from t1 where id
<5) select * from t1;
 

with recursive t(id) as (select * from v0                        union all select id+1 from t where t.id < 8)
select count(*) from t;

-- expected output is 30, not 5


*** src/backend/executor/nodeRecursion.c~       Mon Jul 28 14:41:38 2008
--- src/backend/executor/nodeRecursion.c        Mon Jul 28 15:22:55 2008
***************
*** 124,129 ****
--- 124,130 ---- ExecInitRecursion(Recursion *node, EState *estate, int eflags) {       RecursionState
*recursionstate;
+       Tuplestorestate **save_tuplestorestate;        /* check for unsupported flags */       Assert(!(eflags &
EXEC_FLAG_MARK));
***************
*** 149,154 ****
--- 150,156 ----       /*        * Save the reference for the working table to share        */
+       save_tuplestorestate = estate->es_tuplestorestate;       estate->es_tuplestorestate =
&recursionstate->working_table;       /*
 
***************
*** 196,201 ****
--- 198,205 ----       ExecAssignResultTypeFromTL(&recursionstate->ss.ps);
ExecAssignScanProjectionInfo(&recursionstate->ss);
 
+       estate->es_tuplestorestate = save_tuplestorestate;
+        return recursionstate; } 


-- 
Andrew (irc:RhodiumToad)


pgsql-hackers by date:

Previous
From: "Asko Oja"
Date:
Subject: Re: Do we really want to migrate plproxy and citext into PG core distribution?
Next
From: "Hiroshi Saito"
Date:
Subject: Re: Do we really want to migrate plproxy and citext intoPG core distribution?