N1QL and Total Record Count for Paging


#1

I am wondering if there is an update or any change to the count(*) for a query. I am in the middle of starting to implement
paging support for my grid’s. One of the requirement is to return the total record count so that my grid can calculate the nbr of pages etc. I read in some discussions that there might be a support for count without a separate query but i could not find anything.


#2

we already have support for count(*). More efficient. https://blog.couchbase.com/understanding-index-grouping-aggregation-couchbase-n1ql-query/

SELECT COUNT(*) FROM default;
without any predicate is very fast. It reads from bucket stats and returns.
If you have any predicate we need go through index or fetch document and count on the fly.
If query needs sort and not using index order sortCount in metrics of N1QL query gives total qualified rows.
You also have option of using views and SDK.

https://blog.couchbase.com/offset-keyset-pagination-n1ql-query-couchbase/


#3

I know there is the select count(*) but it requires a separate query to be send which takes, time, resources as well need to maintain separate N1QL query staments