On Tue, Nov 24, 2009 at 08:33:43PM +0100, Dirkjan Ochtman wrote: > On Couch, as far as I can see, pre-issuing a count query means > actually retrieving all the row data, which doesn't seem to scale > nicely.
Not true: you have a count reduce function. Because each node of the Btree contains the already-calculated reduce value, this is very efficient. At best, it just reads the value out of the root node. At worst, for a key range, it will combine (re-reduce) count values for the subtrees within the key range, and count a few loose values at each end of the range. Where it's inefficient is when retrieving: if I understand it correctly, using offset=50000 *will* require walking through 50,000 rows in the index. That's unless each Btree node has a calculated 'number of rows' value which would allow chunks of tree to be skipped over quickly. I haven't heard anyone say that it does, but I could be wrong. For now, the best advice seems to be use 'next' and 'prev' links, using descending=true to get the values for the previous page.
