CouchDB Views: How much processing is allowed in a card to reduce?

I worked with Map Reduce with CouchDB. Some examples show some, perhaps, heavy logic in map reduction functions. In one specific case, they performed for loops inside the map.

Is the card converted to every possible document before it issues the selected documents?

If so, I would think that this means that performing any iterative processing as part of the map reduction functions will increase the processing load by an order of magnitude, at least.

It basically boils down to the following question: how much logic can be performed within a card comes down to its unreasonably expensive request ?

+8
database couchdb nosql mapreduce
source share
2 answers

CouchDB map-reduce allows a lot of expensive processing.

CouchDB (map-reduce) views are more like CREATE INDEX than they are SELECT FROM .

In particular, CouchDB ensures that the card function runs only once per document. (Well, actually once per document revision ever.) This is what an "iterative abbreviation map" is.

Therefore, suppose you had 10,000 documents and they process 1 second each (which is much higher than I have ever seen). It is 10,000 seconds or 2,8 hours to completely build the performance. However, as soon as the presentation is completed, a request for any line ( ?key=... ) or a line cut ( ?startkey=...&endkey=... ) is executed at the same time as a request for documents directly. Search time - O (log n) for the number of documents.

In other words, even if it takes 1 second for each document to complete the card, it takes several milliseconds to get the result. (Of course, the view should be built first, since it is actually an index.)

+8
source share

A db request is an unrelated activity with a map / document reduction. Therefore, the cost of the request is not affected by the complexity of the card / reduction.

In couchdb you are requesting an index. This means that it is a copy of your data in a format optimized for query speed. The query is not like a table in sql. He does not iterate over the records.

So how do you do this index? This is done through the map function. The card function emits a key and a value. The key is placed in the index. Some of the complex map features you mentioned can loop and emit a lot of keys and values. Couchdb is intelligent and only launches a document when it needs it, usually when creating, updating and deleting. That is why it is incremental mapping / reduction.

So, as you can see, the complex map function can affect the speed of creation, updating and deletion. But again, couchdb is smart in that you can specify how outdated the data can be when querying the index.

+2
source share

All Articles