Skip to content

Commit b76ac69

Browse files
committed
Lookup @PreviousExtendedAttributes from table directly
While the `ExtendedAttributeIndex` is quite useful, it also introduces significant performance overhead. In the case of `UpdateTopic`, it represents 99% of the actual execution plan when it comes to just the `SELECT` statements. (Obviously, the `INSERT` statements are comparatively more expensive.) This is a pretty steep price given that it's not really necessary here. When we're working with a single topic, and only need a single record, we can grab the last extended attribute directly from the `ExtendedAttributes` with only a couple of additional lines of code (namely a `TOP 1` and a `ORDER BY` clause). This greatly improves the performance of `UpdateTopic`, and distributes the weight across other tasks.
1 parent afa1e9b commit b76ac69

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

OnTopic.Data.Sql.Database/Stored Procedures/UpdateTopic.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ WHERE AttributeKey != 'ParentId'
4141
--------------------------------------------------------------------------------------------------------------------------------
4242
DECLARE @PreviousExtendedAttributes XML
4343

44-
SELECT @PreviousExtendedAttributes = AttributesXml
45-
FROM ExtendedAttributeIndex
44+
SELECT TOP 1
45+
@PreviousExtendedAttributes = AttributesXml
46+
FROM ExtendedAttributes
4647
WHERE TopicID = @TopicID
48+
ORDER BY Version DESC
4749

4850
--------------------------------------------------------------------------------------------------------------------------------
4951
-- ADD EXTENDED ATTRIBUTES, IF CHANGED

0 commit comments

Comments
 (0)