couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Couchdb Wiki] Update of "Introduction to CouchDB views" by BrianCandler
Date Sat, 31 Jan 2009 21:05:44 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by BrianCandler:

The comment on the change is:
Add some notes about group and group_level

  See HttpViewApi to learn how to work with views. ["View_Snippets"] contain a few examples.
+ == Grouping ==
+ The output of the map function is precomputed and stored on disk in a B-tree. However for
now, the output of the reduce function is calculated 'on demand' from this stored data, rather
than being stored itself.
+ The basic reduce operation with group=false (the default over HTTP) is to reduce to a single
value. But by using startkey and endkey, you can get the summary value for any key interval.
+ Using group=true (which is Futon's default), you get a separate reduce value for each unique
key in the map - that is, all values which share the same key are grouped together and reduced
to a single value.
+ group_level=N queries are essentially a macro, which run one normal (group=false) reduce
query automatically for each interval on a set of intervals as defined by the level.
+ So with group_level=1, and keys like
+ {{{
+ ["a",1,1]
+ ["a",3,4]
+ ["a",3,8]
+ ["b",2,6]
+ ["b",2,6]
+ ["c",1,5]
+ ["c",4,2]
+ }}}
+ CouchDB will internally run 3 reduce queries for you. One that reduces
+ all rows where the first element of the key = "a", one for "b", and
+ one for "c".
+ If you were to query with group_level=2, you'd get a reduce query run
+ for each unique set of keys (according to their first two elements),
+ eg
+ {{{
+ ["a",1], ["a",3], ["b",2"], ["c",1], ["c",4]
+ }}}
+ group=true is the conceptual equivalent of group_level=exact, so
+ CouchDB runs a reduce per unique key in the map row set.
  == Restrictions on map and reduce functions ==
  The restriction on map functions is that they must be referentially transparent. That is,
given the same input document, they will always emit the same key/value pairs. This allows
CouchDB views to be updated incrementally, only reindexing the documents that have changed
since the last index update.

View raw message