更新时间:2023-02-01 22:42:06
SELECT *
FROM mytable
WHERE descendant = @descendant
AND hops <
(
SELECT hops
FROM mytable
WHERE descendant = @descendant
AND ancestor = @ancestor
)
这将自动处理@ancestor
不是真正的@descendant
祖先的情况.
This will automatically take care of cases when @ancestor
is not really a @descendant
's ancestor.
在(descendant, hops)
上创建索引以使其快速运行.
Create an index on (descendant, hops)
for this to work fast.