Skip to content

Commit

Permalink
Add count limits for include (#4761)
Browse files Browse the repository at this point in the history
  • Loading branch information
LTA-Thinking authored Jan 7, 2025
1 parent 9937414 commit 0739200
Showing 1 changed file with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,30 +962,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));

Expand Down

0 comments on commit 0739200

Please sign in to comment.