I'm evaluating CouchBase for an application, and trying to figure out something about range queries on views. I know I can do a view get for a single key, multiple keys, or a range. Can I do a get for multiple ranges? i.e. I want to retrieve items with view key 0-10, 50-100, 5238-81902. I might simultaneously need 100 different ranges, so having to make 100 requests to the database seems like a lot of overhead.
1 Answers
As far as I know in couchbase there is no way to implement getting values from multiple ranges with one view. May be there are (or will be implemented in future) some features in Couchbase N1QL, but I didn't work with it.
Answering your question 100 requests will not be a big overhead. Couchbase is quiet fast and it's designed to handle a lot of operations per second. Also, if your view is correctly designed, it will not be "recalculated" on each query.
Also there is another way: 1. Determine minimum and maximum value of your range (it will be 0..81902 according to your example) 2. Query view that will return only document ids and a value that range was based on, without including all docs in result. 3. On client side filter array of results from previous step according to your ranges (0-10, 50-100, 5238-81902) and then use getMulti with document ids that left in array.
I don't know your data structure, so you can try both ways, test them and choose the best one that will fit your demands.

- 2,508
- 1
- 21
- 41
-
Good answer, if you are really worried about hitting Couchbase a lot (which isn't an issue) you could always cache the range results into their own key/document. – scalabilitysolved Mar 25 '14 at 14:51
-
I'm less concerned with the actual hits to Couchbase and more concerned with the overhead of so many requests. (i.e. memory, threads, etc.) I'm doing this from C# and the Couchbase SDK isn't async, so I'll be tying up threads. – David Pfeffer Mar 25 '14 at 14:59
-
I wouldn't be concerned about that too much, we run a couchbase stack in production with Java (so slightly different) and we've had zero memory/threading problems with the SDK's, plus we've pushed it pretty hard. You can read about it here http://scalabilitysolved.com/build-a-kick-ass-couchbase-stack-for-under-1000/ – scalabilitysolved Mar 25 '14 at 15:08
-
@DavidPfeffer A long time ago I've used Couchbase C# SDK in wrong way: I've created 1 couchbase client instance per each web request. Even with this the bottleneck was maximum connections that Windows can have, not memory. So I think if you use SDK in correct way it will have not too big overhead. Also as I said before you can try also second approach, that will reduce number of requests to 2, but it will increase CPU time and memory usage on client while filtering results. May be if you have many ranges and quiet big network delay between app and couchbase 2nd approach will be better. – m03geek Mar 26 '14 at 10:39