Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
736 stars 491 forks source link

Incorrect order of items on "Order by" query on multi-partition container #4472

Closed markwgit closed 4 months ago

markwgit commented 4 months ago

Describe the bug When I run a targeted multi-partition query with a partition key that includes the first level of subpartitioning and "Order by" keyword, the response contains items with incorrect order. This happens only if QueryRequestOptions.PartitionKey is set.

To Reproduce I created a console application to reproduce the issue. It is based on our test DB. Please download the solution, open the Program.cs and update key (can be supplied separately). Comment out the line 50 (requestOptions: requestOptions) and all works as expected.

Expected behavior The output should be sorted.

Actual behavior The output does not sorted

Environment summary SDK Version: 3.39.1 OS Version: Windows 11 Enterprise

adityasa commented 4 months ago

This is happening because in case of partial partition key CosmosQueryExecutionContextFactory is incorrectly determining query as a "streaming" query. In case of a streaming query, no global sort gets applied and results from backend are returned as is.