incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Copenhaver <sean.copenha...@gmail.com>
Subject Re: Complex queries & results
Date Tue, 07 Jun 2011 11:22:50 GMT
Yeah I'm afraid I can not attest to when a reduce function is unsafe.

I would image you have to be careful because the reduce values for each page
of the b-tree get stored in the view. So you wouldn't want a reduce value
that is getting out of hand. A reduce function that has side effects could
lead to hard to understand results since the whole range of values isn't
computed on each query. Also a reduce function that took a long time to
compute could slow down updating an index. There may be other
considerations.

I wouldn't think that the reduce function I gave you in the example is
unsafe mainly because it's a very simple aggregation dictionary, names to
integers. But it is an unbounded result which is never good. However many
unique 'a_name' values you have is the size of the result. It might cause
problems if you have a millions of unique 'a_name' values but probably not
when you have tens of thousands of unique values. So the order of magnitude
here is important I think, but only testing will uncover that.

On Tue, Jun 7, 2011 at 2:50 AM, Marcello Nuccio
<marcello.nuccio@gmail.com>wrote:

> 2011/6/7 Torstein Krause Johansen <torsteinkrausework@gmail.com>:
> > I'm still puzzled, though. When reading up on reduces, I got put off
> doing
> > anything fancy in the reduce function as the guide on
> > http://guide.couchdb.org/draft/views.html#example/3 states:
> >
> > "A common mistake new CouchDB users make is attempting to construct
> complex
> > aggregate values with a reduce function. Full reductions should result in
> a
> > scalar value, like 5, and not, for instance, a JSON hash with a set of
> > unique keys and the count of each."
> >
> > And from my understanding, this is exactly what I want to do here, but
> > perhaps I'm misunderstanding the author's meaning here?
>
> In my experience it is not a problem for a reduce function to return an
> hash.
>
> The strict requirement for reduce functions, is to actually reduce the
> data it get passed to a small constant size value, be it a scalar or
> an object.
>
> You can look at this example for an idea of what I mean
>
> http://stackoverflow.com/questions/5637412/getting-a-list-of-documents-with-a-maximum-field-value-from-couchdb-view/5654154#5654154
>
> I hope to be corrected if I am wrong.
>
> Marcello
>



-- 
“The limits of language are the limits of one's world. “ -Ludwig von
Wittgenstein

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message