liveBook · Manning

Cross-partition query

As explained in Microsoft Azure in Action

A cross-partition query is a database query that retrieves data from multiple logical partitions.

A cross-partition query retrieves data from multiple logical partitions. In Azure Cosmos DB, that broader search can increase request-unit charges and latency, so partition-key design matters before the query ever runs. section 11.3.3 section 11.3.2

Reduce the number of partitions a query must visit by:

  • Filtering common queries on the partition key; a products-by-region query can use region to narrow its work. section 11.3.3
  • Combining frequently queried attributes in a composite partition key, such as region-category. section 11.3.3
  • Using a time-based component, such as region-date, when access patterns follow time. section 11.3.3

Alpaca-Ma-Bags product search

If products are commonly retrieved by region, choosing region as the partition key helps avoid broad queries. If region and category are usually queried together, a composite region-category key can narrow access further. section 11.3.3

C:/> az cosmosdb mongodb collection create 
--account-name alpacacosmosdbaccount --database-name alpacacosmosdb 
--name alpacacontainer --resource-group AlpacaRG 
--shard "/region-category" --throughput 400

The collection configuration shows a composite /region-category shard, a concrete way to align storage with related query attributes. section 11.3.3

How Microsoft Azure in Action covers it

How deep it goes
Explains costs and mitigation strategies through partition-key alignment, composite keys, and time-based keys, without detailing query execution internals.
Examples
Uses Alpaca-Ma-Bags product searches by region, composite region-category keys, and time-based region-date keys.
What it assumes
Assumes familiarity with Cosmos DB partition keys and logical partitions while reinforcing how access patterns should influence their selection.
What you can do after
Apply partition-key-aligned query design to reduce request-unit consumption and latency in Cosmos DB.
How it connects
Connects cross-partition queries to partition keys, composite partition keys, hot partitions, logical partitions, and physical partitions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microsoft Azure in Action. The section links point to the parts of the book it draws on.