Add index on document_receivers(person_id) for per-person document counts #681
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Surfaced in the review of PR #679 (Phase 5 persons directory, #667) — Markus (architect).
The persons directory computes a per-person
documentCountvia correlated COUNT subqueries overdocuments(as sender) anddocument_receivers(as receiver).documents(sender_id)is indexed (V62), butdocument_receivers(person_id)is effectively unindexed: the join table's composite primary key leads ondocument_id, so it cannot serve a predicate on the trailingperson_idcolumn. The receiver-side count therefore degrades as the corpus grows.Suggested approach
document_receivers(person_id).countByFilter/findByFilter's receiver subquery after adding it.Out of scope / notes