Added code to make use of David Walker's wonderfully abusive hack on the pg_proc table that showed me how to write recursive SQL functions. We now have good use of the index on tree_sortkey when climbing the tree, woo-hoo!