Distinguish required composite indexes from query optimizations - #267
Open
Vsevolod Kukol (sevoku) wants to merge 2 commits into
Open
Vsevolod Kukol (sevoku) wants to merge 2 commits into
Vsevolod Kukol (sevoku) wants to merge 2 commits into
Conversation
Vsevolod Kukol (sevoku)
requested review from
Theo van Kraay (TheovanKraay),
Jay Gordon (jaydestro) and
Sajeetharan (sajeetharan)
as code owners
September 22, 2026 13:34
Copilot started reviewing on behalf of
Vsevolod Kukol (sevoku)
September 22, 2026 13:41
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved moderate issues affect example correctness and consistency with related guidance.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
This PR corrects Cosmos DB composite-index guidance by distinguishing required multi-property indexes from optional filter-and-sort optimizations.
Changes:
- Clarifies composite-index requirements for multi-property
ORDER BY. - Adds equality-filtered
ORDER BYoptimization examples. - Updates SDK and type-discriminator guidance.
| File | Summary and findings |
|---|---|
skills/cosmosdb-best-practices/rules/index-composite.md |
Revises composite-index guidance and examples. Findings: Moderate (1 vote): optimization setup ignores the policy created by the baseline path. Moderate (3 votes): guidance conflicts with index-composite-direction.md. Nit (3 votes): manifests remain at version 1.2.0. Moderate (1 vote): the baseline example uses an uninitialized container. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Vsevolod Kukol (sevoku)
marked this pull request as draft
September 22, 2026 13:46
Vsevolod Kukol (sevoku)
marked this pull request as ready for review
September 22, 2026 14:52
Copilot started reviewing on behalf of
Vsevolod Kukol (sevoku)
September 22, 2026 14:57
View session
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Correct
index-composite.mdandindex-composite-direction.mdto consistently distinguish required multi-property sorting indexes from optional equality-filtered sort optimizations, and explain supported sort directions.Problem
The rule says any equality filter combined with sorting on another property requires a composite index, otherwise the query fails in production or needs client-side sorting. It repeats that claim in the emulator warning, TypeScript example, and type-discriminator guidance.
A single-property
ORDER BYcan instead use the default range indexes. Composite indexes can improve RU efficiency for suitable query shapes, but a filter or type discriminator alone does not make them mandatory.The related direction rule also incorrectly requires composites for all cross-partition sorts, shows one-property composites, and requires duplicate inverse-direction indexes. The Node.js examples need explicit container references and independent setup so the baseline container does not silently retain its original policy during the optimization example.
Changes
ORDER BYand provide a matching composite index. Those properties are constant within the filtered results, preserving the requested ordering.create()calls, and the returned container references. Existing IDs fail explicitly instead of silently retaining a different policy.Documentation Evidence
Microsoft's composite-index documentation states that queries with
ORDER BYon two or more properties require a composite index.The filter-and-ORDER-BY section explicitly says that without a composite index for a filter on one property and sorting on another, "the query will still succeed", while a composite index can reduce RU cost. It demonstrates rewriting
WHERE c.name = "John" ORDER BY c.timestampasORDER BY c.name, c.timestampto apply a composite index.The same indexing-policy documentation specifies two or more composite paths and support for the "opposite order on all paths." The JavaScript SDK implementation returns an existing container from
createIfNotExists()without applying the supplied creation policy, motivating the explicit fresh-container setup.Original Discussion And Scope
Addresses the original review discussion on microsoft/vscode-cosmosdb#3355, where the rule is vendored into the VS Code extension.
The follow-up consistency review and example-setup concerns from the review summary are addressed by fb28dd1. Changes are confined to the two composite-index rules; version metadata is unchanged.
The existing-container replacement example is untouched; its settings-preservation fix remains in #258, which is not included in this branch.