[BUG] A page request with sorting is adding the sort to the count query #25068
Labels
azure-spring-cosmos
Spring cosmos related issues.
Client
This issue points to a problem in the data-plane of the library.
Cosmos
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Describe the bug
A page request with sorting is adding the sort to the count query which is creating a lot of performance issues for large data.
Exception or Stack Trace
The count query takes exceptionally high RUs
To Reproduce
Steps to reproduce the behavior:
Create a page request with sorting.
Execure a find with paged results.
Code Snippet
CosmosPageRequest pageable = CosmosPageRequest.of((long) pageInfo.getPageNumber() * maxResults,
pageInfo.getPageNumber(), maxResults.intValue(), pageInfo.getContinuationToken(),
Sort.by(Direction.fromString(sortDirection), sortColumn));
Page currentPageResults = recipientMessageRepository.findByRecipientId(recipientId, pageable)
is generating these queries:
SELECT * FROM ROOT r WHERE r.recipientId = @recipientId0 ORDER BY r.sendDate DESC
SELECT VALUE COUNT(1) FROM r WHERE r.recipientId = @recipientId0 ORDER BY r.sendDate DESC
Expected behavior
Sorting shouldn't be applied to the count query.
Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
Additional context
We are using page results instead of slice due to an existing issue in azure-cosmos-spring-data library. (#24956)
The text was updated successfully, but these errors were encountered: