NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Cute Tricks and Premature Optimizations (Score:2)
Beware that this is a premature optimization.
While this technique works fine with a static tree, it makes tree transformations hideously difficult. Imagine the pain that comes from moving node 12 to be a sibling of node 5, or removing node 5 and consequently promoting their children up a level.
The other technique
Re:Cute Tricks and Premature Optimizations (Score:2)
Re:Cute Tricks and Premature Optimizations (Score:2)
I personally don't think that the "ton of SELECTs" is all that horrible. That's probably my personal style though.
It starts out with something like this:
...which returns a list of IDs. That list of IDs then goes into a new SQL statement. The IDs are also pushed into a list that contains all IDs returned from your per-leve
Re:Cute Tricks and Premature Optimizations (Score:2)
I've written code as the one you describe dozens of times and I must say that it certainly was "fast enough". I'd be worried if I had very deep trees though, as that would be when it could become costly.
But then why store a tree in an RDB? Wouldn't XPath be a *lot* more pleasant to access random things in a tree? ;)
-- Robin Berjon [berjon.com]
Reply to This
Parent