couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject Re: Views
Date Sat, 26 Apr 2008 19:09:57 GMT
On Sat, Apr 26, 2008 at 11:50 AM, Anthony Mills <> wrote:
>  Then, through the magic of couchdb, I'll only get back those documents between the April
3rd and 5th whose attribute number=1234?
>  Will couchdb only search through records that match the key? or will it
> need to go through all documents every time I call the view?
>  To get nerdy, I want my views to find records in O(log n) not O(n).

My understanding is that because CouchDB uses materialized views,
pulling sequential records from a view key is very efficient. The
database tends to put the weight of creating joins on the client. In
your case you'd select all the view rows in that date range using a
single query, filter them by document number in your application code,
and optionally run GETs to retrieve the indexed documents.

You could avoid the filtering step on the client by changing your view
function so the number sorts first:

       if(doc.type == "hello"){
               map([doc.number,], doc);

As long as you only want to select documents with a single doc.number
at a time, this view returns just the data you need, with a query


on the downside, this version of the view becomes really nasty as soon
as you want to fetch all documents from a given time range, across all
values of doc.number. So unless you're going to be querying by
doc.number a lot (or you have a lot of doc numbers, and don't mind
maintaining both views), I'd recommend your view, plus filtering in
the application.

Chris Anderson

View raw message