Ok, select for update it is. I will do some concurrency testing as
well and see if I can break it.
If by level 0 you mean null, then I think there is a good
reason for things with context_id null to have a non-null tree sortkey.
Say you want all the parents of e given a heirarchy
Node level0 level1
a Null 1
b 1 1.1
c Null 2
d 1 2.1
e 1.1 2.1.1
if a and c are level 0 then as you walk up you have no way of picking
out a or c as the parent of e, whereas in the case of all
tree_sortkeys starting at level1 it's just the same as the other
parents...
I also think given how many are null (~20% for realistic data sets --
a problem in itself really) the optimizer would have better statistics
if there are no null tree_sortkeys. although I guess with postgres
partial indexes can make that much less of a problem.