Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita62873d

Browse files
committed
The attached adds a bit to the contrib/tablefunc regression test for
behavior of connectby() in the presence of infinite recursion. Pleaseapply this one in addition to the one sent earlier.Joe Conway
1 parent620dddf commita62873d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

‎contrib/tablefunc/expected/tablefunc.out

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,41 @@ SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '2', 0) AS t(k
177177
9 | 5 | 2
178178
(6 rows)
179179

180+
-- recursion detection
181+
INSERT INTO connectby_int VALUES(10,9);
182+
INSERT INTO connectby_int VALUES(11,10);
183+
INSERT INTO connectby_int VALUES(9,11);
184+
-- should fail due to infinite recursion
185+
SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '2', 0, '~') AS t(keyid int, parent_keyid int, level int, branch text);
186+
ERROR: infinite recursion detected
187+
-- infinite recursion failure avoided by depth limit
188+
SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '2', 4, '~') AS t(keyid int, parent_keyid int, level int, branch text);
189+
keyid | parent_keyid | level | branch
190+
-------+--------------+-------+-------------
191+
2 | | 0 | 2
192+
4 | 2 | 1 | 2~4
193+
6 | 4 | 2 | 2~4~6
194+
8 | 6 | 3 | 2~4~6~8
195+
5 | 2 | 1 | 2~5
196+
9 | 5 | 2 | 2~5~9
197+
10 | 9 | 3 | 2~5~9~10
198+
11 | 10 | 4 | 2~5~9~10~11
199+
(8 rows)
200+
201+
-- test for falsely detected recursion
202+
DROP TABLE connectby_int;
203+
CREATE TABLE connectby_int(keyid int, parent_keyid int);
204+
INSERT INTO connectby_int VALUES(11,NULL);
205+
INSERT INTO connectby_int VALUES(10,11);
206+
INSERT INTO connectby_int VALUES(111,11);
207+
INSERT INTO connectby_int VALUES(1,111);
208+
-- this should not fail due to recursion detection
209+
SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '11', 0, '-') AS t(keyid int, parent_keyid int, level int, branch text);
210+
keyid | parent_keyid | level | branch
211+
-------+--------------+-------+----------
212+
11 | | 0 | 11
213+
10 | 11 | 1 | 11-10
214+
111 | 11 | 1 | 11-111
215+
1 | 111 | 2 | 11-111-1
216+
(4 rows)
217+

‎contrib/tablefunc/sql/tablefunc.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '2', 0, '~') A
5858
-- without branch
5959
SELECT*FROM connectby('connectby_int','keyid','parent_keyid','2',0)AS t(keyidint, parent_keyidint, levelint);
6060

61+
-- recursion detection
62+
INSERT INTO connectby_intVALUES(10,9);
63+
INSERT INTO connectby_intVALUES(11,10);
64+
INSERT INTO connectby_intVALUES(9,11);
65+
66+
-- should fail due to infinite recursion
67+
SELECT*FROM connectby('connectby_int','keyid','parent_keyid','2',0,'~')AS t(keyidint, parent_keyidint, levelint, branchtext);
68+
69+
-- infinite recursion failure avoided by depth limit
70+
SELECT*FROM connectby('connectby_int','keyid','parent_keyid','2',4,'~')AS t(keyidint, parent_keyidint, levelint, branchtext);
71+
72+
-- test for falsely detected recursion
73+
DROPTABLE connectby_int;
74+
CREATETABLEconnectby_int(keyidint, parent_keyidint);
75+
INSERT INTO connectby_intVALUES(11,NULL);
76+
INSERT INTO connectby_intVALUES(10,11);
77+
INSERT INTO connectby_intVALUES(111,11);
78+
INSERT INTO connectby_intVALUES(1,111);
79+
-- this should not fail due to recursion detection
80+
SELECT*FROM connectby('connectby_int','keyid','parent_keyid','11',0,'-')AS t(keyidint, parent_keyidint, levelint, branchtext);
81+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp