diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/TokenQueryGenerator.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/TokenQueryGenerator.cs index 2d52204cd0..7e6f738c00 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/TokenQueryGenerator.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/QueryGenerators/TokenQueryGenerator.cs @@ -48,13 +48,6 @@ public override SearchParameterQueryGeneratorContext VisitString(StringExpressio return context; case FieldName.TokenCode: - // Temporary fix, once all of the databases are reindexed truncation128 should be removed. - bool truncation128 = expression.Value.Length > 128; - if (truncation128) - { - context.StringBuilder.Append("(("); - } - if (expression.Value.Length < VLatest.TokenSearchParam.Code.Metadata.MaxLength) { // In this case CodeOverflow in the DB table is always NULL, no need to test. There are SQL constraints in each table to enforce this. @@ -82,13 +75,6 @@ public override SearchParameterQueryGeneratorContext VisitString(StringExpressio VisitSimpleString(expression, context, VLatest.TokenSearchParam.CodeOverflow, expression.Value[codeLength..]); } - if (truncation128) - { - context.StringBuilder.Append(") OR ("); - VisitSimpleString(expression, context, VLatest.TokenSearchParam.Code, expression.Value[..128]); - context.StringBuilder.Append("))"); - } - break; default: throw new InvalidOperationException(); diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs index 8a524cc7b9..f0b96a3467 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs @@ -2335,12 +2335,6 @@ public IEnumerable GenerateRows(IList tokens) } yield return new TokenListRow(code, codeOverflow, token.SystemId, token.SystemValue); - - // truncation128 logic: see TokenQueryGenerator or ask RB - if (token.Code.Length > 128) - { - yield return new TokenListRow(code[..128], null, token.SystemId, token.SystemValue); - } } } } diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlComplexQueryTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlComplexQueryTests.cs index 492c1bab1b..3f7567ad39 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlComplexQueryTests.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlComplexQueryTests.cs @@ -42,7 +42,6 @@ public class SqlComplexQueryTests : IClassFixture { private readonly FhirStorageTestsFixture _fixture; private readonly ITestOutputHelper _output; - private string _truncation128code = $"prefix {new string('z', 128)}"; private string _codeWithOverflow = $"prefix {new string('z', 256)}"; public SqlComplexQueryTests(FhirStorageTestsFixture fixture, ITestOutputHelper output) @@ -92,10 +91,8 @@ public async Task SearchByTokens_GetResourcesByTokensIsUsed() await CheckStoredProcedureUsage([Tuple.Create("identifier", "NotExisting|A")], 0, spName); //// not existing system plus await CheckStoredProcedureUsage([Tuple.Create("identifier", "NotExisting|A,TestSystem|B")], 1, spName); - //// truncation - await CheckStoredProcedureUsage([Tuple.Create("identifier", _truncation128code)], 2, spName); - //// overflow. 1 with exact match + 1 from truncate 128 logic - await CheckStoredProcedureUsage([Tuple.Create("identifier", _codeWithOverflow)], 2, spName); + //// overflow. + await CheckStoredProcedureUsage([Tuple.Create("identifier", _codeWithOverflow)], 1, spName); } private async Task CheckStoredProcedureUsage(IReadOnlyList> queryParameters, int expectedResources, string spName, bool validateSpIsUsed = true) @@ -369,8 +366,6 @@ private async Task PrepareData() await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier(null, "A")).ToResourceElement()); await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier("TestSystem", "B")).ToResourceElement()); await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier(null, "B")).ToResourceElement()); - await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier(null, _truncation128code[..128])).ToResourceElement()); - await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier(null, _truncation128code)).ToResourceElement()); await _fixture.Mediator.UpsertResourceAsync(CreateTestPatient(null, new Identifier(null, _codeWithOverflow)).ToResourceElement()); //// search indexes are not calculated for whatever reason, so populating TokenSearchParam manually await _fixture.SqlHelper.ExecuteSqlCmd(@$" @@ -390,11 +385,9 @@ SELECT ResourceTypeId ,Code = CASE WHEN RowId IN (1,2) THEN 'A' WHEN RowId IN (3,4) THEN 'B' - WHEN RowId = 5 THEN '{_truncation128code[..128]}' - WHEN RowId = 6 THEN '{_truncation128code}' - WHEN RowId = 7 THEN '{_codeWithOverflow[..256]}' + WHEN RowId = 5 THEN '{_codeWithOverflow[..256]}' END - ,CodeOverflow = CASE WHEN RowId = 7 THEN '{_codeWithOverflow[256..]}' END + ,CodeOverflow = CASE WHEN RowId = 5 THEN '{_codeWithOverflow[256..]}' END FROM (SELECT RowId = row_number() OVER (ORDER BY ResourceSurrogateId), * FROM dbo.Resource) A "); }