Hi, we recently started with couchbase and n1ql is the best but we have some problem with pagination.
We use couchbase community edition 5 with one bucket and 2.000.000 documents.
This is the problem:
if we run query "SELECT COUNT(*) FROM bucket" return in 11.83ms, but if we run query “SELECT COUNT(*) FROM bucket WHERE attr_name=1” server response in 17.38s.
All the documents have attr_name equal to 1 and it’s indexed. On production we will have 30.000.000 docs.
SELECT COUNT(*) FROM bucket;
Above query has no predicate that means it need to count all the documents in the bucket. So it uses bucket statistics. so it is fast.
SELECT COUNT(*) FROM bucket WHERE attr_name=1;
CREATE INDEX second-index ON bucket(attr_name)
Uses IndexCountScan which uses index to count the values. Which is taking time.
Adding more replica would not improve the scan latency of a single scan. You can try with MOI(memory optimized indexes) in EE version or use partitioned indexes(in Couchbase Server 5.5 EE) which would process the query in parallel across partitions and lead to much improved scan latency.