Skip to content

Commit

Permalink
Query: Refactors Optimistic Direct Execution to be turned on by defau…
Browse files Browse the repository at this point in the history
…lt on .NET SDK (#4225)

* Turned on ODe by default

* update subpartitioning tests to include ODE

* Updated contracts

* adds multihash test cases

* Updated client serialization test output

* Updated OffsetLimitPageSize() test

* Revert changes to Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/PartitionKeyHashBaselineTest.Lists.xml

* Updated EndToEndTraceWriterBaselineTests.ReadManyAsync baseline test

* Removed account details

* Updated performance benchmark results

* Set enableODE to true for some of the tests

* Updated Feed token tests to test ODE and non ODE cases

* Added ODE testing for Session token regression test

* Updated AggregateQueryTests() and CosmosMultiHashTest()

* Reverted changes to OffsetLimitPageSize()

* Added ODE testing to AggregateFunctionAsync()

* Removed account details from baseline tests

* Added assert to confirm that the right document is being returned every time

* Updated location of foreach loop for ODE

* Updated baselines

* Fixed comments

* Cleaned up code

* Fixed baselines

* Updated more baselines

* Setting QueryRequestRateTest() to not use ODE

---------

Co-authored-by: Nalu Tripician <27316859+NaluTripician@users.noreply.github.com>
  • Loading branch information
akotalwar and NaluTripician committed Jan 24, 2024
1 parent fccbc93 commit e11dc9b
Show file tree
Hide file tree
Showing 22 changed files with 1,263 additions and 1,164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class CosmosQueryExecutionContextFactory
{
internal const string ClientDisableOptimisticDirectExecution = "clientDisableOptimisticDirectExecution";
private const string InternalPartitionKeyDefinitionProperty = "x-ms-query-partitionkey-definition";
private const string QueryInspectionPattern = @"\s+(GROUP\s+BY\s+|COUNT\s*\(|MIN\s*\(|MAX\s*\(|AVG\s*\(|SUM\s*\(|DISTINCT\s+)";
private const string QueryInspectionPattern = @"\s*(GROUP\s+BY\s+|COUNT\s*\(|MIN\s*\(|MAX\s*\(|AVG\s*\(|SUM\s*\(|DISTINCT\s+)";
private const string OptimisticDirectExecution = "OptimisticDirectExecution";
private const string Passthrough = "Passthrough";
private const string Specialized = "Specialized";
Expand Down Expand Up @@ -782,7 +782,7 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
Debug.Assert(containerQueryProperties.ResourceId != null, "CosmosQueryExecutionContextFactory Assert!", "Container ResourceId cannot be null!");

List<Documents.PartitionKeyRange> targetRanges;
if (partitionedQueryExecutionInfo != null)
if (partitionedQueryExecutionInfo != null || inputParameters.InitialFeedRange != null)
{
targetRanges = await CosmosQueryExecutionContextFactory.GetTargetPartitionKeyRangesAsync(
cosmosQueryContext.QueryClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ public class QueryRequestOptions : RequestOptions
/// <value>
/// Direct (optimistic) execution offers improved performance for several kinds of queries such as a single partition streaming query.
/// </value>
#if PREVIEW
public
#else
internal
#endif
bool EnableOptimisticDirectExecution { get; set; }
#if PREVIEW
= true;
#endif
public bool EnableOptimisticDirectExecution { get; set; } = true;

/// <summary>
/// Gets or sets the maximum number of items that can be buffered client side during
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -423,7 +423,7 @@ JOIN (
WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20))
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -442,7 +442,7 @@ JOIN (
WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20))
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -482,7 +482,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -559,7 +559,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -578,7 +578,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -597,7 +597,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2["GivenName"]["Length"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -616,7 +616,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2["GivenName"]["Length"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -635,7 +635,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -654,7 +654,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -689,7 +689,7 @@ JOIN (
JOIN v0 IN root["Parents"]) AS v2
ORDER BY v2["FamilyName"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -707,7 +707,7 @@ JOIN (
JOIN v0 IN root["Parents"]) AS v2
ORDER BY v2["FamilyName"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -773,7 +773,7 @@ JOIN (
JOIN p0 IN root["Parents"]) AS v1
ORDER BY v1 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -792,7 +792,7 @@ JOIN (
WHERE (LENGTH(v1) > 10)
ORDER BY v1 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ JOIN (
SELECT VALUE root
FROM root
ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["The order by query does not have a corresponding composite index that it can be served from."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -132,7 +132,7 @@ ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC]]></SqlQuery>
SELECT VALUE root
FROM root
ORDER BY root["FamilyId"] ASC, root["FamilyId"] DESC]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["The order by query does not have a corresponding composite index that it can be served from."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -388,7 +388,6 @@ FROM (
JOIN c0 IN root["Children"]) AS v1) AS r1
ORDER BY r1["FamilyId"] ASC, r1["FamilyNumber"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Underlying object does not have an '_rid' or '__sys_rid' field.]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -435,7 +434,6 @@ FROM (
WHERE (p0["GivenName"]["Length"] > 5)) AS v0) AS r0
ORDER BY r0["FamilyId"] ASC, r0["FamilyNumber"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Underlying object does not have an '_rid' or '__sys_rid' field.]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -586,7 +584,7 @@ FROM root
JOIN f0 IN root["Records"]["Transactions"]
WHERE (ARRAY_LENGTH(root["Children"]) > 0)
ORDER BY f0["Type"] ASC, f0["Amount"] ASC]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest","message":"Message: {"Errors":["Order-by over correlated collections is not supported."]}rn]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ public async Task QueryRequestRateTest(bool directMode)
{
MaxItemCount = 1,
MaxConcurrency = 1,
#if PREVIEW
EnableOptimisticDirectExecution = false
#endif
EnableOptimisticDirectExecution = false,
}))
{
while (feedIterator.HasMoreResults)
Expand Down Expand Up @@ -271,9 +269,7 @@ public async Task QueryRequestRateTest(bool directMode)
{
MaxItemCount = 1,
MaxConcurrency = 1,
#if PREVIEW
EnableOptimisticDirectExecution = false
#endif
EnableOptimisticDirectExecution = false,
});

// First request should be a success
Expand Down Expand Up @@ -803,7 +799,6 @@ public async Task TesOdeTokenCompatibilityWithNonOdePipeline()
QueryRequestOptions queryRequestOptions = new QueryRequestOptions
{
MaxItemCount = 50,
EnableOptimisticDirectExecution = true
};

FeedIteratorInternal feedIterator =
Expand Down Expand Up @@ -833,7 +828,7 @@ public async Task TesOdeTokenCompatibilityWithNonOdePipeline()
responseMessage = await feedIteratorNew.ReadNextAsync(CancellationToken.None);
}

string expectedErrorMessage = "The continuation token supplied requires the Optimistic Direct Execution flag to be enabled in QueryRequestOptions for the query execution to resume. ";
string expectedErrorMessage = "Execution of this query using the supplied continuation token requires EnableOptimisticDirectExecution to be set in QueryRequestOptions. ";
Assert.IsTrue(responseMessage.CosmosException.ToString().Contains(expectedErrorMessage));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public async Task QueryPlanRetryTimeoutTestAsync()

QueryRequestOptions requestOptions = new QueryRequestOptions()
{
#if PREVIEW
// ODE set to false in this scenario as using ODE could cause the query plan to not get invoked.
EnableOptimisticDirectExecution = false
#endif
};

using FeedIterator<JObject> iterator = gatewayQueryPlanContainer.GetItemQueryIterator<JObject>("select * From T order by T.status", requestOptions: requestOptions);
Expand Down

0 comments on commit e11dc9b

Please sign in to comment.