If I run a query, such as this one below:
SELECT
DISTINCT c.vin,
c.year-model-trim,
c.make
FROM c
WHERE c.make= @make // make is partition key
AND c.manufactured > '2020-01-01'
I'll get 25 documents back, with query stats resembling these:
- Request Charge 5.79 RUs
- Retrieved document count 70
- Retrieved document size 25736 bytes
- Output document count 26
- Output document size 1423 bytes
- Index hit document count 25.9
- Index lookup time 0.6 ms
- Document load time 0.5900000000000001 ms
- Query engine execution time 0.26 ms
- System function execution time 0 ms
- User defined function execution time 0 ms
- Document write time 0.01 ms
- Round Trips 1
However, if I want to get only the COUNT results of that query, I can nest the above query in a count query:
SELECT COUNT(m.vin)
FROM
(
SELECT
DISTINCT c.vin,
c.year-model-trim,
c.make
FROM c
WHERE c.make= @make // make is partition key
AND c.manufactured > '2020-01-01'
)m
And my RU's go from ~5 to ~150.
- Request Charge 147.79 RUs
- Showing Results 1 - 1
- Retrieved document count 0
- Retrieved document size 0 bytes
- Output document count 1
- Output document size 79 bytes
- Index hit document count 0
- Index lookup time 124.97000000000001 ms
- Document load time 0 ms
Why is getting the COUNT of a result set in Cosmos so expensive in terms of RU's used?