Re: Nested Sets Insertion
Date: Mon, 12 May 2003 11:30:40 -0700
"Enu" <ewiner_at_adelphia.net> wrote in message
> I'm making some forum software using PHP and MySQL that's quite a bit
> like a Usenet group (i.e. threads). The data won't change much, and
> the program is very dependent on being able to count the number of
> descendants of any post (which is very slow with adjacency tables), so
> I want to use nested sets. Still, for when a post is added directly
> into the tree, I haven't been able to find any optimized examples of
> how to do this. I'm sure there's some sort of spiffy mathematical
> solution of INSERT and UPDATE statements that can append a child to a
> node and update the left and right values of the affected nodes.
> Could somebody point me in the right direction? Thanks!
You either use persistent labeling schema, such as materialized path, or volatile labeling such as nested sets. Admitedly, with persistent labeling schema quering number of children is not as trivial as with nested sets. But it is still easy -- it's index range scan! I never saw a thread bigger than 1000 messages. Comparing to the whole usenet volume it's a pretty selective range scan.
They do have indexes in MySQL, do they?-) Received on Mon May 12 2003 - 20:30:40 CEST