数据库 外键 优缺点_不同数据格式的优缺点:键值与元组

数据库 外键 优缺点

by Hieu Nguyen (Jack)

由Hieu Nguyen(Jack)

不同数据格式的优缺点:键值与元组 (The pros and cons of different data formats: key-values vs tuples)

如何在后台格式化数据 (How data is formatted under the hood)

Working on Vasern (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.

Vasern (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-Value Store)

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:

键值存储的优点:

  • Simple data format makes write and read operations fast

    简单的数据格式使写和读操作更快
  • Value can be anything, including JSON, flexible schemas

    值可以是任何值,包括JSON,灵活的架构

Disadvantages:

缺点:

  • Optimized only for data with single key and value. A parser is required to store multiple values.

    仅针对具有单个键和值的数据进行了优化。 需要解析器来存储多个值。
  • Not optimized for lookup. Lookup requires scanning the whole collection or creating separate index values

    未针对查找进行优化。 查找需要扫描整个集合或创建单独的索引值

元组数据存储(RDBMS) (Tuples Data Store (RDBMS))

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:

元组数据存储的优点:

  • Structured data format helps traverse through values of records quickly

    结构化数据格式有助于快速遍历记录值
  • Optimized for lookup (common use of SQL for querying records)

    针对查找进行了优化(通常使用SQL查询记录)

Disadvantages:

缺点:

  • Constrained by schema structure

    受架构结构约束
  • Change of schema usually requires rewriting the whole database

    更改架构通常需要重写整个数据库

标记的键值存储 (Tagged Key-Value Store)

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:

标记键值存储的优点:

  • Semi-structured, which helps traverse through records and indexes fast

    半结构化,有助于快速遍历记录和索引
  • Optimized for lookup (through keys and indexes)

    针对查找进行了优化(通过键和索引)
  • A record body can be anything, ideal for flexible schemas

    记录主体可以是任何东西,非常适合灵活的模式

  • Space efficiency (key, indices are organized in tight columns)

    空间效率(键,索引按紧凑的列组织)

Disadvantages:

缺点:

  • Change of schema that includes indices might need data migration

    更改包含索引的架构可能需要数据迁移

带有标记键值存储的Vasern (Vasern with Tagged Key-Value Store)

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 0.3.0-RC version, Vasern is switching to a tagged key-value store layout. Focus is on its powerful lookup feature and space efficiency.

在即将发布的0.3.0-RC版本中 Vasern将切换到标记的键值存储布局。 重点在于其强大的查找功能和空间效率。

Below is a demo query. It’s beautiful, isn’t it?

下面是一个演示查询。 很漂亮,不是吗?

结论 (Conclusion)

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!

谢谢阅读!

翻译自: https://www.freecodecamp.org/news/the-pros-and-cons-of-different-data-formats-key-values-vs-tuples-f526ad3fa964/

数据库 外键 优缺点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值