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!!')
}
}
});
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.