以下哪种数据结构更容易被接受,为什么?

发布于 2025-01-04 09:18:10 字数 1432 浏览 1 评论 0原文

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

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

发布评论

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

评论(1

把昨日还给我 2025-01-11 09:18:10

第二个。第一个是 EAV 反模式的实现。

要了解为什么第一个表是一个问题,请假设我们对问题域一无所知。我们只知道目前有两种不同类型的浮点值,分别标记为 GDP 和 GNP,并且我们想添加第三种浮点值 PWT,已知 PWT 的值限制在

  • 0.0 < 0.0 范围内。 PWT <= 1500.0

将该数据添加到第一个表中很简单。将约束添加到第一个表中,即 PWT 必须在 0 到 1500 之间,这是一个不同的故事。

向第二个表添加列也很简单。添加检查约束来保证值在正确的范围内既简单又容易。

想象一下,我们现在想要添加第四种价值,一种仅限于美元金额 > 的价值。 0. 您将如何管理第一个表中的定点值?但是在第二个表中添加该列及其约束非常简单。

The second. The first is an implementation of the EAV anti-pattern.

To see why the first table is a problem, imagine that we don't know anything about the problem domain. We just know that there are currently two different kinds of floating-point values, labeled GDP and GNP, and that we want to add a third, PWT, and the values of PWT are known to be limited to the range

  • 0.0 < PWT <= 1500.0

Adding that data to the first table is simple. Adding that constraint to the first table, that PWT must be between 0 and 1500, is a different story.

Adding a column to the second table is also simple. And adding a check constraint to guarantee the values are in the right range is both simple and easy.

Imagine that we now want to add a fourth kind of value, one that's limited to dollar amounts > 0. How will you manage a fixed-point value in the first table? But adding that column and its constraint are dead simple in the second table.

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