I need to read several documents from a cosmos db container, for which I know the partition keys.
If I were to do a point read for each, this would be an RU cost of about 1 per document.
So I noticed when running some queries that there may be a cheaper way:
Running a well-indexed query that returns one result costs 3 RUs. But if I have a query that has several OR conditions in the WHERE clause, scaling this out becomes cheaper:
SELECT * FROM c
WHERE c.id = 'a'
OR c.id = 'b'
OR c.id = 'c'
//...
Here, the cost for the first condition was 3, but adding each new condition was only about 0.3 RUs. This made me fairly happy, as it seems to be a good way to optimize cost.
However, I decided to actually create a DB with a bunch of data and high provisioned RUs to make sure that this holds when there are more underlying physical partitions. So I made a container with 40k provisioned RUs and about 300k records (for about 400MB of data). I ran a query like
SELECT * FROM c
WHERE c.id = 'a'
OR c.id = 'b'
OR c.id = 'c'
And with each new condition, the cost went up only 0.3RUs. Nice.
But then when I added a fourth OR condition, the cost went up by 3 RUs. Same for the 5th.
Why does the cost increase by 0.3 initially but then by 3 later on?
Is it the case that the first three records I pulled happened to be on one physical partition, and the others were on their own partitions?
Subsequent OR clause additions seem to increase the cost by anything between 1.5 and 3 RUs...