>>>>> "Tatsuo" == Tatsuo Ishii <[EMAIL PROTECTED]> writes:

 Tatsuo> Included patches from Yoshiyuki should fix 1) and 2). I also
 Tatsuo> 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)

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to