Commit e725077
committed
Optimize deduplication join in
In a previous commit, I introduced the ability to prevent `UpdateRelationships` from trying to insert duplicate `Target_TopicID`s. This isn't currently necessary since `SqlTopicRepository` always deletes the relationships (via `UpdateTopic`'s `@DeleteRelationships` flag) before calling `UpdateRelationships`. Nevertheless, in the case that this wasn't done, this avoids a primary key constraint violation if existing keys are sent via `@RelatedTopics`.
Unfortunately, the process by which this was done has proven very expensive, due to the performance of user-defined, table-valued types. While those work fine for data transfer objects _to_ stored procedures, they are suboptimal for internal storage _within_ stored procedures. In this case, it's also completely unnecessary.
To mitigate this, the local `@Existing_TopicIDs` storage is replaced with a new `LEFT JOIN` against the _actual_ `Relationships` table. This proves dramatically faster in testing (representing ≈12% of the test case's execution plan, as opposed to ≈38% with the previous model). Note that the test case includes inserting sample data into the `@RelatedTopics` parameter, so that ends up taking up _most_ of the time.UpdateRelationships
1 parent 5583d22 commit e725077
1 file changed
Lines changed: 5 additions & 21 deletions
Lines changed: 5 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 13 | | |
31 | 14 | | |
32 | 15 | | |
| |||
38 | 21 | | |
39 | 22 | | |
40 | 23 | | |
41 | | - | |
| 24 | + | |
42 | 25 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
46 | 30 | | |
47 | 31 | | |
48 | 32 | | |
| |||
0 commit comments