Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 87548 invoked from network); 10 Aug 2009 20:57:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Aug 2009 20:57:14 -0000 Received: (qmail 81949 invoked by uid 500); 10 Aug 2009 20:57:20 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 81867 invoked by uid 500); 10 Aug 2009 20:57:20 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 81857 invoked by uid 99); 10 Aug 2009 20:57:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 20:57:20 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 209.85.212.177 as permitted sender) Received: from [209.85.212.177] (HELO mail-vw0-f177.google.com) (209.85.212.177) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 20:57:10 +0000 Received: by vws7 with SMTP id 7so3024013vws.29 for ; Mon, 10 Aug 2009 13:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=rmoFUCD2JDE75G+N74iFo4WH0NFJufkWPITeK1raarU=; b=ad3LHHBwdB7WUYr2AsUKk1SQRBmor6q+v3u/3O2wbBh/iwSAO15HTTh4UdO1MW6bVe PP9F/PN4fGvSvn7iu1N4OYXTKKzGWfxY0q48s6XoAH6Z/gi6AfWuZZ5fsnF1xf/iWojW FBCRALY9xTJ4EINWILz9QUThJxCX/gq11QvKs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=GxvpKk9ckToIGP5+vlrV+VK9zDjSWwd6JzM8+Lg2Zb7EPCbK+mCxg14O3iA37RDnYU C/4y7lE0FoPkIDocUPOGqmMPzg59pzitMKYm+KR8QCn/5Y4K8zU9M6e6ShqJmzrtLJjk IrYx2nWpyz45aURp1xsAucO0Y1yMA0kQD8QGw= MIME-Version: 1.0 Sender: jchris@gmail.com Received: by 10.220.74.140 with SMTP id u12mr5435049vcj.93.1249937809544; Mon, 10 Aug 2009 13:56:49 -0700 (PDT) In-Reply-To: <20090810195848.GD27797@uk.tiscali.com> References: <41139fcb0908101135r64ead326k539a1b4eb60aed42@mail.gmail.com> <20090810195848.GD27797@uk.tiscali.com> Date: Mon, 10 Aug 2009 13:56:49 -0700 X-Google-Sender-Auth: 6025962390cd2468 Message-ID: Subject: Re: sort by reduce value From: Chris Anderson To: user@couchdb.apache.org Cc: Anand Chitipothu Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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(*) =A0as count FROM changes GROUP BY author ORDER B= Y 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=3Dtrue, so you'll already have calcu= lated > 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. Cheers, Chris > Regards, > > Brian. > --=20 Chris Anderson http://jchrisa.net http://couch.io