Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to simulate a database table with an index in a key value store?

What is the easiest way to simulate a database table with an index in a key value store? The key value store has NO ranged queries and NO ordered keys.

The things I want to simulate (in order of priority):

  1. Create tables
  2. Add columns
  3. Create indexes
  4. Query based on primary key
  5. Query based on arbitrary columns
like image 715
yazz.com Avatar asked Feb 16 '10 13:02

yazz.com


People also ask

Which database can be used to store data with key-value pair format?

Amazon DynamoDB: Probably the most widely used key-value store database, in fact, it was the research into DynamoDB that really started making NoSQL really popular.

What is a key-value store database?

A key-value database is a type of nonrelational database that uses a simple key-value method to store data. A key-value database stores data as a collection of key-value pairs in which a key serves as a unique identifier. Both keys and values can be anything, ranging from simple objects to complex compound objects.

What is key and index in database?

A key identifies the row stored in the database. An index is a structure like the one at the one at the end of a book. At the end of a book you see several pages with words and where you can find those words. Those pages are an index and the same is the case for a database. The index contains key and their locations.

How do I add an index to an existing table?

ALTER command to add and drop INDEXALTER TABLE tbl_name ADD INDEX index_name (column_list) − This adds an ordinary index in which any value may appear more than once. ALTER TABLE tbl_name ADD FULLTEXT index_name (column_list) − This creates a special FULLTEXT index that is used for text-searching purposes.


1 Answers

If you use Redis (an advanced key-value store that supports strings, lists, sets, etc.) Then this is quite easy. I have already developed a C# redis client that has native support for storing POCO's data models. These exact same POCO's can be used by OrmLite to store it in a RDBMS.

By the way Redis is fast, I have a benchmark that stores and retrieves the entire Northwind Database (3202 records) in under 1.2 seconds (running inside a UnitTest on a 3yo iMac).

I store entities in two ways

  • Distinct entities, where I combine the Class type name and Primary Key to create a unique key e.g. urn:user:1
    • I then maintain a separate set of primary keys (in a Redis Set) to keep track of all my entities, using a key like: ids:user
  • In a Redis server side list - which acts very much like a table with support for paging, using a key like: lists:user
like image 190
mythz Avatar answered Sep 28 '22 07:09

mythz