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

Add count limits for include #4761

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Loading