Users Pricing

forum

Home Forums Optimizing Query Performance and RU Costs in Azure Cosmos DB – MindStick

Optimizing Query Performance and RU Costs in Azure Cosmos DB

Anubhav Sharma 24 17 Sep 2026

Running inefficient SQL queries against Cosmos DB can quickly consume your allocated throughput budget. Understanding index mechanics and query patterns allows you to write lean, low-cost queries.

Indexing Policy Customization

By default, Cosmos DB automatically indexes every path in every item. While convenient for prototyping, indexing unnecessary strings and arrays inflates write latency and storage costs. Excluding heavy fields significantly lowers operational costs.

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*"
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"description\"/?"
        },
        {
            "path": "/\"rawPayload\"/?"
        }
    ]
}

Key Optimization Rules

  • Avoid Cross-Partition Queries: Always include the partition key in your WHERE clause when possible to prevent queries from fanning out to every physical partition.
  • Project Specific Fields: Replace SELECT * with targeted field projections (e.g., SELECT c.id, c.status FROM c) to minimize serialization and bandwidth costs.
  • Use Composite Indexes: Create composite indexes for queries containing multiple ORDER BY or filter clauses across different properties.

1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md