[Internal] Query: Fixes ORDER BY issue when partial partition key is specified in RequestOptions in a query to sub-partitioned container #4587
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.
Pull Request Template
Description
This changes addresses the issue that when an ORDER BY query is issued to a sub-partitioned container with partial partition key in the request options, documents outside the specified logical partition can also be retrieved. This happens if the logical partition range specified by partition key is split across multiple physical partitions (as with all HPK related issues so far) and one of the physical partitions contains data from other logical partitions (which is very likely, especially if a split has taken place).
With the previous fix made in following PR, which is still a required fix, we ensured that in cases when logical partition is split across multiple physical partitions, we perform a cross-partition ordering in the client:
#4507
However, as a result of this change, information regarding the logical partition key is not honored and each physical partition gets queried fully. This is because enumerator is scoped to full partition and when request is issued, epk range header is not specified in the request (only partition id is specified)
This change refactors the existing logic (used in another pipeline) to limit the FeedRangeEpk used by the enumerator to the intersection of physical partition range and logical partition feed range. This effectively limits the query epk range (by including correct header) for cases when a physical partition contains data from other logical partitions as well.
As far as testing is concerned, the InMemoryContainer was already able to repro this case as part of previous change. And it was originally thought to be the issue with the test infra in the previous change and a fix was applied to suppress this issue. The change removes this suppression and it was confirmed that existing ORDER BY queries in SubPartitionedTests repro the issue.
Type of change
Please delete options that are not relevant.
To automatically close an issue: closes #4563