这是 "SQL Anti-Patterns" 书中的错字吗?
Is this a typo in the "SQL Anti-Patterns" book?
相关栏目:
Nested Sets.
The Nested Sets solution stores information with each node that
pertains to the set of its descendants, rather than the node's
immediate parent. This information can be represented by encoding each
node in the tree with two numbers, which you can call nsleft
and
nsright
.
CREATE TABLE Comments (
comment_id SERIAL PRIMARY KEY,
nsleft INTEGER NOT NULL,
nsright INTEGER NOT NULL,
bug_id BIGINT UNSIGNED NOT NULL,
author BIGINT UNISGNED NOT NULL,
comment_date DATETIME NOT NULL,
comment TEXT NOT NULL,
FOREIGN KEY (bug_id) REFERENCES Bugs (bud_id),
FOREIGN KEY (author) REFERENCES Accounts(account_id)
);
Each node is given nsleft
and nsright
numbers in the following way:
the nsleft
number is less than the numbers of all the node's
children, whereas the right number is greater than the numbers of all
the node's children. These numbers have no relation to the
comment_id
values.
(SQL 反模式的第 32 页)
不是应该说
the nsleft
number is less than the numbers of all the node's
descendants, whereas the right number is greater than the numbers of
all the node's descendants.
还是我对这个概念的理解有问题?
我认为这不是打字错误,但你也说得对,它适用于后代,所以你了解情况——你只是没有完全考虑清楚。
假设树有 3 层。对于最低叶级别的每个节点,没有 children。在中间级别,每个节点都有一个 nsleft
小于其任何 children (叶节点)中最小的 nsleft
和一个 nsright
大于最大的 [=其任何 children 的 12=]。类似地,在顶层,单个根节点有一个 nsleft
小于其任何直接 children 中最小的 nsleft
,并且有一个 nsright
大于最大的 nsright
的任何直接 children。但是,通过归纳,这意味着根节点的 nsleft
节点小于其任何后代中最小的 nsleft
,并且其 nsright
节点大于最大的 nsright
它的任何后代。
所以,这个说法是准确的,但是你的推论也是正确的。
相关栏目:
Nested Sets.
The Nested Sets solution stores information with each node that pertains to the set of its descendants, rather than the node's immediate parent. This information can be represented by encoding each node in the tree with two numbers, which you can call
nsleft
andnsright
.CREATE TABLE Comments ( comment_id SERIAL PRIMARY KEY, nsleft INTEGER NOT NULL, nsright INTEGER NOT NULL, bug_id BIGINT UNSIGNED NOT NULL, author BIGINT UNISGNED NOT NULL, comment_date DATETIME NOT NULL, comment TEXT NOT NULL, FOREIGN KEY (bug_id) REFERENCES Bugs (bud_id), FOREIGN KEY (author) REFERENCES Accounts(account_id) );
Each node is given
nsleft
andnsright
numbers in the following way: thensleft
number is less than the numbers of all the node's children, whereas the right number is greater than the numbers of all the node's children. These numbers have no relation to thecomment_id
values.
(SQL 反模式的第 32 页)
不是应该说
the
nsleft
number is less than the numbers of all the node's descendants, whereas the right number is greater than the numbers of all the node's descendants.
还是我对这个概念的理解有问题?
我认为这不是打字错误,但你也说得对,它适用于后代,所以你了解情况——你只是没有完全考虑清楚。
假设树有 3 层。对于最低叶级别的每个节点,没有 children。在中间级别,每个节点都有一个 nsleft
小于其任何 children (叶节点)中最小的 nsleft
和一个 nsright
大于最大的 [=其任何 children 的 12=]。类似地,在顶层,单个根节点有一个 nsleft
小于其任何直接 children 中最小的 nsleft
,并且有一个 nsright
大于最大的 nsright
的任何直接 children。但是,通过归纳,这意味着根节点的 nsleft
节点小于其任何后代中最小的 nsleft
,并且其 nsright
节点大于最大的 nsright
它的任何后代。
所以,这个说法是准确的,但是你的推论也是正确的。