couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <>
Subject Re: sort by reduce value
Date Mon, 10 Aug 2009 20:56:49 GMT
On Mon, Aug 10, 2009 at 12:58 PM, Brian Candler<> wrote:
> On Tue, Aug 11, 2009 at 12:05:28AM +0530, Anand Chitipothu wrote:
>> I'm trying to think of couchdb equivalent of the following SQL query.
>> SELECT author, count(*)  as count FROM changes GROUP BY author ORDER BY count
> Being cheeky, I will point out that you can probably implement this in a
> _list view. But this is probably less efficient than just downloading the
> result set to the client and sorting it there.
> I'm assuming you know that you can get each author's count using a reduce
> view, and then query that with group=true, so you'll already have calculated
> authors and counts. It's just the final sort by count which remains to be
> done client-side.

The reason why CouchDB can't do the sorting by value inside itself is
that on a multi node cluster, an individual couch can't know the
global ordering. We have a commitment to ensuring that CouchDB's API
remains invariant regardless of the size of the underlying cluster.

So you basically have to copy the cluster-wide reduce values to an
intermediate storage mechanism (which itself can be a cluster) before
you can sort them by value.


> Regards,
> Brian.

Chris Anderson

View raw message