I couldn't understand the different between a request and a statement and how consistency is related to each of them.
I couldn't understand the different between a request and a statement and how consistency is related to each of them.
RequestPlus ensures all documents at the time of the query have been indexed.AtPlus (or StatementPlus) ensures that the specified documents have been indexed.
For example:
B contains one document.SELECT COUNT(1) FROM B -> result is 1.abSELECT COUNT(1) FROM B
1 is returned.a was mutated -> result of at least 2 after document a is updated in the index.3 after indexing has completely caught up.Some additional notes.
For better or worse, Couchbase allows you to control when indexes are updated following executing a query. Quite unfortunately, the default behavior when executing a query is a kind of 'eventual' consistency.
In practice, this means that sequential queries, where the second query depends on the results of the first query, are highly likely to fail with inconsistent results, as the indexes used to perform the second query have not yet been updated.
The choice of eventual consistency as the default option in Couchbase is bewildering to me. Performance is important. But it's arguably rarely, if ever, more important than consistency (except for bulk insert-and-forget operations), and especially not in a web application context.
So unless you're using Couchbase as a pure data warehouse (mostly writes, few reads), then you'll need to remember to manually set consistency to REQUEST_PLUS for the vast majority of your queries, or prepare for madness.