2

I was reading the Cosmos DB docs on best practices for query performance, and I found the following ambiguous:

With Azure Cosmos DB, typically queries perform in the following order from fastest/most efficient to slower/less efficient.

  • GET on a single partition key and item key
  • Query with a filter clause on a single partition key
  • Query without an equality or range filter clause on any property
  • Query without filters

Is there a difference in performance or RUs between a "GET on a single partition key and item key" and a "QUERY on a single partition key and item key". It's not entirely clear to me whether this falls into case #1 or #2 or is somewhere in between.

Basically, I'm asking whether we ever need to use GET at all. The docs don't seem to clarify this anywhere.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Loren Paulsen
  • 8,960
  • 1
  • 28
  • 38

1 Answers1

5

A direct GET will be faster. As documented, a 1K document should cost 1 RU to retrieve. You will have a higher RU cost for a query, as you're engaging the query engine.

One caveat: with a direct read (the GET), you will retrieve the entire document. With a query, you can choose the projection of properties. For very large documents, this could result in significant bandwidth savings for your app, when using a query.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • 1
    That's a nice explanation. – Jay Gong Feb 06 '19 at 04:33
  • BTW, I ultimately did find a statement about this buried in the documentation: "Doing a read of a resource is the most efficient way to get a resource from the Database. If you know the resource's ID, do a read instead of a query by ID" (https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.documents.client.documentclient.readdocumentasync?redirectedfrom=MSDN&view=azure-dotnet) – Loren Paulsen Feb 20 '19 at 08:31