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

[Do not review] New schema with reference separation #4710

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
47c370f
Raw resources in the Lake and Resource Id integer map
SergeyGaluzo Sep 27, 2024
5aca029
perf tweeks
SergeyGaluzo Oct 2, 2024
de5a156
Merge history separation with separated raw resources (#4685)
SergeyGaluzo Oct 17, 2024
e37ffd4
Merge resource id map
SergeyGaluzo Oct 17, 2024
5d8d03a
Fix after merge
SergeyGaluzo Oct 18, 2024
cc94008
Fix after merge
SergeyGaluzo Oct 18, 2024
d6ce380
adjustments
SergeyGaluzo Oct 18, 2024
2950bcf
tests
SergeyGaluzo Oct 18, 2024
8e74731
Merge from main
SergeyGaluzo Oct 18, 2024
c3ccf69
Merge fixes
SergeyGaluzo Oct 18, 2024
b0ed1eb
Ignore NULL reference resource tyoe
SergeyGaluzo Oct 18, 2024
51a942d
test fix
SergeyGaluzo Oct 18, 2024
38e869b
default number of columns = 13
SergeyGaluzo Oct 19, 2024
bb535af
commented 84 diff
SergeyGaluzo Oct 19, 2024
7060321
set end date on enqueue
SergeyGaluzo Oct 22, 2024
427cdfa
rename secondary to adls
SergeyGaluzo Oct 22, 2024
02a545f
defrag formatting
SergeyGaluzo Oct 27, 2024
fbbaf20
set timeout to 0 for getting frag
SergeyGaluzo Oct 28, 2024
3f5dcd9
isnull on input param
SergeyGaluzo Oct 28, 2024
e6e3fe9
Merge branch 'main' into users/sergal/rawmaplakeandhistoryandresource…
SergeyGaluzo Oct 29, 2024
5569ea1
after merge from main
SergeyGaluzo Oct 30, 2024
2648ecd
Merge branch 'users/sergal/rawmaplakeandhistoryandresourceidmap' into…
SergeyGaluzo Oct 31, 2024
037061d
Reference separation
SergeyGaluzo Oct 31, 2024
99c6620
file id
SergeyGaluzo Nov 1, 2024
0b226bf
small things
SergeyGaluzo Nov 1, 2024
7f286f9
Do not write raw resource
SergeyGaluzo Nov 7, 2024
873583e
Added missing file id in history insert
SergeyGaluzo Nov 18, 2024
ce28891
hard delete tests
SergeyGaluzo Nov 19, 2024
848195c
change capture
SergeyGaluzo Nov 19, 2024
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

Large diffs are not rendered by default.

5,849 changes: 5,849 additions & 0 deletions src/Microsoft.Health.Fhir.SqlServer/Features/Schema/Migrations/84.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ public enum SchemaVersion
V81 = 81,
V82 = 82,
V83 = 83,
V84 = 84,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Health.Fhir.SqlServer.Features.Schema
public static class SchemaVersionConstants
{
public const int Min = (int)SchemaVersion.V80;
public const int Max = (int)SchemaVersion.V83;
public const int Max = (int)SchemaVersion.V84;
public const int MinForUpgrade = (int)SchemaVersion.V80; // this is used for upgrade tests only
public const int SearchParameterStatusSchemaVersion = (int)SchemaVersion.V6;
public const int SupportForReferencesWithMissingTypeVersion = (int)SchemaVersion.V7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ CREATE SEQUENCE dbo.ResourceSurrogateIdUniquifierSequence
CYCLE
CACHE 1000000
GO
CREATE SEQUENCE dbo.ResourceIdIntMapSequence
AS int
START WITH 0
INCREMENT BY 1
MINVALUE 0
MAXVALUE 79999
CYCLE
CACHE 1000000
GO
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Go

INSERT INTO dbo.SchemaVersion
VALUES
(83, 'started')
(84, 'started')

Go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE PROCEDURE dbo.AssignResourceIdInts @Count int, @FirstIdInt bigint OUT
AS
set nocount on
DECLARE @SP varchar(100) = 'AssignResourceIdInts'
,@Mode varchar(200) = 'Cnt='+convert(varchar,@Count)
,@st datetime = getUTCdate()
,@FirstValueVar sql_variant
,@LastValueVar sql_variant
,@SequenceRangeFirstValue int

BEGIN TRY
SET @FirstValueVar = NULL
WHILE @FirstValueVar IS NULL
BEGIN
EXECUTE sys.sp_sequence_get_range @sequence_name = 'dbo.ResourceIdIntMapSequence', @range_size = @Count, @range_first_value = @FirstValueVar OUT, @range_last_value = @LastValueVar OUT
SET @SequenceRangeFirstValue = convert(int,@FirstValueVar)
IF @SequenceRangeFirstValue > convert(int,@LastValueVar)
SET @FirstValueVar = NULL
END

SET @FirstIdInt = datediff_big(millisecond,'0001-01-01',sysUTCdatetime()) * 80000 + @SequenceRangeFirstValue
END TRY
BEGIN CATCH
IF error_number() = 1750 THROW -- Real error is before 1750, cannot trap in SQL.
IF @@trancount > 0 ROLLBACK TRANSACTION
EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='Error';
THROW
END CATCH
GO
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BEGIN TRY
WHERE NOT EXISTS (SELECT * FROM dbo.IndexProperties WHERE TableName = Tbl AND IndexName = Ind)
EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='Info',@Target='IndexProperties',@Action='Insert',@Rows=@@rowcount

DELETE FROM @Indexes WHERE Tbl = 'Resource' OR IndId = 1
DELETE FROM @Indexes WHERE Tbl IN ('Resource','ResourceCurrent','ResourceHistory') OR IndId = 1
EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='Info',@Target='@Indexes',@Action='Delete',@Rows=@@rowcount

WHILE EXISTS (SELECT * FROM @Indexes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ BEGIN TRY
END
,MatchedVersion = isnull(D.Version,0)
,MatchedRawResource = D.RawResource
,MatchedTransactionId = D.TransactionId
,MatchedOffsetInFile = D.OffsetInFile
-- ResourceIndex allows to deal with more than one late arrival per resource
FROM (SELECT TOP (@DummyTop) *, ResourceIndex = convert(int,row_number() OVER (PARTITION BY ResourceTypeId, ResourceId ORDER BY ResourceSurrogateId DESC)) FROM @ResourceDateKeys) A
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.Version > 0 AND B.ResourceSurrogateId < A.ResourceSurrogateId ORDER BY B.ResourceSurrogateId DESC) L -- lower
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.Version > 0 AND B.ResourceSurrogateId > A.ResourceSurrogateId ORDER BY B.ResourceSurrogateId) U -- upper
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.Version < 0 ORDER BY B.Version) M -- minus
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.ResourceSurrogateId BETWEEN A.ResourceSurrogateId AND A.ResourceSurrogateId + 79999) D -- date
FROM (SELECT TOP (@DummyTop) A.*, M.ResourceIdInt, ResourceIndex = convert(int,row_number() OVER (PARTITION BY A.ResourceTypeId, A.ResourceId ORDER BY ResourceSurrogateId DESC))
FROM @ResourceDateKeys A
LEFT OUTER JOIN dbo.ResourceIdIntMap M WITH (INDEX = U_ResourceIdIntMap_ResourceId_ResourceTypeId) ON M.ResourceTypeId = A.ResourceTypeId AND M.ResourceId = A.ResourceId
) A
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceIdInt = A.ResourceIdInt AND B.Version > 0 AND B.ResourceSurrogateId < A.ResourceSurrogateId ORDER BY B.ResourceSurrogateId DESC) L -- lower
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceIdInt = A.ResourceIdInt AND B.Version > 0 AND B.ResourceSurrogateId > A.ResourceSurrogateId ORDER BY B.ResourceSurrogateId) U -- upper
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceIdInt = A.ResourceIdInt AND B.Version < 0 ORDER BY B.Version) M -- minus
OUTER APPLY (SELECT TOP 1 * FROM dbo.Resource B WHERE B.ResourceTypeId = A.ResourceTypeId AND B.ResourceIdInt = A.ResourceIdInt AND B.ResourceSurrogateId BETWEEN A.ResourceSurrogateId AND A.ResourceSurrogateId + 79999) D -- date
OPTION (MAXDOP 1, OPTIMIZE FOR (@DummyTop = 1))

EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='End',@Start=@st,@Rows=@@rowcount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set nocount on
DECLARE @st datetime = getUTCdate()
,@SP varchar(100) = 'GetResources'
,@InputRows int
,@DummyTop bigint = 9223372036854775807
,@NotNullVersionExists bit
,@NullVersionExists bit
,@MinRT smallint
Expand All @@ -22,57 +21,69 @@ BEGIN TRY
SELECT B.ResourceTypeId
,B.ResourceId
,ResourceSurrogateId
,B.Version
,C.Version
,IsDeleted
,IsHistory
,RawResource
,IsRawResourceMetaSet
,SearchParamHash
FROM (SELECT TOP (@DummyTop) * FROM @ResourceKeys) A
JOIN dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.Version = A.Version
OPTION (MAXDOP 1, OPTIMIZE FOR (@DummyTop = 1))
,TransactionId
,OffsetInFile
FROM (SELECT * FROM @ResourceKeys) A
INNER LOOP JOIN dbo.ResourceIdIntMap B WITH (INDEX = U_ResourceIdIntMap_ResourceId_ResourceTypeId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
INNER LOOP JOIN dbo.Resource C ON C.ResourceTypeId = A.ResourceTypeId AND C.ResourceIdInt = B.ResourceIdInt AND C.Version = A.Version
OPTION (MAXDOP 1)
ELSE
SELECT *
FROM (SELECT B.ResourceTypeId
,B.ResourceId
,ResourceSurrogateId
,B.Version
,C.Version
,IsDeleted
,IsHistory
,RawResource
,IsRawResourceMetaSet
,SearchParamHash
FROM (SELECT TOP (@DummyTop) * FROM @ResourceKeys WHERE Version IS NOT NULL) A
JOIN dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId_Version) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId AND B.Version = A.Version
,TransactionId
,OffsetInFile
FROM (SELECT * FROM @ResourceKeys WHERE Version IS NOT NULL) A
INNER LOOP JOIN dbo.ResourceIdIntMap B WITH (INDEX = U_ResourceIdIntMap_ResourceId_ResourceTypeId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
INNER LOOP JOIN dbo.Resource C ON C.ResourceTypeId = A.ResourceTypeId AND C.ResourceIdInt = B.ResourceIdInt AND C.Version = A.Version
UNION ALL
SELECT B.ResourceTypeId
,B.ResourceId
,ResourceSurrogateId
,B.Version
,C.ResourceSurrogateId
,C.Version
,IsDeleted
,IsHistory
,RawResource
,IsRawResourceMetaSet
,SearchParamHash
FROM (SELECT TOP (@DummyTop) * FROM @ResourceKeys WHERE Version IS NULL) A
JOIN dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
WHERE IsHistory = 0
,TransactionId
,OffsetInFile
FROM (SELECT * FROM @ResourceKeys WHERE Version IS NULL) A
INNER LOOP JOIN dbo.ResourceIdIntMap B WITH (INDEX = U_ResourceIdIntMap_ResourceId_ResourceTypeId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
INNER LOOP JOIN dbo.CurrentResources C ON C.ResourceTypeId = A.ResourceTypeId AND C.ResourceIdInt = B.ResourceIdInt AND C.IsHistory = 0
LEFT OUTER JOIN dbo.RawResources D ON D.ResourceTypeId = A.ResourceTypeId AND D.ResourceSurrogateId = C.ResourceSurrogateId
) A
OPTION (MAXDOP 1, OPTIMIZE FOR (@DummyTop = 1))
OPTION (MAXDOP 1)
ELSE
SELECT B.ResourceTypeId
,B.ResourceId
,ResourceSurrogateId
,B.Version
,C.ResourceSurrogateId
,C.Version
,IsDeleted
,IsHistory
,RawResource
,IsRawResourceMetaSet
,SearchParamHash
FROM (SELECT TOP (@DummyTop) * FROM @ResourceKeys) A
JOIN dbo.Resource B WITH (INDEX = IX_Resource_ResourceTypeId_ResourceId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
WHERE IsHistory = 0
OPTION (MAXDOP 1, OPTIMIZE FOR (@DummyTop = 1))
,TransactionId
,OffsetInFile
FROM (SELECT * FROM @ResourceKeys) A
INNER LOOP JOIN dbo.ResourceIdIntMap B WITH (INDEX = U_ResourceIdIntMap_ResourceId_ResourceTypeId) ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceId = A.ResourceId
INNER LOOP JOIN dbo.CurrentResources C ON C.ResourceTypeId = A.ResourceTypeId AND C.ResourceIdInt = B.ResourceIdInt
LEFT OUTER JOIN dbo.RawResources D ON D.ResourceTypeId = A.ResourceTypeId AND D.ResourceSurrogateId = C.ResourceSurrogateId
OPTION (MAXDOP 1)

EXECUTE dbo.LogEvent @Process=@SP,@Mode=@Mode,@Status='End',@Start=@st,@Rows=@@rowcount
END TRY
Expand All @@ -83,5 +94,5 @@ BEGIN CATCH
END CATCH
GO
--DECLARE @ResourceKeys dbo.ResourceKeyList
--INSERT INTO @ResourceKeys SELECT TOP 1 ResourceTypeId, ResourceId, NULL FROM Resource
--INSERT INTO @ResourceKeys SELECT 96, newid(), NULL
--EXECUTE dbo.GetResources @ResourceKeys
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ BEGIN TRY
,IsRawResourceMetaSet
,SearchParamHash
,RequestMethod
,TransactionId
,OffsetInFile
FROM (SELECT TOP (@DummyTop) * FROM @Keys) A
JOIN dbo.Resource B ON ResourceTypeId = TypeId AND ResourceSurrogateId = SurrogateId
WHERE IsHistory = 0 OR @IncludeHistory = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ BEGIN TRY
OPTION (MAXDOP 1, OPTIMIZE FOR (@DummyTop = 1))
END

SELECT ResourceTypeId, ResourceId, Version, IsDeleted, ResourceSurrogateId, RequestMethod, IsMatch = convert(bit,1), IsPartial = convert(bit,0), IsRawResourceMetaSet, SearchParamHash, RawResource
SELECT ResourceTypeId, ResourceId, Version, IsDeleted, ResourceSurrogateId, RequestMethod, IsMatch = convert(bit,1), IsPartial = convert(bit,0), IsRawResourceMetaSet, SearchParamHash, RawResource, TransactionId, OffsetInFile
FROM dbo.Resource
WHERE ResourceTypeId = @ResourceTypeId
AND ResourceSurrogateId BETWEEN @StartId AND @EndId
AND (IsHistory = 0 OR @IncludeHistory = 1)
AND (IsDeleted = 0 OR @IncludeDeleted = 1)
UNION ALL
SELECT ResourceTypeId, ResourceId, Version, IsDeleted, ResourceSurrogateId, RequestMethod, IsMatch = convert(bit,1), IsPartial = convert(bit,0), IsRawResourceMetaSet, SearchParamHash, RawResource
SELECT ResourceTypeId, ResourceId, Version, IsDeleted, ResourceSurrogateId, RequestMethod, IsMatch = convert(bit,1), IsPartial = convert(bit,0), IsRawResourceMetaSet, SearchParamHash, RawResource, TransactionId, OffsetInFile
FROM @SurrogateIds
JOIN dbo.Resource ON ResourceTypeId = @ResourceTypeId AND ResourceSurrogateId = MaxSurrogateId
WHERE IsHistory = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BEGIN TRY
BEGIN
-- PAGLOCK allows deallocation of empty page without waiting for ghost cleanup
DELETE FROM B FROM @SurrogateIds A INNER LOOP JOIN dbo.ResourceWriteClaim B WITH (INDEX = 1, FORCESEEK, PAGLOCK) ON B.ResourceSurrogateId = A.ResourceSurrogateId OPTION (MAXDOP 1)
DELETE FROM B FROM @SurrogateIds A INNER LOOP JOIN dbo.ReferenceSearchParam B WITH (INDEX = 1, FORCESEEK, PAGLOCK) ON B.ResourceTypeId = @ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId OPTION (MAXDOP 1)
DELETE FROM dbo.ReferenceSearchParam WHERE ResourceTypeId = @ResourceTypeId AND ResourceSurrogateId IN (SELECT ResourceSurrogateId FROM @SurrogateIds)
DELETE FROM B FROM @SurrogateIds A INNER LOOP JOIN dbo.TokenSearchParam B WITH (INDEX = 1, FORCESEEK, PAGLOCK) ON B.ResourceTypeId = @ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId OPTION (MAXDOP 1)
DELETE FROM B FROM @SurrogateIds A INNER LOOP JOIN dbo.TokenText B WITH (INDEX = 1, FORCESEEK, PAGLOCK) ON B.ResourceTypeId = @ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId OPTION (MAXDOP 1)
DELETE FROM B FROM @SurrogateIds A INNER LOOP JOIN dbo.StringSearchParam B WITH (INDEX = 1, FORCESEEK, PAGLOCK) ON B.ResourceTypeId = @ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId OPTION (MAXDOP 1)
Expand Down
Loading
Loading