One thing that might not be clear, from some of the examples, is that you don't have to explicitly handle the rereduce == true case when the shape of the data emitted from the map is the same as that returned by the reduce. This is the case when using reduce to return the sum of an array of numeric values, for instance. —Zach
On Sun, Jun 21, 2009 at 3:21 PM, Brian Candler<[email protected]> wrote: > On Mon, Jun 15, 2009 at 02:28:17PM +0800, hhsuper wrote: >> Hi, guys, I need some help, i want to know when we should implement the >> rereduce in reduce function? > > Answer: always. > > Once you get above a handful of documents you will see re-reduces taking > place. This is because reduce is done in multiple steps: > > doc \ > doc -> reduce - > doc / \ > doc \ \ > doc -> reduce ---rereduce --> answer > doc / / > doc \ / > doc -> reduce - > doc / > > Also: each btree node contains a bunch of documents, and the btree node also > contains a cached reduce value for that set of docs. This makes it much > cheaper for couchdb to calculate the reduce value across a range of keys; it > can use already-reduced values where available, and combine them using > rereduce. > > There's more info linked from the Wiki. > > Regards, > > Brian. >
