Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Query: Adds single physical partition check for OptimisticDirectExecution queries #3699

Merged
merged 9 commits into from
Feb 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -755,22 +755,9 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
{
if (!inputParameters.EnableOptimisticDirectExecution) return null;

// case 1: Is query going to a single partition
bool hasPartitionKey = inputParameters.PartitionKey.HasValue
&& inputParameters.PartitionKey != PartitionKey.Null
&& inputParameters.PartitionKey != PartitionKey.None;

// case 2: does query execution plan have a single query range
bool hasQueryRanges = partitionedQueryExecutionInfo != null
&& partitionedQueryExecutionInfo.QueryRanges.Count == 1
&& partitionedQueryExecutionInfo.QueryRanges[0].IsSingleValue;

if (!hasPartitionKey && !hasQueryRanges) return null;

//TODO: does collection have only one physical partition

List<Documents.PartitionKeyRange> targetRanges = new List<Documents.PartitionKeyRange>();

Debug.Assert(containerQueryProperties.ResourceId != null);
akotalwar marked this conversation as resolved.
Show resolved Hide resolved

List<Documents.PartitionKeyRange> targetRanges;
if (partitionedQueryExecutionInfo != null)
{
targetRanges = await CosmosQueryExecutionContextFactory.GetTargetPartitionKeyRangesAsync(
Expand All @@ -785,7 +772,7 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
else
{
Documents.PartitionKeyDefinition partitionKeyDefinition = GetPartitionKeyDefinition(inputParameters, containerQueryProperties);
if (partitionKeyDefinition != null && containerQueryProperties.ResourceId != null && inputParameters.PartitionKey != null)
if (inputParameters.PartitionKey != null && partitionKeyDefinition != null)
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
{
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
targetRanges = await cosmosQueryContext.QueryClient.GetTargetPartitionKeyRangesByEpkStringAsync(
cosmosQueryContext.ResourceLink,
Expand All @@ -794,6 +781,15 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
forceRefresh: false,
trace);
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
targetRanges = await cosmosQueryContext.QueryClient.GetTargetPartitionKeyRangesAsync(
cosmosQueryContext.ResourceLink,
containerQueryProperties.ResourceId,
new List<Documents.Routing.Range<string>> { FeedRangeEpk.FullRange.Range },
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
forceRefresh: false,
trace);
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
}
}
akotalwar marked this conversation as resolved.
Show resolved Hide resolved

if (targetRanges.Count == 1)
Expand Down
Loading