incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Davis" <paul.joseph.da...@gmail.com>
Subject Re: how do I get the total number of rows returned for a given key?
Date Mon, 25 Aug 2008 15:58:16 GMT
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 <patcito@gmail.com> 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
>

Mime
View raw message