We have a cosmos db container where documents are inserted (append-only). We are seeing the same query consume wildly varying RUs even though the number of matching documents did not change. I am able to reproduce in Data Explorer.
Query:
select * from c where c.Id=<someId> and c.Version > <someVersion> order by c.Version asc
PartitionKeyPath = /Id
When it's executed successively in DataExplorer, I get the following query statistics:
- Request Charge = 4857.38 RUs, Index lookup time = 9562.75 ms, Retrieved document count = 77
- Request Charge = 1900.79 RUs, Index lookup time = 466.72 ms, Retrieved document count = 77
- Request Charge = 1878.25 RUs, Index lookup time = 548.80 ms, Retrieved document count = 77
Note the varying RUs and index lookup times (see actual screen shots with remaining data). Our logs show the same query taking upward of 7964 RUs and 20 seconds!
Also note then when I remove the "order by" clause, I start getting the same RUs on successive executions.
Per documentation: cosmos db guarantees that the same query on the same data always costs the same number of RUs on repeated executions. Why are we seeing those variations?