From 4bec38f34fbe799abeae0767a0f80ca4dfbac91e Mon Sep 17 00:00:00 2001 From: Robert Johnson Date: Fri, 27 Dec 2024 09:37:22 -0800 Subject: [PATCH] Add count limits for include --- .../QueryGenerators/SqlQueryGenerator.cs | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/SqlQueryGenerator.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/SqlQueryGenerator.cs index 59fd7a84c4..9c22d9d0a4 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/SqlQueryGenerator.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/SqlQueryGenerator.cs @@ -961,30 +961,13 @@ private void HandleTableKindInclude( private void HandleTableKindIncludeLimit(SearchOptions context) { - StringBuilder.Append("SELECT DISTINCT "); - - // TODO - https://github.com/microsoft/fhir-server/issues/1309 (limit for _include also) - var isRev = _cteToLimit.Contains(_tableExpressionCounter - 1); - if (isRev) - { - // the related cte is a reverse include, limit the number of returned items and count to - // see if we are over the threshold (to produce a warning to the client) - StringBuilder.Append("TOP (").Append(Parameters.AddParameter(context.IncludeCount, includeInHash: false)).Append(") "); - } - - StringBuilder.Append("T1, Sid1, IsMatch, "); + StringBuilder.Append("SELECT DISTINCT TOP (") + .Append(Parameters.AddParameter(context.IncludeCount, includeInHash: false)) + .Append(") T1, Sid1, IsMatch, "); - if (isRev) - { - StringBuilder.Append("CASE WHEN count_big(*) over() > ") - .Append(Parameters.AddParameter(context.IncludeCount, true)) - .AppendLine(" THEN 1 ELSE 0 END AS IsPartial "); - } - else - { - // if forward, just mark as not partial - StringBuilder.AppendLine("0 AS IsPartial "); - } + StringBuilder.Append("CASE WHEN count_big(*) over() > ") + .Append(Parameters.AddParameter(context.IncludeCount, true)) + .AppendLine(" THEN 1 ELSE 0 END AS IsPartial "); StringBuilder.Append("FROM ").AppendLine(TableExpressionName(_tableExpressionCounter - 1));