Exploit natural rid order to order by { groupKey, rid } without composite index? #4531
Unanswered
Timo van Zijll Langhout (Timovzl)
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Automatic indexing on each property is so powerful. I'm wondering if we can leverage this to efficiently fulfill "top N per group" queries without composite indexes, e.g. find all objects with a given
groupKeyvalue in order of creation. As an example of agroupKey, imagine a customer ID on invoice objects.If I'm not mistaken, elements with the same
groupKeyvalue should be encountered inridorder, andridorder is practically creation order.By that logic, ordering by
groupKey, ridshould require no sorting, even when no composite index exists for the pair. So long asgroupKeyis indexed, which by default it would be, we should be able to efficiently find the instances matching a given value, and we should encounter them inridorder. I'd reason that translates to ordering bygroupKey DESC, rid DESCtoo, as well as to variants that constrain theridto a specific range - basically anything you could do with an index ongroupKey, rid.Is this reasoning correct? Does CosmosDB work this way?
All reactions