[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [HACKERS] output branches before infinite recursion using connectby()?
From:       Joe Conway <mail () joeconway ! com>
Date:       2004-09-30 22:56:02
Message-ID: 415C8F02.5050803 () joeconway ! com
[Download RAW message or body]

Zhenchang Xing wrote:
> is it possible to output the branches before the detection of infinite 
> recursion when using connectby()?

It is possible if you patch the distributed source ;-)

Not heavily tested, but the attached patch against 7.4 seems to do the 
trick for me. I'm not really sure I'd want this in the distribution 
though -- anyone else with opinions?

Joe

["tablefunc-inf-rec.1.patch" (text/x-patch)]

Index: tablefunc.c
===================================================================
RCS file: /cvsroot/pgsql-server/contrib/tablefunc/tablefunc.c,v
retrieving revision 1.25.2.2
diff -c -r1.25.2.2 tablefunc.c
*** tablefunc.c	11 Aug 2004 01:02:07 -0000	1.25.2.2
--- tablefunc.c	30 Sep 2004 22:51:42 -0000
***************
*** 1416,1421 ****
--- 1416,1423 ----
  
  		for (i = 0; i < proc; i++)
  		{
+ 			bool	recursion_detected = false;
+ 
  			/* initialize branch for this pass */
  			appendStringInfo(branchstr, "%s", branch);
  			appendStringInfo(chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);
***************
*** 1433,1439 ****
  
  			/* check to see if this key is also an ancestor */
  			if (strstr(chk_branchstr->data, chk_current_key->data))
! 				elog(ERROR, "infinite recursion detected");
  
  			/* OK, extend the branch */
  			appendStringInfo(branchstr, "%s%s", branch_delim, current_key);
--- 1435,1444 ----
  
  			/* check to see if this key is also an ancestor */
  			if (strstr(chk_branchstr->data, chk_current_key->data))
! 			{
! 				elog(NOTICE, "infinite recursion detected");
! 				recursion_detected = true;
! 			}
  
  			/* OK, extend the branch */
  			appendStringInfo(branchstr, "%s%s", branch_delim, current_key);
***************
*** 1471,1477 ****
  			heap_freetuple(tuple);
  
  			/* recurse using current_key_parent as the new start_with */
! 			tupstore = build_tuplestore_recursively(key_fld,
  													parent_key_fld,
  													relname,
  													orderby_fld,
--- 1476,1483 ----
  			heap_freetuple(tuple);
  
  			/* recurse using current_key_parent as the new start_with */
! 			if (!recursion_detected)
! 				tupstore = build_tuplestore_recursively(key_fld,
  													parent_key_fld,
  													relname,
  													orderby_fld,


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic