forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf490dbe
committed
> Now I'm testing connectby() in the /contrib/tablefunc in 7.3b1, which would
> be a useful function for many users. However, I found the fact that> if connectby_tree has the following data, connectby() tries to search the end> of roots without knowing that the relations are infinite(-5-9-10-11-9-10-11-).> I hope connectby() supports a check routine to find infinite relations.>>> CREATE TABLE connectby_tree(keyid int, parent_keyid int);> INSERT INTO connectby_tree VALUES(1,NULL);> INSERT INTO connectby_tree VALUES(2,1);> INSERT INTO connectby_tree VALUES(3,1);> INSERT INTO connectby_tree VALUES(4,2);> INSERT INTO connectby_tree VALUES(5,2);> INSERT INTO connectby_tree VALUES(6,4);> INSERT INTO connectby_tree VALUES(7,3);> INSERT INTO connectby_tree VALUES(8,6);> INSERT INTO connectby_tree VALUES(9,5);>> INSERT INTO connectby_tree VALUES(10,9);> INSERT INTO connectby_tree VALUES(11,10);> INSERT INTO connectby_tree VALUES(9,11); <-- infinite>The attached patch fixes the infinite recursion bug incontrib/tablefunc/tablefunc.c:connectby found by Masaru Sugawara.test=# SELECT * FROM connectby('connectby_tree', 'keyid','parent_keyid', '2', 4, '~') AS t(keyid int, parent_keyid int, levelint, branch text); keyid | parent_keyid | level | branch-------+--------------+-------+------------- 2 | | 0 | 2 4 | 2 | 1 | 2~4 6 | 4 | 2 | 2~4~6 8 | 6 | 3 | 2~4~6~8 5 | 2 | 1 | 2~5 9 | 5 | 2 | 2~5~9 10 | 9 | 3 | 2~5~9~10 11 | 10 | 4 | 2~5~9~10~11(8 rows)test=# SELECT * FROM connectby('connectby_tree', 'keyid','parent_keyid', '2', 5, '~') AS t(keyid int, parent_keyid int, levelint, branch text);ERROR: infinite recursion detectedI implemented it by checking the branch string for repeated keys(whether or not the branch is returned). The performance hit was prettyminimal -- about 1% for a moderately complex test case (220000 recordtable, 9 level tree with 3800 members).Joe Conway1 parentb2711a0 commitf490dbe
1 file changed
+16
-15
lines changedLines changed: 16 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
801 | 801 |
| |
802 | 802 |
| |
803 | 803 |
| |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
804 | 808 |
| |
805 | 809 |
| |
806 | 810 |
| |
| |||
852 | 856 |
| |
853 | 857 |
| |
854 | 858 |
| |
855 |
| - | |
856 |
| - | |
857 |
| - | |
858 |
| - | |
859 |
| - | |
860 |
| - | |
861 |
| - | |
862 |
| - | |
| 859 | + | |
| 860 | + | |
863 | 861 |
| |
864 | 862 |
| |
865 | 863 |
| |
| |||
868 | 866 |
| |
869 | 867 |
| |
870 | 868 |
| |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
871 | 873 |
| |
872 | 874 |
| |
873 | 875 |
| |
874 | 876 |
| |
875 |
| - | |
876 |
| - | |
877 |
| - | |
878 |
| - | |
879 |
| - | |
880 |
| - | |
881 |
| - | |
| 877 | + | |
| 878 | + | |
882 | 879 |
| |
883 | 880 |
| |
884 | 881 |
| |
| |||
916 | 913 |
| |
917 | 914 |
| |
918 | 915 |
| |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
919 | 920 |
| |
920 | 921 |
| |
921 | 922 |
| |
|
0 commit comments
Comments
(0)