具有参照完整性(删除级联)的 NoSQL/RDBMS 混合? [英] NoSQL / RDBMS hybrid with referential integrity (delete cascade)?

查看:20
本文介绍了具有参照完整性(删除级联)的 NoSQL/RDBMS 混合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个数据库可以为您提供参照完整性的好处,并且能够使用 SQL 类型语言进行查询,同时还允许根据其数据属性以及它们之间的关系来松散地定义实体?

Is there a database out there that gives you the benefit of referential integrity and being able to use a SQL type language for querying, but also lets entities be loosely defined with respect to their data attributes and also the relationships between them?

例如采用 RBAC 类型模型,其中您拥有权限、用户、用户组和角色.复杂/灵活的模型可能具有以下规则:

E.g. take a RBAC type model where you have Permissions, Users, User Groups & Roles. A complex/flexible model could have the following rules:

  • 角色可以拥有一个或多个权限,并且一个权限可以属于一个或多个角色
  • 用户可以拥有一个或多个权限,一个权限可以属于一个或多个用户
  • 用户组可以拥有一个或多个权限,并且一个权限可以属于一个或多个用户组
  • 用户可以拥有一个或多个角色,一个角色可以属于一个或多个用户
  • 用户组可以有一个或多个角色,一个角色可以属于一个或多个用户组
  • 角色可以有一个或多个角色,一个角色可以属于一个或多个角色

在 RDBMS 中对上述内容进行建模将涉及创建大量交叉表.理想情况下,我想在数据库中定义的只是实体本身(用户、角色等)以及一些强制性属性.其他一切都将是动态的(即不需要 DDL),例如我可以创建一个具有未预定义的新属性的用户.我还可以在尚未预定义的实体之间创建关系,尽管数据库会像普通 RDBMS 一样处理引用完整性.

To model the above in an RDBMS would involve the creation of lots of intersection tables. Ideally, all I'd like to define in the database is the entities themselves (User, Role, etc) plus some mandatory attributes. Everything else would then be dynamic (i.e. no DDL required), e.g. I could create a User with a new attribute which wasn't pre-defined. I could also create a relationship between entities that hasn't been predefined, though the database would handle referential integrity like a normal RDBMS.

通过创建一个表来存储实体和另一个表来存储关系等,在 RDBMS 中可以在一定程度上实现上述目标,但这会使执行简单查询所需的 SQL 过于复杂,并且还可能影响性能.

The above can be achieved to some degree in a RDBMS by creating a table to store entities and another one to store relationships etc, but this overly complicates the SQL needed to perform simple queries and may also have performance implications.

推荐答案

大多数 NoSQL 数据库都可以很好地扩展.这是以一致性为代价的,其中引用完整性是其中的一部分.所以大多数 NoSQL 不支持任何类型的关系约束.

Most NoSQL databases are built to scale very well. This is done at the cost of consistency, of which referential integrity is part of. So most NoSQL don't support any type of relational constraints.

有一种类型的 NoSQL 数据库确实支持关系.事实上,它是专门为关系设计的:图数据库.图数据库存储节点和这些节点之间的显式关系(边).节点和边都可以包含键/值对形式的数据,而无需绑定到预定义的架构.

There's one type of NoSQL database that does support relations. In fact, it's designed especially for relations: the graph database. Graph databases store nodes and explicit relations (edges) between these nodes. Both nodes and edges can contain data in the form of key/value pairs, without being tied to a predefined schema.

图数据库针对关系查询和漂亮的图操作进行了优化,例如查找两个节点之间的最短路径,或查找距当前节点给定距离内的所有节点.在角色/权限场景中您不需要此功能,但如果您需要,使用 RDBMS 将更难实现.

Graph databases are optimized for relational queries and nifty graph operations, such as finding the shortest path between two nodes, or finding all nodes within a given distance from the current node. You wouldn't need this in a role/permission scenario, but if you do, it'll be a lot harder to achieve using an RDBMS.

另一种选择是通过使用 RDBMS 来存储关系并使用文档数据库来存储实际数据,从而使您的整个数据层成为一个混合层.这会使您的应用程序稍微复杂化,但我认为这不是一个糟糕的解决方案.您将使用两种不同的技术,它们都处理它们旨在处理的问题.

Another option is to make your entire data layer a hybrid, by using a RDBMS to store the relations and a document database to store the actual data. This would complicate your application slightly, but I don't think it's such a bad solution. You'll be using two different technologies, both dealing with the problems they were designed to deal with.

这篇关于具有参照完整性(删除级联)的 NoSQL/RDBMS 混合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆