Skip to content

High RU (1400 times) utilization on native query invoked with CosmosRequestOptions and cosmosAsyncContainer.queryItems than @Query way of invocation #48707

@ViswanathVeerappan

Description

@ViswanathVeerappan

I have a cosmos container which is hierarchically partitioned.

`@Data
@NoArgsConstructor
@container(hierarchicalPartitionKeyPaths = {"/partitionIdLevel1", "/partitionIdLevel2"})
public class UniqueTransactionInbound {

private String id;

private String originalMessageId;

private String messageTimestamp;

private String timeWindow;

private String partitionIdLevel1;

private String partitionIdLevel2;

private Integer ttl;

private Boolean testFlag;

private String hopUuid;

private Integer scenarioVersion;

private String insertTimestamp;

}`

Also, here is a snippet of the indexing policy we have,

{ "indexingMode": "consistent", "automatic": true, "includedPaths": [ { "path": "/partitionIdLevel1/?" }, { "path": "/partitionIdLevel2/?" }, { "path": "/testFlag/?" }, { "path": "/messageTimestamp/?" }, { "path": "/hopUuid/?" }, { "path": "/scenarioVersion/?" }, { "path": "/timeWindow/?" } ], "excludedPaths": [ { "path": "/*" }, { "path": "/\"_etag\"/?" } ], "fullTextIndexes": [] }

I was trying the following queries

SELECT DISTINCT VALUE c.scenarioVersion FROM c WHERE c.partitionIdLevel1 = @partitionIdLevel1 AND c.testFlag = @testFlag AND (c.messageTimestamp BETWEEN @rangeStart AND @rangeEnd)

SELECT c.timeWindow, COUNT(1) as count FROM c WHERE c.partitionIdLevel1 = @partitionIdLevel1 AND c.hopUuid = @hopUuid GROUP BY c.timeWindow

In the @Query way of executing the query, even though the first level of hierarchical partition was used in the where clause, the CosmosRequestOptions built from the CosmosTemplate did not populate it. We have an issue created in the past for this. (#45737)

I also implemented a custom implementation which would populate the first level of the hierarchical partition key on the CosmosRequestOptions.

PartitionKey partitionKey = new PartitionKeyBuilder().add(partitionIdLevel1).build(); CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); options.setPartitionKey(partitionKey); return cosmosAsyncContainer.queryItems(sqlQuerySpec, options, rclass) .collectList().block();

The custom implementation was consuming 1400 times the RU that was consumed by the @Query. Can someone please help understand the reason for the higher RU consumption and optimize the implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions