Index and document consistency

In the following N1QL query (there is a index on status field)

SELECT bucket.* FROM bucket WHERE status=1

Is it safe to assume that all result has status equal to 1 ? or due to async indexing it is possible that returned value has different status and we have to check it again in application layer

var N1qlQuery = couchbase.N1qlQuery;
// ...
query = N1qlQuery.fromString('SELECT bucket.* FROM bucket WHERE status=1');
bucket.query(query, function(err, rows) {
  for (row in rows) {
      if(row.status!==1){//IS THIS ASSERTION NEEDED?AS MAY BE IN INDEX STATUS IS 1 BUT IN DATA SERVICE IT IS 2
        throw new Error('Unexpected status!!')
     }
  }
});

Check out scan_consistency

https://docs.couchbase.com/server/6.0/learn/services-and-indexes/indexes/index-replication.html

https://docs.couchbase.com/java-sdk/2.7/scan-consistency-examples.html

It is a little unclear for me, can you tell me in not_bounded mode is the abovementioned assertion required?

What about at_plus and request_plus

https://docs.couchbase.com/java-sdk/2.7/scan-consistency-examples.html

The check is not required N1QL will not include status !=1 results because predicate is applied after indexScan/Fetch

As the query does STAR it fetches the document applies filter and gives results. The results will not have status !=1 . If you query fetches document keys and then retrieving document from the application/sdk in mean time some one changes status retrieved document can have different status than when N1QL applied filter.

2 Likes