Repository navigation
granular indexes with create on write and sp clustered indexes - #6100
Open
SergeyGaluzo wants to merge 15 commits into
Open
SergeyGaluzo wants to merge 15 commits into
SergeyGaluzo wants to merge 15 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Schema 123 blocks upgrades for initialized databases, rejects TokenText during writes, and omits required index and cleanup-procedure changes from the migration.
5 open issues
What changed in this PR
Introduces experimental, per-search-parameter indexes in the SQL Server storage layer, with index creation before writes and target-table metadata for resource cleanup.
Changes:
- Adds granular-index creation procedures and write-time checks with client-side caching.
- Moves search-parameter clustered keys to lead with
SearchParamIdand updates cleanup queries. - Adds schema-123 wiring and unit tests for target mapping, key discovery, caching, and retries.
Static SQL assessment: the new leading keys align with the rewritten cleanup predicates. Runtime performance was not verified.
| File | Description |
|---|---|
| src/Microsoft.Health.Fhir.SqlServer/Microsoft.Health.Fhir.SqlServer.csproj | Sets the latest schema to 123. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlStoreClient.cs | Discovers index keys and caches creation results. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirModel.cs | Supplies target-table metadata during initialization. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs | Ensures indexes before writes and reindex batches. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SearchParameterTargetTable.cs | Maps parameter definitions to storage tables. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Storage/Registry/SqlServerSearchParameterStatusDataStore.cs | Persists target tables with status updates. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/VectorSearchParam.sql | Leads the clustered primary key with SearchParamId. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/UriSearchParam.sql | Reorders the URI clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenTokenCompositeSearchParam.sql | Reorders the token/token clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenText.sql | Reorders the token-text clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenStringCompositeSearchParam.sql | Reorders the token/string clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenSearchParam.sql | Reorders the token clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenQuantityCompositeSearchParam.sql | Reorders the token/quantity clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenNumberNumberCompositeSearchParam.sql | Reorders the token/number/number clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/TokenDateTimeCompositeSearchParam.sql | Reorders the token/date-time clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/StringSearchParam.sql | Reorders the string clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/SearchParam.sql | Adds required target-table metadata. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/ReferenceTokenCompositeSearchParam.sql | Reorders the reference/token clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/ReferenceSearchParam.sql | Reorders the reference clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/QuantitySearchParam.sql | Reorders the quantity clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/NumberSearchParam.sql | Reorders the number clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Tables/DateTimeSearchParam.sql | Reorders the date-time clustered index. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/MergeSearchParams.sql | Merges target metadata with parameter statuses. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/MergeResourcesAndSearchParams.sql | Forwards target metadata during combined writes. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/MergeResources.sql | Uses target mappings to select cleanup rows. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/InitializeBase.sql | Initializes registry rows with target tables. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/CreateGranularSecondaryIndexes.sql | Creates filtered indexes from disabled templates. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Sql/Sprocs/CreateAllGranularSecondaryIndexes.sql | Schedules index creation for eligible parameters. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/SchemaVersionConstants.cs | Updates schema bounds and adds a feature gate. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/SchemaVersion.cs | Adds version 123. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/123.diff.sql | Adds experimental migration metadata and procedures. |
| src/Microsoft.Health.Fhir.SqlServer.UnitTests/Features/Storage/SqlStoreClientGranularIndexTests.cs | Tests key extraction, caching, retries, and schema gating. |
| src/Microsoft.Health.Fhir.SqlServer.UnitTests/Features/Storage/SearchParameterTargetTableTests.cs | Tests parameter-to-table mappings. |
| src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterBehaviorTests.cs | Verifies queued statuses retain definitions. |
| src/Microsoft.Health.Fhir.Core/Features/Search/Registry/ResourceSearchParameterStatus.cs | Carries definitions with pending status changes. |
| src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs | Queues definitions with resolved composite components. |
Review effort: Balanced
Comment on lines
+1
to
+3
| IF EXISTS (SELECT 1 FROM dbo.SearchParam) | ||
| THROW 50000, 'This experimental migration requires an empty SearchParam table.', 1 | ||
| ALTER TABLE dbo.SearchParam ADD TargetTable varchar(128) NOT NULL |
| EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='Error',@Start=@st; | ||
| THROW | ||
| END CATCH | ||
| GO |
| IF @@trancount <> 0 | ||
| RAISERROR('Granular secondary indexes must be created outside transaction.', 18, 128) | ||
|
|
||
| IF @ObjectId IS NULL OR @SearchParamId IS NULL OR NOT @TableName LIKE '%SearchParam' |
Comment on lines
+20
to
+27
| INSERT INTO @Targets (TableName, SearchParamId) | ||
| SELECT TargetTable, SearchParamId | ||
| FROM dbo.SearchParam | ||
| WHERE Status IN ('Enabled', 'Supported') AND TargetTable NOT IN ('Resource', 'VectorSearchParam') | ||
|
|
||
| IF EXISTS ( | ||
| SELECT * FROM @Targets T | ||
| WHERE T.TableName NOT LIKE '%SearchParam' OR NOT EXISTS ( |
| DELETE A FROM @PreviousSurrogateIds P CROSS JOIN (SELECT SearchParamId FROM dbo.SearchParam WHERE TargetTable = 'ReferenceSearchParam') S JOIN dbo.ReferenceSearchParam A ON A.SearchParamId = S.SearchParamId AND A.ResourceTypeId = P.TypeId AND A.ResourceSurrogateId = P.SurrogateId | ||
| SET @AffectedRows += @@rowcount | ||
| DELETE FROM dbo.TokenSearchParam WHERE EXISTS (SELECT * FROM @PreviousSurrogateIds WHERE TypeId = ResourceTypeId AND SurrogateId = ResourceSurrogateId) | ||
| DELETE A FROM @PreviousSurrogateIds P CROSS JOIN (SELECT SearchParamId FROM dbo.SearchParam WHERE TargetTable = 'TokenSearchParam') S JOIN dbo.TokenSearchParam A ON A.SearchParamId = S.SearchParamId AND A.ResourceTypeId = P.TypeId AND A.ResourceSurrogateId = P.SurrogateId |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


No description provided.