Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it possible to build database index on top of key/value store?

I was reading about LevelDB and found out that:

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

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

My question is: how is it possible to build an index on top of a key/value store? I know that an index is at it's lowest level is n-ary 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?

like image 309
Lu4 Avatar asked Jan 28 '12 17:01

Lu4


People also ask

Can SQL be layered on top of a key-value store API?

The Key-Value + SQL Architecture. We developed the architecture to support multiple layers on top of the Key-Value Store. Each of these layers can provide a different data model, such as SQL, Document, or Graph against the same FoundationDB back end.

How do databases store indexes?

Indexes are created using a few database columns. The first column is the Search key that contains a copy of the primary key or candidate key of the table. These values are stored in sorted order so that the corresponding data can be accessed quickly. Note: The data may or may not be stored in sorted order.

Does a key-value store support secondary indexes?

A Key-value store does not support Secondary Indexes.

What is an index key database?

An index contains keys built from one or more columns in the table or view. These keys are stored in a structure (B-tree) that enables SQL Server to find the row or rows associated with the key values quickly and efficiently. SQL Server documentation uses the term B-tree generally in reference to indexes.


2 Answers

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.

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.

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.

like image 125
Andy Dent Avatar answered Oct 24 '22 12:10

Andy Dent


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

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.

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.

You can always look through the Chrome source.

like image 25
Matt Warren Avatar answered Oct 24 '22 13:10

Matt Warren