[wp-hackers] Category Operation (Adjacency vs. Modified Preorder)

Denis de Bernardy denis at semiologic.com
Sat Feb 11 17:03:55 GMT 2006


> > sql tree preordering works nice, but imho implementing them without 
> > transactions and triggers is really asking for trouble.
> 
> I suppose performing an index check after every insert/update 
> might be a bit excessive .. or would it?

Technically, you can live with a corrupt tree, but you cannot trust any math
to make assumptions on its contents.

Assume the following if this is not immediate to you:

UPDATE tree SET rgt=rgt+2 WHERE rgt>5;
UPDATE tree SET lft=lft+2 WHERE lft>5;
INSERT INTO tree (lft, rgt, title) values (6, 7, 'Strawberry');

Now, imagine a user who is a little nervous with the save button and a
server than terminates php scripts without executing them until the end on
multi-clicks.

UPDATE tree SET rgt=rgt+2 WHERE rgt>5;
UPDATE tree SET lft=lft+2 WHERE lft>5;
-- user clicks the save button again

UPDATE tree SET rgt=rgt+2 WHERE rgt>5;
-- one more time

UPDATE tree SET rgt=rgt+2 WHERE rgt>5;
UPDATE tree SET lft=lft+2 WHERE lft>5;
INSERT INTO tree (lft, rgt, title) values (6, 7, 'Strawberry');

note that the sql tree remains useful when you traverse the data. when it
comes to the underlying math, however:

descendants != (right - left - 1) / 2

D.



More information about the wp-hackers mailing list