Hi, I’m using the Java SDK and I have a query that fetches some data from a bucket using the WHERE clause, and then applies an ORDER, LIMIT and an OFFSET which works perfectly fine.
Now what I also need to do is figure out how many records in total did I get prior applying the limit/offset. In different posts, I saw that I can just do a COUNT query with my WHERE clause. However, this would require me to do a second query which is not great.
I started looking into what I have in N1qlQueryResult and I saw it gives me N1qlMetrics which in turn has sortCount. Looking at the Couchbase docs, I can see it has exactly what I need, the number of records returned from the WHERE query, prior applying the limits.
HOWEVER:
- I see the bellow in the Java doc, when would that happen and the server would omit the metrics? Is it when it errors out and I actually don’t get any results back ?
/ **
* A class that represents N1QL metrics.
*
* Note that the server could omit the metrics or part of the metrics,
* in which case an {@link #EMPTY_METRICS} will be returned.
- Does this mean that I cannot use the N1qlMetrics in a reliable way and I should fall back to what I see as inefficient and doing 2 queries with a COUNT ?