Commit 8902dbd
fix: restrict DELETE scope in removeDuplicityDescribingEntities
The DELETE query in BatchJobActivityFinalizer.removeDuplicityDescribingEntities
was missing an activity_revision_id filter on the outer WHERE clause. This
caused a full sequential scan of the entire activity_describing_entity table
(5.5 GB in production) on every batch job completion, making the query take
~9 seconds instead of <1ms.
Additionally, the missing filter meant the DELETE could affect rows from
unrelated historical activity revisions that happened to share the same
(entity_class, entity_id) as entities in the batch being merged, silently
corrupting activity history data.
Fix: add (activity_revision_id in (:revisionIds) or activity_revision_id =
:activityRevisionIdToMergeInto) as the leading predicate on the outer DELETE,
restricting it to only the chunk revisions being merged. This allows the
existing index on (activity_revision_id, entity_class, entity_id) to be used.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent d8baa63 commit 8902dbd
1 file changed
Lines changed: 2 additions & 1 deletion
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| |||
0 commit comments