Re: yet another hierarchy model
Date: Mon, 15 Oct 2001 16:48:40 GMT
Message-ID: <IrEy7.29832$ev2.36482_at_www.newsranger.com>
In article <c0d87ec0.0110150804.5bc67845_at_posting.google.com>, --CELKO-- says...
>
>>> I think this approach is somewhat similar to Celko's nested set: <<
>
>Thye are both traversal algorithms, mine is a pre-order traversal, and
>this is an enorder tarversal with a diferent numbering algorithm.
>
>>> I think best would be a combination of both: left, right, level <<
>
>I can generate the level number with a subquery that counts the
>superiors of a node -- i.e. the number of rows which contain this
>node:
>
> CREATE VIEW CombinedTree (node, lft, rgt, level)
> AS SELECT node, lft, rgt,
> (SELECT COUNT(*)
> FROM CelkoTree AS C2
> WHERE C1.lft BETWEEN C2.lft AND C2.rgt)
> FROM CelkoTree AS C1;
>
>Having the level lets you find the immediate subordinates by just
>looking for (level+1), while I have to use subqueries with self-joins.
And I can generate the 'right' number, of course. It is a minimum of the next left sequence number on the same level and the next number on parent level. For closer match of the twos, the Celko's model can be adjusted to half open intervals like [2,5) = {2,3,4}. Received on Mon Oct 15 2001 - 18:48:40 CEST