Monday, January 16

Geek

CouchDB, Riak, And Whatever-The-Hell-You-Want Indexes

One of the things I like most about CouchDB is its index definition mechanism: Javascript.*  For each index you want to attach to a database, you write a short Javascript function that assembles the key (or keys) from the fields in the record.  CouchDB then manages the underlying B-Tree based on those key values.

This means that if you want to index an array, or a user-defined data structure, or build a partial index, or a full-text index, or anything that can be implemented on top of a B-Tree, you can do it.  Write the code once and CouchDB will ensure that it's applied consistently.  Far more powerful than standard SQL indexes, and much cleaner and more efficient than using secondary tables, joins, and stored procedures, which are the canonical way to tackle this problem with SQL.

As of version 1.0, Riak supports indexes as well as the basic key/value access and link walking.  The way Riak handles things is slightly different to CouchDB.

In CouchDB, each record is a JSON document.  Since that's predefined, CouchDB can allow you to inspect the contents of the records and manipulate them using an embedded Javascript interpreter.

In Riak, records are arbitrary binary-safe blobs; you can store anything you want without having to encode it in any special way.  To index your records, you provide the index names and values along with the record.

Just like CouchDB, this allows you to build indexes in any way you like.  Riak stores the index values twice, once in the index structure and once as metadata alongside the record, so that it can maintain index consistency on updates and deletes without you having to worry about it.

You can have as many indexes as you like (the developers note that they've tested it with 1000 indexes), and like CouchDB, you can do anything you can do with a B-Tree (or rather, with an arbitrary number of B-Trees).

It's a very powerful feature.

* Lua would be better, of course.

Posted by: Pixy Misa at 01:35 AM | Comments (2) | Add Comment | Trackbacks (Suck)
Post contains 338 words, total size 2 kb.

1  Looks like Brickmuppet just got heavily spammed again.

Posted by: Steven Den Beste at Tuesday, January 17 2012 02:17 AM (+rSRq)

2 I did see your comment, but by the time I got there it seemed he'd already cleared it out.  I've been really tied up the last couple of weeks, but things are quieting down now, freeing me up to STOMP ON SPAMMERS.

Posted by: Pixy Misa at Wednesday, January 18 2012 09:53 PM (PiXy!)

Hide Comments | Add Comment

Comments are disabled. Post is locked.
47kb generated in CPU 0.0135, elapsed 0.2133 seconds.
56 queries taking 0.205 seconds, 328 records returned.
Powered by Minx 1.1.6c-pink.