|
|
|
|
|
by aristidb
5585 days ago
|
|
If you have stored a tree with adjacence (parent-child) relations, how would you retrieve all nested children? Or would you propose a different storage mechanism that keeps the property that reparenting entire subtrees is cheap? (All this in your RDBMS of choice.) |
|
WITH RECURSIVE r AS (SELECT parent, child FROM tree UNION SELECT r.parent, tree.child FROM tree, r WHERE tree.parent = r.child) SELECT parent, child FROM r;
transforms this: (A,B), (B,C), (B,D)
into this: (A,B), (A,C), (A,D), (B,C), (B,D)