Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 78721 invoked from network); 25 Aug 2008 15:59:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Aug 2008 15:59:04 -0000 Received: (qmail 65601 invoked by uid 500); 25 Aug 2008 15:59:02 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 65570 invoked by uid 500); 25 Aug 2008 15:59:01 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 65559 invoked by uid 99); 25 Aug 2008 15:59:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Aug 2008 08:59:01 -0700 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 paul.joseph.davis@gmail.com designates 209.85.132.250 as permitted sender) Received: from [209.85.132.250] (HELO an-out-0708.google.com) (209.85.132.250) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Aug 2008 15:58:04 +0000 Received: by an-out-0708.google.com with SMTP id b38so238030ana.83 for ; Mon, 25 Aug 2008 08:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=15d1B9Txw/iIcYndmPGIS3m5/iZcRx4+SZgTvI7PsMc=; b=RNLZJbkxF3YIUkdO4bZhdUSo68lA0QDXyJWaT8xUhJgrDmfUXJJI8vRr7Org3nIrpo onDbidK4zsbOh1yA9YQ0M0e3rSqeHwCmzB0E1cgQ+QGJmjBxsxHlWaohP90h09zP5Qzy ouZJ64kt3H7TMDqnGD3koOmFm1eIUxDIDRFr0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=JbIVd1H+/ZMp2UoFr/g66wtDS5MiiS49HjQdfxzEzd/5v6wZsgDqJERzYr5MKdZg70 vb82me7f2niArvHFTQPxPXZYfa9fUbf6u25GX45Mh6MvHNvxlf6ujGIi1gMKxH9fK5Zc SFwHZWDyD3JqMB0ooFw3x1FaYFf/fUrCEqzjw= Received: by 10.100.47.13 with SMTP id u13mr4066423anu.56.1219679896342; Mon, 25 Aug 2008 08:58:16 -0700 (PDT) Received: by 10.100.154.5 with HTTP; Mon, 25 Aug 2008 08:58:16 -0700 (PDT) Message-ID: Date: Mon, 25 Aug 2008 11:58:16 -0400 From: "Paul Davis" To: couchdb-user@incubator.apache.org Subject: Re: how do I get the total number of rows returned for a given key? In-Reply-To: <6b6419750808242159u6eb16499h7a55d66cd3d0cde7@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6b6419750808242159u6eb16499h7a55d66cd3d0cde7@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org Patrick, The total_rows can be a bit misleading. As you've noticed its just the total number of rows in the entire view. The main case for this behavior is that its quick. To report the rows we can just read the view file for an attribute. Calculating the number of rows for a specific key would require one of two things, either we scan the view as we would for docs to be returned, or we create some method that would count the number of times a key exists as docs are added/updated/deleted from the view. The thing is, keys are complex. There's no way couch could keep track of all the different possible start/end key combinations for arbitrary key structures. Which leaves us with scanning the view. This is fairly inefficient in terms of implementation. Which leaves us at, just report total rows in the view. Now that upside is that you can create your own methods that will track the count of a given key combination using reduce. And the awesome part is that you can do it however you want with as many combinations as you want. So while it may look like a pain to get the counts for a specific subset of a view, it really is one of the better solutions. HTH, Paul On Mon, Aug 25, 2008 at 12:59 AM, Patrick Aljord wrote: > Hey all, > > I'm trying to get the number of docs returned by my view given a > certain key such as: > > myview?key=foo&count=0 > > I thought total_rows would give the numbers of docs that have this > specific key but instead it gave me the total rows for all keys. I was > told by "jeffd" on IRC this is the normal behavior but, I quote: > > "there was talk in this channel at some point of adding another piece, > but I dunno how far that went". > > So my question is: are you going to add another piece like total_rows > but that would return the number of rows for a given key? Or is there > a better way to do so? (with reduce I guess, but still it would be > nice to have it included). This is really needed for pagination. > I spotted an issue for that https://issues.apache.org/jira/browse/COUCHDB-82 > > > Thanks in advance, > > Pat >