Skip to content

Commit b09ca5d

Browse files
committed
Introduced UniqueKeyIndex
The `UniqueKeyIndex` view is intended to aid in internal diagnostics. It provides a mapping of `TopicID` to fully-qualified `UniqueKey` values by materializing the path of the nested set. It is not a fast view, and should not be relied upon for production purposes.
1 parent 3ee74ef commit b09ca5d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

OnTopic.Data.Sql.Database/OnTopic.Data.Sql.Database.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Build Include="Utilities\Stored Procedures\DeleteOrphanedLastModifiedAttributes.sql" />
8282
<Build Include="Utilities\Stored Procedures\DeleteConsecutiveAttributes.sql" />
8383
<Build Include="Utilities\Stored Procedures\ConsolidateVersions.sql" />
84+
<Build Include="Views\UniqueKeyIndex.sql" />
8485
</ItemGroup>
8586
<ItemGroup>
8687
<Build Include="Tables\ExtendedAttributes.sql" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--------------------------------------------------------------------------------------------------------------------------------
2+
-- UNIQUE KEY (INDEX)
3+
--------------------------------------------------------------------------------------------------------------------------------
4+
-- Generates a view mapping each TopicID to its UniqueKey.
5+
--------------------------------------------------------------------------------------------------------------------------------
6+
CREATE
7+
VIEW [dbo].[UniqueKeyIndex]
8+
WITH SCHEMABINDING
9+
AS
10+
11+
SELECT Tree.TopicID,
12+
Path = Replace(Path, '&gt;', ':')
13+
FROM [dbo].[Topics] Tree
14+
CROSS APPLY (
15+
SELECT Path = Stuff((
16+
SELECT '>' + AttributeValue
17+
FROM (
18+
SELECT RangeLeft,
19+
AttributeValue
20+
FROM [dbo].[Topics]
21+
CROSS APPLY (
22+
SELECT TOP 1
23+
AttributeValue
24+
FROM [dbo].[Attributes]
25+
WHERE Attributes.TopicID = Topics.TopicID
26+
AND Attributes.AttributeKey = 'Key'
27+
ORDER BY Version DESC
28+
) AttributeValue
29+
WHERE Tree.RangeLeft BETWEEN RangeLeft AND RangeRight
30+
) B1
31+
ORDER BY RangeLeft
32+
FOR XML Path ('')
33+
)
34+
,1,4,'')
35+
) UniqueKeyIndex

0 commit comments

Comments
 (0)