views:

311

answers:

1

I think read somewhere that when a View is requested the "map" is only run across documents that have been added since the last time it was requested? How is this determined? I thought I saw something about a sequence number. Is this something that you can get to? Its not part of the UUID trailing on the _rev field is it?

Any way to force a 'recalc' of the entire View (across all records)?

+1  A: 

The section about View Indexes in the Technical Overview is a great guide to this.

The view builder uses the database sequence ID to determine if the view group is fully up-to-date with the database. If not, the view engine examines the all database documents (in packed sequential order) changed since the last refresh. Documents are read in the order they occur in the disk file, reducing the frequency and cost of disk head seeks.
As documents are examined, their previous row values are removed from the view indexes, if they exist. If the document is selected by a view function, the function results are inserted into the view as a new row.

CouchDB first checks to see if anything has changed in the entire database using a sequence id (that gets updated whenever there's a change to any document in the database). If something has changed it goes looking for those documents and runs the map function on them.

There really shouldn't be any need to rebuild/regenerate your views since it will incrementally refresh as you modify your documents (note that it won't update the view until you use it though). With hat said one way (and I'm sure there's a better way) would be to remove the design document describing the view and insert it again seeing as a design document is no different (almost) from a normal document.

Markus Olsson
ok, that makes a lot more sense then the way I was imagining it in my head. +1 clever trick to rebuild view.
tyndall
I believe recent versions of CouchDB (e.g. .10.1) use a has of the design document's view function to decide whether to rebuild the view. Thus, re-inserting the design document *may* not refresh the view. Certainly, updating with a new view function will, however.
Barry Wark
@barry, that's very interesting and it makes sense to. Do you have any links to where I could read more about view function hashes?
Markus Olsson