diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CosmosQueryExecutionContextFactory.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CosmosQueryExecutionContextFactory.cs index fa98aa209e..dae088bede 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CosmosQueryExecutionContextFactory.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CosmosQueryExecutionContextFactory.cs @@ -584,7 +584,7 @@ private static async Task GetPartitionedQueryExec inputParameters.SqlQuerySpec, cosmosQueryContext.ResourceLink, inputParameters.PartitionKey, - inputParameters.IsNonStreamingOrderByQueryFeatureDisabled, + inputParameters.IsHybridSearchQueryPlanOptimizationDisabled, trace, cancellationToken); } @@ -601,6 +601,7 @@ private static async Task GetPartitionedQueryExec inputParameters.PartitionKey != null, containerQueryProperties.GeospatialType, cosmosQueryContext.UseSystemPrefix, + inputParameters.IsHybridSearchQueryPlanOptimizationDisabled, trace, cancellationToken); } @@ -832,7 +833,7 @@ private InputParameters( PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, bool returnResultsInDeterministicOrder, bool enableOptimisticDirectExecution, - bool isNonStreamingOrderByQueryFeatureDisabled, + bool isHybridSearchQueryPlanOptimizationDisabled, bool enableDistributedQueryGatewayMode, TestInjections testInjections) { @@ -847,7 +848,7 @@ private InputParameters( this.PartitionedQueryExecutionInfo = partitionedQueryExecutionInfo; this.ReturnResultsInDeterministicOrder = returnResultsInDeterministicOrder; this.EnableOptimisticDirectExecution = enableOptimisticDirectExecution; - this.IsNonStreamingOrderByQueryFeatureDisabled = isNonStreamingOrderByQueryFeatureDisabled; + this.IsHybridSearchQueryPlanOptimizationDisabled = isHybridSearchQueryPlanOptimizationDisabled; this.EnableDistributedQueryGatewayMode = enableDistributedQueryGatewayMode; this.TestInjections = testInjections; } @@ -864,7 +865,7 @@ public static InputParameters Create( PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, bool? returnResultsInDeterministicOrder, bool enableOptimisticDirectExecution, - bool isNonStreamingOrderByQueryFeatureDisabled, + bool isHybridSearchQueryPlanOptimizationDisabled, bool enableDistributedQueryGatewayMode, TestInjections testInjections) { @@ -903,7 +904,7 @@ public static InputParameters Create( partitionedQueryExecutionInfo: partitionedQueryExecutionInfo, returnResultsInDeterministicOrder: returnResultsInDeterministicOrder.GetValueOrDefault(InputParameters.DefaultReturnResultsInDeterministicOrder), enableOptimisticDirectExecution: enableOptimisticDirectExecution, - isNonStreamingOrderByQueryFeatureDisabled: isNonStreamingOrderByQueryFeatureDisabled, + isHybridSearchQueryPlanOptimizationDisabled: isHybridSearchQueryPlanOptimizationDisabled, enableDistributedQueryGatewayMode: enableDistributedQueryGatewayMode, testInjections: testInjections); } @@ -920,7 +921,7 @@ public static InputParameters Create( public bool ReturnResultsInDeterministicOrder { get; } public TestInjections TestInjections { get; } public bool EnableOptimisticDirectExecution { get; } - public bool IsNonStreamingOrderByQueryFeatureDisabled { get; } + public bool IsHybridSearchQueryPlanOptimizationDisabled { get; } public bool EnableDistributedQueryGatewayMode { get; } public InputParameters WithContinuationToken(CosmosElement token) @@ -937,7 +938,7 @@ public InputParameters WithContinuationToken(CosmosElement token) this.PartitionedQueryExecutionInfo, this.ReturnResultsInDeterministicOrder, this.EnableOptimisticDirectExecution, - this.IsNonStreamingOrderByQueryFeatureDisabled, + this.IsHybridSearchQueryPlanOptimizationDisabled, this.EnableDistributedQueryGatewayMode, this.TestInjections); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryClient/CosmosQueryClient.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryClient/CosmosQueryClient.cs index 5d8d3b1461..454dd35217 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryClient/CosmosQueryClient.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryClient/CosmosQueryClient.cs @@ -48,6 +48,7 @@ public abstract Task> TryGetPartitionedQ bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken); diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs index a62fa63471..a3fc90c43c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs @@ -127,6 +127,7 @@ public TryCatch TryGetPartitionedQueryExecutionIn bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool hybridSearchSkipOrderByRewrite, GeospatialType geospatialType) { TryCatch tryGetInternalQueryInfo = this.TryGetPartitionedQueryExecutionInfoInternal( @@ -139,6 +140,7 @@ public TryCatch TryGetPartitionedQueryExecutionIn hasLogicalPartitionKey: hasLogicalPartitionKey, allowDCount: allowDCount, useSystemPrefix: useSystemPrefix, + hybridSearchSkipOrderByRewrite: hybridSearchSkipOrderByRewrite, geospatialType: geospatialType); if (!tryGetInternalQueryInfo.Succeeded) @@ -190,6 +192,7 @@ internal TryCatch TryGetPartitionedQueryE bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool hybridSearchSkipOrderByRewrite, GeospatialType geospatialType) { if (querySpecJsonString == null || partitionKeyDefinition == null) @@ -242,7 +245,8 @@ internal TryCatch TryGetPartitionedQueryE bHasLogicalPartitionKey = Convert.ToInt32(hasLogicalPartitionKey), bIsContinuationExpected = Convert.ToInt32(isContinuationExpected), bRequireFormattableOrderByQuery = Convert.ToInt32(requireFormattableOrderByQuery), - bUseSystemPrefix = Convert.ToInt32(useSystemPrefix), + bUseSystemPrefix = Convert.ToInt32(useSystemPrefix), + bHybridSearchSkipOrderByRewrite = Convert.ToInt32(!hybridSearchSkipOrderByRewrite), eGeospatialType = Convert.ToInt32(geospatialType), ePartitionKind = Convert.ToInt32(partitionKind) }; diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs index 3b7d54717e..bc983b2f03 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanHandler.cs @@ -29,6 +29,7 @@ public async Task> TryGetQueryPlanAsync( VectorEmbeddingPolicy vectorEmbeddingPolicy, bool hasLogicalPartitionKey, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, GeospatialType geospatialType, CancellationToken cancellationToken) { @@ -51,6 +52,7 @@ public async Task> TryGetQueryPlanAsync( vectorEmbeddingPolicy, hasLogicalPartitionKey, useSystemPrefix, + isHybridSearchQueryPlanOptimizationDisabled, geospatialType, cancellationToken); if (!tryGetQueryInfo.Succeeded) @@ -68,6 +70,7 @@ private Task> TryGetQueryInfoAsync( VectorEmbeddingPolicy vectorEmbeddingPolicy, bool hasLogicalPartitionKey, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken = default) { @@ -83,7 +86,8 @@ private Task> TryGetQueryInfoAsync( allowNonValueAggregateQuery: true, hasLogicalPartitionKey: hasLogicalPartitionKey, allowDCount: true, - useSystemPrefix: useSystemPrefix, + useSystemPrefix: useSystemPrefix, + isHybridSearchQueryPlanOptimizationDisabled: isHybridSearchQueryPlanOptimizationDisabled, geospatialType: geospatialType, cancellationToken: cancellationToken); } diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs index 1cf49fbf93..c34f897fd6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs @@ -28,36 +28,38 @@ internal static class QueryPlanRetriever | QueryFeatures.OrderBy | QueryFeatures.Top | QueryFeatures.NonValueAggregate - | QueryFeatures.DCount - | QueryFeatures.NonStreamingOrderBy - | QueryFeatures.CountIf - | QueryFeatures.HybridSearch - | QueryFeatures.WeightedRankFusion; - - private static readonly QueryFeatures SupportedQueryFeaturesWithoutNonStreamingOrderBy = - SupportedQueryFeatures & (~QueryFeatures.NonStreamingOrderBy); - - private static readonly string SupportedQueryFeaturesString = SupportedQueryFeatures.ToString(); - - private static readonly string SupportedQueryFeaturesWithoutNonStreamingOrderByString = - SupportedQueryFeaturesWithoutNonStreamingOrderBy.ToString(); - - private static string GetSupportedQueryFeaturesString(bool isNonStreamingOrderByQueryFeatureDisabled) - { - return isNonStreamingOrderByQueryFeatureDisabled ? - SupportedQueryFeaturesWithoutNonStreamingOrderByString : - SupportedQueryFeaturesString; + | QueryFeatures.DCount + | QueryFeatures.NonStreamingOrderBy + | QueryFeatures.CountIf + | QueryFeatures.HybridSearch + | QueryFeatures.WeightedRankFusion + | QueryFeatures.HybridSearchSkipOrderByRewrite; + + private static readonly QueryFeatures SupportedQueryFeaturesWithHybridSearchQueryPlanOptimizationDisabled = + SupportedQueryFeatures & (~QueryFeatures.HybridSearchSkipOrderByRewrite); + + private static readonly string SupportedQueryFeaturesString = SupportedQueryFeatures.ToString(); + + private static readonly string SupportedQueryFeaturesWithHybridSearchQueryPlanOptimizationDisabledString = + SupportedQueryFeaturesWithHybridSearchQueryPlanOptimizationDisabled.ToString(); + + private static string GetSupportedQueryFeaturesString(bool isHybridSearchQueryPlanOptimizationDisabled) + { + return isHybridSearchQueryPlanOptimizationDisabled ? + SupportedQueryFeaturesWithHybridSearchQueryPlanOptimizationDisabledString : + SupportedQueryFeaturesString; } public static async Task GetQueryPlanWithServiceInteropAsync( CosmosQueryClient queryClient, SqlQuerySpec sqlQuerySpec, Documents.ResourceType resourceType, - PartitionKeyDefinition partitionKeyDefinition, + PartitionKeyDefinition partitionKeyDefinition, VectorEmbeddingPolicy vectorEmbeddingPolicy, bool hasLogicalPartitionKey, GeospatialType geospatialType, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, ITrace trace, CancellationToken cancellationToken = default) { @@ -85,10 +87,11 @@ public static async Task GetQueryPlanWithServiceI TryCatch tryGetQueryPlan = await queryPlanHandler.TryGetQueryPlanAsync( sqlQuerySpec, resourceType, - partitionKeyDefinition, + partitionKeyDefinition, vectorEmbeddingPolicy, hasLogicalPartitionKey, useSystemPrefix, + isHybridSearchQueryPlanOptimizationDisabled, geospatialType, cancellationToken); @@ -112,8 +115,8 @@ public static Task GetQueryPlanThroughGatewayAsyn CosmosQueryContext queryContext, SqlQuerySpec sqlQuerySpec, string resourceLink, - PartitionKey? partitionKey, - bool isNonStreamingOrderByQueryFeatureDisabled, + PartitionKey? partitionKey, + bool isHybridSearchQueryPlanOptimizationDisabled, ITrace trace, CancellationToken cancellationToken = default) { @@ -149,7 +152,7 @@ public static Task GetQueryPlanThroughGatewayAsyn OperationType.QueryPlan, sqlQuerySpec, partitionKey, - GetSupportedQueryFeaturesString(isNonStreamingOrderByQueryFeatureDisabled), + GetSupportedQueryFeaturesString(isHybridSearchQueryPlanOptimizationDisabled), trace, cancellationToken); } diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index bbcabfc41c..71d1001380 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -186,7 +186,8 @@ public async Task GetPartitionedQueryExecutionInf isContinuationExpected: isContinuationExpected, allowNonValueAggregateQuery: allowNonValueAggregateQuery, hasLogicalPartitionKey: hasLogicalPartitionKey, - allowDCount: allowDCount, + allowDCount: allowDCount, + hybridSearchSkipOrderByRewrite: false, geospatialType: geospatialType, useSystemPrefix: false); if (!tryGetPartitionedQueryExecutionInfo.Succeeded) diff --git a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs index 3c7b01b154..2172e3ffd6 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v3Query/CosmosQueryClientCore.cs @@ -101,6 +101,7 @@ public override async Task> TryGetPartit bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken) { @@ -126,6 +127,7 @@ public override async Task> TryGetPartit hasLogicalPartitionKey: hasLogicalPartitionKey, allowDCount: allowDCount, useSystemPrefix: useSystemPrefix, + hybridSearchSkipOrderByRewrite: !isHybridSearchQueryPlanOptimizationDisabled, geospatialType: geospatialType); } diff --git a/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs b/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs index a63c6f955e..5891066b42 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs @@ -149,7 +149,7 @@ public static QueryIterator Create( partitionedQueryExecutionInfo: partitionedQueryExecutionInfo, returnResultsInDeterministicOrder: queryRequestOptions.ReturnResultsInDeterministicOrder, enableOptimisticDirectExecution: queryRequestOptions.EnableOptimisticDirectExecution, - isNonStreamingOrderByQueryFeatureDisabled: queryRequestOptions.IsNonStreamingOrderByQueryFeatureDisabled, + isHybridSearchQueryPlanOptimizationDisabled: queryRequestOptions.IsHybridSearchQueryPlanOptimizationDisabled, enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode && (clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway), testInjections: queryRequestOptions.TestSettings); diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 41594a9655..c49a02d479 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -115,18 +115,18 @@ public class QueryRequestOptions : RequestOptions public bool? PopulateIndexMetrics { get; set; } /// - /// Gets or sets the request option for document query requests in the Azure Cosmos DB service. - /// - /// - /// - /// PopulateQueryAdvice is used to obtain the query advice to understand aspect of the query that can be optimized. - /// The results will be displayed in FeedResponse.QueryAdvice. Please note that this options will incur overhead, so it should be - /// enabled only when debugging queries. - /// - /// - internal bool? PopulateQueryAdvice { get; set; } - - /// + /// Gets or sets the request option for document query requests in the Azure Cosmos DB service. + /// + /// + /// + /// PopulateQueryAdvice is used to obtain the query advice to understand aspect of the query that can be optimized. + /// The results will be displayed in FeedResponse.QueryAdvice. Please note that this options will incur overhead, so it should be + /// enabled only when debugging queries. + /// + /// + internal bool? PopulateQueryAdvice { get; set; } + + /// /// Gets or sets the consistency level required for the request in the Azure Cosmos DB service. /// /// @@ -187,8 +187,8 @@ public ConsistencyLevel? ConsistencyLevel /// Enables printing query in Traces db.query.text attribute. By default, query is not printed. /// Users have the option to enable printing parameterized or all queries, /// but has to beware that customer data may be shown when the later option is chosen. It's the user's responsibility to sanitize the queries if necessary. - /// - public QueryTextMode QueryTextMode { get; set; } = QueryTextMode.None; + /// + public QueryTextMode QueryTextMode { get; set; } = QueryTextMode.None; internal CosmosElement CosmosElementContinuationToken { get; set; } @@ -208,10 +208,10 @@ public ConsistencyLevel? ConsistencyLevel internal FeedRange FeedRange { get; set; } - internal bool IsNonStreamingOrderByQueryFeatureDisabled { get; set; } = ConfigurationManager.IsNonStreamingOrderByQueryFeatureDisabled(defaultValue: false); - - // This is a temporary flag to enable the distributed query gateway mode. - // This flag will be removed once we have a way for the client to determine + internal bool IsHybridSearchQueryPlanOptimizationDisabled { get; set; } = ConfigurationManager.IsHybridSearchQueryPlanOptimizationDisabled(defaultValue: false); + + // This is a temporary flag to enable the distributed query gateway mode. + // This flag will be removed once we have a way for the client to determine // that we are talking to a distributed query gateway. internal bool EnableDistributedQueryGatewayMode { get; set; } = ConfigurationManager.IsDistributedQueryGatewayModeEnabled(defaultValue: false); @@ -259,13 +259,13 @@ internal override void PopulateRequestOptions(RequestMessage request) { request.Headers.Add(HttpConstants.HttpHeaders.ResponseContinuationTokenLimitInKB, this.ResponseContinuationTokenLimitInKb.ToString()); } - - // All query APIs (GetItemQueryIterator, GetItemLinqQueryable and GetItemQueryStreamIterator) turn into ReadFeed operation if query text is null. - // In such a case, query pipelines are still involved (including QueryRequestOptions). In general backend only honors SupportedSerializationFormats - // for OperationType Query but has a bug where it returns a binary response for ReadFeed API when partition key is also specified in the request. - if (request.OperationType == OperationType.Query) - { - request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats?.ToString() ?? DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; + + // All query APIs (GetItemQueryIterator, GetItemLinqQueryable and GetItemQueryStreamIterator) turn into ReadFeed operation if query text is null. + // In such a case, query pipelines are still involved (including QueryRequestOptions). In general backend only honors SupportedSerializationFormats + // for OperationType Query but has a bug where it returns a binary response for ReadFeed API when partition key is also specified in the request. + if (request.OperationType == OperationType.Query) + { + request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats?.ToString() ?? DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats; } if (this.StartId != null) @@ -293,11 +293,11 @@ internal override void PopulateRequestOptions(RequestMessage request) request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateIndexMetricsV2, this.PopulateIndexMetrics.ToString()); } - if (this.PopulateQueryAdvice.HasValue) - { - request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateQueryAdvice, this.PopulateQueryAdvice.ToString()); - } - + if (this.PopulateQueryAdvice.HasValue) + { + request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateQueryAdvice, this.PopulateQueryAdvice.ToString()); + } + DedicatedGatewayRequestOptions.PopulateMaxIntegratedCacheStalenessOption(this.DedicatedGatewayRequestOptions, request); DedicatedGatewayRequestOptions.PopulateBypassIntegratedCacheOption(this.DedicatedGatewayRequestOptions, request); diff --git a/Microsoft.Azure.Cosmos/src/Routing/PartitionRoutingHelper.cs b/Microsoft.Azure.Cosmos/src/Routing/PartitionRoutingHelper.cs index 6077aea787..1c0f859eab 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/PartitionRoutingHelper.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/PartitionRoutingHelper.cs @@ -33,7 +33,7 @@ public static IReadOnlyList> GetProvidedPartitionKeyRanges( bool hasLogicalPartitionKey, bool allowDCount, bool allowNonValueAggregates, - bool useSystemPrefix, + bool useSystemPrefix, PartitionKeyDefinition partitionKeyDefinition, Cosmos.VectorEmbeddingPolicy vectorEmbeddingPolicy, QueryPartitionProvider queryPartitionProvider, @@ -64,7 +64,8 @@ public static IReadOnlyList> GetProvidedPartitionKeyRanges( isContinuationExpected: isContinuationExpected, allowNonValueAggregateQuery: allowNonValueAggregates, hasLogicalPartitionKey: hasLogicalPartitionKey, - allowDCount: allowDCount, + allowDCount: allowDCount, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: useSystemPrefix, geospatialType: geospatialType); if (!tryGetPartitionQueryExecutionInfo.Succeeded) diff --git a/Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs b/Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs index 5cf41f4449..a2d0f3652d 100644 --- a/Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs +++ b/Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs @@ -65,7 +65,7 @@ internal static class ConfigurationManager /// /// Environment variable name to disable sending non streaming order by query feature flag to the gateway. /// - internal static readonly string NonStreamingOrderByQueryFeatureDisabled = "AZURE_COSMOS_NON_STREAMING_ORDER_BY_FLAG_DISABLED"; + internal static readonly string HybridSearchQueryPlanOptimizationDisabled = "AZURE_COSMOS_HYBRID_SEARCH_QUERYPLAN_OPTIMIZATION_DISABLED"; /// /// Environment variable name to enable distributed query gateway mode. @@ -246,15 +246,15 @@ public static bool IsOptimisticDirectExecutionEnabled( } /// - /// Gets the boolean value indicating whether the non streaming order by query feature flag should be sent to the gateway + /// Gets the boolean value indicating whether the hybrid search query plan optimization feature flag should be sent to the gateway /// based on the environment variable override. /// - public static bool IsNonStreamingOrderByQueryFeatureDisabled( + public static bool IsHybridSearchQueryPlanOptimizationDisabled( bool defaultValue) { return ConfigurationManager .GetEnvironmentVariable( - variable: NonStreamingOrderByQueryFeatureDisabled, + variable: HybridSearchQueryPlanOptimizationDisabled, defaultValue: defaultValue); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NonStreamingOrderByQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NonStreamingOrderByQueryTests.cs index abf9261351..5862b00814 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NonStreamingOrderByQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/NonStreamingOrderByQueryTests.cs @@ -83,8 +83,8 @@ await this.CreateIngestQueryDeleteAsync( [TestMethod] public async Task QueryFeatureFlagTests() { - using EnvironmentVariable nonStreamingOrderByDisabled = new EnvironmentVariable( - ConfigurationManager.NonStreamingOrderByQueryFeatureDisabled); + using EnvironmentVariable hybridSearchQueryPlanOptimizationDisabled = new EnvironmentVariable( + ConfigurationManager.HybridSearchQueryPlanOptimizationDisabled); static async Task ImplementationAsync(Container container, IReadOnlyList _) { @@ -92,7 +92,7 @@ static async Task ImplementationAsync(Container container, IReadOnlyList ExecuteQueryPlanRequestAsync { this.validator.Validate(supportedQueryFeatures); - if (this.validator.ExpectNonStreamingOrderBy) + if (this.validator.ExpectQueryPlanOptimizationDisabled) { // older emulator in the github repo does not support non-streaming order by, and will send back 400 supportedQueryFeatures = SupportedQueryFeaturesString; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs index 641f557ed2..450d4b622e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs @@ -500,7 +500,7 @@ public async Task ChangeFeedAsync() public async Task QueryAsync() { List inputs = new List(); - QueryRequestOptions requestOptions = new QueryRequestOptions() { IsNonStreamingOrderByQueryFeatureDisabled = true }; + QueryRequestOptions requestOptions = new QueryRequestOptions() { IsHybridSearchQueryPlanOptimizationDisabled = true }; int startLineNumber; int endLineNumber; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/ParsingBenchmark.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/ParsingBenchmark.cs index 62363f8a58..b10010e156 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/ParsingBenchmark.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Query/ParsingBenchmark.cs @@ -120,13 +120,14 @@ private static void ParseUsingNativeParser(SqlQuerySpec sqlQuerySpec) { TryCatch tryGetQueryPlan = QueryPartitionProvider.TryGetPartitionedQueryExecutionInfo( querySpecJsonString: JsonConvert.SerializeObject(sqlQuerySpec), - partitionKeyDefinition: PartitionKeyDefinition, + partitionKeyDefinition: PartitionKeyDefinition, vectorEmbeddingPolicy: null, requireFormattableOrderByQuery: true, isContinuationExpected: false, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/OptimisticDirectExecutionQueryBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/OptimisticDirectExecutionQueryBaselineTests.cs index 48c033b0e3..b751ac3dc8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/OptimisticDirectExecutionQueryBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/OptimisticDirectExecutionQueryBaselineTests.cs @@ -826,7 +826,8 @@ internal static Tuple Get isContinuationExpected: true, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); @@ -1027,7 +1028,7 @@ private static IQueryPipelineStage CreateQueryPipelineStage( partitionedQueryExecutionInfo: null, returnResultsInDeterministicOrder: null, enableOptimisticDirectExecution: queryRequestOptions.EnableOptimisticDirectExecution, - isNonStreamingOrderByQueryFeatureDisabled: queryRequestOptions.IsNonStreamingOrderByQueryFeatureDisabled, + isHybridSearchQueryPlanOptimizationDisabled: queryRequestOptions.IsHybridSearchQueryPlanOptimizationDisabled, enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode, testInjections: queryRequestOptions.TestSettings); @@ -1356,7 +1357,8 @@ public override Task> TryGetPartitionedQ bool isContinuationExpected, bool allowNonValueAggregateQuery, bool hasLogicalPartitionKey, - bool allowDCount, + bool allowDCount, + bool hybridSearchQuerySkipOrderByRewrite, bool useSystemPrefix, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/FullPipelineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/FullPipelineTests.cs index 9d92b084e2..4ef83ab057 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/FullPipelineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/Pipeline/FullPipelineTests.cs @@ -338,7 +338,7 @@ private static IQueryPipelineStage CreateQueryPipelineStage( partitionedQueryExecutionInfo: null, returnResultsInDeterministicOrder: null, enableOptimisticDirectExecution: queryRequestOptions.EnableOptimisticDirectExecution, - isNonStreamingOrderByQueryFeatureDisabled: queryRequestOptions.IsNonStreamingOrderByQueryFeatureDisabled, + isHybridSearchQueryPlanOptimizationDisabled: queryRequestOptions.IsHybridSearchQueryPlanOptimizationDisabled, enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode, testInjections: queryRequestOptions.TestSettings); @@ -378,6 +378,7 @@ private static IQueryPipelineStage CreateQueryPipelineStage( It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) @@ -392,6 +393,7 @@ private static IQueryPipelineStage CreateQueryPipelineStage( bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken) => { @@ -634,7 +636,8 @@ private static QueryInfo GetQueryPlan(string query) isContinuationExpected: false, allowNonValueAggregateQuery: true, allowDCount: true, - hasLogicalPartitionKey: false, + hasLogicalPartitionKey: false, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPartitionProviderTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPartitionProviderTests.cs index 2c5dbfa04b..4859320467 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPartitionProviderTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPartitionProviderTests.cs @@ -39,7 +39,8 @@ public void TestQueryPartitionProviderUpdate() isContinuationExpected: false, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); @@ -57,6 +58,7 @@ public void TestQueryPartitionProviderUpdate() allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs index f6207fd291..3b12b2f4ba 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanBaselineTests.cs @@ -1696,7 +1696,8 @@ public override QueryPlanBaselineTestOutput ExecuteTest(QueryPlanBaselineTestInp isContinuationExpected: false, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: input.GeospatialType ?? Cosmos.GeospatialType.Geography); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanRetrieverTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanRetrieverTests.cs index 7dd2de521d..fd7689de40 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanRetrieverTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/QueryPlanRetrieverTests.cs @@ -38,6 +38,7 @@ public async Task ServiceInterop_BadRequestContainsInnerException() It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TryCatch.FromException(innerException)); @@ -50,7 +51,8 @@ public async Task ServiceInterop_BadRequestContainsInnerException() vectorEmbeddingPolicy:null, hasLogicalPartitionKey: false, geospatialType: Cosmos.GeospatialType.Geography, - useSystemPrefix: false, + useSystemPrefix: false, + isHybridSearchQueryPlanOptimizationDisabled: false, NoOpTrace.Singleton)); Assert.AreEqual(HttpStatusCode.BadRequest, cosmosException.StatusCode); @@ -75,6 +77,7 @@ public async Task ServiceInterop_BadRequestContainsOriginalCosmosException() It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TryCatch.FromException(expectedException)); @@ -87,8 +90,9 @@ public async Task ServiceInterop_BadRequestContainsOriginalCosmosException() new Documents.PartitionKeyDefinition() { Paths = new Collection() { "/id" } }, vectorEmbeddingPolicy: null, hasLogicalPartitionKey: false, - geospatialType: Cosmos.GeospatialType.Geography, + geospatialType: Cosmos.GeospatialType.Geography, useSystemPrefix: false, + isHybridSearchQueryPlanOptimizationDisabled: false, trace.Object, default)); @@ -111,6 +115,7 @@ public async Task ServiceInterop_E_UNEXPECTED() It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TryCatch.FromException(innerException)); @@ -123,7 +128,8 @@ public async Task ServiceInterop_E_UNEXPECTED() vectorEmbeddingPolicy: null, hasLogicalPartitionKey: false, geospatialType: Cosmos.GeospatialType.Geography, - useSystemPrefix: false, + useSystemPrefix: false, + isHybridSearchQueryPlanOptimizationDisabled: false, NoOpTrace.Singleton)); Assert.AreEqual(HttpStatusCode.InternalServerError, cosmosException.StatusCode); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/SubpartitionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/SubpartitionTests.cs index 2cdaedfc37..01648d77d4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/SubpartitionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Query/SubpartitionTests.cs @@ -136,7 +136,7 @@ private static IQueryPipelineStage CreateQueryPipelineStage( partitionedQueryExecutionInfo: null, returnResultsInDeterministicOrder: null, enableOptimisticDirectExecution: queryRequestOptions.EnableOptimisticDirectExecution, - isNonStreamingOrderByQueryFeatureDisabled: queryRequestOptions.IsNonStreamingOrderByQueryFeatureDisabled, + isHybridSearchQueryPlanOptimizationDisabled: queryRequestOptions.IsHybridSearchQueryPlanOptimizationDisabled, enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode, testInjections: queryRequestOptions.TestSettings); @@ -183,7 +183,8 @@ internal static Tuple Get isContinuationExpected: true, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); @@ -368,6 +369,7 @@ public override Task> TryGetPartitionedQ bool hasLogicalPartitionKey, bool allowDCount, bool useSystemPrefix, + bool isHybridSearchQueryPlanOptimizationDisabled, Cosmos.GeospatialType geospatialType, CancellationToken cancellationToken) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs index ca444d7a09..032b099a48 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs @@ -718,7 +718,8 @@ private static async Task PrefixPartitionKeyTestRunnerAsync( isContinuationExpected: true, allowNonValueAggregateQuery: false, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs index ecb747b8d7..b7b165fc5b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/TraceWriterBaselineTests.cs @@ -780,7 +780,8 @@ private static QueryInfo GetQueryPlan(string query) isContinuationExpected: false, allowNonValueAggregateQuery: true, hasLogicalPartitionKey: false, - allowDCount: true, + allowDCount: true, + hybridSearchSkipOrderByRewrite: false, useSystemPrefix: false, geospatialType: Cosmos.GeospatialType.Geography);