How to convert an existing relational database to a key-value store?

巧了我就是萌 提交于 2019-12-20 02:38:54

问题


I am trying to map a existing relational database to a key value store. Couple of example tables are represented below.

For an instance the above "Employee Details" table can be represented as follows in Redis (or any similiar key-value store)

set emp_details.first_name.01 "John"
set emp_details.last_name.01 "Newman"
set emp_details.address.01 "New York"

set emp_details.first_name.02 "Michael"
set emp_details.last_name.02 "Clarke"
set emp_details.address.02 "Melbourne"

set emp_details.first_name.03 "Steve"
set emp_details.last_name.03 "Smith"
set emp_details.address.03 "Los Angeles"

The "Payments" table also can be represented as above. But this method does not build the one-to-many relationship between the "Employee Details" table and the "Payments" table. Therefore, is there any better way of implementing a key-value store from an existing RDBMS. You can refer to these two tables and suggest a better key schema to store values. Thanks in advance.


回答1:


Nosql databases are basically aggregate stores. Relationships and its associated values are stored in a 'value' part of key - val design.

Avoiding joins helps in better performance.

Excellent llink on nosql modeling - https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/




回答2:


Relational tables represent business/application relationships/associations. FKs (foreign keys) get called relationships but aren't. (They're just truths about every business/application situation & corresponding database state.) A FK constraint declaration just tells the RDBMS to enforce that subrows appear elsewhere as a superkey (unique key). (Although the DBMS can use it to optimize.) Constraints are not needed to query relationally.

FKs are relational. In a non-relational DBMS if you want to make certain queries simpler or faster, eg when they are the equivalents of certain relational joins involving certain FKs, at the expense of complicating updates & other queries, then you do things like record data redundantly, or in a nested/hierarchical way, or using pointers/indirection.

This difference in relational vs non-relational schemas & querying is fundamental to the difference in data models & to the benefits of the relational model. Using relational tables as data structure allows straightforward application-neutral querying with with certain implementation computational complexity & optimization opportunities. Any intro to a particular NoSQL DBMS will explain how to model & query. (Typically assuming an initial relational design.)



来源:https://stackoverflow.com/questions/45294578/how-to-convert-an-existing-relational-database-to-a-key-value-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!