有人使用过 SQl Server 2008 HierarchialID 类型来存储谱系数据

发布于 2024-07-14 00:01:14 字数 430 浏览 11 评论 0原文

我有一个家谱数据库(实际上是关于羊的),饲养员用它来研究遗传信息。 在每条记录中我存储父亲和母亲。 在一个单独的表中,我存储完整的“汇总”信息,以便我可以快速说出任何动物的完整家谱,而无需递归整个数据库...

最近发现 SQL Server 2008 中内置的 HierarchyID 类型,表面上听起来有希望,但我想知道是否有人已经使用它足够多来知道它是否适合我的应用程序类型(即两个父母,多个孩子)? 到目前为止,我发现/阅读的所有示例都涉及经理/员工类型的关系,其中给定的老板可以有多个员工,而每个员工可以有一个老板。

我的应用程序的需求相似,但不完全相同。

我相信无论如何我都会深入研究这项新技术,但如果有人已经知道它的设计方式不适合我使用它,那么我的研究就会很顺利。

我也很好奇人们使用这种新数据类型与执行相同操作的其他方法相比会看到什么样的性能。

I have a genealogical database (about sheep actually), that is used by breeders to research genetic information. In each record I store fatherid and motherid. In a seperate table I store complete 'roll up' information so that I can quickly tell the complete family tree of any animal without recursing thru the entire database...

Recently discovered the hierarchicalID type built into SQL server 2008, on the surface it sounds promising, but I and am wondering if anyone has used it enough to know whether or not it would be appropriate in my type of app(i.e. two parents, multiple kids)? All the samples I have found/read so far deal with manager/employee type relationships where a given boss can have multiple employees, and each employee can have a single boss.

The needs of my app are similar, but not quite the same.

I am sure I will dig into this new technology anyway, but it would be nice to shortcut my research if someone already knew that it was not designed in such a fashion that it would allow me to make use of it.

I am also curious what kind of performance people are seeing using this new data type versus other methods that do the same thing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野稚 2024-07-21 00:01:14

假设每只羊都有一个父本和一个母本,并且没有一只羊可以成为自己的父本(导致羊时间悖论),那么使用两个 HierarchyID 怎么样?

CREATE TABLE dbo.Sheep(
    MotherHID hierarchyid NOT NULL,
    FatherHID hierarchyid NOT NULL,
    Name int NOT NULL
)
GO
ALTER TABLE dbo.Sheep 
ADD CONSTRAINT PK_Sheep PRIMARY KEY CLUSTERED (
    MotherHID,
    FatherHID
)
GO

通过让它们成为联合 PK,你可以将每只羊独特地识别为其母系等级制度和父系等级制度的产物。

这里可能潜伏着一些固有的问题,因此请谨慎地使用几个简单的原型 - 但最初它似乎对您有用。

Assuming each sheep has one male parent and one female parent, and that no sheep can be its own parent (leading to an Ovine Temporal Paradox), then what about using two HierarchyIDs?

CREATE TABLE dbo.Sheep(
    MotherHID hierarchyid NOT NULL,
    FatherHID hierarchyid NOT NULL,
    Name int NOT NULL
)
GO
ALTER TABLE dbo.Sheep 
ADD CONSTRAINT PK_Sheep PRIMARY KEY CLUSTERED (
    MotherHID,
    FatherHID
)
GO

By making them a joint PK, you'd be uniquely identifying each sheep as the product of its maternal hierarchy and it's paternal hierarchy.

There may be some inherent problem lurking here, so proceed cautiously with a couple simple prototypes - but initially it seems like it would work for you.

別甾虛僞 2024-07-21 00:01:14

我看不出它是如何运作的; 在常规层次结构中,有一条到根的链,因此它可以存储每个节点的路径(这就是二进制)。 然而,对于多个父母来说,这是不可能的:即使你分裂了母权制和父权制,你仍然有 1 个母亲、2 个祖母、4 个曾祖母等(甚至没有进入一些更“有趣”的扫描仪)可能的,尤其是牲畜)。 没有单一的逻辑路径进行编码,所以不:我认为这不适用于您的情况。

不过,我很高兴得到纠正。

I can't see how it would work; in a regular hierarchy, there is a single chain to the root, so it can store the path (which is what the binary is) to each node. However, with multiple parents, this isn't possible: even if you split matriarchy and partiarchy, you still have 1 mother, 2 grandmothers, 4 great-grand-mothers, etc (not even getting into some of the more "interesting" scanerios possible, especially with livestock). There is no single logical path to encode, so no: I don't think that this can work in your case.

I'm happy to be corrected, though.

定格我的天空 2024-07-21 00:01:14

使用两个单独的 HierarchyID 来指示父亲和母亲效果很好。

但是,您绝对不想将它们用作行的唯一指示符,因为这是 2 对多的情况。 (两只羊可以有多个孩子。)

我不认为使用 HierarchyId 作为祖先有任何本质上的错误——至少对于羊来说是这样。 对于人来说,关系比“这个人生那个人”要复杂得多,所以显然这种用途仅限于繁殖。

Using two separate HierarchyID to indicate father and mother would work well.

However, you definitely would NOT want to use those as a unique indicator of the row, since it's a 2-to-many situation. (Two sheep can have multiple children.)

I don't see anything inherently wrong with using HierarchyId for ancestry--for Sheep at least. For people, the relationships are much more complicated than "this person begat that person", so obviously the use would be limited to breeding.

凑诗 2024-07-21 00:01:14

对于许多谱系分析问题,SQL Server HierarchyID 并不是一个可靠的解决方案。 它基于 ORDPATH,我在谱系学中使用过它一段时间; 但是谱系中有太多场景无法使用有向无环图的 ORDPATH 方法轻松解决。 图形数据库更加强大并且非常适合谱系学。 我使用 Neo4j: http://stumpf.org/genealogy-blog/graph-谱系数据库

SQL Server hierarchyID is not a robust solution for many genealogy analytic questions. It is based on ORDPATH and I've used it for awhile in genealogy; but there are too many scenarios in genealogy that cannot be readily addressed with ORDPATH methods for directed acyclic graphs. A graph database is much more robust and well suited for genealogy. I use Neo4j: http://stumpf.org/genealogy-blog/graph-databases-in-genealogy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文