本文共 5163 字,大约阅读时间需要 17 分钟。
数据库 外键 优缺点
by Hieu Nguyen (Jack)
由Hieu Nguyen(Jack)
Working on (a client database for React Native) has given me an opportunity to try and test different data formats which include key-value, column-oriented, document, and tuples. Each format was designed to suit different scenarios.
在 (React Native的客户端数据库)上工作使我有机会尝试和测试不同的数据格式,包括键值,面向列,文档和元组。 每种格式都设计为适合不同的情况。
The criteria of these tests focus on performance, the ability to lookup values, and space efficiency. Besides, it is not required to have on-disk sorted keys and indices. They will be loaded into memory for fast lookup.
这些测试的标准集中在性能,查找值的能力和空间效率上。 此外,不需要在磁盘上有排序的键和索引。 它们将被加载到内存中以进行快速查找。
In this post, I will recap the pros and cons of the two common formats: key-values and tuples format. Also, I’ll introduce tagged key-values, an extension of key-values with index lookup, which benefits from the tuples format.
在本文中,我将概述两种常见格式的优缺点: 键值和元组格式。 另外,我将介绍带标签的键值 ,它是具有索引查找功能的键值的扩展,该功能得益于元组格式。
Key-values store a collection of key-and-value pairs, where sometimes the value represents more than one value, separated by delimiters (i.e. a comma). Those pairs are organized into blocks with fixed-length (for fast traverse between records).
键值存储键和值对的集合,其中有时该值表示多个值,并用定界符(即逗号)分隔。 这些对被组织成具有固定长度的块(用于记录之间的快速遍历)。
Advantages of the key-value store:
键值存储的优点:
Disadvantages:
缺点:
The tuples data format has existed for many decades. It is used in relational databases such as MySQL, Postgres, etc.
元组数据格式已经存在了数十年。 它用于关系数据库,例如MySQL,Postgres等。
Unlike the key-values format, it relies on the predefined schema to organize records into rows, and its values in fixed-length columns. Each value only/usually represents a single piece of information.
与键值格式不同,它依赖于预定义的架构将记录组织成行,并将其值组织成固定长度的列。 每个值仅/通常代表一条信息。
Advantages of tuples data store:
元组数据存储的优点:
Disadvantages:
缺点:
Tagged Key-Value is an extended version of Key-Value storage — it has more than one key for a single value. In other words, it has a key, indexes (or tags) and a body value for each record. Where:
标记的键值是键值存储的扩展版本-单个值具有多个键。 换句话说,它具有每个记录的键,索引(或标签)和主体值。 哪里:
Key and Indexes will be loaded into memory on startup
键和索引将在启动时加载到内存中
Body value can be anything from a plain string, BSON/JSON, or comma-separated value.
主体值可以是纯字符串,BSON / JSON或逗号分隔值之间的任何值。
Advantages of Tagged Key-Value store:
标记键值存储的优点:
A record body can be anything, ideal for flexible schemas
记录主体可以是任何东西,非常适合灵活的模式
Disadvantages:
缺点:
Change of schema that includes indices might need data migration
更改包含索引的架构可能需要数据迁移
Vasern is a client database for React Native. The latest version was released under beta for testing and was using key-value storage.
Vasern是React Native的客户端数据库。 最新版本已在Beta下发布以进行测试,并且正在使用键值存储。
In the upcoming , Vasern is switching to a tagged key-value store layout. Focus is on its powerful lookup feature and space efficiency.
在即将发布的 , Vasern将切换到标记的键值存储布局。 重点在于其强大的查找功能和空间效率。
Below is a demo query. It’s beautiful, isn’t it?
下面是一个演示查询。 很漂亮,不是吗?
There are many databases with different data formats to choose for an application. Two common formats are:
有许多具有不同数据格式的数据库可供选择。 两种常见格式是:
Key-Value pairs — fast read and write but not optimized for lookup. It’s often used as simple data storage, NoSQL.
键值对 -快速读写,但未针对查找进行优化。 它通常用作NoSQL的简单数据存储。
Tuples — support multi typed-values, indexes, optimized for lookup, but a lack of schema flexibility. Commonly used for Relational Databases.
元组 -支持多种类型的值,索引,已针对查找进行了优化,但缺乏模式灵活性。 常用于关系数据库。
By combining the strengths mentioned above, the Tagged-Key-Values format is flexible with data schema, and is able to look up records through keys and indices. This is often better suited for a client’s database.
通过结合上述优点, Tagged-Key-Values格式可以灵活地用于数据模式,并且能够通过键和索引查找记录。 这通常更适合客户端的数据库。
If you found this article useful, please click on the ? button a few times to make others find the article and show your support! ?
如果您发现本文有用,请单击“ ?”。 几次单击以使其他人找到该文章并表示支持! ?
Thanks for reading!
谢谢阅读!
翻译自:
数据库 外键 优缺点
转载地址:http://lbewd.baihongyu.com/