如何在键/值存储之上构建数据库索引?

时间:2021-05-05 22:50:47

I was reading about LevelDB and found out that:

我正在阅读关于LevelDB的内容并发现:

Upcoming versions of the Chrome browser include an implementation of the IndexedDB HTML5 API that is built on top of LevelDB

即将推出的Chrome浏览器版本包括构建在LevelDB之上的IndexedDB HTML5 API的实现

IndexedDB is also a simple key/value store that has the ability to index data.

IndexedDB也是一个简单的键/值存储,能够索引数据。

My question is: how is it possible to build an index on top of a key/value store? I know that an index is a B-Tree and I understand the way that data is indexed in a database. But how can a key/value store like LevelDB be used for creating a database index?

我的问题是:如何在键/值存储之上构建索引?我知道索引是一个B-Tree,我理解数据在数据库中的索引方式。但是如何使用像LevelDB这样的键/值存储来创建数据库索引呢?

2 个解决方案

#1


7  

The vital feature is not that it supports custom comparators but that it supports ordered iteration through keys and thus searches on partial keys. You can emulate fields in keys just using conventions for separating string values. The many scripting layers that sit on top of leveldb use that approach.

重要的特征并不是它支持自定义比较器,而是支持通过键进行有序迭代,从而搜索部分键。您可以使用约定来分隔字符串值来模拟键中的字段。位于leveldb之上的许多脚本层都使用这种方法。

The dictionary view of a Key-Value store is that you can only tell if a key is present or not by exact match. It is not really feasible to use just such a KV store as a basis for a database index.

键值存储的字典视图是,您只能通过完全匹配来判断键是否存在。仅使用这样的KV商店作为数据库索引的基础是不可行的。

As soon as you can iterate through keys starting from a partial match, you have enough to provide the searching and sorting operations for an index.

只要您可以从部分匹配开始迭代键,就足以为索引提供搜索和排序操作。

#2


5  

Just a couple of things, LevelDB supports sorting of data using a custom comparer, from the page you linked to:

只需要做一些事情,LevelDB支持使用自定义比较器对数据进行排序,从您链接到的页面:

According to the project site the key features are:

根据项目现场,主要特点是:

  • Keys and values are arbitrary byte arrays.
  • 键和值是任意字节数组。
  • Data is stored sorted by key.
  • 按键排序存储数据。
  • Callers can provide a custom comparison function to override the sort order.
  • 调用者可以提供自定义比较功能来覆盖排序顺序。
  • ....
  • ....

So LevelDB can contain data this can be sorted/indexed based on 1 sort order.

因此,LevelDB可以包含可以根据1个排序顺序对数据进行排序/索引的数据。

If you needed several indexable fields, you could just add your own B-Tree that works on-top of LevelDB. I would imagine that this is the type of approach that the Chrome browser takes, but I'm just guessing.

如果您需要多个可索引字段,则可以添加自己的B-Tree,它在LevelDB之上工作。我想这是Chrome浏览器采用的那种方法,但我只是在猜测。

You can always look through the Chrome source.

您始终可以浏览Chrome源代码。

#1


7  

The vital feature is not that it supports custom comparators but that it supports ordered iteration through keys and thus searches on partial keys. You can emulate fields in keys just using conventions for separating string values. The many scripting layers that sit on top of leveldb use that approach.

重要的特征并不是它支持自定义比较器,而是支持通过键进行有序迭代,从而搜索部分键。您可以使用约定来分隔字符串值来模拟键中的字段。位于leveldb之上的许多脚本层都使用这种方法。

The dictionary view of a Key-Value store is that you can only tell if a key is present or not by exact match. It is not really feasible to use just such a KV store as a basis for a database index.

键值存储的字典视图是,您只能通过完全匹配来判断键是否存在。仅使用这样的KV商店作为数据库索引的基础是不可行的。

As soon as you can iterate through keys starting from a partial match, you have enough to provide the searching and sorting operations for an index.

只要您可以从部分匹配开始迭代键,就足以为索引提供搜索和排序操作。

#2


5  

Just a couple of things, LevelDB supports sorting of data using a custom comparer, from the page you linked to:

只需要做一些事情,LevelDB支持使用自定义比较器对数据进行排序,从您链接到的页面:

According to the project site the key features are:

根据项目现场,主要特点是:

  • Keys and values are arbitrary byte arrays.
  • 键和值是任意字节数组。
  • Data is stored sorted by key.
  • 按键排序存储数据。
  • Callers can provide a custom comparison function to override the sort order.
  • 调用者可以提供自定义比较功能来覆盖排序顺序。
  • ....
  • ....

So LevelDB can contain data this can be sorted/indexed based on 1 sort order.

因此,LevelDB可以包含可以根据1个排序顺序对数据进行排序/索引的数据。

If you needed several indexable fields, you could just add your own B-Tree that works on-top of LevelDB. I would imagine that this is the type of approach that the Chrome browser takes, but I'm just guessing.

如果您需要多个可索引字段,则可以添加自己的B-Tree,它在LevelDB之上工作。我想这是Chrome浏览器采用的那种方法,但我只是在猜测。

You can always look through the Chrome source.

您始终可以浏览Chrome源代码。