0

之前问过一个类似的问题,但没有人回答,所以我重新考虑了这个问题,并提出了一个类似/不同的问题。

我有一个以父/根(顶部)应用程序开头的过程。然后根应用程序生成子应用程序,这些子应用程序也可以生成后代应用程序。这可以持续多个级别。然后每个级别可以是一个节点,也可以是一个叶子。一个节点可以有后代。叶子没有生成的子/后代应用程序。

在流程开始时,应用程序知道级别数。该过程也是结构化的,因此每个子应用程序都能够在完成时使用自己的 ID 和 parentID 更新 tbl。

因此,当整个流程运行时,生成的数据是一个层次树。

我试图弄清楚如何能够查看树中的给定项目/节点,并确定后代应用程序是否完整。

我正在尝试在 mysql 中完成此操作。我对存储过程/子选择不太熟悉。我看过许多讨论这个问题的在线论文/网站,但我似乎没有针对我的问题提出任何问题。

寻找 mysql 大师来帮助我弄清楚这个问题。

谢谢!

---------------------------------

The sample tree would look like:

spawn
3 levels
a - 3 copies of b
b - 3 copies of c


                     a(1)
                      |
---------------------------------------------------------------------
          |b(1)                   |b(2)                            |b(3)
-------------------         -------------------          --------------------  
|c(1)    |c(2)    |c(3)     c(1)    |c(2)   |c(3)        |c(1)    |c(2)    |c(3)  


so we have a total of 12 crawls/fetches

the levels
a
b
c

the (parent/child) levelRelationships
"",a
a,b
b,c

start level
a (parent/top)
end level
c (leaf)


operational process:

an app spawns either no child app, a single child app, or multiple child app(s)
an app that spawns children is a node
an app that spawns no children is a leaf
 there is no guarantee that an app at a given level, will stop operation 
 before an app at a lower level started by it's parent
each child app can set a tbl with a status when it completes 
 when each child app is complete, it generates a "level/complete" status
  which is stored in a levelStatusTBL

at the start of the root/top level process:
-the tree can have multiple/unknown levels
-each child app can spawn an unknown number of children


issue...
 how to algorithmically determine when all the descendants of a root/top level function have completed?
 how to algorithmically determine when all the descendants of a node have completed

我正在考虑的示例 tbls 是:

CREATE TABLE `crawlNodeChildrenCountTBL` (
  `rootID` varchar(100) NOT NULL DEFAULT '',
  `uCrawlID` varchar(100) NOT NULL DEFAULT '',
  `childCount` int(5) NOT NULL DEFAULT 0,
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `EdgeNodeCheckTBL` (
  `CollegeID` varchar(100) NOT NULL DEFAULT '',
  `rootID` varchar(100) NOT NULL DEFAULT '',
  `parentLevel` varchar(100) NOT NULL DEFAULT '',
  `Level` varchar(100) NOT NULL DEFAULT '',
  `nodeType` int(5) NOT NULL DEFAULT 0,     
  `masterParseInputUUID` varchar(100) NOT NULL DEFAULT '',
  `parentSetupPreComboID` varchar(100) NOT NULL DEFAULT '',
  `SetupPreComboChildStatusID` varchar(100) NOT NULL DEFAULT '',
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  UNIQUE KEY `ID` (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


EdgeNodeCheckTBL.SetupPreComboChildStatusID is the baseID
EdgeNodeCheckTBL.parentSetupPreComboID is the parentID of SetupPreComboChildStatusID

this is used to implement the standard child/parent relationship tbl 
4

1 回答 1

0

这确实是一个数据算法问题。基本问题是,将父 ID 存储在关系数据库的子记录中将需要递归查询。如果您可以在存储过程或其他语言中这样做,那么这是一种有效的方法。

在关系数据库中存储树的更好方法是使用嵌套集模型。这个想法是每个节点都有一个左 ID 和一个右 ID,这只是使用前序遍历访问每个节点时的一个序列。Left Id 在远离顶部节点的树下设置;Right Id 在向树的顶部节点上升时设置。您还必须在修改树时更新数字。

这种结构给你的好处是你不需要递归查询来检查或更新树。它还鼓励您将对树的修改隔离到一个位置,以便您可以正确更新左右 Id。

维基百科文章有更多细节。

于 2012-01-20T05:10:49.077 回答